Commit Graph

2022 Commits

Author SHA1 Message Date
River Riddle 0816de167a [mlir][DialectConversion] Add support for properly tracking replaceUsesOfBlockArgument
The current implementation of this method performs the replacement directly, and thus doesn't support proper back tracking.

Differential Revision: https://reviews.llvm.org/D78790
2020-04-24 12:37:32 -07:00
Frederik Gossen 7e4b139a04 [MLIR] Ensure `gpu.func` must be inside a `gpu.module`.
Ensure that `gpu.func` is only used within the dedicated `gpu.module`.
Implement the constraint to the GPU dialect and adopt test cases.

Differential Revision: https://reviews.llvm.org/D78541
2020-04-24 07:17:48 +00:00
Rob Suderman 5b89c1dd68 [mlir] DenseStringElementsAttr added to default attribute types
Summary:
Implemented a DenseStringsElements attr for handling arrays / tensors of strings. This includes the
necessary logic for parsing and printing the attribute from MLIR's text format.

To store the attribute we perform a single allocation that includes all wrapped string data tightly packed.
This means no padding characters and no null terminators (as they could be present in the string). This
buffer includes a first chunk of data that represents an array of StringRefs, that contain address pointers
into the string data, with the length of each string wrapped. At this point there is no Sparse representation
however strings are not typically represented sparsely.

Differential Revision: https://reviews.llvm.org/D78600
2020-04-23 19:02:15 -07:00
Sean Silva 1b2c7877a4 Add support for IndexType inside DenseIntElementsAttr.
This also fixes issues discovered in the parsing/printing path.
2020-04-23 17:42:33 -07:00
MaheshRavishankar 542668d1e2 [mlir][Linalg] Add support for fusing linalg.tensor_reshape with
linalg.generic operations.

Differential Revision: https://reviews.llvm.org/D78464
2020-04-23 13:41:47 -07:00
Nicolas Vasilache 37d417bb0a [mlir][EDSC] Hotfix - Provide impl for `negate`
367229e100 retired ValueHandle but
mistakenly removed the implementation for `negate` which was not
tested and would result in linking errors.

