aboutsummaryrefslogtreecommitdiff
path: root/mlir/lib/Transforms/Canonicalizer.cpp
AgeCommit message (Collapse)AuthorFilesLines
10 days[mlir][Transforms] Remove UB dialect dependency from Canonicalizer pass ↵Hideto Ueno1-1/+0
(#150555) The Canonicalizer pass has a dependency to UB dialect which shouldn't have. It also no longer needs to directly depend on the UB dialect since the Vector dialect (which uses UB dialect for poison index operations introduced by 35df525) already declares this dependency(878d3594).
2025-04-24[mlir] add a fluent API to GreedyRewriterConfig (#137122)Oleksandr "Alex" Zinenko1-8/+8
This is similar to other configuration objects used across MLIR. Rename some fields to better reflect that they are no longer booleans. Reland 04d261101b4f229189463136a794e3e362a793af / #132253.
2025-04-18Revert "[mlir] add a fluent API to GreedyRewriterConfig (#132253)"Kazu Hirata1-8/+8
This reverts commit 63b8f1c9482ed0a964980df4aed89bef922b8078. Buildbot failure: https://lab.llvm.org/buildbot/#/builders/172/builds/12083/steps/5/logs/stdio I've reproduced the error with a release build (-DCMAKE_BUILD_TYPE=Release).
2025-04-18[mlir] add a fluent API to GreedyRewriterConfig (#132253)Oleksandr "Alex" Zinenko1-8/+8
This is similar to other configuration objects used across MLIR.
2025-01-28[mlir][Vector] Add support for poison indices to `Extract/IndexOp` (#123488)Diego Caballero1-0/+1
Following up on #122188, this PR adds support for poison indices to `ExtractOp` and `InsertOp`. It also includes canonicalization patterns to turn extract/insert ops with poison indices into `ub.poison`.
2024-12-20[mlir] Enable decoupling two kinds of greedy behavior. (#104649)Jacques Pienaar1-1/+1
The greedy rewriter is used in many different flows and it has a lot of convenience (work list management, debugging actions, tracing, etc). But it combines two kinds of greedy behavior 1) how ops are matched, 2) folding wherever it can. These are independent forms of greedy and leads to inefficiency. E.g., cases where one need to create different phases in lowering and is required to applying patterns in specific order split across different passes. Using the driver one ends up needlessly retrying folding/having multiple rounds of folding attempts, where one final run would have sufficed. Of course folks can locally avoid this behavior by just building their own, but this is also a common requested feature that folks keep on working around locally in suboptimal ways. For downstream users, there should be no behavioral change. Updating from the deprecated should just be a find and replace (e.g., `find ./ -type f -exec sed -i 's|applyPatternsAndFoldGreedily|applyPatternsGreedily|g' {} \;` variety) as the API arguments hasn't changed between the two.
2023-08-22Fix canonicalizer to copy the entire GreedyRewriteConfig instead of selected ↵Mehdi Amini1-11/+13
fields It is surprising for the user that only some fields were honored. Also make the FrozenRewritePatternSet a shared_ptr<const T>. Fixes #64543 Differential Revision: https://reviews.llvm.org/D157469
2023-08-09Revert "Fix canonicalizer to copy the entire GreedyRewriteConfig instead of ↵Mehdi Amini1-13/+11
selected fields" This reverts commit e468c60c96e1af1945179c2ca80b7a9dfcd38398. Flang is broken, investigating...
2023-08-09Fix canonicalizer to copy the entire GreedyRewriteConfig instead of selected ↵Mehdi Amini1-11/+13
fields It is surprising for the user that only some fields were honored. Also make the FrozenRewritePatternSet a shared_ptr<const T>. Fixes #64543 Differential Revision: https://reviews.llvm.org/D157469
2023-01-04[mlir] Add `test-convergence` option to Canonicalizer testsMatthias Springer1-1/+4
This new option is set to `false` by default. It should be set only in Canonicalizer tests to detect faulty canonicalization patterns. I.e., patterns that prevent the canonicalizer from converging. The canonicalizer should always convergence on such small unit tests that we have in `canonicalize.mlir`. Two faulty canonicalization patterns were detected and fixed with this change. Differential Revision: https://reviews.llvm.org/D140873
2023-01-03[mlir][transforms][NFC] Expand CanonicalizerPass documentationMatthias Springer1-0/+1
Mention that canonicalization is best-effort and that pass pipelines should not rely on it for correctness. RFC: https://discourse.llvm.org/t/rfc-canonicalizerpass-convergence-error-handling/67333 Differential Revision: https://reviews.llvm.org/D140729
2022-12-23[mlir] Add option to limit number of pattern rewrites in CanonicalizerPassMatthias Springer1-0/+2
The greedy pattern rewriter consists of two nested loops. `config.maxIterations` (which configurable on the CanonicalizerPass) controls the maximum number of iterations of the outer loop. ``` /// This specifies the maximum number of times the rewriter will iterate /// between applying patterns and simplifying regions. Use `kNoLimit` to /// disable this iteration limit. int64_t maxIterations = 10; ``` This change adds `config.maxNumRewrites` which controls the maximum number of pattern rewrites within an iteration. (It effectively control the maximum number of iterations of the inner loop.) This flag is meant for debugging and useful in cases where one or multiple faulty patterns can be applied indefinitely, resulting in an infinite loop. Differential Revision: https://reviews.llvm.org/D140525
2022-08-31[MLIR] Update pass declarations to new autogenerated filesMichele Scuttari1-3/+8
The patch introduces the required changes to update the pass declarations and definitions to use the new autogenerated files and allow dropping the old infrastructure. Reviewed By: mehdi_amini, rriddle Differential Review: https://reviews.llvm.org/D132838
2022-08-30Revert "[MLIR] Update pass declarations to new autogenerated files"Michele Scuttari1-16/+10
This reverts commit 2be8af8f0e0780901213b6fd3013a5268ddc3359.
2022-08-30[MLIR] Update pass declarations to new autogenerated filesMichele Scuttari1-10/+16
The patch introduces the required changes to update the pass declarations and definitions to use the new autogenerated files and allow dropping the old infrastructure. Reviewed By: mehdi_amini, rriddle Differential Review: https://reviews.llvm.org/D132838
2022-05-18[mlir][Canonicalize] Fix command-line optionsrkayaith1-13/+10
The canonicalize command-line options currently have no effect, as the pass is reading the pass options in its constructor, before they're actually initialized. This results in the default values of the options always being used. The change here moves the initialization of the `GreedyRewriteConfig` out of the constructor, so that it runs after the pass options have been parsed. Fixes #55466 Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D125621
2021-12-22[mlir] Fix missing namespace (NFC)Mogball1-3/+3
2021-12-22[mlir] Canonicalizer constructor should accept disabled/enabled patternsMogball1-3/+12
There is no way to programmatically configure the list of disabled and enabled patterns in the canonicalizer pass, other than the duplicate the whole pass. This patch exposes the `disabledPatterns` and `enabledPatterns` options. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D116055
2021-12-08Adjust "end namespace" comment in MLIR to match new agree'd coding styleMehdi Amini1-1/+1
See D115115 and this mailing list discussion: https://lists.llvm.org/pipermail/llvm-dev/2021-December/154199.html Differential Revision: https://reviews.llvm.org/D115309
2021-11-17[mlir] Refactor AbstractOperation and OperationNameRiver Riddle1-2/+2
The current implementation is quite clunky; OperationName stores either an Identifier or an AbstractOperation that corresponds to an operation. This has several problems: * OperationNames created before and after an operation are registered are different * Accessing the identifier name/dialect/etc. from an OperationName are overly branchy - they need to dyn_cast a PointerUnion to check the state This commit refactors this such that we create a single information struct for every operation name, even operations that aren't registered yet. When an OperationName is created for an unregistered operation, we only populate the name field. When the operation is registered, we populate the remaining fields. With this we now have two new classes: OperationName and RegisteredOperationName. These both point to the same underlying operation information struct, but only RegisteredOperationName can assume that the operation is actually registered. This leads to a much cleaner API, and we can also move some AbstractOperation functionality directly to OperationName. Differential Revision: https://reviews.llvm.org/D114049
2021-06-02[mlir] Add support for filtering patterns based on debug names and labelsRiver Riddle1-1/+3
This revision allows for attaching "debug labels" to patterns, and provides to FrozenRewritePatternSet for filtering patterns based on these labels (in addition to the debug name of the pattern). This will greatly simplify the ability to write tests targeted towards specific patterns (in cases where many patterns may interact), will also simplify debugging pattern application by observing how application changes when enabling/disabling specific patterns. To enable better reuse of pattern rewrite options between passes, this revision also adds a new PassUtil.td file to the Rewrite/ library that will allow for passes to easily hook into a common interface for pattern debugging. Two options are used to seed this utility, `disable-patterns` and `enable-patterns`, which are used to enable the filtering behavior indicated above. Differential Revision: https://reviews.llvm.org/D102441
2021-05-28[mlir] Add missing namespace to createCanonicalizerPass.Jacques Pienaar1-1/+1
2021-05-27[mlir] Support dialect-wide canonicalization pattern registrationMatthias Springer1-0/+2
* Add `hasCanonicalizer` option to Dialect. * Initialize canonicalizer with dialect-wide canonicalization patterns. * Add test case to TestDialect. Dialect-wide canonicalization patterns are useful if a canonicalization pattern does not conceptually associate with any single operation, i.e., it should not be registered as part of an operation's `getCanonicalizationPatterns` function. E.g., this is the case for canonicalization patterns that match an op interface. Differential Revision: https://reviews.llvm.org/D103226
2021-05-25[Canonicalize] Fully parameterize the pass based on config options. NFC.Chris Lattner1-2/+17
This allows C++ clients of the Canonicalize pass to specify their own Config option struct to control how Canonicalize works, increasing reusability. This also allows controlling these settings for the default Canonicalize pass using command line options. This is useful for testing and for playing with things on the command line. Differential Revision: https://reviews.llvm.org/D103069
2021-05-24[GreedyPatternRewriter] Introduce a config object that allows controlling ↵Chris Lattner1-4/+4
internal parameters. NFC. This exposes the iterations and top-down processing as flags, and also allows controlling whether region simplification is desirable for a client. This allows deleting some duplicated entrypoints to applyPatternsAndFoldGreedily. This also deletes the Constant Preprocessing pass, which isn't worth it on balance. All defaults are all kept the same, so no one should see a behavior change. Differential Revision: https://reviews.llvm.org/D102988
2021-05-17Merge with mainline.Chris Lattner1-1/+4
Differential Revision: https://reviews.llvm.org/D102636
2021-05-17[WIP][mlir] Resolve memref dependency in canonicalize pass.Julian Gross1-1/+0
Splitting the memref dialect lead to an introduction of several dependencies to avoid compilation issues. The canonicalize pass also depends on the memref dialect, but it shouldn't. This patch resolves the dependencies and the unintuitive includes are removed. However, the dependency moves to the constructor of the std dialect. Differential Revision: https://reviews.llvm.org/D102060
2021-03-22Rename FrozenRewritePatternList -> FrozenRewritePatternSet; NFC.Chris Lattner1-1/+1
This nicely aligns the naming with RewritePatternSet. This type isn't as widely used, but we keep a using declaration in to help with downstream consumption of this change. Differential Revision: https://reviews.llvm.org/D99131
2021-03-22[PatternMatch] Big mechanical rename OwningRewritePatternList -> ↵Chris Lattner1-1/+1
RewritePatternSet and insert -> add. NFC This doesn't change APIs, this just cleans up the many in-tree uses of these names to use the new preferred names. We'll keep the old names around for a couple weeks to help transitions. Differential Revision: https://reviews.llvm.org/D99127
2021-03-21Change OwningRewritePatternList to carry an MLIRContext with it.Chris Lattner1-1/+1
This updates the codebase to pass the context when creating an instance of OwningRewritePatternList, and starts removing extraneous MLIRContext parameters. There are many many more to be removed. Differential Revision: https://reviews.llvm.org/D99028
2021-03-15[MLIR] Create memref dialect and move dialect-specific ops from std.Julian Gross1-0/+1
Create the memref dialect and move dialect-specific ops from std dialect to this dialect. Moved ops: AllocOp -> MemRef_AllocOp AllocaOp -> MemRef_AllocaOp AssumeAlignmentOp -> MemRef_AssumeAlignmentOp DeallocOp -> MemRef_DeallocOp DimOp -> MemRef_DimOp MemRefCastOp -> MemRef_CastOp MemRefReinterpretCastOp -> MemRef_ReinterpretCastOp GetGlobalMemRefOp -> MemRef_GetGlobalOp GlobalMemRefOp -> MemRef_GlobalOp LoadOp -> MemRef_LoadOp PrefetchOp -> MemRef_PrefetchOp ReshapeOp -> MemRef_ReshapeOp StoreOp -> MemRef_StoreOp SubViewOp -> MemRef_SubViewOp TransposeOp -> MemRef_TransposeOp TensorLoadOp -> MemRef_TensorLoadOp TensorStoreOp -> MemRef_TensorStoreOp TensorToMemRefOp -> MemRef_BufferCastOp ViewOp -> MemRef_ViewOp The roadmap to split the memref dialect from std is discussed here: https://llvm.discourse.group/t/rfc-split-the-memref-dialect-from-std/2667 Differential Revision: https://reviews.llvm.org/D98041
2021-02-11Enable `Pass::initialize()` to fail by returning a LogicalResultMehdi Amini1-1/+2
Differential Revision: https://reviews.llvm.org/D96474
2021-02-04[mlir] Mark LogicalResult as LLVM_NODISCARDRiver Riddle1-1/+1
This makes ignoring a result explicit by the user, and helps to prevent accidental errors with dropped results. Marking LogicalResult as no discard was always the intention from the beginning, but got lost along the way. Differential Revision: https://reviews.llvm.org/D95841
2021-01-08[mlir] Add a hook for initializing passes before execution and use it in the ↵River Riddle1-11/+11
Canonicalizer This revision adds a new `initialize(MLIRContext *)` hook to passes that allows for them to initialize any heavy state before the first execution of the pass. A concrete use case of this is with patterns that rely on PDL, given that PDL is compiled at run time it is imperative that compilation results are cached as much as possible. The first use of this hook is in the Canonicalizer, which has the added benefit of reducing the number of expensive accesses to the context when collecting patterns. Differential Revision: https://reviews.llvm.org/D93147
2020-10-26[mlir][Pattern] Add a new FrozenRewritePatternList classRiver Riddle1-1/+1
This class represents a rewrite pattern list that has been frozen, and thus immutable. This replaces the uses of OwningRewritePatternList in pattern driver related API, such as dialect conversion. When PDL becomes more prevalent, this API will allow for optimizing a set of patterns once without the need to do this per run of a pass. Differential Revision: https://reviews.llvm.org/D89104
2020-10-26[mlir][NFC] Move around the code related to PatternRewriting to improve layeringRiver Riddle1-1/+1
There are several pieces of pattern rewriting infra in IR/ that really shouldn't be there. This revision moves those pieces to a better location such that they are easier to evolve in the future(e.g. with PDL). More concretely this revision does the following: * Create a Transforms/GreedyPatternRewriteDriver.h and move the apply*andFold methods there. The definitions for these methods are already in Transforms/ so it doesn't make sense for the declarations to be in IR. * Create a new lib/Rewrite library and move PatternApplicator there. This new library will be focused on applying rewrites, and will also include compiling rewrites with PDL. Differential Revision: https://reviews.llvm.org/D89103
2020-04-10[MLIR][NFC] applyPatternsGreedily -> applyPatternsAndFoldGreedilyUday Bondhugula1-1/+1
Rename mlir::applyPatternsGreedily -> applyPatternsAndFoldGreedily. The new name is a more accurate description of the method - it performs both, application of the specified patterns and folding of all ops in the op's region irrespective of whether any patterns have been supplied. Differential Revision: https://reviews.llvm.org/D77478
2020-04-07[mlir][Pass] Update the PassGen to generate base classes instead of utilitiesRiver Riddle1-5/+2
Summary: This is much cleaner, and fits the same structure as many other tablegen backends. This was not done originally as the CRTP in the pass classes made it overly verbose/complex. Differential Revision: https://reviews.llvm.org/D77367
2020-04-07[mlir][Pass] Remove the use of CRTP from the Pass classesRiver Riddle1-1/+1
This revision removes all of the CRTP from the pass hierarchy in preparation for using the tablegen backend instead. This creates a much cleaner interface in the C++ code, and naturally fits with the rest of the infrastructure. A new utility class, PassWrapper, is added to replicate the existing behavior for passes not suitable for using the tablegen backend. Differential Revision: https://reviews.llvm.org/D77350
2020-04-01[mlir][Pass] Add support for generating pass utilities via tablegenRiver Riddle1-0/+4
This revision adds support for generating utilities for passes such as options/statistics/etc. that can be inferred from the tablegen definition. This removes additional boilerplate from the pass, and also makes it easier to remove the reliance on the pass registry to provide certain things(e.g. the pass argument). Differential Revision: https://reviews.llvm.org/D76659
2020-04-01[mlir][Pass] Add a tablegen backend for defining Pass informationRiver Riddle1-3/+0
This will greatly simplify a number of things related to passes: * Enables generation of pass registration * Enables generation of boiler plate pass utilities * Enables generation of pass documentation This revision focuses on adding the basic structure and adds support for generating the registration for passes in the Transforms/ directory. Future revisions will add more support and move more passes over. Differential Revision: https://reviews.llvm.org/D76656
2020-03-27[MLIR][NFC] drop some unnecessary includesUday Bondhugula1-1/+1
Drop unnecessary includes Differential Revision: https://reviews.llvm.org/D76898
2020-01-26Mass update the MLIR license header to mention "Part of the LLVM project"Mehdi Amini1-1/+1
This is an artifact from merging MLIR into LLVM, the file headers are now aligned with the rest of the project.
2019-12-23Adjust License.txt file to use the LLVM licenseMehdi Amini1-13/+4
PiperOrigin-RevId: 286906740
2019-10-24Convert the Canonicalize and CSE passes to generic Operation Passes.River Riddle1-23/+16
This allows for them to be used on other non-function, or even other function-like, operations. The algorithms are already generic, so this is simply changing the derived pass type. The majority of this change is just ensuring that the nesting of these passes remains the same, as the pass manager won't auto-nest them anymore. PiperOrigin-RevId: 276573038
2019-09-13NFC: Finish replacing FunctionPassBase/ModulePassBase with OpPassBase.River Riddle1-1/+1
These directives were temporary during the generalization of FunctionPass/ModulePass to OpPass. PiperOrigin-RevId: 268970259
2019-08-17Change from llvm::make_unique to std::make_uniqueJacques Pienaar1-1/+1
Switch to C++14 standard method as llvm::make_unique has been removed ( https://reviews.llvm.org/D66259). Also mark some targets as c++14 to ease next integrates. PiperOrigin-RevId: 263953918
2019-08-12Express ownership transfer in PassManager API through std::unique_ptr (NFC)Mehdi Amini1-2/+2
Since raw pointers are always passed around for IR construct without implying any ownership transfer, it can be error prone to have implicit ownership transferred the same way. For example this code can seem harmless: Pass *pass = .... pm.addPass(pass); pm.addPass(pass); pm.run(module); PiperOrigin-RevId: 263053082
2019-08-09NFC: Update usages of OwningRewritePatternList to pass by & instead of &&.River Riddle1-1/+1
This will allow for reusing the same pattern list, which may be costly to continually reconstruct, on multiple invocations. PiperOrigin-RevId: 262664599
2019-07-01NFC: Refactor Function to be value typed.River Riddle1-1/+1
Move the data members out of Function and into a new impl storage class 'FunctionStorage'. This allows for Function to become value typed, which will greatly simplify the transition of Function to FuncOp(given that FuncOp is also value typed). PiperOrigin-RevId: 255983022