Commit Graph

5900 Commits

Author SHA1 Message Date
Matthias Springer 190f385b7d [mlir][linalg] Implement RegionBranchOpInterface and fix memory effects
* Implement RegionBranchOpInterface: The op has a region, but it is conceptually not entered. The region just describes the semantics of the (monolithic) op.
* Linalg structured ops do not allocate memory.

Differential Revision: https://reviews.llvm.org/D121798
2022-03-16 22:42:08 +09:00
Matthias Springer 75c1d91554 [mlir][SCF] Implement RegionBranchOpInterface on ExecuteRegionOp
This is needed for the BufferDeallocation pass.

Differential Revision: https://reviews.llvm.org/D121526
2022-03-16 19:55:10 +09:00
Matthias Springer 855a11ee68 [mlir][bufferize][NFC] Rename allow-return-memref to allow-return-allocs
Also clean up/split test cases.

Differential Revision: https://reviews.llvm.org/D121522
2022-03-16 19:50:39 +09:00
Matthias Springer 9e24f0f458 [mlir][bufferize] Do not deallocate allocs that are returned from a block
Such IR is rejected by default, but can be allowed with `allow-return-memref`. In preparation of future refactorings, do not deallocate such buffers.

One-Shot Analysis now gathers information about yielded tensors, so that we know during the actual bufferization whether a newly allocated buffer should be deallocated again. (Otherwise, it will leak. This will be addressed in a subsequent commit that also makes `allow-return-memref` a non-experimental flag.)

As a cleanup, `allow-return-memref` is now part of OneShotBufferizationOptions. (It was previously ignored by AlwaysCopyBufferizationState.) Moreover, AlwaysCopyBufferizationState now asserts that `create-deallocs` is deactivated to prevent surprising behavior.

Differential Revision: https://reviews.llvm.org/D121521
2022-03-16 18:59:27 +09:00
Matthias Springer fdb41a22ac [mlir][tensor] Implement ReifyRankedShapedTypeOpInterface on GenerateOp
Differential Revision: https://reviews.llvm.org/D121520
2022-03-16 18:59:27 +09:00
River Riddle 3c405c3b9b [mlir:PDLInterp][NFC] Switch to using prefixed accessors
PDLInterp is effectively an internal dialect, so there isn't a need to
stage the switch.
2022-03-15 17:36:36 -07:00
River Riddle f96a8675cd [mlir][PDL] Define a new PDLInterp::FuncOp operation and drop uses of FuncOp
Defining our own function operation allows for the PDL interpreter
to be more self contained, and also removes any dependency on FuncOp;
which is moving out of the Builtin dialect.

Differential Revision: https://reviews.llvm.org/D121253
2022-03-15 14:55:51 -07:00
Sam Carroll 541d89b02c [mlir] Fix --convert-func-to-llvm=emit-c-wrappers argument and result attribute handling
When using `--convert-func-to-llvm=emit-c-wrappers` the attribute arguments of the wrapper would not be created correctly in some cases.
This patch fixes that and introduces a set of tests for (hopefully) all corner cases.

See https://github.com/llvm/llvm-project/issues/53503

Author: Sam Carroll <sam.carroll@lmns.com>
Co-Author: Laszlo Kindrat <laszlo.kindrat@lmns.com>

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D119895
2022-03-15 15:29:43 +01:00
Arnamoy Bhattacharyya 0e9198c3e9 [MLIR][OpenMP] Add support for basic SIMD construct
Patch adds a new operation for the SIMD construct.  The op is designed to be very similar to the existing `wsloop` operation, so that the `CanonicalLoopInfo` of `OpenMPIRBuilder` can be used.

Reviewed By: shraiysh

Differential Revision: https://reviews.llvm.org/D118065
2022-03-15 09:41:04 -04:00
Matthias Springer 39ec46bd83 [mlir][bufferize] Extract buffer hoisting into separate function
This improves the modularity of the bufferization.

From now on, all ops that do not implement BufferizableOpInterface are considered hoisting barriers. Previously, all ops that do not implement the interface were not considered barriers and such ops had to be marked as barriers explicitly. This was unsafe because we could've hoisted across unknown ops where it was not safe to hoist.

