Commit Graph

8190 Commits

Author SHA1 Message Date
Mehdi Amini 6b7e6ea489 Revert "Fix CUDA runtime wrapper for GPU mem alloc/free to async"
This reverts commit b4117fede2.
This broke one of the MLIR bot, a test is failing.
2022-04-12 06:50:27 +00:00
Mehdi Amini 3c9e09036c Apply clang-tidy fixes for readability-identifier-naming in LinalgOps.cpp (NFC) 2022-04-12 05:30:01 +00:00
Mehdi Amini 47286e17ed Apply clang-tidy fixes for performance-for-range-copy in LinalgOps.cpp (NFC) 2022-04-12 05:30:01 +00:00
Mehdi Amini 0149a437e2 Apply clang-tidy fixes for llvm-qualified-auto in LinalgOps.cpp (NFC) 2022-04-12 04:39:58 +00:00
Mehdi Amini bf62a4b9c5 Apply clang-tidy fixes for performance-move-const-arg in ArithmeticOps.cpp (NFC) 2022-04-12 04:39:57 +00:00
Uday Bondhugula 56245cc18c [MLIR] NFC. Address clang-tidy warning in AffineOps.cpp
NFC. Address clang-tidy warning in AffineOps.cpp.
2022-04-12 09:58:29 +05:30
Uday Bondhugula b4117fede2 Fix CUDA runtime wrapper for GPU mem alloc/free to async
Switch CUDA runtime wrapper for GPU mem alloc/free to async. The
semantics of the GPU dialect ops (gpu.alloc/dealloc) and the wrappers it
lowered to (gpu-to-llvm) was for the async versions -- however, this was
being incorrectly mapped to cuMemAlloc/cuMemFree instead of
cuMemAllocAsync/cuMemFreeAsync.

Reviewed By: csigg

Differential Revision: https://reviews.llvm.org/D123482
2022-04-12 09:04:02 +05:30
Peixin-Qiao 139c5b8a96 [MLIR][OpenMP] Add support for threadprivate directive
This supports the threadprivate directive in OpenMP dialect following
the OpenMP 5.1 [2.21.2] standard. Also lowering to LLVM IR using OpenMP
IRBduiler.

Reviewed By: kiranchandramohan, shraiysh, arnamoy10

Differential Revision: https://reviews.llvm.org/D123350
2022-04-12 10:15:15 +08:00
jacquesguan 920527f4b5 [mlir][NFC] Remove some redundant code.
Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D123487
2022-04-12 02:10:04 +00:00
Eugene Zhulenev b35b9e307f [mlir] Add msan memory unpoisoning macros to mlir ExecutionEngine
Adding annotations on as-needed bases, currently only for memrefCopy, but in general all C API functions that take pointers to memory allocated/initialized inside the jit-compiled code must be annotated, to be able to run with msan.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D123557
2022-04-11 18:58:28 -07:00
Arthur Eubanks 7ccd026cf2 Reland [mlir] Remove uses of LLVM's legacy pass manager
Use the new pass manager.

This also removes the ability to run arbitrary sets of passes. Not sure if this functionality is used, but it doesn't seem to be tested.

No need to initialize passes outside of constructing the PassBuilder with the new pass manager.

Reland: Fixed custom calls to `-lower-matrix-intrinsics` in integration tests by replacing them with `-O0 -enable-matrix`.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D123425
2022-04-11 16:53:32 -07:00
Arthur Eubanks c3efb75061 Revert "[mlir] Remove uses of LLVM's legacy pass manager"
This reverts commit b0f7f6f78d.

Causes test failures: https://lab.llvm.org/buildbot#builders/61/builds/24879
2022-04-11 16:45:19 -07:00
Mahesh Ravishankar 2291705d2b [mlir][Linalg] Split `populateElementwiseOpsFusionPatterns`.
The method to add elementwise ops fusion patterns pulls in many other
patterns by default. The patterns to pull in along with the
elementwise op fusion should be upto the caller. Split the method to
pull in just the elementwise ops fusion pattern. Other cleanup changes
include
- Move the pattern for constant folding of generic ops (currently only
  constant folds transpose) into a separate file, cause it is not
  related to fusion
- Drop the uber LinalgElementwiseFusionOptions. With the
  populateElementwiseOpsFusionPatterns being split, this has no
  utility now.
- Drop defaults for the control function.
- Fusion of splat constants with generic ops doesnt need a control
  function. It is always good to do.

Differential Revision: https://reviews.llvm.org/D123236
2022-04-11 23:37:23 +00:00
Arthur Eubanks b0f7f6f78d [mlir] Remove uses of LLVM's legacy pass manager
Use the new pass manager.

This also removes the ability to run arbitrary sets of passes. Not sure if this functionality is used, but it doesn't seem to be tested.

No need to initialize passes outside of constructing the PassBuilder with the new pass manager.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D123425
2022-04-11 16:18:45 -07:00
Mehdi Amini f74569b37c Apply clang-tidy fixes for llvm-qualified-auto in AffineOps.cpp (NFC) 2022-04-11 23:14:47 +00:00
Mehdi Amini ceefc26145 Apply clang-tidy fixes for llvm-qualified-auto in ConvertShapeConstraints.cpp (NFC) 2022-04-11 23:14:46 +00:00
Arjun P aafb428237 [MLIR][Presburger][Simplex] symbolic lexmin: add some normalization heuristics
Normalize some of the division and inequality expressions used,
which can improve performance. Also deduplicate some of the
normalization functionality throughout the Presburger library.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D123314
2022-04-11 20:46:30 +01:00
Arjun P a2b212bafc [MLIR][Presburger] subtract: fix bug in the non-recursive implementation
When making the subtract implementation non-recursive, tail calls were
implemented by incrementing the level but not pushing a frame, and returning
was implemented as returning to the level corresponding to the number of frames in the stack.

This is incorrect, as there could be a case where we tail-recurse at `level`,
and then recurse at `level + 1`, pushing a frame. However, because the previous
frame was missing, this new frame would be interpreted as corresponding to
`level` and not `level + 1`. Fix this by removing the special handling of tail
calls and just doing them as normal recursion, as this is the simplest correct
implementation and handling them specifically would be a premature optimization.

The impact of this bug is only on performance as this can only lead to
unnecessary subtractions of the same disjuncts multiples times. As subtraction
is idempotent, and rationally empty disjuncts are always discarded, this
does not affect the output, so this patch does not include a regression test.
(This also does not affect termination.)

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D123327
2022-04-11 20:45:29 +01:00
gysit 973dbe20f6 [mlir][tensor] Add pattern to fold ExtractSliceOp, PadOp chains.
The pattern folds chains of tensor::ExtractSliceOp, tensor::PadOp pairs if they pad different dimensions. Repeated tiling and padding of the tiled dimensions may introduce such chains. This canonicalization pattern folds these chains to a single tensor::ExtractSliceOp, tensor::PadOp pair that pads all dimensions at once, which simplifies vectorization and bufferization.

Example:
```mlir
   %0 = tensor.extract_slice %input[16, 0] [%sz0, 64] [1, 1]
       : tensor<64x64xf32> to tensor<?x64xf32>
   %1 = tensor.pad %0 low[0, 0] high[%pw0, 0] { ...
     } : tensor<?x64xf32> to tensor<8x64xf32>
   %2 = tensor.extract_slice %1[0, 4] [8, %sz1] [1, 1]
        : tensor<8x64xf32> to tensor<8x?xf32>
   %res = tensor.pad %2 nofold low[0, 0] high[0, %pw1] { ...
     } : tensor<8x?xf32> to tensor<8x4xf32>
```
folds into:
 ```mlir
   %0 = tensor.extract_slice %input[16, 4] [%sz0, %sz1] [1, 1]
        : tensor<64x64xf32> to tensor<?x?xf32>
   %res = tensor.pad %0 nofold low[0, 0] high[%pw0, %pw1] { ...
     } : tensor<?x?xf32> to tensor<8x4xf32>
 ```

