Commit Graph

10260 Commits

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

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

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

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

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

Fixes #53325

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

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

Fixes #52885

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

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

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

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

Reviewed By: dcaballe

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

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

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

Reviewed By: rriddle

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

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

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

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

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

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

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

Reviewed By: bkramer

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

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

Reviewed By: kiranchandramohan

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

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

Reviewed By: rriddle

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

Reviewed By: NatashaKnk

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

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

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

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

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

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

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

Reviewed By: bkramer

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

Reviewed By: peixin, kiranchandramohan

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

Reviewed By: rriddle, jpienaar

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

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

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

Differential Revision: https://reviews.llvm.org/D118062
2022-01-24 19:25:53 -08:00
River Riddle 88c1df64bd [mlir:ArmSVE][NFC] Remove dead code and unnecessary dependencies
Differential Revision: https://reviews.llvm.org/D117981
2022-01-24 19:25:53 -08:00
River Riddle a70aa7bb0d [mlir:Transforms] Move out the remaining non-dialect independent transforms and utilities
This has been a major TODO for a very long time, and is necessary for establishing a proper
dialect-free dependency layering for the Transforms library. Code was moved to effectively
two main locations:

* Affine/
There was quite a bit of affine dialect related code in Transforms/ do to historical reasons
(of a time way into MLIR's past). The following headers were moved to:
Transforms/LoopFusionUtils.h -> Dialect/Affine/LoopFusionUtils.h
Transforms/LoopUtils.h -> Dialect/Affine/LoopUtils.h
Transforms/Utils.h -> Dialect/Affine/Utils.h

The following transforms were also moved:
AffineLoopFusion, AffinePipelineDataTransfer, LoopCoalescing

* SCF/
Only one SCF pass was in Transforms/ (likely accidentally placed here): ParallelLoopCollapsing
The SCF specific utilities in LoopUtils have been moved to SCF/Utils.h

* Misc:
mlir::moveLoopInvariantCode was also moved to LoopLikeInterface.h given
that it is a simple utility defined in terms of LoopLikeOpInterface.

Differential Revision: https://reviews.llvm.org/D117848
2022-01-24 19:25:53 -08:00
River Riddle 2e2c0738e8 [mlir:Transforms] Move NormalizeMemRefs to MemRef/Transforms/
Transforms/  should only contain transformations that are dialect-independent and
this pass interacts with MemRef operations (making it a better fit for living in that
dialect).

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

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

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

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

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

Reviewed By: ThomasRaoux

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

Differential Revision: https://reviews.llvm.org/D118079
2022-01-24 17:41:09 -08:00
Rob Suderman 3e746c6d9e [mlir] Add support for ExpM1 to GLSL/OpenCL SPIRV Backends
Adding a similar decomposition for exponential minus one to the SPIRV
backends along with the necessary tests.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D118081
2022-01-24 15:38:34 -08:00
Mogball 3628febcf8 [mlir] NFC control-flow sink cleanup 2022-01-24 23:34:42 +00:00
Mogball 572fa9642c [mlir] Add a ControlFlowSink pass.
Control-Flow Sink moves operations whose only uses are in conditionally-executed regions into those regions so that paths in which their results are not needed do not perform unnecessary computation.

Depends on D115087

Reviewed By: jpienaar, rriddle, bondhugula

Differential Revision: https://reviews.llvm.org/D115088
2022-01-24 23:08:34 +00:00
Arjun P 0e98fadc79 [MLIR][Presburger] use braces for single-line loop when inner if uses braces [NFC] 2022-01-25 04:18:20 +05:30
Arjun P c1562683ee [MLIR][Presburger] LinearTransform: rename multiplication functions to be more intuitive 2022-01-25 04:18:19 +05:30
Rahul Joshi adb6494660 [MLIR] Add generic walk support to OpState
- This allows calling the generic walkers on specific operation instances.

Differential Revision: https://reviews.llvm.org/D117949
2022-01-24 13:35:29 -08:00
gysit e494278cee [mlir][linalg] Add transpose support to hoist padding.
Add a transpose option to hoist padding to transpose the padded tensor before storing it into the packed tensor. The early transpose improves the memory access patterns of the actual compute kernel. The patch introduces a transpose right after the hoisted pad tensor and a second transpose inside the compute loop. The second transpose can either be fused into the compute operation or will canonicalize away when lowering to vector instructions.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D117893
2022-01-24 16:33:05 +00:00
Matthias Springer b00ee46b5e [mlir][bufferize][NFC] Implement BufferizableOpInterface on bufferization ops directly
No longer go through an external model. Also put BufferizableOpInterface into the same build target as the BufferizationDialect. This allows for some code reuse between BufferizationOps canonicalizers and BufferizableOpInterface implementations.

Differential Revision: https://reviews.llvm.org/D117987
2022-01-25 01:23:26 +09:00
Lorenzo Chelini 217570b03b [MLIR][OpenMP] Suppress -Wreturn-type warnings (NFC) 2022-01-24 16:50:56 +01:00
Matthias Springer c30d2893a4 [mlir][bufferize] Change insertion point for ToTensorOps
Both insertion points are valid. This is to make BufferizableOpInteface-based bufferization compatible with existing partial bufferization test cases. (So less changes are necessary to unit tests.)

Differential Revision: https://reviews.llvm.org/D117986
2022-01-25 00:43:04 +09:00
Matthias Springer fc08d1c294 [mlir][tensor][bufferize] Support tensor.rank in BufferizableOpInterfaceImpl
This is the only op that is not supported via BufferizableOpInterfaceImpl bufferization. Once this op is supported we can switch `tensor-bufferize` over to the new unified bufferization.

Differential Revision: https://reviews.llvm.org/D117985
2022-01-25 00:31:20 +09:00
Denys Shabalin 2d9ed1aba2 [mlir] Fix broken __repr__ implementation in Linalg OpDSL
Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D118027
2022-01-24 15:58:35 +01:00
Matthias Springer 49e3700069 [mlir][tensor] Move BufferizableOpInterface impl to tensor dialect
This is in preparation of unifying the existing bufferization with One-Shot bufferization.

A subsequent commit will replace `tensor-bufferize`'s implementation with the BufferizableOpInterface-based implementation and move over missing test cases.

Differential Revision: https://reviews.llvm.org/D117984
2022-01-24 23:54:49 +09:00
serge-sans-paille 5f290c090a Move STLFunctionalExtras out of STLExtras
Only using that change in StringRef already decreases the number of
preoprocessed lines from 7837621 to 7776151 for LLVMSupport

Perhaps more interestingly, it shows that many files were relying on the
inclusion of StringRef.h to have the declaration from STLExtras.h. This
patch tries hard to patch relevant part of llvm-project impacted by this
hidden dependency removal.

Potential impact:
- "llvm/ADT/StringRef.h" no longer includes <memory>,
  "llvm/ADT/Optional.h" nor "llvm/ADT/STLExtras.h"

Related Discourse thread:
https://llvm.discourse.group/t/include-what-you-use-include-cleanup/5831
2022-01-24 14:13:21 +01:00
Groverkss b754d09fde [MLIR][Presburger] Refactor duplicate division merging to Utils
This patch moves merging of duplicate divisions to presburger utility
functions. This is required to support division merging in structures other
than IntegerPolyhedron.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D118001
2022-01-24 18:12:13 +05:30
Matthias Springer b2499bf3e8 [mlir][bufferize][NFC] Refactor createAlloc function signature
Pass a ValueRange instead of an ArrayRef<Value> for better compatibility. Also provide an additional function overload that automatically deallocates the buffer if specified.

Differential Revision: https://reviews.llvm.org/D118025
2022-01-24 20:25:35 +09:00
Lorenzo Chelini d6f8f56da0 [MLIR][Presburger] Silence -Wdangling-else warning (NFC)
gcc suggests explicit braces to avoid ambiguous ‘else’.
2022-01-24 09:16:05 +01:00
Kazu Hirata 47d7e922d8 [mlir] Ensure a newline at the end of a file (NFC) 2022-01-23 13:59:59 -08:00
Groverkss ad36f37ce2 [MLIR][Presburger] Clean PresburgerSet identifier interface to match IntegerPolyhedron's interface
This patch changes names of identifiers and their corresponding getters in
PresburgerSet to match those of IntegerPolyhedron.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D117998
2022-01-24 01:09:07 +05:30
Alexander Belyaev 4041354b4c [mlir] Add SingleBlockImplicitTerminator<"tensor::YieldOp"> to PadOp. 2022-01-22 11:46:27 +01:00
Prashant Kumar b6098c07cb [MLIR] Fix negative gcd in `normalizeDivisionByGCD` function.
When the coefficients of dividend are negative, the gcd may be negative
which will change the sign of dividend and overflow denominator.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D117911
2022-01-22 13:09:28 +05:30
not-jenni 08574ce4d6 [mlir][tosa] Add clamp + clamp as single clamp canonicalization
When 2 clamp ops are in a row, they can be canonicalized into a single clamp
that uses the most constrained range

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D117934
2022-01-21 16:24:43 -08:00
Aart Bik efa15f4178 [mlir][sparse] add ability for sparse tensor output
Rationale:
Although file I/O is a bit alien to MLIR itself, we provide two convenient ways
for sparse tensor I/O. The input part was already there (behind the swiss army
knife sparse_tensor.new). Now we have a sparse_tensor.out to write out data. As
before, the ops are kept vague and may change in the future. For now this
allows us to compare TACO vs MLIR very easily.

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D117850
2022-01-21 15:43:29 -08:00
Bixia Zheng ba093fe58b Fix a commit.
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D117932
2022-01-21 15:18:28 -08:00
Bixia Zheng b796709a62 Only run MLIR PyTACO tests when python bindings are enabled.
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D117930
2022-01-21 15:05:29 -08:00
Rob Suderman 2f9f9afa4e [mlir] Add polynomial approximation for atan and atan2
Implement a taylor series approximation for atan and add an atan2 lowering
that uses atan's appromation. This includes tests for edge cases and tests
for each quadrant.

Reviewed By: NatashaKnk

Differential Revision: https://reviews.llvm.org/D115682
2022-01-21 12:22:58 -08:00
wren romano 4d0a18d06e [mlir][sparse] Adding assertions for overhead storage types
Fixes https://bugs.llvm.org/show_bug.cgi?id=52314 aka https://github.com/llvm/llvm-project/issues/51656

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D117597
2022-01-21 11:56:52 -08:00
Alexander Belyaev fd0c6f5391 [mlir] Move linalg::PadTensorOp to tensor::PadOp.
RFC: https://llvm.discourse.group/t/rfc-move-linalg-padtensorop-to-tensor-padop/5785

Differential Revision: https://reviews.llvm.org/D117892
2022-01-21 20:02:39 +01:00
Lei Zhang 4710750854 [mlir][spirv] Support size-1 vector inserts during conversion
Differential Revision: https://reviews.llvm.org/D115517
2022-01-21 13:56:26 -05:00
Bixia Zheng b7fd91c84b Upstream MLIR PyTACO implementation.
Add TACO tests to test/Integration/Dialect/SparseTensor/taco. Add the MLIR
PyTACO implementation as tools under the directory.

Reviewed By: aartbik, mehdi_amini

Differential Revision: https://reviews.llvm.org/D117260
2022-01-21 08:38:36 -08:00
serge-sans-paille 75e164f61d [llvm] Cleanup header dependencies in ADT and Support
The cleanup was manual, but assisted by "include-what-you-use". It consists in

1. Removing unused forward declaration. No impact expected.
2. Removing unused headers in .cpp files. No impact expected.
3. Removing unused headers in .h files. This removes implicit dependencies and
   is generally considered a good thing, but this may break downstream builds.
   I've updated llvm, clang, lld, lldb and mlir deps, and included a list of the
   modification in the second part of the commit.
4. Replacing header inclusion by forward declaration. This has the same impact
   as 3.

Notable changes:

- llvm/Support/TargetParser.h no longer includes llvm/Support/AArch64TargetParser.h nor llvm/Support/ARMTargetParser.h
- llvm/Support/TypeSize.h no longer includes llvm/Support/WithColor.h
- llvm/Support/YAMLTraits.h no longer includes llvm/Support/Regex.h
- llvm/ADT/SmallVector.h no longer includes llvm/Support/MemAlloc.h nor llvm/Support/ErrorHandling.h

You may need to add some of these headers in your compilation units, if needs be.

As an hint to the impact of the cleanup, running

clang++ -E  -Iinclude -I../llvm/include ../llvm/lib/Support/*.cpp -std=c++14 -fno-rtti -fno-exceptions | wc -l

before: 8000919 lines
after:  7917500 lines

Reduced dependencies also helps incremental rebuilds and is more ccache
friendly, something not shown by the above metric :-)

Discourse thread on the topic: https://llvm.discourse.group/t/include-what-you-use-include-cleanup/5831
2022-01-21 13:54:49 +01:00
Siddharth Bhat 357f2d9ccf [mlir][LangRef] Add top-level production to the MLIR grammar
The LangRef currently lacks a top-level production, leaving the productions attribute-alias-def and type-alias-defunused. Clarify the situation by declaring what is to be parsed by an MLIR parser at the toplevel.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D117668
2022-01-21 17:08:53 +05:30
Markus Böck d03c5bc8d4 [mlir] Fully qualify return types in OpAsmInterface.td and FunctionInterfaces.td 2022-01-21 10:04:02 +01:00
MaheshRavishankar a99e06aa86 [mlir][Linalg] Avoid generating illegal operations during elementwise fusion.
In some cases, fusion can produce illegal operations if after fusion
the range of some of the loops cannot be computed from shapes of its
operands. Check for this case and abort the fusion if this happens.

Differential Revision: https://reviews.llvm.org/D117602
2022-01-20 23:43:50 -08:00
Mehdi Amini 9006bf4248 Remove obsolete `getAsmResultNames` from OpAsmDialectInterface
This is superseded by the same method on OpAsmOpInterface, which is
available on the Dialect through the Fallback mechanism,

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D117750
2022-01-21 05:58:32 +00:00
Rahul Kayaith 308d8b8c66 [mlir][python] 8b/16b DenseIntElements access
This extends dense attribute element access to support 8b and 16b ints.
Also extends the corresponding parts of the C api.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D117731
2022-01-21 05:21:09 +00:00
Mehdi Amini 26167cae45 Print the `// ----` separator between modules when using -split-input-file with mlir-opt
This allows to pipe sequences of `mlir-opt -split-input-file | mlir-opt -split-input-file`.

Depends On D117750

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D117756
2022-01-21 05:16:02 +00:00
Rob Suderman cd2d736963 [mlir][tosa] Limit right-shift to 31 bits
Right shift can occur that is a 32-bit right shift. This is undefined behavior.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D117732
2022-01-20 14:39:57 -08:00
River Riddle 5ef7abbc6f [mlir:TiingInterface] Remove unnecessary include of Tensor.h
Interfaces in Interfaces/ should not depend on any dialects, and this include
is unnecessary anyways.
2022-01-20 13:10:44 -08:00
Krzysztof Drewniak 40aef79db0 [MLIR][GPU] Add debug output to enable dumping GPU assembly
- Set the DEBUG_TYPE of SerializeToBlob to serialize-to-blob
- Add debug output to print the assembly or PTX for GPU modules before
  they are assembled and linked

Note that, as SerializeToBlob is a superclass of SerializeToCubin and
SerializeToHsaco, --debug-only=serialize-to-blom will dump the
intermediate compiler result for both of these passes.

In addition, if LLVM options such as --stop-after are used to control
the GPU kernel compilation process, the debug output will contain the
appropriate intermediate IR.

Reviewed By: herhut

Differential Revision: https://reviews.llvm.org/D117519
2022-01-20 20:52:12 +00:00
Mogball e99835ffed [mlir][pdl] Make `pdl` the default dialect when parsing/printing
PDLDialect being a somewhat user-facing dialect and whose ops contain exclusively other PDL ops in their regions can take advantage of `OpAsmOpInterface` to provide nicer IR.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D117828
2022-01-20 20:22:53 +00:00
Mogball 7c471b56f2 [mlir][pdl] OperationOp should not be side-effect free
Unbound OperationOp in the matcher (i.e. one with no uses) is already disallowed by the verifier. However, an OperationOp in the rewriter is not side-effect free -- it's creating an op!

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D117825
2022-01-20 20:22:01 +00:00
Mogball d0cace5087 [mlir][pdl] Some ops are missing `NoSideEffect`
Querying or building constraints on types, operands, results, and attributes are side-effect free in both the matcher and rewriter. The ops should be marked as such.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D117826
2022-01-20 20:21:02 +00:00
John Ericson df31ff1b29 [cmake] Make include(GNUInstallDirs) always below project(..)
Its defaulting logic must go after `project(..)` to work correctly,  but `project(..)` is often in a standalone condition making this
awkward, since the rest of the condition code may also need GNUInstallDirs.

The good thing is there are the various standalone booleans, which I had missed before. This makes splitting the conditional blocks less awkward.

Reviewed By: arichardson, phosek, beanz, ldionne, #libunwind, #libc, #libc_abi

Differential Revision: https://reviews.llvm.org/D117639
2022-01-20 18:59:17 +00:00
Sergei Grechanik 5abf116322 [mlir][vector] Allow values outside of [0; dim-size] in create_mask
This commits explicitly states that negative values and values exceeding
vector dimensions are allowed in vector.create_mask (but not in
vector.constant_mask). These values are now truncated when
canonicalizing vector.create_mask to vector.constant_mask.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D116069
2022-01-20 09:34:42 -08:00
Michael Kruse 616f77172f [OpenMPIRBuilder] Detect and fix ambiguous InsertPoints for createParallel.
When a Builder methods accepts multiple InsertPoints, when both point to
the same position, inserting instructions at one position will "move" the
other after the inserted position since the InsertPoint is pegged to the
instruction following the intended InsertPoint. For instance, when
creating a parallel region at Loc and passing the same position as AllocaIP,
creating instructions at Loc will "move" the AllocIP behind the Loc
position.

To avoid this ambiguity, add an assertion checking this condition and
fix the unittests.

In case of AllocaIP, an alternative solution could be to implicitly
split BasicBlock at InsertPoint, using the first as AllocaIP, the second
for inserting the instructions themselves. However, this solution is
specific to AllocaIP since AllocaIP will always have to be first. Hence,
this is an argument to generally handling ambiguous InsertPoints as API
sage error.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D117226
2022-01-20 10:13:44 -06:00
Stephan Herhut 6d45284618 [mlir][memref] Add better support for identity layouts in memref.collapse_shape canonicalizer
When computing the new type of a collapse_shape operation, we need to at least
take into account whether the type has an identity layout, in which case we can
easily support dynamic strides. Otherwise, the canonicalizer creates invalid
IR.

Longer term, both the verifier and the canoncializer need to be extended to
support the general case.

Differential Revision: https://reviews.llvm.org/D117772
2022-01-20 15:31:43 +01:00
Prashant Kumar 770353cd94 [MLIR] The return type in the `computeSingleVarRepr` function is modified to include equality expressions.
Earlier `computeSingleVarRepr` was returning a pair of upper bound and
lower bound indices of the inequality contraints that can be expressed
as a floordiv of an affine function. The equality expression can also be
expressed as a floordiv but contains only one index and hence the `LocalRepr`
class is introduced to facilitate this.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D117430
2022-01-20 16:40:58 +05:30
Matthias Springer 7a1579ac67 [mlir][bufferization] Move one-shot bufferization to Bufferization dialect
This commit is the first step towards unifying core bufferization and One-Shot Bufferize.

This commit does not move over the implementations of BufferizableOpInterface yet. This will be done in separate commits. This change does also not move the unit tests yet. The tests will be moved together with op interface implementations and split into separate files.

Differential Revision: https://reviews.llvm.org/D117641
2022-01-20 18:21:20 +09:00
River Riddle e39dae85f1 [mlir] Fix GCC5 build broken by improper name redefinition 2022-01-19 19:24:12 -08:00
River Riddle e084679f96 [mlir] Make locations required when adding/creating block arguments
BlockArguments gained the ability to have locations attached a while ago, but they
have always been optional. This goes against the core tenant of MLIR where location
information is a requirement, so this commit updates the API to require locations.

Fixes #53279

Differential Revision: https://reviews.llvm.org/D117633
2022-01-19 17:35:35 -08:00
Dominik Grewe 1e09f0a972 Preserve function argument locations.
Previously the optional locations of function arguments were dropped in
`parseFunctionArgumentList`. This CL adds another output argument to the
function through which they are now returned. The values are then plumbed
through as an array of optional locations in the various places.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D117604
2022-01-20 00:01:12 +00:00
River Riddle d75c3e8396 [mlir] Don't print `// no predecessors` on entry blocks
Entry blocks can never have predecessors, so this is unnecessary.

Fixes #53287

Differential Revision: https://reviews.llvm.org/D117713
2022-01-19 15:57:58 -08:00
Mehdi Amini 4b12f4b2b1 Fix crash in MLIR opaque attribute parser
An assertion is triggered when the dialect is malformed.

Differential Revision: https://reviews.llvm.org/D117709
2022-01-19 23:35:48 +00:00
Mehdi Amini e7ab36f191 Change elided large constant syntax to make it more explicit
When the printer is requested to elide large constant, we emit an opaque
attribute instead. This patch fills the dialect name with
"elided_large_const" instead of "_" to remove some user confusion when
they later try to consume it.

Differential Revision: https://reviews.llvm.org/D117711
2022-01-19 20:41:42 +00:00
Stella Stamenova 438f805145 [mlir] Configure mlir so that it can be directly included in a parent cmakelists.txt
The goal is to allow a project to directly include the `CMakeLists.txt` of mlir via something such as `add_directory`. This currently doesn't work because the exported targets then end up being imported in the same top-level project and `cmake` is not happy. LLVM works around this by guarding the exports based on the existence of the `LLVMSupport` library. This change does the same using `MLIRSupport`. In our experience, no targets need to be added to the export in the case.

If there's a preferred way of doing this or a better lib to use as the main target to check for, please let me know.

Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D117599
2022-01-19 12:02:22 -08:00
wren romano c4017f9d0c [mlir][sparse] Simplifying assertions in fromCOO
Hoisting invariant assertions to the top

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D117408
2022-01-19 11:25:41 -08:00
natashaknk b9b10c0e61 [tosa][mlir] Lowering for dynamic shapes in the reduce_x ops in tosa-to-linalg
Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D117691
2022-01-19 11:15:14 -08:00
Thomas Raoux d9edc1a585 [mlir][spirv] Add math.fma lowering to spirv
Differential Revision: https://reviews.llvm.org/D117704
2022-01-19 10:57:05 -08:00
Nicolas Vasilache d492a7b2ca [mlir][Linalg] Add a useLinalgCopy option to Linalg bufferization.
Benchmarks show that memref::CopyOp is curently up to 200x slower than
tiled and vectorized versions of linalg::Copy.
Add a temporary flag to allow comprehensive bufferize to generate a
linalg::GenericOp that implements a copy until this performance bug is
resolved.

Differential Revision: https://reviews.llvm.org/D117696
2022-01-19 13:00:11 -05:00
John Ericson 5ad96992ef [mlir][cmake] Use `GNUInstallDirs` to support custom installation dirs
I am breaking apart D99484 so the cause of build failures is easier to
understand.

Differential Revision: https://reviews.llvm.org/D117540
2022-01-19 17:11:04 +00:00
Alex Zinenko 89a92fb3ba [mlir] Rework subclass construction in PybindAdaptors.h
The constructor function was being defined without indicating its "__init__"
name, which made it interpret it as a regular fuction rather than a
constructor. When overload resolution failed, Pybind would attempt to print the
arguments actually passed to the function, including "self", which is not
initialized since the constructor couldn't be called. This would result in
"__repr__" being called with "self" referencing an uninitialized MLIR C API
object, which in turn would cause undefined behavior when attempting to print
in C++. Even if the correct name is provided, the mechanism used by
PybindAdaptors.h to bind constructors directly as "__init__" functions taking
"self" is deprecated by Pybind. The new mechanism does not seem to have access
to a fully-constructed "self" object (i.e., the constructor in C++ takes a
`pybind11::detail::value_and_holder` that cannot be forwarded back to Python).

Instead, redefine "__new__" to perform the required checks (there are no
additional initialization needed for attributes and types as they are all
wrappers around a C++ pointer). "__new__" can call its equivalent on a
superclass without needing "self".

Bump pybind11 dependency to 3.8.0, which is the first version that allows one
to redefine "__new__".

Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D117646
2022-01-19 18:09:05 +01:00
Matthias Springer cd0a923b4c [mlir][linalg][bufferize][NFC] Move analysis-related code to Comprehensive Bufferize
The code in `BufferizableOpInterface`'s header/source no longer contains any analysis code. This makes it easier to run the bufferization with a different analysis or without any analysis.

Differential Revision: https://reviews.llvm.org/D117478
2022-01-19 22:25:36 +09:00
Matthias Springer 31355482e5 [mlir][linalg][bufferize][NFC] Split analysis-related code from BufferizationState/Options
This separates the analysis (and its helpers/data structures) more clearly from the rest of the bufferization.

Differential Revision: https://reviews.llvm.org/D117477
2022-01-19 21:59:23 +09:00
Denys Shabalin 19c3026891 [mlir] Fix PDL python bindings build
Fixes incorrect build definition for the bindings for the PDL dialect.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D117657
2022-01-19 13:58:55 +01:00
Denys Shabalin ed21c9276a [mlir] Introduce Python bindings for the PDL dialect
This change adds full python bindings for PDL, including types and operations
with additional mixins to make operation construction more similar to the PDL
syntax.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D117458
2022-01-19 11:19:56 +01:00
Matthias Springer be8742b6c9 [mlir][linalg][bufferize][NFC] Merge AllocationCallbacks into BufferizationOptions
Also move `createAlloc` and related helper functions out of BufferizationState. The goal is to make BufferizationState as small as possible. (Code cleanup)

Differential Revision: https://reviews.llvm.org/D117476
2022-01-19 18:36:34 +09:00
Matthias Springer b44defa5a5 [mlir][linalg][bufferize] Generalize destination-passing style detection
If not allow-return-memref, raise an error if a new memory allocation is returned/yielded from a block. We do not check for new allocations directly, but for ops that yield/return values that are not equivalent to values that are defined outside of the current of the block.

Note: We still need to check that scf.for yield values and bbArgs are aliasing to ensure that getAliasingOpOperand/getAliasingOpResult is correct.

Differential Revision: https://reviews.llvm.org/D116687
2022-01-19 18:21:29 +09:00
Matthias Springer b83c67d978 [mlir][linalg][bufferize] Support scf.execute_region bufferization
This op is needed for unit testing in a subsequent revision. (This is the first op that has a block that yields equivalent values via the op's results.)

Note: Bufferization of scf.execute_region ops with multiple blocks is not yet supported.

Differential Revision: https://reviews.llvm.org/D117424
2022-01-19 18:17:09 +09:00
not-jenni 41d05e29c0 [mlir][tosa] Add tosa.clamp as no-op canonicalization
When the min/max are the total range of the value, it is a no-op as the values
are already restricted to that range.

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D117625
2022-01-18 23:15:40 -08:00
Mehdi Amini 3df97bfebc Fix GCC 5 MLIR Build (NFC)
Try to fix the error:

mlir/lib/Parser/Parser.cpp:553:14: error: cannot call member function 'mlir::InFlightDiagnostic mlir::detail::Parser::emitError(llvm::SMLoc, const llvm::Twine&)' without object
              << "operation location alias was never defined";
2022-01-19 06:44:28 +00:00
River Riddle 7ceffae18c [mlir] Convert OpTrait::FunctionLike to FunctionOpInterface
This commit refactors the FunctionLike trait into an interface (FunctionOpInterface).
FunctionLike as it is today is already a pseudo-interface, with many users checking the
presence of the trait and then manually into functionality implemented in the
function_like_impl namespace. By transitioning to an interface, these accesses are much
cleaner (ideally with no direct calls to the impl namespace outside of the implementation
of the derived function operations, e.g. for parsing/printing utilities).

I've tried to maintain as much compatability with the current state as possible, while
also trying to clean up as much of the cruft as possible. The general migration plan for
current users of FunctionLike is as follows:

* function_like_impl -> function_interface_impl
Realistically most user calls should remove references to functions within this namespace
outside of a vary narrow set (e.g. parsing/printing utilities). Calls to the attribute name
accessors should be migrated to the `FunctionOpInterface::` equivalent, most everything
else should be updated to be driven through an instance of the interface.

* OpTrait::FunctionLike -> FunctionOpInterface
`hasTrait` checks will need to be moved to isa, along with the other various Trait vs
Interface API differences.

* populateFunctionLikeTypeConversionPattern -> populateFunctionOpInterfaceTypeConversionPattern

Fixes #52917

Differential Revision: https://reviews.llvm.org/D117272
2022-01-18 20:56:53 -08:00
Peixin-Qiao a56a7d99e8 [MLIR][OpenMP] Support schedule chunk size with various bit width
The chunk size in schedule clause is one integer expression, which can
be either constant integer or integer variable. Fix schedule clause in
MLIR Op Def to support integer expression with different bit width.

Reviewed By: shraiysh

Differential Revision: https://reviews.llvm.org/D116073
2022-01-19 12:36:53 +08:00
River Riddle d288656368 [mlir] Mark FunctionPass as deprecated using the C++14 deprecated attribute 2022-01-18 20:18:47 -08:00
River Riddle 4157455425 [mlir][Pass] Deprecate FunctionPass in favor of OperationPass<FuncOp>
The only benefit of FunctionPass is that it filters out function
declarations. This isn't enough to justify carrying it around, as we can
simplify filter out declarations when necessary within the pass. We can
also explore with better scheduling primitives to filter out declarations
at the pipeline level in the future.

The definition of FunctionPass is left intact for now to allow time for downstream
users to migrate.

Differential Revision: https://reviews.llvm.org/D117182
2022-01-18 19:52:44 -08:00
Jacques Pienaar d5db25fb1d [mlir][textmate] Add support for function visibility
Avoids functions with visibility not being marked as functions. Tested
via Lightshow.
2022-01-18 18:48:43 -08:00
Benjamin Kramer ff5de8a9e0 [linalg][fusion] Disallow fusion when it would create an invalid expand_shape
The input type of a linalg.generic can be less dynamic than its output
type. If this is the case moving a reshape across the generic op would
create invalid IR, as expand_shape cannot expand arbitrary dynamic
dimensions.

Check that the reshape is actually valid before creating the
expand_shape. This exposes the existing verification logic in reshape
utils and removes the incomplete custom implementation in fusion.

Differential Revision: https://reviews.llvm.org/D116600
2022-01-18 23:44:14 +01:00
Benjamin Kramer f100bedb03 [mlir][linalg] Insert a cast for identity linalg.generics when the types don't match
This can happen when the result has different dynamic dimensions than
the input.

Differential Revision: https://reviews.llvm.org/D117498
2022-01-18 23:44:14 +01:00
Mehdi Amini 58cb303777 Allows deferred location attribute in `parseOptionalLocationSpecifier`
Before this patch, deferred location in operation like `test.pretty_printed_region` would
break the parser, and so the IR round-trip.

Depends On D117088

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D117413
2022-01-18 22:00:36 +00:00
Mehdi Amini a440b0404f Use Opaque location for handling deferred references to aliases internally to the parser (NFC)
This will allow to return to the client of `parseLocationInstance` a location that is resolved later.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D117088
2022-01-18 20:43:36 +00:00
River Riddle 755dc07d69 [mlir:Analysis] Move the LoopAnalysis library to Dialect/Affine/Analysis
The current state of the top level Analysis/ directory is that it contains two libraries;
a generic Analysis library (free from dialect dependencies), and a LoopAnalysis library
that contains various analysis utilities that originated from Affine loop transformations.
This commit moves the LoopAnalysis to the more appropriate home of `Dialect/Affine/Analysis/`,
given the use and intention of the majority of the code within it. After the move, if there
are generic utilities that would fit better in the top-level Analysis/ directory, we can move
them.

Differential Revision: https://reviews.llvm.org/D117351
2022-01-18 10:28:22 -08:00
Mogball d083a0e589 [mlir] NFC fix a typo in assembly format 2022-01-18 17:36:09 +00:00
Mogball aae5125550 [mlir] Replace StrEnumAttr -> EnumAttr in core dialects
Removes uses of `StrEnumAttr` in core dialects

Reviewed By: mehdi_amini, rriddle

Differential Revision: https://reviews.llvm.org/D117514
2022-01-18 17:15:00 +00:00
Mogball 5c36ee8d57 [mlir] Drop the leading space when printing regions
The leading space that is always printed at the beginning of regions is not consistent with other parts of the printing API. Moreover, this leading space can lead to undesirable assembly formats:

```
attr-dict-with-keyword $region
```

Prints as:

```
// Two spaces between `}` and `{`
attributes {foo}  { ... }
```

Moreover, the leading space results in the odd generic op format:

```
"test.op"() ( {...}) : () -> ()
```

Reviewed By: rriddle, mehdi_amini

Differential Revision: https://reviews.llvm.org/D117411
2022-01-18 16:52:34 +00:00
Alex Zinenko 1ad48d6de2 [mlir] handle nested regions in llvm-legalize-for-export
The translation from the MLIR LLVM dialect to LLVM IR includes a mechanism that
ensures the successors of a block to be different blocks in case block
arguments are passed to them since the opposite cannot be expressed in LLVM IR.
This mechanism previously only worked for functions because it was written
prior to the introduction of other region-carrying operations such as the
OpenMP dialect, which also translates directly to LLVM IR. Modify this
mechanism to handle all regions in the module and not only functions.

Reviewed By: wsmoses

Differential Revision: https://reviews.llvm.org/D117548
2022-01-18 17:09:14 +01:00
Alex Zinenko 7b1ceee63e Revert "[mlir] fix crash in PybindAdaptors.h"
This reverts commit 289021a45d.
2022-01-18 17:05:44 +01:00
Nicolas Vasilache efdd4c169d [mlir][Linalg] NFC - Drop vectorization reliance on ConvolutionOpInterface
Differential revision: https://reviews.llvm.org/D117323
2022-01-18 09:30:46 +00:00
Nicolas Vasilache cc0d208805 [mlir][Linalg] Drop deprecated convolution vectorization patterns
Differential revision: https://reviews.llvm.org/D117326
2022-01-18 09:26:50 +00:00
Alex Zinenko 289021a45d [mlir] fix crash in PybindAdaptors.h
The constructor function was being defined without indicating its "__init__"
name, which made it interpret it as a regular fuction rather than a
constructor. When overload resolution failed, Pybind would attempt to print the
arguments actually passed to the function, including "self", which is not
initialized since the constructor couldn't be called. This would result in
"__repr__" being called with "self" referencing an uninitialized MLIR C API
object, which in turn would cause undefined behavior when attempting to print
in C++.

Fix this by specifying the correct name.

This in turn uncovers the fact the the mechanism used by PybindAdaptors.h to
bind constructors directly as "__init__" functions taking "self" is deprecated
by Pybind. Instead, leverage the fact that the adaptors are intended for
attrbutes/types that cannot have additional data members and are all ultimately
instances of "PyAttribute"/"PyType" C++ class. In constructors of derived
classes, construct an instance of the base class first, then steal its internal
pointer to the C++ object to construct the instance of the derived class.

On top of that, the definition of the function was incorrectly indicated as the
method on the "None" object instead of being the method of its parent class.
This would result in a second problem when Pybind would attempt to print
warnings pointing to the parent class since the "None" does not have a
"__name__" field or its C API equivalent.

Fix this by specifying the correct parent class by looking it up by name in the
parent module.

Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D117325
2022-01-18 10:24:11 +01:00
Mehdi Amini 78fdbdbf26 Use reference for large object passed by value at the moment in MLIR TableGen (NFC)
Also make the ODS Operator class have const iterator, and use const
references for existing API taking Operator by reference.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D117516
2022-01-18 06:48:33 +00:00
Mehdi Amini 7265688e09 Use more references in MLIR Diagnostic handling (NFC)
This saves some copies of non-trivial objects, flagged by Coverity.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D117525
2022-01-18 06:45:04 +00:00
Mehdi Amini c8e047f5e1 Enable useDefault{Type/Attribute}PrinterParser by default in ODS Dialect definition
The majority of dialects reimplement the same boilerplate over and over,
switching the default makes it for better discoverability and make it simpler
to implement new dialects.

Differential Revision: https://reviews.llvm.org/D117524
2022-01-18 06:36:34 +00:00
Mehdi Amini e965d068e0 Pass options by const ref in TestLinalgCodegenStrategy (NFC)
These aren't small object, fix Coverity report.
2022-01-17 23:16:47 +00:00
Benjamin Kramer 964dc368e7 [AsyncToLLVM] aligned_alloc requires the size to be a multiple of aignment, so round up
Fixes a crash with debug malloc.
2022-01-17 21:48:00 +01:00
Nicolas Vasilache f40a579bea Revert "[mlir][Linalg] NFC - Drop vectorization reliance on ConvolutionOpInterface"
This reverts commit c8f5735301.

The integration tests are broken.
2022-01-17 19:38:07 +00:00
Benjamin Kramer 5acd6e0522 [AsyncToLLVM] Align frames to 64 bytes
Coroutine lowering always takes the natural alignment when spilling to
the frame (issue #53148) so using AVX2 or AVX512 in a coroutine doesn't
work. Always overalign to 64 bytes to avoid this issue until we have a
better solution.

Differential Revision: https://reviews.llvm.org/D117501
2022-01-17 18:51:42 +01:00
Nicolas Vasilache 392e16c27f [mlir][Linalg] NFC - Cleanup conv1d generators
Differential Revision: https://reviews.llvm.org/D117330
2022-01-17 17:39:19 +00:00
Nicolas Vasilache 8a8f0a00b2 [mlir][Linalg] Relax PadTensor tiling constraints and expose it to strategies.
Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D117334
2022-01-17 17:13:55 +00:00
Nicolas Vasilache c8f5735301 [mlir][Linalg] NFC - Drop vectorization reliance on ConvolutionOpInterface
Differential Revision: https://reviews.llvm.org/D117323
2022-01-17 17:01:36 +00:00
Nicolas Vasilache f98025d867 [mlir][Vector] Generalize and improve folding of ExtractOp from Insert/Transpose chain.
This revision fixes a bug where the iterative algorithm would walk back def-use chains to an incorrect operand.
This exposed opportunities for a larger refactoring and behavior improvement.
The new algorithm has improved folding behavior and proceeds by tracking both the
permutation of the extraction position and the internal vector permutation.
Multiple partial intersection cases with a candidate insertOp are supported.

The refactoring of the implementation should also help it generalize to strided insert/extract op.

This also subsumes the previous `foldExtractOpFromTranspose` which is now a simple special case and can be deleted.

Differential Revision: https://reviews.llvm.org/D117322
2022-01-17 16:05:23 +00:00
Lorenzo Chelini ca2ac2bb14 [MLIR][Linalg] Handle Attribute in InitTensorOp
In some cases, the result of an initTensorOp may have an attribute.
However, the Attribute was not passed to `inferResultType`, failing the
verifier. Therefore, propagate the Attribute to `inferResultType`.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D117192
2022-01-17 11:43:19 +01:00
Alex Zinenko 2325f36301 Revert "[mlir] fix crash in PybindAdaptors.h"
This reverts commit 970cb57ef7.

Broke the buildbot.
2022-01-17 10:56:01 +01:00
Alex Zinenko 970cb57ef7 [mlir] fix crash in PybindAdaptors.h
The constructor function was being defined without indicating its "__init__"
name, which made it interpret it as a regular fuction rather than a
constructor. When overload resolution failed, Pybind would attempt to print the
arguments actually passed to the function, including "self", which is not
initialized since the constructor couldn't be called. This would result in
"__repr__" being called with "self" referencing an uninitialized MLIR C API
object, which in turn would cause undefined behavior when attempting to print
in C++.

Fix this by specifying the correct name.

This in turn uncovers the fact the the mechanism used by PybindAdaptors.h to
bind constructors directly as "__init__" functions taking "self" is deprecated
by Pybind. The modern method requires using "py::init", which seems to rely on
the C++ equivalent of the bound class to be available, which is not the case in
PybindAdaptors.h. A deeper inspection shows that the deprecation concerns
old-style pybind11 constructors that had to allocate the object using
placement new with "self" as memory. The PybindAdaptors.h only provides
extension classes and never allocates (the object construction is delegated to
the base class), so it does not use the deprecated functionality. Use the
implementation detail tag class to convince pybind11 that we are using the
modern constructor binding method and suppress the warning.

On top of that, the definition of the function was incorrectly indicated as the
method on the "None" object instead of being the method of its parent class.
This would result in a second problem when Pybind would attempt to print
warnings pointing to the parent class since the "None" does not have a
"__name__" field or its C API equivalent.

Fix this by specifying the correct parent class by looking it up by name in the
parent module.

Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D117325
2022-01-17 10:28:01 +01:00
Dominik Grewe 5f782d25a7 Preserve argument locations when cloning a region.
Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D117403
2022-01-16 21:17:23 +00:00
Arjun P 79be1fe0d5 [MLIR] Simplex::getRationalSample: return an optional, empty if Simplex is empty 2022-01-16 22:02:27 +05:30
John Ericson da77db58d7 Revert "[cmake] Use `GNUInstallDirs` to support custom installation dirs."
https://lab.llvm.org/buildbot/#/builders/46/builds/21146 Still have
this odd error, not sure how to reproduce, so I will just try breaking
up my patch.

This reverts commit 4a678f8072.
2022-01-16 05:48:30 +00:00
John Ericson 4a678f8072 [cmake] Use `GNUInstallDirs` to support custom installation dirs.
This is the original patch in my GNUInstallDirs series, now last to merge as the final piece!

It arose as a new draft of D28234. I initially did the unorthodox thing of pushing to that when I wasn't the original author, but since I ended up

 - Using `GNUInstallDirs`, rather than mimicking it, as the original author was hesitant to do but others requested.

 - Converting all the packages, not just LLVM, effecting many more projects than LLVM itself.

I figured it was time to make a new revision.

I have used this patch series (and many back-ports) as the basis of https://github.com/NixOS/nixpkgs/pull/111487 for my distro (NixOS), which was merged last spring (2021). It looked like people were generally on board in D28234, but I make note of this here in case extra motivation is useful.

---

As pointed out in the original issue, a central tension is that LLVM already has some partial support for these sorts of things. Variables like `COMPILER_RT_INSTALL_PATH` have already been dealt with. Variables like `LLVM_LIBDIR_SUFFIX` however, will require further work, so that we may use `CMAKE_INSTALL_LIBDIR`.

These remaining items will be addressed in further patches. What is here is now rote and so we should get it out of the way before dealing more intricately with the remainder.

Reviewed By: #libunwind, #libc, #libc_abi, compnerd

Differential Revision: https://reviews.llvm.org/D99484
2022-01-16 05:33:07 +00:00
Mehdi Amini 772f7b87f8 Disable the MLIR ExecutionEngine library when the native target is not configured
The execution engine would not be functional anyway, we're already
disabling the tests, this also disable the rest of the code.

Anecdotally this reduces the number of static library built when the
builtin target is disabled goes from 236 to 218.

Here is the complete list of LLVM targets built when running
`ninja check-mlir`:

libLLVMAggressiveInstCombine.a
libLLVMAnalysis.a
libLLVMAsmParser.a
libLLVMBinaryFormat.a
libLLVMBitReader.a
libLLVMBitstreamReader.a
libLLVMBitWriter.a
libLLVMCore.a
libLLVMDebugInfoCodeView.a
libLLVMDebugInfoDWARF.a
libLLVMDemangle.a
libLLVMFileCheck.a
libLLVMFrontendOpenMP.a
libLLVMInstCombine.a
libLLVMIRReader.a
libLLVMMC.a
libLLVMMCParser.a
libLLVMObject.a
libLLVMProfileData.a
libLLVMRemarks.a
libLLVMScalarOpts.a
libLLVMSupport.a
libLLVMTableGen.a
libLLVMTableGenGlobalISel.a
libLLVMTextAPI.a
libLLVMTransformUtils.a

Differential Revision: https://reviews.llvm.org/D117287
2022-01-15 19:36:27 +00:00
John Ericson 6e52bfe09d Revert "[cmake] Use `GNUInstallDirs` to support custom installation dirs."
Sorry for the disruption, I will try again later.

This reverts commit efeb501970.
2022-01-15 07:35:02 +00:00
John Ericson efeb501970 [cmake] Use `GNUInstallDirs` to support custom installation dirs.
This is the original patch in my GNUInstallDirs series, now last to merge as the final piece!

It arose as a new draft of D28234. I initially did the unorthodox thing of pushing to that when I wasn't the original author, but since I ended up

 - Using `GNUInstallDirs`, rather than mimicking it, as the original author was hesitant to do but others requested.

 - Converting all the packages, not just LLVM, effecting many more projects than LLVM itself.

I figured it was time to make a new revision.

I have used this patch series (and many back-ports) as the basis of https://github.com/NixOS/nixpkgs/pull/111487 for my distro (NixOS), which was merged last spring (2021). It looked like people were generally on board in D28234, but I make note of this here in case extra motivation is useful.

---

As pointed out in the original issue, a central tension is that LLVM already has some partial support for these sorts of things. Variables like `COMPILER_RT_INSTALL_PATH` have already been dealt with. Variables like `LLVM_LIBDIR_SUFFIX` however, will require further work, so that we may use `CMAKE_INSTALL_LIBDIR`.

These remaining items will be addressed in further patches. What is here is now rote and so we should get it out of the way before dealing more intricately with the remainder.

Reviewed By: #libunwind, #libc, #libc_abi, compnerd

Differential Revision: https://reviews.llvm.org/D99484
2022-01-15 01:08:35 +00:00
Aart Bik e383eaa647 [mlir][sparse] parameterize MTTKRP kernel
Rather than hardcoding all constants, we now use the input tensor to drive the
code setup. Of course, we still need to hardcode dim-2 of A and the final
verification in CHECK is input dependent, but overall this sets a slightly
better example of tensor setup in general.

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D117349
2022-01-14 16:20:31 -08:00
James Y Knight 3bd1ff9a23 Fix NDEBUG unused-variable warning after 05f6e93938. 2022-01-14 21:15:33 +00:00
Eugene Zhulenev 69bc334be5 [mlir] Remove getNumberOfExecutions from RegionBranchOpInterface
`getNumRegionInvocations` was originally added for the async reference counting, but turned out to be not useful, and currently is not used anywhere (couldn't find any uses in public github repos). Removing dead code.

Reviewed By: Mogball, mehdi_amini

Differential Revision: https://reviews.llvm.org/D117347
2022-01-14 13:15:27 -08:00
Mehdi Amini fd6ba1d2c0 Apply clang-tidy fixes for readability-container-size-empty in SCF.cpp (NFC) 2022-01-14 18:08:43 +00:00
Mehdi Amini 1c173c9442 Apply clang-tidy fixes for readability-identifier-naming in MathOps.cpp (NFC) 2022-01-14 18:08:42 +00:00
Mehdi Amini 3b6943e66c Apply clang-tidy fixes for performance-for-range-copy in PadOpInterchange.cpp (NFC) 2022-01-14 18:08:42 +00:00
Mehdi Amini 813156eaa9 Apply clang-tidy fixes for performance-unnecessary-value-param in MLIRGen.cpp (NFC) 2022-01-14 18:08:42 +00:00
Rahul Joshi 8067ced144 [MLIR] Introduce generic visitors.
- Generic visitors invoke operation callbacks before/in-between/after visiting the regions
  attached to an operation and use a `WalkStage` to indicate which regions have been
  visited.
- This can be useful for cases where we need to visit the operation in between visiting
  regions attached to the operation.

Differential Revision: https://reviews.llvm.org/D116230
2022-01-14 09:15:27 -08:00
Stephan Herhut aa3cabe3cb [mlir][memref] Fix memref.copy of scalar memref
Also fix a memory leak in the test while at it.

Differential Revision: https://reviews.llvm.org/D117314
2022-01-14 16:13:12 +01:00
Uday Bondhugula 05f6e93938 [MLIR] NFC. affine data copy generate utility return value cleanup
Clean up return value on affineDataCopyGenerate utility. Return the
actual success/failure status instead of the "number of bytes" which
isn't being used in the codebase in any way. The success/failure status
wasn't being sent out earlier.

Differential Revision: https://reviews.llvm.org/D117209
2022-01-14 19:37:05 +05:30
Matthias Springer 1eeffcdb7a [mlir][linalg][bufferize] Support custom insertion point for buffer copies
By default, copies are inserted right before the tensor OpOperand use. With this change, `bufferize` implementation can change the insertion point. This is needed for some ops where it would be illegal to insert a copy right before the use.

Differential Revision: https://reviews.llvm.org/D117291
2022-01-14 22:47:20 +09:00
Matthias Springer e58e401b79 [mlir][memref] Fold self copies
Fold `memref.copy %x, %x`.

Differential Revision: https://reviews.llvm.org/D117224
2022-01-14 22:44:22 +09:00
Matthias Springer 40f5f3d62d [mlir][linalg][bufferize] Use memref.copy instead of linalg.copy
Differential Revision: https://reviews.llvm.org/D117220
2022-01-14 22:29:05 +09:00
Stephan Herhut ab95ba704d [mlir][memref] Implement fast lowering of memref.copy
In the absence of maps, we can lower memref.copy to a memcpy.

Differential Revision: https://reviews.llvm.org/D116099
2022-01-14 14:22:15 +01:00
Matthias Springer 96acdfa0de [mlir][memref] Fold copy of cast
If the source/dest is a cast that does not change shape/element type, the cast can be skipped.

Differential Revision: https://reviews.llvm.org/D117215
2022-01-14 21:51:12 +09:00
Alex Zinenko bea16e72a7 [mlir] Fix invalid assertion in ModuleTranslation.cpp
LLVM dialect supports terminators with repeated successor blocks that take
different operands. This cannot be directly expressed in LLVM IR though since
it uses the number of the predecessor block to differentiate values in its PHI
nodes. Therefore, the translation to LLVM IR inserts dummy blocks to forward
arguments in case of repeated succesors with arguments. The insertion works
correctly. However, when connecting PHI nodes to their source values, the
assertion of the insertion having worked correctly was incorrect: it would only
trigger if repeated blocks were adjacent in the successor list (not guaranteed
by anything) and would not check if the successors have operands (no need for
dummy blocks in absence of operands since no PHIs are being created). Change
the assertion to only trigger in case of duplicate successors with operands,
and don't expect them to be adjacent.

Reviewed By: wsmoses

Differential Revision: https://reviews.llvm.org/D117214
2022-01-14 12:56:33 +01:00
Adrian Kuegel cc79d603c9 [mlir] Use .empty() instead of checking size() == 0.
Based on a finding by ClangTidy readability-container-size-empty check.
2022-01-14 11:58:52 +01:00
Mehdi Amini 8d20d83dd7 Fix a comment in CMake (NFC) 2022-01-14 07:33:06 +00:00
Mehdi Amini 46b1e83716 Do not build llc and mlir-cpu-runner to run MLIR tests with the native target isn't configured (NFC)
The relevant tests are already disabled in this case.
2022-01-14 07:30:34 +00:00
Alexander Belyaev 436d17a8e9 [mlir] Expose a function to get vector::CombiningKind from Operation*.
Differential Revision: https://reviews.llvm.org/D117283
2022-01-14 08:28:18 +01:00
Mehdi Amini 5a68a85d85 Mark some MLIR tests as requiring the native target to be configured
This makes `ninja check-mlir` work without the host targets configured.
2022-01-14 07:23:14 +00:00
Mehdi Amini dc9f18da86 Partially revert cac7aabbd82: some APIs don't have in-tree users and some build breaks weren't caught 2022-01-14 06:16:38 +00:00
River Riddle 11067d711b [mlir] Optimize OperationName construction and usage
When constructing an OperationName, the overwhelming majority of
cases are from registered operations. This revision adds a non-locked
lookup into the currently registered operations, which prevents locking
in the common case. This revision also optimizes several uses of
RegisteredOperationName that expect the operation to be registered,
e.g. such as in OpBuilder.

These changes provides a reasonable speedup (5-10%) in some
compilations, especially on platforms where locking is expensive.

Differential Revision: https://reviews.llvm.org/D117187
2022-01-13 21:14:36 -08:00
wren romano cf35825388 [mlir][sparse] Moving the sort from factory method to the constructor.
This guarantees the preconditions of fromCOO; whereas prior to this, one could call the constructor directly with an unsorted tensor, which would cause fromCOO to misbehave.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D117167
2022-01-13 19:44:51 -08:00
Mehdi Amini 58ec17cb4e Apply clang-tidy fixes for readability-simplify-boolean-expr to MLIR (NFC) 2022-01-14 02:26:28 +00:00
Mehdi Amini cac7aabbd8 Apply clang-tidy fixes for readability-identifier-naming to MLIR (NFC) 2022-01-14 02:26:28 +00:00
Mehdi Amini d1b63c603a Apply clang-tidy fixes for readability-avoid-const-params-in-decls to MLIR (NFC) 2022-01-14 02:26:28 +00:00
Mehdi Amini e8d073951b Apply clang-tidy fixes for performance-unnecessary-value-param to MLIR (NFC) 2022-01-14 02:26:27 +00:00
Mehdi Amini 8e5f112c05 Apply clang-tidy fixes for performance-move-const-arg to MLIR (NFC) 2022-01-14 02:26:27 +00:00
Mehdi Amini a68c8d3009 Apply clang-tidy fixes for performance-for-range-copy to MLIR (NFC) 2022-01-14 02:26:27 +00:00
Mehdi Amini 2071e7204d Apply clang-tidy fixes for modernize-use-using to MLIR (NFC) 2022-01-14 02:26:27 +00:00
Mehdi Amini bd87241c44 Apply clang-tidy fixes for modernize-use-override to MLIR (NFC) 2022-01-14 02:26:27 +00:00
Mehdi Amini 9940dcfa4a Apply clang-tidy fixes for modernize-use-equals-default to MLIR (NFC) 2022-01-14 02:26:27 +00:00
Mehdi Amini 59d8740f2f Apply clang-tidy fixes for modernize-use-default-member-init to MLIR (NFC) 2022-01-14 02:26:26 +00:00
Mehdi Amini d19f89b5d2 Apply clang-tidy fixes for llvm-qualified-auto to MLIR (NFC) 2022-01-14 02:26:26 +00:00
Peixin-Qiao f52805539b [OMPIRBuilder] Fix store inst alignment for ordered depend directive
OpenMP runtime requires depend vec with i64 type and the alignment of
store instruction should be set as 8.

Reviewed By: kiranchandramohan, shraiysh

Differential Revision: https://reviews.llvm.org/D116300
2022-01-14 09:47:11 +08:00
Mehdi Amini ba37c3b152 Apply clang-tidy fixes for llvm-namespace-comment in ToolUtilities.h (NFC) 2022-01-13 23:25:49 +00:00
Mehdi Amini b0aea19813 Apply clang-tidy fixes for llvm-namespace-comment in ParallelLoopMapper.h (NFC) 2022-01-13 23:25:49 +00:00
Mehdi Amini 63edb563a1 Apply clang-tidy fixes for llvm-namespace-comment in GPUToNVVMPass.h (NFC) 2022-01-13 23:25:49 +00:00
Mehdi Amini e4f5d47296 Apply clang-tidy fixes for llvm-namespace-comment in MemoryPromotion.h (NFC) 2022-01-13 23:25:49 +00:00
Mehdi Amini ac7a2742b2 Apply clang-tidy fixes for llvm-else-after-return in CommonFolders.h (NFC) 2022-01-13 23:25:49 +00:00
Mehdi Amini 4e08ce7adb Revert "Upstream MLIR PyTACO implementation."
This reverts commit 778a264da9.

This broke the bot: tests are failing at the moment.
2022-01-13 23:14:13 +00:00
Mehdi Amini 8f23296bcc Apply clang-tidy fixes for llvm-header-guard in MLIR (NFC)
Differential Revision: https://reviews.llvm.org/D117251
2022-01-13 23:14:06 +00:00
Aart Bik e52f530c36 [mlir][sparse] fix two typos
(1) copy-and-past error in encoding alias name:
    this is an annotation for a tensor (3-d) not a matrix (2-d).

(2) typo in "initialization"

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D117255
2022-01-13 15:11:55 -08:00
Bixia Zheng 778a264da9 Upstream MLIR PyTACO implementation.
Add TACO tests to test/Integration/Dialect/SparseTensor/taco. Add the MLIR
PyTACO implementation as tools under the directory.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D117126
2022-01-13 14:50:28 -08:00
Markus Böck 52b8fe9b6e [mlir] Fix attaching side effects on `FlatSymbolRefAttr`
The names of the generated attribute getters for ops changed some time ago. The method created from the attribute name returns the return type and an additional method of the same name with Attr as suffix is generated which returns the actual attribute as its storage type.

The code generating effects however was using the methods without the Attr suffix, which is a problem in the case of FlatSymbolRefAttr as it has a return type of llvm::StringRef. This would lead to compilation errors as the constructor of SideEffects::EffectInstance expects a SymbolRefAttr in this case.

This patch simply fixes the generated effects code to use the Attr suffixed getter to get the actual storage type of the attribute.

Differential Revision: https://reviews.llvm.org/D117194
2022-01-13 19:57:01 +01:00
Mehdi Amini f7c589d3e7 Clarify that fold() can't "erase" an operation in the MLIR Canonicalization doc (NFC) 2022-01-13 18:43:18 +00:00
Rob Suderman 173fce4205 [mlir][tosa] Update default tosa-to-linalg passes
Adding the optional decompositions have been verified to improve memory
usage on common models. Added the decomposition to the default tosa to linalg
passes.

Reviewed By: NatashaKnk

Differential Revision: https://reviews.llvm.org/D117175
2022-01-13 10:17:44 -08:00
Duncan P. N. Exon Smith b77d4d54f9 mlir: Avoid SmallVector::set_size in SerializeToHsacoPass::loadLibraries
Spotted this in a final grep of projects I don't usually build before
pushing https://reviews.llvm.org/D115380, which makes
`SmallVector::set_size()` private.

Update to `truncate()`, a new-ish variant of `resize()` that asserts the
new size is not bigger and that avoids pulling in the allocation and
initialization code for growing. Doesn't really look like the perf
impact of that would matter here, but since `dirLength` is known to be a
smaller size then we might as well.

Differential Revision: https://reviews.llvm.org/D117073
2022-01-13 10:17:00 -08:00
Benoit Jacob 499703e9c0 Enable ReassociatingReshapeOpConversion with "non-identity" layouts.
Enable ReassociatingReshapeOpConversion with "non-identity" layouts.

This removes an early-return in this function, which seems unnecessary and is
preventing some memref.collapse_shape from converting to LLVM (see included lit test).

It seems unnecessary because the return message says "only empty layout map is supported"
but there actually is code in this function to deal with non-empty layout maps. Maybe
it refers to an earlier state of implementation and is just out of date?

Though, there is another concern about this early return: the condition that it actually
checks, `{src,dst}MemrefType.getLayout().isIdentity()`, is not quite the same as what the
return message says, "only empty layout map is supported". Stepping through this
`getLayout().isIdentity()` code in GDB, I found that it evaluates to `.getAffineMap().isIdentity()`
which does (AffineMap.cpp:271):

```
  if (getNumDims() != getNumResults())
    return false;
```

This seems that it would always return false for memrefs of rank greater than 1 ?

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D114808
2022-01-13 17:46:20 +00:00
Denys Shabalin a8a2ee6331 [mlir] Introduce C API for PDL dialect types
This change introduces C API helper functions to work with PDL types.
Modification closely follow the format of the https://reviews.llvm.org/D116546.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D117221
2022-01-13 15:29:01 +01:00
Denys Shabalin edcac733dc [mlir] Fix reference to out of date CMake function
Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D117222
2022-01-13 15:26:36 +01:00
Javier Setoain 7c56458616 [mlir] Fix scalable type translation in splat element attr
LLVM Dialect Constant Op translations assume that if the attribute is a
vector, it's a fixed length one, generating an invalid translation for
constant scalable vector initializations.

Differential Revision: https://reviews.llvm.org/D117125
2022-01-13 11:14:41 +00:00
Ivan Butygin b65f21a498 [mlir] Provide getMixedOffsets/sizes/strides as free functions
* This is useful when you need to build mixed array from external static/dynamic arrays (e.g. from adaptor during dialect conversion)
* Also, to reduce C++ code in td and generated files

Differential Revision: https://reviews.llvm.org/D117106
2022-01-13 13:46:31 +03:00
Adrian Kuegel 159898d568 [mlir] Add missing const to cloneWith method. 2022-01-13 09:40:29 +01:00
River Riddle 0998637e6f [mlir] Add a parsePassPipeline overload that returns a new pass manager
This overload parses a pipeline string that contains the anchor operation type, and returns an OpPassManager
corresponding to the provided pipeline. This is useful for various situations, such as dynamic pass pipelines
which are not anchored within a parent pass pipeline.

fixes #52813

Differential Revision: https://reviews.llvm.org/D116525
2022-01-12 14:54:30 -08:00
natashaknk 310e9636ca [tosa][mlir] Support dynamic batch dimension for ops where the batch dim is explicit
Dynamic batch for rescale, gather, max_pool, avg_pool, conv2D and depthwise_conv2D. Split helper functions into a separate header file.

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D117031
2022-01-12 14:16:50 -08:00
River Riddle 676bfb2a22 [mlir] Refactor ShapedType into an interface
ShapedType was created in a time before interfaces, and is one of the earliest
type base classes in the ecosystem. This commit refactors ShapedType into
an interface, which is what it would have been if interfaces had existed at that
time. The API of ShapedType and it's derived classes are essentially untouched
by this refactor, with the exception being the API surrounding kDynamicIndex
(which requires a sole home).

For now, the API of ShapedType and its name have been kept as consistent to
the current state of the world as possible (to help with potential migration churn,
among other reasons). Moving forward though, we should look into potentially
restructuring its API and possible its name as well (it should really have "Interface"
at the end like other interfaces at the very least).

One other potentially interesting note is that I've attached the ShapedType::Trait
to TensorType/BaseMemRefType to act as mixins for the ShapedType API. This
is kind of weird, but allows for sharing the same API (i.e. preventing API loss from
the transition from base class -> Interface). This inheritance doesn't affect any
of the derived classes, it is just for API mixin.

Differential Revision: https://reviews.llvm.org/D116962
2022-01-12 14:12:09 -08:00
River Riddle a60e83fe7c [mlir][Interfaces] Add a extraSharedClassDeclaration field
This field allows for defining a code block that is placed in both the interface
and trait declarations. This is very useful when defining a set of utilities to
expose on both the Interface class and the derived attribute/operation/type.

In non-static methods, `$_attr`/`$_op`/`$_type` (depending on the type of
interface) may be used to refer to an instance of the IR entity. In the interface
declaration, this is an instance of the interface class. In the trait declaration,
this is an instance of the concrete entity class (e.g. `IntegerAttr`, `FuncOp`, etc.).

Differential Revision: https://reviews.llvm.org/D116961
2022-01-12 14:12:08 -08:00
Rob Suderman aa1c533a4e [mlir][tosa] Expand tosa.apply_scale lowering for vectors
Apply scale may encounter scalar, tensor, or vector operations. Expand the
lowering so that it can lower arbitrary of container types.

Reviewed By: NatashaKnk

Differential Revision: https://reviews.llvm.org/D117080
2022-01-12 14:07:52 -08:00
River Riddle d4d016869d [mlir] Remove populateFuncOpTypeConversionPattern
This method simply forwards to populateFunctionLikeTypeConversionPattern,
which is more general. This also helps to remove special treatment of FuncOp from
DialectConversion.

Differential Revision: https://reviews.llvm.org/D116624
2022-01-12 14:05:35 -08:00
Mehdi Amini 9dc4dea110 Add llc to the list of build dependencies to test MLIR (Fix buildbot) 2022-01-12 20:55:52 +00:00
Mehdi Amini 453a056df6 Add split-file to the MLIR test dependencies (Fix bot) 2022-01-12 20:33:52 +00:00
Kazu Hirata 44bb5cd80d [mlir] Fix a warning
This patch fixes:

  mlir/lib/Dialect/Arithmetic/Transforms/ExpandOps.cpp:161:52: error:
  'static_assert' with no message is a C++17 extension
  [-Werror,-Wc++17-extensions]
2022-01-12 12:31:43 -08:00
Mehdi Amini 44bdcb889a Apply clang-tidy fixes for bugprone-macro-parentheses in Interop.h (NFC) 2022-01-12 20:21:47 +00:00
Mehdi Amini ac5d32b103 Add an example of integration test invoking MLIR source with Memref from C
Reviewed By: ftynse, nicolasvasilache, bondhugula

Differential Revision: https://reviews.llvm.org/D117072
2022-01-12 20:18:56 +00:00
River Riddle 56f62fbf73 [mlir] Finish removing Identifier from the C++ API
There have been a few API pieces remaining to allow for a smooth transition for
downstream users, but these have been up for a few months now. After this only
the C API will have reference to "Identifier", but those will be reworked in a followup.

The main updates are:
* Identifier -> StringAttr
* StringAttr::get requires the context as the first parameter
  - i.e. `Identifier::get("...", ctx)` -> `StringAttr::get(ctx, "...")`

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D116626
2022-01-12 11:58:23 -08:00
Christian Sigg be1aeb818c Remove NaN constant from arith.minf, arith.maxf expansion
If any of the operands is NaN, return the operand instead of a new constant.

When the rhs operand is a constant, the second arith.cmpf+select ops will be folded away.

https://reviews.llvm.org/D117010 marks the two ops commutative, which will place the constant on the rhs.

Reviewed By: herhut

Differential Revision: https://reviews.llvm.org/D117011
2022-01-12 20:56:40 +01:00
Christian Sigg f6fab68c30 Fold arith.cmpf when at least one operand is known to be NaN.
Reviewed By: herhut

Differential Revision: https://reviews.llvm.org/D117101
2022-01-12 20:48:52 +01:00
Thomas Raoux b0a309dd7a [mlir][vector] Add folding for extract + extract/insert_strided
Differential Revision: https://reviews.llvm.org/D116785
2022-01-12 11:48:35 -08:00
William S. Moses 1773dddadf [MLIR][Math] Enable constant folding of ops
Enable constant folding of ops within the math dialect, and introduce constant folders for ceil and log2

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D117085
2022-01-12 12:19:29 -05:00
Matthias Springer 57e714bcc8 [mlir][linalg][bufferize] Add pass options for `createDeallocs`
This change makes it possible to use a different buffer deallocation strategy. E.g., `-buffer-deallocation` can be used, which also works for allocations that are not in destination-passing style.

Differential Revision: https://reviews.llvm.org/D117096
2022-01-12 18:55:36 +09:00
Matthias Springer 6c654b5198 [mlir][linalg][bufferize] Support std.select bufferization
This op is an example for how to deal with ops who's OpResult may aliasing with one of multiple OpOperands.

Differential Revision: https://reviews.llvm.org/D116868
2022-01-12 17:46:44 +09:00
Uday Bondhugula fc61d07dc1 Add inliner interface for GPU dialect
Add inliner interface for GPU dialect. The interface marks all GPU
dialect ops legal to inline anywhere.

Differential Revision: https://reviews.llvm.org/D116889
2022-01-12 12:55:02 +05:30
William S. Moses d2c547342c Revert "[MLIR][Math] Enable constant folding of ops"
This reverts commit 2f8b956ab6.

There is a linker error for mlir-nvidia as seen on
https://lab.llvm.org/buildbot/#/builders/61/builds/19939.

As it's late for me here, I'm oing to rever this for now to be
investigated later.
2022-01-12 02:00:53 -05:00
William S. Moses 2f8b956ab6 [MLIR][Math] Enable constant folding of ops
Enable constant folding of ops within the math dialect, and introduce constant folders for ceil and log2

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D117085
2022-01-12 01:55:48 -05:00
William S. Moses aaa0c81683 [MLIR][LLVM] Add memoryeffect for alloca
Add memory effect for llvm.alloca op

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D117086
2022-01-12 01:53:24 -05:00
William S. Moses d23fa4f2f1 [MLIR][SCF] Remove unused arguments to whileop
Canonicalize away unused arguments to the before region of a whileOp

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D117059
2022-01-11 20:18:08 -05:00
William S. Moses 97567bde5b [MLIR][SCF] Canonicalize while statement whose cmp condition is recomputed in the after region
Given a while loop whose condition is given by a cmp, don't recomputed the comparison (or its inverse) in the after region, instead use a constant since  the original condition must be true if we branched to the after region.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D117047
2022-01-11 18:34:04 -05:00
MaheshRavishankar e7cb716ef9 [mlir][Linalg] Pattern to fuse pad operation with elementwise operations.
Most convolution operations need explicit padding of the input to
ensure all accesses are inbounds. In such cases, having a pad
operation can be a significant overhead. One way to reduce that
overhead is to try to fuse the pad operation with the producer of its
source.

A sequence

```
linalg.generic -> linalg.pad_tensor
```

can be replaced with

```
linalg.fill -> tensor.extract_slice -> linalg.generic ->
tensor.insert_slice.
```

if the `linalg.generic` has all parallel iterator types.

Differential Revision: https://reviews.llvm.org/D116418
2022-01-11 13:37:25 -08:00
William S. Moses 65c15cbd4a [MLIR][LLVM] Add MemRead/MemWrite behavior to llvm store/load/addressof ops
This patch adds corresponding memory effects to mlir llvm-dialect load/store/addressof ops, which thus enables canonicalizations of those ops (like dead code elimination) that rely on the effect interface

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D117041
2022-01-11 14:55:30 -05:00
Mehdi Amini 75b08cce47 Apply clang-tidy fixes for readability-redundant-control-flow in OpenMPDialect.cpp (NFC) 2022-01-11 19:13:58 +00:00
Kazu Hirata 0ceb332a76 [mlir] Fix a missing override warning
This patch fixes:

  mlir/lib/Dialect/Tosa/Transforms/TosaOptionalDecompositions.cpp:28:8:
  error: 'runOnFunction' overrides a member function but is not marked
  'override' [-Werror,-Wsuggest-override]
2022-01-11 11:03:22 -08:00
Aaron DeBattista dfd070820c [mlir][tosa] Allow optional TOSA decompositions to be populated separately
Moved all TOSA decomposition patterns so that they can be optionally populated
and used by external rewrites. This avoids decomposing TOSa operations when
backends may benefit from the non-decomposed version.

Reviewed By: rsuderman, mehdi_amini

Differential Revision: https://reviews.llvm.org/D116526
2022-01-11 10:26:30 -08:00
Rob Suderman 630084549b [mlir][tosa] Relax tosa.apply_scale operations
Apply scale may operate on vectors, scalars, or tensors during
tiling. Relax the requirements to avoid failures.

Reviewed By: NatashaKnk

Differential Revision: https://reviews.llvm.org/D116981
2022-01-11 09:57:36 -08:00
William S. Moses 5443d2ed98 [MLIR][SCF] Simplify scf.if by swapping regions if condition is a not
Given an if of the form, simplify it by eliminating the not and swapping the regions

scf.if not(c) {
  yield origTrue
} else {
  yield origFalse
}

becomes

scf.if c {
  yield origFalse
} else {
  yield origTrue
}

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D116990
2022-01-11 12:57:29 -05:00
Lei Zhang b22a93f4fb [mlir][linalg] Improve pooling op iterator order consistency
All named ops list iterators for accessing output first except
pooling ops. This commit made the pooling ops consistent with
the rest.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D115520
2022-01-11 17:49:22 +00:00
Christian Sigg d345ce65ff Mark arith.minf, arith.maxf as commutative.
Reviewed By: herhut

Differential Revision: https://reviews.llvm.org/D117010
2022-01-11 17:47:53 +01:00
Benjamin Kramer 7f47005dcc [mlir][linalg] Use cast instead of dyn_cast that's always dereferenced
This turns a random nullptr deref into an assertion failure in case
`tensor::registerInferTypeOpInterfaceExternalModels` isn't called.
2022-01-11 15:05:45 +01:00