As a side effect, this allows for cleaning up AffineBufferizableOpInterfaceImpl. This build unit no longer needed and can be deleted.

Differential Revision: https://reviews.llvm.org/D121519
2022-03-15 21:25:03 +09:00
Ivan Butygin 9f864a5447 [mlir][gpu] Introduce gpu.global_id op
Introduce OpenCL-style global_id op and corresponding spirv lowering.

Differential Revision: https://reviews.llvm.org/D121548
2022-03-15 13:25:50 +03:00
Ivan Butygin 7b0e041df8 [mlir][spirv] Add AssumeTrueKHROp
Differential Revision: https://reviews.llvm.org/D121601
2022-03-15 13:03:45 +03:00
Matthias Springer 05e0495f1d [mlir][bufferize][NFC] Deallocate all buffers at the end of bufferization
This makes bufferization more modular. This is in preparation of future refactorings.

Differential Revision: https://reviews.llvm.org/D121362
2022-03-15 17:53:53 +09:00
Matthias Springer 9597b16aa9 [mlir][bufferize][NFC] Split BufferizationState into AnalysisState/BufferizationState
Differential Revision: https://reviews.llvm.org/D121361
2022-03-15 17:35:47 +09:00
River Riddle bbfec2a1b0 [mlir] Remove the deprecated ODS Op verifier/parser/printer code blocks
These have been deprecated for ~1 month now and can be removed.

Differential Revision: https://reviews.llvm.org/D121090
2022-03-15 01:17:30 -07:00
River Riddle 23e3cbe24a [mlir] Refactor how parser/printers are specified for AttrDef/TypeDef
There is currently an awkwardly complex set of rules for how a
parser/printer is generated for AttrDef/TypeDef. It can change depending on if a
mnemonic was specified, if there are parameters, if using the assemblyFormat, if
individual parser/printer code blocks were specified, etc. This commit refactors
this to make what the attribute/type wants more explicit, and to better align
with how formats are specified for operations.

Firstly, the parser/printer code blocks are removed in favor of a
`hasCustomAssemblyFormat` bit field. This aligns with the operation format
specification (and is nice to remove code blocks from ODS).

This commit also adds a requirement to explicitly set `assemblyFormat` or
`hasCustomAssemblyFormat` when the mnemonic is set and the attr/type
has no parameters. This removes the weird implicit matrix of behavior,
and also encourages the author to make a conscious choice of either C++
or declarative format instead of implicitly opting them into the C++
format (we should be pushing towards declarative when possible).

Differential Revision: https://reviews.llvm.org/D121505
2022-03-15 00:42:31 -07:00
River Riddle 1d7120c69a [mlir] Split out AttrDef/TypeDef and pattern constructs from OpBase.td
OpBase.td has formed into a huge monolith of all ODS constructs. This
commits starts to rectify that by splitting out some constructs to their
own .td files.

Differential Revision: https://reviews.llvm.org/D118636
2022-03-15 00:18:03 -07:00
Chris Lattner 2ef95efb41 Revert "[mlirTranslateMain] Add a customization callback."
This reverts commit f18d6af7e9.
This patch is a more controversial than I expected, it is
better to revert while the discussion continues.  xref this
thread:
https://discourse.llvm.org/t/doc-mlir-translate-mlir-opt/60751/

xref this phab patch: https://reviews.llvm.org/D120970

Differential Revision: https://reviews.llvm.org/D121668
2022-03-14 22:04:46 -07:00
Matthias Springer de5022c7d7 [mlir][vector] Implement unrolling of ReductionOp
Differential Revision: https://reviews.llvm.org/D121597
2022-03-15 01:21:24 +09:00
Thomas Raoux f69175b1e6 [mlir][vector] Add unrolling pattern for multidim_reduce op
Implement the vectorLoopUnroll interface for MultiDimReduceOp and add a
pattern to do the unrolling following the same interface other vector
unroll patterns.

