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) {
120 MlirRegion region, MlirBlock before) {
130 MlirRegion region, MlirBlock before) {
135 MlirOperation op, intptr_t nValues,
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
288 MlirFrozenRewritePatternSet
patterns,
289 MlirGreedyRewriteDriverConfig) {
295 MlirFrozenRewritePatternSet
patterns,
296 MlirGreedyRewriteDriverConfig) {
301 MlirFrozenRewritePatternSet
patterns) {
326 callbacks(callbacks), userData(userData) {
327 if (callbacks.construct)
328 callbacks.construct(userData);
332 if (callbacks.destruct)
333 callbacks.destruct(userData);
338 return unwrap(callbacks.matchAndRewrite(
340 wrap(&rewriter), userData));
351 MlirStringRef rootName,
unsigned benefit, MlirContext context,
354 std::vector<mlir::StringRef> generatedNamesVec;
355 generatedNamesVec.reserve(nGeneratedNames);
356 for (
size_t i = 0; i < nGeneratedNames; ++i) {
357 generatedNamesVec.push_back(
unwrap(generatedNames[i]));
361 unwrap(context), generatedNamesVec));
377 MlirRewritePattern pattern) {
378 std::unique_ptr<mlir::RewritePattern> patternPtr(
380 pattern.ptr =
nullptr;
381 unwrap(set)->add(std::move(patternPtr));
388#if MLIR_ENABLE_PDL_IN_PATTERNMATCH
389MlirPDLPatternModule mlirPDLPatternModuleFromModule(MlirModule op) {
390 return wrap(
new mlir::PDLPatternModule(
394void mlirPDLPatternModuleDestroy(MlirPDLPatternModule op) {
400mlirRewritePatternSetFromPDLPatternModule(MlirPDLPatternModule op) {
406MlirValue mlirPDLValueAsValue(MlirPDLValue value) {
407 return wrap(
unwrap(value)->dyn_cast<mlir::Value>());
410MlirType mlirPDLValueAsType(MlirPDLValue value) {
411 return wrap(
unwrap(value)->dyn_cast<mlir::Type>());
414MlirOperation mlirPDLValueAsOperation(MlirPDLValue value) {
415 return wrap(
unwrap(value)->dyn_cast<mlir::Operation *>());
418MlirAttribute mlirPDLValueAsAttribute(MlirPDLValue value) {
419 return wrap(
unwrap(value)->dyn_cast<mlir::Attribute>());
422void mlirPDLResultListPushBackValue(MlirPDLResultList results,
427void mlirPDLResultListPushBackType(MlirPDLResultList results, MlirType value) {
431void mlirPDLResultListPushBackOperation(MlirPDLResultList results,
432 MlirOperation value) {
436void mlirPDLResultListPushBackAttribute(MlirPDLResultList results,
437 MlirAttribute value) {
442 std::vector<MlirPDLValue> mlirValues;
443 mlirValues.reserve(values.size());
444 for (
auto &value : values) {
445 mlirValues.push_back(
wrap(&value));
450void mlirPDLPatternModuleRegisterRewriteFunction(
452 MlirPDLRewriteFunction rewriteFn,
void *userData) {
453 unwrap(pdlModule)->registerRewriteFunction(
455 [userData, rewriteFn](
PatternRewriter &rewriter, PDLResultList &results,
457 std::vector<MlirPDLValue> mlirValues =
wrap(values);
459 mlirValues.size(), mlirValues.data(),
464void mlirPDLPatternModuleRegisterConstraintFunction(
466 MlirPDLConstraintFunction constraintFn,
void *userData) {
467 unwrap(pdlModule)->registerConstraintFunction(
470 PDLResultList &results,
472 std::vector<MlirPDLValue> mlirValues =
wrap(values);
474 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 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...
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
mlir::Diagnostic & unwrap(MlirDiagnostic 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)
void walkAndApplyPatterns(Operation *op, const FrozenRewritePatternSet &patterns, RewriterBase::Listener *listener=nullptr)
A fast walk-based pattern rewrite driver.
A logical result value, essentially a boolean with named states.
A pointer to a sized fragment of a string, not necessarily null-terminated.