MLIR 22.0.0git
Rewrite.h
Go to the documentation of this file.
1//===-- mlir-c/Rewrite.h - Helpers for C API to Rewrites ----------*- C -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM
4// Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9//
10// This header declares the registration and creation method for
11// rewrite patterns.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef MLIR_C_REWRITE_H
16#define MLIR_C_REWRITE_H
17
18#include "mlir-c/IR.h"
19#include "mlir-c/Support.h"
20#include "mlir/Config/mlir-config.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26//===----------------------------------------------------------------------===//
27/// Opaque type declarations (see mlir-c/IR.h for more details).
28//===----------------------------------------------------------------------===//
29
30#define DEFINE_C_API_STRUCT(name, storage) \
31 struct name { \
32 storage *ptr; \
33 }; \
34 typedef struct name name
35
36DEFINE_C_API_STRUCT(MlirRewriterBase, void);
37DEFINE_C_API_STRUCT(MlirFrozenRewritePatternSet, void);
38DEFINE_C_API_STRUCT(MlirGreedyRewriteDriverConfig, void);
39DEFINE_C_API_STRUCT(MlirRewritePatternSet, void);
40DEFINE_C_API_STRUCT(MlirPatternRewriter, void);
41DEFINE_C_API_STRUCT(MlirRewritePattern, const void);
42
43//===----------------------------------------------------------------------===//
44/// RewriterBase API inherited from OpBuilder
45//===----------------------------------------------------------------------===//
46
47/// Get the MLIR context referenced by the rewriter.
48MLIR_CAPI_EXPORTED MlirContext
49mlirRewriterBaseGetContext(MlirRewriterBase rewriter);
50
51//===----------------------------------------------------------------------===//
52/// Insertion points methods
53//===----------------------------------------------------------------------===//
54
55// These do not include functions using Block::iterator or Region::iterator, as
56// they are not exposed by the C API yet. Similarly for methods using
57// `InsertPoint` directly.
58
59/// Reset the insertion point to no location. Creating an operation without a
60/// set insertion point is an error, but this can still be useful when the
61/// current insertion point a builder refers to is being removed.
63mlirRewriterBaseClearInsertionPoint(MlirRewriterBase rewriter);
64
65/// Sets the insertion point to the specified operation, which will cause
66/// subsequent insertions to go right before it.
68mlirRewriterBaseSetInsertionPointBefore(MlirRewriterBase rewriter,
69 MlirOperation op);
70
71/// Sets the insertion point to the node after the specified operation, which
72/// will cause subsequent insertions to go right after it.
74mlirRewriterBaseSetInsertionPointAfter(MlirRewriterBase rewriter,
75 MlirOperation op);
76
77/// Sets the insertion point to the node after the specified value. If value
78/// has a defining operation, sets the insertion point to the node after such
79/// defining operation. This will cause subsequent insertions to go right
80/// after it. Otherwise, value is a BlockArgument. Sets the insertion point to
81/// the start of its block.
83mlirRewriterBaseSetInsertionPointAfterValue(MlirRewriterBase rewriter,
84 MlirValue value);
85
86/// Sets the insertion point to the start of the specified block.
88mlirRewriterBaseSetInsertionPointToStart(MlirRewriterBase rewriter,
89 MlirBlock block);
90
91/// Sets the insertion point to the end of the specified block.
93mlirRewriterBaseSetInsertionPointToEnd(MlirRewriterBase rewriter,
94 MlirBlock block);
95
96/// Return the block the current insertion point belongs to. Note that the
97/// insertion point is not necessarily the end of the block.
98MLIR_CAPI_EXPORTED MlirBlock
99mlirRewriterBaseGetInsertionBlock(MlirRewriterBase rewriter);
100
101/// Returns the current block of the rewriter.
102MLIR_CAPI_EXPORTED MlirBlock
103mlirRewriterBaseGetBlock(MlirRewriterBase rewriter);
104
105/// Returns the operation right after the current insertion point
106/// of the rewriter. A null MlirOperation will be returned
107// if the current insertion point is at the end of the block.
108MLIR_CAPI_EXPORTED MlirOperation
109mlirRewriterBaseGetOperationAfterInsertion(MlirRewriterBase rewriter);
110
111//===----------------------------------------------------------------------===//
112/// Block and operation creation/insertion/cloning
113//===----------------------------------------------------------------------===//
114
115// These functions do not include the IRMapper, as it is not yet exposed by the
116// C API.
117
118/// Add new block with 'argTypes' arguments and set the insertion point to the
119/// end of it. The block is placed before 'insertBefore'. `locs` contains the
120/// locations of the inserted arguments, and should match the size of
121/// `argTypes`.
123 MlirRewriterBase rewriter, MlirBlock insertBefore, intptr_t nArgTypes,
124 MlirType const *argTypes, MlirLocation const *locations);
125
126/// Insert the given operation at the current insertion point and return it.
127MLIR_CAPI_EXPORTED MlirOperation
128mlirRewriterBaseInsert(MlirRewriterBase rewriter, MlirOperation op);
129
130/// Creates a deep copy of the specified operation.
131MLIR_CAPI_EXPORTED MlirOperation
132mlirRewriterBaseClone(MlirRewriterBase rewriter, MlirOperation op);
133
134/// Creates a deep copy of this operation but keep the operation regions
135/// empty.
137 MlirRewriterBase rewriter, MlirOperation op);
138
139/// Clone the blocks that belong to "region" before the given position in
140/// another region "parent".
142mlirRewriterBaseCloneRegionBefore(MlirRewriterBase rewriter, MlirRegion region,
143 MlirBlock before);
144
145//===----------------------------------------------------------------------===//
146/// RewriterBase API
147//===----------------------------------------------------------------------===//
148
149/// Move the blocks that belong to "region" before the given position in
150/// another region "parent". The two regions must be different. The caller
151/// is responsible for creating or updating the operation transferring flow
152/// of control to the region and passing it the correct block arguments.
154mlirRewriterBaseInlineRegionBefore(MlirRewriterBase rewriter, MlirRegion region,
155 MlirBlock before);
156
157/// Replace the results of the given (original) operation with the specified
158/// list of values (replacements). The result types of the given op and the
159/// replacements must match. The original op is erased.
161mlirRewriterBaseReplaceOpWithValues(MlirRewriterBase rewriter, MlirOperation op,
162 intptr_t nValues, MlirValue const *values);
163
164/// Replace the results of the given (original) operation with the specified
165/// new op (replacement). The result types of the two ops must match. The
166/// original op is erased.
168mlirRewriterBaseReplaceOpWithOperation(MlirRewriterBase rewriter,
169 MlirOperation op, MlirOperation newOp);
170
171/// Erases an operation that is known to have no uses.
172MLIR_CAPI_EXPORTED void mlirRewriterBaseEraseOp(MlirRewriterBase rewriter,
173 MlirOperation op);
174
175/// Erases a block along with all operations inside it.
176MLIR_CAPI_EXPORTED void mlirRewriterBaseEraseBlock(MlirRewriterBase rewriter,
177 MlirBlock block);
178
179/// Inline the operations of block 'source' before the operation 'op'. The
180/// source block will be deleted and must have no uses. 'argValues' is used to
181/// replace the block arguments of 'source'
182///
183/// The source block must have no successors. Otherwise, the resulting IR
184/// would have unreachable operations.
186mlirRewriterBaseInlineBlockBefore(MlirRewriterBase rewriter, MlirBlock source,
187 MlirOperation op, intptr_t nArgValues,
188 MlirValue const *argValues);
189
190/// Inline the operations of block 'source' into the end of block 'dest'. The
191/// source block will be deleted and must have no uses. 'argValues' is used to
192/// replace the block arguments of 'source'
193///
194/// The dest block must have no successors. Otherwise, the resulting IR would
195/// have unreachable operation.
196MLIR_CAPI_EXPORTED void mlirRewriterBaseMergeBlocks(MlirRewriterBase rewriter,
197 MlirBlock source,
198 MlirBlock dest,
199 intptr_t nArgValues,
200 MlirValue const *argValues);
201
202/// Unlink this operation from its current block and insert it right before
203/// `existingOp` which may be in the same or another block in the same
204/// function.
205MLIR_CAPI_EXPORTED void mlirRewriterBaseMoveOpBefore(MlirRewriterBase rewriter,
206 MlirOperation op,
207 MlirOperation existingOp);
208
209/// Unlink this operation from its current block and insert it right after
210/// `existingOp` which may be in the same or another block in the same
211/// function.
212MLIR_CAPI_EXPORTED void mlirRewriterBaseMoveOpAfter(MlirRewriterBase rewriter,
213 MlirOperation op,
214 MlirOperation existingOp);
215
216/// Unlink this block and insert it right before `existingBlock`.
218mlirRewriterBaseMoveBlockBefore(MlirRewriterBase rewriter, MlirBlock block,
219 MlirBlock existingBlock);
220
221/// This method is used to notify the rewriter that an in-place operation
222/// modification is about to happen. A call to this function *must* be
223/// followed by a call to either `finalizeOpModification` or
224/// `cancelOpModification`. This is a minor efficiency win (it avoids creating
225/// a new operation and removing the old one) but also often allows simpler
226/// code in the client.
228mlirRewriterBaseStartOpModification(MlirRewriterBase rewriter,
229 MlirOperation op);
230
231/// This method is used to signal the end of an in-place modification of the
232/// given operation. This can only be called on operations that were provided
233/// to a call to `startOpModification`.
235mlirRewriterBaseFinalizeOpModification(MlirRewriterBase rewriter,
236 MlirOperation op);
237
238/// This method cancels a pending in-place modification. This can only be
239/// called on operations that were provided to a call to
240/// `startOpModification`.
242mlirRewriterBaseCancelOpModification(MlirRewriterBase rewriter,
243 MlirOperation op);
244
245/// Find uses of `from` and replace them with `to`. Also notify the listener
246/// about every in-place op modification (for every use that was replaced).
248mlirRewriterBaseReplaceAllUsesWith(MlirRewriterBase rewriter, MlirValue from,
249 MlirValue to);
250
251/// Find uses of `from` and replace them with `to`. Also notify the listener
252/// about every in-place op modification (for every use that was replaced).
254 MlirRewriterBase rewriter, intptr_t nValues, MlirValue const *from,
255 MlirValue const *to);
256
257/// Find uses of `from` and replace them with `to`. Also notify the listener
258/// about every in-place op modification (for every use that was replaced)
259/// and that the `from` operation is about to be replaced.
261mlirRewriterBaseReplaceAllOpUsesWithValueRange(MlirRewriterBase rewriter,
262 MlirOperation from, intptr_t nTo,
263 MlirValue const *to);
264
265/// Find uses of `from` and replace them with `to`. Also notify the listener
266/// about every in-place op modification (for every use that was replaced)
267/// and that the `from` operation is about to be replaced.
269 MlirRewriterBase rewriter, MlirOperation from, MlirOperation to);
270
271/// Find uses of `from` within `block` and replace them with `to`. Also notify
272/// the listener about every in-place op modification (for every use that was
273/// replaced). The optional `allUsesReplaced` flag is set to "true" if all
274/// uses were replaced.
276 MlirRewriterBase rewriter, MlirOperation op, intptr_t nNewValues,
277 MlirValue const *newValues, MlirBlock block);
278
279/// Find uses of `from` and replace them with `to` except if the user is
280/// `exceptedUser`. Also notify the listener about every in-place op
281/// modification (for every use that was replaced).
283mlirRewriterBaseReplaceAllUsesExcept(MlirRewriterBase rewriter, MlirValue from,
284 MlirValue to, MlirOperation exceptedUser);
285
286//===----------------------------------------------------------------------===//
287/// IRRewriter API
288//===----------------------------------------------------------------------===//
289
290/// Create an IRRewriter and transfer ownership to the caller.
291MLIR_CAPI_EXPORTED MlirRewriterBase mlirIRRewriterCreate(MlirContext context);
292
293/// Create an IRRewriter and transfer ownership to the caller. Additionally
294/// set the insertion point before the operation.
295MLIR_CAPI_EXPORTED MlirRewriterBase
296mlirIRRewriterCreateFromOp(MlirOperation op);
297
298/// Takes an IRRewriter owned by the caller and destroys it. It is the
299/// responsibility of the user to only pass an IRRewriter class.
300MLIR_CAPI_EXPORTED void mlirIRRewriterDestroy(MlirRewriterBase rewriter);
301
302//===----------------------------------------------------------------------===//
303/// FrozenRewritePatternSet API
304//===----------------------------------------------------------------------===//
305
306/// Freeze the given MlirRewritePatternSet to a MlirFrozenRewritePatternSet.
307/// Note that the ownership of the input set is transferred into the frozen set
308/// after this call.
309MLIR_CAPI_EXPORTED MlirFrozenRewritePatternSet
310mlirFreezeRewritePattern(MlirRewritePatternSet set);
311
312/// Destroy the given MlirFrozenRewritePatternSet.
314mlirFrozenRewritePatternSetDestroy(MlirFrozenRewritePatternSet set);
315
317 MlirOperation op, MlirFrozenRewritePatternSet patterns,
318 MlirGreedyRewriteDriverConfig);
319
321 MlirModule op, MlirFrozenRewritePatternSet patterns,
322 MlirGreedyRewriteDriverConfig);
323
324//===----------------------------------------------------------------------===//
325/// PatternRewriter API
326//===----------------------------------------------------------------------===//
327
328/// Cast the PatternRewriter to a RewriterBase
329MLIR_CAPI_EXPORTED MlirRewriterBase
330mlirPatternRewriterAsBase(MlirPatternRewriter rewriter);
331
332//===----------------------------------------------------------------------===//
333/// RewritePattern API
334//===----------------------------------------------------------------------===//
335
336/// Callbacks to construct a rewrite pattern.
337typedef struct {
338 /// Optional constructor for the user data.
339 /// Set to nullptr to disable it.
340 void (*construct)(void *userData);
341 /// Optional destructor for the user data.
342 /// Set to nullptr to disable it.
343 void (*destruct)(void *userData);
344 /// The callback function to match against code rooted at the specified
345 /// operation, and perform the rewrite if the match is successful,
346 /// corresponding to RewritePattern::matchAndRewrite.
347 MlirLogicalResult (*matchAndRewrite)(MlirRewritePattern pattern,
348 MlirOperation op,
349 MlirPatternRewriter rewriter,
350 void *userData);
352
353/// Create a rewrite pattern that matches the operation
354/// with the given rootName, corresponding to mlir::OpRewritePattern.
356 MlirStringRef rootName, unsigned benefit, MlirContext context,
357 MlirRewritePatternCallbacks callbacks, void *userData,
358 size_t nGeneratedNames, MlirStringRef *generatedNames);
359
360//===----------------------------------------------------------------------===//
361/// RewritePatternSet API
362//===----------------------------------------------------------------------===//
363
364/// Create an empty MlirRewritePatternSet.
365MLIR_CAPI_EXPORTED MlirRewritePatternSet
366mlirRewritePatternSetCreate(MlirContext context);
367
368/// Destruct the given MlirRewritePatternSet.
369MLIR_CAPI_EXPORTED void mlirRewritePatternSetDestroy(MlirRewritePatternSet set);
370
371/// Add the given MlirRewritePattern into a MlirRewritePatternSet.
372/// Note that the ownership of the pattern is transferred to the set after this
373/// call.
374MLIR_CAPI_EXPORTED void mlirRewritePatternSetAdd(MlirRewritePatternSet set,
375 MlirRewritePattern pattern);
376
377//===----------------------------------------------------------------------===//
378/// PDLPatternModule API
379//===----------------------------------------------------------------------===//
380
381#if MLIR_ENABLE_PDL_IN_PATTERNMATCH
382DEFINE_C_API_STRUCT(MlirPDLPatternModule, void);
383DEFINE_C_API_STRUCT(MlirPDLValue, const void);
384DEFINE_C_API_STRUCT(MlirPDLResultList, void);
385
386MLIR_CAPI_EXPORTED MlirPDLPatternModule
387mlirPDLPatternModuleFromModule(MlirModule op);
388
389MLIR_CAPI_EXPORTED void mlirPDLPatternModuleDestroy(MlirPDLPatternModule op);
390
391MLIR_CAPI_EXPORTED MlirRewritePatternSet
392mlirRewritePatternSetFromPDLPatternModule(MlirPDLPatternModule op);
393
394/// Cast the MlirPDLValue to an MlirValue.
395/// Return a null value if the cast fails, just like llvm::dyn_cast.
396MLIR_CAPI_EXPORTED MlirValue mlirPDLValueAsValue(MlirPDLValue value);
397
398/// Cast the MlirPDLValue to an MlirType.
399/// Return a null value if the cast fails, just like llvm::dyn_cast.
400MLIR_CAPI_EXPORTED MlirType mlirPDLValueAsType(MlirPDLValue value);
401
402/// Cast the MlirPDLValue to an MlirOperation.
403/// Return a null value if the cast fails, just like llvm::dyn_cast.
404MLIR_CAPI_EXPORTED MlirOperation mlirPDLValueAsOperation(MlirPDLValue value);
405
406/// Cast the MlirPDLValue to an MlirAttribute.
407/// Return a null value if the cast fails, just like llvm::dyn_cast.
408MLIR_CAPI_EXPORTED MlirAttribute mlirPDLValueAsAttribute(MlirPDLValue value);
409
410/// Push the MlirValue into the given MlirPDLResultList.
412mlirPDLResultListPushBackValue(MlirPDLResultList results, MlirValue value);
413
414/// Push the MlirType into the given MlirPDLResultList.
415MLIR_CAPI_EXPORTED void mlirPDLResultListPushBackType(MlirPDLResultList results,
416 MlirType value);
417
418/// Push the MlirOperation into the given MlirPDLResultList.
420mlirPDLResultListPushBackOperation(MlirPDLResultList results,
421 MlirOperation value);
422
423/// Push the MlirAttribute into the given MlirPDLResultList.
425mlirPDLResultListPushBackAttribute(MlirPDLResultList results,
426 MlirAttribute value);
427
428/// This function type is used as callbacks for PDL native rewrite functions.
429/// Input values can be accessed by `values` with its size `nValues`;
430/// output values can be added into `results` by `mlirPDLResultListPushBack*`
431/// APIs. And the return value indicates whether the rewrite succeeds.
432typedef MlirLogicalResult (*MlirPDLRewriteFunction)(
433 MlirPatternRewriter rewriter, MlirPDLResultList results, size_t nValues,
434 MlirPDLValue *values, void *userData);
435
436/// Register a rewrite function into the given PDL pattern module.
437/// `userData` will be provided as an argument to the rewrite function.
438MLIR_CAPI_EXPORTED void mlirPDLPatternModuleRegisterRewriteFunction(
439 MlirPDLPatternModule pdlModule, MlirStringRef name,
440 MlirPDLRewriteFunction rewriteFn, void *userData);
441
442/// This function type is used as callbacks for PDL native constraint functions.
443/// Input values can be accessed by `values` with its size `nValues`;
444/// output values can be added into `results` by `mlirPDLResultListPushBack*`
445/// APIs. And the return value indicates whether the constraint holds.
446typedef MlirLogicalResult (*MlirPDLConstraintFunction)(
447 MlirPatternRewriter rewriter, MlirPDLResultList results, size_t nValues,
448 MlirPDLValue *values, void *userData);
449
450/// Register a constraint function into the given PDL pattern module.
451/// `userData` will be provided as an argument to the constraint function.
452MLIR_CAPI_EXPORTED void mlirPDLPatternModuleRegisterConstraintFunction(
453 MlirPDLPatternModule pdlModule, MlirStringRef name,
454 MlirPDLConstraintFunction constraintFn, void *userData);
455
456#endif // MLIR_ENABLE_PDL_IN_PATTERNMATCH
457
458#undef DEFINE_C_API_STRUCT
459
460#ifdef __cplusplus
461}
462#endif
463
464#endif // MLIR_C_REWRITE_H
MLIR_CAPI_EXPORTED void mlirRewriterBaseMoveBlockBefore(MlirRewriterBase rewriter, MlirBlock block, MlirBlock existingBlock)
Unlink this block and insert it right before existingBlock.
Definition Rewrite.cpp:184
MLIR_CAPI_EXPORTED 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:194
MLIR_CAPI_EXPORTED 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:133
MLIR_CAPI_EXPORTED void mlirRewriterBaseEraseBlock(MlirRewriterBase rewriter, MlirBlock block)
Erases a block along with all operations inside it.
Definition Rewrite.cpp:151
MLIR_CAPI_EXPORTED 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:40
MLIR_CAPI_EXPORTED void mlirRewriterBaseCancelOpModification(MlirRewriterBase rewriter, MlirOperation op)
This method cancels a pending in-place modification.
Definition Rewrite.cpp:199
MLIR_CAPI_EXPORTED 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:45
MLIR_CAPI_EXPORTED 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:235
MLIR_CAPI_EXPORTED MlirOperation mlirRewriterBaseGetOperationAfterInsertion(MlirRewriterBase rewriter)
Returns the operation right after the current insertion point of the rewriter.
Definition Rewrite.cpp:74
MLIR_CAPI_EXPORTED void mlirRewriterBaseReplaceAllOpUsesWithOperation(MlirRewriterBase rewriter, MlirOperation from, MlirOperation to)
Find uses of from and replace them with to.
Definition Rewrite.cpp:229
MLIR_CAPI_EXPORTED void mlirRewritePatternSetAdd(MlirRewritePatternSet set, MlirRewritePattern pattern)
Add the given MlirRewritePattern into a MlirRewritePatternSet.
Definition Rewrite.cpp:370
MLIR_CAPI_EXPORTED MlirOperation mlirRewriterBaseClone(MlirRewriterBase rewriter, MlirOperation op)
Creates a deep copy of the specified operation.
Definition Rewrite.cpp:108
#define DEFINE_C_API_STRUCT(name, storage)
Opaque type declarations (see mlir-c/IR.h for more details).
Definition Rewrite.h:30
MLIR_CAPI_EXPORTED MlirOperation mlirRewriterBaseInsert(MlirRewriterBase rewriter, MlirOperation op)
Insert the given operation at the current insertion point and return it.
Definition Rewrite.cpp:101
MLIR_CAPI_EXPORTED 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:209
MLIR_CAPI_EXPORTED void mlirRewriterBaseEraseOp(MlirRewriterBase rewriter, MlirOperation op)
Erases an operation that is known to have no uses.
Definition Rewrite.cpp:147
MLIR_CAPI_EXPORTED 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:155
MLIR_CAPI_EXPORTED 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:344
MLIR_CAPI_EXPORTED MlirRewriterBase mlirIRRewriterCreateFromOp(MlirOperation op)
Create an IRRewriter and transfer ownership to the caller.
Definition Rewrite.cpp:261
MLIR_CAPI_EXPORTED 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:189
MLIR_CAPI_EXPORTED MlirContext mlirRewriterBaseGetContext(MlirRewriterBase rewriter)
RewriterBase API inherited from OpBuilder.
Definition Rewrite.cpp:28
MLIR_CAPI_EXPORTED 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:141
MLIR_CAPI_EXPORTED MlirRewriterBase mlirIRRewriterCreate(MlirContext context)
IRRewriter API.
Definition Rewrite.cpp:257
MLIR_CAPI_EXPORTED MlirLogicalResult mlirApplyPatternsAndFoldGreedily(MlirModule op, MlirFrozenRewritePatternSet patterns, MlirGreedyRewriteDriverConfig)
Definition Rewrite.cpp:286
MLIR_CAPI_EXPORTED MlirBlock mlirRewriterBaseGetInsertionBlock(MlirRewriterBase rewriter)
Return the block the current insertion point belongs to.
Definition Rewrite.cpp:65
MLIR_CAPI_EXPORTED void mlirRewritePatternSetDestroy(MlirRewritePatternSet set)
Destruct the given MlirRewritePatternSet.
Definition Rewrite.cpp:366
MLIR_CAPI_EXPORTED void mlirRewriterBaseClearInsertionPoint(MlirRewriterBase rewriter)
Insertion points methods.
Definition Rewrite.cpp:36
MLIR_CAPI_EXPORTED 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:179
MLIR_CAPI_EXPORTED 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:118
MLIR_CAPI_EXPORTED MlirRewriterBase mlirPatternRewriterAsBase(MlirPatternRewriter rewriter)
PatternRewriter API.
Definition Rewrite.cpp:303
MLIR_CAPI_EXPORTED MlirLogicalResult mlirApplyPatternsAndFoldGreedilyWithOp(MlirOperation op, MlirFrozenRewritePatternSet patterns, MlirGreedyRewriteDriverConfig)
Definition Rewrite.cpp:293
MLIR_CAPI_EXPORTED MlirRewritePatternSet mlirRewritePatternSetCreate(MlirContext context)
RewritePatternSet API.
Definition Rewrite.cpp:362
MLIR_CAPI_EXPORTED void mlirRewriterBaseInlineRegionBefore(MlirRewriterBase rewriter, MlirRegion region, MlirBlock before)
RewriterBase API.
Definition Rewrite.cpp:128
MLIR_CAPI_EXPORTED MlirBlock mlirRewriterBaseGetBlock(MlirRewriterBase rewriter)
Returns the current block of the rewriter.
Definition Rewrite.cpp:69
MLIR_CAPI_EXPORTED void mlirRewriterBaseSetInsertionPointToEnd(MlirRewriterBase rewriter, MlirBlock block)
Sets the insertion point to the end of the specified block.
Definition Rewrite.cpp:60
MLIR_CAPI_EXPORTED 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:246
MLIR_CAPI_EXPORTED void mlirRewriterBaseReplaceAllOpUsesWithValueRange(MlirRewriterBase rewriter, MlirOperation from, intptr_t nTo, MlirValue const *to)
Find uses of from and replace them with to.
Definition Rewrite.cpp:220
MLIR_CAPI_EXPORTED 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:174
MLIR_CAPI_EXPORTED 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:166
MLIR_CAPI_EXPORTED void mlirFrozenRewritePatternSetDestroy(MlirFrozenRewritePatternSet set)
Destroy the given MlirFrozenRewritePatternSet.
Definition Rewrite.cpp:280
MLIR_CAPI_EXPORTED void mlirRewriterBaseSetInsertionPointAfterValue(MlirRewriterBase rewriter, MlirValue value)
Sets the insertion point to the node after the specified value.
Definition Rewrite.cpp:50
MLIR_CAPI_EXPORTED MlirOperation mlirRewriterBaseCloneWithoutRegions(MlirRewriterBase rewriter, MlirOperation op)
Creates a deep copy of this operation but keep the operation regions empty.
Definition Rewrite.cpp:113
MLIR_CAPI_EXPORTED MlirFrozenRewritePatternSet mlirFreezeRewritePattern(MlirRewritePatternSet set)
FrozenRewritePatternSet API.
Definition Rewrite.cpp:274
MLIR_CAPI_EXPORTED void mlirIRRewriterDestroy(MlirRewriterBase rewriter)
Takes an IRRewriter owned by the caller and destroys it.
Definition Rewrite.cpp:265
MLIR_CAPI_EXPORTED MlirBlock mlirRewriterBaseCreateBlockBefore(MlirRewriterBase rewriter, MlirBlock insertBefore, intptr_t nArgTypes, MlirType const *argTypes, MlirLocation const *locations)
Block and operation creation/insertion/cloning.
Definition Rewrite.cpp:88
MLIR_CAPI_EXPORTED void mlirRewriterBaseReplaceAllUsesWith(MlirRewriterBase rewriter, MlirValue from, MlirValue to)
Find uses of from and replace them with to.
Definition Rewrite.cpp:204
MLIR_CAPI_EXPORTED void mlirRewriterBaseSetInsertionPointToStart(MlirRewriterBase rewriter, MlirBlock block)
Sets the insertion point to the start of the specified block.
Definition Rewrite.cpp:55
struct MlirLogicalResult MlirLogicalResult
Definition Support.h:119
#define MLIR_CAPI_EXPORTED
Definition Support.h:46
A logical result value, essentially a boolean with named states.
Definition Support.h:116
RewritePattern API.
Definition Rewrite.h:337
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...
Definition Rewrite.h:347
void(* construct)(void *userData)
Optional constructor for the user data.
Definition Rewrite.h:340
void(* destruct)(void *userData)
Optional destructor for the user data.
Definition Rewrite.h:343
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition Support.h:73