MLIR 23.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
37DEFINE_C_API_STRUCT(MlirFrozenRewritePatternSet, void);
38DEFINE_C_API_STRUCT(MlirGreedyRewriteDriverConfig, void);
39
40/// Greedy rewrite strictness levels.
41typedef enum {
42 /// No restrictions wrt. which ops are processed.
44 /// Only pre-existing and newly created ops are processed.
46 /// Only pre-existing ops are processed.
49
50/// Greedy simplify region levels.
51typedef enum {
52 /// Disable region control-flow simplification.
54 /// Run the normal simplification (e.g. dead args elimination).
56 /// Run extra simplifications (e.g. block merging).
59DEFINE_C_API_STRUCT(MlirRewritePatternSet, void);
60DEFINE_C_API_STRUCT(MlirPatternRewriter, void);
61DEFINE_C_API_STRUCT(MlirRewritePattern, const void);
62DEFINE_C_API_STRUCT(MlirConversionTarget, void);
63DEFINE_C_API_STRUCT(MlirConversionPattern, const void);
64DEFINE_C_API_STRUCT(MlirTypeConverter, void);
65DEFINE_C_API_STRUCT(MlirConversionPatternRewriter, void);
66DEFINE_C_API_STRUCT(MlirConversionConfig, void);
67
68//===----------------------------------------------------------------------===//
69/// RewriterBase API inherited from OpBuilder
70//===----------------------------------------------------------------------===//
71
72/// Get the MLIR context referenced by the rewriter.
73MLIR_CAPI_EXPORTED MlirContext
75
76//===----------------------------------------------------------------------===//
77/// Insertion points methods
78//===----------------------------------------------------------------------===//
79
80// These do not include functions using Block::iterator or Region::iterator, as
81// they are not exposed by the C API yet. Similarly for methods using
82// `InsertPoint` directly.
83
84/// Reset the insertion point to no location. Creating an operation without a
85/// set insertion point is an error, but this can still be useful when the
86/// current insertion point a builder refers to is being removed.
89
90/// Sets the insertion point to the specified operation, which will cause
91/// subsequent insertions to go right before it.
94 MlirOperation op);
95
96/// Sets the insertion point to the node after the specified operation, which
97/// will cause subsequent insertions to go right after it.
100 MlirOperation op);
101
102/// Sets the insertion point to the node after the specified value. If value
103/// has a defining operation, sets the insertion point to the node after such
104/// defining operation. This will cause subsequent insertions to go right
105/// after it. Otherwise, value is a BlockArgument. Sets the insertion point to
106/// the start of its block.
109 MlirValue value);
110
111/// Sets the insertion point to the start of the specified block.
114 MlirBlock block);
115
116/// Sets the insertion point to the end of the specified block.
119 MlirBlock block);
120
121/// Return the block the current insertion point belongs to. Note that the
122/// insertion point is not necessarily the end of the block.
123MLIR_CAPI_EXPORTED MlirBlock
125
126/// Returns the current block of the rewriter.
127MLIR_CAPI_EXPORTED MlirBlock
129
130/// Returns the operation right after the current insertion point
131/// of the rewriter. A null MlirOperation will be returned
132// if the current insertion point is at the end of the block.
133MLIR_CAPI_EXPORTED MlirOperation
135
136//===----------------------------------------------------------------------===//
137/// Block and operation creation/insertion/cloning
138//===----------------------------------------------------------------------===//
139
140// These functions do not include the IRMapper, as it is not yet exposed by the
141// C API.
142
143/// Add new block with 'argTypes' arguments and set the insertion point to the
144/// end of it. The block is placed before 'insertBefore'. `locs` contains the
145/// locations of the inserted arguments, and should match the size of
146/// `argTypes`.
148 MlirRewriterBase rewriter, MlirBlock insertBefore, intptr_t nArgTypes,
149 MlirType const *argTypes, MlirLocation const *locations);
150
151/// Insert the given operation at the current insertion point and return it.
152MLIR_CAPI_EXPORTED MlirOperation
153mlirRewriterBaseInsert(MlirRewriterBase rewriter, MlirOperation op);
154
155/// Creates a deep copy of the specified operation.
156MLIR_CAPI_EXPORTED MlirOperation
157mlirRewriterBaseClone(MlirRewriterBase rewriter, MlirOperation op);
158
159/// Creates a deep copy of this operation but keep the operation regions
160/// empty.
162 MlirRewriterBase rewriter, MlirOperation op);
163
164/// Clones the given operation using the rewriter and the provided IRMapping.
165/// The mapping is updated with the results of the cloned operation.
167 MlirRewriterBase rewriter, MlirOperation op, MlirIRMapping mapping);
168
169/// Clone the blocks that belong to "region" before the given position in
170/// another region "parent".
172mlirRewriterBaseCloneRegionBefore(MlirRewriterBase rewriter, MlirRegion region,
173 MlirBlock before);
174
175//===----------------------------------------------------------------------===//
176/// RewriterBase API
177//===----------------------------------------------------------------------===//
178
179/// Move the blocks that belong to "region" before the given position in
180/// another region "parent". The two regions must be different. The caller
181/// is responsible for creating or updating the operation transferring flow
182/// of control to the region and passing it the correct block arguments.
184mlirRewriterBaseInlineRegionBefore(MlirRewriterBase rewriter, MlirRegion region,
185 MlirBlock before);
186
187/// Replace the results of the given (original) operation with the specified
188/// list of values (replacements). The result types of the given op and the
189/// replacements must match. The original op is erased.
192 intptr_t nValues, MlirValue const *values);
193
194/// Replace the results of the given (original) operation with the specified
195/// new op (replacement). The result types of the two ops must match. The
196/// original op is erased.
199 MlirOperation op, MlirOperation newOp);
200
201/// Erases an operation that is known to have no uses.
203 MlirOperation op);
204
205/// Erases a block along with all operations inside it.
207 MlirBlock block);
208
209/// Inline the operations of block 'source' before the operation 'op'. The
210/// source block will be deleted and must have no uses. 'argValues' is used to
211/// replace the block arguments of 'source'
212///
213/// The source block must have no successors. Otherwise, the resulting IR
214/// would have unreachable operations.
216mlirRewriterBaseInlineBlockBefore(MlirRewriterBase rewriter, MlirBlock source,
217 MlirOperation op, intptr_t nArgValues,
218 MlirValue const *argValues);
219
220/// Inline the operations of block 'source' into the end of block 'dest'. The
221/// source block will be deleted and must have no uses. 'argValues' is used to
222/// replace the block arguments of 'source'
223///
224/// The dest block must have no successors. Otherwise, the resulting IR would
225/// have unreachable operation.
227 MlirBlock source,
228 MlirBlock dest,
229 intptr_t nArgValues,
230 MlirValue const *argValues);
231
232/// Unlink this operation from its current block and insert it right before
233/// `existingOp` which may be in the same or another block in the same
234/// function.
236 MlirOperation op,
237 MlirOperation existingOp);
238
239/// Unlink this operation from its current block and insert it right after
240/// `existingOp` which may be in the same or another block in the same
241/// function.
243 MlirOperation op,
244 MlirOperation existingOp);
245
246/// Unlink this block and insert it right before `existingBlock`.
248mlirRewriterBaseMoveBlockBefore(MlirRewriterBase rewriter, MlirBlock block,
249 MlirBlock existingBlock);
250
251/// This method is used to notify the rewriter that an in-place operation
252/// modification is about to happen. A call to this function *must* be
253/// followed by a call to either `finalizeOpModification` or
254/// `cancelOpModification`. This is a minor efficiency win (it avoids creating
255/// a new operation and removing the old one) but also often allows simpler
256/// code in the client.
259 MlirOperation op);
260
261/// This method is used to signal the end of an in-place modification of the
262/// given operation. This can only be called on operations that were provided
263/// to a call to `startOpModification`.
266 MlirOperation op);
267
268/// This method cancels a pending in-place modification. This can only be
269/// called on operations that were provided to a call to
270/// `startOpModification`.
273 MlirOperation op);
274
275/// Find uses of `from` and replace them with `to`. Also notify the listener
276/// about every in-place op modification (for every use that was replaced).
279 MlirValue to);
280
281/// Find uses of `from` and replace them with `to`. Also notify the listener
282/// about every in-place op modification (for every use that was replaced).
284 MlirRewriterBase rewriter, intptr_t nValues, MlirValue const *from,
285 MlirValue const *to);
286
287/// Find uses of `from` and replace them with `to`. Also notify the listener
288/// about every in-place op modification (for every use that was replaced)
289/// and that the `from` operation is about to be replaced.
292 MlirOperation from, intptr_t nTo,
293 MlirValue const *to);
294
295/// Find uses of `from` and replace them with `to`. Also notify the listener
296/// about every in-place op modification (for every use that was replaced)
297/// and that the `from` operation is about to be replaced.
299 MlirRewriterBase rewriter, MlirOperation from, MlirOperation to);
300
301/// Find uses of `from` within `block` and replace them with `to`. Also notify
302/// the listener about every in-place op modification (for every use that was
303/// replaced). The optional `allUsesReplaced` flag is set to "true" if all
304/// uses were replaced.
306 MlirRewriterBase rewriter, MlirOperation op, intptr_t nNewValues,
307 MlirValue const *newValues, MlirBlock block);
308
309/// Find uses of `from` and replace them with `to` except if the user is
310/// `exceptedUser`. Also notify the listener about every in-place op
311/// modification (for every use that was replaced).
314 MlirValue to, MlirOperation exceptedUser);
315
316//===----------------------------------------------------------------------===//
317/// IRRewriter API
318//===----------------------------------------------------------------------===//
319
320/// Create an IRRewriter and transfer ownership to the caller.
322
323/// Create an IRRewriter and transfer ownership to the caller. Additionally
324/// set the insertion point before the operation.
326mlirIRRewriterCreateFromOp(MlirOperation op);
327
328/// Takes an IRRewriter owned by the caller and destroys it. It is the
329/// responsibility of the user to only pass an IRRewriter class.
331
332//===----------------------------------------------------------------------===//
333/// FrozenRewritePatternSet API
334//===----------------------------------------------------------------------===//
335
336/// Freeze the given MlirRewritePatternSet to a MlirFrozenRewritePatternSet.
337/// Note that the ownership of the input set is transferred into the frozen set
338/// after this call.
339MLIR_CAPI_EXPORTED MlirFrozenRewritePatternSet
340mlirFreezeRewritePattern(MlirRewritePatternSet set);
341
342/// Destroy the given MlirFrozenRewritePatternSet.
344mlirFrozenRewritePatternSetDestroy(MlirFrozenRewritePatternSet set);
345
347 MlirOperation op, MlirFrozenRewritePatternSet patterns,
348 MlirGreedyRewriteDriverConfig);
349
351 MlirModule op, MlirFrozenRewritePatternSet patterns,
352 MlirGreedyRewriteDriverConfig config);
353
354//===----------------------------------------------------------------------===//
355/// GreedyRewriteDriverConfig API
356//===----------------------------------------------------------------------===//
357
358/// Creates a greedy rewrite driver configuration with default settings.
359MLIR_CAPI_EXPORTED MlirGreedyRewriteDriverConfig
361
362/// Destroys a greedy rewrite driver configuration.
364mlirGreedyRewriteDriverConfigDestroy(MlirGreedyRewriteDriverConfig config);
365
366/// Sets the maximum number of iterations for the greedy rewrite driver.
367/// Use -1 for no limit.
369 MlirGreedyRewriteDriverConfig config, int64_t maxIterations);
370
371/// Sets the maximum number of rewrites within an iteration.
372/// Use -1 for no limit.
374 MlirGreedyRewriteDriverConfig config, int64_t maxNumRewrites);
375
376/// Sets whether to use top-down traversal for the initial population of the
377/// worklist.
379 MlirGreedyRewriteDriverConfig config, bool useTopDownTraversal);
380
381/// Enables or disables folding during greedy rewriting.
383mlirGreedyRewriteDriverConfigEnableFolding(MlirGreedyRewriteDriverConfig config,
384 bool enable);
385
386/// Sets the strictness level for the greedy rewrite driver.
388 MlirGreedyRewriteDriverConfig config,
389 MlirGreedyRewriteStrictness strictness);
390
391/// Sets the region simplification level.
394 MlirGreedyRewriteDriverConfig config, MlirGreedySimplifyRegionLevel level);
395
396/// Enables or disables constant CSE.
398 MlirGreedyRewriteDriverConfig config, bool enable);
399
400/// Gets the maximum number of iterations for the greedy rewrite driver.
402 MlirGreedyRewriteDriverConfig config);
403
404/// Gets the maximum number of rewrites within an iteration.
406 MlirGreedyRewriteDriverConfig config);
407
408/// Gets whether top-down traversal is used for initial worklist population.
410 MlirGreedyRewriteDriverConfig config);
411
412/// Gets whether folding is enabled during greedy rewriting.
414 MlirGreedyRewriteDriverConfig config);
415
416/// Gets the strictness level for the greedy rewrite driver.
419 MlirGreedyRewriteDriverConfig config);
420
421/// Gets the region simplification level.
424 MlirGreedyRewriteDriverConfig config);
425
426/// Gets whether constant CSE is enabled.
428 MlirGreedyRewriteDriverConfig config);
429
430/// Applies the given patterns to the given op by a fast walk-based pattern
431/// rewrite driver.
433mlirWalkAndApplyPatterns(MlirOperation op,
434 MlirFrozenRewritePatternSet patterns);
435
436/// Apply a partial conversion on the given operation.
438 MlirOperation op, MlirConversionTarget target,
439 MlirFrozenRewritePatternSet patterns, MlirConversionConfig config);
440
441/// Apply a full conversion on the given operation.
443 MlirOperation op, MlirConversionTarget target,
444 MlirFrozenRewritePatternSet patterns, MlirConversionConfig config);
445
446//===----------------------------------------------------------------------===//
447/// ConversionConfig API
448//===----------------------------------------------------------------------===//
449
450/// Create a default ConversionConfig.
451MLIR_CAPI_EXPORTED MlirConversionConfig mlirConversionConfigCreate(void);
452
453/// Destroy the given ConversionConfig.
455mlirConversionConfigDestroy(MlirConversionConfig config);
456
462
463/// Set the folding mode for the given ConversionConfig.
465mlirConversionConfigSetFoldingMode(MlirConversionConfig config,
467
468/// Get the folding mode for the given ConversionConfig.
470mlirConversionConfigGetFoldingMode(MlirConversionConfig config);
471
472/// Enable or disable building materializations during conversion.
474mlirConversionConfigEnableBuildMaterializations(MlirConversionConfig config,
475 bool enable);
476
477/// Check if building materializations during conversion is enabled.
479mlirConversionConfigIsBuildMaterializationsEnabled(MlirConversionConfig config);
480
481//===----------------------------------------------------------------------===//
482/// PatternRewriter API
483//===----------------------------------------------------------------------===//
484
485/// Cast the PatternRewriter to a RewriterBase
487mlirPatternRewriterAsBase(MlirPatternRewriter rewriter);
488
489//===----------------------------------------------------------------------===//
490/// ConversionPatternRewriter API
491//===----------------------------------------------------------------------===//
492
493/// Cast the ConversionPatternRewriter to a PatternRewriter
494MLIR_CAPI_EXPORTED MlirPatternRewriter
496 MlirConversionPatternRewriter rewriter);
497
498/// Apply a signature conversion to each block in the given region.
501 MlirConversionPatternRewriter rewriter, MlirRegion region,
502 MlirTypeConverter typeConverter);
503
504//===----------------------------------------------------------------------===//
505/// ConversionTarget API
506//===----------------------------------------------------------------------===//
507
508/// Create an empty ConversionTarget.
509MLIR_CAPI_EXPORTED MlirConversionTarget
510mlirConversionTargetCreate(MlirContext context);
511
512/// Destroy the given ConversionTarget.
514mlirConversionTargetDestroy(MlirConversionTarget target);
515
516/// Register the given operations as legal.
518mlirConversionTargetAddLegalOp(MlirConversionTarget target,
519 MlirStringRef opName);
520
521/// Register the given operations as illegal.
523mlirConversionTargetAddIllegalOp(MlirConversionTarget target,
524 MlirStringRef opName);
525
526/// Register the operations of the given dialect as legal.
529 MlirStringRef dialectName);
530
531/// Register the operations of the given dialect as illegal.
534 MlirStringRef dialectName);
535
536/// Result of a dynamic legality callback.
537typedef enum {
538 /// The operation instance is legal.
540 /// The operation instance is illegal.
542 /// The callback has no opinion on this instance. The decision is deferred to
543 /// other registered callbacks (legality callbacks are composed) or, failing
544 /// that, to the operation's static legality action.
547
548/// Callback for dynamic legality checks. Returns the legality of the given
549/// operation instance (see MlirConversionTargetLegality).
552 void *userData);
553
554/// Register the given operation as dynamically legal, with a callback to
555/// determine per-instance legality. The callback must not be NULL.
557 MlirConversionTarget target, MlirStringRef opName,
558 MlirConversionTargetDynamicLegalityCallback callback, void *userData);
559
560/// Register the given dialect as dynamically legal, with a callback to
561/// determine per-instance legality for all operations in the dialect. The
562/// callback must not be NULL.
564 MlirConversionTarget target, MlirStringRef dialectName,
565 MlirConversionTargetDynamicLegalityCallback callback, void *userData);
566
567/// Mark the given operation as recursively legal. The optional callback (may
568/// be NULL) determines whether a specific instance is recursively legal; a NULL
569/// callback marks the operation as unconditionally recursively legal.
571 MlirConversionTarget target, MlirStringRef opName,
572 MlirConversionTargetDynamicLegalityCallback callback, void *userData);
573
574/// Mark unknown operations as dynamically legal, with a callback. The callback
575/// must not be NULL.
577 MlirConversionTarget target,
578 MlirConversionTargetDynamicLegalityCallback callback, void *userData);
579
580//===----------------------------------------------------------------------===//
581/// TypeConverter API
582//===----------------------------------------------------------------------===//
583
584/// Create a TypeConverter.
585MLIR_CAPI_EXPORTED MlirTypeConverter mlirTypeConverterCreate(void);
586
587/// Destroy the given TypeConverter.
589mlirTypeConverterDestroy(MlirTypeConverter typeConverter);
590
591/// Callback type for type conversion functions.
592/// Returns failure or sets convertedType to MlirType{NULL} to indicate failure.
593/// If failure is returned, the converter is allowed to try another
594/// conversion function to perform the conversion.
596 MlirType type, MlirType *convertedType, void *userData);
597
598/// Add a type conversion function to the given TypeConverter.
600mlirTypeConverterAddConversion(MlirTypeConverter typeConverter,
602 void *userData);
603
604/// Convert the given type using the given TypeConverter.
605MLIR_CAPI_EXPORTED MlirType
606mlirTypeConverterConvertType(MlirTypeConverter typeConverter, MlirType type);
607
608//===----------------------------------------------------------------------===//
609/// ConversionPattern API
610//===----------------------------------------------------------------------===//
611
612typedef struct {
613 /// Optional constructor for the user data.
614 /// Set to nullptr to disable it.
615 void (*construct)(void *userData);
616 /// Optional destructor for the user data.
617 /// Set to nullptr to disable it.
618 void (*destruct)(void *userData);
619 /// The callback function to match against code rooted at the specified
620 /// operation, and perform the conversion rewrite if the match is successful,
621 /// corresponding to ConversionPattern::matchAndRewrite.
622 MlirLogicalResult (*matchAndRewrite)(MlirConversionPattern pattern,
623 MlirOperation op, intptr_t nOperands,
624 MlirValue *operands,
625 MlirConversionPatternRewriter rewriter,
626 void *userData);
628
629/// Create a conversion pattern that matches the operation with the given
630/// rootName, corresponding to mlir::OpConversionPattern.
632 MlirStringRef rootName, unsigned benefit, MlirContext context,
633 MlirTypeConverter typeConverter, MlirConversionPatternCallbacks callbacks,
634 void *userData, size_t nGeneratedNames, MlirStringRef *generatedNames);
635
636/// Get the type converter used by this conversion pattern.
637MLIR_CAPI_EXPORTED MlirTypeConverter
638mlirConversionPatternGetTypeConverter(MlirConversionPattern pattern);
639
640/// Cast the ConversionPattern to a RewritePattern.
641MLIR_CAPI_EXPORTED MlirRewritePattern
642mlirConversionPatternAsRewritePattern(MlirConversionPattern pattern);
643
644//===----------------------------------------------------------------------===//
645/// RewritePattern API
646//===----------------------------------------------------------------------===//
647
648/// Callbacks to construct a rewrite pattern.
649typedef struct {
650 /// Optional constructor for the user data.
651 /// Set to nullptr to disable it.
652 void (*construct)(void *userData);
653 /// Optional destructor for the user data.
654 /// Set to nullptr to disable it.
655 void (*destruct)(void *userData);
656 /// The callback function to match against code rooted at the specified
657 /// operation, and perform the rewrite if the match is successful,
658 /// corresponding to RewritePattern::matchAndRewrite.
659 MlirLogicalResult (*matchAndRewrite)(MlirRewritePattern pattern,
660 MlirOperation op,
661 MlirPatternRewriter rewriter,
662 void *userData);
664
665/// Create a rewrite pattern that matches the operation
666/// with the given rootName, corresponding to mlir::OpRewritePattern.
668 MlirStringRef rootName, unsigned benefit, MlirContext context,
669 MlirRewritePatternCallbacks callbacks, void *userData,
670 size_t nGeneratedNames, MlirStringRef *generatedNames);
671
672//===----------------------------------------------------------------------===//
673/// RewritePatternSet API
674//===----------------------------------------------------------------------===//
675
676/// Create an empty MlirRewritePatternSet.
677MLIR_CAPI_EXPORTED MlirRewritePatternSet
678mlirRewritePatternSetCreate(MlirContext context);
679
680/// Get the context associated with a MlirRewritePatternSet.
681MLIR_CAPI_EXPORTED MlirContext
682mlirRewritePatternSetGetContext(MlirRewritePatternSet set);
683
684/// Destruct the given MlirRewritePatternSet.
685MLIR_CAPI_EXPORTED void mlirRewritePatternSetDestroy(MlirRewritePatternSet set);
686
687/// Add the given MlirRewritePattern into a MlirRewritePatternSet.
688/// Note that the ownership of the pattern is transferred to the set after this
689/// call.
690MLIR_CAPI_EXPORTED void mlirRewritePatternSetAdd(MlirRewritePatternSet set,
691 MlirRewritePattern pattern);
692
693//===----------------------------------------------------------------------===//
694/// PDLPatternModule API
695//===----------------------------------------------------------------------===//
696
697#if MLIR_ENABLE_PDL_IN_PATTERNMATCH
698DEFINE_C_API_STRUCT(MlirPDLPatternModule, void);
699DEFINE_C_API_STRUCT(MlirPDLValue, const void);
700DEFINE_C_API_STRUCT(MlirPDLResultList, void);
701
702MLIR_CAPI_EXPORTED MlirPDLPatternModule
703mlirPDLPatternModuleFromModule(MlirModule op);
704
705MLIR_CAPI_EXPORTED void mlirPDLPatternModuleDestroy(MlirPDLPatternModule op);
706
707MLIR_CAPI_EXPORTED MlirRewritePatternSet
708mlirRewritePatternSetFromPDLPatternModule(MlirPDLPatternModule op);
709
710/// Cast the MlirPDLValue to an MlirValue.
711/// Return a null value if the cast fails, just like llvm::dyn_cast.
712MLIR_CAPI_EXPORTED MlirValue mlirPDLValueAsValue(MlirPDLValue value);
713
714/// Cast the MlirPDLValue to an MlirType.
715/// Return a null value if the cast fails, just like llvm::dyn_cast.
716MLIR_CAPI_EXPORTED MlirType mlirPDLValueAsType(MlirPDLValue value);
717
718/// Cast the MlirPDLValue to an MlirOperation.
719/// Return a null value if the cast fails, just like llvm::dyn_cast.
720MLIR_CAPI_EXPORTED MlirOperation mlirPDLValueAsOperation(MlirPDLValue value);
721
722/// Cast the MlirPDLValue to an MlirAttribute.
723/// Return a null value if the cast fails, just like llvm::dyn_cast.
724MLIR_CAPI_EXPORTED MlirAttribute mlirPDLValueAsAttribute(MlirPDLValue value);
725
726/// Push the MlirValue into the given MlirPDLResultList.
728mlirPDLResultListPushBackValue(MlirPDLResultList results, MlirValue value);
729
730/// Push the MlirType into the given MlirPDLResultList.
731MLIR_CAPI_EXPORTED void mlirPDLResultListPushBackType(MlirPDLResultList results,
732 MlirType value);
733
734/// Push the MlirOperation into the given MlirPDLResultList.
736mlirPDLResultListPushBackOperation(MlirPDLResultList results,
737 MlirOperation value);
738
739/// Push the MlirAttribute into the given MlirPDLResultList.
741mlirPDLResultListPushBackAttribute(MlirPDLResultList results,
742 MlirAttribute value);
743
744/// This function type is used as callbacks for PDL native rewrite functions.
745/// Input values can be accessed by `values` with its size `nValues`;
746/// output values can be added into `results` by `mlirPDLResultListPushBack*`
747/// APIs. And the return value indicates whether the rewrite succeeds.
748typedef MlirLogicalResult (*MlirPDLRewriteFunction)(
749 MlirPatternRewriter rewriter, MlirPDLResultList results, size_t nValues,
750 MlirPDLValue *values, void *userData);
751
752/// Register a rewrite function into the given PDL pattern module.
753/// `userData` will be provided as an argument to the rewrite function.
754MLIR_CAPI_EXPORTED void mlirPDLPatternModuleRegisterRewriteFunction(
755 MlirPDLPatternModule pdlModule, MlirStringRef name,
756 MlirPDLRewriteFunction rewriteFn, void *userData);
757
758/// This function type is used as callbacks for PDL native constraint functions.
759/// Input values can be accessed by `values` with its size `nValues`;
760/// output values can be added into `results` by `mlirPDLResultListPushBack*`
761/// APIs. And the return value indicates whether the constraint holds.
762typedef MlirLogicalResult (*MlirPDLConstraintFunction)(
763 MlirPatternRewriter rewriter, MlirPDLResultList results, size_t nValues,
764 MlirPDLValue *values, void *userData);
765
766/// Register a constraint function into the given PDL pattern module.
767/// `userData` will be provided as an argument to the constraint function.
768MLIR_CAPI_EXPORTED void mlirPDLPatternModuleRegisterConstraintFunction(
769 MlirPDLPatternModule pdlModule, MlirStringRef name,
770 MlirPDLConstraintFunction constraintFn, void *userData);
771
772#endif // MLIR_ENABLE_PDL_IN_PATTERNMATCH
773
774#undef DEFINE_C_API_STRUCT
775
776#ifdef __cplusplus
777}
778#endif
779
780#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:196
MLIR_CAPI_EXPORTED void mlirConversionTargetDestroy(MlirConversionTarget target)
Destroy the given ConversionTarget.
Definition Rewrite.cpp:554
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:206
MLIR_CAPI_EXPORTED MlirContext mlirRewritePatternSetGetContext(MlirRewritePatternSet set)
Get the context associated with a MlirRewritePatternSet.
Definition Rewrite.cpp:798
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:145
MLIR_CAPI_EXPORTED void mlirRewriterBaseEraseBlock(MlirRewriterBase rewriter, MlirBlock block)
Erases a block along with all operations inside it.
Definition Rewrite.cpp:163
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:46
MLIR_CAPI_EXPORTED void mlirConversionTargetMarkUnknownOpDynamicallyLegal(MlirConversionTarget target, MlirConversionTargetDynamicLegalityCallback callback, void *userData)
Mark unknown operations as dynamically legal, with a callback.
Definition Rewrite.cpp:630
MLIR_CAPI_EXPORTED void mlirConversionTargetMarkOpRecursivelyLegal(MlirConversionTarget target, MlirStringRef opName, MlirConversionTargetDynamicLegalityCallback callback, void *userData)
Mark the given operation as recursively legal.
Definition Rewrite.cpp:619
MlirDialectConversionFoldingMode
Definition Rewrite.h:457
@ MLIR_DIALECT_CONVERSION_FOLDING_MODE_AFTER_PATTERNS
Definition Rewrite.h:460
@ MLIR_DIALECT_CONVERSION_FOLDING_MODE_BEFORE_PATTERNS
Definition Rewrite.h:459
@ MLIR_DIALECT_CONVERSION_FOLDING_MODE_NEVER
Definition Rewrite.h:458
MLIR_CAPI_EXPORTED MlirRewritePattern mlirConversionPatternAsRewritePattern(MlirConversionPattern pattern)
Cast the ConversionPattern to a RewritePattern.
Definition Rewrite.cpp:735
MLIR_CAPI_EXPORTED void mlirRewriterBaseCancelOpModification(MlirRewriterBase rewriter, MlirOperation op)
This method cancels a pending in-place modification.
Definition Rewrite.cpp:211
MLIR_CAPI_EXPORTED void mlirGreedyRewriteDriverConfigEnableConstantCSE(MlirGreedyRewriteDriverConfig config, bool enable)
Enables or disables constant CSE.
Definition Rewrite.cpp:374
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:51
MLIR_CAPI_EXPORTED MlirLogicalResult mlirApplyPartialConversion(MlirOperation op, MlirConversionTarget target, MlirFrozenRewritePatternSet patterns, MlirConversionConfig config)
Apply a partial conversion on the given operation.
Definition Rewrite.cpp:456
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:247
MLIR_CAPI_EXPORTED MlirOperation mlirRewriterBaseGetOperationAfterInsertion(MlirRewriterBase rewriter)
Returns the operation right after the current insertion point of the rewriter.
Definition Rewrite.cpp:80
MLIR_CAPI_EXPORTED void mlirRewriterBaseReplaceAllOpUsesWithOperation(MlirRewriterBase rewriter, MlirOperation from, MlirOperation to)
Find uses of from and replace them with to.
Definition Rewrite.cpp:241
MLIR_CAPI_EXPORTED MlirGreedySimplifyRegionLevel mlirGreedyRewriteDriverConfigGetRegionSimplificationLevel(MlirGreedyRewriteDriverConfig config)
Gets the region simplification level.
Definition Rewrite.cpp:414
MLIR_CAPI_EXPORTED MlirDialectConversionFoldingMode mlirConversionConfigGetFoldingMode(MlirConversionConfig config)
Get the folding mode for the given ConversionConfig.
Definition Rewrite.cpp:501
MLIR_CAPI_EXPORTED bool mlirConversionConfigIsBuildMaterializationsEnabled(MlirConversionConfig config)
Check if building materializations during conversion is enabled.
Definition Rewrite.cpp:517
MLIR_CAPI_EXPORTED MlirLogicalResult mlirApplyFullConversion(MlirOperation op, MlirConversionTarget target, MlirFrozenRewritePatternSet patterns, MlirConversionConfig config)
Apply a full conversion on the given operation.
Definition Rewrite.cpp:463
MLIR_CAPI_EXPORTED bool mlirGreedyRewriteDriverConfigIsFoldingEnabled(MlirGreedyRewriteDriverConfig config)
Gets whether folding is enabled during greedy rewriting.
Definition Rewrite.cpp:394
MLIR_CAPI_EXPORTED void mlirConversionConfigEnableBuildMaterializations(MlirConversionConfig config, bool enable)
Enable or disable building materializations during conversion.
Definition Rewrite.cpp:512
MLIR_CAPI_EXPORTED MlirGreedyRewriteDriverConfig mlirGreedyRewriteDriverConfigCreate(void)
GreedyRewriteDriverConfig API.
Definition Rewrite.cpp:310
MLIR_CAPI_EXPORTED bool mlirGreedyRewriteDriverConfigIsConstantCSEEnabled(MlirGreedyRewriteDriverConfig config)
Gets whether constant CSE is enabled.
Definition Rewrite.cpp:429
MLIR_CAPI_EXPORTED void mlirRewritePatternSetAdd(MlirRewritePatternSet set, MlirRewritePattern pattern)
Add the given MlirRewritePattern into a MlirRewritePatternSet.
Definition Rewrite.cpp:806
MLIR_CAPI_EXPORTED void mlirConversionTargetAddIllegalDialect(MlirConversionTarget target, MlirStringRef dialectName)
Register the operations of the given dialect as illegal.
Definition Rewrite.cpp:575
MLIR_CAPI_EXPORTED MlirOperation mlirRewriterBaseClone(MlirRewriterBase rewriter, MlirOperation op)
Creates a deep copy of the specified operation.
Definition Rewrite.cpp:114
#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 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:450
MLIR_CAPI_EXPORTED void mlirGreedyRewriteDriverConfigSetRegionSimplificationLevel(MlirGreedyRewriteDriverConfig config, MlirGreedySimplifyRegionLevel level)
Sets the region simplification level.
Definition Rewrite.cpp:357
MLIR_CAPI_EXPORTED MlirTypeConverter mlirTypeConverterCreate(void)
TypeConverter API.
Definition Rewrite.cpp:642
MLIR_CAPI_EXPORTED MlirOperation mlirRewriterBaseInsert(MlirRewriterBase rewriter, MlirOperation op)
Insert the given operation at the current insertion point and return it.
Definition Rewrite.cpp:107
MLIR_CAPI_EXPORTED void mlirConversionTargetAddLegalOp(MlirConversionTarget target, MlirStringRef opName)
Register the given operations as legal.
Definition Rewrite.cpp:558
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:221
MLIR_CAPI_EXPORTED MlirLogicalResult mlirApplyPatternsAndFoldGreedily(MlirModule op, MlirFrozenRewritePatternSet patterns, MlirGreedyRewriteDriverConfig config)
Definition Rewrite.cpp:435
MLIR_CAPI_EXPORTED void mlirGreedyRewriteDriverConfigDestroy(MlirGreedyRewriteDriverConfig config)
Destroys a greedy rewrite driver configuration.
Definition Rewrite.cpp:314
MLIR_CAPI_EXPORTED void mlirGreedyRewriteDriverConfigSetUseTopDownTraversal(MlirGreedyRewriteDriverConfig config, bool useTopDownTraversal)
Sets whether to use top-down traversal for the initial population of the worklist.
Definition Rewrite.cpp:329
MLIR_CAPI_EXPORTED void mlirRewriterBaseEraseOp(MlirRewriterBase rewriter, MlirOperation op)
Erases an operation that is known to have no uses.
Definition Rewrite.cpp:159
MLIR_CAPI_EXPORTED void mlirGreedyRewriteDriverConfigSetMaxIterations(MlirGreedyRewriteDriverConfig config, int64_t maxIterations)
Sets the maximum number of iterations for the greedy rewrite driver.
Definition Rewrite.cpp:319
MLIR_CAPI_EXPORTED MlirTypeConverter mlirConversionPatternGetTypeConverter(MlirConversionPattern pattern)
Get the type converter used by this conversion pattern.
Definition Rewrite.cpp:730
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:167
MLIR_CAPI_EXPORTED MlirPatternRewriter mlirConversionPatternRewriterAsPatternRewriter(MlirConversionPatternRewriter rewriter)
ConversionPatternRewriter API.
Definition Rewrite.cpp:534
MLIR_CAPI_EXPORTED MlirOperation mlirRewriterBaseCloneWithMapping(MlirRewriterBase rewriter, MlirOperation op, MlirIRMapping mapping)
Clones the given operation using the rewriter and the provided IRMapping.
Definition Rewrite.cpp:124
MLIR_CAPI_EXPORTED MlirConversionTarget mlirConversionTargetCreate(MlirContext context)
ConversionTarget API.
Definition Rewrite.cpp:550
MlirConversionTargetLegality
Result of a dynamic legality callback.
Definition Rewrite.h:537
@ MLIR_CONVERSION_TARGET_LEGALITY_LEGAL
The operation instance is legal.
Definition Rewrite.h:539
@ MLIR_CONVERSION_TARGET_LEGALITY_NO_OPINION
The callback has no opinion on this instance.
Definition Rewrite.h:545
@ MLIR_CONVERSION_TARGET_LEGALITY_ILLEGAL
The operation instance is illegal.
Definition Rewrite.h:541
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:776
MLIR_CAPI_EXPORTED void mlirConversionTargetAddIllegalOp(MlirConversionTarget target, MlirStringRef opName)
Register the given operations as illegal.
Definition Rewrite.cpp:564
MLIR_CAPI_EXPORTED MlirRewriterBase mlirIRRewriterCreateFromOp(MlirOperation op)
Create an IRRewriter and transfer ownership to the caller.
Definition Rewrite.cpp:273
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:201
MLIR_CAPI_EXPORTED void mlirConversionConfigSetFoldingMode(MlirConversionConfig config, MlirDialectConversionFoldingMode mode)
Set the folding mode for the given ConversionConfig.
Definition Rewrite.cpp:483
MLIR_CAPI_EXPORTED MlirContext mlirRewriterBaseGetContext(MlirRewriterBase rewriter)
RewriterBase API inherited from OpBuilder.
Definition Rewrite.cpp:34
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:153
MLIR_CAPI_EXPORTED int64_t mlirGreedyRewriteDriverConfigGetMaxIterations(MlirGreedyRewriteDriverConfig config)
Gets the maximum number of iterations for the greedy rewrite driver.
Definition Rewrite.cpp:379
MLIR_CAPI_EXPORTED MlirRewriterBase mlirIRRewriterCreate(MlirContext context)
IRRewriter API.
Definition Rewrite.cpp:269
MLIR_CAPI_EXPORTED MlirGreedyRewriteStrictness mlirGreedyRewriteDriverConfigGetStrictness(MlirGreedyRewriteDriverConfig config)
Gets the strictness level for the greedy rewrite driver.
Definition Rewrite.cpp:399
MLIR_CAPI_EXPORTED MlirBlock mlirRewriterBaseGetInsertionBlock(MlirRewriterBase rewriter)
Return the block the current insertion point belongs to.
Definition Rewrite.cpp:71
MLIR_CAPI_EXPORTED MlirType mlirTypeConverterConvertType(MlirTypeConverter typeConverter, MlirType type)
Convert the given type using the given TypeConverter.
Definition Rewrite.cpp:667
MLIR_CAPI_EXPORTED void mlirGreedyRewriteDriverConfigSetStrictness(MlirGreedyRewriteDriverConfig config, MlirGreedyRewriteStrictness strictness)
Sets the strictness level for the greedy rewrite driver.
Definition Rewrite.cpp:339
MLIR_CAPI_EXPORTED void mlirTypeConverterAddConversion(MlirTypeConverter typeConverter, MlirTypeConverterConversionCallback convertType, void *userData)
Add a type conversion function to the given TypeConverter.
Definition Rewrite.cpp:650
MLIR_CAPI_EXPORTED void mlirTypeConverterDestroy(MlirTypeConverter typeConverter)
Destroy the given TypeConverter.
Definition Rewrite.cpp:646
MLIR_CAPI_EXPORTED void mlirRewritePatternSetDestroy(MlirRewritePatternSet set)
Destruct the given MlirRewritePatternSet.
Definition Rewrite.cpp:802
MLIR_CAPI_EXPORTED void mlirRewriterBaseClearInsertionPoint(MlirRewriterBase rewriter)
Insertion points methods.
Definition Rewrite.cpp:42
MlirLogicalResult(* MlirTypeConverterConversionCallback)(MlirType type, MlirType *convertedType, void *userData)
Callback type for type conversion functions.
Definition Rewrite.h:595
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:191
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:130
MLIR_CAPI_EXPORTED MlirRewriterBase mlirPatternRewriterAsBase(MlirPatternRewriter rewriter)
PatternRewriter API.
Definition Rewrite.cpp:526
MLIR_CAPI_EXPORTED MlirLogicalResult mlirApplyPatternsAndFoldGreedilyWithOp(MlirOperation op, MlirFrozenRewritePatternSet patterns, MlirGreedyRewriteDriverConfig)
Definition Rewrite.cpp:443
MLIR_CAPI_EXPORTED bool mlirGreedyRewriteDriverConfigGetUseTopDownTraversal(MlirGreedyRewriteDriverConfig config)
Gets whether top-down traversal is used for initial worklist population.
Definition Rewrite.cpp:389
MLIR_CAPI_EXPORTED MlirRewritePatternSet mlirRewritePatternSetCreate(MlirContext context)
RewritePatternSet API.
Definition Rewrite.cpp:794
MLIR_CAPI_EXPORTED void mlirGreedyRewriteDriverConfigSetMaxNumRewrites(MlirGreedyRewriteDriverConfig config, int64_t maxNumRewrites)
Sets the maximum number of rewrites within an iteration.
Definition Rewrite.cpp:324
MLIR_CAPI_EXPORTED void mlirConversionConfigDestroy(MlirConversionConfig config)
Destroy the given ConversionConfig.
Definition Rewrite.cpp:479
MLIR_CAPI_EXPORTED void mlirRewriterBaseInlineRegionBefore(MlirRewriterBase rewriter, MlirRegion region, MlirBlock before)
RewriterBase API.
Definition Rewrite.cpp:140
MLIR_CAPI_EXPORTED MlirConversionConfig mlirConversionConfigCreate(void)
ConversionConfig API.
Definition Rewrite.cpp:475
MLIR_CAPI_EXPORTED MlirBlock mlirRewriterBaseGetBlock(MlirRewriterBase rewriter)
Returns the current block of the rewriter.
Definition Rewrite.cpp:75
MLIR_CAPI_EXPORTED void mlirRewriterBaseSetInsertionPointToEnd(MlirRewriterBase rewriter, MlirBlock block)
Sets the insertion point to the end of the specified block.
Definition Rewrite.cpp:66
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:258
MLIR_CAPI_EXPORTED void mlirGreedyRewriteDriverConfigEnableFolding(MlirGreedyRewriteDriverConfig config, bool enable)
Enables or disables folding during greedy rewriting.
Definition Rewrite.cpp:334
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:232
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:186
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:178
MLIR_CAPI_EXPORTED void mlirFrozenRewritePatternSetDestroy(MlirFrozenRewritePatternSet set)
Destroy the given MlirFrozenRewritePatternSet.
Definition Rewrite.cpp:292
MlirConversionTargetLegality(* MlirConversionTargetDynamicLegalityCallback)(MlirOperation op, void *userData)
Callback for dynamic legality checks.
Definition Rewrite.h:551
MLIR_CAPI_EXPORTED void mlirRewriterBaseSetInsertionPointAfterValue(MlirRewriterBase rewriter, MlirValue value)
Sets the insertion point to the node after the specified value.
Definition Rewrite.cpp:56
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:119
MLIR_CAPI_EXPORTED MlirFrozenRewritePatternSet mlirFreezeRewritePattern(MlirRewritePatternSet set)
FrozenRewritePatternSet API.
Definition Rewrite.cpp:286
MLIR_CAPI_EXPORTED void mlirConversionTargetAddDynamicallyLegalDialect(MlirConversionTarget target, MlirStringRef dialectName, MlirConversionTargetDynamicLegalityCallback callback, void *userData)
Register the given dialect as dynamically legal, with a callback to determine per-instance legality f...
Definition Rewrite.cpp:611
MLIR_CAPI_EXPORTED void mlirIRRewriterDestroy(MlirRewriterBase rewriter)
Takes an IRRewriter owned by the caller and destroys it.
Definition Rewrite.cpp:277
MlirGreedySimplifyRegionLevel
Greedy simplify region levels.
Definition Rewrite.h:51
@ MLIR_GREEDY_SIMPLIFY_REGION_LEVEL_DISABLED
Disable region control-flow simplification.
Definition Rewrite.h:53
@ MLIR_GREEDY_SIMPLIFY_REGION_LEVEL_NORMAL
Run the normal simplification (e.g. dead args elimination).
Definition Rewrite.h:55
@ MLIR_GREEDY_SIMPLIFY_REGION_LEVEL_AGGRESSIVE
Run extra simplifications (e.g. block merging).
Definition Rewrite.h:57
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:94
MLIR_CAPI_EXPORTED void mlirRewriterBaseReplaceAllUsesWith(MlirRewriterBase rewriter, MlirValue from, MlirValue to)
Find uses of from and replace them with to.
Definition Rewrite.cpp:216
MLIR_CAPI_EXPORTED MlirLogicalResult mlirConversionPatternRewriterConvertRegionTypes(MlirConversionPatternRewriter rewriter, MlirRegion region, MlirTypeConverter typeConverter)
Apply a signature conversion to each block in the given region.
Definition Rewrite.cpp:539
MLIR_CAPI_EXPORTED MlirConversionPattern mlirOpConversionPatternCreate(MlirStringRef rootName, unsigned benefit, MlirContext context, MlirTypeConverter typeConverter, MlirConversionPatternCallbacks callbacks, void *userData, size_t nGeneratedNames, MlirStringRef *generatedNames)
Create a conversion pattern that matches the operation with the given rootName, corresponding to mlir...
Definition Rewrite.cpp:716
MlirGreedyRewriteStrictness
Greedy rewrite strictness levels.
Definition Rewrite.h:41
@ MLIR_GREEDY_REWRITE_STRICTNESS_EXISTING_AND_NEW_OPS
Only pre-existing and newly created ops are processed.
Definition Rewrite.h:45
@ MLIR_GREEDY_REWRITE_STRICTNESS_EXISTING_OPS
Only pre-existing ops are processed.
Definition Rewrite.h:47
@ MLIR_GREEDY_REWRITE_STRICTNESS_ANY_OP
No restrictions wrt. which ops are processed.
Definition Rewrite.h:43
MLIR_CAPI_EXPORTED void mlirConversionTargetAddDynamicallyLegalOp(MlirConversionTarget target, MlirStringRef opName, MlirConversionTargetDynamicLegalityCallback callback, void *userData)
Register the given operation as dynamically legal, with a callback to determine per-instance legality...
Definition Rewrite.cpp:601
MLIR_CAPI_EXPORTED void mlirConversionTargetAddLegalDialect(MlirConversionTarget target, MlirStringRef dialectName)
Register the operations of the given dialect as legal.
Definition Rewrite.cpp:570
MLIR_CAPI_EXPORTED void mlirRewriterBaseSetInsertionPointToStart(MlirRewriterBase rewriter, MlirBlock block)
Sets the insertion point to the start of the specified block.
Definition Rewrite.cpp:61
MLIR_CAPI_EXPORTED int64_t mlirGreedyRewriteDriverConfigGetMaxNumRewrites(MlirGreedyRewriteDriverConfig config)
Gets the maximum number of rewrites within an iteration.
Definition Rewrite.cpp:384
struct MlirLogicalResult MlirLogicalResult
Definition Support.h:124
#define MLIR_CAPI_EXPORTED
Definition Support.h:46
ConversionPattern API.
Definition Rewrite.h:612
MlirLogicalResult(* matchAndRewrite)(MlirConversionPattern pattern, MlirOperation op, intptr_t nOperands, MlirValue *operands, MlirConversionPatternRewriter rewriter, void *userData)
The callback function to match against code rooted at the specified operation, and perform the conver...
Definition Rewrite.h:622
void(* construct)(void *userData)
Optional constructor for the user data.
Definition Rewrite.h:615
void(* destruct)(void *userData)
Optional destructor for the user data.
Definition Rewrite.h:618
A logical result value, essentially a boolean with named states.
Definition Support.h:121
RewritePattern API.
Definition Rewrite.h:649
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:659
void(* construct)(void *userData)
Optional constructor for the user data.
Definition Rewrite.h:652
void(* destruct)(void *userData)
Optional destructor for the user data.
Definition Rewrite.h:655
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition Support.h:78