Commit Graph

9798 Commits

Author SHA1 Message Date
Matthias Springer 446f0c609f [mlir][linalg][bufferize][NFC] Update comments in BufferizableOpInterface
Differential Revision: https://reviews.llvm.org/D116932
2022-01-10 22:34:26 +09:00
Matthias Springer cb64c541f9 [mlir][linalg][bufferize][NFC] Clean up bufferization entry point
Differential Revision: https://reviews.llvm.org/D116892
2022-01-10 21:50:36 +09:00
Alex Zinenko c44d521b30 [mlir] address post-commit review for D116759 2022-01-10 12:40:58 +01:00
Alex Zinenko 2f672e2ffa [mlir] Don't inline calls from dead SCCs
During iterative inlining of the functions in a multi-step call chain, the
inliner could add the same call operation several times to the worklist, which
led to use-after-free when this op was considered more than once.

Closes #52887.

Reviewed By: wsmoses

Differential Revision: https://reviews.llvm.org/D116820
2022-01-10 12:07:14 +01:00
Stephan Herhut 33cec20dbd [mlir][memref] Tighten verification of memref.reinterpret_cast
We allow the omission of a map in memref.reinterpret_cast under the assumption,
that the cast might cast to an identity layout. This change adds verification
that the static knowledge that is present in the reinterpret_cast supports
this assumption.

Differential Revision: https://reviews.llvm.org/D116601
2022-01-10 11:55:47 +01:00
Shraiysh Vaishay a8586b573e [mlir][OpenMP] Change the syntax of omp.atomic.read op
This patch changes the syntax of omp.atomic.read to take the address of
destination, instead of having the value in a result. This will allow
using omp.atomic.read operation within an omp.atomic.capture operation
thus making its implementation less complex.

Reviewed By: peixin

Differential Revision: https://reviews.llvm.org/D116396
2022-01-10 16:19:45 +05:30
Stephen Neuendorffer 3523876873 Fix exported MLIR_TABLEGEN_EXE
LLVM_OPTIMIZED_TABLEGEN results in MLIR_TABLEGEN_EXE pointing to
an absolute path in the build directory.  This doesn't work
when exporting to an install directory.  This patch fixes the exported
information for an install directory to refer to the installed
mlir-tblgen.  (Note that this is probably a debug version if
LLVM_OPTIMIZED_TABLEGEN is set)
2022-01-09 23:27:08 -08:00
Mehdi Amini 60d13b85ca Apply clang-tidy fixes for performance-move-const-arg in ReductionNode.cpp (NFC) 2022-01-10 01:05:14 +00:00
Mehdi Amini ba19fa5779 Apply clang-tidy fixes for performance-for-range-copy in ElementwiseOpFusion.cpp (NFC) 2022-01-10 01:05:14 +00:00
Mehdi Amini 0c9d59e56a Apply clang-tidy fixes for performance-for-range-copy in ModuleBufferization.cpp (NFC) 2022-01-10 01:05:14 +00:00
Mehdi Amini 6a38cbfb53 Apply clang-tidy fixes for modernize-use-equals-default in IRCore.cpp (NFC) 2022-01-10 01:05:13 +00:00
Nicolas Vasilache 8871d8236a [mlir][MemRef] NFC - Improve assertion error message 2022-01-09 14:17:37 -05:00
Nicolas Vasilache 9ba25ec92d [mlir][Bufferize] NFC - Introduce areCastCompatible assertions to catch misformed CastOp early
Differential Revision: https://reviews.llvm.org/D116893
2022-01-09 14:13:08 -05:00
Mehdi Amini 18eb681821 Fix clang-tidy readability-redundant-smartptr-get in MLIR ModuleTranslation.cpp (NFC) 2022-01-08 20:07:11 +00:00
Mehdi Amini 651c73b8d1 Enable readability-redundant-smartptr-get in MLIR local clang-tidy config 2022-01-08 20:07:11 +00:00
Kazu Hirata 51fd157635 Remove duplicate forward declarations (NFC) 2022-01-08 11:56:42 -08:00
Uday Bondhugula 9cf9ed94ed Multiple fixes to affine loop tiling return status and checks
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-08 16:50:44 +05:30
Groverkss 0e19186c82 [MLIR][NFC] Move PresburgerSet to Presburger/ directory
This patch moves PresburgerSet to Presburger/ directory. This patch is purely
mechincal, it only moves and renames functionality and tests.