Differential Revision: https://reviews.llvm.org/D121263
2022-03-14 15:22:24 +00:00
gysit 7294be2b8e [mlir][linalg] Replace linalg.fill by OpDSL variant.
The revision removes the linalg.fill operation and renames the OpDSL generated linalg.fill_tensor operation to replace it. After the change, all named structured operations are defined via OpDSL and there are no handwritten operations left.

A side-effect of the change is that the pretty printed form changes from:
```
%1 = linalg.fill(%cst, %0) : f32, tensor<?x?xf32> -> tensor<?x?xf32>
```
changes to
```
%1 = linalg.fill ins(%cst : f32) outs(%0 : tensor<?x?xf32>) -> tensor<?x?xf32>
```
Additionally, the builder signature now takes input and output value ranges as it is the case for all other OpDSL operations:
```
rewriter.create<linalg::FillOp>(loc, val, output)
```
changes to
```
rewriter.create<linalg::FillOp>(loc, ValueRange{val}, ValueRange{output})
```
All other changes remain minimal. In particular, the canonicalization patterns are the same and the `value()`, `output()`, and `result()` methods are now implemented by the FillOpInterface.

Depends On D120726

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D120728
2022-03-14 10:51:08 +00:00
Groverkss 852a3f969e [MLIR][Presburger][NFC] Fix doc for PresburgerSpace::numLocals 2022-03-13 20:04:23 +05:30
Christian Sigg 732c39fa3b [MLIR][NFC] Fix deprecation message. 2022-03-13 14:17:46 +01:00
Groverkss ff1d9a4b97 [MLIR][Presburger] Add support for PresburgerRelation
This patch adds supports for union of relations (PresburgerRelation).  Along
with this, support for PresburgerSet is also maintained.

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

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D121417
2022-03-13 17:31:19 +05:30
Chris Lattner f18d6af7e9 [mlirTranslateMain] Add a customization callback.
mlir-translate and related tools currently have a fixed set
of flags that are built into Translation.cpp.  This works for
simple cases, but some clients want to change the default
globally (e.g. default to allowing unregistered dialects
without a command line flag), or support dialect-independent
translations without having those translations register every
conceivable dialect they could be used with (breaking
modularity).

This approach could also be applied to mlirOptMain to reduce
the significant number of flags it has accumulated.

Differential Revision: https://reviews.llvm.org/D120970
2022-03-12 13:18:31 -08:00
Jacques Pienaar a547028d46 [mlir] Update function referenced in comment (NFC) 2022-03-11 16:36:47 -08:00
Ivan Butygin 4df9544108 [mlir][spirv] Make EntryPointABIAttr.local_size optional
* It doesn't required by OpenCL/Intel Level Zero and can be set programmatically.
* Add GPU to spirv lowering in case when attribute is not present.
* Set higher benefit to WorkGroupSizeConversion pattern so it will always try to lower first from the attribute.

Differential Revision: https://reviews.llvm.org/D120399
2022-03-11 22:25:23 +03:00
Ivan Butygin f3676c3273 [mlir][memref] memref.reinterpret_cast folding
* reinterpret_cast(reinterpret_cast(x)) -> reinterpret_cast(x)
* reinterpret_cast(cast(x)) -> reinterpret_cast(x)
* reinterpret_cast(subview(x)) -> reinterpret_cast(x) if subview offsets are 0

Differential Revision: https://reviews.llvm.org/D120242
2022-03-11 21:22:43 +03:00
Chia-hung Duan ed645f6336 [mlir] Support verification order (3/3)
In this CL, update the function name of verifier according to the
behavior. If a verifier needs to access the region then it'll be updated
to `verifyRegions`.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D120373
2022-03-11 01:16:28 +00:00
Diego Caballero f71f9958b9 [mlir][Vector] Modernize default lowering of vector transpose
This patch removes an old recursive implementation to lower vector.transpose to extract/insert operations
and replaces it with a iterative approach that leverages newer linearization/delinearization utilities.
The patch should be NFC except by the order in which the extract/insert ops are generated.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D121321
2022-03-10 22:33:14 +00:00
Thomas Raoux 2f33f11428 [mlir][NVVM] Add ldmatrix op to NVVM dialect
Differential Revision: https://reviews.llvm.org/D121347
2022-03-10 20:37:17 +00:00
Bixia Zheng 13d3307176 [mlir][linalg] Add a few unary operations.
Add operations abs, ceil, floor, and neg to the C++ API and Python API.