This revision adds the implementation back and provides a test.
2020-04-23 14:18:47 -04:00
MaheshRavishankar 9391941bd3 [mlir][StandardToSPIRV] Fix test cases where DCE removes all the code.
Differential Revision: https://reviews.llvm.org/D78727
2020-04-23 09:48:37 -07:00
Nicolas Vasilache 367229e100 [mlir][EDSC] Retire ValueHandle
The EDSC discussion [thread](https://llvm.discourse.group/t/evolving-builder-apis-based-on-lessons-learned-from-edsc/879) points out that ValueHandle has become an unnecessary level of abstraction since MLIR switch from `Value *` to `Value` everywhere.

This revision removes this level of indirection.
2020-04-23 11:01:16 -04:00
Marcel Koester c79227cabb [mlir] Extended Liveness analysis to support nested regions.
The current Liveness analysis does not support operations with nested regions.
This causes issues when querying liveness information about blocks nested within
operations. Furthermore, the live-in and live-out sets are not computed properly
in these cases.

Differential Revision: https://reviews.llvm.org/D77714
2020-04-23 16:19:54 +02:00
River Riddle 7f85adb54d [mlir][Standard] Allow select to use an i1 for vector and tensor values
It currently requires that the condition match the shape of the selected value, but this is only really useful for things like masks. This revision allows for the use of i1 to mean that all of the vector/tensor is selected. This also matches the behavior of LLVM select. A benefit of this change is that transformations that want to generate selects, like those on the CFG, don't have to special case vector/tensor. Previously the only way to generate  a select from an i1 was to use a splat, but that doesn't support dynamically shaped/unranked tensors.

Differential Revision: https://reviews.llvm.org/D78690
2020-04-23 04:50:09 -07:00
River Riddle 2fafe7ff59 [mlir][Standard] Add support for canonicalizing branches to passthrough blocks
This revision adds support for canonicalizing the following:

```
   br ^bb1
 ^bb1
   br ^bbN(...)

 br ^bbN(...)
```

Differential Revision: https://reviews.llvm.org/D78683
2020-04-23 04:42:02 -07:00
River Riddle af331bc52d [mlir][Standard] Add a canonicalization to simplify cond_br when the successors are identical
This revision adds support for canonicalizing the following:

```
cond_br %cond, ^bb1(A, ..., N), ^bb1(A, ..., N)

br ^bb1(A, ..., N)
```

 If the operands to the successor are different and the cond_br is the only predecessor, we emit selects for the branch operands.

```
cond_br %cond, ^bb1(A), ^bb1(B)

%select = select %cond, A, B
br ^bb1(%select)
```

Differential Revision: https://reviews.llvm.org/D78682
2020-04-23 04:42:02 -07:00
River Riddle 2f4b303d68 [mlir][Standard] Add canonicalization for collapsing pass through cond_br successors.
This revision adds support for the following canonicalization:

```
   cond_br %cond, ^bb1, ^bb2
 ^bb1
   br ^bbN(...)
 ^bb2
   br ^bbK(...)

   cond_br %cond, ^bbN(...), ^bbK(...)
```

Differential Revision: https://reviews.llvm.org/D78681
2020-04-23 04:42:01 -07:00
Alexander Belyaev 21caba599e [MLIR] Lower GenericAtomicRMWOp to llvm.cmpxchg.
Summary:
Lowering is pretty much a copy of AtomicRMWOp -> llvm.cmpxchg
pattern.

Differential Revision: https://reviews.llvm.org/D78647
2020-04-23 09:29:34 +02:00
Sean Silva 7b5497f258 Isolate zero_whitespace parser test into its own file.
Summary:
This test is in a different file because it contains a literal NUL
character, which causes various tools to treat it as a binary file.
Hence it is useful to have this test kept in a separate, rarely-changing
file.

Differential Revision: https://reviews.llvm.org/D78689
2020-04-22 19:58:40 -07:00
Denis Khalikov 1009177d49 [mlir][vulkan-runner] Add support for integer types.
Summary:
Add support for memrefs with element type as integer type
and simple test.

Differential Revision: https://reviews.llvm.org/D78560
2020-04-22 19:42:39 +03:00
Denis Khalikov ec16df7066 [mlir][vulkan-runner] Fix testsuite.
Summary: Fix testsuite after D78542.

Differential Revision: https://reviews.llvm.org/D78639
2020-04-22 18:24:15 +03:00
Frederik Gossen 0372db05bb [MLIR] Use nested symbol to identify kernel in `LaunchFuncOp`.
Summary:
Use a nested symbol to identify the kernel to be invoked by a `LaunchFuncOp` in the GPU dialect.
This replaces the two attributes that were used to identify the kernel module and the kernel within seperately.

Differential Revision: https://reviews.llvm.org/D78551
2020-04-22 07:44:29 +00:00
Frederik Gossen 648fc95083 [MLIR] Use `kernel` as a short hand for `gpu.kernel` attribute.
Summary:
Use the shortcu `kernel` for the `gpu.kernel` attribute of `gpu.func`.
The parser supports this and test cases are easier to read.

Differential Revision: https://reviews.llvm.org/D78542
2020-04-22 07:38:30 +00:00
Frederik Gossen 2813802746 [MLIR] Fix test case for kernel attribute.
Summary:
Fix a broken test case in the `invalid.mlir` lit test case.
`expect` was missing its `e`.

Differential Revision: https://reviews.llvm.org/D78540
2020-04-22 07:27:39 +00:00
Alexander Belyaev 146d52e732 [MLIR] Verify there are no side-effecting ops in GenericAtomicRMWOp body.
Differential Revision: https://reviews.llvm.org/D78559
2020-04-22 09:02:58 +02:00
Pierre Oechsel 128d72751f [mlir] [linalg] Specify alignment during promotion.
The buffer allocated by a promotion can be subject to other transformations afterward. For example it could be vectorized, in which case it is needed to ensure that this buffer is memory-aligned.

Differential Revision: https://reviews.llvm.org/D78556
2020-04-21 18:13:40 +02:00
Nicolas Vasilache 538ac26f25 [mlir][Linalg] Create a named batch_matmul op and pipe it through.
This revision is the first in a set of improvements that aim at allowing
more generalized named Linalg op generation from a mathematical
specification.

This revision allows creating a new op and checks that the parser,
printer and verifier are hooked up properly.

This opened up a few design points that will be addressed in the future:
1. A named linalg op has a static region builder instead of an
explicitly parsed region. This is not currently compatible with
assemblyFormat so a custom parser / printer are needed.
2. The convention for structured ops and tensor return values needs to
evolve to allow tensor-land and buffer land specifications to agree
3. ReferenceIndexingMaps and referenceIterators will need to become
static to allow building attributes at parse time.
4. Error messages will be improved once we have 3. and we pretty print
in custom form.

Differential Revision: https://reviews.llvm.org/D78327
2020-04-21 12:09:46 -04:00
Pierre Oechsel 49202476e6 [mlir] [linalg] Fix transform-patterns test.
Unfortunately FileCheck ignores directives with whitespace between the directive and the colon (`CHECK  :` for example), thus most of the directives of this test were ignored.

Differential Revision: https://reviews.llvm.org/D78548
2020-04-21 12:53:45 +02:00
River Riddle 2eda87dfbe [mlir][SCCP] Add support for propagating constants across inter-region control flow.
This is possible by adding two new ControlFlowInterface additions:

- A new interface, RegionBranchOpInterface
This interface allows for region holding operations to describe how control flows between regions. This interface initially contains two methods:

* getSuccessorEntryOperands
Returns the operands of this operation used as the entry arguments when entering the region at `index`, which was specified as a successor by `getSuccessorRegions`. when entering. These operands should correspond 1-1 with the successor inputs specified in `getSuccessorRegions`, and may be a subset of the entry arguments for that region.

*  getSuccessorRegions
Returns the viable successors of a region, or the possible successor when branching from the parent op. This allows for describing which regions may be executed when entering an operation, and which regions are executed after having executed another region of the parent op. For example, a structured loop operation may always enter into the loop body region. The loop body region may branch back to itself, or exit to the operation.

- A trait, ReturnLike
This trait signals that a terminator exits a region and forwards all of its operands as "exiting" values.

These additions allow for performing more general dataflow analysis in the presence of region holding operations.

Differential Revision: https://reviews.llvm.org/D78447
2020-04-21 02:59:25 -07:00
River Riddle 152d29cc74 [mlir][Transforms] Add pass to perform sparse conditional constant propagation
This revision adds the initial pass for performing SCCP generically in MLIR. SCCP is an algorithm for propagating constants across control flow, and optimistically assumes all values to be constant unless proven otherwise. It currently supports branching control, with support for regions and inter-procedural propagation being added in followups.

Differential Revision: https://reviews.llvm.org/D78397
2020-04-21 02:59:25 -07:00
Pierre Oechsel 12dcb89dad [mlir] [linalg] Only promote selected buffers.
The promotion transformation is promoting all input and output buffers of the transformed op. The user might want to only promote some of these buffers.

Differential Revision: https://reviews.llvm.org/D78498
2020-04-21 11:50:08 +02:00
River Riddle b87531ca68 [mlir] Fix getTypes() support for result ranges. 2020-04-20 17:18:42 -07:00
Sean Silva 22219cfc6a Fix inlining multi-block callees with type conversion.
The previous code result a mismatch between block argument types and
predecessor successor args when a type conversion was needed in a
multiblock case. It was assuming the replaced result types matched the
region result types.

Also, slighly improve the debug output from the inliner.

Differential Revision: https://reviews.llvm.org/D78415
2020-04-20 16:54:01 -07:00
Jacques Pienaar 9ba37b3bf2 [mlir][ods] Add materialize derived attribute method
Summary:
Generate method to generate a DictionaryAttr with attribute values of
derived attribute. If a conversion back from the derived attribute C++
type to Attribute is not defined, then attempting to materialize such an
op's derived attributes would result in runtime failure.

This allows to treat derived attributes and attributes of an op in more
uniform manner where needed. The derived attributes are not added to the
operation but returned as new attribute instead.

Differential Revision: https://reviews.llvm.org/D78302
2020-04-20 13:13:04 -07:00
Uday Bondhugula 2d231c703d [MLIR] NFC clean up loop tiling test cases
Summary:
Improve the checks and drop redundant ones. Rename the outlined maps
better.

Reviewers: andydavis1, nicolasvasilache

Subscribers: mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, Joonsoo, grosul1, frgossen, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78514
2020-04-21 01:13:46 +05:30
Uday Bondhugula 3dff8c9109 [MLIR] Fix affine loop tiling utility upper bound bug
Fix intra-tile upper bound setting in a scenario where the tile size was
larger than the trip count.

Differential Revision: https://reviews.llvm.org/D78505
2020-04-21 00:54:01 +05:30
Lei Zhang f83d502feb [mlir][spirv] NFC: remove unnecessary `%N =` in test CHECKs 2020-04-20 11:52:29 -04:00
Lei Zhang ba49096817 [mlir][spirv] Lower memref with dynamic dimensions to runtime arrays
memref types with dynamic dimensions do not have a compile-time
known size. They should be mapped to SPIR-V runtime array types.

Differential Revision: https://reviews.llvm.org/D78197
2020-04-20 11:48:47 -04:00
Alexander Belyaev 871beba234 [MLIR] Add AtomicRMWRegionOp.
https://llvm.discourse.group/t/rfc-add-std-atomic-rmw-op/489

Differensial revision: https://reviews.llvm.org/D78352
2020-04-20 17:13:28 +02:00
Denis Khalikov a48f0a3c7e [mlir][vulkan-runner] Simplify vulkan launch call op.
Summary:
Workgroup size is written into the kernel. So to properly modelling
vulkan launch, we have to skip local workgroup size for vulkan launch
call op.

Differential Revision: https://reviews.llvm.org/D78307
2020-04-18 16:49:47 +03:00
Lucy Fox a0d5e54966 [MLIR] Update tutorial to add missing tests and bring directory paths and code snippets up to date.
Summary:
The tests referred to in Chapter 3 of the tutorial were missing from the tutorial test
directory; this adds those missing tests. This also cleans up some stale directory paths and code
snippets used throughout the tutorial.

Differential Revision: https://reviews.llvm.org/D76809
2020-04-17 20:15:16 -07:00
Lucy Fox a6b427167e [MLIR] Update tutorial to add missing tests and bring directory paths and code snippets up to date.
Summary:
The tests referred to in Chapter 3 of the tutorial were missing from the tutorial test
directory; this adds those missing tests. This also cleans up some stale directory paths and code
snippets used throughout the tutorial.

Differential Revision: https://reviews.llvm.org/D76809
2020-04-17 20:15:15 -07:00
Lucy Fox 495cf27291 [MLIR] Update tutorial to add missing tests and bring directory paths and code snippets up to date.
Summary:
The tests referred to in Chapter 3 of the tutorial were missing from the tutorial test
directory; this adds those missing tests. This also cleans up some stale directory paths and code
snippets used throughout the tutorial.

Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, aartbik, liufengdb, Joonsoo, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D76809
2020-04-17 20:15:15 -07:00
aartbik 186709c6e0 [mlir] [VectorOps] Progressive lowering of vector.broadcast
Summary:
Rather than having a full, recursive, lowering of vector.broadcast
to LLVM IR, it is much more elegant to have a progressive lowering
of each vector.broadcast into a lower dimensional vector.broadcast,
until only elementary vector operations remain. This results
in more elegant, step-wise code, that is easier to understand.
Also makes some optimizations in the generated code.

Reviewers: nicolasvasilache, mehdi_amini, andydavis1, grosul1

Reviewed By: nicolasvasilache

Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, grosul1, frgossen, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78071
2020-04-16 21:02:27 -07:00
Nicolas Vasilache 40d139c620 [mlir][Linalg] NFC - Split out EDSCs that require a Folder
Summary: This is an NFC cleanup in preparation for end-to-end named Linalg ops.

Differential Revision: https://reviews.llvm.org/D78331
2020-04-16 18:06:05 -04:00
Alex Zinenko f072942fe2 [mlir] ODS: support operations with resizable operand lists
MLIR supports operations with resizable operand lists, but this property must
be indicated during the construction of such operations. It can be done
programmatically by calling a function on OperationState. Introduce an
ODS-internal trait `ResizableOperandList` to indicate such operations are use
it when generating the bodies of various `build` functions as well as the
`parse` function when the declarative assembly format is used.

Differential Revision: https://reviews.llvm.org/D78292
2020-04-16 23:30:34 +02:00
Stephen Neuendorffer f061295732 [MLIR] Complete refactoring of Affine dialect into sub-libraries.
There were some unused CMakeFiles for Affine/IR and Affine/EDSC.
This change builds separate MLIRAffineOps and MLIRAffineEDSC libraries
using those CMakeFiles.  This combination replaces the old MLIRAffine
library.

Differential Revision: https://reviews.llvm.org/D78317
2020-04-16 13:41:17 -07:00
Nicolas Vasilache f54312277c [mlir][Linalg] Drop function attribute from generic ops.
The function attribute in generic ops is not paying for itself.
A region is the more standardized way of specifying a custom computation.
If needed this region can call a function directly.
This is deemed more natural than managing a dedicated function attribute.

This also simplifies named ops generation by trimming unnecessary complexity.

Differential Revision: https://reviews.llvm.org/D78266
2020-04-16 09:47:08 -04:00
Ulysse Beaugnon 11f093fab4 [MLIR] Add IndexAttr to primitive attributes kinds in tablegen.
OpBase.td defined attributes kind for all integer types expect index. This
commit fixes that by adding an IndexAttr attribute kind. Update the
respective tests.

Differential Revision: https://reviews.llvm.org/D78195
2020-04-16 14:59:26 +02:00
Benjamin Kramer d9c7fc658d Revert "[MLIR] Add IndexAttr to primitive attributes kinds in tablegen."
This reverts commit 997f33cfee. Breaks check-mlir

******************** TEST 'MLIR :: IR/attribute.mlir' FAILED ********************
Script:
--
: 'RUN: at line 1';   mlir-opt llvm-project/mlir/test/IR/attribute.mlir -split-input-file -verify-diagnostics | /FileCheck llvm-project/mlir/test/IR/attribute.mlir
--
Exit Code: 1

Command Output (stderr):
--
llvm-project/mlir/test/IR/attribute.mlir split at line #1:19:3: error: unexpected error: 'test.int_attrs' op requires attribute 'index_attr'
  "test.int_attrs"() {
  ^
llvm-project/mlir/test/IR/attribute.mlir split at line #120:6:3: error: unexpected error: 'test.int_attrs' op requires attribute 'index_attr'
  "test.int_attrs"() {
  ^
llvm-project/mlir/test/IR/attribute.mlir split at line #120:5:6: error: expected error "'si32_attr' failed to satisfy constraint: 32-bit signed integer attribute" was not produced
  // expected-error @+1 {{'si32_attr' failed to satisfy constraint: 32-bit signed integer attribute}}
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
llvm-project/mlir/test/IR/attribute.mlir split at line #133:5:3: error: unexpected error: 'test.int_attrs' op requires attribute 'index_attr'
  "test.int_attrs"() {
  ^
llvm-project/mlir/test/IR/attribute.mlir split at line #133:4:6: error: expected error "'ui32_attr' failed to satisfy constraint: 32-bit unsigned integer attribute" was not produced
  // expected-error @+1 {{'ui32_attr' failed to satisfy constraint: 32-bit unsigned integer attribute}}
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
llvm-project/mlir/test/IR/attribute.mlir:9:12: error: CHECK: expected string not found in input
 // CHECK: any_i32_attr = 5 : ui32
           ^
<stdin>:3:1: note: scanning from here
module {
^
<stdin>:21:28: note: possible intended match here
 "test.non_negative_int_attr"() {i32attr = 5 : i32, i64attr = 10 : i64} : () -> ()
2020-04-16 14:28:18 +02:00
Stephan Herhut 69040d5b0b [MLIR] Allow for multiple gpu modules during translation.
This change makes the ModuleTranslation threadsafe by locking on the
LLVMContext. Furthermore, we now clone the llvm module into a new
context when compiling to PTX similar to what the OrcJit does.

Differential Revision: https://reviews.llvm.org/D78207
2020-04-16 14:18:31 +02:00
Alexander Belyaev be9c3bdc44 [MLIR] Fix fusion of linalg.indexed_generic producer into tiled (Indexed)GenericOp.
Differential Revision: https://reviews.llvm.org/D78209
2020-04-16 10:45:17 +02:00
Ulysse Beaugnon 997f33cfee [MLIR] Add IndexAttr to primitive attributes kinds in tablegen.
Summary:
OpBase.td defined attributes kind for all integer types expect index. This
commit fixes that by adding an IndexAttr attribute kind.

Differential Revision: https://reviews.llvm.org/D78195
2020-04-16 10:28:33 +02:00
Mehdi Amini a07e5b8574 Fix build by adding missing CMake link dependency
This would only fail when using a linker that is sensitive to the order
in which the libraries are passed on the command line (like bfd).
2020-04-16 03:49:21 +00:00