Commit Graph

15027 Commits

Author SHA1 Message Date
Johannes de Fine Licht
a7c574d0c1 [MLIR][LLVM] Move the LLVM inliner interface into a separate file.
A fully fledged LLVM inliner will require a lot of logic. Since
`LLVMDialect.cpp` is large enough as it is, preemptively outline the
inlining logic into a separate `.cpp` file. This will also allow us to
add a `DEBUG_TYPE` for debugging the inliner.

The name `LLVMInlining` was chosen over `LLVMInlinerInterface` to keep
the option open for exposing inlining functionality even when not
invoked through the `DialectInlinerInterface`.

Depends on D146616

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D146628
2023-03-23 14:22:25 +01:00
Quentin Colombet
0cbfd68af7 [mlir] Fix call of overloaded ‘dropResults(<brace-enclosed initializer list>)’ is ambiguous
NFC
2023-03-23 12:45:54 +01:00
Nicolas Vasilache
4dc72d47ce [mlir][Tensor] Add a FoldTensorSubsetOps pass and patterns
These patterns follow FoldMemRefAliasOps which is further refactored for reuse.
In the process, fix FoldMemRefAliasOps handling of strides for vector.transfer ops which was previously incorrect.

These opt-in patterns generalize the existing canonicalizations on vector.transfer ops.
In the future the blanket canonicalizations will be retired.
They are kept for now to minimize porting disruptions.

Differential Revision: https://reviews.llvm.org/D146624
2023-03-23 04:03:27 -07:00
Adam Paszke
61f33def13 [mlir][Vector] Make sure that vector.contract preserves extra attributes while parsing
The old implementation parsed the optional attribute dict, only to replace its
contents by using `assign`.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D146707
2023-03-23 10:31:46 +00:00
Matthias Springer
47bff1cc46 [mlir][Analysis][NFC] Make BoundType a top-level enum
`BoundType` is no longer a nested member of `IntegerRelation` but a top-level enum in the `presburger` namespace.

This allows `BoundType` to be predeclared in header files. Nested members cannot be predeclared.

Differential Revision: https://reviews.llvm.org/D146210
2023-03-23 09:46:21 +01:00
Uday Bondhugula
e50f131ae6 [MLIR][Affine] Fix bug and MSAN issue in affine loop utils
Fix bug and MSAN issue in affine loop utils introduced by
d25e022cd1 (D146495). While on it,
fix/clean up issues in immediately surrounding code.

Differential Revision: https://reviews.llvm.org/D146698
2023-03-23 14:13:28 +05:30
Matthias Springer
5b0055a4ae [mlir][Analysis][NFC] Split FlatAffineValueConstraints into multiple classes
The new class hierarchy is as follows:

* `IntegerRelation` (no change)
* `IntegerPolyhedron` (no change)
* `FlatLinearConstraints`: provides an AffineExpr-based API
* `FlatLinearValueConstraints`: stores an additional mapping of non-local vars to SSA values
* `FlatAffineValueConstraints`: provides additional helper functions for Affine dialect ops
* `FlatAffineRelation` (no change)

`FlatConstraints` and `FlatValueConstraints` are moved from `MLIRAffineAnalysis` to `MLIRAnalysis` and can be used without depending on the Affine dialect.

This change is in preparation of D145681, which adds an MLIR interface that depends on `FlatConstraints` (and cannot depend on the Affine dialect or any other dialect).

Differential Revision: https://reviews.llvm.org/D146201
2023-03-23 09:38:12 +01:00
Tobias Gysi
79df1a785d [mlir][llvm] Switch rountrip tests to opaque pointers.
The revision switches all remaining LLVM dialect roundtrip
tests to opaque pointers. Selected tests are copied to a
postfixed test file for the time being.

Part of https://discourse.llvm.org/t/rfc-switching-the-llvm-dialect-and-dialect-lowerings-to-opaque-pointers/68179

Reviewed By: zero9178