Add test cases.

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D121339
2022-03-10 09:38:58 -08:00
Groverkss 58966dd42b [MLIR][Presburger] Remove `spaceKind` from PresburgerSpace
This patch remove `spaceKind` from PresburgerSpace, making PresburgerSpace only
a space supporting relations.

Sets are still implemented in the same way, i.e. with a zero domain but instead
the asserts to check if the space is still set are added to users of
PresburgerSpace which treat it as a Set space.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D121357
2022-03-10 22:20:44 +05:30
Emilio Cota b24de9f684 [mlir] ExecutionEngine: default enableObjectCache to false
The enableObjectCache option was added in
https://reviews.llvm.org/rG06e8101034e, defaulting to false. However,
the init code added there got its logic reversed
(cache(enableObjectCache ? nullptr : new SimpleObjectCache()), which was
fixed in https://reviews.llvm.org/rGd1186fcb04 by setting the default to
true, thereby preserving the existing behavior even if it was
unintentional.

Default now the object cache to false as it was originally intended.
While at it, mention in enableObjectCache's documentation how the
cache can be dumped.

Reviewed-by: mehdi_amini
Differential Revision: https://reviews.llvm.org/D121291
2022-03-10 11:24:48 -05:00
Shraiysh Vaishay 6dd54da5a5 [OpenMP][mlir] Lowering for omp.atomic.update
This patch adds lowering from omp.atomic.update to LLVM IR. Whenever a
special LLVM IR instruction is available for the operation, `atomicrmw`
instruction is emitted, otherwise a compare-exchange loop based update
is emitted.

Depends on D119522

Reviewed By: ftynse, peixin

Differential Revision: https://reviews.llvm.org/D119657
2022-03-10 18:28:51 +05:30
Groverkss c896e6540a [MLIR][Presburger] Use IdKind for removeIdRange in PresburgerSpace
This patch moves PresburgerSpace::removeIdRange(idStart, idLimit) to
PresburgerSpace::removeIdRange(kind, idStart, idLimit), i.e. identifiers
can only be removed at once for a single kind.

This makes users of PresburgerSpace to not assume any inside ordering of
identifier kinds.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D121079
2022-03-10 15:39:32 +05:30
Uday Bondhugula af9f7d319b NFC. Clean up memref utils library
NFC. Clean up memref utils library. This library had a single function
that was completely misplaced. MemRefUtils is expected to be (also per
its comment) a library providing analysis/transforms utilities on memref
dialect ops or memref types. However, in reality it had a helper that
was depended upon by the MemRef dialect, i.e., it was a helper for the
dialect ops library and couldn't contain anything that itself depends on
the MemRef dialect. Move the single method to the memref dialect that
will now allow actual utilities depending on the memref dialect to be
placed in it.

Put findDealloc in the `memref` namespace. This is a pure move.

Differential Revision: https://reviews.llvm.org/D121273
2022-03-09 16:00:39 +05:30
Chia-hung Duan fcd4ee52cd [mlir] Make ShapedTypeComponents contructible from ShapeAdaptor
ValueShapeRange::getShape() returns ShapeAdaptor rather than ShapedType
and ShapeAdaptor allows implicit conversion to bool. It ends up that
ShapedTypeComponents can be constructed with ShapeAdaptor incorrectly.
The reason is that the type trait
  std::is_constructible<ShapeStorageT, Arg>::value
is fulfilled because ShapeAdaptor can be converted to bool and it can be
used to construct ShapeStorageT. In the end, we won't give any warning
or error message when doing things like
  inferredReturnShapes.emplace_back(valueShapeRange.getShape(0));

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D120845
2022-03-09 03:35:24 +00:00
Aart Bik 53cc3a0637 [mlir][sparse] index support in sparse compiler codegen
This revision adds support for the linalg.index to the sparse compiler
pipeline. In essence, this adds the ability to refer to indices in
the tensor index expression, as illustrated below:

 Y[i, j, k, l, m] = T[i, j, k, l, m]  * i * j

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D121251
2022-03-08 17:25:36 -08:00
River Riddle 06057248c8 [mlir][NFC] Add various includes currently transitively found in
BuiltinOps.h

These includes are going to be removed from BuiltinOps.h in a followup
when FuncOp is moved out of the Builtin dialect. This commit
pre-emptively adds those includes to simplify the patch moving FuncOp.
2022-03-08 17:20:50 -08:00
Lei Zhang cfb9e474ae [mlir][spirv] Define spv.VectorTimesScalar op
Reviewed By: hanchung

Differential Revision: https://reviews.llvm.org/D121247
2022-03-08 15:58:31 -05:00
Lei Zhang f8fb2aff70 [mlir][spirv] Fix spv.GLSL.{S|U}Clamp type checking
It's fine to use any integer (vector) values regardless of the
signedness. The opcode decides how to interpret the bits.

Reviewed By: hanchung

Differential Revision: https://reviews.llvm.org/D121238
2022-03-08 15:56:37 -05:00
River Riddle 7ea8c65369 [mlir][MemRef] Change memref-expand to be a generic operation pass
This pass doesn't rely on any specific characteristics of FuncOp, and
can just be a generic operation pass.

Differential Revision: https://reviews.llvm.org/D121193
2022-03-08 12:25:32 -08:00
River Riddle f05b0afa79 [mlir] Change ComplexToLLVM to be a generic pass
It is currently a module pass, but shouldn't be. All of the patterns
are local conversions, and don't require anything about
functions/modules.

Differential Revision: https://reviews.llvm.org/D121192
2022-03-08 12:25:32 -08:00
River Riddle 47f175b09b [mlir] Update FuncOp conversion passes to Pass/InterfacePass<FunctionOpInterface>
These passes generally don't rely on any special aspects of FuncOp, and moving allows
for these passes to be used in many more situations. The passes that obviously weren't
relying on invariants guaranteed by a "function" were updated to be generic pass, the
rest were updated to be FunctionOpinterface InterfacePasses.

The test updates are NFC switching from implicit nesting (-pass -pass2) form to
the -pass-pipeline form (generic passes do not implicitly nest as op-specific passes do).

Differential Revision: https://reviews.llvm.org/D121190
2022-03-08 12:25:32 -08:00
River Riddle f8d5c73c82 [mlir][NFC] Update the Builtin dialect to use "Both" accessors
Differential Revision: https://reviews.llvm.org/D121189
2022-03-08 12:25:32 -08:00
River Riddle 171850c55a [mlir][Vector] Drop use of FuncOp in transferOpflowOpt
FuncOp isn't really important to hardcode here, it is only used to act
as a root operation for the transformation.

Differential Revision: https://reviews.llvm.org/D121195
2022-03-08 12:25:32 -08:00
River Riddle 87d6bf3728 [mlir][test] Generalize a bunch of FuncOp based passes to run on any operation/interfaces
A lot of test passes are currently anchored on FuncOp, but this
dependency
is generally just historical. A majority of these test passes can run on
any operation, or can operate on a specific interface
(FunctionOpInterface/SymbolOpInterface).
This allows for greatly reducing the API dependency on FuncOp, which
is slated to be moved out of the Builtin dialect.

Differential Revision: https://reviews.llvm.org/D121191
2022-03-08 12:25:32 -08:00
Lei Zhang 86fe16b67d [mlir][spirv] NFC: Move GLSL canonicalization pass to Transforms/
This is a pass that can be used by downstream consumers directly
to avoid the boilerplate to wrap around the `populate*Patterns`.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D121222
2022-03-08 13:49:14 -05:00
Mahesh Ravishankar 589eac6524 [mlir] Add canonicalizations for op -> tensor.cast folding.
A `tensor.cast` consumer can be folded with its producer. This is
beneficial only if the result of the tensor cast is more static than
the source. This patch adds a utility function to check that this is
the case, and adds a couple of canonicalizations patterns that fold an
operation with `tensor.cast` conusmers.

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D120950
2022-03-08 18:26:55 +00:00
Chia-hung Duan 60d719b462 [mlir] Check nullity of MixedContainerType and TypedArrayAttrBase
It's valid to create a TypedArrayAttr or MixedContainerType with
    nullptr, e.g.,
      std::vector<mlir::Attribute> attrs = {mlir::StringAttr()};
      builder.createArrayAttr(attrs);

    The predicate didn't check if it's a nullptr and it ended up a crash in
    the attribute static verifier. We always check if an attribute is null
    so it's better to align the check for these two container type attr.

Reviewed By: rdzhabarov

Differential Revision: https://reviews.llvm.org/D121178
2022-03-08 18:10:55 +00:00
Nicolas Vasilache eb6a3c0c0c [mlir][Linalg] Add a polymorphic linalg.copy operation
With the recent improvements to OpDSL it is cheap to reintroduce a linalg.copy operation.

This operation is needed in at least 2 cases:
  1. for copies that may want to change the elemental type (e.g. cast, truncate, quantize, etc)
  2. to specify new tensors that should bufferize to a copy operation. The linalg.generic form
     always folds away which is not always the right call.

Differential Revision: https://reviews.llvm.org/D121230
2022-03-08 12:52:51 -05:00
gysit 3231b6d3a2 [mlir][OpDSL] Remove unused SoftPlus2DOp operation.
The revision removes the SoftPlus2DOp operation that previously served as a test operation. It has been replaced by the elemwise_unary operation, which is now used to test unary log and exp functions.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D120794
2022-03-08 17:25:29 +00:00
gysit d629645fcd [mlir][OpDSL] Add support for adding canonicalization patterns.
Extend OpDSL with a `defines` method that can set the `hasCanonicalizer` flag for an OpDSL operation. If the flag is set via `defines(Canonicalizer)` the operation needs to implement the `getCanonicalizationPatterns` method. The revision specifies the flag for linalg.fill_tensor and adds an empty `FillTensorOp::getCanonicalizationPatterns` implementation.

This revision is a preparation step to replace linalg.fill by its OpDSL counterpart linalg.fill_tensor. The two are only functionally equivalent if both specify the same canonicalization patterns. The revision is thus a prerequisite for the linalg.fill replacement.

Depends On D120725

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D120726
2022-03-08 15:56:59 +00:00
gysit 8d7850705c [mlir][linalg] Add returning rewrite method to fusion pattern (NFC).
Enhance `LinalgTileAndFuseTensorOpsPattern` with an additional rewrite signature that returns the result of the rewrite.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D121212
2022-03-08 15:50:28 +00:00
gysit f4ae02afe7 [mlir][linalg] Add a FillOpInterface.
Add a FillOpInterface similar to the contraction and convolution op interfaces. The FillOpInterface is a preparation step to replace linalg.fill by its OpDSL version linalg.fill_tensor. The interface implements the `value()`, `output()`, and `result()` methods that by default are not available on linalg.fill_tensor.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D120725
2022-03-08 15:48:02 +00:00
Groverkss 802fc8cb53 [MLIR][Presburger] Move PresburgerLocalSpace::isEqual from protected to public
This change is done to match the interface of PresburgerSpace, which has
PresburgerSpace::isEqual as public.
2022-03-08 14:22:35 +05:30
River Riddle 043f4e3b33 [mlir][NFC] Remove dead forward declaration of FuncOp 2022-03-08 00:08:39 -08:00
Groverkss abc2c2309a [MLIR][Presburger][NFC] Cleanup PresburgerSet
This patch cleans up the interface to PresburgerSet. At a high level it does
the following changes:

  - Move member functions around to have constructors at top and print/dump
    at end.
  - Move a private function to be a static function instead.
  - Change member functions of type "getAllIntegerPolyhedron" to "getAllPolys"
    instead.
  - Improve documentation for PresburgerSet.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D121027
2022-03-08 03:02:12 +05:30
River Riddle a0b4aaffac [mlir][NFC] Remove FuncOp overload of NestedPattern::match
This method is redundant with the Operation* overload, and is an artifact of when
FuncOp wasn't an operation.
2022-03-07 11:25:23 -08:00
River Riddle b04c87cf08 [mlir][NFC] Drop a few dead forward declarations of FuncOp 2022-03-07 11:25:23 -08:00
River Riddle 5a7b919409 [mlir][NFC] Rename StandardToLLVM to FuncToLLVM
The current StandardToLLVM conversion patterns only really handle
the Func dialect. The pass itself adds patterns for Arithmetic/CFToLLVM, but
those should be/will be split out in a followup. This commit focuses solely
on being an NFC rename.

Aside from the directory change, the pattern and pass creation API have been renamed:
 * populateStdToLLVMFuncOpConversionPattern -> populateFuncToLLVMFuncOpConversionPattern
 * populateStdToLLVMConversionPatterns -> populateFuncToLLVMConversionPatterns
 * createLowerToLLVMPass -> createConvertFuncToLLVMPass

Differential Revision: https://reviews.llvm.org/D120778
2022-03-07 11:25:23 -08:00
Sergei Grechanik 27df7158fe [mlir] Fix dumping invalid ops
This patch fixes the crash when printing some ops (like affine.for and
scf.for) when they are dumped in invalid state, e.g. during pattern
application. Now the AsmState constructor verifies the operation
first and switches to generic operation printing when the verification
fails. Also operations are now printed in generic form when emitting
diagnostics and the severity level is Error.

Reviewed By: rriddle, mehdi_amini

Differential Revision: https://reviews.llvm.org/D117834
2022-03-07 08:32:31 -08:00
Matthias Springer 93e663273b [mlir][shape] Migrate bufferization to BufferizableOpInterface
Differential Revision: https://reviews.llvm.org/D121043
2022-03-07 21:54:27 +09:00
Mehdi Amini 51894cbb2e Apply clang-tidy fixes for performance-unnecessary-value-param to MLIR (NFC) 2022-03-07 10:41:45 +00:00
River Riddle ee1d447e5f [mlir][NFC] Move Translation.h to a Tools/mlir-translate directory
Translation.h is currently awkwardly shoved into the top-level mlir, even though it is
specific to the mlir-translate tool. This commit moves it to a new Tools/mlir-translate
directory, which is intended for libraries used to implement tools. It also splits the
translate registry from the main entry point, to more closely mirror what mlir-opt
does.

Differential Revision: https://reviews.llvm.org/D121026
2022-03-07 01:05:38 -08:00
River Riddle 6b7d211a1b [mlir][NFC] Move MlirOptMain to the Tools/ directory
MlirOptMain is currently awkwardly shoved into mlir/Support. This commit
moves it to the Tools/ directory, which is intended for libraries used to
implement tools.

Differential Revision: https://reviews.llvm.org/D121025
2022-03-07 01:05:38 -08:00
River Riddle 9eaff42360 [mlir][NFC] Move Parser.h to Parser/
There is no reason for this file to be at the top-level, and
its current placement predates the Parser/ folder's existence.

Differential Revision: https://reviews.llvm.org/D121024
2022-03-07 01:05:38 -08:00
Christian Sigg 0dc66b76fe [MLIR] Change call sites from deprecated `parseSourceFile()` to `parseSourceFile<ModuleOp>()`.
Mark `parseSourceFile()` deprecated. The functions will be removed two weeks after landing this change.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D121075
2022-03-07 06:49:38 +01:00
Michael Kruse fb75afd730 [mlir][support] Fix msvc build.
Add typename keyword to help the C++ parser to disambiguate dependent
qualified name after D120852/1c941d. Fixes the msvc build.
2022-03-06 16:59:23 -06:00
River Riddle 9c9a431735 [mlir][Pass] Add support for an InterfacePass and pass filtering based on OperationName
This commit adds a new hook Pass `bool canScheduleOn(RegisteredOperationName)` that
indicates if the given pass can be scheduled on operations of the given type. This makes it
easier to define constraints on generic passes without a) adding conditional checks to
the beginning of the `runOnOperation`, or b) defining a new pass type that forwards
from `runOnOperation` (after checking the invariants) to a new hook. This new hook is
used to implement an `InterfacePass` pass class, that represents a  generic pass that
runs on operations of the given interface type.

