summaryrefslogtreecommitdiff
path: root/mlir/test/lib/Dialect/SCF/TestSCFUtils.cpp
AgeCommit message (Collapse)Author
2025-09-17[MLIR] Add a getStaticTripCount method to LoopLikeOpInterface (#158679)Mehdi Amini
This patch adds a `getStaticTripCount` to the LoopLikeOpInterface, allowing loops to optionally return a static trip count when possible. This is implemented on SCF ForOp, revamping the implementation of `constantTripCount`, removing redundant duplicate implementations from SCF.cpp.
2025-07-25[mlir][NFC] update `mlir/Dialect` create APIs (28/n) (#150641)Maksim Levental
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-05-06[mlir] Remove unused local variables (NFC) (#138642)Kazu Hirata
2024-12-20[mlir] Enable decoupling two kinds of greedy behavior. (#104649)Jacques Pienaar
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.
2024-12-20[mlir] fix crash when scf utils work on llvm.func (#120688)donald chen
fixed https://github.com/llvm/llvm-project/issues/119378
2024-09-04[MLIR][SCF] Add support for loop pipeline peeling for dynamic loops. (#106436)SJW
Allow speculative execution and predicate results per stage.
2024-01-25[mlir][IR] Add rewriter API for moving operations (#78988)Matthias Springer
The pattern rewriter documentation states that "*all* IR mutations [...] are required to be performed via the `PatternRewriter`." This commit adds two functions that were missing from the rewriter API: `moveOpBefore` and `moveOpAfter`. After an operation was moved, the `notifyOperationInserted` callback is triggered. This allows listeners such as the greedy pattern rewrite driver to react to IR changes. This commit narrows the discrepancy between the kind of IR modification that can be performed and the kind of IR modifications that can be listened to.
2023-12-10[MLIR][SCF] Add support for pipelining dynamic loops (#74350)Thomas Raoux
Support loops without static boundaries. Since the number of iteration is not known we need to predicate prologue and epilogue in case the number of iterations is smaller than the number of stages. This patch includes work from @chengjunlu
2023-10-16[mlir][Interfaces] `LoopLikeOpInterface`: Add helper to get yielded values ↵Matthias Springer
(#67305) Add a new interface method that returns the yielded values. Also add a verifier that checks the number of inits/iter_args/yielded values. Most of the checked invariants (but not all of them) are already covered by the `RegionBranchOpInterface`, but the `LoopLikeOpInterface` now provides (additional) error messages that are easier to read.
2023-09-27[mlir][Interfaces] `LoopLikeOpInterface`: Add `replaceWithAdditionalYields` ↵Matthias Springer
(#67121) `affine::replaceForOpWithNewYields` and `replaceLoopWithNewYields` (for "scf.for") are now interface methods and additional loop-carried variables can now be added to "scf.for"/"affine.for" uniformly. (No more `TypeSwitch` needed.) Note: `scf.while` and other loops with loop-carried variables can implement `replaceWithAdditionalYields`, but to keep this commit small, that is not done in this commit.
2023-07-18[mlir] NFC: untangle SCF Patterns.h and Transforms.hAlex Zinenko
These two headers both contained a strange mix of definitions related to both patterns and non-pattern transforms. Put patterns and "populate" functions into Patterns.h and standalone transforms into Transforms.h. Depends On: D155223 Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D155454
2023-03-14[mlir][Transform] NFC - Various API cleanups and use RewriterBase in lieu of ↵Nicolas Vasilache
PatternRewriter Depends on: D145685 Differential Revision: https://reviews.llvm.org/D145977
2023-02-01[mlir][scf] Fix typo in description of option of TestSCFForUtilsPass (NFC).Ingo Müller
Reviewed By: ingomueller-net Differential Revision: https://reviews.llvm.org/D143067
2023-01-13[mlir] GreedyPatternRewriter: Add ancestors to worklistMatthias Springer
When adding an op to the worklist, also add its ancestors to the worklist. This allows for RewritePatterns to match an op `a` based on what is inside of the body of `a`. This change fixes a problem that became apparent with `vector.warp_execute_on_lane_0`, but could probably be triggered with similar patterns. The pattern extracts an op `b` with `eligible = true` from the body of an op `a`: ``` test.a { %0 = test.b() {eligible = true} yield %0 } ``` Afterwards: ``` %0 = test.b() {eligible = true} test.a { yield %0 } ``` The pattern is an `OpRewritePattern<OpA>`. For some reason, `test.a` is not on the GreedyPatternRewriter's worklist. E.g., because no pattern could be applied and it was removed. Now, another pattern updates `test.b`, so that `eligible` is changed from `true` to `false`. The `OpRewritePattern<OpA>` could now be applied, but (without this revision) `test.a` is still not on the worklist. Note: In the above example, an `OpRewritePattern<OpB>` could have been used instead of an `OpRewritePattern<OpA>`. With such a design, we can run into the same problem (when the `eligible` attr is on `test.a` and `test.b` is removed from the worklist because no patterns could be applied). Note: This change uncovered an unrelated bug in TestSCFUtils.cpp that was triggered due to a change in the order in which ops are processed. A TODO is added to the broken code and test cases are adapted so that the bug is no longer triggered. Differential Revision: https://reviews.llvm.org/D140304
2022-09-29[mlir][arith] Change dialect name from Arithmetic to ArithJakub Kuderski
Suggested by @lattner in https://discourse.llvm.org/t/rfc-define-precise-arith-semantics/65507/22. Tested with: `ninja check-mlir check-mlir-integration check-mlir-mlir-spirv-cpu-runner check-mlir-mlir-vulkan-runner check-mlir-examples` and `bazel build --config=generic_clang @llvm-project//mlir:all`. Reviewed By: lattner, Mogball, rriddle, jpienaar, mehdi_amini Differential Revision: https://reviews.llvm.org/D134762
2022-09-20[mlir][SCF] Fix loop pipelining unable to handle ops with regionsChristopher Bate
This change allows the SCF LoopPipelining transform to handle ops with nested regions within the pipelined `scf.for` body. The op and nested regions are treated as a single unit from the transform's perspective. This change also makes explicit the requirement that only ops whose parent Block is the loop body Block are allowed to be scheduled by the caller. Reviewed By: ThomasRaoux, nicolasvasilache Differential Revision: https://reviews.llvm.org/D133965
2022-09-17[mlir] Don't include SetVector.h (NFC)Kazu Hirata
2022-06-20[mlir] move SCF headers to SCF/{IR,Transforms} respectivelyAlex Zinenko
This aligns the SCF dialect file layout with the majority of the dialects. Reviewed By: jpienaar Differential Revision: https://reviews.llvm.org/D128049
2022-06-03[mlir][scf] Add option to loop pipelining to not peel the epilogueThomas Raoux
Add an option to predicate the epilogue within the kernel instead of peeling the epilogue. This is a useful option to prevent generating large amount of code for deep pipeline. This currently require a user lamdba to implement operation predication. Differential Revision: https://reviews.llvm.org/D126753
2022-05-10[mlir][SCF] Retire `cloneWithNewYields` helper function.Nicolas Vasilache
This is now subsumed by `replaceLoopWithNewYields`. Differential Revision: https://reviews.llvm.org/D125309
2022-05-10[mlir][SCF] Add utility method to add new yield values to a loop.Mahesh Ravishankar
The current implementation of `cloneWithNewYields` has a few issues - It clones the loop body of the original loop to create a new loop. This is very expensive. - It performs `erase` operations which are incompatible when this method is called from within a pattern rewrite. All erases need to go through `PatternRewriter`. To address these a new utility method `replaceLoopWithNewYields` is added which - moves the operations from the original loop into the new loop. - replaces all uses of the original loop with the corresponding results of the new loop - use a call back to allow caller to generate the new yield values. - the original loop is modified to just yield the basic block arguments corresponding to the iter_args of the loop. This represents a no-op loop. The loop itself is dead (since all its uses are replaced), but is not removed. The caller is expected to erase the op. Consequently, this method can be called from within a `matchAndRewrite` method of a `PatternRewriter`. The `cloneWithNewYields` could be replaces with `replaceLoopWithNewYields`, but that seems to trigger a failure during walks, potentially due to the operations being moved. That is left as a TODO. Differential Revision: https://reviews.llvm.org/D125147
2022-04-18[mlir:NFC] Remove the forward declaration of FuncOp in the mlir namespaceRiver Riddle
FuncOp has been moved to the `func` namespace for a little over a month, the using directive can be dropped now.
2022-04-04[mlir] Rework the implementation of TypeIDRiver Riddle
This commit restructures how TypeID is implemented to ideally avoid the current problems related to shared libraries. This is done by changing the "implicit" fallback path to use the name of the type, instead of using a static template variable (which breaks shared libraries). The major downside to this is that it adds some additional initialization costs for the implicit path. Given the use of type names for uniqueness in the fallback, we also no longer allow types defined in anonymous namespaces to have an implicit TypeID. To simplify defining an ID for these classes, a new `MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID` macro was added to allow for explicitly defining a TypeID directly on an internal class. To help identify when types are using the fallback, `-debug-only=typeid` can be used to log which types are using implicit ids. This change generally only requires changes to the test passes, which are all defined in anonymous namespaces, and thus can't use the fallback any longer. Differential Revision: https://reviews.llvm.org/D122775
2022-03-28[mlir] Simplify LoopLikeOpInterfaceMogball
- Adds default implementations of `isDefinedOutsideOfLoop` and `moveOutOfLoop` since 99% of all implementations of these functions were identical - `moveOutOfLoop` takes one operation and doesn't return anything anymore. 100% of all implementations of this function would always return `success` and uses would either respond with a pass failure or an `llvm_unreachable`.
2022-03-16[mlir] Move the Builtin FuncOp to the Func dialectRiver Riddle
This commit moves FuncOp out of the builtin dialect, and into the Func dialect. This move has been planned in some capacity from the moment we made FuncOp an operation (years ago). This commit handles the functional aspects of the move, but various aspects are left untouched to ease migration: func::FuncOp is re-exported into mlir to reduce the actual API churn, the assembly format still accepts the unqualified `func`. These temporary measures will remain for a little while to simplify migration before being removed. Differential Revision: https://reviews.llvm.org/D121266
2022-03-01[mlir] Trim a huge number of unnecessary dependencies on the Func dialectRiver Riddle
The Func has a large number of legacy dependencies carried over from the old Standard dialect, which was pervasive and contained a large number of varied operations. With the split of the standard dialect and its demise, a lot of lingering dead dependencies have survived to the Func dialect. This commit removes a large majority of then, greatly reducing the dependence surface area of the Func dialect.
2022-03-01[mlir] Rename the Standard dialect to the Func dialectRiver Riddle
The last remaining operations in the standard dialect all revolve around FuncOp/function related constructs. This patch simply handles the initial renaming (which by itself is already huge), but there are a large number of cleanups unlocked/necessary afterwards: * Removing a bunch of unnecessary dependencies on Func * Cleaning up the From/ToStandard conversion passes * Preparing for the move of FuncOp to the Func dialect See the discussion at https://discourse.llvm.org/t/standard-dialect-the-final-chapter/6061 Differential Revision: https://reviews.llvm.org/D120624
2022-02-15[mlir][scf] Add callback to annotate ops during pipeliningThomas Raoux
This allow user to register a callback that can annotate operations during software pipelining. This allows user potential annotate op to know what part of the pipeline they correspond to. Differential Revision: https://reviews.llvm.org/D119866
2022-02-11Remove spurious includes and dependencies from Bazel files (NFC)Mehdi Amini
Differential Revision: https://reviews.llvm.org/D119526
2022-01-28[mlir] Move SCF utils implementations to SCF/Utils.Adrian Kuegel
BEGIN_PUBLIC [mlir] Move SCF utils implementations to SCF/Utils. END_PUBLIC
2022-01-18[mlir][Pass] Deprecate FunctionPass in favor of OperationPass<FuncOp>River Riddle
The only benefit of FunctionPass is that it filters out function declarations. This isn't enough to justify carrying it around, as we can simplify filter out declarations when necessary within the pass. We can also explore with better scheduling primitives to filter out declarations at the pipeline level in the future. The definition of FunctionPass is left intact for now to allow time for downstream users to migrate. Differential Revision: https://reviews.llvm.org/D117182
2022-01-05[mlir][scf] NFC - refactor the implementation of outlineIfOpNicolas Vasilache
This revision refactors the implementation of outlineIfOp to expose a finer-grain functionality `outlineSingleBlockRegion` that will be reused in other contexts. Differential Revision: https://reviews.llvm.org/D116591
2021-10-13[MLIR] Replace std ops with arith dialect opsMogball
Precursor: https://reviews.llvm.org/D110200 Removed redundant ops from the standard dialect that were moved to the `arith` or `math` dialects. Renamed all instances of operations in the codebase and in tests. Reviewed By: rriddle, jpienaar Differential Revision: https://reviews.llvm.org/D110797
2021-07-19[mlir] Add software pipelining transformation for scf.For opthomasraoux
This is the first step to support software pipeline for scf.for loops. This is only the transformation to create pipelined kernel and prologue/epilogue. The scheduling needs to be given by user as many different algorithm and heuristic could be applied. This currently doesn't handle loop arguments, this will be added in a follow up patch. Differential Revision: https://reviews.llvm.org/D105868
2021-06-16Migrate MLIR test passes to the new registration APIMehdi Amini
Make sure they all define getArgument()/getDescription(). Depends On D104421 Differential Revision: https://reviews.llvm.org/D104426
2021-05-14[mlir][NFC] Move passes in test/lib/Transforms/ to a directory that mirrors ↵River Riddle
what they test test/lib/Transforms/ has bitrot and become somewhat of a dumping grounds for testing pretty much any part of the project. This revision cleans this up, and moves the files within to a directory that reflects what is actually being tested. Differential Revision: https://reviews.llvm.org/D102456