Differential Revision: https://reviews.llvm.org/D146639
2023-03-23 08:24:43 +01:00
Théo Degioanni
a35f9c6e08 [mlir][llvm] Add poison constant.
This patch introduces the poison constant from LLVM in the LLVM IR dialect. It also adds import and export support for it, along with roundtrip tests.

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D146631
2023-03-23 07:58:56 +01:00
Matthias Gehre
89a1af7491 [mlir][tosa] TosaToLinalg: Lower TOSA.Cast via RoundEven according to TOSA spec 0.60.0
TOSA now specifies rounding of ties to even in section 1.8.2., "Main Inference Profile"

Reviewed By: eric-k256, rsuderman

Differential Revision: https://reviews.llvm.org/D146617
2023-03-23 01:52:26 +00:00
Kai Sasaki
3d7383d7f4 [mlir][affine] Prevent vectorizer test from crash without any map
If the vectorizer test pass does not get any affine map, it should output nothing instead of crash.

Issue: https://github.com/llvm/llvm-project/issues/61534

Reviewed By: nicolasvasilache, dcaballe

Differential Revision: https://reviews.llvm.org/D146601
2023-03-23 10:08:53 +09:00
Kai Sasaki
d859275e77 [mlir] Fix typo for unknown operation
Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D146607
2023-03-23 09:58:40 +09:00
Jakub Kuderski
c81f14e589 [mlir][arith] Fix typos in WIE. NFC. 2023-03-22 19:15:12 -04:00
Jakub Kuderski
abfc358cff [mlir][arith] Add sitofp support to WIE
This depends on the handling of `uitofp` in D146606.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D146597
2023-03-22 19:12:16 -04:00
Jakub Kuderski
909e5ce47a [mlir][arith] Add uitofp support to WIE
This includes standard LIT tests and integration tests with the LLVM CPU
runner.

I plan to use this to implement `sitofp` in D146597.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D146606
2023-03-22 19:04:10 -04:00
Luke Hutton
9e3ca7987a [mlir][tosa] Canonicalize concatenate->slice sequence
Adds a canonicalizer for the concatenate->slice sequence where
an output of slice can be replaced with an input of concatenate.

This is useful in the context of operations with complex inputs
and outputs that are legalized from a framework such as TFL.
For example, a TFL graph (FFT->FFT) will be legalized to the
following TOSA graph:

     <complex input>
         /     \
     slice    slice
         \     /
           FFT
          /   \     -+
       concatenate   |
         /     \     |  Redundant
     slice    slice  |
         \     /    -+
           FFT
         /     \
       concatenate
            |
     <complex output>

Concatenate and slice operations at the boundaries of the graph are
useful as they maintain the correct correspondance of input/output
tensors to the original TFL graph. However, consecutive
complex operations will result in redundant concatenate->slice
sequences which should be removed from the final TOSA graph.

The canonicalization does not currently handle dynamic types.

Signed-off-by: Luke Hutton <luke.hutton@arm.com>

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D144545
2023-03-22 16:52:44 +00:00
Johannes de Fine Licht
ed114b6ffc [MLIR][LLVM] Copy byval attributes during inlining.
Support inlining of function calls with the byval attribute on function
arguments by copying the pointee into a newly alloca'ed pointer at the
callsite before inlining.

The alignment attribute is not yet taken into account.

Reviewed By: ftynse, gysit

Differential Revision: https://reviews.llvm.org/D146616
2023-03-22 15:38:16 +01:00
Nicolas Vasilache
255ba1c334 [mlir][AffineMap] NFC - Refactor getProjectedMap and split into projectDims and projectSymbols
The default behavior of getProjectedMap may be surprising as it implicitly compresses the dims and
the unused symbols.

Make these explicit in the API and refactor to more idiomatic implementations with better reuse.

Differential Revision: https://reviews.llvm.org/D146611
2023-03-22 05:30:48 -07:00
Alexander Belyaev
c8117eb964 [mlir] Add a pattern to fold tensor.cast into scf.forall.
Differential revision: https://reviews.llvm.org/D146558
2023-03-22 13:26:22 +01:00
Uday Bondhugula
d25e022cd1 [MLIR][Affine] Fix assumption on int type in memref elt size method
Fix assumption on memref element type being int/float in memref elt size
related method and affine data copy generate.