The PassManager will also verify that passes added to a pass manager can actually be
scheduled on that pass manager, meaning that we will properly error when an Interface
is scheduled on an operation that doesn't actually implement that interface.

Differential Revision: https://reviews.llvm.org/D120791
2022-03-04 15:14:04 -08:00
Mogball 210bdc651b [mlir] RegionBranchOpInterface should be verifyWithRegions 2022-03-04 22:25:25 +00:00
Mogball acf603b947 [mlir][ods] Save the Enum info in EnumAttr 2022-03-04 21:59:14 +00:00
Mogball e7c7b16a84 [mlir] Region/BranchOpInterface: Allow implicit type conversions along control-flow edges
RegionBranchOpInterface and BranchOpInterface are allowed to make implicit type conversions along control-flow edges. In effect, this adds an interface method, `areTypesCompatible`, to both interfaces, which should return whether the types of corresponding successor operands and block arguments are compatible. Users of the interfaces, here on forth, must be aware that types may mismatch, although current users (in MLIR core), are not affected by this change. By default, type equality is used.

`async.execute` already has unequal types along control-flow edges (`!async.value<f32>` vs. `f32`), but it opted out of calling `RegionBranchOpInterface::verifyTypes` in its verifier. That method has now been removed and `RegionBranchOpInterface` will verify types along control edges by default in its verifier.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D120790
2022-03-04 20:33:14 +00:00
Matthias Springer 6fc11d4d3e [mlir][bufferize] Add BufferizationState initializers
Such initializer functions can be enqueued in `BufferizationOptions`. They can be used to set up dialect-specific bufferization state.