This patch is part of a series of patches to move presburger functionality to
Presburger/ directory.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D116836
2022-01-08 15:39:40 +05:30
Mehdi Amini 3e13c4c37c Avoid creating a ThreadPool in MlirOptMain when `--mlir-disable-threading` option is set
a32300a changed it to create a ThreadPool eagerly so that it gets reused
across buffers, however it also made it so that we create a ThreadPool
early even if we're not gonna use it later because of the command line
option `--mlir-disable-threading` is provided.

Fix #53056

Reland 45adf60802 after build fixes

Differential Revision: https://reviews.llvm.org/D116848
2022-01-08 02:26:41 +00:00
Mehdi Amini 4938949310 Revert "Avoid creating a ThreadPool in MlirOptMain when `--mlir-disable-threading` option is set"
This reverts commit 45adf60802.
Build is broken
2022-01-08 02:25:18 +00:00
Mehdi Amini 45adf60802 Avoid creating a ThreadPool in MlirOptMain when `--mlir-disable-threading` option is set
a32300a changed it to create a ThreadPool eagerly so that it gets reused
across buffers, however it also made it so that we create a ThreadPool
early even if we're not gonna use it later because of the command line
option `--mlir-disable-threading` is provided.

Fix #53056

Differential Revision: https://reviews.llvm.org/D116848
2022-01-08 02:18:19 +00:00
Groverkss 74903059b2 [MLIR] Add IntegerPolyhedron::getUniverse
This operation already exists in FlatAffineConstraints but is added to
IntegerPolyhedron to keep consistancy in available methods.
2022-01-08 02:59:56 +05:30
John Ericson 44e3365775 [CMake] Factor out config prefix finding logic
See the docs in the new function for details.

 I think I found every instance of this copy pasted code. Polly could
 also use it, but currently does something different, so I will save the
 behavior change for a future revision.

We get the shared, non-installed CMake modules following the pattern
established in D116472.

It might be good to have LLD and Flang also use this, but that would be
a functional change and so I leave it as future work.

Reviewed By: beanz, lebedev.ri

Differential Revision: https://reviews.llvm.org/D116521
2022-01-07 20:16:18 +00:00
Groverkss 49b754b5c6 [MLIR][NFC] Move presburger functionality from FlatAffineConstraints to IntegerPolyhedron
This patch moves all presburger functionality from FlatAffineConstraints to
IntegerPolyhedron. This patch is purely mechanical, it only moves and renames
functionality and tests.

This patch is part of a series of patches to move presburger functionality to
Presburger/ directory.

Reviewed By: bondhugula

Differential Revision: https://reviews.llvm.org/D116681
2022-01-08 01:22:49 +05:30
Kazu Hirata fb7cf90071 Use nullptr instead of 0 or NULL (NFC)
Identified with modernize-use-nullptr.
2022-01-07 10:17:29 -08:00
Kazu Hirata 117422c0da [ComprehensiveBufferize] Fix a warning
This patch fixes:

  mlir/lib/Dialect/Linalg/ComprehensiveBufferize/LinalgInterfaceImpl.cpp:292:12:
  error: comparison of integers of different signs: 'int' and
  'unsigned int' [-Werror,-Wsign-compare]
2022-01-07 09:25:59 -08:00
Matthias Springer 089b910abc [mlir][linalg][bufferize][NFC] Add `analyzeOp` helper function
This function runs just the analysis of Comprehensive Bufferize, but does not bufferize the IR yet.

This is in preparation of fixing CallOp bufferization. Also needed for unifying Comprehensive Bufferize and core bufferization; the new partial bufferization can simply run bufferization without an analysis.

Differential Revision: https://reviews.llvm.org/D116456
2022-01-08 01:33:41 +09:00
Matthias Springer d9184ab1a5 [mlir][linalg][bufferize][NFC] Simplify buffer API of BufferizationState
Instead of `lookupBuffer` and `getResultBuffer`, there is now a single `getBuffer` function. This simplifies the `BufferizableOpInterface` API and is less confusing to users. They could previously have called the wrong function.

Furthermore, since `getBuffer` now takes an `OpOperand &` instead of a `Value`, users can no longer accidentally use one of the previous two functions incorrectly, which would have resulted in missing buffer copies.

