MLIR 22.0.0git
Rewrite.cpp
Go to the documentation of this file.
1//===- Rewrite.cpp - C API for Rewrite Patterns ---------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "mlir-c/Rewrite.h"
10
11#include "mlir-c/Transforms.h"
12#include "mlir/CAPI/IR.h"
13#include "mlir/CAPI/Rewrite.h"
14#include "mlir/CAPI/Support.h"
15#include "mlir/CAPI/Wrap.h"
16#include "mlir/IR/Attributes.h"
22
23using namespace mlir;
24
25//===----------------------------------------------------------------------===//
26/// RewriterBase API inherited from OpBuilder
27//===----------------------------------------------------------------------===//
28
29MlirContext mlirRewriterBaseGetContext(MlirRewriterBase rewriter) {
30 return wrap(unwrap(rewriter)->getContext());
31}
32
33//===----------------------------------------------------------------------===//
34/// Insertion points methods
35//===----------------------------------------------------------------------===//
36
37void mlirRewriterBaseClearInsertionPoint(MlirRewriterBase rewriter) {
38 unwrap(rewriter)->clearInsertionPoint();
39}
40
41void mlirRewriterBaseSetInsertionPointBefore(MlirRewriterBase rewriter,
42 MlirOperation op) {
43 unwrap(rewriter)->setInsertionPoint(unwrap(op));
44}
45
46void mlirRewriterBaseSetInsertionPointAfter(MlirRewriterBase rewriter,
47 MlirOperation op) {
48 unwrap(rewriter)->setInsertionPointAfter(unwrap(op));
49}
50
51void mlirRewriterBaseSetInsertionPointAfterValue(MlirRewriterBase rewriter,
52 MlirValue value) {
53 unwrap(rewriter)->setInsertionPointAfterValue(unwrap(value));
54}
55
56void mlirRewriterBaseSetInsertionPointToStart(MlirRewriterBase rewriter,
57 MlirBlock block) {
58 unwrap(rewriter)->setInsertionPointToStart(unwrap(block));
59}
60
61void mlirRewriterBaseSetInsertionPointToEnd(MlirRewriterBase rewriter,
62 MlirBlock block) {
63 unwrap(rewriter)->setInsertionPointToEnd(unwrap(block));
64}
65
66MlirBlock mlirRewriterBaseGetInsertionBlock(MlirRewriterBase rewriter) {
67 return wrap(unwrap(rewriter)->getInsertionBlock());
68}
69
70MlirBlock mlirRewriterBaseGetBlock(MlirRewriterBase rewriter) {
71 return wrap(unwrap(rewriter)->getBlock());
72}
73
74MlirOperation
76 mlir::RewriterBase *base = unwrap(rewriter);
77 mlir::Block *block = base->getInsertionBlock();
79 if (it == block->end())
80 return {nullptr};
81
82 return wrap(std::addressof(*it));
83}
84
85//===----------------------------------------------------------------------===//
86/// Block and operation creation/insertion/cloning
87//===----------------------------------------------------------------------===//
88
89MlirBlock mlirRewriterBaseCreateBlockBefore(MlirRewriterBase rewriter,
90 MlirBlock insertBefore,
91 intptr_t nArgTypes,
92 MlirType const *argTypes,
93 MlirLocation const *locations) {
95 ArrayRef<Type> unwrappedArgs = unwrapList(nArgTypes, argTypes, args);
97 ArrayRef<Location> unwrappedLocs = unwrapList(nArgTypes, locations, locs);
98 return wrap(unwrap(rewriter)->createBlock(unwrap(insertBefore), unwrappedArgs,
99 unwrappedLocs));
100}
101
102MlirOperation mlirRewriterBaseInsert(MlirRewriterBase rewriter,
103 MlirOperation op) {
104 return wrap(unwrap(rewriter)->insert(unwrap(op)));
105}
106
107// Other methods of OpBuilder
108
109MlirOperation mlirRewriterBaseClone(MlirRewriterBase rewriter,
110 MlirOperation op) {
111 return wrap(unwrap(rewriter)->clone(*unwrap(op)));
112}
113
114MlirOperation mlirRewriterBaseCloneWithoutRegions(MlirRewriterBase rewriter,
115 MlirOperation op) {
116 return wrap(unwrap(rewriter)->cloneWithoutRegions(*unwrap(op)));
117}
118
119void mlirRewriterBaseCloneRegionBefore(MlirRewriterBase rewriter,
120 MlirRegion region, MlirBlock before) {
121
122 unwrap(rewriter)->cloneRegionBefore(*unwrap(region), unwrap(before));
123}
124
125//===----------------------------------------------------------------------===//
126/// RewriterBase API
127//===----------------------------------------------------------------------===//
128
129void mlirRewriterBaseInlineRegionBefore(MlirRewriterBase rewriter,
130 MlirRegion region, MlirBlock before) {
131 unwrap(rewriter)->inlineRegionBefore(*unwrap(region), unwrap(before));
132}
133
134void mlirRewriterBaseReplaceOpWithValues(MlirRewriterBase rewriter,
135 MlirOperation op, intptr_t nValues,
136 MlirValue const *values) {
138 ArrayRef<Value> unwrappedVals = unwrapList(nValues, values, vals);
139 unwrap(rewriter)->replaceOp(unwrap(op), unwrappedVals);
140}
141
142void mlirRewriterBaseReplaceOpWithOperation(MlirRewriterBase rewriter,
143 MlirOperation op,
144 MlirOperation newOp) {
145 unwrap(rewriter)->replaceOp(unwrap(op), unwrap(newOp));
146}
147
148void mlirRewriterBaseEraseOp(MlirRewriterBase rewriter, MlirOperation op) {
149 unwrap(rewriter)->eraseOp(unwrap(op));
150}
151
152void mlirRewriterBaseEraseBlock(MlirRewriterBase rewriter, MlirBlock block) {
153 unwrap(rewriter)->eraseBlock(unwrap(block));
154}
155
156void mlirRewriterBaseInlineBlockBefore(MlirRewriterBase rewriter,
157 MlirBlock source, MlirOperation op,
158 intptr_t nArgValues,
159 MlirValue const *argValues) {
161 ArrayRef<Value> unwrappedVals = unwrapList(nArgValues, argValues, vals);
162
163 unwrap(rewriter)->inlineBlockBefore(unwrap(source), unwrap(op),
164 unwrappedVals);
165}
166
167void mlirRewriterBaseMergeBlocks(MlirRewriterBase rewriter, MlirBlock source,
168 MlirBlock dest, intptr_t nArgValues,
169 MlirValue const *argValues) {
171 ArrayRef<Value> unwrappedArgs = unwrapList(nArgValues, argValues, args);
172 unwrap(rewriter)->mergeBlocks(unwrap(source), unwrap(dest), unwrappedArgs);
173}
174
175void mlirRewriterBaseMoveOpBefore(MlirRewriterBase rewriter, MlirOperation op,
176 MlirOperation existingOp) {
177 unwrap(rewriter)->moveOpBefore(unwrap(op), unwrap(existingOp));
178}
179
180void mlirRewriterBaseMoveOpAfter(MlirRewriterBase rewriter, MlirOperation op,
181 MlirOperation existingOp) {
182 unwrap(rewriter)->moveOpAfter(unwrap(op), unwrap(existingOp));
183}
184
185void mlirRewriterBaseMoveBlockBefore(MlirRewriterBase rewriter, MlirBlock block,
186 MlirBlock existingBlock) {
187 unwrap(rewriter)->moveBlockBefore(unwrap(block), unwrap(existingBlock));
188}
189
190void mlirRewriterBaseStartOpModification(MlirRewriterBase rewriter,
191 MlirOperation op) {
192 unwrap(rewriter)->startOpModification(unwrap(op));
193}
194
195void mlirRewriterBaseFinalizeOpModification(MlirRewriterBase rewriter,
196 MlirOperation op) {
197 unwrap(rewriter)->finalizeOpModification(unwrap(op));
198}
199
200void mlirRewriterBaseCancelOpModification(MlirRewriterBase rewriter,
201 MlirOperation op) {
202 unwrap(rewriter)->cancelOpModification(unwrap(op));
203}
204
205void mlirRewriterBaseReplaceAllUsesWith(MlirRewriterBase rewriter,
206 MlirValue from, MlirValue to) {
207 unwrap(rewriter)->replaceAllUsesWith(unwrap(from), unwrap(to));
208}
209
210void mlirRewriterBaseReplaceAllValueRangeUsesWith(MlirRewriterBase rewriter,
211 intptr_t nValues,
212 MlirValue const *from,
213 MlirValue const *to) {
214 SmallVector<Value, 4> fromVals;
215 ArrayRef<Value> unwrappedFromVals = unwrapList(nValues, from, fromVals);
217 ArrayRef<Value> unwrappedToVals = unwrapList(nValues, to, toVals);
218 unwrap(rewriter)->replaceAllUsesWith(unwrappedFromVals, unwrappedToVals);
219}
220
222 MlirOperation from,
223 intptr_t nTo,
224 MlirValue const *to) {
226 ArrayRef<Value> unwrappedToVals = unwrapList(nTo, to, toVals);
227 unwrap(rewriter)->replaceAllOpUsesWith(unwrap(from), unwrappedToVals);
228}
229
231 MlirOperation from,
232 MlirOperation to) {
233 unwrap(rewriter)->replaceAllOpUsesWith(unwrap(from), unwrap(to));
234}
235
236void mlirRewriterBaseReplaceOpUsesWithinBlock(MlirRewriterBase rewriter,
237 MlirOperation op,
238 intptr_t nNewValues,
239 MlirValue const *newValues,
240 MlirBlock block) {
242 ArrayRef<Value> unwrappedVals = unwrapList(nNewValues, newValues, vals);
243 unwrap(rewriter)->replaceOpUsesWithinBlock(unwrap(op), unwrappedVals,
244 unwrap(block));
245}
246
247void mlirRewriterBaseReplaceAllUsesExcept(MlirRewriterBase rewriter,
248 MlirValue from, MlirValue to,
249 MlirOperation exceptedUser) {
250 unwrap(rewriter)->replaceAllUsesExcept(unwrap(from), unwrap(to),
251 unwrap(exceptedUser));
252}
253
254//===----------------------------------------------------------------------===//
255/// IRRewriter API
256//===----------------------------------------------------------------------===//
257
258MlirRewriterBase mlirIRRewriterCreate(MlirContext context) {
259 return wrap(new IRRewriter(unwrap(context)));
260}
261
262MlirRewriterBase mlirIRRewriterCreateFromOp(MlirOperation op) {
263 return wrap(new IRRewriter(unwrap(op)));
264}
265
266void mlirIRRewriterDestroy(MlirRewriterBase rewriter) {
267 delete static_cast<IRRewriter *>(unwrap(rewriter));
268}
269
270//===----------------------------------------------------------------------===//
271/// RewritePatternSet and FrozenRewritePatternSet API
272//===----------------------------------------------------------------------===//
273
274MlirFrozenRewritePatternSet
275mlirFreezeRewritePattern(MlirRewritePatternSet set) {
276 auto *m = new mlir::FrozenRewritePatternSet(std::move(*unwrap(set)));
277 set.ptr = nullptr;
278 return wrap(m);
279}
280
281void mlirFrozenRewritePatternSetDestroy(MlirFrozenRewritePatternSet set) {
282 delete unwrap(set);
283 set.ptr = nullptr;
284}
285
288 MlirFrozenRewritePatternSet patterns,
289 MlirGreedyRewriteDriverConfig) {
291}
292
295 MlirFrozenRewritePatternSet patterns,
296 MlirGreedyRewriteDriverConfig) {
298}
299
300void mlirWalkAndApplyPatterns(MlirOperation op,
301 MlirFrozenRewritePatternSet patterns) {
303}
304
305//===----------------------------------------------------------------------===//
306/// PatternRewriter API
307//===----------------------------------------------------------------------===//
308
309MlirRewriterBase mlirPatternRewriterAsBase(MlirPatternRewriter rewriter) {
310 return wrap(static_cast<mlir::RewriterBase *>(unwrap(rewriter)));
311}
312
313//===----------------------------------------------------------------------===//
314/// RewritePattern API
315//===----------------------------------------------------------------------===//
316
317namespace mlir {
318
320public:
322 StringRef rootName, PatternBenefit benefit,
323 MLIRContext *context,
324 ArrayRef<StringRef> generatedNames)
325 : RewritePattern(rootName, benefit, context, generatedNames),
326 callbacks(callbacks), userData(userData) {
327 if (callbacks.construct)
328 callbacks.construct(userData);
329 }
330
332 if (callbacks.destruct)
333 callbacks.destruct(userData);
334 }
335
336 LogicalResult matchAndRewrite(Operation *op,
337 PatternRewriter &rewriter) const override {
338 return unwrap(callbacks.matchAndRewrite(
339 wrap(static_cast<const mlir::RewritePattern *>(this)), wrap(op),
340 wrap(&rewriter), userData));
341 }
342
343private:
345 void *userData;
346};
347
348} // namespace mlir
349
350MlirRewritePattern mlirOpRewritePatternCreate(
351 MlirStringRef rootName, unsigned benefit, MlirContext context,
352 MlirRewritePatternCallbacks callbacks, void *userData,
353 size_t nGeneratedNames, MlirStringRef *generatedNames) {
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]));
358 }
360 callbacks, userData, unwrap(rootName), PatternBenefit(benefit),
361 unwrap(context), generatedNamesVec));
362}
363
364//===----------------------------------------------------------------------===//
365/// RewritePatternSet API
366//===----------------------------------------------------------------------===//
367
368MlirRewritePatternSet mlirRewritePatternSetCreate(MlirContext context) {
369 return wrap(new mlir::RewritePatternSet(unwrap(context)));
370}
371
372void mlirRewritePatternSetDestroy(MlirRewritePatternSet set) {
373 delete unwrap(set);
374}
375
376void mlirRewritePatternSetAdd(MlirRewritePatternSet set,
377 MlirRewritePattern pattern) {
378 std::unique_ptr<mlir::RewritePattern> patternPtr(
379 const_cast<mlir::RewritePattern *>(unwrap(pattern)));
380 pattern.ptr = nullptr;
381 unwrap(set)->add(std::move(patternPtr));
382}
383
384//===----------------------------------------------------------------------===//
385/// PDLPatternModule API
386//===----------------------------------------------------------------------===//
387
388#if MLIR_ENABLE_PDL_IN_PATTERNMATCH
389MlirPDLPatternModule mlirPDLPatternModuleFromModule(MlirModule op) {
390 return wrap(new mlir::PDLPatternModule(
392}
393
394void mlirPDLPatternModuleDestroy(MlirPDLPatternModule op) {
395 delete unwrap(op);
396 op.ptr = nullptr;
397}
398
399MlirRewritePatternSet
400mlirRewritePatternSetFromPDLPatternModule(MlirPDLPatternModule op) {
401 auto *m = new mlir::RewritePatternSet(std::move(*unwrap(op)));
402 op.ptr = nullptr;
403 return wrap(m);
404}
405
406MlirValue mlirPDLValueAsValue(MlirPDLValue value) {
407 return wrap(unwrap(value)->dyn_cast<mlir::Value>());
408}
409
410MlirType mlirPDLValueAsType(MlirPDLValue value) {
411 return wrap(unwrap(value)->dyn_cast<mlir::Type>());
412}
413
414MlirOperation mlirPDLValueAsOperation(MlirPDLValue value) {
415 return wrap(unwrap(value)->dyn_cast<mlir::Operation *>());
416}
417
418MlirAttribute mlirPDLValueAsAttribute(MlirPDLValue value) {
419 return wrap(unwrap(value)->dyn_cast<mlir::Attribute>());
420}
421
422void mlirPDLResultListPushBackValue(MlirPDLResultList results,
423 MlirValue value) {
424 unwrap(results)->push_back(unwrap(value));
425}
426
427void mlirPDLResultListPushBackType(MlirPDLResultList results, MlirType value) {
428 unwrap(results)->push_back(unwrap(value));
429}
430
431void mlirPDLResultListPushBackOperation(MlirPDLResultList results,
432 MlirOperation value) {
433 unwrap(results)->push_back(unwrap(value));
434}
435
436void mlirPDLResultListPushBackAttribute(MlirPDLResultList results,
437 MlirAttribute value) {
438 unwrap(results)->push_back(unwrap(value));
439}
440
441inline std::vector<MlirPDLValue> wrap(ArrayRef<PDLValue> values) {
442 std::vector<MlirPDLValue> mlirValues;
443 mlirValues.reserve(values.size());
444 for (auto &value : values) {
445 mlirValues.push_back(wrap(&value));
446 }
447 return mlirValues;
448}
449
450void mlirPDLPatternModuleRegisterRewriteFunction(
451 MlirPDLPatternModule pdlModule, MlirStringRef name,
452 MlirPDLRewriteFunction rewriteFn, void *userData) {
453 unwrap(pdlModule)->registerRewriteFunction(
454 unwrap(name),
455 [userData, rewriteFn](PatternRewriter &rewriter, PDLResultList &results,
456 ArrayRef<PDLValue> values) -> LogicalResult {
457 std::vector<MlirPDLValue> mlirValues = wrap(values);
458 return unwrap(rewriteFn(wrap(&rewriter), wrap(&results),
459 mlirValues.size(), mlirValues.data(),
460 userData));
461 });
462}
463
464void mlirPDLPatternModuleRegisterConstraintFunction(
465 MlirPDLPatternModule pdlModule, MlirStringRef name,
466 MlirPDLConstraintFunction constraintFn, void *userData) {
467 unwrap(pdlModule)->registerConstraintFunction(
468 unwrap(name),
469 [userData, constraintFn](PatternRewriter &rewriter,
470 PDLResultList &results,
471 ArrayRef<PDLValue> values) -> LogicalResult {
472 std::vector<MlirPDLValue> mlirValues = wrap(values);
473 return unwrap(constraintFn(wrap(&rewriter), wrap(&results),
474 mlirValues.size(), mlirValues.data(),
475 userData));
476 });
477}
478#endif // MLIR_ENABLE_PDL_IN_PATTERNMATCH
void mlirRewriterBaseReplaceOpUsesWithinBlock(MlirRewriterBase rewriter, MlirOperation op, intptr_t nNewValues, MlirValue const *newValues, MlirBlock block)
Find uses of from within block and replace them with to.
Definition Rewrite.cpp:236
MlirRewritePatternSet mlirRewritePatternSetCreate(MlirContext context)
RewritePatternSet API.
Definition Rewrite.cpp:368
void mlirRewriterBaseMergeBlocks(MlirRewriterBase rewriter, MlirBlock source, MlirBlock dest, intptr_t nArgValues, MlirValue const *argValues)
Inline the operations of block 'source' into the end of block 'dest'.
Definition Rewrite.cpp:167
void mlirIRRewriterDestroy(MlirRewriterBase rewriter)
Takes an IRRewriter owned by the caller and destroys it.
Definition Rewrite.cpp:266
void mlirRewriterBaseStartOpModification(MlirRewriterBase rewriter, MlirOperation op)
This method is used to notify the rewriter that an in-place operation modification is about to happen...
Definition Rewrite.cpp:190
MlirOperation mlirRewriterBaseInsert(MlirRewriterBase rewriter, MlirOperation op)
Insert the given operation at the current insertion point and return it.
Definition Rewrite.cpp:102
MlirRewriterBase mlirIRRewriterCreate(MlirContext context)
IRRewriter API.
Definition Rewrite.cpp:258
void mlirRewriterBaseMoveOpAfter(MlirRewriterBase rewriter, MlirOperation op, MlirOperation existingOp)
Unlink this operation from its current block and insert it right after existingOp which may be in the...
Definition Rewrite.cpp:180
void mlirRewriterBaseCloneRegionBefore(MlirRewriterBase rewriter, MlirRegion region, MlirBlock before)
Clone the blocks that belong to "region" before the given position in another region "parent".
Definition Rewrite.cpp:119
void mlirRewriterBaseSetInsertionPointAfter(MlirRewriterBase rewriter, MlirOperation op)
Sets the insertion point to the node after the specified operation, which will cause subsequent inser...
Definition Rewrite.cpp:46
MlirLogicalResult mlirApplyPatternsAndFoldGreedilyWithOp(MlirOperation op, MlirFrozenRewritePatternSet patterns, MlirGreedyRewriteDriverConfig)
Definition Rewrite.cpp:294
void mlirFrozenRewritePatternSetDestroy(MlirFrozenRewritePatternSet set)
Destroy the given MlirFrozenRewritePatternSet.
Definition Rewrite.cpp:281
void mlirRewriterBaseReplaceAllOpUsesWithOperation(MlirRewriterBase rewriter, MlirOperation from, MlirOperation to)
Find uses of from and replace them with to.
Definition Rewrite.cpp:230
void mlirRewriterBaseMoveBlockBefore(MlirRewriterBase rewriter, MlirBlock block, MlirBlock existingBlock)
Unlink this block and insert it right before existingBlock.
Definition Rewrite.cpp:185
void mlirRewriterBaseReplaceAllValueRangeUsesWith(MlirRewriterBase rewriter, intptr_t nValues, MlirValue const *from, MlirValue const *to)
Find uses of from and replace them with to.
Definition Rewrite.cpp:210
void mlirRewriterBaseEraseBlock(MlirRewriterBase rewriter, MlirBlock block)
Erases a block along with all operations inside it.
Definition Rewrite.cpp:152
void mlirRewriterBaseReplaceAllUsesExcept(MlirRewriterBase rewriter, MlirValue from, MlirValue to, MlirOperation exceptedUser)
Find uses of from and replace them with to except if the user is exceptedUser.
Definition Rewrite.cpp:247
MlirBlock mlirRewriterBaseCreateBlockBefore(MlirRewriterBase rewriter, MlirBlock insertBefore, intptr_t nArgTypes, MlirType const *argTypes, MlirLocation const *locations)
Block and operation creation/insertion/cloning.
Definition Rewrite.cpp:89
MlirLogicalResult mlirApplyPatternsAndFoldGreedily(MlirModule op, MlirFrozenRewritePatternSet patterns, MlirGreedyRewriteDriverConfig)
Definition Rewrite.cpp:287
void mlirRewriterBaseSetInsertionPointToStart(MlirRewriterBase rewriter, MlirBlock block)
Sets the insertion point to the start of the specified block.
Definition Rewrite.cpp:56
MlirRewriterBase mlirPatternRewriterAsBase(MlirPatternRewriter rewriter)
PatternRewriter API.
Definition Rewrite.cpp:309
MlirRewritePattern mlirOpRewritePatternCreate(MlirStringRef rootName, unsigned benefit, MlirContext context, MlirRewritePatternCallbacks callbacks, void *userData, size_t nGeneratedNames, MlirStringRef *generatedNames)
Create a rewrite pattern that matches the operation with the given rootName, corresponding to mlir::O...
Definition Rewrite.cpp:350
MlirContext mlirRewriterBaseGetContext(MlirRewriterBase rewriter)
RewriterBase API inherited from OpBuilder.
Definition Rewrite.cpp:29
void mlirRewriterBaseReplaceAllOpUsesWithValueRange(MlirRewriterBase rewriter, MlirOperation from, intptr_t nTo, MlirValue const *to)
Find uses of from and replace them with to.
Definition Rewrite.cpp:221
MlirOperation mlirRewriterBaseClone(MlirRewriterBase rewriter, MlirOperation op)
Creates a deep copy of the specified operation.
Definition Rewrite.cpp:109
void mlirRewriterBaseInlineBlockBefore(MlirRewriterBase rewriter, MlirBlock source, MlirOperation op, intptr_t nArgValues, MlirValue const *argValues)
Inline the operations of block 'source' before the operation 'op'.
Definition Rewrite.cpp:156
void mlirRewriterBaseReplaceOpWithValues(MlirRewriterBase rewriter, MlirOperation op, intptr_t nValues, MlirValue const *values)
Replace the results of the given (original) operation with the specified list of values (replacements...
Definition Rewrite.cpp:134
void mlirRewriterBaseCancelOpModification(MlirRewriterBase rewriter, MlirOperation op)
This method cancels a pending in-place modification.
Definition Rewrite.cpp:200
void mlirRewriterBaseSetInsertionPointAfterValue(MlirRewriterBase rewriter, MlirValue value)
Sets the insertion point to the node after the specified value.
Definition Rewrite.cpp:51
void mlirRewriterBaseSetInsertionPointToEnd(MlirRewriterBase rewriter, MlirBlock block)
Sets the insertion point to the end of the specified block.
Definition Rewrite.cpp:61
MlirOperation mlirRewriterBaseCloneWithoutRegions(MlirRewriterBase rewriter, MlirOperation op)
Creates a deep copy of this operation but keep the operation regions empty.
Definition Rewrite.cpp:114
void mlirRewritePatternSetDestroy(MlirRewritePatternSet set)
Destruct the given MlirRewritePatternSet.
Definition Rewrite.cpp:372
MlirBlock mlirRewriterBaseGetBlock(MlirRewriterBase rewriter)
Returns the current block of the rewriter.
Definition Rewrite.cpp:70
MlirOperation mlirRewriterBaseGetOperationAfterInsertion(MlirRewriterBase rewriter)
Returns the operation right after the current insertion point of the rewriter.
Definition Rewrite.cpp:75
void mlirRewriterBaseClearInsertionPoint(MlirRewriterBase rewriter)
Insertion points methods.
Definition Rewrite.cpp:37
MlirFrozenRewritePatternSet mlirFreezeRewritePattern(MlirRewritePatternSet set)
RewritePatternSet and FrozenRewritePatternSet API.
Definition Rewrite.cpp:275
void mlirRewriterBaseInlineRegionBefore(MlirRewriterBase rewriter, MlirRegion region, MlirBlock before)
RewriterBase API.
Definition Rewrite.cpp:129
void mlirRewriterBaseReplaceOpWithOperation(MlirRewriterBase rewriter, MlirOperation op, MlirOperation newOp)
Replace the results of the given (original) operation with the specified new op (replacement).
Definition Rewrite.cpp:142
void mlirRewriterBaseReplaceAllUsesWith(MlirRewriterBase rewriter, MlirValue from, MlirValue to)
Find uses of from and replace them with to.
Definition Rewrite.cpp:205
void mlirRewriterBaseFinalizeOpModification(MlirRewriterBase rewriter, MlirOperation op)
This method is used to signal the end of an in-place modification of the given operation.
Definition Rewrite.cpp:195
void mlirRewritePatternSetAdd(MlirRewritePatternSet set, MlirRewritePattern pattern)
Add the given MlirRewritePattern into a MlirRewritePatternSet.
Definition Rewrite.cpp:376
void mlirWalkAndApplyPatterns(MlirOperation op, MlirFrozenRewritePatternSet patterns)
Applies the given patterns to the given op by a fast walk-based pattern rewrite driver.
Definition Rewrite.cpp:300
MlirRewriterBase mlirIRRewriterCreateFromOp(MlirOperation op)
Create an IRRewriter and transfer ownership to the caller.
Definition Rewrite.cpp:262
void mlirRewriterBaseMoveOpBefore(MlirRewriterBase rewriter, MlirOperation op, MlirOperation existingOp)
Unlink this operation from its current block and insert it right before existingOp which may be in th...
Definition Rewrite.cpp:175
void mlirRewriterBaseSetInsertionPointBefore(MlirRewriterBase rewriter, MlirOperation op)
Sets the insertion point to the specified operation, which will cause subsequent insertions to go rig...
Definition Rewrite.cpp:41
MlirBlock mlirRewriterBaseGetInsertionBlock(MlirRewriterBase rewriter)
Return the block the current insertion point belongs to.
Definition Rewrite.cpp:66
void mlirRewriterBaseEraseOp(MlirRewriterBase rewriter, MlirOperation op)
Erases an operation that is known to have no uses.
Definition Rewrite.cpp:148
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.
Definition IRCore.cpp:91
b getContext())
static llvm::ArrayRef< CppTy > unwrapList(size_t size, CTy *first, llvm::SmallVectorImpl< CppTy > &storage)
Definition Wrap.h:40
Block represents an ordered list of Operations.
Definition Block.h:33
OpListType::iterator iterator
Definition Block.h:140
iterator end()
Definition Block.h:144
ExternalRewritePattern(MlirRewritePatternCallbacks callbacks, void *userData, StringRef rootName, PatternBenefit benefit, MLIRContext *context, ArrayRef< StringRef > generatedNames)
Definition Rewrite.cpp:321
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 ...
Definition Rewrite.cpp:336
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.
Definition MLIRContext.h:63
Block::iterator getInsertionPoint() const
Returns the current insertion point of the builder.
Definition Builders.h:445
Block * getInsertionBlock() const
Return the block the current insertion point belongs to.
Definition Builders.h:442
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
This class acts as an owning reference to an op, and will automatically destroy the held op on destru...
Definition OwningOpRef.h:29
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)
Definition Diagnostics.h:24
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
Definition Diagnostics.h:19
Include the generated interface declarations.
LogicalResult applyPatternsGreedily(Region &region, 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.
Definition Support.h:116
RewritePattern API.
Definition Rewrite.h:343
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition Support.h:73