Differential Revision: https://reviews.llvm.org/D120985
2022-03-05 05:20:11 +09:00
Uday Bondhugula 5a99b776eb [MLIR] Extend isLoopMemoryParallel to account for locally allocated memrefs
Extend isLoopMemoryParallel check to include locally allocated memrefs.
This strengthens and also speeds up the dependence check used by the
utility by excluding locally allocated memrefs where appropriate.

Additional memref dialect ops can be supported exhaustively via proper
interfaces.

Reviewed By: dcaballe

Differential Revision: https://reviews.llvm.org/D120617
2022-03-04 09:16:28 +05:30
William S. Moses ae5a70f2c2 [MLIR][OpenMP] Mark openmp.parallel and omp.wsloop as having recursive side effects
An OpenMP wsloop is simply a regular for loop with the bounds determined by the thread number, and the same justification to allow this for scf.for works for omp.wsloop.

An OpenMP parallel is a parallel for, per thread. Similarly the same justification for scf.parallel having recursive side effects applies here.

In both cases the general justification is that the ops themselves don't have side effects (besides inaccessible runtime-specific memory) and thus the side effects are simply that of the contained ops.

Reviewed By: bondhugula

Differential Revision: https://reviews.llvm.org/D120853
2022-03-03 22:37:24 -05:00
River Riddle 81f2f4dfb2 [PDLL] Add support for tablegen includes and importing ODS information
This commit adds support for processing tablegen include files, and importing
various information from ODS. This includes operations, attribute+type constraints,
attribute/operation/type interfaces, etc. This will allow for much more robust tooling,
and also allows for referencing ODS constructs directly within PDLL (imported interfaces
can be used as constraints, operation result names can be used for member access, etc).

Differential Revision: https://reviews.llvm.org/D119900
2022-03-03 16:14:03 -08:00
Michael Kruse 1c941d98f8 [mlir] Fix gcc -std=c++17 compilation.
Ensure that `Handler` within the class is interpreted as the as the current template instantiation (instead the class template itself).

Fixes #53447

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D120852
2022-03-03 09:03:36 -06:00
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 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
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
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
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
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
River Riddle 026fe5ffc3 [mlir][NFC] Remove several dead references to the old standard dialect 2022-03-01 14:02:24 -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
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
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
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
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
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
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
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 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 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
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
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
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
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
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
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
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
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
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
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
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
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 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
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
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
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