Differential Revision: https://reviews.llvm.org/D116455
2022-01-08 01:12:18 +09:00
Matthias Springer 8e2b6aac32 [mlir][linalg][bufferize][NFC] Analyze OpOperands instead of OpResults
With this change, the analysis takes a look at OpOperands instead of OpResults. OpOperands can bufferize out-of-place (even if they have no aliasing OpResults). The analysis does no longer care about OpResults.

Previously, only OpResults could bufferize out-of-place, so OpOperands that have no aliasing OpResults were never copied by Comprehensive Bufferize. This does not fit wwell with the new CallOp bufferization that is introduced in a subsequent change. In essence, called FuncOps can then be treated as "black boxes" that may read/write to any bbArg, even if they do not return anything.

Differential Revision: https://reviews.llvm.org/D115706
2022-01-08 01:00:30 +09:00
Kazu Hirata e56a9c9b5b Remove redundant return statements (NFC)
Identified by readability-redundant-control-flow.
2022-01-07 07:42:35 -08:00
Matthias Springer 547b9afc54 [mlir][linalg][bufferize][NFC] Add explicit inplaceable attrs to test cases
This is in preparation of fixing CallOp bufferization. Add explicit linalg.inplaceable attrs to all bbArgs, except for the ones where inplaceability should be decided by the analysis.

Differential Revision: https://reviews.llvm.org/D115840
2022-01-08 00:25:15 +09:00
Matthias Springer b8d0753694 [mlir][linalg][bufferize] Fix copy elision in `getResultBuffer`
A buffer copy may not be elided if the to-be-bufferized op is reading the data.

Differential Revision: https://reviews.llvm.org/D116454
2022-01-08 00:19:17 +09:00
gysit e3b442b62f [mlir][OpDSL] Separate `ReduceFn` and `ReduceFnUse`.
The revision distinguishes `ReduceFn` and `ReduceFnUse`. The latter has the reduction dimensions attached while the former specifies the arithmetic function only. This separation allows us to adapt the reduction syntax a little bit and specify the reduction dimensions using square brackets (in contrast to the round brackets used for the values to reduce). It als is a preparation to add reduction function attributes to OpDSL. A reduction function attribute shall only specify the arithmetic function and not the reduction dimensions.

Example:
```
ReduceFn.max_unsigned(D.kh, D.kw)(...)
```
changes to:
```
ReduceFn.max_unsigned[D.kh, D.kw](...)
```

Depends On D115240

Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D115241
2022-01-07 12:51:06 +00:00
gysit cf05668c17 [mlir][OpDSL] Rename `PrimFn` to `ArithFn`.
The revision renames `PrimFn` to `ArithFn`. The name resembles the newly introduced arith dialect that implements most of the arithmetic functions. An exception are log/exp that are part of the math dialect.

Depends On D115239

Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D115240
2022-01-07 12:38:03 +00:00
gysit 15757ea80a [mlir][OpDSL] Add `TypeFn` class.
This revision introduces a the `TypeFn` class that similar to the `PrimFn` class contains an extensible set of type conversion functions. Having the same mechanism for both type conversion functions and arithmetic functions improves code consistency. Additionally, having an explicit function class and function name is a prerequisite to specify a conversion or arithmetic function via attribute. In a follow up commits, we will introduce function attributes to make OpDSL operations more generic. In particular, the goal is to handle signed and unsigned computation in one operations. Today, there is a linalg.matmul and a linalg.matmul_unsigned.

The commit implements the following changes:
- Introduce the class of type conversion functions `TypeFn`
- Replace the hardwired cast and cast_unsigned ops by the `TypeFn` counterparts
- Adapt the python and C++ code generation paths to support the new cast operations

Example:
```
cast(U, A[D.m, D.k])
```
changes to
```
TypeFn.cast(U, A[D.m, D.k])
```

Depends On D115237

Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D115239
2022-01-07 12:26:47 +00:00
Adrian Kuegel babad7c566 [mlir][python] Use a named object
Currently, the object would be immediately destroyed after creation.
Found by ClangTidy bugprone-unused-raii.
2022-01-07 13:22:32 +01:00
gysit 2648e2d5dd [mlir][OpDSL] Rename `AttributeDef` to `IndexAttrDef`.
Renaming `AttributeDef` to `IndexAttrDef` prepares OpDSL to support different kinds of attributes and more closely reflects the purpose of the attribute.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D115237
2022-01-07 12:09:25 +00:00
Benjamin Kramer ae29d5a484 [mlir] Provide a home for mlir::LLVM::GEPOp::kDynamicIndex
C++14 requires this and will trigger linker errors when optimizations
are disabled.
2022-01-07 12:06:04 +01:00
Adrian Kuegel 50da013406 [mlir] Use const reference for loop iteration variable. 2022-01-07 12:00:53 +01:00
Alex Zinenko f50cfc44d6 [mlir] Require struct indices in LLVM::GEPOp to be constant
Recent commits added a possibility for indices in LLVM dialect GEP operations
to be supplied directly as constant attributes to ensure they remain such until
translation to LLVM IR happens. Make this required for indexing into LLVM
struct types to match LLVM IR requirements, otherwise the translation would
assert on constructing such IR.

