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) {
273MlirFrozenRewritePatternSet
287 MlirFrozenRewritePatternSet
patterns,
288 MlirGreedyRewriteDriverConfig) {
294 MlirFrozenRewritePatternSet
patterns,
295 MlirGreedyRewriteDriverConfig) {
320 callbacks(callbacks), userData(userData) {
321 if (callbacks.construct)
322 callbacks.construct(userData);
326 if (callbacks.destruct)
327 callbacks.destruct(userData);
332 return unwrap(callbacks.matchAndRewrite(
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
383MlirPDLPatternModule mlirPDLPatternModuleFromModule(MlirModule op) {
384 return wrap(
new mlir::PDLPatternModule(
388void mlirPDLPatternModuleDestroy(MlirPDLPatternModule op) {
394mlirRewritePatternSetFromPDLPatternModule(MlirPDLPatternModule op) {
400MlirValue mlirPDLValueAsValue(MlirPDLValue value) {
401 return wrap(
unwrap(value)->dyn_cast<mlir::Value>());
404MlirType mlirPDLValueAsType(MlirPDLValue value) {
405 return wrap(
unwrap(value)->dyn_cast<mlir::Type>());
408MlirOperation mlirPDLValueAsOperation(MlirPDLValue value) {
409 return wrap(
unwrap(value)->dyn_cast<mlir::Operation *>());
412MlirAttribute mlirPDLValueAsAttribute(MlirPDLValue value) {
413 return wrap(
unwrap(value)->dyn_cast<mlir::Attribute>());
416void mlirPDLResultListPushBackValue(MlirPDLResultList results,
421void mlirPDLResultListPushBackType(MlirPDLResultList results, MlirType value) {
425void mlirPDLResultListPushBackOperation(MlirPDLResultList results,
426 MlirOperation value) {
430void mlirPDLResultListPushBackAttribute(MlirPDLResultList results,
431 MlirAttribute value) {
436 std::vector<MlirPDLValue> mlirValues;
437 mlirValues.reserve(values.size());
438 for (
auto &value : values) {
439 mlirValues.push_back(
wrap(&value));
444void mlirPDLPatternModuleRegisterRewriteFunction(
446 MlirPDLRewriteFunction rewriteFn,
void *userData) {
447 unwrap(pdlModule)->registerRewriteFunction(
449 [userData, rewriteFn](
PatternRewriter &rewriter, PDLResultList &results,
451 std::vector<MlirPDLValue> mlirValues =
wrap(values);
453 mlirValues.size(), mlirValues.data(),
458void mlirPDLPatternModuleRegisterConstraintFunction(
460 MlirPDLConstraintFunction constraintFn,
void *userData) {
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 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)
A logical result value, essentially a boolean with named states.
A pointer to a sized fragment of a string, not necessarily null-terminated.