Fixes https://github.com/llvm/llvm-project/issues/61310

Differential Revision: https://reviews.llvm.org/D146495
2023-03-22 16:23:59 +05:30
Tobias Gysi
56d94a90db [mlir][llvm] Add experimental alias scope decl intrinsic.
The revision adds the llvm.experimental.noalias.scope.decl intrinsic
to the LLVM dialect and updates the import and export accordingly.

Reviewed By: Dinistro

Differential Revision: https://reviews.llvm.org/D146504
2023-03-22 10:21:09 +01:00
Matthias Springer
9297b9f8ee [mlir][Transforms][NFC] Improve builder/listener API of OperationFolder
The constructor of `OperationFolder` takes a listener. Therefore, the remaining API should not take any builder/rewriters. This could lead to double notifications in case a listener is attached to the builder/rewriter.

As an internal cleanup, `OperationFolder` now has an `IRRewriter` instead of a `RewriterBase::Listener`. In most cases, `OperationFolder` no longer has to notify/deal with listeners. This is done by the rewriter.

Differential Revision: https://reviews.llvm.org/D146134
2023-03-22 09:24:47 +01:00
Tobias Gysi
f809eb4db2 [mlir] Argument and result attribute handling during inlining.
The revision adds the handleArgument and handleResult handlers that
allow users of the inlining interface to implement argument and result
conversions that take argument and result attributes into account. The
motivating use cases for this revision are taken from the LLVM dialect
inliner, which has to copy arguments that are marked as byval and that
also has to consider zeroext / signext when converting integers.

All type conversions are currently handled by the
materializeCallConversion hook. It runs before isLegalToInline and
supports only the introduction of a single cast operation since it may
have to rollback. The new handlers run shortly before and after
inlining and cannot fail. As a result, they can introduce more complex
ir such as copying a struct argument. At the moment, the new hooks
cannot be used to perform type conversions since all type conversions
have to be done using the materializeCallConversion. A follow up
revision will either relax this constraint or drop
materializeCallConversion in favor of the new and more flexible
handlers.

The revision also extends the CallableOpInterface to provide access
to the argument and result attributes if available.

Reviewed By: rriddle, Dinistro

Differential Revision: https://reviews.llvm.org/D145582
2023-03-22 09:02:15 +01:00
Matthias Springer
9c16eef1ec [mlir][IR] Add ReverseDominanceIterator for IR walkers
Blocks are enumerated depth-first, but post-order. I.e., a block is enumerated when its successors have been enumerated. This iteration style is suitable when deleting blocks in a regions: in the absence of cycles, uses are deleted before their definitions.

Differential Revision: https://reviews.llvm.org/D146125
2023-03-22 09:01:58 +01:00
Nicolas Vasilache
829446cb45 [mlir][memref] Use folded composed affine apply ops in FoldMemRefAliasOps
Creating maximally folded and composd affine.apply operation during
FoldMemRefAliasOps composes better with other transformations without having
to interleave canonicalization passes.