Reviewed By: nicolasvasilache, hanchung

Differential Revision: https://reviews.llvm.org/D122722
2022-04-11 14:28:59 +00:00
gysit 39b9336474 [mlir][vector] Swap ExtractSliceOp(TransferWriteOp).
Rewrite tensor::ExtractSliceOp(vector::TransferWriteOp) to vector::TransferWriteOp(tensor::ExtractSliceOp) if the full slice is overwritten and inserted into another tensor. After this rewrite, the operations bufferize in-place since all of them work on the same %iter_arg slice.

For example:
```mlir
  %0 = vector.transfer_write %vec, %init_tensor[%c0, %c0]
       : vector<8x16xf32>, tensor<8x16xf32>
  %1 = tensor.extract_slice %0[0, 0] [%sz0, %sz1] [1, 1]
       : tensor<8x16xf32> to tensor<?x?xf32>
  %r = tensor.insert_slice %1 into %iter_arg[%iv0, %iv1] [%sz0, %sz1] [1, 1]
       : tensor<?x?xf32> into tensor<27x37xf32>
```
folds to
```mlir
  %0 = tensor.extract_slice %iter_arg[%iv0, %iv1] [%sz0, %sz1] [1, 1]
       : tensor<27x37xf32> to tensor<?x?xf32>
  %1 = vector.transfer_write %vec, %0[%c0, %c0]
       : vector<8x16xf32>, tensor<?x?xf32>
  %r = tensor.insert_slice %1 into %iter_arg[%iv0, %iv1] [%sz0, %sz1] [1, 1]
       : tensor<?x?xf32> into tensor<27x37xf32>

Reviewed By: nicolasvasilache, hanchung

Differential Revision: https://reviews.llvm.org/D123190
2022-04-11 10:28:53 +00:00
wren romano 8d8b566f0c [mlir][sparse] Moving <P,I,V>-invariant parts of SparseTensorStorage to base
This reorganization helps to clean up the changes needed for D122060.

Work towards fixing: https://github.com/llvm/llvm-project/issues/51652

Depends On D122625

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D122928
2022-04-08 11:44:17 -07:00
Matthias Springer d7a9bf9143 [mlir][tensor] Fix verifier and bufferization of collapse_shape
Insert a buffer copy unless the dims are guaranteed to be collapsible. In the verifier, accept collapses unless they are guaranteed to be non-collapsible.

Differential Revision: https://reviews.llvm.org/D123316
2022-04-08 18:20:40 +09:00
Matthias Springer d2608adf49 [mlir][bufferize] Do not insert useless casts for newly allocated buffers
Differential Revision: https://reviews.llvm.org/D123369
2022-04-08 18:12:02 +09:00
Matthias Springer 8b09141909 [mlir][arith][bufferize] Fix tensors with different layouts after bufferization
Insert a cast if the two tensors with identical layout (that are passed to `arith.select`) have different layout maps after bufferization.

Differential Revision: https://reviews.llvm.org/D123321
2022-04-08 18:11:10 +09:00
jacquesguan e79b7f501c [mlir][Vector] Fold extractelement splat.
This revision supports to fold vector.extractelement (splat X) -> X.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D122960
2022-04-08 07:54:37 +00:00
jacquesguan 088d38890c [mlir][Arithmetic] Add constant folder for negf.
Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D123293
2022-04-08 07:36:29 +00:00
River Riddle 36d3efea15 [mlir][NFC] Drop a few unnecessary includes from Pass.h 2022-04-07 23:42:47 -07:00
Markus Böck 0c789db541 [mlir] Add support for operation-produced successor arguments in BranchOpInterface
This patch revamps the BranchOpInterface a bit and allows a proper implementation of what was previously `getMutableSuccessorOperands` for operations, which internally produce arguments to some of the block arguments. A motivating example for this would be an invoke op with a error handling path:
```
invoke %function(%0)
  label ^success ^error(%1 : i32)

^error(%e: !error, %arg0 : i32):
  ...