For better compatibility with MLIR-style operation construction interface,
allow GEP operations to be constructed programmatically using Values pointing
to known constant operations as struct indices.

Depends On D116758

Reviewed By: wsmoses

Differential Revision: https://reviews.llvm.org/D116759
2022-01-07 09:56:05 +01:00
Alex Zinenko 43ff4a6d55 [mlir] Add ConstantLike trait to LLVM::ConstantOp
This make LLVM dialect constants to work with `m_constant` matches. Implement
the folding hook for this operation as required by the trait. This in turn
allows LLVM::ConstantOp to properly participate in constant-folding.

Depends On D116757

Reviewed By: wsmoses

Differential Revision: https://reviews.llvm.org/D116758
2022-01-07 09:56:03 +01:00
Alex Zinenko cafaa35036 [mlir] Make it possible to directly supply constant values to LLVM GEPOp
In LLVM IR, the GEP indices that correspond to structures are required to be
i32 constants. MLIR models constants as just values defined by special
operations, and there is no verification that it is the case for structure
indices in GEP. Furthermore, some common transformations such as control flow
simplification may lead to the operands becoming non-constant. Make it possible
to directly supply constant values to LLVM GEPOp to guarantee they remain
constant until the translation to LLVM IR. This is not yet a requirement and
the verifier is not modified, this will be introduced separately.

Reviewed By: wsmoses

Differential Revision: https://reviews.llvm.org/D116757
2022-01-07 09:56:01 +01:00
William S. Moses 34646a2f7e [MLIR][Arith] Fold repeated xor and trunc
This patch adds two folds. One for a repeated xor (e.g. xor(xor(x, a), a)) and one for a repeated trunc (e.g. trunc(trunc(x))).

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D116383
2022-01-07 03:36:10 -05:00
Kazu Hirata 410480e32b Ensure newlines at the end of files (NFC) 2022-01-06 23:44:02 -08:00
Shraiysh Vaishay 6bcb4c44de [mlir][OpenMP] Added omp.atomic.write lowering to LLVM IR
This patch adds omp.atomic.write lowering to LLVM IR.
Also, changed the syntax to have equal symbol instead of the comma to
make it more intuitive.

Reviewed By: kiranchandramohan, peixin

Differential Revision: https://reviews.llvm.org/D116416
2022-01-07 10:01:57 +05:30
Kazu Hirata e6075b2c2c [mlir] Fix a warning
This patch fixes:

  mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h:913:30:
  error: private field 'options' is not used
  [-Werror,-Wunused-private-field]
2022-01-06 18:41:07 -08:00
Nicolas Vasilache 07c009ed55 [mlir][Linalg] Fix invalid FailureOr construction from LogicalResult::success 2022-01-06 18:43:23 -05:00
Nicolas Vasilache 9cd7e880fd [mlir][Linalg] NFC - Modernize more transformation patterns.
Differential Revision: https://reviews.llvm.org/D116763
2022-01-06 17:40:23 -05:00
Matthias Springer 42fd68b344 [mlir][linalg][bufferize] LinalgOp: Move existing region to new op
This has two advantages.

1. It is more efficient. No need to clone the entire region.
2. Recreating ops (via cloning) invalidates analysis results. Previously, an OpResult could have bufferized out-of-place, even though the analysis requested an in-place bufferization. That is because BufferizationState keeps track of OpResults for storing bufferization analysis results (and cloned ops have new OpResults).

Differential Revision: https://reviews.llvm.org/D116453
2022-01-07 07:00:24 +09:00
Matthias Springer 698896cd6c [mlir][linalg][bufferize][NFC] Change allocationFn return type to FailureOr<Value>
In addition, all functions that call `allocationFn` now return FailureOr<Value>. This resolves a few TODOs in the code base.

Differential Revision: https://reviews.llvm.org/D116452
2022-01-07 06:33:19 +09:00