Differential Revision: https://reviews.llvm.org/D146515
2023-03-21 22:17:36 -07:00
Peiming Liu
2b21327fee [mlir][sparse] fix crash when using pure constant index in indexing mapping (fixes #61530)
To address https://github.com/llvm/llvm-project/issues/61530

Reviewed By: aartbik, wrengr

Differential Revision: https://reviews.llvm.org/D146563
2023-03-21 23:45:20 +00:00
wren romano
13e9afd16d [mlir][sparse] Adding new Merger::addLat overload
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D146559
2023-03-21 16:22:04 -07:00
TatWai Chong
08b0977a19 [mlir][tosa] Add check if the operand of the operations is constant.
Some uses of TOSA rely on the constant operands of particular operations,
e.g. paddings and pad_const in pad op. Add a verification pattern in the
validation pass, and this is optionally enabled.

Change-Id: I1628c0840a27ab06ef91150eee56ad4f5ac9543d

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D145412
2023-03-21 20:54:47 +00:00
Aart Bik
a2c63d7f0b [mlir][sparse][gpu] end-to-end test for 2:4 sparsity on NVidia GPUs
Example of using 2:4 sparsity on NVidia GPU

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D145447
2023-03-21 13:32:43 -07:00
Adam Paszke
9125996380 Support retrieving the splat value from DenseElementsAttrs in Python
This is especially convenient when trying to resize the splat.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D146510
2023-03-21 08:43:17 -07:00
Maya Amrami
fd004a4986 [mlir] tosa.concat - Add InferTensorType interface
When this interface is used, a call to inferReturnTypeComponents()
is generated on creation and verification of the op.
A few changes were required in inferReturnTypeComponents():
- Emit error when it fails.
  The verifier calls this method now, and it is preferable to
  indicate what caused the failure.
- Fix the inferred return shapes so they have a type too.

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D146132
2023-03-21 17:01:08 +02:00
Alex Zinenko
fb409a2822 [mlir] Transform dialect: add named sequences
Named sequences introduce an additional abstraction and reuse capability
to the transform dialect. They can be though of as macros parameterized
with handles that can be invoked in places where a transform dialect
operation is expected. Such reuse was previously not possible in the
dialect and required dynamic construction of the transform IR from the
client language. Named sequences are intentionally restricted to
disallow recursion, as it could make the dialect accidentally
Turing-complete, which isn't desired at this point.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D146433
2023-03-21 14:53:54 +00:00
Adrian Kuegel
dc9d2e588d [mlir] Add missing registrations to runners. 2023-03-21 15:17:21 +01:00
Jan Sjodin
382eb7c2c7 [mlir] Add alloca address space handling to the data layout subsystem
This patch adds alloca address space information to the data layout interface
and implementation in the DLTI dialect. This is needed for targets that use
separate address spaces for local/stack data.

Reviewed By: ftynse, krzysz00

Differential Revision: https://reviews.llvm.org/D144657
2023-03-21 09:37:08 -04:00
Nicolas Vasilache
20294bf6c1 [mlir][Transform] NFC - Add more advanced debug spew to help hunt down potential misuses
Differential Revision: https://reviews.llvm.org/D146509
2023-03-21 06:12:07 -07:00
Sergio Afonso
0e9523efda [mlir] Support lowering of dialect attributes attached to top-level modules
This patch supports the processing of dialect attributes attached to top-level
module-type operations during MLIR-to-LLVMIR lowering.

This approach modifies the `mlir::translateModuleToLLVMIR()` function to call
`ModuleTranslation::convertOperation()` on the top-level operation, after its
body has been lowered. This, in turn, will get the
`LLVMTranslationDialectInterface` object associated to that operation's dialect
before trying to use it for lowering prior to processing dialect attributes
attached to the operation.

Since there are no `LLVMTranslationDialectInterface`s for the builtin and GPU
dialects, which define their own module-type operations, this patch also adds
and registers them. The requirement for always calling
`mlir::registerBuiltinDialectTranslation()` before any translation of MLIR to
LLVM IR where builtin module operations are present is introduced. The purpose
of these new translation interfaces is to succeed when processing module-type
operations, allowing the lowering process to continue and to prevent the
introduction of failures related to not finding such interfaces.

Differential Revision: https://reviews.llvm.org/D145932
2023-03-21 12:54:26 +00:00
Uday Bondhugula
8f072bbd74 [MLIR] Fix warnings in AttrTypeSubElements.h
Fix warnings in AttrTypeSubElements.h (below) with GCC 9.4.0.

```
mlir/lib/IR/ExtensibleDialect.cpp:443:62:   required from here
mlir/include/mlir/IR/AttrTypeSubElements.h:412:37: warning: parameter ‘derived’ set but not used [-Wunused-but-set-parameter]
  412 | void walkImmediateSubElementsImpl(T derived,
      |                                   ~~^~~
```

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D146107
2023-03-21 17:48:51 +05:30
Alexander Belyaev
3a8f161a34 [mlir] Add a pattern to fold single- and zero-iteration scf.forall ops.
Differential Revision: https://reviews.llvm.org/D145368
2023-03-21 11:59:25 +01:00
Nicolas Vasilache
9437bf418a [mlir][Linalg][Transform] Fix effect on RewriteInDestinationPassingStyleOp that did not consume its operand 2023-03-21 02:17:45 -07:00
Uday Bondhugula
71d97df6af [MLIR][Affine] Fix addInductionVarOrTerminalSymbol
Update affine analysis method `addInductionVarOrTerminalSymbol` for
affine.parallel IV.

Fixes https://github.com/llvm/llvm-project/issues/61371

Reviewed By: dcaballe

Differential Revision: https://reviews.llvm.org/D146493
2023-03-21 10:22:28 +05:30
wren romano
72455b314f [mlir][sparse] Fixing -Wunused-variable in Sparsification.cpp
Reviewed By: aartbik, Peiming

Differential Revision: https://reviews.llvm.org/D146474
2023-03-20 16:53:19 -07:00
wren romano
1f58ae8066 [mlir][sparse] Making TensorExp::Kind a nested enum-class
This improves namespacing, and follows the pattern used for "Kind" enums elsewhere in MLIR.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D146086
2023-03-20 16:12:31 -07:00
Peiming Liu
1328bb6ef1 [mlir][sparse] extend loop emitter and optimize lattices with the awareness of slice based iteration
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D142929
2023-03-20 22:19:57 +00:00
Peiming Liu
d03805f2ee [mlir][sparse] add merger/topo sort support for slice-based affine sparse index codegen
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D142928
2023-03-20 21:24:10 +00:00
Mahesh Ravishankar
411b1d8f07 [mlir][Tensor] Make TilingInterface implementation only return handle to the created pad operation.
Pad tiling implementation only needs to return the tiled pad
operation. The rest of the generated code is related to handling
boundary conditions.

Reviewed By: hanchung

Differential Revision: https://reviews.llvm.org/D146439
2023-03-20 21:23:18 +00:00
Mahesh Ravishankar
d0e507f569 [mlir][Tensor] Fix build error due to missing <> in D146440.
Differential Revision: https://reviews.llvm.org/D146458
2023-03-20 21:21:50 +00:00
Mahesh Ravishankar
c21e88cc02 [mlir][Tensor] Avoid dropping attributes for tensor.pad operations during canonicalization.
Reviewed By: hanchung

Differential Revision: https://reviews.llvm.org/D146440
2023-03-20 21:03:46 +00:00
Mahesh Ravishankar
3af1c48c66 Changes to SCFFuseProducerOfSliceResult to also return the operations created during fusion.
This is follow up to https://reviews.llvm.org/D145133 that allows
propogating information about ops that are fused back to the caller.

Reviewed By: hanchung

Differential Revision: https://reviews.llvm.org/D146254
2023-03-20 20:55:48 +00:00
giuseros
82ac02e4a8 Add scalar support for amdgpu.raw_buffer_{load,store}
Introduce the possibility to load/store scalars via amdgpu.raw_buffer_{load,store}

Reviewed By: krzysz00

Differential Revision: https://reviews.llvm.org/D146413
2023-03-20 20:19:20 +00:00
Akash Banerjee
2d373e4dc7 [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives
This patch adds OpenMP IRBuilder support for the Target Data directives to allow lowering to LLVM IR.

The mlir::Translation is responsible for generating supporting code for processing the map_operands through the processMapOperand function, and also generate code for the r>

The OMPIRBuilder is responsible for generating the begin and end mapper function calls.

Limitations:
        - use_device_ptr and use_device_addr clauses are NOT supported for Target Data operation.
        - nowait clauses are NOT supported for Target Enter and Exit Data operations.
        - Only LLVMPointerType is supported for map_operands.

Differential Revision: https://reviews.llvm.org/D142914
2023-03-20 18:48:21 +00:00