38 unwrap(rewriter)->clearInsertionPoint();
53 unwrap(rewriter)->setInsertionPointAfterValue(
unwrap(value));
58 unwrap(rewriter)->setInsertionPointToStart(
unwrap(block));
67 return wrap(
unwrap(rewriter)->getInsertionBlock());
79 if (it == block->
end())
82 return wrap(std::addressof(*it));
90 MlirBlock insertBefore,
92 MlirType
const *argTypes,
93 MlirLocation
const *locations) {
98 return wrap(
unwrap(rewriter)->createBlock(
unwrap(insertBefore), unwrappedArgs,
120 MlirRegion region, MlirBlock before) {
130 MlirRegion region, MlirBlock before) {
136 MlirValue
const *values) {
144 MlirOperation newOp) {
157 MlirBlock source, MlirOperation op,
159 MlirValue
const *argValues) {
168 MlirBlock dest,
intptr_t nArgValues,
169 MlirValue
const *argValues) {
176 MlirOperation existingOp) {
181 MlirOperation existingOp) {
186 MlirBlock existingBlock) {
206 MlirValue from, MlirValue to) {
212 MlirValue
const *from,
213 MlirValue
const *to) {
218 unwrap(rewriter)->replaceAllUsesWith(unwrappedFromVals, unwrappedToVals);
224 MlirValue
const *to) {
227 unwrap(rewriter)->replaceAllOpUsesWith(
unwrap(from), unwrappedToVals);
239 MlirValue
const *newValues,
243 unwrap(rewriter)->replaceOpUsesWithinBlock(
unwrap(op), unwrappedVals,
248 MlirValue from, MlirValue to,
249 MlirOperation exceptedUser) {
274MlirFrozenRewritePatternSet
291 assert(
config.ptr &&
"unexpected null config");
304 MlirGreedyRewriteDriverConfig
config) {
309 MlirGreedyRewriteDriverConfig
config,
int64_t maxIterations) {
314 MlirGreedyRewriteDriverConfig
config,
int64_t maxNumRewrites) {
319 MlirGreedyRewriteDriverConfig
config,
bool useTopDownTraversal) {
324 MlirGreedyRewriteDriverConfig
config,
bool enable) {
329 MlirGreedyRewriteDriverConfig
config,
332 switch (strictness) {
364 MlirGreedyRewriteDriverConfig
config,
bool enable) {
369 MlirGreedyRewriteDriverConfig
config) {
374 MlirGreedyRewriteDriverConfig
config) {
379 MlirGreedyRewriteDriverConfig
config) {
384 MlirGreedyRewriteDriverConfig
config) {
389 MlirGreedyRewriteDriverConfig
config) {
391 switch (cppStrictness) {
403 MlirGreedyRewriteDriverConfig
config) {
417 MlirGreedyRewriteDriverConfig
config) {
423 MlirFrozenRewritePatternSet
patterns,
424 MlirGreedyRewriteDriverConfig
config) {
431 MlirFrozenRewritePatternSet
patterns,
432 MlirGreedyRewriteDriverConfig
config) {
438 MlirFrozenRewritePatternSet
patterns) {
463 callbacks(callbacks), userData(userData) {
464 if (callbacks.construct)
465 callbacks.construct(userData);
469 if (callbacks.destruct)
470 callbacks.destruct(userData);
475 return unwrap(callbacks.matchAndRewrite(
477 wrap(&rewriter), userData));
488 MlirStringRef rootName,
unsigned benefit, MlirContext context,
491 std::vector<mlir::StringRef> generatedNamesVec;
492 generatedNamesVec.reserve(nGeneratedNames);
493 for (
size_t i = 0; i < nGeneratedNames; ++i) {
494 generatedNamesVec.push_back(
unwrap(generatedNames[i]));
498 unwrap(context), generatedNamesVec));
514 MlirRewritePattern pattern) {
515 std::unique_ptr<mlir::RewritePattern> patternPtr(
517 pattern.ptr =
nullptr;
518 unwrap(set)->add(std::move(patternPtr));
525#if MLIR_ENABLE_PDL_IN_PATTERNMATCH
526MlirPDLPatternModule mlirPDLPatternModuleFromModule(MlirModule op) {
527 return wrap(
new mlir::PDLPatternModule(
531void mlirPDLPatternModuleDestroy(MlirPDLPatternModule op) {
537mlirRewritePatternSetFromPDLPatternModule(MlirPDLPatternModule op) {
543MlirValue mlirPDLValueAsValue(MlirPDLValue value) {
544 return wrap(
unwrap(value)->dyn_cast<mlir::Value>());
547MlirType mlirPDLValueAsType(MlirPDLValue value) {
548 return wrap(
unwrap(value)->dyn_cast<mlir::Type>());
551MlirOperation mlirPDLValueAsOperation(MlirPDLValue value) {
552 return wrap(
unwrap(value)->dyn_cast<mlir::Operation *>());
555MlirAttribute mlirPDLValueAsAttribute(MlirPDLValue value) {
556 return wrap(
unwrap(value)->dyn_cast<mlir::Attribute>());
569 MlirOperation value) {
574 MlirAttribute value) {
579 std::vector<MlirPDLValue> mlirValues;
580 mlirValues.reserve(values.size());
581 for (
auto &value : values) {
582 mlirValues.push_back(
wrap(&value));
587void mlirPDLPatternModuleRegisterRewriteFunction(
589 MlirPDLRewriteFunction rewriteFn,
void *userData) {
590 unwrap(pdlModule)->registerRewriteFunction(
592 [userData, rewriteFn](
PatternRewriter &rewriter, PDLResultList &results,
594 std::vector<MlirPDLValue> mlirValues =
wrap(values);
596 mlirValues.size(), mlirValues.data(),
601void mlirPDLPatternModuleRegisterConstraintFunction(
603 MlirPDLConstraintFunction constraintFn,
void *userData) {
604 unwrap(pdlModule)->registerConstraintFunction(
607 PDLResultList &results,
609 std::vector<MlirPDLValue> mlirValues =
wrap(values);
611 mlirValues.size(), mlirValues.data(),
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 allows control over how the GreedyPatternRewriteDriver works.
bool isFoldingEnabled() const
Whether this should fold while greedily rewriting.
GreedyRewriteConfig & setRegionSimplificationLevel(GreedySimplifyRegionLevel level)
bool isConstantCSEEnabled() const
If set to "true", constants are CSE'd (even across multiple regions that are in a parent-ancestor rel...
GreedyRewriteConfig & enableConstantCSE(bool enable=true)
GreedyRewriteStrictness getStrictness() const
Strict mode can restrict the ops that are added to the worklist during the rewrite.
bool getUseTopDownTraversal() const
This specifies the order of initial traversal that populates the rewriters worklist.
GreedyRewriteConfig & enableFolding(bool enable=true)
int64_t getMaxNumRewrites() const
This specifies the maximum number of rewrites within an iteration.
GreedyRewriteConfig & setMaxIterations(int64_t iterations)
GreedyRewriteConfig & setMaxNumRewrites(int64_t limit)
int64_t getMaxIterations() const
This specifies the maximum number of times the rewriter will iterate between applying patterns and si...
GreedyRewriteConfig & setUseTopDownTraversal(bool use=true)
GreedySimplifyRegionLevel getRegionSimplificationLevel() const
Perform control flow optimizations to the region tree after applying all patterns.
GreedyRewriteConfig & setStrictness(GreedyRewriteStrictness mode)
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...
MlirGreedySimplifyRegionLevel
Greedy simplify region levels.
@ MLIR_GREEDY_SIMPLIFY_REGION_LEVEL_DISABLED
Disable region control-flow simplification.
@ MLIR_GREEDY_SIMPLIFY_REGION_LEVEL_NORMAL
Run the normal simplification (e.g. dead args elimination).
@ MLIR_GREEDY_SIMPLIFY_REGION_LEVEL_AGGRESSIVE
Run extra simplifications (e.g. block merging).
MlirGreedyRewriteStrictness
Greedy rewrite strictness levels.
@ MLIR_GREEDY_REWRITE_STRICTNESS_EXISTING_AND_NEW_OPS
Only pre-existing and newly created ops are processed.
@ MLIR_GREEDY_REWRITE_STRICTNESS_EXISTING_OPS
Only pre-existing ops are processed.
@ MLIR_GREEDY_REWRITE_STRICTNESS_ANY_OP
No restrictions wrt. which ops are processed.
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
Include the generated interface declarations.
GreedySimplifyRegionLevel
@ Aggressive
Run extra simplificiations (e.g.
@ Normal
Run the normal simplification (e.g. dead args elimination).
@ Disabled
Disable region control-flow simplification.
const FrozenRewritePatternSet GreedyRewriteConfig config
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)
void walkAndApplyPatterns(Operation *op, const FrozenRewritePatternSet &patterns, RewriterBase::Listener *listener=nullptr)
A fast walk-based pattern rewrite driver.
GreedyRewriteStrictness
This enum controls which ops are put on the worklist during a greedy pattern rewrite.
@ ExistingOps
Only pre-existing ops are processed.
@ ExistingAndNewOps
Only pre-existing and newly created ops are processed.
@ AnyOp
No restrictions wrt. which ops are processed.
A logical result value, essentially a boolean with named states.
A pointer to a sized fragment of a string, not necessarily null-terminated.