aboutsummaryrefslogtreecommitdiff
path: root/mlir/lib/Transforms/Utils/LoopUtils.cpp
AgeCommit message (Collapse)AuthorFilesLines
2022-01-24[mlir:Transforms] Move out the remaining non-dialect independent transforms ↵River Riddle1-3443/+0
and utilities This has been a major TODO for a very long time, and is necessary for establishing a proper dialect-free dependency layering for the Transforms library. Code was moved to effectively two main locations: * Affine/ There was quite a bit of affine dialect related code in Transforms/ do to historical reasons (of a time way into MLIR's past). The following headers were moved to: Transforms/LoopFusionUtils.h -> Dialect/Affine/LoopFusionUtils.h Transforms/LoopUtils.h -> Dialect/Affine/LoopUtils.h Transforms/Utils.h -> Dialect/Affine/Utils.h The following transforms were also moved: AffineLoopFusion, AffinePipelineDataTransfer, LoopCoalescing * SCF/ Only one SCF pass was in Transforms/ (likely accidentally placed here): ParallelLoopCollapsing The SCF specific utilities in LoopUtils have been moved to SCF/Utils.h * Misc: mlir::moveLoopInvariantCode was also moved to LoopLikeInterface.h given that it is a simple utility defined in terms of LoopLikeOpInterface. Differential Revision: https://reviews.llvm.org/D117848
2022-01-18[mlir:Analysis] Move the LoopAnalysis library to Dialect/Affine/AnalysisRiver Riddle1-3/+3
The current state of the top level Analysis/ directory is that it contains two libraries; a generic Analysis library (free from dialect dependencies), and a LoopAnalysis library that contains various analysis utilities that originated from Affine loop transformations. This commit moves the LoopAnalysis to the more appropriate home of `Dialect/Affine/Analysis/`, given the use and intention of the majority of the code within it. After the move, if there are generic utilities that would fit better in the top-level Analysis/ directory, we can move them. Differential Revision: https://reviews.llvm.org/D117351
2022-01-14Fix NDEBUG unused-variable warning after ↵James Y Knight1-2/+1
05f6e93938b73d8335f72e852f5686521cca2390.
2022-01-14[MLIR] NFC. affine data copy generate utility return value cleanupUday Bondhugula1-31/+20
Clean up return value on affineDataCopyGenerate utility. Return the actual success/failure status instead of the "number of bytes" which isn't being used in the codebase in any way. The success/failure status wasn't being sent out earlier. Differential Revision: https://reviews.llvm.org/D117209
2022-01-10Don't fail if unable to promote loops during unrollingTyler Augustine1-8/+23
When the unroll factor is 1, we should only fail "unrolling" when the trip count also is determined to be 1 and it is unable to be promoted. Reviewed By: bondhugula Differential Revision: https://reviews.llvm.org/D115365
2022-01-08Multiple fixes to affine loop tiling return status and checksUday Bondhugula1-35/+57
Fix crash in the presence of yield values. Multiple fixes to affine loop tiling pre-condition checks and return status. Do not signal pass failure on a failure to tile since the IR is still valid. Detect index set computation failure in checkIfHyperrectangular and return failure. Replace assertions with proper status return. Move checks to an appropriate place earlier in the utility before mutation happens. Differential Revision: https://reviews.llvm.org/D116738
2022-01-02Apply clang-tidy fixes for performance-for-range-copy to MLIR (NFC)Mehdi Amini1-1/+1
2022-01-02Apply clang-tidy fixes for readability-simplify-boolean-expr to MLIR (NFC)Mehdi Amini1-3/+1
Reviewed By: rriddle, Mogball Differential Revision: https://reviews.llvm.org/D116253
2022-01-02Apply clang-tidy fixes for bugprone-argument-comment to MLIR (NFC)Mehdi Amini1-3/+3
Differential Revision: https://reviews.llvm.org/D116244
2021-12-30[MLIR] Move AtomicRMW into MemRef dialect and enum into ArithWilliam S. Moses1-1/+1
Per the discussion in https://reviews.llvm.org/D116345 it makes sense to move AtomicRMWOp out of the standard dialect. This was accentuated by the need to add a fold op with a memref::cast. The only dialect that would permit this is the memref dialect (keeping it in the standard dialect or moving it to the arithmetic dialect would require those dialects to have a dependency on the memref dialect, which breaks linking). As the AtomicRMWKind enum is used throughout, this has been moved to Arith. Reviewed By: Mogball Differential Revision: https://reviews.llvm.org/D116392
2021-12-22Fix more clang-tidy cleanups in mlir/ (NFC)Mehdi Amini1-7/+5
2021-12-20Fix clang-tidy issues in mlir/ (NFC)Mehdi Amini1-1/+1
Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D115956
2021-12-20[mlir] Switching accessors to prefixed form (NFC)Jacques Pienaar1-33/+33
Makes eventual prefixing flag flip smaller change.
2021-12-04[MLIR] Fix affine.for unroll for multi-result upper bound mapsUday Bondhugula1-55/+47
Fix affine.for unroll for multi-result upper bound maps: these can't be unrolled/unroll-and-jammed in cases where the trip count isn't known to be a multiple of the unroll factor. Fix and clean up repeated/unnecessary checks/comments at helper callees. Also, fix clang-tidy variable naming warnings and redundant includes. Differential Revision: https://reviews.llvm.org/D114662
2021-10-19[mlir][RFC] Refactor layout representation in MemRefTypeVladislav Vinogradov1-3/+1
The change is based on the proposal from the following discussion: https://llvm.discourse.group/t/rfc-memreftype-affine-maps-list-vs-single-item/3968 * Introduce `MemRefLayoutAttr` interface to get `AffineMap` from an `Attribute` (`AffineMapAttr` implements this interface). * Store layout as a single generic `MemRefLayoutAttr`. This change removes the affine map composition feature and related API. Actually, while the `MemRefType` itself supported it, almost none of the upstream can work with more than 1 affine map in `MemRefType`. The introduced `MemRefLayoutAttr` allows to re-implement this feature in a more stable way - via separate attribute class. Also the interface allows to use different layout representations rather than affine maps. For example, the described "stride + offset" form, which is currently supported in ASM parser only, can now be expressed as separate attribute. Reviewed By: ftynse, bondhugula Differential Revision: https://reviews.llvm.org/D111553
2021-10-13[MLIR] Replace std ops with arith dialect opsMogball1-73/+83
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-10-11[MLIR] Fix affine loop unroll corner case for full unrollUday Bondhugula1-0/+2
Fix affine loop unroll for zero trip count loops. Add missing check. Differential Revision: https://reviews.llvm.org/D111375
2021-10-03[MLIR][NFC] Drop unnecessary use of OpBuilder in build trip count mapUday Bondhugula1-1/+1
NFC. Drop unnecessary use of OpBuilder in buildTripCountMapAndOperands. Rename this to getTripCountMapAndOperands and remove stale comments. Differential Revision: https://reviews.llvm.org/D110993
2021-09-28[mlir] Unroll-and-jam loops with iter_args.Amy Zhuang1-78/+198
Unroll-and-jam currently doesn't work when the loop being unroll-and-jammed or any of its inner loops has iter_args. This patch modifies the unroll-and-jam utility to support loops with iter_args. Reviewed By: bondhugula Differential Revision: https://reviews.llvm.org/D110085
2021-09-08[MLIR] Add loop coalesce utility for affine.forArnab Dutta1-1/+115
Add loop coalesce utility for affine.for. This expects loops to have been normalized a-priori. This works for both constant as well non constant upper bounds having single/multiple result upper bound affine map. With contributions from Arnab Dutta and Uday Bondhugula. Reviewed By: bondhugula, ayzhuang Differential Revision: https://reviews.llvm.org/D108126
2021-08-19[mlir][Analysis][NFC] FlatAffineConstraints: Use BoundType enum in functionsMatthias Springer1-2/+2
Differential Revision: https://reviews.llvm.org/D108185
2021-08-17[mlir][Analysis][NFC] Clean up FlatAffineValueConstraintsMatthias Springer1-4/+4
* Rename ids to values in FlatAffineValueConstraints. * Overall cleanup of comments in FlatAffineConstraints and FlatAffineValueConstraints. Differential Revision: https://reviews.llvm.org/D107947
2021-08-17[mlir][Analysis][NFC] Split FlatAffineConstraints classMatthias Springer1-5/+5
* Extract "value" functionality of `FlatAffineConstraints` into a new derived `FlatAffineValueConstraints` class. Current users of `FlatAffineConstraints` can use `FlatAffineValueConstraints` without additional code changes, thus NFC. * `FlatAffineConstraints` no longer associates dimensions with SSA Values. All functionality that requires this, is moved to `FlatAffineValueConstraints`. * `FlatAffineConstraints` no longer makes assumptions about where Values associated with dimensions are coming from. Differential Revision: https://reviews.llvm.org/D107725
2021-08-11Support post-processing Ops in unrolled loop iterationsTyler Augustine1-12/+27
This can be useful when one needs to know which unrolled iteration an Op belongs to, for example, conveying noalias information among memory-affecting ops in parallel-access loops. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D107789
2021-07-28[mlir] Set the namespace of the BuiltinDialect to 'builtin'River Riddle1-1/+1
Historically the builtin dialect has had an empty namespace. This has unfortunately created a very awkward situation, where many utilities either have to special case the empty namespace, or just don't work at all right now. This revision adds a namespace to the builtin dialect, and starts to cleanup some of the utilities to no longer handle empty namespaces. For now, the assembly form of builtin operations does not require the `builtin.` prefix. (This should likely be re-evaluated though) Differential Revision: https://reviews.llvm.org/D105149
2021-06-30[MLIR] Fix generateCopyForMemRefRegionUday Bondhugula1-2/+6
Fix generateCopyForMemRefRegion for a missing check: in some cases, when the thing to generate copies for itself is empty, no fast buffer/copy loops would have been allocated/generated. Add an extra assertion there while at this. Differential Revision: https://reviews.llvm.org/D105170
2021-04-15[mlir][NFC] Add a using directive for llvm::SetVectorRiver Riddle1-1/+0
Differential Revision: https://reviews.llvm.org/D100436
2021-04-01Setup OpBuilder to support detached block in loopUnrollByFactor (NFC)Mehdi Amini1-2/+3
Setting the builder from a block is looking up for a parent operation to get a context, instead by setting up the builder with an explicit context we can support invoking this helper in absence of a parent operation.
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-4/+6
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-03-09[mlir] Use affine.apply when distributing to processorsLei Zhang1-7/+18
This makes it easy to compose the distribution computation with other affine computations. Reviewed By: mravishankar Differential Revision: https://reviews.llvm.org/D98171
2021-03-02[mlir][NFC] Rename `MemRefType::getMemorySpace` to `getMemorySpaceAsInt`Vladislav Vinogradov1-2/+2
Just a pure method renaming. It is a preparation step for replacing "memory space as raw integer" with more generic "memory space as attribute", which will be done in separate commit. The `MemRefType::getMemorySpace` method will return `Attribute` and become the main API, while `getMemorySpaceAsInt` will be declared as deprecated and will be replaced in all in-tree dialects (also in separate commits). Reviewed By: mehdi_amini, rriddle Differential Revision: https://reviews.llvm.org/D97476
2021-02-23[MLIR] Fix tilePerfectlyNested utility for handling non-unit step sizeVivek1-9/+15
The current implementation of tilePerfectlyNested utility doesn't handle the non-unit step size. We have added support to perform tiling correctly even if the step size of the loop to be tiled is non-unit. Fixes https://bugs.llvm.org/show_bug.cgi?id=49188. Differential Revision: https://reviews.llvm.org/D97037
2021-02-18Revert "[MLIR] Create memref dialect and move several dialect-specific ops ↵Alexander Belyaev1-6/+4
from std." This commit introduced a cyclic dependency: Memref dialect depends on Standard because it used ConstantIndexOp. Std depends on the MemRef dialect in its EDSC/Intrinsics.h Working on a fix. This reverts commit 8aa6c3765b924d86f623d452777eb76b83bf2787.
2021-02-18[MLIR] Create memref dialect and move several dialect-specific ops from std.Julian Gross1-4/+6
Create the memref dialect and move several dialect-specific ops without dependencies to other ops from std dialect to this dialect. Moved ops: AllocOp -> MemRef_AllocOp AllocaOp -> MemRef_AllocaOp DeallocOp -> MemRef_DeallocOp MemRefCastOp -> MemRef_CastOp GetGlobalMemRefOp -> MemRef_GetGlobalOp GlobalMemRefOp -> MemRef_GlobalOp PrefetchOp -> MemRef_PrefetchOp ReshapeOp -> MemRef_ReshapeOp StoreOp -> MemRef_StoreOp TransposeOp -> MemRef_TransposeOp 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/D96425
2021-02-16[mlir] Drop reliance of SliceAnalysis on specific ops.Nicolas Vasilache1-5/+5
SliceAnalysis originally was developed in the context of affine.for within mlfunc. It predates the notion of region. This revision updates it to not hardcode specific ops like scf::ForOp. When rooted at an op, the behavior of the slice computation changes as it recurses into the regions of the op. This does not support gathering all values transitively depending on a loop induction variable anymore. Additional variants rooted at a Value are added to also support the existing behavior. Differential revision: https://reviews.llvm.org/D96702
2021-02-10[MLIR] Update affine.for unroll utility for iter_args supportUday Bondhugula1-20/+47
Update affine.for loop unroll utility for iteration arguments support. Fix promoteIfSingleIteration as well. Fixes PR49084: https://bugs.llvm.org/show_bug.cgi?id=49084 Differential Revision: https://reviews.llvm.org/D96383
2021-02-04[mlir] Mark LogicalResult as LLVM_NODISCARDRiver Riddle1-21/+21
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-29[mlir] Preserve lexicographic order after loop collapsing.Alexander Belyaev1-10/+12
Currently, for a scf.parallel (i,j,k) after the loop collapsing to 1D is done, the IVs would be traversed as for an scf.parallel(k,j,i). Differential Revision: https://reviews.llvm.org/D95693
2021-01-08[mlir] NFC: fix trivial typosKazuaki Ishizaki1-1/+2
fix typo under include and lib directories Reviewed By: antiagainst Differential Revision: https://reviews.llvm.org/D94220
2020-12-09[mlir] Use mlir::OpState::operator->() to get to methods of mlir::Operation. ↵Christian Sigg1-3/+3
This is a preparation step to remove the corresponding methods from OpState. Reviewed By: silvas, rriddle Differential Revision: https://reviews.llvm.org/D92878
2020-12-02Add `Operation* OpState::operator->()` to provide more convenient access to ↵Christian Sigg1-31/+24
members of Operation. Given that OpState already implicit converts to Operator*, this seems reasonable. The alternative would be to add more functions to OpState which forward to Operation. Reviewed By: rriddle, ftynse Differential Revision: https://reviews.llvm.org/D92266
2020-11-19[mlir][BuiltinDialect] Resolve comments from D91571River Riddle1-1/+1
* Move ops to a BuiltinOps.h * Add file comments
2020-11-17[mlir][NFC] Remove references to Module.h and Function.hRiver Riddle1-1/+1
These includes have been deprecated in favor of BuiltinDialect.h, which contains the definitions of ModuleOp and FuncOp. Differential Revision: https://reviews.llvm.org/D91572
2020-10-29[mlir] NFC: fix trivial typosKazuaki Ishizaki1-4/+4
fix typos in comments and documents Reviewed By: jpienaar Differential Revision: https://reviews.llvm.org/D90089
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-10-10[mlir][scf] Fix a bug in scf::ForOp loop unroll with an epilogueTatiana Shpeisman1-15/+58
Fixes a bug in formation and simplification of an epilogue loop generated during loop unroll of scf::ForOp (https://bugs.llvm.org/show_bug.cgi?id=46689) Differential Revision: https://reviews.llvm.org/D87583
2020-09-17[MLIR][Affine] Add parametric tile size support for affine.for tilingNavdeep Kumar1-4/+567
Add support to tile affine.for ops with parametric sizes (i.e., SSA values). Currently supports hyper-rectangular loop nests with constant lower bounds only. Move methods - moveLoopBody(*) - getTileableBands(*) - checkTilingLegality(*) - tilePerfectlyNested(*) - constructTiledIndexSetHyperRect(*) to allow reuse with constant tile size API. Add a test pass -test-affine -parametric-tile to test parametric tiling. Differential Revision: https://reviews.llvm.org/D87353
2020-09-08Add an option for unrolling loops up to a factor.Lubomir Litchev1-1/+0
Currently, there is no option to allow for unrolling a loop up to a specific factor (specified by the user). The code for doing that is there and there are benefits when unrolling is done to smaller loops (smaller than the factor specified). Reviewed By: bondhugula Differential Revision: https://reviews.llvm.org/D87111