```
The advantages of this are that any users of `BranchOpInterface` can still argue over remaining block argument operands (such as `%1` in the example above), as well as make use of the modifying capabilities to add more operands, erase an operand etc.

The way this patch implements that functionality is via a new class called `SuccessorOperands`, which is now returned by `getSuccessorOperands`. It basically contains an `unsigned` denoting how many operator produced operands exist, as well as a `MutableOperandRange`, which are the usual forwarded operands we are used to. The produced operands are assumed to the first few block arguments, followed by the forwarded operands afterwards. The role of `SuccessorOperands` is to provide various utility functions to modify and query the successor arguments from a `BranchOpInterface`.

Differential Revision: https://reviews.llvm.org/D123062
2022-04-08 08:28:16 +02:00
Stella Laurenzo 497f87bb7b NFC: Silence unused function 'scaleAndAdd' in release build.
Differential Revision: https://reviews.llvm.org/D123354
2022-04-07 21:19:19 -07:00
River Riddle af371f9f98 Reland [GreedPatternRewriter] Preprocess constants while building worklist when not processing top down
Reland Note: Adds a fix to properly mark a commutative operation as folded if we change the order
             of its operands. This was uncovered by the fact that we no longer re-process constants.

This avoids accidentally reversing the order of constants during successive
application, e.g. when running the canonicalizer. This helps reduce the number
of iterations, and also avoids unnecessary changes to input IR.

Fixes #51892

Differential Revision: https://reviews.llvm.org/D122692
2022-04-07 11:31:42 -07:00
natashaknk fac9f45e05 [tosa][mlir] Add dynamic width/height support for depthwise convolution in tosa-to-linalg
In addition, fixed a small bug with padding incorrectly inferring output shape for dynaic inputs in convolution

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D121872
2022-04-07 10:50:06 -07:00
Lei Zhang 7becf0f6cd [mlir][vector] Fold extract(broadcast) of same rank
This case is handled in neither the folding or canonicalization
patterns. The folding pattern cannot generate new broadcast ops,
so it should be handled by the canonicalization pattern.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D123307
2022-04-07 12:59:54 -04:00
Arjun P 00b293e83f [MLIR][Presburger] refactor subtraction to be non-recursive
Subtraction was previously implemented recursively. This refactors it to be
non-recursive to avoid issues with potential stack overflows.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D123248
2022-04-07 15:20:19 +01:00
Valentin Clement 02da964350
[mlir][CSE] Remove duplicated operations with MemRead side-effect
This patch enhances the CSE pass to deal with simple cases of duplicated
operations with MemoryEffects.

It allows the CSE pass to remove safely duplicate operations with the
MemoryEffects::Read that have no other side-effecting operations in
between. Other MemoryEffects::Read operation are allowed.

The use case is pretty simple so far so we can build on top of it to add
more features.

This patch is also meant to avoid a dedicated CSE pass in FIR and was
brought together afetr discussion on https://reviews.llvm.org/D112711.
It does not currently cover the full range of use cases described in
https://reviews.llvm.org/D112711 but the idea is to gradually enhance
the MLIR CSE pass to handle common use cases that can be used by
other dialects.

This patch takes advantage of the new CSE capabilities in Fir.

Reviewed By: mehdi_amini, rriddle, schweitz

Differential Revision: https://reviews.llvm.org/D122801
2022-04-07 10:08:55 +02:00
River Riddle 5520e07f46 [mlir:Parser][NFC] Replace SSAUseInfo with OpAsmParser::UnresolvedOperand
These are functionally identical, and merging the two removes the number of
redundant conversions within the parser.
2022-04-06 18:25:08 -07:00
River Riddle ea64828a10 [mlir:PDL] Expand how native constraint/rewrite functions can be defined
This commit refactors the expected form of native constraint and rewrite
functions, and greatly reduces the necessary user complexity required when
defining a native function. Namely, this commit adds in automatic processing
of the necessary PDLValue glue code, and allows for users to define
constraint/rewrite functions using the C++ types that they actually want to
use.

As an example, lets see a simple example rewrite defined today:

```
static void rewriteFn(PatternRewriter &rewriter, PDLResultList &results,
                      ArrayRef<PDLValue> args) {
  ValueRange operandValues = args[0].cast<ValueRange>();
  TypeRange typeValues = args[1].cast<TypeRange>();
  ...
  // Create an operation at some point and pass it back to PDL.
  Operation *op = rewriter.create<SomeOp>(...);
  results.push_back(op);
}
```

After this commit, that same rewrite could be defined as:

```
static Operation *rewriteFn(PatternRewriter &rewriter ValueRange operandValues,
                            TypeRange typeValues) {
  ...
  // Create an operation at some point and pass it back to PDL.
  return rewriter.create<SomeOp>(...);
}
```

Differential Revision: https://reviews.llvm.org/D122086
2022-04-06 17:41:59 -07:00
Aart Bik 0b55f94d2b [mlir][sparse] replace stack-based access pattern with dyn-alloc
Rationale:
Allocating the temporary buffers for access pattern expansion on the stack
(using alloca) is a bit too agressive, since it easily runs out of stack space
for large enveloping tensor dimensions. This revision changes the dynamic
allocation of these buffers with explicit alloc/dealloc pairs.

Reviewed By: bixia, wrengr

Differential Revision: https://reviews.llvm.org/D123253
2022-04-06 17:10:43 -07:00
John Demme 8d8738f6fe [MLIR] Add block detach func to CAPI and use it in Python bindings
Adds `mlirBlockDetach` to the CAPI to remove a block from its parent
region. Use it in the Python bindings to implement
`Block.append_to(region)`.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D123165
2022-04-06 13:11:56 -07:00
Matthias Springer 7e6de86ff6 [mlir][bufferize][NFC] Remove caller map and ordered func list from FuncAnalysisState
These can be local variables. No need to store them in the struct.

Differential Revision: https://reviews.llvm.org/D123210
2022-04-07 00:49:24 +09:00
Matthias Springer cb186bc508 [mlir][bufferize][NFC] Rename ModuleAnalysisState to FuncAnalysisState
This is for consistency reasons. `*AnalysisState` always starts with the name of the dialect.

Differential Revision: https://reviews.llvm.org/D123209
2022-04-07 00:48:53 +09:00
Arjun P 1ba6043332 [MLIR][Presburger] Refactor subtraction in preparation for making it iterative
Refactor the operation of subtraction by
- removing the usage of SimplexRollbackScopeExit since this
  can't be used in the iterative version
- reducing the number of stack variables to make the
  iterative version easier to follow

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D123156
2022-04-06 16:35:28 +01:00
Matthias Springer f4f1cf6c31 [mlir][bufferize] Better analysis for return values of CallOps
Support returning arbitrary tensors from functions. Even those that are
not equivalent. To that end, additional information is gathered during
the analysis phase. In particular, which function args are aliasing with
which return values.

Also fix bugs in the current implementation when returning equivalent
tensors. Various unit tests are added to ensure that we have better test
coverage.

Note: Returning non-equivalent tensors is only allowed when
allowReturnAllocs is enabled. This functionality is useful for unit
testing and compatibility with other bufferizations such as the sparse
compiler. This is also towards using ModuleBufferization as a
replacement for --func-bufferize.

Differential Revision: https://reviews.llvm.org/D119120
2022-04-06 23:54:32 +09:00
Matthias Springer cd7de446fd [mlir][bufferize] Simplify ModuleBufferization driver
* Bufferize FuncOp bodies and boundaries in the same loop. This is in preparation of moving FuncOp bufferization into an external model implementation.
* As a side effect, stop bufferization earlier if there was an error. (Do not continue bufferization, fewer error messages.)
* Run equivalence analysis of CallOps before the main analysis. This is needed so that equialvence info is propagated properly.

Differential Revision: https://reviews.llvm.org/D123208
2022-04-06 23:53:07 +09:00
Matthias Springer 5ab34492d6 [mlir][bufferize] Fix dropped return type in ModuleBufferization
Differential Revision: https://reviews.llvm.org/D123192
2022-04-06 23:48:15 +09:00
Alexander Belyaev 747b10be95 Revert "Revert "[mlir] Rewrite canonicalization of collapse(expand) and expand(collapse).""
This reverts commit 96e9b6c9dc.
2022-04-06 12:18:30 +02:00
Matthias Springer 7a50560354 [mlir][bufferize][NFC] Clean up ModuleBufferizationState
* Store bbArg indices instead of BlockArguments, so that args can be changed during bufferizationn.
* Use type aliases for better readability.

Differential Revision: https://reviews.llvm.org/D123191
2022-04-06 18:32:53 +09:00
Nicolas Vasilache fc8f465a00 [mlir][MemRef] Allow transposed layouts in ExpandShapeOp.
https://reviews.llvm.org/D122641 introduced fixes to the ExpandShapeOp verifier
but also introduced an artificial layout limitation that prevents the consideration of transposed layouts.

This revision fixes the omissions and reimplements the logic using saturated arithmetic which is more
idiomatic and avoids leaking internal implementation details.

Tests cases are added for transposed layouts.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D122845
2022-04-06 04:19:30 -04:00
Argyrios Kyrtzidis 330268ba34 [Support/Hash functions] Change the `final()` and `result()` of the hashing functions to return an array of bytes
Returning `std::array<uint8_t, N>` is better ergonomics for the hashing functions usage, instead of a `StringRef`:

* When returning `StringRef`, client code is "jumping through hoops" to do string manipulations instead of dealing with fixed array of bytes directly, which is more natural
* Returning `std::array<uint8_t, N>` avoids the need for the hasher classes to keep a field just for the purpose of wrapping it and returning it as a `StringRef`

As part of this patch also:

* Introduce `TruncatedBLAKE3` which is useful for using BLAKE3 as the hasher type for `HashBuilder` with non-default hash sizes.
* Make `MD5Result` inherit from `std::array<uint8_t, 16>` which improves & simplifies its API.

Differential Revision: https://reviews.llvm.org/D123100
2022-04-05 21:38:06 -07:00
Aart Bik 175b9af484 [mlir][sparse] avoid reserving dense storage for ptr/idx
This avoids a rather big bug where we were reserving
dense space for the ptx/idx in the first sparse dimension.
For example, using CSR for a 140874 x 140874 matrix with
3977139 nonzero would reserve the full 19845483876 space.
This revision fixes this for now, but we need to revisit
the reservation heuristic to make this better.

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D123166
2022-04-05 17:40:01 -07:00
Hanhan Wang 96e9b6c9dc Revert "[mlir] Rewrite canonicalization of collapse(expand) and expand(collapse)."
This reverts commit 64f659bee6.

An invalid tensor.expand_shape op is generated with the commit. To repro:

$ mlir-opt -canonicalize a.mlir

```
func @foo(%0: tensor<1x1xf32>, %1: tensor<1x1xf32>, %2: tensor<1x1xf32>) -> tensor<1x1xf32> {
  %cst = arith.constant 0.000000e+00 : f32
  %3 = linalg.init_tensor [8, 1] : tensor<8x1xf32>
  %4 = linalg.fill ins(%cst : f32) outs(%3 : tensor<8x1xf32>) -> tensor<8x1xf32>
  %5 = tensor.collapse_shape %0 [] : tensor<1x1xf32> into tensor<f32>
  %6 = tensor.insert_slice %5 into %4[0, 0] [1, 1] [1, 1] : tensor<f32> into tensor<8x1xf32>
  %7 = linalg.init_tensor [8, 1] : tensor<8x1xf32>
  %8 = linalg.fill ins(%cst : f32) outs(%7 : tensor<8x1xf32>) -> tensor<8x1xf32>
  %9 = tensor.collapse_shape %2 [] : tensor<1x1xf32> into tensor<f32>
  %10 = tensor.insert_slice %9 into %8[0, 0] [1, 1] [1, 1] : tensor<f32> into tensor<8x1xf32>
  %11 = tensor.collapse_shape %6 [[0, 1]] : tensor<8x1xf32> into tensor<8xf32>
  %12 = linalg.init_tensor [8] : tensor<8xf32>
  %13 = linalg.generic {indexing_maps = [affine_map<(d0) -> (d0)>, affine_map<(d0) -> (d0)>], iterator_types = ["parallel"]} ins(%11 : tensor<8xf32>) outs(%12 : tensor<8xf32>) {
  ^bb0(%arg3: f32, %arg4: f32):
    linalg.yield %arg3 : f32
  } -> tensor<8xf32>
  %14 = tensor.expand_shape %13 [[0, 1, 2, 3]] : tensor<8xf32> into tensor<1x1x8x1xf32>
  %15 = tensor.collapse_shape %1 [] : tensor<1x1xf32> into tensor<f32>
  %16 = linalg.init_tensor [] : tensor<f32>
  %17 = linalg.generic {indexing_maps = [affine_map<() -> ()>, affine_map<() -> ()>], iterator_types = []} ins(%15 : tensor<f32>) outs(%16 : tensor<f32>) {
  ^bb0(%arg3: f32, %arg4: f32):
    linalg.yield %arg3 : f32
  } -> tensor<f32>
  %18 = tensor.expand_shape %17 [] : tensor<f32> into tensor<1x1x1x1xf32>
  %19 = tensor.collapse_shape %10 [[0, 1]] : tensor<8x1xf32> into tensor<8xf32>
  %20 = linalg.init_tensor [8] : tensor<8xf32>
  %21 = linalg.generic {indexing_maps = [affine_map<(d0) -> (d0)>, affine_map<(d0) -> (d0)>], iterator_types = ["parallel"]} ins(%19 : tensor<8xf32>) outs(%20 : tensor<8xf32>) {
  ^bb0(%arg3: f32, %arg4: f32):
    linalg.yield %arg3 : f32
  } -> tensor<8xf32>
  %22 = tensor.expand_shape %21 [[0, 1, 2, 3]] : tensor<8xf32> into tensor<1x1x8x1xf32>
  %23 = linalg.mmt4d {comment = "f32*f32->f32, aarch64, matrix*vector"} ins(%14, %18 : tensor<1x1x8x1xf32>, tensor<1x1x1x1xf32>) outs(%22 : tensor<1x1x8x1xf32>) -> tensor<1x1x8x1xf32>
  %24 = tensor.collapse_shape %23 [[0, 1, 2, 3]] : tensor<1x1x8x1xf32> into tensor<8xf32>
  %25 = linalg.init_tensor [8] : tensor<8xf32>
  %26 = linalg.generic {indexing_maps = [affine_map<(d0) -> (d0)>, affine_map<(d0) -> (d0)>], iterator_types = ["parallel"]} ins(%24 : tensor<8xf32>) outs(%25 : tensor<8xf32>) {
  ^bb0(%arg3: f32, %arg4: f32):
    linalg.yield %arg3 : f32
  } -> tensor<8xf32>
  %27 = tensor.expand_shape %26 [[0, 1]] : tensor<8xf32> into tensor<8x1xf32>
  %28 = tensor.extract_slice %27[0, 0] [1, 1] [1, 1] : tensor<8x1xf32> to tensor<f32>
  %29 = tensor.expand_shape %28 [] : tensor<f32> into tensor<1x1xf32>
  return %29 : tensor<1x1xf32>
}
```

Differential Revision: https://reviews.llvm.org/D123161
2022-04-05 15:05:41 -07:00
Groverkss 0a06ac749b [MLIR][Affine][Analysis] Merge FAC and FACV
With the introduction of IntegerPolyhedron and IntegerRelation in Presburger
directory, the purpose of FlatAffineConstraints becomes redundant. For users
requiring Presburger arithmetic without IR information, Presburger library can
directly be used. For users requiring IR information,
FlatAffineValueConstraints can be used.

This patch merges FAC and FACV to remove redundancy of FAC.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D122476
2022-04-06 03:02:32 +05:30
Bill Wendling 1acba8a4b5 [mlir] Reinstate the variable
Mid-air collition of patches.
2022-04-05 13:57:14 -07:00
Bill Wendling 4169650537 [mlir] Remove an unused variable and correct types.
No functionality change.
2022-04-05 13:44:12 -07:00
Nirvedh 01055ed1d7 [mlir][linalg] Move linalg.fill folding into linalg.generic pattern from canonicalization to elementwise fusion
Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D122847
2022-04-05 20:13:03 +00:00
Benjamin Kramer e7f0552682 [mlir] Fix unused variable warning. NFCI. 2022-04-05 21:24:05 +02:00
Lei Zhang 59d3a9e087 [mlir][vector] Separate high-D insert/extract strided slice rewrite
Right now `populateVectorInsertExtractStridedSliceTransforms` contains
two categories of patterns, one for decomposing high-D insert/extract
strided slices, the other for lowering them to shuffle ops.
They are at different levels---the former is in the middle, while
the latter is a step of final lowering. Split them to give users
more control of which pattern to pick.

This means break down the previous `VectorExtractStridedSliceOpRewritePattern`,
which is doing two things together.

Also renamed those patterns to be clearer.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D123137
2022-04-05 15:00:50 -04:00
Arjun P 79ad5fb295 [MLIR][Presburger] IntegerPolyhedron: add support for symbolic integer lexmin
Add support for computing the symbolic integer lexmin of a polyhedron.
This finds, for every assignment to the symbols, the lexicographically
minimum value attained by the dimensions. For example, the symbolic lexmin
of the set

`(x, y)[a, b, c] : (a <= x, b <= x, x <= c)`

can be written as

```
x = a if b <= a, a <= c
x = b if a <  b, b <= c
```

This also finds the set of assignments to the symbols that make the lexmin unbounded.

This was previously landed in da92f92621 and
reverted in b238c252e8 due to a build failure
in the code. Re-landing now with a fixed build.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122985
2022-04-05 18:50:34 +01:00
Michael Kruse c082ca16f1 [OpenMPIRBuilder] Detect and fix ambiguous InsertPoints for createSections.
Follow-up on D117226 for createSections.

Reviewed By: shraiysh

Differential Revision: https://reviews.llvm.org/D117835
2022-04-05 12:36:29 -05:00
Krzysztof Drewniak 408a67ff49 [MLIR][ROCm] Suppress warnings generated by HIP headers
This removes tens of warnings from build logs that we can't do
anything about.

Reviewed By: pcf000

Differential Revision: https://reviews.llvm.org/D122927
2022-04-05 16:49:37 +00:00
Lorenzo Chelini ae0fb61303 [MLIR] Check for static shape before bare pointer conversion
Originally in the returnOp conversion, the result type was changing to bare
pointer if the type was a memref. This is incorrect as conversion to bare
pointer can only be done if the memref has static shape, strides and offset.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D123121
2022-04-05 17:56:41 +02:00
Alex Zinenko 0be38d4f32 [mlir][ods] Add description to Attr and ensure doc generation
Add the description textual field to the Attr ODS class to mirror an
identical field in the Type ODS class. Add support for generating
documentation for attribute constraints defined using this field. This
ensures mlir-tblgen produces at least some documentation for dialects
that only define attribute constraints, such as DLTI.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D123024
2022-04-05 10:40:15 +02:00
Mehdi Amini d2ca2b94fd Apply clang-tidy fixes for readability-redundant-control-flow in FuncToLLVM.cpp (NFC) 2022-04-05 08:19:33 +00:00
Alexander Belyaev 64f659bee6 [mlir] Rewrite canonicalization of collapse(expand) and expand(collapse).
Differential Revision: https://reviews.llvm.org/D122666
2022-04-05 10:03:07 +02:00
Adrian Kuegel 72fe439a4e [mlir] Fix 1 ClangTidyPerformance finding (NFC) 2022-04-05 09:29:35 +02:00
wren romano 72ec2f7639 [mlir][sparse] Factoring out `finalizeSegment` and (generic) `appendIndex`
This change introduces two new methods: `finalizeSegment` and `appendIndex`; and removes three old methods: `endDim`, `appendCurrentPointer`, `appendIndex`.  The two new methods better encapsulate their algorithms, thus allowing to remove repetitious code in several other places.

Depends On D122435

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D122625
2022-04-04 19:11:31 -07:00
Arjun P b238c252e8 Revert "[MLIR][Presburger] IntegerPolyhedron: add support for symbolic integer lexmin"
This reverts commit da92f92621.
2022-04-05 00:31:17 +01:00
Arjun P da92f92621 [MLIR][Presburger] IntegerPolyhedron: add support for symbolic integer lexmin
Add support for computing the symbolic integer lexmin of a polyhedron.
This finds, for every assignment to the symbols, the lexicographically
minimum value attained by the dimensions. For example, the symbolic lexmin
of the set

`(x, y)[a, b, c] : (a <= x, b <= x, x <= c)`

can be written as

```
x = a if b <= a, a <= c
x = b if a <  b, b <= c
```

This also finds the set of assignments to the symbols that make the lexmin unbounded.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122985
2022-04-05 00:24:57 +01:00
River Riddle 1269f96d2e [mlir] Add MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID to SerializeToCubinPass
This pass is defined in an anonymous namespace and requires an explicit TypeID
2022-04-04 14:28:10 -07:00
Lei Zhang f1a7e508a5 [mlir][spirv] Check nullptr before usage to fix crash
Reviewed By: mravishankar, hanchung

Differential Revision: https://reviews.llvm.org/D123035
2022-04-04 17:20:00 -04:00
River Riddle 5e50dd048e [mlir] Rework the implementation of TypeID
This commit restructures how TypeID is implemented to ideally avoid
the current problems related to shared libraries. This is done by changing
the "implicit" fallback path to use the name of the type, instead of using
a static template variable (which breaks shared libraries). The major downside to this
is that it adds some additional initialization costs for the implicit path. Given the
use of type names for uniqueness in the fallback, we also no longer allow types
defined in anonymous namespaces to have an implicit TypeID. To simplify defining
an ID for these classes, a new `MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID` macro
was added to allow for explicitly defining a TypeID directly on an internal class.

To help identify when types are using the fallback, `-debug-only=typeid` can be
used to log which types are using implicit ids.

This change generally only requires changes to the test passes, which are all defined
in anonymous namespaces, and thus can't use the fallback any longer.

Differential Revision: https://reviews.llvm.org/D122775
2022-04-04 13:52:26 -07:00
wren romano 3bf2ba3b9a [mlir][sparse] Simplifying code in expInsert
Just some minor cleanup

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D122934
2022-04-04 12:53:42 -07:00
Rob Suderman 126e7eaf0d [tosa] Add option to disable tosa.apply_scale lowering in TosaToStandard
Apply scale should be optionally disabled when lowering via TosaToStandard.
In most cases it should persist until the lowering to specific backend.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D122948
2022-04-04 12:22:12 -07:00
Mehdi Amini dacb2713c4 Apply clang-tidy fixes for llvm-qualified-auto in FuncToLLVM.cpp (NFC) 2022-04-04 18:18:10 +00:00
Benjamin Kramer 4ae24d9fd9 [mlir][capi] Unbreak Interfaces CAPI after 2387fadea3
No idea why check-mlir doesn't build this.
2022-04-04 18:52:11 +02:00
Daniel Resnick 2387fadea3 [mlir][capi] Add external pass creation to MLIR C-API
Adds the ability to create external passes using the C-API. This allows passes
to be written in C or languages that use the C-bindings.

Differential Revision: https://reviews.llvm.org/D121866
2022-04-04 10:27:11 -06:00
PeixinQiao 706dec3e47 [mlir] Fix the build error in OpenMPToLLVMIRTranslation.cpp
Fix the build error with "-Werror,-Wcovered-switch-default".

Reviewed By: hpmorgan

Differential Revision: https://reviews.llvm.org/D123018
2022-04-04 19:46:16 +08:00
Groverkss bab2a4f2fb [MLIR][Presburger] Use PresburgerSpace in SetCoalescer
This patch changes the implementation of SetCoalescer to use PresburgerSpace
instead of reimplementing parts of PresburgerSpace.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D122984
2022-04-03 04:06:47 +05:30
Groverkss 1483fb33b3 [MLIR][Presburger][NFC] Rename getCompatibleSpace to getSpaceWithoutLocals
Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D122973
2022-04-02 23:39:57 +05:30
Arjun P fbeb0db54f [MLIR][Presburger] LexSimplex: support is{Redundant,Separate}Inequality
Add integer-exact checks for inequalities being separate and redundant in LexSimplex.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122921
2022-04-02 12:31:17 +01:00
River Riddle 0d8df98035 [mlir] Allow for using OpPassManager in pass options
This significantly simplifies the boilerplate necessary for passes
to define nested pass pipelines.

Differential Revision: https://reviews.llvm.org/D122880
2022-04-02 00:45:11 -07:00
River Riddle 6edef13569 [mlir:PassOption] Rework ListOption parsing and add support for std::vector/SmallVector options
ListOption currently uses llvm:🆑:list under the hood, but the usages
of ListOption are generally a tad different from llvm:🆑:list. This
commit codifies this by making ListOption implicitly comma separated,
and removes the explicit flag set for all of the current list options.
The new parsing for comma separation of ListOption also adds in support
for skipping over delimited sub-ranges (i.e. {}, [], (), "", ''). This
more easily supports nested options that use those as part of the
format, and this constraint (balanced delimiters) is already codified
in the syntax of pass pipelines.

See https://discourse.llvm.org/t/list-of-lists-pass-option/5950 for
related discussion

Differential Revision: https://reviews.llvm.org/D122879
2022-04-02 00:45:11 -07:00
jacquesguan bc37077947 [mlir][Vector] Add constant folder for extractelement.
This revision adds constant folder for vector.extractelement.

Differential Revision: https://reviews.llvm.org/D122886
2022-04-02 11:10:42 +08:00
jacquesguan 262823612d [mlir][Vector] Add constant folder for insertelement.
This revision adds constant folder for vector.insertelement.

Differential Revision: https://reviews.llvm.org/D122721
2022-04-02 10:20:19 +08:00
Lei Zhang a480d75fe4 [mlir][vector] Fold transpose(broadcast(<scalar>))
For such cases, the transpose op can be elided.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D122903
2022-04-01 14:51:36 -04:00
wren romano 63bdcaf92a [mlir][sparse] Moving `delete coo` into codegen instead of runtime library
Prior to this change there were a number of places where the allocation and deallocation of SparseTensorCOO objects were not cleanly paired, leading to inconsistencies regarding whether each function released its tensor/coo arguments or not, as well as making it easy to run afoul of memory leaks, use-after-free, or double-free errors.  This change cleans up the codegen vs runtime boundary to resolve those issues.  Now, the only time the runtime library frees an object is either (a) because it's a function explicitly designed to do so, or (b) because the allocated object is entirely local to the function and would be a memory leak if not released.  Thus, now the codegen takes complete responsibility for releasing any objects it caused to be allocated.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D122435
2022-04-01 11:08:52 -07:00
Lei Zhang 57b101bdec [mlir][vector] Handle scalars in extract_strided_slice(broadcast)
For such cases we cannot generate extract_strided_slice ops.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D122902
2022-04-01 12:07:47 -04:00
Lei Zhang 533ec929f6 [mlir][spirv] Add pattern to lower math.copysign
This follows the logic:
https://git.musl-libc.org/cgit/musl/tree/src/math/copysignf.c

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D122910
2022-04-01 12:06:47 -04:00
Matthias Springer 73c0333dee [mlir][tensor][bufferize] Support 0-d collapse_shape with offset
Differential Revision: https://reviews.llvm.org/D122901
2022-04-01 22:30:37 +09:00
Groverkss de70ff10e4 [MLIR][Presburger][NFC] Use "disjunct" to refer to disjuncts in PresburgerRelation
This patch modifies the name "integerRelations" and "relation" to refer to the
disjuncts in PresburgerRelation to "disjunct(s)".  This is done to be
consistent with the rest of the interface.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D122892
2022-04-01 17:38:30 +05:30
Arjun P 31cb99959f [MLIR][Presburger] subtract: fix bug when an input set has duplicate divisions
Previously, when an input set had a duplicate division, the duplicates might
be removed by a call to mergeLocalIds due to being detected as being duplicate
for the first time. The subtraction implementation cannot handle existing
locals being removed, so this would lead to unexpected behaviour. Resolve this
by removing all the duplicates up front.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122826
2022-04-01 12:38:45 +01:00
Arjun P acb378e21c [MLIR][Presburger] Factor out some functionality from LexSimplex into a LexSimplexBase
LexSimplex cannot be made to support symbols for symbolic lexmin; this requires
a second class. In preparation for upstreaming support for symbolic lexmin,
keep the part of LexSimplex that are specific to non-symbolic lexmin in LexSimplex
and move the parts that are required to a common class LexSimplexBase for both to
inherit from.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122828
2022-04-01 11:54:26 +01:00
Groverkss a5a598be44 [MLIR][Presburger] Use PresburgerSpace in constructors
This patch modifies IntegerPolyhedron, IntegerRelation, PresburgerRelation,
PresburgerSet, PWMAFunction, constructors to take PresburgerSpace instead of
dimensions. This allows information present in PresburgerSpace to be carried
better and allows for a general interface.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D122842
2022-04-01 15:07:26 +05:30
Peixin-Qiao 3e7415a0ff [OMPIRBuilder] Support ordered clause specified without parameter
This patch supports ordered clause specified without parameter in
worksharing-loop directive in the OpenMPIRBuilder and lowering MLIR to
LLVM IR.

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D114940
2022-04-01 16:17:29 +08:00
Mehdi Amini ba43d6f85c Revert "[GreedPatternRewriter] Preprocess constants while building worklist when not processing top down"
This reverts commit 59bbc7a085.

This exposes an issue breaking the contract of
`applyPatternsAndFoldGreedily` where we "converge" without applying
remaining patterns.
2022-04-01 06:16:55 +00:00
River Riddle 59bbc7a085 [GreedPatternRewriter] Preprocess constants while building worklist when not processing top down
This avoids accidentally reversing the order of constants during successive
application, e.g. when running the canonicalizer. This helps reduce the number
of iterations, and also avoids unnecessary changes to input IR.

Fixes #51892

Differential Revision: https://reviews.llvm.org/D122692
2022-03-31 12:08:55 -07:00
Okwan Kwon 65bdeddb1e [mlir] Bubble up tensor.extract_slice above linalg operation
Bubble up extract_slice above Linalg operation.

A sequence of operations

    %0 = linalg.<op> ... arg0, arg1, ...
    %1 = tensor.extract_slice %0 ...

can be replaced with

    %0 = tensor.extract_slice %arg0
    %1 = tensor.extract_slice %arg1
    %2 = linalg.<op> ... %0, %1, ...

This results in the reduce computation of the linalg operation.

The implementation uses the tiling utility functions. One difference
from the tiling process is that we don't need to insert the checking
code for the out-of-bound accesses. The use of the slice itself
represents that the code writer is sure about the boundary condition.
To avoid adding the boundary condtion check code, `omitPartialTileCheck`
is introduced for the tiling utility functions.

Differential Revision: https://reviews.llvm.org/D122437
2022-03-31 16:48:38 +00:00
Groverkss 152e501d87 [MLIR][Presburger] Carry IdKind information in LinearTransform::applyTo
This patch fixes a bug in LinearTransform::applyTo where it did not carry the
IdKind information, and instead treated every id as IdKind::Domain.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D122823
2022-03-31 20:42:50 +05:30
Arjun P 9615d717d1 [MLIR][Presburger] IntegerRelation::truncate: fix bug when truncating equalities
This was truncating inequalities instead of equalities.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122811
2022-03-31 15:16:30 +01:00
Arjun P d81fa76f3a [MLIR][Presburger] MultiAffineFunction:eliminateRedundantLocalId: fix bug where local offset was not considered
Previously, when updating the outputs matrix, the local offset was not being considered.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122812
2022-03-31 15:11:55 +01:00
Matthias Springer 566975a252 [mlir][memref][NFC] Remove unused function
This fixes a compiler warning.
2022-03-31 17:16:03 +09:00
Matthias Springer 51df62388e [mlir][tensor] Fix bufferization of CollapseShapeOp / ExpandShapeOp
Infer a tighter MemRef type instead of always falling back to the most dynamic MemRef type. This is inefficient and caused op verification errors.

Differential Revision: https://reviews.llvm.org/D122649
2022-03-31 17:11:45 +09:00
Matthias Springer 86d118e7f2 [mlir][memref] Fix CollapseShapeOp verifier
Differential Revision: https://reviews.llvm.org/D122647
2022-03-31 17:08:16 +09:00
Matthias Springer 2bd7ee4566 [mlir][memref] Fix ExpandShapeOp verifier
* Complete rewrite of the verifier.
* CollapseShapeOp verifier will be updated in a subsequent commit.
* Update and expand op documentation.
* Add a new builder that infers the result type based on the source type, result shape and reassociation indices. In essence, only the result layout map is inferred.

Differential Revision: https://reviews.llvm.org/D122641
2022-03-31 17:05:52 +09:00
jacquesguan 01ad70fd1d [mlir][Vector] Fold ShuffleOp if result is identical to one of source vectors.
For example, we could do the following eliminations:
  fold vector.shuffle V1, V2, [0, 1, 2, 3] : <4xi32>, <2xi32> -> V1
  fold vector.shuffle V1, V2, [4, 5] : <4xi32>, <2xi32> -> V2

Differential Revision: https://reviews.llvm.org/D122706
2022-03-31 10:46:13 +08:00
Arjun P b97aa413d1 Revert "[MLIR][Presburger] LexSimplex::addEquality: add equalities as fixed columns"
This reverts commit 5630143af3. The
implementation in this commit was incorrect. Also, handling this representation
of equalities in the upcoming support for symbolic lexicographic minimization
makes that patch much more complex. It will be easier to review that without
this representaiton and then reintroduce the fixed column representation
later, hence the revert rather than a bug fix.
2022-03-30 23:26:05 +01:00
Nikita Popov ea043ea183 [MLIR] Avoid some pointer element type accesses
Determine the element type from the MLIR LLVMPointerType, rather
than the LLVM PointerType.
2022-03-30 10:00:51 +02:00
Shraiysh Vaishay 4d1010909f [mlir][OpenMP] Fix memory leak by deleting unused value
Reviewed By: ftynse, rriddle

Differential Revision: https://reviews.llvm.org/D122633
2022-03-30 03:25:53 +05:30
Benjamin Kramer 35dab904c0 [linalg] When removing noop linalg.generics, check that inserting a cast is valid
linalg.generic can also take scalars instead of tensors, which
tensor.cast doesn't support. We don't have an easy way to cast between
scalars and tensors so just keep the linalg.generic in those cases.

Differential Revision: https://reviews.llvm.org/D122575
2022-03-29 23:05:54 +02:00
Arjun P ef6f7c4a60 [MLIR][Presburger] Simplify std::{all,any}_of -> llvm::{all,any}_of (NFC)
Also simplify [](const F &f){ return f.foo(); } -> std::mem_fn(&F::foo)
2022-03-29 18:04:45 +01:00
Javier Setoain 7bc8ad5109 [mlir][vector][nfc] Rename index optimizations option
We are using "enable-index-optimizations" and "indexOptimizations" as
names for an optimization that consists of using i32 for indices within
a vector. For instance, when building a vector comparison for mask
generation. The name is confusing and suggests a scope beyond these
vector indices.  This change makes the function of the option explicit
in its name.

Differential Revision: https://reviews.llvm.org/D122415
2022-03-29 11:33:22 +01:00
Jacques Pienaar 0217d1178b [mlir] Fix leak in case of failed parse
A Block is optionally allocated & leaks in case of failed parse. Inline the
function and ensure Block gets freed unless parse is successful.

Differential Revision: https://reviews.llvm.org/D122112
2022-03-28 20:04:31 -07:00
lipracer 16ed79d569 [mlir] tosa: build error when building with clang
The change of https://reviews.llvm.org/D121513#3411651
has caused a build error when building with clang:

/mnt/vss/_work/1/llvm-project/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp:599:26: error: extra ';' outside of a function is incompatible with C++98 [-Werror,-Wc++98-compat-extra-semi]
ReduceFolder(ReduceAllOp);

Reviewed By: hpmorgan, Mogball

Differential Revision: https://reviews.llvm.org/D122599
2022-03-28 20:02:15 +00:00
Mogball 979ffe97b9 [mlir] Allow RegionRange to accept ArrayRef<Region *>
Adds another pointer to the union in RegionRange to allow RegionRange to work on ArrayRef<Region *> (i.e. vectors of Region *).

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D122514
2022-03-28 19:39:42 +00:00
Mogball b73f1d2c5d [mlir][cf-sink] Accept a callback for sinking operations
(This was a TODO from the initial patch).

The control-flow sink utility accepts a callback that is used to sink an operation into a region.
The `moveIntoRegion` is called on the same operation and region that return true for `shouldMoveIntoRegion`.
The callback must preserve the dominance of the operation within the region. In the default control-flow
sink implementation, this is moving the operation to the start of the entry block.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D122445
2022-03-28 19:31:23 +00:00
Jacques Pienaar 7c38fd605b [mlir] Flip Vector dialect accessors used to prefixed form.
This has been on _Both for a couple of weeks. Flip usages in core with
intention to flip flag to _Prefixed in follow up. Needed to add a couple
of helper methods in AffineOps and Linalg to facilitate a pure flag flip
in follow up as some of these classes are used in templates and so
sensitive to Vector dialect changes.

Differential Revision: https://reviews.llvm.org/D122151
2022-03-28 11:24:47 -07:00
Mogball e51652f9bf [mlir] Simplify LoopLikeOpInterface
- Adds default implementations of `isDefinedOutsideOfLoop` and `moveOutOfLoop` since 99% of all implementations of these functions were identical
- `moveOutOfLoop` takes one operation and doesn't return anything anymore. 100% of all implementations of this function would always return `success` and uses would either respond with a pass failure or an `llvm_unreachable`.
2022-03-28 18:10:04 +00:00
Marius Brehler c5c9d6e0d5 [mlir][emitc] Adapt to move of FuncOp
Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D122305
2022-03-28 17:44:47 +02:00
Markus Böck a7865228b3 [mlir][NFC] Fix codestyle issues introduced in D121988
These were noticed in the post commit review of https://reviews.llvm.org/D121988
2022-03-28 16:55:01 +02:00
gysit d26c42af57 [mlir][linalg] Control dimensions to pad.
This revision supports padding only a subset of the iteration dimensions via an additional padding-dimensions parameter. This control allows us to pad an operation in multiple steps. For example, one may want to pad only the output dimensions of a producer matmul fused into a consumer loop nest, before tiling and padding its reduction dimension.

Depends On D122309

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D122560
2022-03-28 14:39:57 +00:00
Dominik Grewe 774818c09c Expose MlirOperationClone in Python bindings.
Expose MlirOperationClone in Python bindings.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D122526
2022-03-28 15:58:22 +02:00
gysit 58d0da885e [mlir][linalg] Use arrays to pass padding options.
Pass the padding options using arrays instead of lambdas. In particular pass the padding value as string and use the argument parser to create the padding value. Arrays are a more natural choice that matches the current use cases and avoids converting arrays to lambdas.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D122309
2022-03-28 13:49:05 +00:00
Shraiysh Vaishay fcbf00f098 [mlir][OpenMP] Added ReductionClauseInterface
This patch adds the ReductionClauseInterface and also adds reduction
support for `omp.parallel` operation.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D122402
2022-03-28 14:24:28 +05:30
xndcn c0ccb69228 [mlir][spirv] Convert func.call to spv.FunctionCall
Differential Revision: https://reviews.llvm.org/D122368
2022-03-26 19:21:23 +08:00
Uday Bondhugula 5576579c86 Update affine.load folding hook to fold global splat constant loads
Enhance affine.load folding hook to fold loads on global splat constant
memrefs.

Differential Revision: https://reviews.llvm.org/D122292
2022-03-26 06:44:03 +05:30
Christopher Bate 3be7c28917 [mlir][NVVM] Add support for nvvm mma.sync ops
This patch adds MLIR NVVM support for the various NVPTX `mma.sync`
operations. There are a number of possible data type, shape,
and other attribute combinations supported by the operation, so a
custom assebmly format is added and attributes are inferred where
possible.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D122410
2022-03-25 17:28:05 +00:00
lipracer 5161835d5a [mlir][tosa] : adding folder and canonicalizer for select
define canonicalizer and folder for tosa::select

Reviewed By: mehdi_amini, Mogball

Differential Revision: https://reviews.llvm.org/D121513
2022-03-25 16:50:29 +00:00
Benjamin Kramer 12bd1ef37c [bazel] Add missing dependency after a75a46db89 2022-03-25 12:02:36 +01:00
Javier Setoain 7783a178f5 [mlir][Sparse] Add option for VLA sparsification
Use "enable-vla-vectorization=vla" to generate a vector length agnostic
loops during vectorization. This option works for vectorization strategy 2.

Differential Revision: https://reviews.llvm.org/D118379
2022-03-25 10:54:49 +00:00
Javier Setoain a75a46db89 [mlir][Vector] Enable create_mask for scalable vectors
The way vector.create_mask is currently lowered is
vector-length-dependent, and therefore incompatible with scalable vector
types. This patch adds an alternative lowering path for create_mask
operations that return a scalable vector mask.

Differential Revision: https://reviews.llvm.org/D118248
2022-03-25 10:48:59 +00:00
Thomas Raoux d77f483640 [mlir][gpu] Relax restriction on mma load/store op
Those ops can support more complex layout as long as the most inner
dimension is contiguous.

Differential Revision: https://reviews.llvm.org/D122452
2022-03-25 04:03:40 +00:00
Groverkss fcbe64ddb8 [MLIR][Presburger] Merge PresburgerLocalSpace and PresburgerSpace
This patch is a cleanup patch that merges PresburgerLocalSpace and
PresburgerSpace. Asserting that there are no locals is shifted to the
users of PresburgerSpace themselves.

The reasoning for this patch is that PresburgerLocalSpace did not contribute
much and only introduced additional complexity as locals could still be present
in PresburgerSpace, just not writable. This could introduce problems if a
PresburgerSpace with locals was copied to PresburgerLocalSpace which expected
no locals in a PresburgerSpace.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D122353
2022-03-25 05:36:32 +05:30
Thomas Raoux 33d2a780a1 [mlir][linalg] Add pattern to split reduction dimension in a linalg op
This transformation allow to break up a reduction dimension in a
parallel and a reduction dimension. This is followed by a separate
reduction op. This allows to generate tree reduction which is beneficial
on target allowing to take advantage parallelism.

Differential Revision: https://reviews.llvm.org/D122045
2022-03-24 23:22:53 +00:00
Shraiysh Vaishay 8722c12c12 [mlir][OpenMP][IRBuilder] Add support for nowait on single construct
This patch adds the nowait parameter to `createSingle` in
OpenMPIRBuilder and handling for IR generation from OpenMP Dialect.

Also added tests for the same.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D122371
2022-03-24 22:51:52 +05:30
gysit b1b57f8104 [mlir][linalg] Support padding LinalgOps in use-def chain.
Previously, only LinalgOps whose operands are defined by an ExtractSliceOp could be padded. The revision supports walking a use-def chain of LinalgOps to find an ExtractSliceOp.

Reviewed By: hanchung

Differential Revision: https://reviews.llvm.org/D122116
2022-03-24 10:44:44 +00:00
gysit 53f7fb0a87 [mlir][linalg] Do not fuse shape-only producers.
This revision introduces a heuristic to stop fusion for shape-only tensors. A shape-only tensor only defines the shape of the consumer computation while the data is not used. Pure producer consumer fusion thus shall not fuse the producer of a shape-only tensor. In particular, since the shape-only tensor will have other uses that actually consume the data.

The revision enables fusion for consumers that have two uses of the same tensor. One as input operand and one as shape-only output operand. In these cases, we want to fuse only the input operand and avoid output fusion via iteration argument.

Reviewed By: hanchung

Differential Revision: https://reviews.llvm.org/D120981
2022-03-24 10:22:41 +00:00
gysit b257dba58e [mlir][linalg] Create AffineMinOp map in canoncial form.
Create the AffineMinOp used to compute the padding width in canonical form and update the tests.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D122311
2022-03-24 06:55:59 +00:00
Shraiysh Vaishay 3c0d470865 [mlir][OpenMP] omp.single translation to LLVM IR
This patch adds translation from omp.single to LLVM IR.

Depends on D122288

Reviewed By: ftynse, kiranchandramohan

Differential Revision: https://reviews.llvm.org/D122297
2022-03-24 10:07:30 +05:30
Arjun P 30c0a14846 [MLIR][Presburger] Matrix::insertColumns: add doc, fix lint issue, and early exit when possible
Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122137
2022-03-24 00:42:55 +00:00
Arjun P 4418669f1e [MLIR][Presburger] PWMAFunction::valueAt: support local ids
Add a baseline implementation of support for local ids for `PWMAFunction::valueAt`. This can be made more efficient later if needed by handling locals with known div representations separately.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122144
2022-03-24 00:42:21 +00:00
Arjun P 5630143af3 [MLIR][Presburger] LexSimplex::addEquality: add equalities as fixed columns
In LexSimplex, instead of adding equalities as a pair of inequalities,
add them as a single row, move them into the basis, and keep them there.

There will always be a valid basis involving all non-redundant equalities. Such
equalities will then be ignored in some other operations, such as when looking
for pivot columns. This speeds them up a little bit.

More importantly, this is an important precursor patch to adding support for
symbolic integer lexmin, as this heuristic can sometimes make a big difference there.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122165
2022-03-24 00:41:17 +00:00
Arjun P 08543a5a47 [MLIR][Presburger] Introduce SimplexRollbackScopeExit to rollback on scope exit
This simplifies many places where we just want to do something in a "transient context"
and return some value.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122172
2022-03-24 00:27:47 +00:00
Arjun P 93b9f50b4c [MLIR][Presburger] IntegerRelation: implement partial rollback support
It is often necessary to "rollback" IntegerRelations to an earlier state. Although providing full rollback support is non-trivial, we really only need to support the case where the only changes made are to append ids or append constraints, and then rollback these additions. This patch adds support to rollback in such situations by recording the number of ids and constraints of each kind and providing support to truncate the IntegerRelation to those counts by removing appended ids and constraints. This already simplifies subtraction a little bit and will also be useful in the implementation of symbolic integer lexmin.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122178
2022-03-24 00:27:21 +00:00
Chia-hung Duan 14ecafd0bd [mlir] Make OpBuilder::createOperation to accept raw inputs
This provides a way to create an operation without manipulating
OperationState directly. This is useful for creating unregistered ops.

Reviewed By: rriddle, mehdi_amini

Differential Revision: https://reviews.llvm.org/D120787
2022-03-23 22:13:48 +00:00
Mogball 7c72f55ea8 [mlir] Fix emitting an error at EOF
Emitting at error at EOF will emit the diagnostic past the end of the file. When emitting an error during parsing at EOF, emit it at the previous character.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D122295
2022-03-23 20:23:01 +00:00
Nathaniel McVicar 4907cfe2cb [mlir][MemRef] Fix warning on unsigned comparison
Fix warning in clang introduced in D121766.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D122333
2022-03-23 12:47:04 -07:00
wren romano ebc8466481 [mlir][sparse] Adding {pointer,index}OverheadTypeEncoding
Work towards: https://github.com/llvm/llvm-project/issues/51652

The new functions fill the gap between `overheadTypeEncoding` and `get{Pointer,Index}OverheadType`.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D122056
2022-03-23 12:04:47 -07:00
Matthias Springer 3b74aac29c [mlir][bufferize] Do not run the buffer deallocation pass if no allocs escape block boundaries
This fixes a bufferization issue with ops that are not supported by the buffer deallocation pass when `allow-return-allocs=0`.

Differential Revision: https://reviews.llvm.org/D122304
2022-03-23 21:07:35 +09:00
Shraiysh Vaishay 11ed2d4acd [mlir][OpenMP] Add omp.single
This patch adds omp.single according to Section 2.8.2 of OpenMP 5.0.

Also added tests for the same.

Reviewed By: peixin

Differential Revision: https://reviews.llvm.org/D122288

Co-authored-by: Kiran Kumar T P <kirankumar.tp@amd.com>
2022-03-23 16:45:27 +05:30
Arjun P 87cffeb635 [MLIR][Presburger] support IntegerRelation::convertIdKind
Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122154
2022-03-23 11:12:08 +00:00
Arjun P ff44760427 [MLIR][Presburger] add Simplex:addDivisionVariable
This is a convenience function for adding new divisions to the Simplex given the numerator and denominator.

This will be needed for symbolic integer lexmin support.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122159
2022-03-23 10:53:32 +00:00