37 unwrap(rewriter)->clearInsertionPoint();
52 unwrap(rewriter)->setInsertionPointAfterValue(
unwrap(value));
57 unwrap(rewriter)->setInsertionPointToStart(
unwrap(block));
66 return wrap(
unwrap(rewriter)->getInsertionBlock());
78 if (it == block->
end())
81 return wrap(std::addressof(*it));
89 MlirBlock insertBefore,
91 MlirType
const *argTypes,
92 MlirLocation
const *locations) {
119 MlirRegion region, MlirBlock before) {
129 MlirRegion region, MlirBlock before) {
134 MlirOperation op, intptr_t nValues,
135 MlirValue
const *values) {
143 MlirOperation newOp) {
156 MlirBlock source, MlirOperation op,
158 MlirValue
const *argValues) {
167 MlirBlock dest, intptr_t nArgValues,
168 MlirValue
const *argValues) {
175 MlirOperation existingOp) {
180 MlirOperation existingOp) {
185 MlirBlock existingBlock) {
205 MlirValue from, MlirValue to) {
211 MlirValue
const *from,
212 MlirValue
const *to) {
217 unwrap(rewriter)->replaceAllUsesWith(unwrappedFromVals, unwrappedToVals);
223 MlirValue
const *to) {
226 unwrap(rewriter)->replaceAllOpUsesWith(
unwrap(from), unwrappedToVals);
238 MlirValue
const *newValues,
242 unwrap(rewriter)->replaceOpUsesWithinBlock(
unwrap(op), unwrappedVals,
247 MlirValue from, MlirValue to,
248 MlirOperation exceptedUser) {
273 MlirFrozenRewritePatternSet
287 MlirFrozenRewritePatternSet
patterns,
288 MlirGreedyRewriteDriverConfig) {
294 MlirFrozenRewritePatternSet
patterns,
295 MlirGreedyRewriteDriverConfig) {
320 callbacks(callbacks), userData(userData) {
334 wrap(&rewriter), userData));
345 MlirStringRef rootName,
unsigned benefit, MlirContext context,
348 std::vector<mlir::StringRef> generatedNamesVec;
349 generatedNamesVec.reserve(nGeneratedNames);
350 for (
size_t i = 0; i < nGeneratedNames; ++i) {
351 generatedNamesVec.push_back(
unwrap(generatedNames[i]));
355 unwrap(context), generatedNamesVec));
371 MlirRewritePattern pattern) {
372 std::unique_ptr<mlir::RewritePattern> patternPtr(
374 pattern.ptr =
nullptr;
375 unwrap(set)->add(std::move(patternPtr));
382 #if MLIR_ENABLE_PDL_IN_PATTERNMATCH
384 return wrap(
new mlir::PDLPatternModule(
393 MlirRewritePatternSet
401 return wrap(
unwrap(value)->dyn_cast<mlir::Value>());
405 return wrap(
unwrap(value)->dyn_cast<mlir::Type>());
409 return wrap(
unwrap(value)->dyn_cast<mlir::Operation *>());
413 return wrap(
unwrap(value)->dyn_cast<mlir::Attribute>());
426 MlirOperation value) {
431 MlirAttribute value) {
436 std::vector<MlirPDLValue> mlirValues;
437 mlirValues.reserve(values.size());
438 for (
auto &value : values) {
439 mlirValues.push_back(
wrap(&value));
447 unwrap(pdlModule)->registerRewriteFunction(
449 [userData, rewriteFn](
PatternRewriter &rewriter, PDLResultList &results,
451 std::vector<MlirPDLValue> mlirValues =
wrap(values);
453 mlirValues.size(), mlirValues.data(),
461 unwrap(pdlModule)->registerConstraintFunction(
464 PDLResultList &results,
466 std::vector<MlirPDLValue> mlirValues =
wrap(values);
468 mlirValues.size(), mlirValues.data(),
static MlirBlock createBlock(const nb::sequence &pyArgTypes, const std::optional< nb::sequence > &pyArgLocs)
Create a block, using the current location context if no locations are specified.
static MLIRContext * getContext(OpFoldResult val)
static llvm::ArrayRef< CppTy > unwrapList(size_t size, CTy *first, llvm::SmallVectorImpl< CppTy > &storage)
Block represents an ordered list of Operations.
OpListType::iterator iterator
ExternalRewritePattern(MlirRewritePatternCallbacks callbacks, void *userData, StringRef rootName, PatternBenefit benefit, MLIRContext *context, ArrayRef< StringRef > generatedNames)
LogicalResult matchAndRewrite(Operation *op, PatternRewriter &rewriter) const override
Attempt to match against code rooted at the specified operation, which is the same operation code as ...
~ExternalRewritePattern()
This class represents a frozen set of patterns that can be processed by a pattern applicator.
This class coordinates rewriting a piece of IR outside of a pattern rewrite, providing a way to keep ...
MLIRContext is the top-level object for a collection of MLIR operations.
Block::iterator getInsertionPoint() const
Returns the current insertion point of the builder.
Block * getInsertionBlock() const
Return the block the current insertion point belongs to.
Operation is the basic unit of execution within MLIR.
This class acts as an owning reference to an op, and will automatically destroy the held op on destru...
This class represents the benefit of a pattern match in a unitless scheme that ranges from 0 (very li...
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
RewritePattern is the common base class for all DAG to DAG replacements.
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
MLIR_CAPI_EXPORTED void mlirPDLPatternModuleDestroy(MlirPDLPatternModule op)
MLIR_CAPI_EXPORTED MlirValue mlirPDLValueAsValue(MlirPDLValue value)
Cast the MlirPDLValue to an MlirValue.
MLIR_CAPI_EXPORTED void mlirPDLPatternModuleRegisterRewriteFunction(MlirPDLPatternModule pdlModule, MlirStringRef name, MlirPDLRewriteFunction rewriteFn, void *userData)
Register a rewrite function into the given PDL pattern module.
MLIR_CAPI_EXPORTED MlirPDLPatternModule mlirPDLPatternModuleFromModule(MlirModule op)
MLIR_CAPI_EXPORTED MlirType mlirPDLValueAsType(MlirPDLValue value)
Cast the MlirPDLValue to an MlirType.
MLIR_CAPI_EXPORTED MlirOperation mlirPDLValueAsOperation(MlirPDLValue value)
Cast the MlirPDLValue to an MlirOperation.
MlirLogicalResult(* MlirPDLRewriteFunction)(MlirPatternRewriter rewriter, MlirPDLResultList results, size_t nValues, MlirPDLValue *values, void *userData)
This function type is used as callbacks for PDL native rewrite functions.
MlirLogicalResult(* MlirPDLConstraintFunction)(MlirPatternRewriter rewriter, MlirPDLResultList results, size_t nValues, MlirPDLValue *values, void *userData)
This function type is used as callbacks for PDL native constraint functions.
MLIR_CAPI_EXPORTED void mlirPDLResultListPushBackAttribute(MlirPDLResultList results, MlirAttribute value)
Push the MlirAttribute into the given MlirPDLResultList.
MLIR_CAPI_EXPORTED void mlirPDLResultListPushBackOperation(MlirPDLResultList results, MlirOperation value)
Push the MlirOperation into the given MlirPDLResultList.
MLIR_CAPI_EXPORTED MlirRewritePatternSet mlirRewritePatternSetFromPDLPatternModule(MlirPDLPatternModule op)
MLIR_CAPI_EXPORTED void mlirPDLResultListPushBackType(MlirPDLResultList results, MlirType value)
Push the MlirType into the given MlirPDLResultList.
MLIR_CAPI_EXPORTED MlirAttribute mlirPDLValueAsAttribute(MlirPDLValue value)
Cast the MlirPDLValue to an MlirAttribute.
MLIR_CAPI_EXPORTED void mlirPDLPatternModuleRegisterConstraintFunction(MlirPDLPatternModule pdlModule, MlirStringRef name, MlirPDLConstraintFunction constraintFn, void *userData)
Register a constraint function into the given PDL pattern module.
MLIR_CAPI_EXPORTED void mlirPDLResultListPushBackValue(MlirPDLResultList results, MlirValue value)
Push the MlirValue into the given MlirPDLResultList.
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
Include the generated interface declarations.
LogicalResult applyPatternsGreedily(Region ®ion, const FrozenRewritePatternSet &patterns, GreedyRewriteConfig config=GreedyRewriteConfig(), bool *changed=nullptr)
Rewrite ops in the given region, which must be isolated from above, by repeatedly applying the highes...
Operation * cloneWithoutRegions(OpBuilder &b, Operation *op, TypeRange newResultTypes, ValueRange newOperands)
const FrozenRewritePatternSet & patterns
Operation * clone(OpBuilder &b, Operation *op, TypeRange newResultTypes, ValueRange newOperands)
A logical result value, essentially a boolean with named states.
MlirLogicalResult(* matchAndRewrite)(MlirRewritePattern pattern, MlirOperation op, MlirPatternRewriter rewriter, void *userData)
The callback function to match against code rooted at the specified operation, and perform the rewrit...
void(* construct)(void *userData)
Optional constructor for the user data.
void(* destruct)(void *userData)
Optional destructor for the user data.
A pointer to a sized fragment of a string, not necessarily null-terminated.