Commit Graph

10859 Commits

Author SHA1 Message Date
Lei Zhang 7d249dfd7d [mlir][linalg] NFC: minor cleanups after moving pad to tensor dialect
Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D120627
2022-03-03 09:44:54 -05:00
Matthias Springer 6fc753adaf [mlir][bufferize] Always bufferize top-to-bottom
This ensures that we generate memref types with matching layout maps. (Especially when using partial bufferization passes.)

Differential Revision: https://reviews.llvm.org/D120893
2022-03-03 22:12:20 +09:00
Matthias Springer 16cbe883b5 [mlir][linalg][bufferize] Migrate --linalg-bufferize to BufferizableOpInterface-based bufferization
This commit deletes the old dialect conversion-based bufferization patterns, which are now obsolete.

Differential Revision: https://reviews.llvm.org/D120883
2022-03-03 20:12:37 +09:00
Andrzej Warzynski 1b2e35e4d4 Revert "[mlir] Add extensible dialects"
This reverts commit dbe9f0914f.

The flang-x86_64-windows buildbot has been failing since this has been merged:
* https://lab.llvm.org/buildbot/#/builders/172/builds/9124
Similar failure was reported by the pre-commit CI.
2022-03-03 10:30:50 +00:00
Peixin-Qiao a5605c9a15 [MLIR] Fix afterIP for dynamic worksharing-loop after collaping loops
The loopInfos gets invalidated after collapsing nested loops. Use the
saved afterIP since the returned afterIP by applyDynamicWorkshareLoop
may be not valid.

Reviewed By: shraiysh

Differential Revision: https://reviews.llvm.org/D120294
2022-03-03 15:22:20 +08:00
River Riddle 3ba66435d9 [mlir][SPIRV] Split up StandardToSPIRV now that the Standard dialect is gone
StandardToSPIRV currently contains an assortment of patterns converting from
different dialects to SPIRV. This commit splits up StandardToSPIRV into separate
conversions for each of the dialects involved (some of which already exist).

Differential Revision: https://reviews.llvm.org/D120767
2022-03-02 13:14:36 -08:00
Mathieu Fehr dbe9f0914f [mlir] Add extensible dialects
Add support for extensible dialects, which are dialects that can be
extended at runtime with new operations and types.

These operations and types cannot at the moment implement traits
or interfaces.

Differential Revision: https://reviews.llvm.org/D104554
2022-03-02 12:42:59 -08:00
natashaknk 8d7a833eed [tosa][mlir] Add support for dynamic width/height for Conv2D inputs in tosa-to-linalg
Infers output shape for dynamic width/height inputs.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D119977
2022-03-02 12:16:35 -08:00
William S. Moses 758ddba381 [MLIR] Use Datalayout defaults when importing LLVM
LLVM defines several default datalayouts for integer and floating point types that are not being considered when importing into MLIR. This patch remedies this.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D120832
2022-03-02 13:00:53 -05:00
William S. Moses bf6477ebeb [MLIR][OpenMP] Place alloca scope within wsloop in scf.parallel to omp lowering
https://reviews.llvm.org/D120423 replaced the use of stacksave/restore with memref.alloca_scope, but kept the save/restore at the same location. This PR places the allocation scope within the wsloop, thus keeping the same allocation scope as the original scf.parallel (e.g. no longer over stack allocating).

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D120772
2022-03-02 12:46:58 -05:00
William S. Moses 2af81c6978 [MLIR][Arith] Canonicalize cmpi of extui/extsi
Canonicalize cmpi(eq, ext a, ext b) and cmpi(ne, ext a, ext b)

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D120620
2022-03-02 12:30:03 -05:00
William S. Moses db31da279f [MLIR][Arith] Add constant folder for left shift
Add constant folder for left shift

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D120661
2022-03-02 12:00:23 -05:00
Alex Zinenko eb27da7dec [mlir] Ignore index data layout in translation to LLVM
It can be present, but is irrelevant for the translation.
2022-03-02 16:56:21 +01:00
Groverkss bb9013555f [MLIR][Presburger] Move functionality from IntegerPolyhedron to IntegerRelation
This patch moves all functionality from IntegerPolyhedron to IntegerRelation.
IntegerPolyhedron is now implemented as a relation with no domain. All existing
functionality is extended to work on relations.

This patch does not affect external users like FlatAffineConstraints as they
can still continue to use IntegerPolyhedron abstraction.

This patch is part of a series of patches to support relations in Presburger
library.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D120652
2022-03-02 20:10:44 +05:30
Alex Zinenko ea998709eb [mlir] Add partial support for translating data layout
Add support for translating data layout specifications for integer and float
types between MLIR and LLVM IR. This is a first step towards removing the
string-based LLVM dialect data layout attribute on modules. The latter is still
available and will remain so until the first-class MLIR modeling can fully
replace it.

Depends On D120739

Reviewed By: wsmoses

Differential Revision: https://reviews.llvm.org/D120740
2022-03-02 14:56:50 +01:00
Alex Zinenko f64170aa1d [mlir] Data layout for integer and float types
Add support for integer and float types into the data layout subsystem with
default logic similar to LLVM IR. Given the flexibility of the sybsystem, the
logic can be easily overwritten by operations if necessary. This provides the
connection necessary, e.g., for the GPU target where alignment requirements for
integers and floats differ from those provided by default (although still
compatible with the LLVM IR model). Previously, it was impossible to use
non-default alignment requirements for integer and float types, which could
lead to incorrect address and size calculations when targeting GPUs.

Depends On D120737

Reviewed By: wsmoses

Differential Revision: https://reviews.llvm.org/D120739
2022-03-02 14:56:49 +01:00
Alex Zinenko 554839ecdf [mlir] support f80 and f128 in parseOptionalType
This seems to have been forgotten when the types were introduced.

Reviewed By: wsmoses

Differential Revision: https://reviews.llvm.org/D120737
2022-03-02 14:56:47 +01:00
Shraiysh Vaishay d2f0fe23d2 [mlir][OpenMP] Added assemblyFormat for atomic and critical operations
This patch adds assemblyFormat for `omp.critical.declare`, `omp.atomic.read`,
`omp.atomic.write`, `omp.atomic.update` and `omp.atomic.capture`.

Also removing those clauses from `parseClauses` that aren't needed
anymore, thanks to the new assemblyFormats.

Reviewed By: NimishMishra, rriddle

Differential Revision: https://reviews.llvm.org/D120248
2022-03-02 11:22:09 +05:30
Aart Bik d8b229a1d5 [mlir][sparse][pytaco] added test with various sparse annotations
This also found a bug in the new toMLIR code (missing permutation)

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D120783
2022-03-01 16:36:19 -08:00
Bixia Zheng c25f3dfff3 [mlir][sparse][taco] Support tensor dimension storage ordering and more general
sparsity values.

Previously, we can't properly handle input tensors with a dimension
ordering that is different from the natural ordering or with a mixed of
compressed and dense dimensions. This change fixes the problems by
passing the dimension ordering and sparsity values to the runtime
routine.

Modify an existing test to test the situation.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D120777
2022-03-01 15:36:38 -08:00
Max Kudryavtsev c26fcd1ab8 [MLIR] [Arith] [NFC] Remove switch statement default label due to warning
We are getting compiler warning because default label is excessive. Removing it for now.

