summaryrefslogtreecommitdiff
path: root/mlir/lib/Dialect/SCF/Transforms/LoopPipelining.cpp
AgeCommit message (Collapse)Author
2025-08-15[mlir][SCF] `scf.for`: Add support for unsigned integer comparison (#153379)Matthias Springer
Add a new unit attribute to allow for unsigned integer comparison. Example: ```mlir scf.for unsigned %iv_32 = %lb_32 to %ub_32 step %step_32 : i32 { // body } ``` Discussion: https://discourse.llvm.org/t/scf-should-scf-for-support-unsigned-comparison/84655
2025-07-25[mlir] Switch to new LDBG macro (#150616)Jacques Pienaar
Change local variants to use new central one.
2025-07-24[mlir][NFC] update `mlir/Dialect` create APIs (20/n) (#149927)Maksim Levental
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-05[MLIR][SCF] fix loop pipelining pass use of uninitialized value (#146991)Hu Yufan
fix issue https://github.com/llvm/llvm-project/issues/146990
2025-05-12[NFC][MLIR] Add {} for `else` when `if` body has {} (#139422)Rahul Joshi
2025-03-26[mlir] Use *Set::insert_range (NFC) (#133043)Kazu Hirata
We can use *Set::insert_range to collapse: for (auto Elem : Range) Set.insert(E); down to: Set.insert_range(Range); In some cases, we can further fold that into the set declaration.
2025-03-20[mlir][scf] Fix a div-by-zero bug when step of `scf.for` is zero (#131079)Longsheng Mou
Fixes #130095.
2024-10-15[mlir][SCF] Fix dynamic loop pipeline peeling for num_stages > total_iters ↵SJW
(#112418) When pipelining an `scf.for` with dynamic loop bounds, the epilogue ramp-down must align with the prologue when num_stages > total_iterations. For example: ``` scf.for (0..ub) { load(i) add(i) store(i) } ``` When num_stages=3 the pipeline follows: ``` load(0) - add(0) - scf.for (0..ub-2) - store(ub-2) load(1) - - add(ub-1) - store(ub-1) ``` The trailing `store(ub-2)`, `i=ub-2`, must align with the ramp-up for `i=0` when `ub < num_stages-1`, so the index `i` should be `max(0, ub-2)` and each subsequent index is an increment. The predicate must also handle this scenario, so it becomes `predicate[0] = total_iterations > epilogue_stage`.
2024-09-25[mlir][scf] Fix loop iteration calculation for negative step in ↵SJW
LoopPipelining (#110035) This fixes loop iteration count calculation if the step is a negative value, where we should adjust the added delta from `step-1` to `step+1` when doing the ceil div.
2024-09-23[SCF] Fixed epilogue predicates in loop pipelining (#108964)SJW
The computed loop iteration is zero based, so only check it is less than zero. This fixes the case when lower bound is not zero.
2024-09-05[MLIR][SCF] Loop pipelining fails on failed predication (no assert) (#107442)SJW
The SCFLoopPipelining allows predication on peeled or loop ops. When the predicationFn returns a nullptr this signifies the op type is unsupported and the pipeliner fails except in `emitPrologue` where it asserts. This patch fixes handling in the prologue to gracefully fail.
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-08-23[SCF][PIPELINE] Handle the case when values from the peeled prologue may ↵pawelszczerbuk
escape out of the loop (#105755) Previously the values in the peeled prologue that weren't treated with the `predicateFn` were passed to the loop body without any other predication. If those values are later used outside of the loop body, they may be incorrect if the num iterations is smaller than num stages - 1. We need similar masking for those, as is done in the main loop body, using already existing predicates.
2024-06-11mlir/MathExtras: consolidate with llvm/MathExtras (#95087)Ramkumar Ramachandra
This patch is part of a project to move the Presburger library into LLVM.
2024-04-11[MLIR][LoopPipelining] Improve schedule verifier, so it checks also operands ↵pawelszczerbuk
of nested operations (#88450) `verifySchedule` was not looking at the operands of nested operations, which caused incorrect schedule to be allowed in some cases, potentially leading to crash during expansion. There is also minor fix in `cloneAndUpdateOperands` in the pipeline expander that prevents double visit of the cloned op. This one has no functional impact, so no test for it.
2024-01-10[MLIR][SCF] Add checks to verify that the pipeliner schedule is correct. ↵Thomas Raoux
(#77083) Add a check to validate that the schedule passed to the pipeliner transformation is valid and won't cause the pipeliner to break SSA. This checks that the for each operation in the loop operations are scheduled after their operands.
2023-12-13[mlir] Fix loop pipelining when the operand of `yield` is not defined in the ↵Keren Zhou
loop body (#75423)
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-12-01[MLIR][SCF] Handle more cases in pipelining transform (#74007)Thomas Raoux
-Fix case where an op is scheduled in stage 0 and used with a distance of 1 -Fix case where we don't peel the epilogue and a value not part of the last stage is used outside the loop.
2023-10-28[mlir][Interfaces] `LoopLikeOpInterface`: Add helpers to query tied ↵Matthias Springer
inits/iter_args (#70408) The `LoopLikeOpInterface` already has interface methods to query inits and iter_args. This commit adds helper functions to query tied init/iter_arg pairs and removes the corresponding functions for `scf::ForOp`.
2023-07-17[mlir][nvgpu] add simple pipelining for shared memory copiesAlex Zinenko
Add a simple transform operation to the NVGPU extension that performs software pipelining of copies to shared memory. The functionality is extremely minimalistic in this version and only supports copies from global to shared memory inside an `scf.for` loop with either `vector.transfer` or `nvgpu.device_async_copy` operations when pipelining preconditions are already satisfied in the IR. This is the minimally useful version that uses the more general loop pipeliner in an NVGPU-specific way. Further extensions and orthogonalizations will be necessary. This required a change to the loop pipeliner itself to properly propagate errors should the predicate generator fail. This is loosely inspired from the vesion in IREE, but has less unsafe assumptions and more principled way of communicating decisions. Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D155223
2023-05-30[mlir][scf] NFC - Add debug information to scf pipeliningNicolas Vasilache
2023-05-12[mlir] Move casting calls from methods to function callsTres Popp
The MLIR classes Type/Attribute/Operation/Op/Value support cast/dyn_cast/isa/dyn_cast_or_null functionality through llvm's doCast functionality in addition to defining methods with the same name. This change begins the migration of uses of the method to the corresponding function call as has been decided as more consistent. Note that there still exist classes that only define methods directly, such as AffineExpr, and this does not include work currently to support a functional cast/isa call. Caveats include: - This clang-tidy script probably has more problems. - This only touches C++ code, so nothing that is being generated. Context: - https://mlir.llvm.org/deprecation/ at "Use the free function variants for dyn_cast/cast/isa/…" - Original discussion at https://discourse.llvm.org/t/preferred-casting-style-going-forward/68443 Implementation: This first patch was created with the following steps. The intention is to only do automated changes at first, so I waste less time if it's reverted, and so the first mass change is more clear as an example to other teams that will need to follow similar steps. Steps are described per line, as comments are removed by git: 0. Retrieve the change from the following to build clang-tidy with an additional check: https://github.com/llvm/llvm-project/compare/main...tpopp:llvm-project:tidy-cast-check 1. Build clang-tidy 2. Run clang-tidy over your entire codebase while disabling all checks and enabling the one relevant one. Run on all header files also. 3. Delete .inc files that were also modified, so the next build rebuilds them to a pure state. 4. Some changes have been deleted for the following reasons: - Some files had a variable also named cast - Some files had not included a header file that defines the cast functions - Some files are definitions of the classes that have the casting methods, so the code still refers to the method instead of the function without adding a prefix or removing the method declaration at the same time. ``` ninja -C $BUILD_DIR clang-tidy run-clang-tidy -clang-tidy-binary=$BUILD_DIR/bin/clang-tidy -checks='-*,misc-cast-functions'\ -header-filter=mlir/ mlir/* -fix rm -rf $BUILD_DIR/tools/mlir/**/*.inc git restore mlir/lib/IR mlir/lib/Dialect/DLTI/DLTI.cpp\ mlir/lib/Dialect/Complex/IR/ComplexDialect.cpp\ mlir/lib/**/IR/\ mlir/lib/Dialect/SparseTensor/Transforms/SparseVectorization.cpp\ mlir/lib/Dialect/Vector/Transforms/LowerVectorMultiReduction.cpp\ mlir/test/lib/Dialect/Test/TestTypes.cpp\ mlir/test/lib/Dialect/Transform/TestTransformDialectExtension.cpp\ mlir/test/lib/Dialect/Test/TestAttributes.cpp\ mlir/unittests/TableGen/EnumsGenTest.cpp\ mlir/test/python/lib/PythonTestCAPI.cpp\ mlir/include/mlir/IR/ ``` Differential Revision: https://reviews.llvm.org/D150123
2023-03-14[mlir] Use Use *{Set,Map}::contains (NFC)Kazu Hirata
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-03-08[mlir][scf] Fix bug in software pipeliner and simplify the logicThomas Raoux
Fix bug when pipelining while interleaving stages. Re-do the logic to only consider cloned operands when updating the use-def chain. Differential Revision: https://reviews.llvm.org/D145598
2023-01-12[mlir] Add operations to BlockAndValueMapping and rename it to IRMappingJeff Niu
The patch adds operations to `BlockAndValueMapping` and renames it to `IRMapping`. When operations are cloned, old operations are mapped to the cloned operations. This allows mapping from an operation to a cloned operation. Example: ``` Operation *opWithRegion = ... Operation *opInsideRegion = &opWithRegion->front().front(); IRMapping map Operation *newOpWithRegion = opWithRegion->clone(map); Operation *newOpInsideRegion = map.lookupOrNull(opInsideRegion); ``` Migration instructions: All includes to `mlir/IR/BlockAndValueMapping.h` should be replaced with `mlir/IR/IRMapping.h`. All uses of `BlockAndValueMapping` need to be renamed to `IRMapping`. Reviewed By: rriddle, mehdi_amini Differential Revision: https://reviews.llvm.org/D139665
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-08-31[MLIR] Update pass declarations to new autogenerated filesMichele Scuttari
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 Scuttari
This reverts commit 2be8af8f0e0780901213b6fd3013a5268ddc3359.
2022-08-30[MLIR] Update pass declarations to new autogenerated filesMichele Scuttari
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-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-09[mlir] Introduce Transform ops for loopsAlex Zinenko
Introduce transform ops for "for" loops, in particular for peeling, software pipelining and unrolling, along with a couple of "IR navigation" ops. These ops are intended to be generalized to different kinds of loops when possible and therefore use the "loop" prefix. They currently live in the SCF dialect as there is no clear place to put transform ops that may span across several dialects, this decision is postponed until the ops actually need to handle non-SCF loops. Additionally refactor some common utilities for transform ops into trait or interface methods, and change the loop pipelining to be a returning pattern. Reviewed By: springerm Differential Revision: https://reviews.llvm.org/D127300
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-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-03[mlir][scf] Fix bug in pipelining prologue emissionThomas Raoux
Induction variable calculation was ignoring scf.for step value. Fix it to get the correct induction variable value in the prologue. Differential Revision: https://reviews.llvm.org/D118932
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-02Apply clang-tidy fixes for performance-for-range-copy to MLIR (NFC)Mehdi Amini
2021-12-20[mlir] Switching accessors to prefixed form (NFC)Jacques Pienaar
Makes eventual prefixing flag flip smaller change.
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-21[mlir] Extend scf pipeling to support loop carried dependenciesthomasraoux
Differential Revision: https://reviews.llvm.org/D106325
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