[[ http://lab.llvm.org:8011/#/builders/61/builds/22782/steps/5/logs/warnings__2_ | view on buildbot ]]

```
/vol/worker/mlir-nvidia/mlir-nvidia/llvm.src/mlir/lib/Dialect/Arithmetic/IR/ArithmeticOps.cpp:1597:9: warning: default label in switch which covers all enumeration values [-Wcovered-switch-default]
```

Related to: [[ https://reviews.llvm.org/D117257 | D117257 ]]

Reviewed By: stella.stamenova

Differential Revision: https://reviews.llvm.org/D120730
2022-03-01 15:24:03 -08:00
rkayaith d75ac58117 [mlir] Add option to control python search priming
This adds an option to configure the CMake python search priming
behaviour that was introduced in D118148. In some environments the
priming would cause the "real" search to fail. The default behaviour is
unchanged, i.e. the search will be primed.

Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D120765
2022-03-01 14:52:56 -08:00
River Riddle 026fe5ffc3 [mlir][NFC] Remove several dead references to the old standard dialect 2022-03-01 14:02:24 -08:00
River Riddle 2f5715dc78 [mlir][NFC] Rename the old Standard dialect test directory to Func
The remanants of Standard was renamed to Func, but the test directory
remained named as Standard. In adidition to fixing the name, this commit
also moves the tests for operations not in the Func dialect to the proper
parent dialect test directory.
2022-03-01 13:48:34 -08:00
River Riddle 1f971e23f0 [mlir] Trim a huge number of unnecessary dependencies on the Func dialect
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 12:10:04 -08:00
River Riddle 23aa5a7446 [mlir] Rename the Standard dialect to the Func dialect
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-03-01 12:10:04 -08:00
rdzhabarov 2e32525d95 [mlir] Fix unused var warning in the IR/MemRefOps.cpp
Fix unused var compiler warning.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D120759
2022-03-01 19:53:52 +00:00
Aart Bik 1e47888de6 [mlir][sparse] fix compile-time warning
Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D120756
2022-03-01 11:26:15 -08:00
Bixia Zheng 20eaa88fff [mlir][sparse] Extend convertToMLIRSparseTensor to support permutation and more general sparsity values.
Previously, convertToMLIRSparseTensor assumes identity storage ordering and all
compressed dimensions. This change extends the function with two parameters for
users to specify the storage ordering and the sparsity of each dimension.

Modify PyTACO to reflect this change.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D120643
2022-03-01 10:51:39 -08:00
William S. Moses 78fb4f9d5d [SCF][MemRef] Enable SCF.Parallel Lowering to use Scope Op
As discussed in https://reviews.llvm.org/D119743 scf.parallel would continuously stack allocate since the alloca op was placd in the wsloop rather than the omp.parallel. This PR is the second stage of the fix for that problem. Specifically, we now introduce an alloca scope around the inlined body of the scf.parallel and enable a canonicalization to hoist the allocations to the surrounding allocation scope (e.g. omp.parallel).

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D120423
2022-03-01 13:25:09 -05:00
Lei Zhang c809c9bd3b [mlir][spirv] Convert gpu.barrier to spv.ControlBarrier
Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D120722
2022-03-01 12:04:00 -05:00
Alex Zinenko 5c73db24df [mlir] disallow side-effecting ops in llvm.mlir.global
The llvm.mlir.global operation accepts a region as initializer. This region
corresponds to an LLVM IR constant expression and therefore should not accept
operations with side effects. Add a corresponding verifier.

Reviewed By: wsmoses, bondhugula

Differential Revision: https://reviews.llvm.org/D120632
2022-03-01 14:16:09 +01:00
gysit e9085d0d25 [mlir][OpDSL] Rename function to make signedness explicit (NFC).
The revision renames the following OpDSL functions:
```
TypeFn.cast -> TypeFn.cast_signed
BinaryFn.min -> BinaryFn.min_signed
BinaryFn.max -> BinaryFn.max_signed
```
The corresponding enum values on the C++ side are renamed accordingly:
```
#linalg.type_fn<cast> -> #linalg.type_fn<cast_signed>
#linalg.binary_fn<min> -> #linalg.binary_fn<min_signed>
#linalg.binary_fn<max> -> #linalg.binary_fn<max_signed>
```

Depends On D120110

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D120562
2022-03-01 08:15:53 +00:00
Lorenzo Chelini e8659c994d [MLIR][Standalone] Don't look for Python if bindings are OFF
Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D120700
2022-03-01 08:55:15 +01:00
gysit 24357fec8d [mlir][OpDSL] Add arithmetic function attributes.
The revision extends OpDSL with unary and binary function attributes. A function attribute, makes the operations used in the body of a structured operation configurable. For example, a pooling operation may take an aggregation function attribute that specifies if the op shall implement a min or a max pooling. The goal of this revision is to define less and more flexible operations.

We may thus for example define an element wise op:
```
linalg.elem(lhs, rhs, outs=[out], op=BinaryFn.mul)
```
If the op argument is not set the default operation is used.

Depends On D120109

Reviewed By: nicolasvasilache, aartbik

Differential Revision: https://reviews.llvm.org/D120110
2022-03-01 07:45:47 +00:00
Michael Kruse a66f7769a3 [OpenMPIRBuilder] Implement static-chunked workshare-loop schedules.
Add applyStaticChunkedWorkshareLoop method implementing static schedule when chunk-size is specified. Unlike a static schedule without chunk-size (where chunk-size is chosen by the runtime such that each thread receives one chunk), we need two nested loops: one for looping over the iterations of a chunk, and a second for looping over all chunks assigned to the threads.

This patch includes the following related changes:
 * Adapt applyWorkshareLoop to triage between the schedule types, now possible since all schedules have been implemented. The default schedule is assumed to be non-chunked static, as without OpenMPIRBuilder.
 * Remove the chunk parameter from applyStaticWorkshareLoop, it is ignored by the runtime. Change the value for the value passed to the init function to 0, as without OpenMPIRBuilder.
 * Refactor CanonicalLoopInfo::setTripCount and CanonicalLoopInfo::mapIndVar as used by both, applyStaticWorkshareLoop and applyStaticChunkedWorkshareLoop.
 * Enable Clang to use the OpenMPIRBuilder in the presence of the schedule clause.

Differential Revision: https://reviews.llvm.org/D114413
2022-02-28 18:18:33 -06:00
not-jenni fd2550d80c Adds a flag to optionally disable tosa decompositions
Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D120338
2022-02-28 15:41:13 -08:00
Okwan Kwon 4c901bf447 [mlir] Match Arithmetic::ConstantOp and Tensor::ExtractSliceOp.
Add a pattern matcher for ExtractSliceOp when its source is a constant.

The matching heuristics can be governed by the control function since
generating a new constant is not always beneficial.

Differential Revision: https://reviews.llvm.org/D119605
2022-02-28 23:09:03 +00:00
Lei Zhang 96bc2233c4 [mlir][linalg] Enhance FoldInsertPadIntoFill to support op chain
If we have a chain of `tensor.insert_slice` ops inserting some
`tensor.pad` op into a `linalg.fill` and ranges do not overlap,
we can also elide the `tensor.pad` later.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D120446
2022-02-28 16:51:17 -05:00
Lei Zhang 5d47332783 [mlir][linalg] Fold tensor.pad when inserting into linalg.fill
Fold tensor.insert_slice(tensor.pad(<input>), linalg.fill) into
tensor.insert_slice(<input>, linalg.fill) if the padding value and
the filling value are the same.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D120410
2022-02-28 16:42:32 -05:00
Okwan Kwon 4f5eb53e68 Revert "[mlir] Fold Arithmetic::ConstantOp and Tensor::ExtractSliceOp."
This reverts commit 3104994104.
2022-02-28 19:14:05 +00:00
Chia-hung Duan d56ef5ed20 [mlir-tblgen] Fix non-deterministic generating static verifier in DRR.
Use SetVector instead of DenseSet to ensure we always generate the same
name for the same function. This issue is found in
https://github.com/llvm/llvm-project/issues/53768.

Reviewed By: quinnp, rdzhabarov

Differential Revision: https://reviews.llvm.org/D120514
2022-02-28 18:36:22 +00:00
Okwan Kwon 3104994104 [mlir] Fold Arithmetic::ConstantOp and Tensor::ExtractSliceOp.
Fold ExtractSliceOp when the source is a constant.
2022-02-28 17:47:29 +00:00
Adrian Kuegel a91ade0ba6 [mlir] Apply ClangTidy performance fixes (NFC) 2022-02-28 13:18:10 +01:00
gysit 11d144c576 [mlir][linalg] Check the iterator types are valid.
Improve the LinalgOp verification to ensure the iterator types is known. Previously, unknown iterator types have been ignored without warning, which can lead to confusing bugs.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D120649
2022-02-28 11:25:40 +00:00
Adrian Kuegel 44adca60d4 [mlir] Remove unused static variables (NFC) 2022-02-28 11:52:39 +01:00
Mehdi Amini 47ddf382e6 Add explicit `this->` to access method in attempt to fix gcc5 build (NFC) 2022-02-28 08:54:38 +00:00
Shraiysh Vaishay 77296dc5e9 [mlir][OpenMP][NFC] Removing unnecessary builders for wsloop
This patch removes the builders for `omp.wsloop` operation that aren't
specifically needed anywhere. We can add them later if the need arises.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D120533
2022-02-28 14:22:43 +05:30
Alexander Belyaev 1a829d2d06 [mlir] Purge linalg.tiled_loop.
Differential Revision: https://reviews.llvm.org/D119415
2022-02-28 09:05:18 +01:00
Mehdi Amini fdfe26ddbe Add explicit capture for `this` pointer in attempt to fix gcc5 build (NFC) 2022-02-27 21:41:23 +00:00
Groverkss b486a9de80 [MLIR][Presburger] Move IntegerPolyhedron::reset to FlatAffineConstraints::reset
This patch moves IntegerPolyhedron::reset to FlatAffineConstraints::reset. This
function is not required in IntegerPolyhedron and creates ambiguity while
shifting implementations to IntegerRelation.

This patch is part of a series of patches to introduce relations in Presburger
library.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D120628
2022-02-27 22:27:28 +05:30
River Riddle b474ca1d5a [PDLL] Properly error out on returning results from native constraints
PDL currently doesn't support result values from constraints, meaning we need
to error out until this is actually supported to avoid crashes.

Differential Revision: https://reviews.llvm.org/D119782
2022-02-26 11:08:51 -08:00
River Riddle 9ad64a5c78 [mlir:PDLL] Add support for C++ generation
This commits adds a C++ generator to PDLL that generates wrapper PDL patterns
directly usable in C++ code, and also generates the definitions of native constraints/rewrites
that have code bodies specified in PDLL. This generator is effectively the PDLL equivalent of
the current DRR generator, and will allow easy replacement of DRR patterns with PDLL patterns.
A followup will start to utilize this for end-to-end integration testing and show case how to
use this as a drop-in replacement for DRR tablegen usage.

Differential Revision: https://reviews.llvm.org/D119781
2022-02-26 11:08:51 -08:00
River Riddle a486cf5e98 [mlir:PDLL] Fix handling of unspecified operands/results on operation expressions
If the operand list or result list of an operation expression is not specified, we interpret
this as meaning that the operands/results are "unconstraint" (i.e. "could be anything").
We currently don't properly handle differentiating this case from the case of
"no operands/results". This commit adds the insertion of implicit value/type range
variables when these lists are unspecified. This allows for adding proper support
for when zero operands or results are expected.

Differential Revision: https://reviews.llvm.org/D119780
2022-02-26 11:08:51 -08:00
River Riddle 95b4e88b1d [mlir:PDLL] Add support for PDL MLIR code generation
This commits starts to plumb PDLL down into MLIR and adds an initial
PDL generator. After this commit, we will have conceptually support
end-to-end execution of PDLL. Followups will add CPP generation to
match the current DRR setup, and begin to add various end-to-end
tests to test PDLL execution.

Differential Revision: https://reviews.llvm.org/D119779
2022-02-26 11:08:51 -08:00
Groverkss e897214e97 [MLIR][Presburger] Remove redundant check from hasConsistentState
This patch removes a redundant check in hasConsistentState which is always true
after introduction of PresburgerSpace.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D120615
2022-02-26 22:02:17 +05:30
Groverkss 3001d4674d [MLIR][Presburger] Move IdKind specific insert/append
This patch moves identifier kind specific insert/append functions like
`insertDimId`, `appendSymbolId`, etc. from IntegerPolyhedron to
FlatAffineConstraints.

This change allows for a smoother transition to IntegerRelation.

This change is part of a series of patches to introduce Relations in Presburger
library.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D120576
2022-02-26 18:54:30 +05:30
Groverkss 24008dee9e [MLIR][Presburger] Factor out various Space equality checks to PresburgerSpace::isEqual
This patch factors out various checks for dimension compatibility to
PresburgerSpace::isEqual and PresburgerLocalSpace::isEqual (for local
identifiers).

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D120565
2022-02-26 18:02:14 +05:30
Arjun P 72005a1325 [MLIR][Presburger] coalesce: add assert noting that locals are not yet supported 2022-02-26 12:31:02 +00:00
Michel Weber 730acdc445 [MLIR][Presburger] fix double increment in coalesce
In the main-loop of the current coalesce implementation `i` was incremented
twice for some cases. This patch fixes this bug and adds a regression
testcase.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D120613
2022-02-26 10:37:19 +00:00
Aart Bik 8e4f8d3532 [mlir][sparse] merge ifs in new sparse rewriting rules
Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D120500
2022-02-25 15:06:47 -08:00
Aart Bik 180c9f9efe [mlir][sparse] enable scalar test
Removed TODO now that we support scalars properly

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D120590
2022-02-25 15:05:25 -08:00
Bixia Zheng 6f07191101 [mlir][sparse][taco] Support reduction to scalar tensors.
The PyTACO DSL doesn't support reduction to scalars. This change
enhances the MLIR-PyTACO implementation to support reduction to scalars.

Extend an existing test to show the syntax of reduction to scalars and
two methods to retrieve the scalar values.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D120572
2022-02-25 14:17:45 -08:00
Hanhan Wang 748bf4bb28 [mlir][Linalg] Add support for tileFuseAndDistribute on tensors.
This extends TileAndFuse to handle distribution on tensors.

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D120441
2022-02-25 11:51:11 -08:00
Diego Caballero 875bbce9f7 [mlir][Vector] Prevent AVX2 lowering for non-f32 transpose ops
The AVX2 lowering for transpose operations is only applicable to f32 vector types.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D120427
2022-02-25 19:27:32 +00:00
Diego Caballero d7e0a0846b [mlir][Vector] Generalize AVX2 transpose lowering to n-D vectors
The existing AVX2 lowering patterns for the transpose op only triggers if the
input vector is 2-D. This patch extends the patterns to trigger for n-D vectors
which are effectively 2-D vectors (e.g., vector<1x4x1x8x1). The main constraint
for the generalized AVX2 patterns to be applicable to these vectors is that the
dimensions that are greater than one must be transposed. Otherwise, the existing
patterns are not applicable.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D119505
2022-02-25 19:27:32 +00:00
Chia-hung Duan 9445b39673 [mlir] Support verification order (2/3)
This change gives explicit order of verifier execution and adds
    `hasRegionVerifier` and `verifyWithRegions` to increase the granularity
    of verifier classification. The orders are as below,

    1. InternalOpTrait will be verified first, they can be run independently.
    2. `verifyInvariants` which is constructed by ODS, it verifies the type,
       attributes, .etc.
    3. Other Traits/Interfaces that have marked their verifier as
       `verifyTrait` or `verifyWithRegions=0`.
    4. Custom verifier which is defined in the op and has marked
       `hasVerifier=1`

    If an operation has regions, then it may have the second phase,

    5. Traits/Interfaces that have marked their verifier as
       `verifyRegionTrait` or
       `verifyWithRegions=1`. This implies the verifier needs to access the
       operations in its regions.
    6. Custom verifier which is defined in the op and has marked
       `hasRegionVerifier=1`

    Note that the second phase will be run after the operations in the
    region are verified. Based on the verification order, you will be able to
    avoid verifying duplicate things.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D116789
2022-02-25 19:04:56 +00:00
Bixia Zheng c601dfbcc2 [mlir][sparse][taco] Use np.array_equal to compare integer values.
Fix MLIR-PyTACO and some tests to use np.array_equal to compare integer
values.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D120526
2022-02-25 07:38:15 -08:00
gysit cd2776b0d5 [mlir][OpDSL] Split arithmetic functions.
Split arithmetic function into unary and binary functions. The revision prepares the introduction of unary and binary function attributes that work similar to type function attributes.

Depends On D120108

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D120109
2022-02-25 15:27:42 +00:00
Bixia Zheng 90f22ab3ad [mlir][sparse][taco] Add support for scalar tensors.
This change allows the use of scalar tensors with index 0 in tensor index
expressions. In this case, the scalar value is broadcast to match the
dimensions of other tensors in the same expression.

Using scalar tensors as a destination in tensor index expressions is not
supported in the PyTACO DSL.

Add a PyTACO test to show the use of scalar tensors.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D120524
2022-02-25 07:20:15 -08:00
gysit 4d4cb17da8 [mlir][OpDSL] Refactor function handling.
Prepare the OpDSL function handling to introduce more function classes. A follow up commit will split ArithFn into UnaryFn and BinaryFn. This revision prepares the split by adding a function kind enum to handle different function types using a single class on the various levels of the stack (for example, there is now one TensorFn and one ScalarFn).

Depends On D119718

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D120108
2022-02-25 15:05:32 +00:00
Arjun P cfab126888 [MLIR][Presburger] coalesce fixups: inline comments /// -> //, i++ -> ++i (NFC)
Also use empty() instead of size() == 0.
2022-02-25 13:53:03 +00:00
Michel Weber 4ae1855356 [MLIR][Presburger] Refactor looping strategy in coalesce
This patch refactors the looping strategy of coalesce for future patches. The new strategy works in-place and uses IneqType to organize inequalities into vectors of the same type. Future coalesce cases will pattern match on this organization. E.g. the contained case needs all inequalities and equalities to be redundant, so this case becomes checking whether the respective vectors are empty. For other cases, the patterns consider the types of all inequalities of both sets making it wasteful to only consider whether a can be coalesced with b in one step, as inequalities would need to be typed again for the opposite case. Therefore, the new strategy tries to coalesce a with b and b with a in a single step.

Reviewed By: Groverkss, arjunp

Differential Revision: https://reviews.llvm.org/D120392
2022-02-25 12:41:20 +00:00
Groverkss eff51cf9f3 [MLIR][Presburger] Use Matrix utilities for IntegerPolyhedron
This patch replaces various functions over inequalities/equalities in
IntegerPolyhedron with Matrix functions already implementing them or refactors
them to a Matrix function.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D120482
2022-02-25 17:35:13 +05:30
Groverkss 0c1f6865e9 [MLIR][Presburger] Move Presburger/ files to presburger namespace
This patch moves the Presburger library to a new `presburger` namespace.

This allows to shorten some names, helps to avoid polluting the mlir namespace,
and also provides some structure.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D120505
2022-02-25 16:01:29 +05:30
Groverkss aefd6b9f5a [MLIR][Presburger][NFC] Refactor redundant code in fourierMotzkinEliminate
This patch removes redundant code from fourierMotzkinEliminate implementation
using existing functions in IntegerPolyhedron.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D120502
2022-02-25 15:40:38 +05:30
gysit 51fdd802c7 [mlir][OpDSL] Add type function attributes.
Previously, OpDSL operation used hardcoded type conversion operations (cast or cast_unsigned). Supporting signed and unsigned casts thus meant implementing two different operations. Type function attributes allow us to define a single operation that has a cast type function attribute which at operation instantiation time may be set to cast or cast_unsigned. We may for example, defina a matmul operation with a cast argument:

```
@linalg_structured_op
def matmul(A=TensorDef(T1, S.M, S.K), B=TensorDef(T2, S.K, S.N), C=TensorDef(U, S.M, S.N, output=True),
    cast=TypeFnAttrDef(default=TypeFn.cast)):
  C[D.m, D.n] += cast(U, A[D.m, D.k]) * cast(U, B[D.k, D.n])
```

When instantiating the operation the attribute may be set to the desired cast function:

```
linalg.matmul(lhs, rhs, outs=[out], cast=TypeFn.cast_unsigned)
```

The revsion introduces a enum in the Linalg dialect that maps one-by-one to the type functions defined by OpDSL.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D119718
2022-02-25 08:25:23 +00:00
Michel Weber b3ebcd7226 [MLIR][Presburger] enable copy assignment operator for Simplex
This patch removes the `const` from `usingBigM` to enable the implicit copy assignment operator for Simplex.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D120542
2022-02-25 07:34:05 +00:00
Thomas Raoux b1357fe618 [mlir][memref] Add transformation to do loop multi-buffering
This transformation is useful to break dependency between consecutive loop
iterations by increasing the size of a temporary buffer. This is usually
combined with heavy software pipelining.

Differential Revision: https://reviews.llvm.org/D119406
2022-02-24 09:41:21 -08:00
Marius Brehler 1fa1251116 [mlir][emitc] Add a variable op
This adds a variable op, emitted as C/C++ locale variable, which can be
used if the `emitc.constant` op is not sufficient.

As an example, the canonicalization pass would transform
```mlir
%0 = "emitc.constant"() {value = 0 : i32} : () -> i32
%1 = "emitc.constant"() {value = 0 : i32} : () -> i32
%2 = emitc.apply "&"(%0) : (i32) -> !emitc.ptr<i32>
%3 = emitc.apply "&"(%1) : (i32) -> !emitc.ptr<i32>
emitc.call "write"(%2, %3) : (!emitc.ptr<i32>, !emitc.ptr<i32>) -> ()
```
into
```mlir
%0 = "emitc.constant"() {value = 0 : i32} : () -> i32
%1 = emitc.apply "&"(%0) : (i32) -> !emitc.ptr<i32>
%2 = emitc.apply "&"(%0) : (i32) -> !emitc.ptr<i32>
emitc.call "write"(%1, %2) : (!emitc.ptr<i32>, !emitc.ptr<i32>) -> ()
```
resulting in pointer aliasing, as %1 and %2 point to the same address.
In such a case, the `emitc.variable` operation can be used instead.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D120098
2022-02-24 15:25:21 +00:00
Shraiysh Vaishay f9fbaabe0f [mlir][OpenMP][NFC] Remove unused binary operator enum
This patch removes binary operator enum which was introduced with `omp.atomic.update`. Now the update operation handles update in a region so this is no longer required.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D120458
2022-02-24 19:06:10 +05:30
Alex Zinenko 5146067578 [mlir] Document creation of Python bindings for a dialect
Documentation exists about the details of the API but is missing a
description of the overall structure per dialect.

Reviewed By: shabalin

Differential Revision: https://reviews.llvm.org/D117002
2022-02-24 14:18:56 +01:00
Benjamin Kramer 92cf9f1481 [mlir][linalg] Cast back to the original type after making linalg.generic outputs more static
This codepath was entirely untested.

Differential Revision: https://reviews.llvm.org/D120473
2022-02-24 13:35:54 +01:00
Javier Setoain cd0d21b47b [mlir][LLVM] Allow scalable vectors in ShuffleVectorOp
The current implementation of ShuffleVectorOp assumes all vectors are
scalable. LLVM IR allows shufflevector operations on scalable vectors,
and the current translation between LLVM Dialect and LLVM IR does the
rigth thing when the shuffle mask is all zeroes. This is required to
do a splat operation on a scalable vector, but it doesn't make sense
for scalable vectors outside of that operation, i.e.: with non-all zero
masks.

Differential Revision: https://reviews.llvm.org/D118371
2022-02-24 11:24:34 +00:00
Matthias Springer 25bc684603 [mlir][linalg][bufferize] Always bufferize in-place with "out" operands by default
In D115022, we introduced an optimization where OpResults of a `linalg.generic` may bufferize in-place with an "in" OpOperand if the corresponding "out" OpOperand is not used in the computation.

This optimization can lead to unexpected behavior if the newly chosen OpOperand is in the same alias set as another OpOperand (that is used in the computation). In that case, the newly chosen OpOperand must bufferize out-of-place. This can be confusing to users, as always choosing the "out" OpOperand (regardless of whether it is used) would be expected when having the notion of "destination-passing style" in mind.

With this change, we go back to always bufferizing in-place with "out" OpOperands by default, but letting users override the behavior with a bufferization option.

Differential Revision: https://reviews.llvm.org/D120182
2022-02-24 19:58:05 +09:00
rkayaith e9db306dcd [mlir][python] Support more types in IntegerAttr.value
Previously only accessing values for `index` and signless int types
would work; signed and unsigned ints would hit an assert in
`IntegerAttr::getInt`. This exposes `IntegerAttr::get{S,U}Int` to the C
API and calls the appropriate function from the python bindings.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D120194
2022-02-24 10:26:31 +01:00
Adrian Kuegel c1d36e2304 [mlir][SCF] Apply suggested ClangTidy fixes. 2022-02-24 08:23:24 +01:00
Bixia Zheng c8ae8cfb5d [mlir][sparse][taco] Add support for float32.
Previously, we only support float64. We now support float32 and float64. When
constructing a tensor without providing a data type, the default is float32.

Fix the tests to data type consistency. All PyTACO application tests now use
float32 to match the default data type of TACO. Other tests may use float32 or
float64.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D120356
2022-02-23 18:24:22 -08:00
Aart Bik 652b39b46f [mlir][sparse][linalg] add linalg rewriting specific to sparse tensors
Now that sparse tensor types are first-class citizens and the sparse compiler
is taking shape, it is time to make sure other compiler optimizations compose
well with sparse tensors. Mostly, this should be completely transparent (i.e.,
dense and sparse take the same path). However, in some cases, optimizations
only make sense in the context of sparse tensors. This is a first example of
such an optimization, where fusing a sampled elt-wise multiplication only makes
sense when the resulting kernel has a potential lower asymptotic complexity due
to the sparsity.

As an extreme example, running SDDMM with 1024x1024 matrices and a sparse
sampling matrix with only two elements runs in 463.55ms in the unfused
case but just 0.032ms in the fused case, with a speedup of 14485x that
is only possible in the exciting world of sparse computations!

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D120429
2022-02-23 17:29:41 -08:00
Emilio Cota 011f653265 [mlir] Add sectionMemoryMapper to ExecutionEngineOptions
By specifying a sectionMemoryMapper, users can control how
memory for JIT code is allocated.

In particular, I need this in order to use a named memory
region so that profilers such as perf(1) can correctly label
execution cycles coming from JIT'ed code.

Reviewed-by: ezhulenev

Differential Revision: https://reviews.llvm.org/D120415
2022-02-23 14:56:50 -05:00
Arjun P 280d41d9bb [MLIR][Presburger] PresburgerSet::subtract: automatically restore state on return
Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D120339
2022-02-23 19:20:44 +00:00
William S. Moses 1b2a1f8473 [MLIR][Arith] Canonicalize cmpf(int to fp) to cmpi
Given a cmpf of either uitofp or sitofp and a constant, attempt to canonicalize it to a cmpi.

This PR rewrites equivalent code within LLVM to now apply to MLIR arith.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D117257
2022-02-23 14:09:20 -05:00
Eugene Zhulenev beff16f7bd [mlir] Async: update condition for dispatching block-aligned compute function
+ compare block size with the unrollable inner dimension
+ reduce nesting in the code and simplify a bit IR building

Reviewed By: cota

Differential Revision: https://reviews.llvm.org/D120075
2022-02-23 10:29:55 -08:00
Daniel Resnick e7f4ea8abe [MLIR][Pass] Have PassRegistryEntry own pass strings
This eliminates the requirement that pass-related strings outlive pass
instances, which will facilitate future work enabling dynamic passes
written in other languages.

Differential Revision: https://reviews.llvm.org/D120341
2022-02-23 10:04:04 -07:00
Emilio Cota a7db3c611b [mlir][NFC] Use options struct in ExecutionEngine::create
Its number of optional parameters has grown too large,
which makes adding new optional parameters quite a chore.

Fix this by using an options struct.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D120380
2022-02-23 10:21:46 -05:00
Arjun P 4b86d55997 [MLIR][Presburger] unittests: use an MLIRContext declared in parsePoly
Use an `MLIRContext` declared in a single place in the `parsePoly` function that almost all Presburger unit tests use for parsing sets. This function is only used in tests.

This saves us from having to declare and pass a new `MLIRContext` in every test.

Reviewed By: bondhugula, mehdi_amini

Differential Revision: https://reviews.llvm.org/D119251
2022-02-23 15:07:00 +00:00
Aart Bik 8b83b8f131 [mlir][sparse] refactor sparse compiler pipeline to single place
Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D120347
2022-02-22 16:23:56 -08:00
Okwan Kwon f79f430d4b Fold Tensor.extract_slice into a constant splat.
Fold arith.extract_slice into arith.constant when the source is a constant
splat and the result type is statically shaped.
2022-02-22 21:39:57 +00:00
Reid Kleckner de2cc2a002 Reland "[mlir][pdl] NFC re-add NoSideEffect to Result and Results Op"
This reverts commit 9865c3f28a.

Looks like our commits raced and Jeff fixed the build issue.
2022-02-22 10:48:25 -08:00
Mogball ef7b9824cd [mlir][pdl] NFC fix missing include 2022-02-22 18:47:25 +00:00
Reid Kleckner 9865c3f28a Revert "[mlir][pdl] NFC re-add NoSideEffect to Result and Results Op"
This reverts commit 63eb963e58.

Breaks MLIR build.
2022-02-22 10:46:49 -08:00
Mogball 63eb963e58 [mlir][pdl] NFC re-add NoSideEffect to Result and Results Op 2022-02-22 18:27:44 +00:00
Mogball 1da213836b [pdl] Remove `NoSideEffect` from all PDL ops
This trait results in PDL ops being erroneously CSE'd. These ops are side-effect free in the rewriter but not in the matcher (where unused values aren't allowed anyways). These ops should have a more nuanced side-effect modeling, this is fixing a bug introduced by a previous change.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D120222
2022-02-22 18:20:59 +00:00
Matthias Springer 5c4f749429 [mlir][bufferize] Fix GCC build
Differential Revision: https://reviews.llvm.org/D120326
2022-02-23 00:03:33 +09:00
Alexander Batashev 01c0b4d51c [mlir][spirv] Fix SPIR-V spec parser
Header class in SPIR-V HTML spec has changed. Update script to reflect that.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D120179
2022-02-22 14:07:46 +03:00
Arjun P cfd6ba89fd [MLIR][Presburger] rename get*LexMin -> find*LexMin
This reflects the fact that we are performing some non-trivial computations
here. Also, this is more uniform in line with findIntegerSample.
2022-02-22 11:00:22 +00:00
Matthias Springer 3b42686869 [mlir][bufferize] Do not assert destination passing style for non-bufferizable ops 2022-02-22 17:42:02 +09:00
Matthias Springer d2dacde5d8 [mlir][bufferize][NFC] Rename `comprehensive-function-bufferize` to `one-shot-bufferize`
The related functionality is moved over to the bufferization dialect. Test cases are cleaned up a bit.

Differential Revision: https://reviews.llvm.org/D120191
2022-02-22 17:19:20 +09:00
Groverkss e1191965da [MLIR][Presburger] Add support for IntegerRelation
This patch adds a class to represent a relation in Presburger Library.

This patch only adds the skeleton class. Functionality from IntegerPolyhedron
will be moved to IntegerRelation in later patches to make it easier to review.

This patch is a part of a series of patches adding support for relations in
Presburger Library.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D120156
2022-02-22 02:41:06 +05:30
Arjun P 9f8cb68570 [MLIR][Presburger] Support finding integer lexmin in IntegerPolyhedron
Note: this does not yet support PrebsurgerSets.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D120239
2022-02-21 21:02:21 +00:00
Benjamin Kramer ea7be7e32d [MLIR][PDL] Fix C++20 build. concept is a new keyword. NFC. 2022-02-21 18:37:19 +01:00
fuzzypixelz 175d5fa388 [MLIR] replace C++ function type defintion in the C API's Interfaces.h
Clearly this something of a typo, and it obviously doesn't even compile.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D120247
2022-02-21 07:53:59 -08:00
Alex Zinenko 8b734798a5 [mlir] Annotate methods on a correct class in PybindAdaptors.h
The `.def` and `.def_property_readonly` functions in PybindAdaptors.h should
construct the functions as method of the current class rather than as method of
pybind11:none(), which is an object and not even a class.

Depends On D117658

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D117659
2022-02-21 13:04:19 +01:00
Matthias Springer 41cb504b7c [mlir][linalg][bufferize][NFC] Move interface impl to Linalg Transforms
This is for consistency with other dialects.

Differential Revision: https://reviews.llvm.org/D120190
2022-02-21 17:14:24 +09:00
Prateek Gupta 1a2bb03eda [MLIR][LINALG] Add canonicalization pattern in `linalg.generic` op for static shape inference.
This commit adds canonicalization pattern in `linalg.generic` op
for static shape inference. If any of the inputs or outputs have
static shape or is casted from a tensor of static shape, then
shapes of all the inputs and outputs can be inferred by using the
affine map of the static shape input/output.

Signed-Off-By: Prateek Gupta <prateek@nod-labs.com>

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D118929
2022-02-21 07:51:13 +00:00
Shraiysh Vaishay c1e4e01945 [mlir][OpenMP] Added assemblyFormat for SectionsOp
This patch adds assemblyFormat for omp.sections operation.

Some existing functions have been altered to fit the custom directive
in assemblyFormat. This has led to their callsites to get modified too,
but those will be removed in later patches, when other operations get
their assemblyFormat. All operations were not changed in one patch for
ease of review.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D120176
2022-02-21 13:01:49 +05:30
Michel Weber 56bc87322c [MLIR][Presburger] Inequality Typing in coalesce
This patch adds typing of inequalities to the simplex. This is a cental part of the coalesce algorithm and will be heavily used in later coalesce patches. Currently, only the three most basic types are supported with more to be introduced when they are needed.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D119925
2022-02-20 23:19:14 +05:30
Arjun P 8e7995884a [MLIR][Presburger] Introduce MaybeOptimum type to represent computed optima
This allows to differentiate between the cases where the optimum does not
exist due to being unbounded and due to the polytope being empty.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D120127
2022-02-19 21:58:26 +00:00
Matthias Springer 4ec00fb3ea [mlir][bufferize] Add a way for ops to fail the analysis
Add `BufferizableOpInterface::verifyAnalysis`. Ops can implement this method to check for expected invariants and limitations.

The purpose of this change is to introduce a modular way of checking assertions such as `assertScfForAliasingProperties`.

Differential Revision: https://reviews.llvm.org/D120189
2022-02-20 05:51:18 +09:00
Shraiysh Vaishay 39151717db [mlir][OpenMP] Added assemblyFormat for ParallelOp
This patch adds assemblyFormat for omp.parallel operation.

Some existing functions have been altered to fit the custom directive
in assemblyFormat. This has led to their callsites to get modified too,
but those will be removed in later patches, when other operations get
their assemblyFormat. All operations were not changed in one patch for
ease of review.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D120157
2022-02-19 10:28:58 +05:30
Aart Bik 9b9a084af0 [mlir][sparse][pytaco] test with 3-dim tensor and scalar
Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D120163
2022-02-18 15:16:35 -08:00
Aart Bik 6438783fda [mlir][sparse] provide more types for external to/from MLIR routines
These routines will need to be specialized a lot more based on value types,
index types, pointer types, and permutation/dimension ordering. This is a
careful first step, providing some functionality needed in PyTACO bridge.

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D120154
2022-02-18 13:36:52 -08:00
Shraiysh Vaishay 60210f9acb [mlir][OpenMP] Added assemblyformat for TargetOp
This patch removes custom parser/printer for `omp.target` and adds
assemblyformat.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D120138
2022-02-19 01:22:59 +05:30
Shraiysh Vaishay 5ee500acbb [mlir][OpenMP] Remove clauses that are not being handled
This patch removes the following clauses from OpenMP Dialect:

 - private
 - firstprivate
 - lastprivate
 - shared
 - default
 - copyin
 - copyprivate

The privatization clauses are being handled in the flang frontend. The
data copying clauses are not being handled anywhere for now. Once
we have a better picture of how to handle these clauses in OpenMP
Dialect, we can add these. For the time being, removing unneeded
clauses.

For detailed discussion about this refer to [[ https://discourse.llvm.org/t/rfc-privatisation-in-openmp-dialect/3526 | Privatisation in OpenMP dialect ]]

Reviewed By: kiranchandramohan, clementval

Differential Revision: https://reviews.llvm.org/D120029
2022-02-19 01:13:05 +05:30
Groverkss eae62b2266 [mlir][Presburger] Introduce Domain and Range identifiers in PresburgerSpace
This patch introducing seperating dimensions into two types: Domain and Range.
This allows building relations over PresburgerSpace.

This patch is part of a series of patches to introduce relations in Presburger
library.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D119709
2022-02-19 00:30:58 +05:30
William S. Moses 670aeece51 [MLIR][OpenMP][SCF] Mark parallel regions as allocation scopes
MLIR has the notion of allocation scopes which specify that stack allocations (e.g. memref.alloca, llvm.alloca) should be freed or equivalently aren't available at the end of the corresponding region.
Currently neither OpenMP parallel nor SCF parallel regions have the notion of such a scope.

This clearly makes sense for an OpenMP parallel as this is implemented in with a new function which outlines the region, and clearly any allocations in that newly outlined function have a lifetime that ends at the return of the function, by definition.

While SCF.parallel doesn't have a guaranteed runtime which it is implemented with, this similarly makes sense for SCF.parallel since otherwise an allocation within an SCF.parallel will needlessly continue to allocate stack memory that isn't cleaned up until the function (or other allocation scope op) which contains the SCF.parallel returns. This means that it is impossible to represent thread or iteration-local memory without causing a stack blow-up. In the case that this stack-blow-up behavior is intended, this can be equivalently represented with an allocation outside of the SCF.parallel with a size equal to the number of iterations.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D119743
2022-02-18 11:06:32 -05:00
Benjamin Kramer 3ce2ee28f0 [mlir][ODS] Infer return types if the operands are variadic but the results are not
Clean up code that worked around this limitation.

Differential Revision: https://reviews.llvm.org/D120119
2022-02-18 15:29:06 +01:00
Benjamin Kramer d558540fae [mlir][Vector] Add return type inference for multi_reduction
This subsumes the builder and verifier.
2022-02-18 13:00:42 +01:00
Tres Popp b4e0507ce0 Rename PatternRewriteSet::insert to add
insert is soft deprecated, so remove all references so it's less likely
to be used and can be easily removed in the future.

Differential Revision: https://reviews.llvm.org/D120021
2022-02-18 12:18:41 +01:00
Benjamin Kramer b47be47ac2 [mlir][Vector] Switch ExtractOp to the declarative assembly format
This is a bit awkward since ExtractOp allows both `f32` and
`vector<1xf32>` results for a scalar extraction. Allow both, but make
inference return the scalar to make this as NFC as possible.
2022-02-18 11:45:59 +01:00
Matthias Springer 4086b3be44 [mlir][bufferize][NFC] Remove obsolete tensor bufferization patterns from Linalg/Bufferize.cpp
Differential Revision: https://reviews.llvm.org/D119824
2022-02-18 19:39:44 +09:00
Matthias Springer fa7c8cb4d0 [mlir][bufferize] Support memrefs with non-standard layout in `finalizing-bufferize`
Differential Revision: https://reviews.llvm.org/D119935
2022-02-18 19:34:04 +09:00
Stephan Herhut a43f7d6d76 [mlir][tensor] Extend reshape utils.
This change changes the handling of trailing dimensions with unknown
extent. Users of the changessociationIndicesForReshape helper should
see benefits when transforming reshape like operations into
expand/collapse pairs if the higher-rank type has trailing unknown
dimensions.

The motivating example is a reshape from tensor<16x1x?xi32> to
tensor<16xi32> that can be modeled as collapsing the three dimensions.

Differential Revision: https://reviews.llvm.org/D119730
2022-02-18 09:57:39 +01:00
Tres Popp f5efe28070 [mlir] Propagate NaNs in PolynomialApproximation
Previously, NaNs would be dropped in favor of bounded values which was
strictly incorrect. Now the min/max operation propagate this
information. Not all uses of min/max need this, but the given change
will help protect future additions, and this prevents the need for an
additional cmpf and select operation to handle NaNs.

Differential Revision: https://reviews.llvm.org/D120020
2022-02-18 09:25:36 +01:00
Benjamin Kramer f0dd818be3 [mlir][Vector] Switch ShuffleOp to the declarative assembly format
This also requires implementing return type deduction.
2022-02-18 01:46:58 +01:00
Benjamin Kramer a83e08b450 [mlir][Vector] Add InferTypeOpInterface to vector dialect and remove the now redundant builders 2022-02-18 01:46:58 +01:00
Aart Bik 7d05d35b35 [mlir][sparse] remove unused test matrix file
Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D120069
2022-02-17 15:04:06 -08:00
Krzysztof Drewniak c5803ee4fa [MLIR][GPU] Remove call to cudaSetDevice(), which no longer exists
Differential Revision: https://reviews.llvm.org/D120085
2022-02-17 21:38:05 +00:00
Krzysztof Drewniak 84718d37db [MLIR][GPU] Add gpu.set_default_device op
This op is added to allow MLIR code running on multi-GPU systems to
select the GPU they want to execute operations on when no GPU is
otherwise specified.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D119883
2022-02-17 21:30:09 +00:00
Benjamin Kramer 3773d04a13 [mlir][memref] Switch ViewOp to the declarative assembly format 2022-02-17 21:34:15 +01:00
Mogball 0aa3072649 [mlir] NFC NamedAttrList append with StringAttr
NamedAttrList.append(StringAttr, StringAttr) fails to compile because it is
matched to the IteratorT append. Fixes the method to only match if the type is
an iterator.
2022-02-17 20:30:25 +00:00
Benjamin Kramer 1af15de6b7 [mlir] Switch {collapse,expand}_shape ops to the declarative assembly format
Same functionality, a lot less code.
2022-02-17 20:00:05 +01:00
Aart Bik 515c617003 [mlir][linalg][sparse] add linalg optimization passes "upstream"
It is time to compose Linalg related optimizations with SparseTensor
related optimizations. This is a careful first start by adding some
general Linalg optimizations "upstream" of the sparse compiler in the
full sparse compiler pipeline. Some minor changes were needed to make
those optimizations aware of sparsity.

Note that after this, we will add a sparse specific fusion rule,
just to demonstrate the power of the new composition.

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D119971
2022-02-17 08:55:50 -08:00
Lei Zhang c9b36807be [mlir][spirv] Add a pass to unify aliased resource variables
In SPIR-V, resources are represented as global variables that
are bound to certain descriptor. SPIR-V requires those global
variables to be declared as aliased if multiple ones are bound
to the same slot. Such aliased decorations can cause issues
for transcompilers like SPIRV-Cross when converting to source
shading languages like MSL.

So this commit adds a pass to perform analysis of aliased
resources and see if we can unify them into one.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D119872
2022-02-17 09:08:58 -05:00
Shao-Ce SUN 21ac474392 [NFC] Correct typo `interger` to `integer` 2022-02-17 21:17:47 +08:00
Benjamin Kramer d955ca4937 [BufferDeallocation] Don't assume successor operands are unique
This would create a double free when a memref is passed twice to the
same op. This wasn't a problem at the time the pass was written but is
common since the introduction of scf.while.

There's a latent non-determinism that's triggered by the test, but this
change is messy enough as-is so I'll leave that for later.

Differential Revision: https://reviews.llvm.org/D120044
2022-02-17 14:16:32 +01:00
Siddharth Bhat 24a37a396a [MLIR] add entry block to MLIR grammar.
The MLIR parser allows regions to have an unnamed entry block.
Make this explicit in the language grammar.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D119950
2022-02-17 15:40:43 +05:30
Alex Zinenko d4a53f3bfa [mlir] call target materialization more in dialect conversion
During dialect conversion, target materialization is triggered to create
cast-like operations when a type mismatch occurs between the value that
replaces a rewritten operation and the type that another operations expects as
operands processed by the type conversion. First, a dummy cast is inserted to
make sure the pattern application can proceed. The decision to trigger the
user-provided materialization hook is taken later based on the result of the
dummy cast having uses. However, it only has uses if other patterns constructed
new operations using the casted value as operand. If existing (legal)
operations use the replaced value, they may have not been updated to use the
casted value yet. The conversion infra would then delete the dummy cast first,
and then would replace the uses with now-invalid (null in the bast case) value.
When deciding whether to trigger cast materialization, check for liveness the
uses not only of the casted value, but also of all the values that it replaces.

This was discovered in the finalizing bufferize pass that cleans up
mutually-cancelling casts without touching other operations. It is not
impossible that there are other scenarios where the dialect converison infra
could produce invalid operand uses because of dummy casts erased too eagerly.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D119937
2022-02-17 10:13:23 +01:00
Lorenzo Chelini 25f1d50ca5 [MLIR][PDL] Fix typo (NFC) 2022-02-17 10:06:16 +01:00
Ivan Butygin d271fc04d5 [mlir][gpu] Split ops sinking from gpu-kernel-outlining pass into separate pass
Previously `gpu-kernel-outlining` pass was also doing index computation sinking into gpu.launch before actual outlining.
Split ops sinking from `gpu-kernel-outlining` pass into separate pass, so users can use theirs own sinking pass before outlining.
To achieve old behavior users will need to call both passes: `-gpu-launch-sink-index-computations -gpu-kernel-outlining`.

Differential Revision: https://reviews.llvm.org/D119932
2022-02-17 10:34:20 +03:00
Shraiysh Vaishay 5bec1ea7a7 [mlir] Added oilist primitive
This patch attempts to add the `oilist` primitive proposed in the [[ https://llvm.discourse.group/t/rfc-extending-declarative-assembly-format-to-support-order-independent-variadic-segments/4388 | RFC: Extending Declarative Assembly Format to support order-independent variadic segments ]].

This element supports optional order-independent variadic segments for operations. This will allow OpenACC and OpenMP Dialects to have similar and relaxed requirements while encouraging the use of Declarative Assembly Format and avoiding code duplication.

An oilist element parses grammar of the form:
```
clause-list := clause clause-list | empty
clause := `keyword` clause1 | `otherKeyword` clause2
clause1 := <assembly-format element>
clause2 := <assembly-format element>
```

AssemblyFormat specification:
```
let assemblyFormat = [{
  oilist( `keyword` clause1
        | `otherkeyword` clause2
        ...
        )
}];
```

Example:
```
oilist( `private` `(` $arg0 `:` type($arg0) `)`
      | `nowait`
      | `reduction` custom<ReductionClause>($arg1, type($arg1)))

oilist( `private` `=` $arg0 `:` type($arg0)
      | `reduction` `=` $arg1 `:` type($arg1)
      | `firstprivate` `=` $arg3 `:` type($arg2))
```

Reviewed By: Mogball, rriddle

Differential Revision: https://reviews.llvm.org/D115215
2022-02-17 11:10:24 +05:30
Eugene Zhulenev abe2dee5eb [mlir] NFC Async: always use 'b' for the current builder
Currently some of the nested IR building inconsistently uses `nb` and `b`, it's very easy to call wrong builder outside of the current scope, so for simplicity all builders are always called `b`, and in nested IR building regions they just shadow the "parent" builder.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D120003
2022-02-16 21:20:53 -08:00
Aart Bik 34381a76c1 [mlir][sparse] avoid some codeup in sparsification transformation
A very small refactoring, but a big impact on tests that expect an exact order.
This revision fixes the tests, but also makes them less brittle for similar
minor changes in the future!

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D119992
2022-02-16 17:39:04 -08:00
Jacques Pienaar 6e2cf33b24 [mlir][doc] Add passes docs to Passes.md 2022-02-16 15:42:20 -08:00
Eugene Zhulenev b171583ae7 [mlir] Async: create async.group inside the scf.if branch
Reviewed By: cota

Differential Revision: https://reviews.llvm.org/D119959
2022-02-16 14:47:04 -08:00
Lei Zhang e027c00821 [mlir][tensor] Add a pattern to split tensor.pad ops
This commit adds a pattern to wrap a tensor.pad op with
an scf.if op to separate the cases where we don't need padding
(all pad sizes are actually zeros) and where we indeed need
padding.

This pattern is meant to handle padding inside tiled loops.
Under such cases the padding sizes typically depend on the
loop induction variables. Splitting them would allow treating
perfect tiles and edge tiles separately.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D117018
2022-02-16 13:43:57 -05:00
Lei Zhang 0edb412773 [mlir][linalg] Add control to pad-slice swap pattern
The pad-slice swap pattern generates `scf.if` and `tensor.generate`
to guard against zero-sized slices if it cannot prove the slice is
always non-zero. This is safe but quite conservative. It can be
unnecessary for cases where we know by problem definition such cases
does not exist, even if with dynamic shaped ops or unknown tile/slice
sizes, e.g., convolution padding size = 1 with kernel dim size = 3.

So this commit introduces a control to the pattern to specify
whether to generate the if constructs to handle such cases better,
given that once the if constructs is materialized, it's very hard
to analyze and simplify.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D117017
2022-02-16 11:19:35 -05:00
Benjamin Kramer 27cd2a6284 [mlir][MemRef] Lower memref.copy with an offset to memcpy
memcpy can handle them as long as they're contiguous.

Differential Revision: https://reviews.llvm.org/D119938
2022-02-16 17:18:31 +01:00
Shao-Ce SUN 2aed07e96c [NFC][MC] remove unused argument `MCRegisterInfo` in `MCCodeEmitter`
Reviewed By: skan

Differential Revision: https://reviews.llvm.org/D119846
2022-02-16 13:10:09 +08:00
Shao-Ce SUN 9cc49c1951 Revert "[NFC][MC] remove unused argument `MCRegisterInfo` in `MCCodeEmitter`"
This reverts commit fe25c06cc5.
2022-02-16 11:57:49 +08:00
Shao-Ce SUN fe25c06cc5 [NFC][MC] remove unused argument `MCRegisterInfo` in `MCCodeEmitter`
For ten years, it seems that `MCRegisterInfo` is not used by any target.

Reviewed By: skan

Differential Revision: https://reviews.llvm.org/D119846
2022-02-16 11:47:17 +08:00
Mahesh Ravishankar 2c58cde003 [mlir][Linalg] Add pattern for folding reshape by collapsing.
Fusion of `linalg.generic` with
`tensor.expand_shape/tensor.collapse_shape` currently handles fusion
with reshape by expanding the dimensionality of the `linalg.generic`
operation. This helps fuse elementwise operations better since they
are fused at the highest dimensionality while keeping all indexing
maps involved projected permutations. The intent of these is to push
the reshape to the boundaries of functions.

The presence of named ops (or other ops across which the reshape
cannot be propagated) stops the propagation to the edges of the
function. At this stage, the converse patterns that fold the reshapes
with generic ops by collapsing the dimensions of the generic op can
push the reshape towards edges. In particular it helps the case where
reshapes exist in between named ops and generic ops.

`linalg.named_op` -> `tensor.expand_shape` -> `linalg.generic`

Pushing the reshape down will help fusion of `linalg.named_op` ->
`linalg.generic` using tile + fuse transformations.

This pattern is intended to replace the following patterns

1) FoldReshapeByLinearization : These patterns create indexing maps
that are not projected permutations that affect future
transformations. They are only useful for folding unit-dimensions.
2) PushReshapeByExpansion : This pattern has the same functionality
but has some restrictions
    a) It tries to avoid creating new reshapes that limits its
    applicability. The pattern added here can achieve the same
    functionality through use of the `controlFn` that allows clients
    of the pattern freedom to make this decision.
    b) It does not work for ops with indexing semantics.

These patterns will be deprecated in a future patch.

Differential Revision: https://reviews.llvm.org/D119365
2022-02-16 03:15:20 +00:00
Sergei Grechanik 988a3ba0d8 [mlir] Expose printer flags in AsmState
This change exposes printer flags in AsmState and AsmStateImpl. All functions
receiving AsmState as a parameter now use the flags from the AsmState instead of
taking an additional OpPrintingFlags parameter.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D119870
2022-02-15 17:27:45 -08:00
Bixia Zheng 746c68eafd [mlir][sparse][taco] Handle tensor copy and trivial reduction expression.
Handle tensor copy, such as A[i, j] = B[i, j]. Also, handle trivial
reduction expression, such as A[i] = B[i, j].

Add unit tests.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D119867
2022-02-15 15:57:18 -08:00
Thomas Raoux 0736bbd7e2 [mlir][scf] Add callback to annotate ops during pipelining
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-15 12:48:01 -08:00
Jacques Pienaar b077ee9240 [mlir][ods] Allow type attribute/operand for 0 result ops prefixed
Without results, there is no getType injected and so generating one in prefixed form doesn't result in any failures during C++ compilation.

Differential Revision: https://reviews.llvm.org/D119871
2022-02-15 12:20:07 -08:00
Aart Bik ae76fafc3f [mlir][sparse] sparse transpose operation
This test shows that when access patterns do not match (e.g. transposing
a row-wise sparse matrix into another row-wise sparse matrix), a conversion
operation in between can enable codegen (i.e. avoid cycle in iteration graph).

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D119864
2022-02-15 11:51:30 -08:00
Mogball 26a61db93f [mlir][ods] NFC fix compilation error on clang-8 2022-02-15 19:41:16 +00:00
Mogball 761bc83af4 [mlir][ods] Default-valued parameters in attribute or type defs
Optional parameters with `defaultValue` set will be populated with that value if they aren't encountered during parsing. Moreover, parameters equal to their default values are elided when printing.

Depends on D118210

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D118544
2022-02-15 19:02:11 +00:00
Krzysztof Drewniak 5f6ce97408 [MLIR] Add support for alloca() of non-zero address spaces
This change is needed when lowering alloca()-using code on targets
such as ROCDL that represent private scratch space as a separate
address space.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D119775
2022-02-15 18:41:30 +00:00
Jacques Pienaar 75044e9b4f [mlir] Flipping vector dialect to both prefixed form.
Following
https://discourse.llvm.org/t/psa-ods-generated-accessors-will-change-to-have-a-get-prefix-update-you-apis/4476

Mostly mechanical, avoiding function name conflicts.

Differential Revision: https://reviews.llvm.org/D119607
2022-02-15 09:48:51 -08:00
Javier Setoain 71705f531f [mlir][Arith] Disallow casting between scalable and fixed-length vectors
Casting between scalable vectors and fixed-length vectors doesn't make
sense. If one of the operands is scalable, the other has to be scalable
to be able to guarantee they have the same shape at runtime.

Differential Revision: https://reviews.llvm.org/D119568
2022-02-15 17:34:42 +00:00
Krzysztof Drewniak 1aa71944cf [MLIR][GPU] Add missing include to SerilazeToHsaco
Differential Revision: https://reviews.llvm.org/D119852
2022-02-15 17:11:33 +00:00
Krzysztof Drewniak cc15141794 [MLIR] Link SerializeToHsaco dependencies to correct MLIR library
Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D119774
2022-02-15 16:31:10 +00:00
Adrian Kuegel b122cbebec [mlir][Math] Fix NaN handling in Exp approximation
Differential Revision: https://reviews.llvm.org/D119832
2022-02-15 15:17:56 +01:00
Benjamin Kramer 97db9d32f5 [mlir][gpu] Make header parse standalone. NFC. 2022-02-15 15:09:39 +01:00
Ivan Butygin a2e2fbba17 [mlir][gpu] sinkOperationsIntoLaunchOp: Add user hook for isSinkingBeneficiary
Differential Revision: https://reviews.llvm.org/D119632
2022-02-15 16:50:49 +03:00
Adrian Kuegel 14843d0c3d [mlir][OpenMP] NFC: Remove unused variable 2022-02-15 14:01:12 +01:00
Shraiysh Vaishay 166713f987 [mlir][OpenMP] Change omp.atomic.update to have generic updates
This patch changes the syntax of omp.atomic.update to allow the other
dialects to modify the variable with appropriate operations in the
region.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D119522
2022-02-15 17:58:13 +05:30
Matthias Springer 73e880fbf1 [mlir][bufferize] Add vector-bufferize pass and remove obsolete patterns from Linalg Bufferize
Differential Revision: https://reviews.llvm.org/D119444
2022-02-15 21:25:14 +09:00
Adrian Kuegel 87de451bc5 [mlir][Math] Fix NaN handling in ExpM1 approximation.
Differential Revision: https://reviews.llvm.org/D119822
2022-02-15 12:10:12 +01:00
Matthias Springer e6f691615e [mlir][bufferize] Support tensor.expand_shape and tensor.collapse_shape
Differential Revision: https://reviews.llvm.org/D112512
2022-02-15 19:53:49 +09:00
Akshay Baviskar f1efac7f08 Add verifier for gpu.alloc op
Add verifier for gpu.alloc op to verify if the dimension operand counts
and symbol operand counts are same as their memref counterparts.

Differential Revision: https://reviews.llvm.org/D117427
2022-02-15 15:57:58 +05:30
Matthias Springer 695c341b84 [mlir][bufferize] Generalize filtering mechanism in BufferizationOptions
Support ALLOW filters and DENY filters. This is needed for compatibility with existing code that specifies more complex op filters.

Differential Revision: https://reviews.llvm.org/D119820
2022-02-15 19:17:33 +09:00
Ivan Butygin 32389d0c2e [mlir][spirv] Add OpenCL fma op and lowering
Also, it seems Khronos has changed html spec format so small adjustment to script was needed.
Base op parsing is also probably broken.

Differential Revision: https://reviews.llvm.org/D119678
2022-02-15 11:28:20 +03:00
Bixia Zheng ad932a75f9 [mlir][sparse][taco] Support true dense tensors and all dense sparse tensors.
The only method to create a true dense tensor (i.e un-annotated) in MLIR-PyTACO
is through the from_array method. However, the annotated all dense tensors are
also implemented as true dense tensor currently. The PR fixes the
implementation to support annotated all dense sparse tensors.

Extend the tensor init method to support the construction of a tensor without
any sparsity annotation.

Change the tensor to_file method to only support writing unpacked sparse
tensors to file through the MLIR sparse tensor dialect.

Add unit tests for true dense tensors and all dense sparse tensors.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D119500
2022-02-14 15:35:01 -08:00
Shraiysh Vaishay b85cfe208f [OpenMP][IRBuilder] Change the default constructor for OpenMPIRBuilder::LocationDescription
This patch changes the argument from template-IRBuilder to IRBuilderBase
thus allowing us to write less code while getting the location from a
builder.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D119717
2022-02-15 00:40:34 +05:30
Stella Laurenzo 429b0cf1de [mlir][python] Directly implement sequence protocol on Sliceable.
* While annoying, this is the only way to get C++ exception handling out of the happy path for normal iteration.
* Implements sq_length and sq_item for the sequence protocol (used for iteration, including list() construction).
* Implements mp_subscript for general use (i.e. foo[1] and foo[1:1]).
* For constructing a `list(op.results)`, this reduces the time from ~4-5us to ~1.5us on my machine (give or take measurement overhead) and eliminates C++ exceptions, which is a worthy goal in itself.
  * Compared to a baseline of similar construction of a three-integer list, which takes 450ns (might just be measuring function call overhead).
  * See issue discussed on the pybind side: https://github.com/pybind/pybind11/issues/2842

Differential Revision: https://reviews.llvm.org/D119691
2022-02-14 09:45:17 -08:00
Aart Bik 5517208d4e [mlir][sparse] minor cleanup of include placement
Rationale:
empty line between main include for this file
moved include that actually defines code into right section

Note that this revision started as breaking up ops/attrs even more
(for bug https://github.com/llvm/llvm-project/issues/52748), but due
the the connection in Dialect.initalize(), this cannot be split further).
All heavy lifting refactoring was already done by River in previous cleanup.

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D119617
2022-02-14 09:16:45 -08:00
Marius Brehler 88b9d1a49a [mlir][emitc] Add a pointer type
Adds a pointer type to EmitC. The emission of pointers is so far only
possible by using the `emitc.opaque` type

Co-authored-by: Simon Camphausen <simon.camphausen@iml.fraunhofer.de>

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D119337
2022-02-14 16:42:21 +00:00
gysit 348bfc8e50 [mlir][linalg] Add attributes to region builder (NFC).
Adapt the region builder signature to hand in the attributes of the created ops. The revision is a preparation step the support named ops that need access to the operation attributes during op creation.

Depends On D119692

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D119693
2022-02-14 13:14:14 +00:00
gysit 4121090893 [mlir][OpDSL] Restructure comprehension.py (NFC).
Group and reorder the classed defined by comprehension.py and add type annotations.

Depends On D119126

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D119692
2022-02-14 12:56:01 +00:00
gysit d50571ab07 [mlir][OpDSL] Add default value to index attributes.
Index attributes had no default value, which means the attribute values had to be set on the operation. This revision adds a default parameter to `IndexAttrDef`. After the change, every index attribute has to define a default value. For example, we may define the following strides attribute:
```

```
When using the operation the default stride is used if the strides attribute is not set. The mechanism is implemented using `DefaultValuedAttr`.

Additionally, the revision uses the naming index attribute instead of attribute more consistently, which is a preparation for follow up revisions that will introduce function attributes.

Depends On D119125

Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D119126
2022-02-14 12:14:12 +00:00
gysit 01e04867e8 [mlir][OpDSL] Consistently use the term op_def (NFC).
... and remove unused type aliases.

Depends On D119003

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D119125
2022-02-14 11:19:53 +00:00
Ivan Butygin 5217801dae [mlir][arith] Do not limit arith-expand pass to FuncOp
This pass doesn't have any limitations specific to FuncOp and it will be useful to be able to run it on other ops (e.g. gpu.func).

Differential Revision: https://reviews.llvm.org/D119662
2022-02-14 11:49:19 +03:00
Ivan Butygin cd0d095c07 [mlir][tensor] Check ops generated by InsertSliceOpCastFolder are valid
Fixes https://github.com/llvm/llvm-project/issues/53099

Differential Revision: https://reviews.llvm.org/D119663
2022-02-13 21:37:31 +03:00
Benjamin Kramer c45c53bbae [Shape] Simplify getShapeVec a bit. NFCI. 2022-02-13 16:58:16 +01:00
Benjamin Kramer 935a5f67d1 [AffineMap] Move result exprs into trailing storage. NFCI. 2022-02-12 15:24:00 +01:00
Benjamin Kramer a9dcbcfe9f Use AffineMap::getSliceMap where applicable. NFCI. 2022-02-12 14:22:05 +01:00
Matthias Springer 9106d35b91 [mlir][bufferize] Use rewriter instead of replacing all uses directly
This is important for compatibility with DialectConversion.
2022-02-12 02:35:36 +09:00
Sameer Sahasrabuddhe d8f99bb6e0 [AMDGPU] replace hostcall module flag with function attribute
The module flag to indicate use of hostcall is insufficient to catch
all cases where hostcall might be in use by a kernel. This is now
replaced by a function attribute that gets propagated to top-level
kernel functions via their respective call-graph.

If the attribute "amdgpu-no-hostcall-ptr" is absent on a kernel, the
default behaviour is to emit kernel metadata indicating that the
kernel uses the hostcall buffer pointer passed as an implicit
argument.

The attribute may be placed explicitly by the user, or inferred by the
AMDGPU attributor by examining the call-graph. The attribute is
inferred only if the function is not being sanitized, and the
implictarg_ptr does not result in a load of any byte in the hostcall
pointer argument.

Reviewed By: jdoerfert, arsenm, kpyzhov

Differential Revision: https://reviews.llvm.org/D119216
2022-02-11 22:51:56 +05:30
Adrian Kuegel 2219f9f57c [mlir][MemRef] Fix MemRefCopyOpLowering to use correct number of bytes
When lowering to memrefCopy call, the size for i1 type was calculated as 0.
Instead of using getTypeSizeInBits() and dividing by 8, we should just use getTypeSize().

Differential Revision: https://reviews.llvm.org/D119540
2022-02-11 13:59:08 +01:00
Adrian Kuegel 5b02a48085 [mlir][MemRef] Fix MemRefCastOpLowering for 32 bit index type.
The lowering creates llvm.insertvalue with the rank value, so it needs to use
index type instead of 64 bit integer type. Otherwise, we get an error:

llvm.insertvalue' op Type mismatch: cannot insert 'i64' into '!llvm.struct<(i32, ptr<i8>)>'

Differential Revision: https://reviews.llvm.org/D119534
2022-02-11 12:37:15 +01:00
Arjun P 855cd847f7 [MLIR][Presburger] normalizeDivisionByGCD: fix bug when constant term is negative
Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D119531
2022-02-11 17:02:52 +05:30
Markus Böck 1bf7921374 [mlir][LLVM] Add support for adding a garbage collector to a LLVM function
This patch simply adds an optional garbage collector attribute to LLVMFuncOp which maps 1:1 to the "gc" property of functions in LLVM.

Differential Revision: https://reviews.llvm.org/D119492
2022-02-11 10:23:51 +01:00
Mehdi Amini b055e6d313 Add a new interface method `getAsmBlockName()` on OpAsmOpInterface to control block names
This allows operations to control the block ids used by the printer in nested regions.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D115849
2022-02-11 08:46:08 +00:00
gysit a3655de2c8 [mlir][OpDSL] Add support for basic rank polymorphism.
Previously, OpDSL did not support rank polymorphism, which required a separate implementation of linalg.fill. This revision extends OpDSL to support rank polymorphism for a limited class of operations that access only scalars and tensors of rank zero. At operation instantiation time, it scales these scalar computations to multi-dimensional pointwise computations by replacing the empty indexing maps with identity index maps. The revision does not change the DSL itself, instead it adapts the Python emitter and the YAML generator to generate different indexing maps and and iterators depending on the rank of the first output.

Additionally, the revision introduces a `linalg.fill_tensor` operation that in a future revision shall replace the current handwritten `linalg.fill` operation. `linalg.fill_tensor` is thus only temporarily available and will be renamed to `linalg.fill`.

Reviewed By: nicolasvasilache, stellaraccident

Differential Revision: https://reviews.llvm.org/D119003
2022-02-11 08:27:49 +00:00
Mehdi Amini 4e58cb18d3 Remove spurious includes and dependencies from Bazel files (NFC)
Differential Revision: https://reviews.llvm.org/D119526
2022-02-11 07:57:17 +00:00
Uday Bondhugula f2ff8a8e83 [MLIR] Add result status for normalizeAffineFor
Add result status for normalizeAffineFor utility.

Differential Revision: https://reviews.llvm.org/D119413
2022-02-11 11:29:52 +05:30
Thomas Raoux 5ab04bc068 [mlir][gpu] Add device side async copy operations
Add new operations to the gpu dialect to represent device side
asynchronous copies. This also add the lowering of those operations to
nvvm dialect.
Those ops are meant to be low level and map directly to llvm dialects
like nvvm or rocdl.

We can further add higher level of abstraction by building on top of
those operations.
This has been discuss here:
https://discourse.llvm.org/t/modeling-gpu-async-copy-ampere-feature/4924

Differential Revision: https://reviews.llvm.org/D119191
2022-02-10 17:25:59 -08:00
River Riddle ceb5dc55c2 [PDLL] Attempt to fix the gcc5 build by adding this-> to auto lambda 2022-02-10 16:59:03 -08:00
Aart Bik 719b865be2 [mlir][sparse][pytaco] add SDDMM test with two different ways of defining kernel
Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D119465
2022-02-10 13:33:06 -08:00
River Riddle faf42264e5 [PDLL] Add support for user defined constraint and rewrite functions
These functions allow for defining pattern fragments usable within the `match` and `rewrite` sections of a pattern. The main structure of Constraints and Rewrites functions are the same, and are similar to functions in other languages; they contain a signature (i.e. name, argument list, result list) and a body:

```pdll
// Constraint that takes a value as an input, and produces a value:
Constraint Cst(arg: Value) -> Value { ... }

// Constraint that returns multiple values:
Constraint Cst() -> (result1: Value, result2: ValueRange);
```

When returning multiple results, each result can be optionally be named (the result of a Constraint/Rewrite in the case of multiple results is a tuple).

These body of a Constraint/Rewrite functions can be specified in several ways:

* Externally
In this case we are importing an external function (registered by the user outside of PDLL):

```pdll
Constraint Foo(op: Op);
Rewrite Bar();
```

* In PDLL (using PDLL constructs)
In this case, the body is defined using PDLL constructs:

```pdll
Rewrite BuildFooOp() {
  // The result type of the Rewrite is inferred from the return.
  return op<my_dialect.foo>;
}
// Constraints/Rewrites can also implement a lambda/expression
// body for simple one line bodies.
Rewrite BuildFooOp() => op<my_dialect.foo>;
```

* In PDLL (using a native/C++ code block)
In this case the body is specified using a C++(or potentially other language at some point) code block. When building PDLL in AOT mode this will generate a native constraint/rewrite and register it with the PDL bytecode.

```pdll
Rewrite BuildFooOp() -> Op<my_dialect.foo> [{
  return rewriter.create<my_dialect::FooOp>(...);
}];
```

Differential Revision: https://reviews.llvm.org/D115836
2022-02-10 12:48:59 -08:00
River Riddle 3d8b906012 [PDLL] Add support for single line lambda-like patterns
This allows for defining simple patterns in a single line. The lambda
body of a Pattern expects a single operation rewrite statement:

```
Pattern => replace op<my_dialect.foo>(operands: ValueRange) with operands;
```

Differential Revision: https://reviews.llvm.org/D115835
2022-02-10 12:48:58 -08:00
Krzysztof Drewniak 1ce314ce6b [MLIR][GPU][lld] Use LLD bundled in ROCm, removing workaround
Having clarified that executing the SerializeToHsaco pass can
depend on a ROCm installation, switch from calling lld as a library to
using the copy of lld guaranteed to be included in a ROCm install.

This removes the workaround introduced in D119277

Reviewed By: whchung

Differential Revision: https://reviews.llvm.org/D119463
2022-02-10 19:37:30 +00:00
Krzysztof Drewniak c37b3e4108 [MLIR][GPU] Add now-required include to SerializeToHsaco
Reviewed By: whchung

Differential Revision: https://reviews.llvm.org/D119455
2022-02-10 18:36:38 +00:00
Nirvedh ad9b5a4b8e [mlir][vector] Add pattern to drop lead unit dim for Contraction Op
If the result operand has a unit leading dim it is removed from all operands.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D119206
2022-02-10 09:51:07 -08:00
Aart Bik 8189a2b8bd [mlir][sparse][pytaco] migrate to sparse compiler pipeline
Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D119395
2022-02-10 07:42:54 -08:00
Marius Brehler 44c1582265 [mlir] Add missing dep to new cf dialect 2022-02-10 14:15:20 +00:00
Lei Zhang 06a0385142 [mlir][linalg] Fold tensor.pad(linalg.fill) with the same value
Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D119160
2022-02-10 08:39:35 -05:00
Matthias Springer 9b5a3d14b2 [mlir][vector] Add helper that builds a scalar reduction according to CombiningKind
Differential Revision: https://reviews.llvm.org/D119433
2022-02-10 22:35:43 +09:00
Groverkss 4807587cf2 [MLIR][Presburger] Factor out space information to PresburgerSpace
This patch factors out space information from IntegerPolyhedron, PresburgerSet
and PWMAFunction to PresburgerSpace and its extension with local variables,
PresburgerLocalSpace.

Generally any new data structure additions in Presburger library will require
space information. This patch removes the need to duplicate the space
information.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D119280
2022-02-10 18:24:40 +05:30
Matthias Springer fe0bf7d469 [mlir][vector][NFC] Use CombiningKindAttr instead of StringAttr
This makes the op consistent with other ops in vector dialect.

Differential Revision: https://reviews.llvm.org/D119343
2022-02-10 19:13:29 +09:00
Tres Popp 34ff99a0b7 Revert "[MLIR] Fix fold-memref-subview-ops for affine.load/store"
This reverts commit ac6cb41303.

This code has a stack-use-after-scope error that can be seen with asan.
2022-02-10 10:46:59 +01:00
Uday Bondhugula ac6cb41303 [MLIR] Fix fold-memref-subview-ops for affine.load/store
Fix fold-memref-subview-ops for affine.load/store. We need to expand out
the affine apply on its operands.

Differential Revision: https://reviews.llvm.org/D119402
2022-02-10 13:55:38 +05:30
Uday Bondhugula 8d12bf4ac1 [MLIR][NFC] Move expandAffineMap/Expr out to Affine utils
Move expandAffineMap and expandAffineApplyExpr out to AffineUtils. This
is a useful method. The child revision uses it. NFC.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D119401
2022-02-10 09:56:26 +05:30
Uday Bondhugula c2246eb893 [MLIR][NFC] Remove unused argument in affine scalrep helper util
NFC. Remove unused argument in affine scalrep helper utility.

Differential Revision: https://reviews.llvm.org/D119397
2022-02-10 08:25:55 +05:30
Aart Bik 6195a25487 [mlir][sparse][pytaco] test cleanup
removed obsoleted TODO
removed strange Fp precision for coordinates
lined up meta data testing code for readability

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D119377
2022-02-09 16:58:25 -08:00
Mathieu Fehr cf4f97c812 [mlir] Add classes to define new TypeIDs at runtime
TypeIDAllocator enables the allocation of new TypeIDs at runtime,
that are unique during the lifetime of the allocator.

NonMovableTypeIDOwner is a class used to define a new TypeID for each instance
of a class, using the instance address. This class cannot be copied or moved.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D104534
2022-02-09 23:24:49 +01:00
Rainer Orth 9159675535 [MLIR][Presburger] Disambiguate call to floor
While testing LLVM 14.0.0 rc1 on Solaris, compilation of `FAIL`ed with

  /var/llvm/llvm-14.0.0-rc1/rc1/llvm-project/mlir/lib/Analysis/Presburger/Utils.cpp: In lambda function:
  /var/llvm/llvm-14.0.0-rc1/rc1/llvm-project/mlir/lib/Analysis/Presburger/Utils.cpp:48:58: error: call of overloaded ‘floor(int64_t)’ is ambiguous
     48 |                  [gcd](int64_t &n) { return floor(n / gcd); });
        |                                                          ^
  ...
  /usr/gcc/10/lib/gcc/sparcv9-sun-solaris2.11/10.3.0/include-fixed/iso/math_iso.h:201:21:
note: candidate: ‘long double std::floor(long double)’
    201 |  inline long double floor(long double __X) { return __floorl(__X); }
        |                     ^~~~~
  /usr/gcc/10/lib/gcc/sparcv9-sun-solaris2.11/10.3.0/include-fixed/iso/math_iso.h:165:15:
note: candidate: ‘float std::floor(float)’
    165 |  inline float floor(float __X) { return __floorf(__X); }
        |               ^~~~~
  /usr/gcc/10/lib/gcc/sparcv9-sun-solaris2.11/10.3.0/include-fixed/iso/math_iso.h:78:15:
note: candidate: ‘double std::floor(double)’
     78 | extern double floor __P((double));
        |               ^~~~~

The same issue had already occured in the past, cf. D108750
<https://reviews.llvm.org/D108750>, and the solution is the same: cast the
`floor` arg to `double`.

Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11`.

Differential Revision: https://reviews.llvm.org/D119324
2022-02-09 22:01:55 +01:00
Rainer Orth d2215e79ac [mlir][sparse] Rename index_t to index_type again
While testing LLVM 14.0.0 rc1 on Solaris, I ran into a compile failure:

                   from /var/llvm/llvm-14.0.0-rc1/rc1/llvm-project/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp:22:
  /usr/include/sys/types.h:103:16: error: conflicting declaration ‘typedef short int index_t’
    103 | typedef short  index_t;
        |                ^~~~~~~
  In file included from
/var/llvm/llvm-14.0.0-rc1/rc1/llvm-project/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp:17:
  /var/llvm/llvm-14.0.0-rc1/rc1/llvm-project/mlir/include/mlir/ExecutionEngine/SparseTensorUtils.h:26:7:
note: previous declaration as ‘using index_t = uint64_t’
     26 | using index_t = uint64_t;
        |       ^~~~~~~

The same issue had already occured in the past and fixed in D72619
<https://reviews.llvm.org/D72619>.  More detailed explanation can also be
found there.

Tested on `amd64-pc-solaris2.11` and `sparcv9-solaris2.11`.

Differential Revision: https://reviews.llvm.org/D119323
2022-02-09 21:59:52 +01:00
Saurabh Jha 0ed0a8e2f0 [mlir] Use sparse-compiler pass in sparse benchmark
This patch uses sparse-compiler option in mlir sparse tensor benchmark

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D118579
2022-02-09 20:16:47 +00:00
Matthias Springer 69f7647158 [mlir][GPU] Add ShuffleOp builder for constant offset/width
Differential Revision: https://reviews.llvm.org/D119345
2022-02-10 02:55:44 +09:00
Alexander Belyaev c962038914 [mlir][nfc] Expose linalg tiling helpers.
Differential Revision: https://reviews.llvm.org/D119330
2022-02-09 15:26:06 +01:00
Matthias Springer 585a8a321c [mlir][bufferize] OpOperands can have multiple aliasing OpResults
This makes getAliasingOpResult symmetric to getAliasingOpOperand. The previous implementation was confusing for users and implemented in such a way only because there are currently no bufferizable ops that have multiple aliasing OpResults.

Differential Revision: https://reviews.llvm.org/D119259
2022-02-09 20:58:45 +09:00
Matthias Springer 22a1973dbe [mlir][linalg][bufferize] Print results of FuncOp read/write analysis
Print more information with test-analysis-only.

Differential Revision: https://reviews.llvm.org/D119118
2022-02-09 20:52:38 +09:00
Matthias Springer f30ec8f627 [mlir][linalg][bufferize][NFC] Allow passing custom BufferizationOptions to pass
Differential Revision: https://reviews.llvm.org/D118891
2022-02-09 19:15:31 +09:00
Matthias Springer cdb7675c26 [mlir][bufferize][NFC] Make PostAnalysisSteps a function
They used to be classes with a virtual `run` function. This was inconvenient because post analysis steps are stored in BufferizationOptions. Because of this design choice, BufferizationOptions were not copyable.

Differential Revision: https://reviews.llvm.org/D119258
2022-02-09 18:56:06 +09:00
Alexandre Ganea 1e661e583d [MLIR] Temporary workaround for calling the LLD ELF driver as-a-lib
This fixes the situation described in https://github.com/llvm/llvm-project/issues/53475 with a repro exposed by https://github.com/ROCmSoftwarePlatform/D108850-lld-bug-reproduction

This is purposely just a workaround to unblock users. This could be transplanted to the release/14.x branch if need be. A proper fix will later be provided in https://reviews.llvm.org/D119049.

Differential Revision: https://reviews.llvm.org/D119277
2022-02-08 19:12:15 -05:00
Mogball 740e832644 [mlir][ods] Attribute and type formats: support whitespaces
Supports whitespace elements: ` ` and `\\n` as well as the "empty" whitespace `` that removes an otherwise printed space.

Depends on D118208

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D118210
2022-02-08 23:27:36 +00:00
Jacques Pienaar bbddd19ec7 [mlir][math] Expand coverage of atan2 expansion
Reuse the higher precision F32 approximation for the F16 one (by expanding and
truncating). This is partly RFC as I'm not sure what the expectations are here
(e.g., these are only for F32 and should not be expanded, that reusing
higher-precision ones for lower precision is undesirable due to increased
compute cost and only approximations per exact type is preferred, or this is
appropriate [at least as fallback] but we need to see how to make it more
generic across all the patterns here).

Differential Revision: https://reviews.llvm.org/D118968
2022-02-08 15:00:39 -08:00
Mogball 72619d101f [mlir][ods] NFC fix tblgen crash with empty assembly format 2022-02-08 21:13:58 +00:00
Mogball 07486395d2 [mlir][ods] Optional Attribute or Type Parameters
Implements optional attribute or type parameters, including support for such parameters in the assembly format `struct` directive. Also implements optional groups.

Depends on D117971

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D118208
2022-02-08 20:09:44 +00:00
harsh 4a876b13fb Add case to handle 0-D vectors in FlattenContiguousRowMajorTransferWritePattern and FlattenContiguousRowMajorTransferReadPattern.
For 0-D as well as 1-D vectors, both these patterns should
return a failure as there is no need to collapse the shape
of the source. Currently, only 1-D vectors were handled. This
patch handles the 0-D case as well.

Reviewed By: Benoit, ThomasRaoux

Differential Revision: https://reviews.llvm.org/D119202
2022-02-08 20:00:12 +00:00
Mahesh Ravishankar 2abd7f13bc [mlir][Linalg] NFC: Combine elementwise fusion test passes.
There are a few different test passes that check elementwise fusion in
Linalg. Consolidate them to a single pass controlled by different pass
options (in keeping with how `TestLinalgTransforms` exists).
2022-02-08 18:08:37 +00:00
Benjamin Kramer 78eeda7529 [MLIR][Presburger] Fix linkage of functions in header
Static functions in a header cause spurious unused function warnings.
2022-02-08 17:51:34 +01:00
Bixia Zheng 61a3dd70ff [mlir][taco] Use sparse_tensor.out to write sparse tensors to files.
Add a Python method, output_sparse_tensor, to use sparse_tensor.out to write
a sparse tensor value to a file.

Modify the method that evaluates a tensor expression to return a pointer of the
MLIR sparse tensor for the result to delay the extraction of the coordinates and
non-zero values.

Implement the Tensor to_file method to evaluate the tensor assignment and write
the result to a file.

Add unit tests. Modify test golden files to reflect the change that TNS outputs
now have a comment line and two meta data lines.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D118956
2022-02-08 08:47:05 -08:00
Krzysztof Drewniak 24a1869d00 [MLIR][GPU] Update GPUToROCDL to account for ControlFlow dialect
The conversion to the new ControlFlow dialect didn't change the
GPUToROCDL pass - this commit fixes this issue.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D119188
2022-02-08 16:34:34 +00:00
Arjun P 1096fcff7d [MLIR][Presburger] Support computing volumes via hyperrectangular overapproximation
Add support for computing an overapproximation of the number of integer points
in a polyhedron. The returned result is actually the number of integer points
one gets by computing the "rational shadow" obtained by projecting out the
local IDs, finding the minimal axis-parallel hyperrectangular approximation
of the shadow, and returning the number of integer points in that. This does
not currently support symbols.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D119228
2022-02-08 21:06:49 +05:30
Arjun P 738c738b44 [MLIR][Presburger] Simplex::computeIntegerBounds: support unbounded directions by returning Optionals 2022-02-08 20:57:18 +05:30
Arjun P 6472546fb7 [MLIR][Presburger] factor out duplicated function `parsePoly` into a Utils.h
Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D119194
2022-02-09 00:35:43 +05:30
Tres Popp 64b918852c Remove restriction on static dimensions in Shape method
mlir::shape::ToExtentTensorOp::areCastCompatible didn't allow the input
to have a static dimension, but that is allowed.
2022-02-08 11:20:01 +01:00
Cullen Rhodes 99d95025e1 [mlir][Affine][Vector] NFC: fix examples in comments
s/-affine-vectorize/-affine-super-vectorize/g

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D118892
2022-02-08 10:03:32 +00:00
Alex Zinenko 68784267b1 [mlir] Move constBuidlerCall from to ArrayAttrBase
This makes it applicable to both ArrayAttr and its typed subclasses instead of
only the latter. There is no good reason why ArrayAttr shouldn't be
const-buildable while its typed subclasses are, this was likely just an
omission.

Depends On D119113

Reviewed By: rriddle, nicolasvasilache

Differential Revision: https://reviews.llvm.org/D119114
2022-02-08 09:31:11 +01:00
Alex Zinenko 3df6cadec4 [mlir] ODS: require DefaultValuedAttr to be const-buildable
ODS provides a mechanism for defalut-valued attributes based on a wrapper
TableGen class that is recognized by mlir-tblgen. Such attributes, if not set
on the operaiton, can be construted on-the-fly in their getter given a constant
value. In order for this construction to work, the attribute specificaiton in
ODS must set the constBuilderCall field correctly. This has not been verified,
which could lead to invalid C++ code being generated by mlir-tblgen.

Closes #53588.

Reviewed By: rriddle, mehdi_amini

Differential Revision: https://reviews.llvm.org/D119113
2022-02-08 09:31:09 +01:00
River Riddle 7889ff7f00 [mlir] Finish removing FunctionPass
FunctionPass has been deprecated in favor of OperationPass<FuncOp>
for a few weeks, and this commit finished the deprecation with deletion.
The only difference between the two is that FunctionPass filters out function
declarations. When updating references to FunctionPass, ensure that
the pass either can handle declarations or explicitly add in filtering.

See https://llvm.discourse.group/t/functionpass-deprecated-in-favor-of-operationpass-funcop

Differential Revision: https://reviews.llvm.org/D118735
2022-02-07 19:04:52 -08:00
River Riddle 2418cd92c0 [mlir] Update uses of `parser`/`printer` ODS op field to `hasCustomAssemblyFormat`
The parser/printer fields are deprecated and in the process of being removed.
2022-02-07 19:03:58 -08:00
River Riddle 12bfd159b7 [mlir] Update Toy operations to use the `hasCustomAssemblyFormat` field
The parser/printer fields are deprecated and in the process of being removed.
2022-02-07 19:03:58 -08:00
River Riddle 60cac0c081 [mlir][NFC] Remove deprecated/old build/fold/parser utilities from OpDefinition
These have generally been replaced by better ODS functionality, and do not
need to be explicitly provided anymore.

Differential Revision: https://reviews.llvm.org/D119065
2022-02-07 19:03:58 -08:00
River Riddle 3c69bc4d6e [mlir][NFC] Remove a few op builders that simply swap parameter order
Differential Revision: https://reviews.llvm.org/D119093
2022-02-07 19:03:57 -08:00
River Riddle d7f0083dca [mlir:ODS] Deprecate Op parser/printer fields in favor of a new hasCustomAssemblyFormat field
Currently if an operation wants a C++ implemented parser/printer, it specifies inline
code blocks. This is quite problematic for various reasons, e.g. it requires defining
C++ inside of Tablegen which is discouraged when possible, but mainly because
nearly all usages simply forward to static functions (e.g. `static void parseSomeOp(...)`)
with users devising their own standards for how these are defined.

This commit adds support for a `hasCustomAssemblyFormat` bit field that specifies if
a C++ parser/printer is needed, and when set to 1 declares the parse/print methods for
operations to override. For migration purposes, the existing behavior is untouched. Upstream
usages will be replaced in a followup to keep this patch focused on the new implementation.

Differential Revision: https://reviews.llvm.org/D119054
2022-02-07 19:03:57 -08:00
Mahesh Ravishankar 7568f7101f Revert "[mlir][Linalg] NFC: Combine elementwise fusion test passes."
This reverts commit d730336411.
2022-02-07 22:51:29 +00:00
Mahesh Ravishankar d730336411 [mlir][Linalg] NFC: Combine elementwise fusion test passes.
There are a few different test passes that check elementwise fusion in
Linalg. Consolidate them to a single pass controlled by different pass
options (in keeping with how `TestLinalgTransforms` exists).
2022-02-07 22:46:57 +00:00
Sergei Grechanik bb39ad43ce [mlir][spirv] Fix verification of nested array constants
Fix the verification function of spirv::ConstantOp to allow nesting
array attributes.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D118939
2022-02-07 13:48:53 -08:00
Arjun P d5a2944219 [MLIR][Presburger] Add support for piece-wise multi-affine functions
Add the class MultiAffineFunction which represents functions whose domain is an
IntegerPolyhedron and which produce an output given by a tuple of affine
expressions in the IntegerPolyhedron's ids.

Also add support for piece-wise MultiAffineFunctions, which are defined on a
union of IntegerPolyhedrons, and may have different output affine expressions
on each IntegerPolyhedron. Thus the function is affine on each individual
IntegerPolyhedron piece in the domain.

This is part of a series of patches leading up to parametric integer programming.

Depends on D118778.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D118779
2022-02-08 00:43:59 +05:30
Matthias Springer 9aa74347d5 [mlir][SCF] Further simplify affine maps during `for-loop-canonicalization`
* Implement `FlatAffineConstraints::getConstantBound(EQ)`.
* Inject a simpler constraint for loops that have at most 1 iteration.
* Taking into account constant EQ bounds of FlatAffineConstraint dims/symbols during canonicalization of the resulting affine map in `canonicalizeMinMaxOp`.

Differential Revision: https://reviews.llvm.org/D119153
2022-02-08 02:40:08 +09:00
Nikita Popov c45a99f36b [MatrixBuilder] Require explicit element type in CreateColumnMajorLoad()
This makes the method compatible with opaque pointers.
2022-02-07 16:57:33 +01:00
Nikita Popov 4d30a245c9 [mlir] Remove MatrixBuilder template argument
I dropped this argument in cdc0573f75,
but did not adjust mlir. (Or rather I did, but I modified a generated
file ... oops)
2022-02-07 16:52:10 +01:00
Benjamin Kramer 6635c12ada [mlir] Use SmallBitVector instead of SmallDenseSet for AffineMap::compressSymbols
This is both more efficient and more ergonomic to use, as inverting a
bit vector is trivial while inverting a set is annoying.

Sadly this leaks into a bunch of APIs downstream, so adapt them as well.

This would be NFC, but there is an ordering dependency in MemRefOps's
computeMemRefRankReductionMask. This is now deterministic, previously it
was dependent on SmallDenseSet's unspecified iteration order.

Differential Revision: https://reviews.llvm.org/D119076
2022-02-07 00:21:44 +01:00
River Riddle 330838eb90 [mlir] Fix GpuToLLVM conversion pass after ControlFlow operations were split from Standard 2022-02-06 15:10:03 -08:00
Stella Laurenzo fe23a6fb75 [mlir] Fixup python bindings after splitting cf ops from std. 2022-02-06 14:51:17 -08:00
River Riddle ace01605e0 [mlir] Split out a new ControlFlow dialect from Standard
This dialect is intended to model lower level/branch based control-flow constructs. The initial set
of operations are: AssertOp, BranchOp, CondBranchOp, SwitchOp; all split out from the current
standard dialect.

See https://discourse.llvm.org/t/standard-dialect-the-final-chapter/6061

Differential Revision: https://reviews.llvm.org/D118966
2022-02-06 14:51:16 -08:00
Eugene Zhulenev edca177cbe [mlir] Add canonicalizer to remove redundant shape.cstr_broadcastable ops
Depends On D119025

Reviewed By: frgossen

Differential Revision: https://reviews.llvm.org/D119043
2022-02-06 14:46:42 -08:00
Mehdi Amini 0d8850ae2c Remove dead forward declaration (NFC) 2022-02-06 19:48:46 +00:00
Stella Laurenzo b4626f22de [mlir] Do not use an empty source file when building aggregate libraries.
See discussion: https://discourse.llvm.org/t/check-mlir-times-examples-standalone-testing-time/6073/7

It turns out that it has been legal since CMake 3.11 to omit sources at library creation time if they are added later via target_sources, as is done here. This side-steps the issue of having a file that changes and invalidates the build of leaves.

Differential Revision: https://reviews.llvm.org/D119069
2022-02-05 23:06:28 -08:00
Arjun P 8a98c3e07f [MLIR][Presburger] MaybeLocalRepr: add explicit bool() for convenience
This also slightly simplifies some code.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D118790
2022-02-05 19:33:01 +05:30
Groverkss 2845ed29d4 [MLIR][Presburger][NFC] Use getters for IntegerPolyhedron members
This patch makes IntegerPolyhedron and derived classes use of getters to access
IntegerPolyhedron space information (`numIds, numDims, numSymbols`) instead of
directly accessing them.

This patch makes it easier to change the underlying implementation of the way
identifiers are stored, making it easier to extend/modify existing implementation.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D118888
2022-02-05 18:08:15 +05:30
Groverkss 070bc9c1fb [MLIR][Presburger][NFC] Fix clang-tidy warnings
This patch changes variable naming to lowerCamelCase to remove
clang-tidy warning in Presburger/Utils.cpp.
2022-02-05 11:59:21 +05:30
Markus Böck 296e03fc64 [mlir][NFC] Fully qualify call to `mlir::success` in auto generated C++ 2022-02-05 00:40:04 +01:00
Eugene Zhulenev 981f0a14f1 [mlir] Add canonicalizer to merge shape.assuming_all ops
Depends On D119021

Reviewed By: frgossen

Differential Revision: https://reviews.llvm.org/D119025
2022-02-04 15:27:37 -08:00
River Riddle c64655c78c [mlir:NFC] Move BaseOpWithOffsetSizesAndStrides out of OpBase.td
This is not a general construct, and shouldn't have been defined in OpBase.
This moves a copy to both MemRefOps+TensorOps, which are the only
users.
2022-02-04 14:31:59 -08:00
Lei Zhang 9dd4c2dcb6 [mlir][vector] Add constant folder for vector.shuffle ops
Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D119032
2022-02-04 16:59:32 -05:00
Lei Zhang 36e68c11ad [mlir][spirv] Add support for converting vector.shuffle
Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D119030
2022-02-04 16:31:11 -05:00
wren romano 4998b1a6cd [mlir][sparse] Updating sparse-compiler pipeline for python usage
Explicitly nests passes for FuncOp, adds more options to the sparse-compiler pipeline, and updates python integration tests.  This should be sufficient to close https://github.com/llvm/llvm-project/issues/51751

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D118658
2022-02-04 11:39:48 -08:00
Eugene Zhulenev 2cff9ee46b [mlir] Use SetVector to deduplicate shape ops operands
Do not use quadratic complexity algorithm to find unique operands

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D119021
2022-02-04 11:34:13 -08:00
gysit b5ea288d13 [mlir][linalg] Let tile and fuse fail for tile sizes zero.
Adapt `tileConsumerAndFuseProducers` to return failure if the generated tile loop nest is empty since all tile sizes are zero. Additionally, fix `LinalgTileAndFuseTensorOpsPattern` to return success if the pattern applied successfully.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D118878
2022-02-04 19:19:21 +00:00
Prashant Kumar 37bad565bf Revert "[MLIR][Presburger] Use `SmallVector` instead of `std::vector` in `getLocalRepr`"
This reverts commit 3cc5447728.
SmallVector inside SmallVector are not optimized.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D119005
2022-02-04 23:24:08 +05:30
serge-sans-paille ffe8720aa0 Reduce dependencies on llvm/BinaryFormat/Dwarf.h
This header is very large (3M Lines once expended) and was included in location
where dwarf-specific information were not needed.

More specifically, this commit suppresses the dependencies on
llvm/BinaryFormat/Dwarf.h in two headers: llvm/IR/IRBuilder.h and
llvm/IR/DebugInfoMetadata.h. As these headers (esp. the former) are widely used,
this has a decent impact on number of preprocessed lines generated during
compilation of LLVM, as showcased below.

This is achieved by moving some definitions back to the .cpp file, no
performance impact implied[0].

As a consequence of that patch, downstream user may need to manually some extra
files:

llvm/IR/IRBuilder.h no longer includes llvm/BinaryFormat/Dwarf.h
llvm/IR/DebugInfoMetadata.h no longer includes llvm/BinaryFormat/Dwarf.h

In some situations, codes maybe relying on the fact that
llvm/BinaryFormat/Dwarf.h was including llvm/ADT/Triple.h, this hidden
dependency now needs to be explicit.

$ clang++ -E  -Iinclude -I../llvm/include ../llvm/lib/Transforms/Scalar/*.cpp -std=c++14 -fno-rtti -fno-exceptions | wc -l
after:   10978519
before:  11245451

Related Discourse thread: https://llvm.discourse.group/t/include-what-you-use-include-cleanup
[0] https://llvm-compile-time-tracker.com/compare.php?from=fa7145dfbf94cb93b1c3e610582c495cb806569b&to=995d3e326ee1d9489145e20762c65465a9caeab4&stat=instructions

Differential Revision: https://reviews.llvm.org/D118781
2022-02-04 11:44:03 +01:00
Jacques Pienaar 88c525235b [mlir] Add pass to privatize symbols unless excluded.
Simple pass that changes all symbols to private unless symbol is excluded (and
in which case there is no change to symbol's visibility).

Differential Revision: https://reviews.llvm.org/D118752
2022-02-03 20:20:54 -08:00
Eugene Zhulenev 0557c6a797 [mlir] Keep sorted vector of registered operation names for efficient lookup
I see a lot of array sorting in stack traces of our compiler, canonicalizer traverses this list every time it builds a pattern set, and it gets expensive very quickly.

Reviewed By: rriddle, mehdi_amini

Differential Revision: https://reviews.llvm.org/D118937
2022-02-03 14:19:34 -08:00
Thomas Raoux c3c1c5c695 [mlir][scf] Fix bug in pipelining prologue emission
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-02-03 13:12:50 -08:00
River Riddle 139751e514 [mlir:Vector][NFC] Remove unnecessary dependency on Affine 2022-02-03 11:55:14 -08:00
River Riddle 14124c3025 [mlir][NFC] Split MlirQuant into proper IR/Utils/Transforms libraries
This matches the structure of other dialects, and also removes
unnecessary dependencies from the core dialect lib.
2022-02-03 10:54:52 -08:00
Mahesh Ravishankar 32288d3722 [mli][Linalg] NFC: Refactor methods in `ElementwiseOpFusion`.
Reorder the methods and patterns to move related patterns/methods
closer (textually).

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D118870
2022-02-03 18:53:13 +00:00
Chris Lattner 968280bc40 [mlir-translate] Teach these tools about --allow-unregistered-dialect
Some translations do work with unregistered dialects, this allows one
to write testcases against them.  It works the same way as it does for
mlir-opt.

Differential Revision: https://reviews.llvm.org/D118872
2022-02-03 09:00:38 -08:00
Bixia Zheng 93c81f44cc [mlir][taco] Uses sparse_tensor.new to read tensor input data from files.
Replace the Python implementation for reading tensor input data from files with
create_sparse_tensor that uses sparse_tensor.new.

The MLIR TNS format has two extra meta data lines. Add the extra meta data to a
test data file.

Implement TACO tensor methods evaluate and unpack.

Add unit tests.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D118803
2022-02-03 08:26:33 -08:00
Abhishek Varma 59b23c4aec [MLIR][SCF] Remove loop invariant arguments of scf.while
-- This commit adds a canonicalization pattern on scf.while to remove
   the loop invariant arguments.
-- An argument is considered loop invariant if the iteration argument value is
   the same as the corresponding one being yielded (at the same position) in both
   the before/after block of scf.while.
-- For the arguments removed, their use within scf.while and their corresponding
   scf.while's result are replaced with their corresponding initial value.

Signed-off-by: Abhishek Varma <abhishek.varma@polymagelabs.com>

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D116923
2022-02-03 17:13:25 +01:00
Markus Böck 7b196f1b09 [mlir][Rewrite] Add support for using an operation with no results as location
Prior to this patch, using an operation without any results as the location would result in the generation of invalid C++ code. It'd try to format using the result values, which would would end up being an empty string for an operation without any.
This patch fixes that issue by instead using getValueAndRangeUse which handles both ranges as well as the case for an op without any results.

Differential Revision: https://reviews.llvm.org/D118885
2022-02-03 15:08:09 +01:00
Benjamin Kramer 309b48ca5e [mlir][vector] Sink StandardOps include to its user in VectorUtils 2022-02-03 12:34:41 +01:00
Markus Böck 8652fc8453 [mlir][NFC] Fully qualify a default C++ string in Pattern.cpp 2022-02-03 11:50:37 +01:00
Markus Böck 7a9e3ef77a [mlir] Fix crash in RewriterGen when a `TypeConstraint` is not given an argument
The code assumes that a TypeConstraint in the additional constraints list specifies precisely one argument.
If the user were to not specify any, it'd result in a crash. If given more than one, the additional ones were ignored.

This patch fixes the crash and disallows user errors by adding a check that a single argument is supplied to the TypeConstraint

Differential Revision: https://reviews.llvm.org/D118763
2022-02-03 09:08:27 +01:00
River Riddle cf70f7ce8b [mlir] Remove dangling reference to std-bufferize which got removed 2022-02-02 15:04:40 -08:00
River Riddle 8e123ca65f [mlir:Standard] Remove support for creating a `unit` ConstantOp
This is completely unused upstream, and does not really have well defined semantics
on what this is supposed to do/how this fits into the ecosystem. Given that, as part of
splitting up the standard dialect it's best to just remove this behavior, instead of try
to awkwardly fit it somewhere upstream. Downstream users are encouraged to
define their own operations that clearly can define the semantics of this.

This also uncovered several lingering uses of ConstantOp that weren't
updated to use arith::ConstantOp, and worked during conversions because
the constant was removed/converted into something else before
verification.

See https://llvm.discourse.group/t/standard-dialect-the-final-chapter/ for more discussion.

Differential Revision: https://reviews.llvm.org/D118654
2022-02-02 14:45:12 -08:00
River Riddle ead1107257 [mlir] Move StandardOps/Utils to Arithmetic and sever a bunch of dependencies on Standard
The Utils.cpp file in StandardOps essentially just contains utilities for interacting with arithmetic
operations, and at this point makes more sense as a utility file for the arithemtic dialect.

Differential Revision: https://reviews.llvm.org/D118280
2022-02-02 14:45:12 -08:00
River Riddle dec8af701f [mlir] Move SelectOp from Standard to Arithmetic
This is part of splitting up the standard dialect. See https://llvm.discourse.group/t/standard-dialect-the-final-chapter/ for discussion.

Differential Revision: https://reviews.llvm.org/D118648
2022-02-02 14:45:12 -08:00
River Riddle 6a8ba3186e [mlir] Split std.splat into tensor.splat and vector.splat
This is part of the larger effort to split the standard dialect. This will also allow for pruning some
additional dependencies on Standard (done in a followup).

Differential Revision: https://reviews.llvm.org/D118202
2022-02-02 14:45:12 -08:00
River Riddle 1be88f5ab1 [mlir][NFC] Update remaining dialect operations to use `hasVerifier` instead of `verifier`
The verifier field is deprecated, and slated for removal.

Differential Revision: https://reviews.llvm.org/D118829
2022-02-02 13:34:31 -08:00
River Riddle 0d86e53e18 [mlir][NFC] Update PDL operations to use `hasVerifier` instead of `verifier`
The verifier field is deprecated, and slated for removal.

Differential Revision: https://reviews.llvm.org/D118828
2022-02-02 13:34:31 -08:00
River Riddle 094ede6d20 [mlir][NFC] Update GPU/SCF operations to use `hasVerifier` instead of `verifier`
The verifier field is deprecated, and slated for removal.

Differential Revision: https://reviews.llvm.org/D118827
2022-02-02 13:34:31 -08:00
River Riddle 4809da8eaf [mlir][NFC] Update Affine operations to use `hasVerifier` instead of `verifier`
The verifier field is deprecated, and slated for removal.

Differential Revision: https://reviews.llvm.org/D118826
2022-02-02 13:34:30 -08:00
River Riddle ef72cf4413 [mlir][NFC] Update OpenACC/OpenMP operations to use `hasVerifier` instead of `verifier`
The verifier field is deprecated, and slated for removal.

Differential Revision: https://reviews.llvm.org/D118825
2022-02-02 13:34:30 -08:00
River Riddle b98dc0351a [mlir][NFC] Update MemRef/Tensor operations to use `hasVerifier` instead of `verifier`
The verifier field is deprecated, and slated for removal.

Differential Revision: https://reviews.llvm.org/D118821
2022-02-02 13:34:30 -08:00
River Riddle bdc7ce975a [mlir][NFC] Update Vector operations to use `hasVerifier` instead of `verifier`
The verifier field is deprecated, and slated for removal.

Differential Revision: https://reviews.llvm.org/D118820
2022-02-02 13:34:30 -08:00
River Riddle 38abdddf6f [mlir][NFC] Update AMX/LLVM/NVVM/X86 vector operations to use `hasVerifier` instead of `verifier`
The verifier field is deprecated, and slated for removal.

Differential Revision: https://reviews.llvm.org/D118819
2022-02-02 13:34:29 -08:00
River Riddle f7d85f010f [mlir][NFC] Update SPIRV operations to use `hasVerifier` instead of `verifier`
The verifier field is deprecated, and slated for removal.

Differential Revision: https://reviews.llvm.org/D118817
2022-02-02 13:34:29 -08:00
River Riddle 4e190c58de [mlir][NFC] Update Toy operations to use `hasVerifier` instead of `verifier`
The verifier field is deprecated, and slated for removal.

Differential Revision: https://reviews.llvm.org/D118816
2022-02-02 13:34:28 -08:00
River Riddle 42e5f1d97b [mlir] Refactor how additional verification is specified in ODS
Currently if an operation requires additional verification, it specifies an inline
code block (`let verifier = "blah"`). This is quite problematic for various reasons, e.g.
it requires defining C++ inside of Tablegen which is discouraged when possible, but mainly because
nearly all usages simply forward to a static function `static LogicalResult verify(SomeOp op)`.
This commit adds support for a `hasVerifier` bit field that specifies if an additional verifier
is needed, and when set to `1` declares a `LogicalResult verify()` method for operations to
override. For migration purposes, the existing behavior is untouched. Upstream usages will
be replaced in a followup to keep this patch focused on the hasVerifier implementation.

One main user facing change is that what was one `MyOp::verify` is now `MyOp::verifyInvariants`.
This better matches the name this method is called everywhere else, and also frees up `verify` for
the user defined additional verification. The `verify` function when generated now (for additional
verification) is private to the operation class, which should also help avoid accidental usages after
this switch.

Differential Revision: https://reviews.llvm.org/D118742
2022-02-02 13:34:28 -08:00
Chia-hung Duan 91e8a63c20 [mlir] Support verification order (1/3)
This CL supports adding dependency between traits verifiers and the
dependency will be checked statically.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D115135
2022-02-02 18:25:44 +00:00
Arjun P 79728453b7 [MLIR][Presburger] Simplify checkExplicitRepresentation
This also gets rid of a clang-tidy warning.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D118780
2022-02-02 20:20:16 +05:30
Prashant Kumar 3cc5447728 [MLIR][Presburger] Use `SmallVector` instead of `std::vector` in `getLocalRepr`
Use `SmallVector` instead of `std::vector` in `getLocalRepr` function.
 Also, fix the casing of a variable.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D118722
2022-02-02 19:57:15 +05:30
Arjun P 29d1651d7b [MLIR][Presburger] maybeLocalRepr: rename inEqualityPair -> inequalityPair 2022-02-02 18:59:50 +05:30
Arjun P ec10ff37e2 [MLIR][Presburger] Support isSubsetOf in PresburgerSet and IntegerPolyhedron
Also support isEqual in IntegerPolyhedron.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D118778
2022-02-02 18:44:14 +05:30
Arjun P 55459f67b4 [MLIR] PresburgerSet::isIntegerEmpty: address clang-tidy warning 2022-02-02 18:05:14 +05:30
Arjun P 81d3144ebf [MLIR][AffineAnalysis] Fix typo in comment (NFC) 2022-02-02 17:50:06 +05:30
Arjun P 255494144f [MLIR] Matrix: support matrix-vector multiplication
This just moves in the implementation from LinearTransform.

Reviewed By: Groverkss, bondhugula

Differential Revision: https://reviews.llvm.org/D118479
2022-02-02 17:41:14 +05:30
Nicolas Vasilache 3c3810e72e [mlir][vector] Avoid hoisting alloca'ed temporary buffers across AutomaticAllocationScope
This revision avoids incorrect hoisting of alloca'd buffers across an AutomaticAllocationScope boundary.
In the more general case, we will probably need a ParallelScope-like interface.

Differential Revision: https://reviews.llvm.org/D118768
2022-02-02 06:00:42 -05:00
Markus Böck 513ba61ca1 [mlir] Fully qualify generated C++ code in RewriterGen.cpp
By fully qualifying the use of any types and functions from the mlir namespace, users are not required to add using namespace mlir; into the C++ file including the Tablegen output.

Differential Revision: https://reviews.llvm.org/D118767
2022-02-02 11:57:57 +01:00
Nicolas Vasilache aea4929dbb [mlir][async] Add AutomaticAllocationScope to async::ExecuteOp
Differential Revision: https://reviews.llvm.org/D118761
2022-02-02 05:15:23 -05:00
gysit dc82547b17 [mlir][vector] Make write permutation lowering work with tensors.
Use type inference when building the TransferWriteOp in the TransferWritePermutationLowering. Previously, the result type has been set to Type() which triggers an assertion if the pattern is used with tensors instead of memrefs.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D118758
2022-02-02 09:21:10 +00:00
Mogball 42f87a0354 [mlir][ods] NFC Fix ASAN error in FormatParser
Some FormatElement subclasses contain `std::vector`. Since these use
BumpPtrAllocator, they need to be converted to trailing objects.
However, this is not a trivial fix so I will leave it as a FIXME and use
a workaround.
2022-02-02 04:29:57 +00:00
Bixia Zheng ae7ee655a9 [mlir][taco] Add a utility to create an MLIR sparse tensor from a file.
Move the functions that retrieve the supporting C library, compile an MLIR
module and build a JIT execution engine to mlir_pytaco_utils.

Add a function to create an MLIR sparse tensor from a file and return a pointer
to the MLIR sparse tensor as well as the shape of the sparse tensor.

Add unit tests.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D118496
2022-02-01 15:43:53 -08:00
Daniel Resnick 97fc568211 [mlir][capi] Add DialectRegistry to MLIR C-API
Exposes mlir::DialectRegistry to the C API as MlirDialectRegistry along with
helper functions. A hook has been added to MlirDialectHandle that inserts
the dialect into a registry.

A future possible change is removing mlirDialectHandleRegisterDialect in
favor of using mlirDialectHandleInsertDialect, which it is now implemented with.

Differential Revision: https://reviews.llvm.org/D118293
2022-02-01 13:42:06 -07:00
Mahesh Ravishankar a2361eb281 Avoid doing tile + fuse if tile sizes are zero.
Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D118576
2022-02-01 18:34:06 +00:00
Alexander Belyaev ebc8153786 Revert "Revert "[mlir] Purge `linalg.copy` and use `memref.copy` instead.""
This reverts commit 25bf6a2a9b.
2022-02-01 18:21:21 +01:00
Alex Zinenko 22fea18e5f [mlir] Better error message in PybindAdaptors.h
When attempting to cast a pybind11 handle to an MLIR C API object through
capsules, the binding code would attempt to directly access the "_CAPIPtr"
attribute on the object, leading to a rather obscure AttributeError when the
attribute was missing, e.g., on non-MLIR types. Check for its presence and
throw a TypeError instead.

Depends On D117646

Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D117658
2022-02-01 17:49:18 +01:00
Nicolas Vasilache 31b7f8857f [mlir][vector][integration] Reactivate LLI in vector integration test.
The test introduced in https://reviews.llvm.org/D118006 was missing a return and would
introduce a non-0 return which would fail tests.
2022-02-01 08:00:50 -05:00
Nicolas Vasilache c2fa5ff5ad Temporarily disable LLI to investigate weird non 0 error code
Somehow the test introduced in https://reviews.llvm.org/D118006 produces the expected result but running
through lli with Intel SDE activated sneaks in an error code 2 (before this commit) or an error code 10
(after this commit).

The test as is is still meaningful in that the LLVMIR generation would crash if the `elementtype` is set
improperly.

Still, this should run with lli turned on.
2022-02-01 07:24:49 -05:00
Benjamin Kramer a0ea73394f [mlir] Attempt working around a GCC 5 bug
It doesn't like implicit `this` in generic lambdas.
2022-02-01 11:58:27 +01:00
Nicolas Vasilache 42398b5142 [mlir][LLVM] Add support for operand_attrs to InlineAsmOp
This revision adds enough support to allow InlineAsmOp to work properly with indirect memory constraints "*m".
These require an explicit "elementtype" TypeAttr on the operands to pass LLVM verification and need to be provided.

Reviewed By: bkramer

Differential Revision: https://reviews.llvm.org/D118006
2022-02-01 05:56:14 -05:00
Prashant Kumar 1e7c464d2c [MLIR] Extract division representation from equality expressions.
Extract the division representation from equality constraints.
For example:
    32*k == 16*i + j - 31                 <-- k is the localVariable
    expr = 16*i + j - 31, divisor = 32
    k = (16*i + j - 32) floordiv 32
The dividend of the division is set to [16, 1, -32] and the divisor is set
to 32.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D117959
2022-02-01 16:24:28 +05:30
Christian Sigg 9b078f8fd2 [MLIR][arith] Mark addf/mulf as commutative
Following the discussion in D118318, mark `arith.addf/mulf` commutative.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D118600
2022-02-01 08:33:48 +01:00
Mogball 0bc0ad86e2 [mlir][ods] Unify Attr/TypeDef and Operation Format Parsing
Part 2 of 3 of unifying the assembly formats of attributes/types and operations.The last patch that introduced attribute/type formats (D111594) factored out the format lexer entirely. This patch factors out most of the format parsers such that the attribute/type and op parsers only need to implement handling for specific elements.

Certain things could be factored better (element verification, 'seen' variables) but the primary goal of factoring is so that features can be used across both assembly formats.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D117971
2022-02-01 07:28:37 +00:00
River Riddle 58e7bf78a3 [mlir] Add isa/dyn_cast support for dialect interfaces
This matches the same API usage as attributes/ops/types. For example:

```c++
Dialect *dialect = ...;

// Instead of this:
if (auto *interface = dialect->getRegisteredInterface<DialectInlinerInterface>())

// You can do this:
if (auto *interface = dyn_cast<DialectInlinerInterface>(dialect))
```

Differential Revision: https://reviews.llvm.org/D117859
2022-01-31 19:24:34 -08:00
River Riddle 6ec9fd20bd [mlir:Standard][NFC] Remove the dead Arithmetic op classes from Ops.td
These were dead after the arithmetic operations moved from Standard to the Arithmetic dialect.
2022-01-31 12:53:29 -08:00
Sanjoy Das 18e33ba9c9 Remove `mutable` and stray comment
The `mutable` was added back when `scope` was a `DataLayoutOpInterface`.

Differential Revision: https://reviews.llvm.org/D118643
2022-01-31 12:33:20 -08:00
bakhtiyar 149311b405 [async] Get the number of worker threads from the runtime.
Reviewed By: ezhulenev

Differential Revision: https://reviews.llvm.org/D117751
2022-01-31 12:06:01 -08:00
Sanjoy Das 697a5036cd Remove OpTrait, AttrTrait and TypeTrait
- Remove the `{Op,Attr,Type}Trait` TableGen classes and replace with `Trait`
  - Rename `OpTraitList` to `TraitList` and use it in a few places

The bulk of this change is a mechanical s/OpTrait/Trait/ throughout the codebase.

Reviewed By: rriddle, jpienaar, herhut

Differential Revision: https://reviews.llvm.org/D118543
2022-01-31 11:04:00 -08:00
Christian Sigg f278cf9cbc [MLIR][arith] More float op folders
Fold `arith.fadd %x, -0.0 -> %x` and similarly for `fsub`, `fmul`, `fdiv`.

Fold `arith.fmin %x, %x -> %x`, `arith.fmin %x, +inf -> %x` and similarly for `fmax`.

Reviewed By: pifon2a, mehdi_amini, bondhugula

Differential Revision: https://reviews.llvm.org/D118244
2022-01-31 19:31:48 +01:00
Alexander Belyaev 25bf6a2a9b Revert "[mlir] Purge `linalg.copy` and use `memref.copy` instead."
This reverts commit 016956b680.
Reverting it to fix NVidia build without being in a hurry.
2022-01-31 18:51:39 +01:00
Alexander Belyaev 016956b680 [mlir] Purge `linalg.copy` and use `memref.copy` instead.
Differential Revision: https://reviews.llvm.org/D118028
2022-01-31 18:25:56 +01:00
Matthias Springer 5523c1455a [mlir][bufferize][NFC] Move vector BufferizableOpInterface impl to vector dialect
Differential Revision: https://reviews.llvm.org/D118540
2022-02-01 00:28:28 +09:00
Matthias Springer 99ef9eebad [mlir][vector][NFC] Split into IR, Transforms and Utils
This reduces the dependencies of the MLIRVector target and makes the dialect consistent with other dialects.

Differential Revision: https://reviews.llvm.org/D118533
2022-01-31 19:17:09 +09:00
Mehdi Amini 081cff628a Add missing include to mlir/Target/LLVMIR/Import.h to be standalone (NFC) 2022-01-31 07:55:00 +00:00
Uday Bondhugula f8a2cd67b9 Support affine.load/store ops in fold-memref-subview-ops pass
Support affine.load/store ops in fold-memref-subview ops pass. The
existing pass just "inlines" the subview operation on load/stores by
inserting affine.apply ops in front of the memref load/store ops: this
is by design always consistent with the semantics on affine.load/store
ops and the same would work even more naturally/intuitively with the
latter.

Differential Revision: https://reviews.llvm.org/D118565
2022-01-31 10:10:49 +05:30
Uday Bondhugula 92ccb8cc50 [MLIR][NFC] Update SCF pass cmd line names to prefix scf
Update SCF pass cmd line names to prefix `scf`. This is consistent with
guidelines/convention on how to name dialect passes. This also avoids
ambiguity on the context given the multiple `for` operations in the
tree.

NFC.

Differential Revision: https://reviews.llvm.org/D118564
2022-01-31 07:09:30 +05:30
Alexandre Ganea dc3b9365b6 [mlir] Silence warnings when building with MSVC
Differential Revision: https://reviews.llvm.org/D118536
2022-01-30 17:31:35 -05:00
Sanjoy Das 8f66ab1c2e Replace OwningModuleRef with OwningOpRef<ModuleOp>
This addresses a TODO in BuiltinOps.h.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D118574
2022-01-30 14:07:10 -08:00
Matthias Springer dab72a35e9 [mlir][bufferize] Clean up remaining references to `tensor-constant-bufferize` 2022-01-31 05:02:11 +09:00
Mehdi Amini 446425f898 Apply clang-tidy fixes for llvm-include-order in AttrOrTypeFormatGen.cpp (NFC) 2022-01-30 19:49:23 +00:00
Mehdi Amini bb31503989 Apply clang-tidy fixes for performance-move-const-arg in TestLinalgCodegenStrategy.cpp (NFC) 2022-01-30 19:49:23 +00:00
Mehdi Amini d7ab71f7b9 Apply clang-tidy fixes for readability-identifier-naming in TosaOps.cpp (NFC) 2022-01-30 19:49:23 +00:00
Mehdi Amini 70ed93ec4c Apply clang-tidy fixes for readability-identifier-naming in PolynomialApproximation.cpp (NFC) 2022-01-30 19:49:22 +00:00
Mehdi Amini bb6119eb77 Apply clang-tidy fixes for performance-for-range-copy in SCFInterfaceImpl.cpp (NFC) 2022-01-30 19:49:22 +00:00
Mehdi Amini 3b3fbd56ec Apply clang-tidy fixes for modernize-use-equals-default in BufferizableOpInterface.cpp (NFC) 2022-01-30 19:49:22 +00:00
Mehdi Amini f65994c9f1 Apply clang-tidy fixes for readability-identifier-naming in AsyncToLLVM.cpp (NFC) 2022-01-30 19:49:22 +00:00
Matthias Springer 6700a26d5f [mlir][linalg][bufferize] Fix insertion point InitTensorElimination
There was a bug where some of the OpOperands needed in the replacement op were not in scope.

It does not matter where the replacement op is inserted. Any insertion point is OK as long as there are no dominance errors. In the worst case, the newly inserted op will bufferize out-of-place. This is no worse than not eliminating the InitTensorOp at all.

Differential Revision: https://reviews.llvm.org/D117685
2022-01-30 22:25:39 +09:00
Matthias Springer e448c793c6 [mlir][bufferize][NFC] Move std BufferizableOpInterfaceImpl to std dialect
Also reimplement `std-bufferize` in terms of BufferizableOpInterface-based bufferization. The old `std.select` bufferization pattern is no longer needed and deleted.

Differential Revision: https://reviews.llvm.org/D118559
2022-01-30 22:12:14 +09:00
Matthias Springer 19efe141f7 [mlir][bufferize][NFC] Move scf BufferizableOpInterface impl to scf dialect
Differential Revision: https://reviews.llvm.org/D118557
2022-01-30 21:53:33 +09:00
Matthias Springer ab47418df6 [mlir][bufferize] Merge tensor-constant-bufferize into arith-bufferize
The bufferization of arith.constant ops is also switched over to BufferizableOpInterface-based bufferization. The old implementation is deleted. Both implementations utilize GlobalCreator, now renamed to just `getGlobalFor`.

GlobalCreator no longer maintains a set of all created allocations to avoid duplicate allocations of the same constant. Instead, `getGlobalFor` scans the module to see if there is already a global allocation with the same constant value.

For compatibility reasons, it is still possible to create a pass that bufferizes only `arith.constant`. This pass (createConstantBufferizePass) could be deleted once all users were switched over to One-Shot bufferization.

Differential Revision: https://reviews.llvm.org/D118483
2022-01-30 21:37:48 +09:00
Sanjoy Das c080456d64 Delete dead code
Differential Revision: https://reviews.llvm.org/D118501
2022-01-28 20:01:35 -08:00
wren romano b85ed4e0e1 [mlir][sparse] Adding standard pipeline for tests.
Addresses https://bugs.llvm.org/show_bug.cgi?id=52409 aka https://github.com/llvm/llvm-project/issues/51751

Reviewed By: aartbik, mehdi_amini

Differential Revision: https://reviews.llvm.org/D117919
2022-01-28 15:11:12 -08:00
Krzysztof Drewniak e7d0dae76e [MLIR][GPU] Add missing #include to SerializeToHsaco.cpp
llvm/Support/Path.h was likely previously implicitly included, and a
refactoring removed that inclusion, breaking the pass.

Differential Revision: https://reviews.llvm.org/D118508
2022-01-28 22:56:38 +00:00
Krzysztof Drewniak c918c68f5c [MLIR] Factor out common parts of the TLike constraint
Type constraints such as BoolLike and SignlessIntegerLike appear to
have been defined by copy-paste and all share an underlying TypesLike
structure that can be factored out.

This also allows for defining additional constraints of a similar
form, such as F32Like.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D118382
2022-01-28 22:55:41 +00:00
Alexandre Ganea 1cf9876661 [mlir] Fix build after 83d59e05b2
Differential Revision: https://reviews.llvm.org/D118510
2022-01-28 17:21:30 -05:00
Aart Bik 0daa72a505 [mlir][sparse][pytaco] enable dimension ordering syntax
Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D118500
2022-01-28 13:33:04 -08:00
harsh 80e0bf1af1 Add vector.scan op
This patch adds the vector.scan op which computes the
scan for a given n-d vector. It requires specifying the operator,
the identity element and whether the scan is inclusive or
exclusive.

TEST: Added test in ops.mlir

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D117171
2022-01-28 20:07:57 +00:00
Bixia Zheng 91865cc027 [mlir][taco] Accept an integer list for the ordering when defining a tensor format.
The unit tests for PyTACO hasn't been upstreamed yet. A unit test for this
change will be added when we upstream all the unit tests for PyTACO.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D118417
2022-01-28 10:33:25 -08:00
Stella Stamenova c0861fcbb9 [mlir] Only build mlir-cpu-runner when the native arch is targeted
mlir-cpu-runner has a dependency on ExecutionEngine which is only built for the native arch. So currently mlir-cpu-runner does not link correctly when the native arch is not targeted.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D118422
2022-01-28 10:09:09 -08:00
Arjun P 6db019582a [MLIR] Introduce LexSimplex to support lexicographic optimization
This patch introduces a class LexSimplex that can currently be used to find the
lexicographically minimal rational point in an IntegerPolyhedron. This is a
series of patches leading to computing the lexicographically minimal integer
lattice point as well parametric lexicographic minimization.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D117437
2022-01-28 22:06:58 +05:30
Adrian Kuegel f40475c7fd [mlir] Move SCF utils implementations to SCF/Utils.
BEGIN_PUBLIC
[mlir] Move SCF utils implementations to SCF/Utils.
END_PUBLIC
2022-01-28 11:54:27 +01:00
Nikita Popov a4ad79c50a [MLIR] Remove some pointer element type accesses
Use the MLIR pointer element type, rather than the LLVM pointer
element type.
2022-01-28 09:50:52 +01:00
Nikita Popov f2c2a31dd7 [OpenMPIRBuilder] Store element type in AtomicOpValue
With opaque pointers, we can no longer derive this from the pointer
type, so we need to explicitly provide the element type the atomic
operation should work with.

Differential Revision: https://reviews.llvm.org/D118359
2022-01-28 09:35:11 +01:00
Adrian Kuegel c962b3fdf8 [mlir][Bazel][cmake] Add missing dependency.
After 2c7b0685e1 this dependency is needed.
2022-01-28 08:20:24 +01:00
Frederik Gossen 2c7b0685e1 Fix tensor.extract for complex elements 2022-01-28 04:33:15 +01:00
Aart Bik 35ece3beaa [mlir][sparse][pytaco] add PyTACO SpMM example
Also contains a few TODOs on future enhancements

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D118418
2022-01-27 17:26:22 -08:00
Mogball 1e3a02162d [mlir][scf] Update IfOp to have getInvocationBounds
This allows `scf.if` to be used by Control-Flow sink.

Depends on D115088

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D115089
2022-01-27 23:15:53 +00:00
Saurabh Jha fa90c9d5e7 [mlir] Set up boilerplate build for MLIR benchmarks
This is is the start of the MLIR benchmarks. It sets up a command
line tool along with conventions to define and run benchmarks
using mlir's python bindings.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D115174
2022-01-27 21:38:15 +00:00
Thomas Raoux a57ccad5a6 [VectorToGPU] Fix horizontal stride calculation for N-D memref
Fix a bug in how we calculate the stride of mma load/store ops for N-D
memrefs

Differential Revision: https://reviews.llvm.org/D118378
2022-01-27 13:35:56 -08:00
Stephen Neuendorffer 84fe34a0b7 [MLIR] Workaround for python detection problems.
Although cmake should be platform-independent, we've observed
that some aspects of Python detection don't work on all platforms,
even with recent versions of cmake.  This appears to be due to bugs
in the python detection logic, especially when the NumPy component
is required and not located within the python installation.
As a workaround, this patch first searches for "Development" before
searching for "Development.Module", which seems to workaround the
issue.

Differential Revision: https://reviews.llvm.org/D118148
2022-01-27 13:32:29 -08:00
natashaknk 024a1fab5c [tosa][mlir] Add dynamic shape support for remaining ops
Added support for concat, tile, pad, argmax and table ops

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D118397
2022-01-27 11:25:38 -08:00
Matthias Springer 075e3fdda1 [mlir][bufferize] Move arith BufferizableOpInterface impl to arith dialect
Also switch the implementation of `-arith-bufferize` to BufferizableOpInterface.

Differential Revision: https://reviews.llvm.org/D118325
2022-01-28 01:40:22 +09:00
Benjamin Kramer b70366c9c4 [mlir][BufferOptimization] Use datalayout instead of a flag to find index size
This has the additional advantage of supporting more types.

Differential Revision: https://reviews.llvm.org/D118348
2022-01-27 13:50:29 +01:00
Benjamin Kramer 608cc6b163 [mlir][complex] Lower complex.constant to LLVM
This fixes a regression from 480cd4cb85

Differential Revision: https://reviews.llvm.org/D118347
2022-01-27 13:48:23 +01:00
Matthias Springer b2f5004259 Revert "[mlir][bufferize] Insert memref.cast ops during finalizing pass"
This reverts commit 1043107ce5.

This commit caused a breakage in `finalizing-bufferize.mlir`.
2022-01-27 20:48:58 +09:00
Matthias Springer dbd1bbced9 [mlir][linalg][bufferize] Support arith.index_cast bufferization
This is in preparation of switching `-tensor-constant-bufferize` and `-arith-bufferize` to BufferizableOpInterface-based implementations.

Differential Revision: https://reviews.llvm.org/D118324
2022-01-27 19:50:31 +09:00
Matthias Springer daf18108ec [mlir][tensor] Replace tensor-bufferize with BufferizableOpInterface impl
This commit switches the `tensor-bufferize` pass over to BufferizableOpInterface-based bufferization.

Differential Revision: https://reviews.llvm.org/D118246
2022-01-27 19:30:45 +09:00
Matthias Springer 1043107ce5 [mlir][bufferize] Insert memref.cast ops during finalizing pass
The pass can currently not handle to_memref(to_tensor(x)) folding where a cast is necessary. This is required with the new unified bufferization. There is already a canonicalization pattern that handles such foldings and it should be used during this pass.

Differential Revision: https://reviews.llvm.org/D117988
2022-01-27 19:06:53 +09:00
Marius Brehler 578122c18a [mlir] Don't emit unused labels
Stop the Cpp target from emitting unused labels. The previosly generated
code generated warning if `-Wunused-label` is passed to a compiler.

Co-authored-by: Simon Camphausen <simon.camphausen@iml.fraunhofer.de>

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D118154
2022-01-27 07:56:03 +00:00
Uday Bondhugula fa5c5230d9 [MLIR] NFC. Rename pass cmd-line to prefix affine
Prefix "affine-" to affine transform passes that were missing it -- to
avoid ambiguity and for uniformity. There were only two needed this.

Move mispaced affine coalescing test case file.

NFC.

Differential Revision: https://reviews.llvm.org/D118314
2022-01-27 13:01:39 +05:30
Uday Bondhugula 970f94d051 [MLIR] Fix integration tests broken by D118285
[MLIR] Fix integration tests broken by D118285.
2022-01-27 13:00:30 +05:30
River Riddle 9f85c198db [mlir] Finish replacing OwningRewritePatternList with RewritePatternSet
OwningRewritePatternList has been deprecated for ~10 months now, we can remove
the leftover using directives at this point.

Differential Revision: https://reviews.llvm.org/D118287
2022-01-26 23:11:02 -08:00
River Riddle 7d0426dd95 [mlir] Move ComposeSubView+ExpandOps from Standard to MemRef
These transformations already operate on memref operations (as part of
splitting up the standard dialect). Now that the operations have moved,
it's time for these transformations to move as well.

Differential Revision: https://reviews.llvm.org/D118285
2022-01-26 23:11:02 -08:00
River Riddle 6842ec42f6 [mlir][NFC] Add a using for llvm::SMLoc/llvm::SMRange to LLVM.h
These are used pervasively during parsing.

Differential Revision: https://reviews.llvm.org/D118291
2022-01-26 21:37:23 -08:00
River Riddle d10d49dce4 [mlir][NFC] Add a using for llvm::BitVector to LLVM.h
BitVector is becoming widespread enough that we should add a proper using.

Differential Revision: https://reviews.llvm.org/D118290
2022-01-26 21:37:23 -08:00
River Riddle e3cd80ea9f [mlir:Function][NFC] Use BitVector instead of ArrayRef for indices when removing arguments/results
We already convert to BitVector internally, and other APIs (namely Operation::eraseOperands)
already use BitVector as well. Switching over provides a common format between
API and also reduces the amount of format conversions necessary.

Fixes #53325

Differential Revision: https://reviews.llvm.org/D118083
2022-01-26 21:37:22 -08:00
River Riddle f4a368689f [mlir:PassOptions] Fix parsing of nested option values/better handle escaping
The option parser currently does not properly handle nested options, meaning that
in some cases we can print pass pipelines that we can't actually parse back in. For example,
from #52885 we currently can't parse in inliner pipelines that have nested pipeline strings.

This commit adds handling for string values (e.g. "...") and nested options
(e.g. `foo{baz{bar=10 pizza=11}}`).

Fixes #52885

Differential Revision: https://reviews.llvm.org/D118078
2022-01-26 21:37:22 -08:00
Aart Bik 11fb049954 [mlir][amx] add a full tile matrix mult integral example to integration tests
Reviewed By: dcaballe

Differential Revision: https://reviews.llvm.org/D118292
2022-01-26 17:10:01 -08:00
Aart Bik 19f67ee29e [mlir][amx] fix some whitespace issues in AMX tests
Reviewed By: dcaballe

Differential Revision: https://reviews.llvm.org/D118289
2022-01-26 16:00:03 -08:00
Mehdi Amini 7ebd22c504 Revert "[mlir][LLVM] Add support for operand_attrs to InlineAsmOp"
This reverts commit e6ce2c0b8d.

The test is failing in CI right now.
2022-01-26 23:59:24 +00:00
Aart Bik a5257ae277 [mlir][amx] add a full tile matrix mult example to integration tests
Rationale:
Demonstrates the maximum tile size allowed for the f32 <= bf16 x bf16 op

Reviewed By: dcaballe

Differential Revision: https://reviews.llvm.org/D118277
2022-01-26 14:13:30 -08:00
Jeremy Furtek 33185e66f2 [mlir] Add ODS support for enum attributes with grouped bit cases
This diff modifies the tablegen specification and code generation for
BitEnumAttr attributes in MLIR Operation Definition Specification (ODS) files.
Specifically:

- there is a new tablegen class for "none" values (i.e. no bits set)
- single-bit enum cases are specified via bit index (i.e. [0, 31]) instead of
  the resulting enum integer value
- there is a new tablegen class to represent a "grouped" bitwise OR of other
  enum values

This diff is intended as an initial step towards improving "fastmath"
optimization support in MLIR, to allow more precise control of whether certain
floating point optimizations are applied in MLIR passes. "Fast" math options
for floating point MLIR operations would (following subsequent RFC and
discussion) be specified by using the improved enum bit support in this diff.
For example, a "fast" enum value would act as an alias for a group of other
cases (e.g. finite-math-only, no-signed-zeros, etc.), in a way that is similar
to support in C/C++ compilers (clang, gcc).

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D117029
2022-01-26 21:01:01 +00:00
River Riddle 632a4f8829 [mlir] Move std.generic_atomic_rmw to the memref dialect
This is part of splitting up the standard dialect. The move makes sense anyways,
given that the memref dialect already holds memref.atomic_rmw which is the non-region
sibling operation of std.generic_atomic_rmw (the relationship is even more clear given
they have nearly the same description % how they represent the inner computation).

Differential Revision: https://reviews.llvm.org/D118209
2022-01-26 11:52:01 -08:00
River Riddle 480cd4cb85 [mlir] Move the complex support of std.constant to a new complex.constant operation
This is part of splitting up the standard dialect.

Differential Revision: https://reviews.llvm.org/D118182
2022-01-26 11:52:00 -08:00
River Riddle b88a4d72d9 [mlir:GPU] Replace reference to LLVMFuncOp with FuncOpInterface
The GPU dialect currently contains an explicit reference to  LLVMFuncOp
during verification to handle the situation where the kernel has already been
converted. This commit changes that reference to instead use FunctionOpInterface,
which has two main benefits:

* It allows for removing an otherwise unnecessary dependency on the LLVM dialect
* It removes hardcoded assumptions about the lowering path and use of the GPU dialect

Differential Revision: https://reviews.llvm.org/D118172
2022-01-26 11:52:00 -08:00
Benjamin Kramer f15014ff54 Revert "Rename llvm::array_lengthof into llvm::size to match std::size from C++17"
This reverts commit ef82063207.

- It conflicts with the existing llvm::size in STLExtras, which will now
  never be called.
- Calling it without llvm:: breaks C++17 compat
2022-01-26 16:55:53 +01:00
serge-sans-paille ef82063207 Rename llvm::array_lengthof into llvm::size to match std::size from C++17
As a conquence move llvm::array_lengthof from STLExtras.h to
STLForwardCompat.h (which is included by STLExtras.h so no build
breakage expected).
2022-01-26 16:17:45 +01:00
Matthias Springer 268524238e [mlir][bufferization] Add an option to use memref types without layout maps
This is for compatibility with existing bufferization passes. Also clean up memref type generation a bit.

Differential Revision: https://reviews.llvm.org/D118243
2022-01-27 00:03:34 +09:00
Nicolas Vasilache e6ce2c0b8d [mlir][LLVM] Add support for operand_attrs to InlineAsmOp
This revision adds enough support to allow InlineAsmOp to work properly with indirect memory constraints "*m".
These require an explicit "elementtype" TypeAttr on the operands to pass LLVM verification and need to be provided.

Reviewed By: bkramer

Differential Revision: https://reviews.llvm.org/D118006
2022-01-26 07:42:35 -05:00
Nicolas Vasilache 9b6c2ea302 [mlir][Linalg] Add GenericOp self-copy on buffers folding
Reviewed By: pifon2a

Differential Revision: https://reviews.llvm.org/D118116
2022-01-26 05:56:31 -05:00
Alexander Batashev e9b4239fef [mlir][openmp] Custom syntax for `omp.target` operation
Add a custom parser and printer for `omp.target` operation.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D117539
2022-01-26 10:26:19 +00:00
Matthias Springer 18778b8863 [mlir] Fix merging of delayed registrations during DialectRegistry::appendTo
The existing implementation called DenseMap::insert, which is a no-op if the map already contains an entry with the same key.

Differential Revision: https://reviews.llvm.org/D118165
2022-01-26 17:28:42 +09:00
Rob Suderman 7c984be21a [mlir] Propagate arith.index_cast past tensor.extract
If we are extracting it is more useful to push the index_cast past the
extraction. This increases the chance the tensor.extract can evaluated at
compile time.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D118204
2022-01-25 22:16:07 -08:00
Rob Suderman d81a3c51e7 [mlir] Fold tensor.reshape operations into tensor.from_elements.
There is not much of a benefit to reshape a from element vs reloading it.
Updated to progagate shape manipulations into the output type of
tensor.from_elements.

Reviewed By: NatashaKnk

Differential Revision: https://reviews.llvm.org/D118201
2022-01-25 15:54:57 -08:00
MaheshRavishankar f3ab0ccd00 [mlir][Linalg] Add couple of convenience methods to `LinalgInterface`.
Add methods to
- Get block argument that is tied with an opOperand
- Get the yield value that is tied with a output opOperand.

Differential Revision: https://reviews.llvm.org/D118085
2022-01-25 11:46:11 -08:00
MaheshRavishankar ea1ac183f4 [mlir][Linalg] Fix incorrect fusion with reshape ops by linearization.
Fusion of reshape ops by linearization incorrectly inverted the
indexing map before linearizing dimensions. This leads to incorrect
indexing maps used in the fused operation.

Differential Revision: https://reviews.llvm.org/D117908
2022-01-25 11:42:58 -08:00
MaheshRavishankar e5a315f57a [mlir][Linalg] Disallow ops with index semantics in `PushExpandingReshape`.
This pattern is not written to handle operations with `linalg.index`
operations in its body, i.e. operations that have index semantics.

Differential Revision: https://reviews.llvm.org/D117856
2022-01-25 10:37:30 -08:00
Benjamin Kramer 2c8a77ab21 [mlir] Move duplicated BufferizableOpInterface::kBufferLayoutAttrName defs to a single place 2022-01-25 15:20:30 +01:00
Matthias Springer d581c94d6b [mlir][linalg][bufferize] Support tensor.from_elements
This is mostly a copy of the existing tensor.from_elements bufferization. Once TensorInterfaceImpl.cpp is moved to the tensor dialect, the existing rewrite pattern can be deleted.

Differential Revision: https://reviews.llvm.org/D117775
2022-01-25 22:19:59 +09:00
Matthias Springer 71bbb78b8f [mlir][linalg][bufferize] Support tensor.generate
This is mostly a copy of the existing tensor.generate bufferization. Once TensorInterfaceImpl.cpp is moved to the tensor dialect, the existing rewrite pattern can be deleted.

Differential Revision: https://reviews.llvm.org/D117770
2022-01-25 22:19:22 +09:00
Matthias Springer 694df0f0a8 [mlir][linalg][bufferize] Fix build
This fixes a linker error related to ModuleBufferization.cpp.

Differential Revision: https://reviews.llvm.org/D118127
2022-01-25 21:59:23 +09:00
Chuanqi Xu dbbe010908 [MLIR] [AsyncToLLVM] Use llvm.coro.align intrinsic
Use llvm.coro.align to align coroutine frame properly.

Reviewed By: bkramer

Differential Revision: https://reviews.llvm.org/D117978
2022-01-25 19:28:25 +08:00
Nikita Popov 22487280dc [NFC] Remove more uses of PointerType::getElementType() (NFC)
Replace more uses which I missed in the first pass with
Type::getPointerElementType().
2022-01-25 10:13:53 +01:00
Lorenzo Chelini bca2d85153 [MLIR][Interfaces] Silence -Wparentheses warning (NFC)
warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
2022-01-25 09:02:49 +01:00
River Riddle 881ff4e4eb [mlir] Remove unnecessary dependency on Tensor from MemRef 2022-01-24 22:59:01 -08:00
Shraiysh Vaishay 320dc8c4df [mlir][OpenMP] Added omp.atomic.capture operation
This patch supports the atomic construct (capture) following section 2.17.7 of OpenMP 5.0 standard. Also added tests for the same.

Reviewed By: peixin, kiranchandramohan

Differential Revision: https://reviews.llvm.org/D115851
2022-01-25 12:25:54 +05:30
River Riddle 633f5badbf [mlir] Add more missing dependencies after D118062
These used to be covered transitively, but now need to be explicit.
2022-01-24 22:12:03 -08:00
Uday Bondhugula 8676e10f74 [MLIR] Improve doc for -mlir-print-local-scope and unhide
This is a pretty important debugging option to stay hidden. Also,
improve its cmd-line description; the current description gives no hint
that this is the one to use to have locations printed inline.
Out-of-line locations are also unproductive to work with in many cases
where the locations are actually compact, which is also why this option
should be more visible.  This revision doesn't change the default on it
though.

Reviewed By: rriddle, jpienaar

Differential Revision: https://reviews.llvm.org/D117186
2022-01-25 11:13:48 +05:30
River Riddle e697b97148 [mlir] Add more missing dependencies after D118062
These used to be covered transitively, but now need to be explicit.
2022-01-24 21:36:31 -08:00
River Riddle b827b6340b [mlir] Add missing dependencies after D118062
These used to be covered transitively, but now need to be explicit.
2022-01-24 21:31:37 -08:00
River Riddle 61b81e0f49 [mlir:MLIRAffineUtils] Add missing dependency on MLIRAffineAnalysis
This was missed in a70aa7bb0d.
2022-01-24 21:23:39 -08:00
Mehdi Amini e51a20e166 Fix python test to register all passes before using "normalize-memrefs"
The pass moved from mlir.transforms to the Memref dialect.
2022-01-25 05:15:42 +00:00
River Riddle 63b8018468 [mlir:LoopLikeInterface] Add missing dependency on SideEffectInterfaces
This was missed when moveLoopInvariantCode was added.
2022-01-24 21:13:31 -08:00
River Riddle 65e7cd13bb [mlir] Remove a bunch of unnecessary dialect dependencies
A lot of dialects have dependencies that are unnecessary, either because of copy/paste
of files when creating things or some other means. This commit cleans up a bunch of
the simple ones:

* Copy/Paste or missed during refactoring
Most of the dependencies cleaned up here look like copy/paste errors when creating
new dialects/transformations, or because the dependency wasn't removed during a
refactoring (e.g. when splitting the standard dialect).

* Unnecessary hard coding of constant operations in matchers
There are a few instances where a dialect had a dependency because it
was hardcoding checks for constant operations instead of using the better m_Constant
approach.

Differential Revision: https://reviews.llvm.org/D118062
2022-01-24 19:25:53 -08:00
River Riddle 88c1df64bd [mlir:ArmSVE][NFC] Remove dead code and unnecessary dependencies
Differential Revision: https://reviews.llvm.org/D117981
2022-01-24 19:25:53 -08:00
River Riddle a70aa7bb0d [mlir:Transforms] Move out the remaining non-dialect independent transforms 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-24 19:25:53 -08:00
River Riddle 2e2c0738e8 [mlir:Transforms] Move NormalizeMemRefs to MemRef/Transforms/
Transforms/  should only contain transformations that are dialect-independent and
this pass interacts with MemRef operations (making it a better fit for living in that
dialect).

Differential Revision: https://reviews.llvm.org/D117841
2022-01-24 19:25:53 -08:00
River Riddle 0e9a4a3b65 [mlir] Move the Buffer related source files out of Transforms/
Transforms/ should only contain dialect-independent transformations,
and these files are a much better fit for the bufferization dialect anyways.

Differential Revision: https://reviews.llvm.org/D117839
2022-01-24 19:25:52 -08:00
harsh e01e4c9115 Fix bugs in GPUToNVVM lowering
The current lowering from GPU to NVVM does
not correctly handle the following cases when
lowering the gpu shuffle op.

1. When the active width is set to 32 (all lanes),
then the current approach computes (1 << 32) -1 which
results in poison values in the LLVM IR. We fix this by
defining the active mask as (-1) >> (32 - width).

2. In the case of shuffle up, the computation of the third
operand c has to be different from the other 3 modes due to
the op definition in the ISA reference.
(https://docs.nvidia.com/cuda/parallel-thread-execution/index.html)
Specifically, the predicate value is computed as j >= maxLane
for up and j <= maxLane for all other modes. We fix this by
computing maskAndClamp as 32 - width for this mode.

TEST: We modify the existing test and add more checks for the up mode.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D118086
2022-01-25 03:24:14 +00:00
Mehdi Amini ff8f7904d1 Remove null check after dereferencing the pointer (NFC)
Flagged by Coverity
2022-01-25 02:08:16 +00:00
Aart Bik 92c1c63dae [mlir][sparse] integration test for sparse output operation
Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D118079
2022-01-24 17:41:09 -08:00