Commit Graph

10859 Commits

Author SHA1 Message Date
River Riddle 469c58944d [mlir][PDLL] Add signature help to the PDLL language server
This commit adds signature support to the language server,
and initially supports providing help for: operation operands and results,
and constraint/rewrite calls.

Differential Revision: https://reviews.llvm.org/D121545
2022-03-19 13:28:24 -07:00
River Riddle 008de486f7 [mlir][PDLL] Add code completion to the PDLL language server
This commit adds code completion support to the language server,
and initially supports providing completions for: Member access,
attributes/constraint/dialect/operation names, and pattern metadata.

Differential Revision: https://reviews.llvm.org/D121544
2022-03-19 13:28:24 -07:00
River Riddle 8dd4272ca2 [mlir][PDLL] Add symbol support to the PDLL language server
This adds support for documenting the top-level "symbols",
e.g. patterns, constraints, rewrites, etc., within a PDLL file.

Differential Revision: https://reviews.llvm.org/D121543
2022-03-19 13:28:23 -07:00
River Riddle 41ae211458 [mlir][PDLL] Add hover support to the PDLL language server
This adds support for providing information when hovering over
operation names, variables, patters, constraints, and rewrites.

Differential Revision: https://reviews.llvm.org/D121542
2022-03-19 13:28:23 -07:00
River Riddle 52b34df9d6 [mlir][PDLL] Add an initial language server for PDLL
This commits adds a basic language server for PDLL to enable providing
language features in IDEs such as VSCode. This initial commit only
adds support for tracking definitions, references, and diagnostics, but
followup commits will build upon this to provide more significant behavior.

In addition to the server, this commit also updates mlir-vscode to support
the PDLL language and invoke the server.

Differential Revision: https://reviews.llvm.org/D121541
2022-03-19 13:28:23 -07:00
William S. Moses d8a6a696bf [MLIR][SCF] Place hoisted scf.if->select prior to the remaining if
This patch slightly updates the behavior of scf.if->select to
place any hoisted select statements prior to the remaining scf.if body.

This allows better composition with other canonicalization passes, such as
scf.if nested merging.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D122027
2022-03-18 22:14:21 -04:00
Thomas Raoux b4d08dfd9d [mlir] Remove incorrect builders for ExpandShapeOp
ExpandShapeOp builder cannot infer the result type since it doesn't know
how the dimension needs to be split. Remove this builder so that it
doesn't get used accidently. Also remove one potential path using it in
generic fusion.

Differential Revision: https://reviews.llvm.org/D122019
2022-03-18 22:31:17 +00:00
Benjamin Kramer 89d8035e36 Use llvm::append_range where applicable
It knows the size, so no need to call reserve beforehand. NFCI.
2022-03-18 20:05:48 +01:00
William S. Moses d144cf5a98 [MLIR][MemRef] Nested allocation scope inlining
If a stack allocation is within a nested allocation scope
don't count that as an allocation of the outer allocation scope
that would prevent inlining.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D121981
2022-03-18 13:04:13 -04:00
William S. Moses dbe96c8da0 [MLIR][SCF] Combine nested ifs with yields
This patch extends the existing combine nested if
combination canonicalization to also handle ifs which
yield values

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D121923
2022-03-18 13:00:28 -04:00
William S. Moses 5a31403b51 [MLIR][SCF] Create selects from if yield results which are not defined in the body
Previously, the canonicalizer to create ifs from selects would only work
if the if did not have a body other than yielding. This patch upgrade the functionality
to be able to create selects from any if result whose operands are not defined
within the body.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D121943
2022-03-18 11:38:29 -04:00
Eric Schweitz d50298dded [NFC][mlir] Run clang-format on file. 2022-03-18 08:19:37 -07:00
Eric Schweitz 1c083e6985 [mlir] Add support for the nest attribute to the LLVM-IR dialect conversion.
Differential Revision: https://reviews.llvm.org/D121948
2022-03-18 08:15:03 -07:00
Michel Weber ae3e3c6362 [MLIR][Presburger] introduce SetCoalescer
This patch refactors the current coalesce implementation. It introduces
the `SetCoalescer`, a class in which all coalescing functionality lives.
The main advantage over the old design is the fact that the vectors of
constraints do not have to be passed around, but are implemented as
private fields of the SetCoalescer. This will become especially
important once more inequality types are introduced.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D121364
2022-03-18 08:19:10 +00:00
jacquesguan 26c95ae389 [mlir][Math] Add constant folder for sqrt.
Differential Revision: https://reviews.llvm.org/D121980
2022-03-18 16:01:44 +08:00
Nandor Licker 1ebf1afb4f [mlir][SymbolDCE] Track the number of symbols DCE'd
Added a statistic counting the number of erased symbols.

Differential Revision: https://reviews.llvm.org/D121930
2022-03-18 09:23:02 +02:00
Mehdi Amini 71302b6711 Revert "[MLIR][Presburger] introduce SetCoalescer"
This reverts commit dad80e9710.

The build is broken with some configurations (gcc-5 and gcc-8):

mlir/lib/Analysis/Presburger/PresburgerRelation.cpp:402:32: error: qualified name does not name a class before '{' token
 class presburger::SetCoalescer {
2022-03-17 22:50:16 +00:00
Michel Weber dad80e9710 [MLIR][Presburger] introduce SetCoalescer
This patch refactors the current coalesce implementation. It introduces
the `SetCoalescer`, a class in which all coalescing functionality lives.
The main advantage over the old design is the fact that the vectors of
constraints do not have to be passed around, but are implemented as
private fields of the SetCoalescer. This will become especially
important once more inequality types are introduced.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D121364
2022-03-17 19:52:01 +00:00
Benjamin Kramer 548757ba86 [mlir] Move InterfaceMap::InterfaceMap to the cpp file
So we don't end up with a copy of std::sort in every dialect definition.
NFCI.
2022-03-17 20:14:24 +01:00
Benjamin Kramer ba8e336a23 [mlir] Use array_pod_sort for sorting stats/counters.
This isn't performance sensitive and array_pod_sort is a lot smaller.
NFCI.
2022-03-17 20:14:24 +01:00
William S. Moses 164c7afaf5 [MLIR][Math] Add constant folder for powf
Constant fold powf, given two constant operands and a compatible type

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D121845
2022-03-17 14:19:47 -04:00
Uday Bondhugula 54691a58db [MLIR] Add affine.load fold hook on global constant memrefs
Fold affine.load ops on global constant memrefs when indices are all
constant.

Reviewed By: ayzhuang

Differential Revision: https://reviews.llvm.org/D120612
2022-03-17 23:27:43 +05:30
Jim Kitchen 414ed019ac [mlir][sparse] Introduce new binary and unary op
When the sparse_tensor dialect lowers linalg.generic,
it makes inferences about how the operations should
affect the looping logic. For example, multiplication
is an intersection while addition is a union of two
sparse tensors.

The new binary and unary op separate the looping logic
from the computation by nesting the computation code
inside a block which is merged at the appropriate level
in the lowered looping code.

The binary op can have custom computation code for the
overlap, left, and right sparse overlap regions. The
unary op can have custom computation code for the
present and absent values.

Reviewed by: aartbik

Differential Revision: https://reviews.llvm.org/D121018
2022-03-17 12:31:09 -05:00
Ingo Mueller 3a03704fd1 [mlir][docs] Fix formatting issue in Dialects/Vector.md.
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D114165
2022-03-17 16:38:50 +00:00
Amy Zhuang 9842bb0b16 [mlir] Extend SimplifyTrivialLoops
Fold away empty loops that iterate at least once and only return
values defined outside of the loop.

Reviewed By: bondhugula, dcaballe

Differential Revision: https://reviews.llvm.org/D121148
2022-03-17 09:11:24 -07:00
Adrian Kuegel 713c8f6ae5 [mlir] Make header standalone (NFC) 2022-03-17 09:20:18 +01:00
River Riddle 7bc5273367 [mlir][NFC] Move the LSP agnostic files to a new lsp-server directory
This allows for sharing the implementation of key components across multiple
MLIR language servers. These will be used in a followup to help implement
a PDLL language server.

Differential Revision: https://reviews.llvm.org/D121540
2022-03-16 23:40:00 -07:00
River Riddle 943ad665e2 [PDLL] Add proper expansive documentation for PDLL
This commit adds detailed documentation for PDLL, its language design, and
captures a bit of the rationale. This document captures everything in-tree at present,
and is intended to be an all encompassing manual for interacting with and understanding
PDLL.

Differential Revision: https://reviews.llvm.org/D119903
2022-03-16 23:40:00 -07:00
River Riddle 77eee5795e [mlir] Refactor DialectRegistry delayed interface support into a general DialectExtension mechanism
The current dialect registry allows for attaching delayed interfaces, that are added to attrs/dialects/ops/etc.
when the owning dialect gets loaded. This is clunky for quite a few reasons, e.g. each interface type has a
separate tracking structure, and is also quite limiting. This commit refactors this delayed mutation of
dialect constructs into a more general DialectExtension mechanism. This mechanism is essentially a registration
callback that is invoked when a set of dialects have been loaded. This allows for attaching interfaces directly
on the loaded constructs, and also allows for loading new dependent dialects. The latter of which is
extremely useful as it will now enable dependent dialects to only apply in the contexts in which they
are necessary. For example, a dialect dependency can now be conditional on if a user actually needs the
interface that relies on it.

Differential Revision: https://reviews.llvm.org/D120367
2022-03-16 22:15:25 -07:00
Jacques Pienaar 999fb7d045 [mlir][vscode] Don't inject inside strings
Avoids matching R"mlir( while already inside a string.
2022-03-16 21:57:56 -07:00
William S. Moses 57f72ad91d [NFC][MLIR][Affine] Add todo for adding affine namespace 2022-03-16 23:44:52 -04:00
William S. Moses 8670656170 [MLIR][Affine] Expose region-based isTopLevelValue
This PR exposes the region-based isTopLevelValue,
which is useful for other code that performs Affine transformations,
but is not within AffineOps.cpp

Reviewed By: bondhugula

Differential Revision: https://reviews.llvm.org/D121877
2022-03-16 23:43:34 -04:00
William S. Moses 97eedc7443 [MLIR][Affine] Expose getAffineScope as a utility function
The getAffineScope function is currently internal
to AffineOps.cpp. However, as the comment on the function
itself notes, this is useful in a variety of other places
externally. This PR allows other files to use the function.

Reviewed By: bondhugula

Differential Revision: https://reviews.llvm.org/D121827
2022-03-16 23:26:15 -04:00
River Riddle 4a3460a791 [mlir:FunctionOpInterface] Rename the "type" attribute to "function_type"
This removes any potential confusion with the `getType` accessors
which correspond to SSA results of an operation, and makes it
clear what the intent is (i.e. to represent the type of the function).

Differential Revision: https://reviews.llvm.org/D121762
2022-03-16 17:07:04 -07:00
River Riddle 3655069234 [mlir] Move the Builtin FuncOp to the Func dialect
This commit moves FuncOp out of the builtin dialect, and into the Func
dialect. This move has been planned in some capacity from the moment
we made FuncOp an operation (years ago). This commit handles the
functional aspects of the move, but various aspects are left untouched
to ease migration: func::FuncOp is re-exported into mlir to reduce
the actual API churn, the assembly format still accepts the unqualified
`func`. These temporary measures will remain for a little while to
simplify migration before being removed.

Differential Revision: https://reviews.llvm.org/D121266
2022-03-16 17:07:03 -07:00
Martin Erhart f4548ed7fc [mlir] Add C API for ControlFlow dialect
Add basic C API for the ControlFlow dialect. Follows the format of the other dialects.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D121867
2022-03-17 00:29:00 +01:00
River Riddle 50f82e6847 [mlir] Fix missing verification after running an OpToOpAdaptorPass
The current decision of when to run the verifier is running on the
assumption that nested passes can't affect the validity of the parent
operation, which isn't true. Parent operations may attach any number
of constraints on nested operations, which may not necessarily be
captured (or shouldn't be captured) at a smaller granularity.

This commit rectifies this by properly running the verifier after an
OpToOpAdaptor pass. To avoid an explosive increase in compile time,
we only run verification on the parent operation itself. To do this, a
flag to mlir::verify is added to avoid recursive verification if it isn't
desired.

Fixes #54288

Differential Revision: https://reviews.llvm.org/D121836
2022-03-16 14:53:41 -07:00
Siddharth Bhat e83c6aa91e [MLIR] [LangRef] Clarify parsing of dense<...>
dense<...> expects ... to be a tensor-literal.
Define this in the grammar in BuiltinAttributes.td,
and reflect this in the reference grammar written in
AttributeParser.cpp.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D121048
2022-03-16 22:25:52 +05:30
Matthias Springer b59fd8c20a [mlir][bufferize] Update documentation with allow-return-allocs
Differential Revision: https://reviews.llvm.org/D121807
2022-03-16 23:30:09 +09:00
Matthias Springer 1e1eeae840 [mlir][bufferize] Allow non-equivalent yields from scf.for loops
This removes a restriction wrt. scf.for loops during One-Shot Bufferization. Such IR was previously rejected. It is still rejected by default because the bufferized IR could be slow. But such IR can now be bufferized with `allow-return-allocs`.

Differential Revision: https://reviews.llvm.org/D121529
2022-03-16 23:22:06 +09:00
Matthias Springer c076fa1c44 [mlir][bufferize] Deallocate returned buffers with `BufferDeallocation`
New buffer allocations can now be returned/yielded from blocks with `allow-return-allocs`. One-Shot Bufferize deallocates all buffers at the end of the block. If this is not possible (because the buffer escapes the block), this is now done by the existing BufferDeallocation pass.

Differential Revision: https://reviews.llvm.org/D121527
2022-03-16 23:13:34 +09:00
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 8dca38d534 [mlir][bufferize] Support layout maps in bufferization.clone lowering
Differential Revision: https://reviews.llvm.org/D121278
2022-03-16 22:29:22 +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
Sam McCall 75acad41bc Use lit_config.substitute instead of foo % lit_config.params everywhere
This mechanically applies the same changes from D121427 everywhere.

Differential Revision: https://reviews.llvm.org/D121746
2022-03-16 09:57:41 +01:00
MaheshRavishankar 4b644fca08 [mlir][Linalg] Add multi-result op cast test.
https://reviews.llvm.org/D121369 fixed an issue with canonicalizing a
linalg op producer with a cast op consumer. Adding a test to verify
that change.

Reviewed By: hanchung

Differential Revision: https://reviews.llvm.org/D121648
2022-03-16 05:06:20 +00:00
River Riddle 0bf9aabd09 [mlir:OpenMP] Fix memory leak in asan translation
A fake unreachable was created and removed, but never
erased.
2022-03-15 21:54:55 -07:00
Aart Bik f98e1c40ca [mlir][sparse] add one extra index test on f32 matrix
Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D121743
2022-03-15 17:43:30 -07: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 ccfcfa9423 [mlir:Toy][NFC] Switch toy to use prefixed accessors 2022-03-15 17:36:36 -07:00
Bixia Zheng 3580721a59 [mlir][sparse][taco] Support the use of index values in tensor expressions.
PyTACO DSL doesn't support the use of index values as in A[i] = B[i]+ i.
We extend the DSL to support such a use in MLIR-PyTACO.

Remove an obsolete unit test. Add unit tests and PyTACO tests.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D121716
2022-03-15 15:30:55 -07:00
River Riddle ee2c6cd906 [mlir][toy] Define a FuncOp operation in toy and drop the dependence on FuncOp
FuncOp is being moved out of the builtin dialect, and defining a custom
toy operation showcases various aspects of defining function-like operation
(e.g. inlining, passes, etc.).

Differential Revision: https://reviews.llvm.org/D121264
2022-03-15 14:55:51 -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
Ian Bearman 7ecb7efc89 [MLIR] UnknownLoc on Inlinable Calls in LLVMIR Translation
During MLIR translation to LLVMIR if an inlineable call has an UnkownLoc we get this error message:

```
inlinable function call in a function with debug info must have a !dbg location
  call void @callee()
```

There is code that checks for this case and strips debug information to avoid this situation. I'm expanding this code to handle the case where an debug location points at a UnknownLoc. For example, a NamedLoc whose child location is an UnknownLoc.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D121633
2022-03-15 14:48:50 -07:00
Nirvedh 59582adc3d [MLIR][Linalg] Canonicalization patterns for linalg.generic.
Fold linalg.fill into linalg.generic.
Remove dead arguments used in linalg.generic.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D121535
2022-03-15 18:48:02 +00:00
Aart Bik 1f3c482b76 [mlir][sparse] more test cases for linalg.index
Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D121660
2022-03-15 10:30:54 -07:00
Bixia Zheng 3a4229696d [mlir][sparse][taco] Reorder a class.
Define IndexExpr before IndexVar. This is to prepare for the next change
to support the use of index values in tensor expressions.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D121649
2022-03-15 08:51:22 -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
Matthias Springer 76b1601001 [mlir][bufferize] Fix config not passed to greedy rewriter
Also add a TODO to switch to a custom walk instead of the GreedyPatternRewriter, which should be more efficient. (The bufferization pattern is guaranteed to apply only a single time for every op, so a simple walk should suffice.)

We currently specify a top-to-bottom walk order. This is important because other walk orders could introduce additional casts and/or buffer copies. These canonicalize away again, but it is more efficient to never generate them in the first place.

Note: A few of these canonicalizations are not yet implemented.

Differential Revision: https://reviews.llvm.org/D121518
2022-03-15 17:32:38 +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 84d2549e82 [mlir] Rewrite and modernize the documentation for defining Attributes/Types
The current documentation is super old, crusty, and at times wrong. This commit
rewrites the documentation to focus on the TableGen declarative definition,
expounds on various components, and moves the doc out of Tutorials/ and into
a new top level `AttributesAndTypes.md` doc. As part of this, the AttrDef/TypeDef
documentation in OpDefinitions.md is removed.

Differential Revision: https://reviews.llvm.org/D120011
2022-03-15 00:19:52 -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
Mogball 4767e26775 [mlir][ods] Add support for custom directive in attr/type formats
This patch adds support for custom directives in attribute and type formats. Custom directives dispatch calls to user-defined parser and printer functions.

For example, the assembly format "custom<Foo>($foo, ref($bar))" expects a function with the signature

```
LogicalResult parseFoo(AsmParser &parser, FailureOr<FooT> &foo, BarT bar);
void printFoo(AsmPrinter &printer, FooT foo, BarT bar);
```

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D120944
2022-03-15 07:15:15 +00: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
Thomas Raoux 6d007e0278 [mlir][nvvm] Fix bug in ldmatrix intrinsic conversion
The ldmatrix intrinsic trans option was inverted.

Bug found by @christopherbate!

Differential Revision: https://reviews.llvm.org/D121666
2022-03-15 05:04:09 +00:00
Stella Laurenzo 0c3156bd43 NFC: Remove unterminated string from Python pyi file. 2022-03-14 14:10:38 -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
Matthias Springer 975284ab4b [mlir][bufferization] Update public MLIR documentation
Differential Revision: https://reviews.llvm.org/D121071
2022-03-14 22:13:41 +09: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
gysit f2f89751e4 [mlir][linalg] Use explicit replace in canonicalization pattern (NFC).
Introduce an explicit `replaceOp` call to enable the tracking of the producer LinalgOp.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D121369
2022-03-14 07:09:51 +00:00
Mehdi Amini 03078ec20b Remove include_directories() from cmake `mlir_tablegen()` function (NFC)
This is present since the beginning, but does not seem needed by any
in-tree target right now. This seems like the kind of thing to populate
by the caller if needed.

Differential Revision: https://reviews.llvm.org/D121565
2022-03-14 04:36:24 +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
chhzh123 036088fd6e [MLIR][Python] Add SCFIfOp Python binding
Current generated Python binding for the SCF dialect does not allow
users to call IfOp to create if-else branches on their own.
This PR sets up the default binding generation for scf.if operation
to address this problem.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D121076
2022-03-13 05:24:10 +00:00
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
Uday Bondhugula aea31f62d4 [MLIR] Fix block label parsing bug
Fix bug in `Block` label parsing:
https://github.com/llvm/llvm-project/issues/54343

The `parseOptionalBlockArgList` method was doing the wrong thing
(contrary to its doc comment) and its calling context was also
incorrect. This led to a parse failure for something like "^bb0()".

Fixes #54343

Differential Revision: https://reviews.llvm.org/D121503
2022-03-12 20:32:41 +05:30
Jacques Pienaar a547028d46 [mlir] Update function referenced in comment (NFC) 2022-03-11 16:36:47 -08:00
Petr Hosek 0c0f6cfb7b [CMake] Rename TARGET_TRIPLE to LLVM_TARGET_TRIPLE
This clarifies that this is an LLVM specific variable and avoids
potential conflicts with other projects.

Differential Revision: https://reviews.llvm.org/D119918
2022-03-11 15:43:01 -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
Fangrui Song bd0bddc1ea [CommandLine] Remove `may only occur zero or one times!` error
Early adoption of new technologies or adjusting certain code generation/IR optimization thresholds
is often available through some cl::opt options (which have unstable surfaces).
Specifying such an option twice will lead to an error.

```
% clang -c a.c -mllvm -disable-binop-extract-shuffle -mllvm -disable-binop-extract-shuffle
clang (LLVM option parsing): for the --disable-binop-extract-shuffle option: may only occur zero or one times!
% clang -c a.c -mllvm -hwasan-instrument-reads=0 -mllvm -hwasan-instrument-reads=0
clang (LLVM option parsing): for the --hwasan-instrument-reads option: may only occur zero or one times!
% clang -c a.c -mllvm --scalar-evolution-max-arith-depth=32 -mllvm --scalar-evolution-max-arith-depth=16
clang (LLVM option parsing): for the --scalar-evolution-max-arith-depth option: may only occur zero or one times!
```

The option is specified twice, because there is sometimes a global setting and
a specific file or project may need to override (or duplicately specify) the
value.

The error is contrary to the common practice of getopt/getopt_long command line
utilities that let the last option win and the `getLastArg` behavior used by
Clang driver options. I have seen such errors for several times. I think the
error just makes users inconvenient, while providing very little value on
discouraging production usage of unstable surfaces (this goal is itself
controversial, because developers might not want to commit to a stable surface
too early, or there is just some subtle codegen toggle which is infeasible to
have a driver option). Therefore, I suggest we drop the diagnostic, at least
before the diagnostic gets sufficiently better support for the overridding needs.

Removing the error is a degraded error checking experience. I think this error
checking behavior, if desirable, should be enabled explicitly by tools. Users
preferring the behavior can figure out a way to do so.

Reviewed By: jhenderson, rnk

Differential Revision: https://reviews.llvm.org/D120455
2022-03-11 11:25:04 -08: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
Bixia Zheng 30c5269d93 [mlir][sparse][taco] Add a few unary operations.
Add operations -, abs, ceil and floor to the index notation.

Add test cases.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D121388
2022-03-11 08:08:55 -08:00
Yun Long 5c3861b277 [MLIR][python binding] Add OpaqueAttribute to python binding.
Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D120847
2022-03-11 10:56:21 +01: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
wren romano 3734c0783e [mlir][sparse] Improving error messages for openSparseTensorCOO
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D121333
2022-03-10 11:48:19 -08: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 a1ac771247 [MLIR][OpenMP][NFC] Move the modifier testcases to correct directory
This patch moves the testcases from
`mlir/test/Target/LLVMIR/openmp-llvm-bad-schedule-modifier.mlir` to
`mlir/test/Dialect/OpenMP/invalid.mlir` as they test the verifier
(not the translation to LLVM IR).

Reviewed By: NimishMishra

Differential Revision: https://reviews.llvm.org/D120877
2022-03-10 21:32:00 +05:30
John Demme cb318526b0 [MLIR] [CMake/Python] Fix ignored Python3_EXECUTABLE
On Windows (at least), cmake ignores Python3_EXECUTABLE unless the
'Interpreter' component is being found. If the user is specifying a
different version than the latest installed (say, 3.8 vs 3.9) with the
Python3_EXECUTABLE, cmake was using a combination of the newest version
and the desired version. Mitigated by adding 'Interpreter' in the first
invocation like the second one.
2022-03-10 07:43:43 -08: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
Michel Weber 06eb057738 [MLIR][Presburger] fix vector update in coalesce
When `addCoalescedPolyhedron` was called with `j == n - 1`,
the `polyhedrons`-vector was not properly updated (the
`IntegerPolyhedron` at position `n - 2` was "lost"). This patch adds
special handling to that case and a regression testcase.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D121356
2022-03-10 15:42:11 +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
Aart Bik 0123d2a9fe [mlir][sparse] add end2end test for linalg.dot sparsification
Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D121344
2022-03-09 16:05:53 -08:00
Aart Bik 52fb4f53c2 [mlir][sparse] added linalg.dot to sparse kernel collection
Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D121315
2022-03-09 15:10:44 -08:00
Shraiysh Vaishay 7c385c4b2f [mlir][OpenMP] Generating enums in accordance with the guidelines
This patch changes the enums generated from `OMP.td` for MLIR according
to the enum naming guidelines in LLVM Coding Standards.

This also helps the issues we had with `static` being a C++ keyword and
also a value for the schedule clause.

Enumerator naming guidelines: https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D120825
2022-03-09 20:10:45 +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
Amy Zhuang 6edfb628f9 [mlir] Extend AffineForEmptyLoopFolder
Currently when we fold an empty loop, we assume that any loop
with iterArgs returns its iterArgs in order, which is not always
the case. It may return values defined outside of the loop or
return its iterArgs out of order. This patch adds support to
those cases.

Reviewed By: dcaballe

Differential Revision: https://reviews.llvm.org/D120776
2022-03-08 17:17:22 -08: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
River Riddle 8de6260a20 [mlir:toy][NFC] Add comment blocks for toy operations. 2022-03-08 16:22:38 -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
Lei Zhang 55a4df9c14 [mlir][spirv] Handle another form of folding comparsion into clamp
Reviewed By: hanchung

Differential Revision: https://reviews.llvm.org/D121227
2022-03-08 15:53:22 -05:00
Mehdi Amini b389d68e52 Revert "Fix link of libmlir.so by adding ExecutionEngine as dependency to GPUTransforms"
This reverts commit b743850b73.

This didn't produce the expected result.
2022-03-08 20:40:36 +00:00
Mehdi Amini b743850b73 Fix link of libmlir.so by adding ExecutionEngine as dependency to GPUTransforms
This feels like a layering violation, but it fixes the build.

Fixes #54242

tools/mlir/lib/Dialect/GPU/CMakeFiles/obj.MLIRGPUTransforms.dir/Transforms/SerializeToHsaco.cpp.o:SerializeToHsaco.cpp:function (anonymous namespace)::SerializeToHsacoPass::optimizeLlvm(llvm::Module&, llvm::TargetMachine&):
error: undefined reference to 'mlir::makeOptimizingTransformer(unsigned int, unsigned int, llvm::TargetMachine*)'
2022-03-08 20:33:03 +00:00
River Riddle 47e3f94636 [mlir][SCF] Replace use of FuncOp with FunctionOpInterface
There is nothing specific to FuncOp about the check, it can be changed
to be interface based.

Differential Revision: https://reviews.llvm.org/D121194
2022-03-08 12:25:32 -08: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
Mahesh Ravishankar f740bdbd2d [mlir][Linalg] Modify `InferStaticShapeOfOperands` to work on Linalg Ops.
Commit rG1a2bb03edab9d7aa31beb587d0c863acc6715d27 introduced a pattern
to convert dynamic dimensions in operands of `GenericOp`s to static
values based on indexing maps and shapes of other operands. The logic
is directly usable to any `LinalgOp`. Move that pattern as an
`OpInterfaceRewritePattern`.

Differential Revision: https://reviews.llvm.org/D120968
2022-03-08 18:54:45 +00: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 f345f7e30b [mlir][OpDSL] Support pointwise ops with rank zero inputs.
Allow pointwise operations to take rank zero input tensors similarly to scalar inputs. Use an empty indexing map to broadcast rank zero tensors to the iteration domain of the operation.

Depends On D120734

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D120807
2022-03-08 17:39:47 +00: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 f4939d5618 [mlir][OpDSL] Simplify index and constant tests.
Simplify tests that use `linalg.fill_rng_2d` to focus on testing the `const` and `index` functions. Additionally, cleanup emit_misc.py to use simpler test functions and fix an error message in config.py.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D120734
2022-03-08 17:11:03 +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
Christian Sigg dfaadf6b12 Update more `parseSourceString()` call sites.
Change to non-deprecated function template (see D121075).

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D121102
2022-03-08 13:25:54 +01:00
Lorenzo Chelini f3e1dcc5df [MLIR][Presburger] Silence warnings in GCC (NFC)
Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D121205
2022-03-08 12:38:59 +01:00
Matthias Springer d1d79920f7 [mlir][bufferize][NFC] Better error messages if analysis fails
Differential Revision: https://reviews.llvm.org/D121203
2022-03-08 19:45:00 +09:00
Javier Setoain f2b89c7ae0 [mlir][Vector] Use create_mask in transfer mask materializations
Currently, the transfer mask is materialized by generating the vector
comparison: [offset + 0, .., offset + length - 1] < [dim, .., dim]

A better alternative is to materialize the transfer mask by using the
operation: `vector.create_mask (dim - offset)`, which will generate
simpler code and compose better with scalable vectors.

Differential Revision: https://reviews.llvm.org/D120487
2022-03-08 09:02:50 +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 11a7635b30 [mlir][NFC] Properly include PassDetail.h for FoldSubViewOpsPass 2022-03-08 00:08:39 -08:00
River Riddle 043f4e3b33 [mlir][NFC] Remove dead forward declaration of FuncOp 2022-03-08 00:08:39 -08:00
Lorenzo Chelini b204ce0ca8 [MLIR][OpDSL] Silence warning (NFC) 2022-03-08 08:33:17 +01:00
Uday Bondhugula da93537bf8 NFC. Improve isInnermostAffineForOp - drop unnecessary check
Rewrite isInnermostAffineForOp utility to make it more direct/efficient.
Drop unnecessary check. NFC.

Differential Revision: https://reviews.llvm.org/D121170
2022-03-08 10:44:54 +05:30
Bixia Zheng 5b87e0521d [mlir][sparse][taco] Split the evaluate method into compile and compute.
This is to align with the PyTACO API better.

Modify an existing unit test to test the new routines.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D121083
2022-03-07 16:58:41 -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
Hanhan Wang 1538bd518c [mlir][Vector] Add patterns to reorder elementwise ops and broadcast/transpose ops.
In quantized comutation, there are casting ops around computation ops.
Reorder the ops to make reduce-to-contract actually work.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D120760
2022-03-07 12:52:12 -08:00
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
Bixia Zheng 4b7745c176 [mlir][sparse][taco] Add more unit tests.
These unit tests resides in an internal repository. Porting the tests to the
public repository.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D121021
2022-03-07 10:10:01 -08:00
Diego Caballero 917d95fc8a [mlir][Vector] Improve default lowering of vector transpose operations
The default lowering of vector transpose operations generates a large sequence of
scalar extract/insert operations, one pair for each scalar element in the input tensor.
In other words, the vector transpose is scalarized. However, there are transpose
patterns where one or more adjacent high-order dimensions are not transposed (for
example, in the transpose pattern [1, 0, 2, 3], dimensions 2 and 3 are not transposed).
This patch improves the lowering of those cases by not scalarizing them and extracting/
inserting a full n-D vector, where 'n' is the number of adjacent high-order dimensions
not being transposed. By doing so, we prevent the scalarization of the code and generate a
more performant vector version.

Paradoxically, this patch shouldn't improve the performance of transpose operations if
we are using LLVM. The LLVM pipeline is able to optimize away some of the extract/insert
operations and the SLP vectorizer is converting the scalar operations back to its vector
form. However, scalarizing a vector version of the code in MLIR and relying on the SLP
vectorizer to reconstruct the vector code again is highly undesirable for several reasons.

Reviewed By: nicolasvasilache, ThomasRaoux

Differential Revision: https://reviews.llvm.org/D120601
2022-03-07 17:56:02 +00:00
Benjamin Kramer 03ed395149 [mlir] Add missing override keyword. NFC. 2022-03-07 17:58:32 +01: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
Uday Bondhugula 9b740c035c Update normalizeAffineFor to canonicalize maps/operands before using them
Update normalizeAffineFor utility to canonicalize maps and operands
before using them.

Differential Revision: https://reviews.llvm.org/D121086
2022-03-07 18:49:50 +05:30
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 ebd9f44584 Partially revert 03e6d10cac86: it broke the build 2022-03-07 11:18:20 +00:00
Mehdi Amini c9f2beff35 Revert "Apply clang-tidy fixes for bugprone-macro-parentheses to MLIR (NFC)"
This reverts commit 393c6db7a1.
This broke the build.
2022-03-07 11:11:26 +00:00
Mehdi Amini e1f389a89f Apply clang-tidy fixes for readability-simplify-boolean-expr to MLIR (NFC) 2022-03-07 10:41:45 +00:00
Mehdi Amini 03e6d10cac Apply clang-tidy fixes for readability-identifier-naming to MLIR (NFC) 2022-03-07 10:41:45 +00:00
Mehdi Amini 51894cbb2e Apply clang-tidy fixes for performance-unnecessary-value-param to MLIR (NFC) 2022-03-07 10:41:45 +00:00
Mehdi Amini cc96d2d6bc Apply clang-tidy fixes for modernize-use-emplace to MLIR (NFC) 2022-03-07 10:41:44 +00:00
Mehdi Amini 671e30a12f Apply clang-tidy fixes for modernize-use-default-member-init to MLIR (NFC) 2022-03-07 10:41:44 +00:00
Mehdi Amini e6e36b9c20 Apply clang-tidy fixes for modernize-loop-convert to MLIR (NFC) 2022-03-07 10:41:44 +00:00
Mehdi Amini cfdf9747bf Apply clang-tidy fixes for llvm-qualified-auto to MLIR (NFC) 2022-03-07 10:41:44 +00:00
Mehdi Amini 393c6db7a1 Apply clang-tidy fixes for bugprone-macro-parentheses to MLIR (NFC) 2022-03-07 10:41:44 +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
Adrian Kuegel ef193a7a7c [mlir] Use empty() instead of checking size() == 0 (NFC) 2022-03-07 09:41:43 +01: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
William S. Moses 87ec6f41bb [OpenMPIRBuilder] Allocate temporary at the correct block in a nested parallel
The OpenMPIRBuilder has a bug. Specifically, suppose you have two nested openmp parallel regions (writing with MLIR for ease)

```
omp.parallel {
  %a = ...
  omp.parallel {
    use(%a)
  }
}
```

As OpenMP only permits pointer-like inputs, the builder will wrap all of the inputs into a stack allocation, and then pass this
allocation to the inner parallel. For example, we would want to get something like the following:

```
omp.parallel {
  %a = ...
  %tmp = alloc
  store %tmp[] = %a
  kmpc_fork(outlined, %tmp)
}
```

However, in practice, this is not what currently occurs in the context of nested parallel regions. Specifically to the OpenMPIRBuilder,
the entirety of the function (at the LLVM level) is currently inlined with blocks marking the corresponding start and end of each
region.

```
entry:
  ...

parallel1:
  %a = ...
  ...

parallel2:
  use(%a)
  ...

endparallel2:
  ...

endparallel1:
  ...
```

When the allocation is inserted, it presently inserted into the parent of the entire function (e.g. entry) rather than the parent
allocation scope to the function being outlined. If we were outlining parallel2, the corresponding alloca location would be parallel1.

This causes a variety of bugs, including https://github.com/llvm/llvm-project/issues/54165 as one example.

This PR allows the stack allocation to be created at the correct allocation block, and thus remedies such issues.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D121061
2022-03-06 18:34:25 -05: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
Groverkss ae2764e835 [MLIR][Presburger][NFC] Fix PresburgerLocalSpace::print() output
This change puts a colon before before the printing number of locals in
PresburgerLocalSpace::print().
2022-03-06 16:42:20 +05:30
Benjamin Kramer f5d578847d Drop iostream include, which is forbidden in LLVM 2022-03-05 19:32:05 +01: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
Aart Bik 988d4b0d62 [mlir][sparse] fix mlir-window build breakage
Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D121022
2022-03-04 14:29:07 -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 9d6c2ffcaa [mlir] NFC fix missing dependency on Async 2022-03-04 21:58:39 +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
wren romano 289f84a4a2 [mlir][sparse] Rename add{Pointer,Index} to append{Pointer,Index}
This clarifies that these methods only work in append mode, not for general insertions.  This is a prospective change towards https://github.com/llvm/llvm-project/issues/51652 which also performs random-access insertions, so we want to avoid confusion.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D120929
2022-03-04 12:03:24 -08:00
Krzysztof Drewniak 4e817b3fa3 [MLIR][AMDGPU] Fix typo and add comment to SerializeToHsaco
Reviewed By: bondhugula

Differential Revision: https://reviews.llvm.org/D120943
2022-03-04 17:15:11 +00:00
William S. Moses 62f84c73d2 [MLIR][SCF] Allow combining subsequent if statements that yield & negated condition
This patch extends the existing if combining canonicalization to also handle the case where a value returned by the first if is used within the body of the second if.

This patch also extends if combining to support if's whose conditions are logical negations of each other.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D120924
2022-03-04 12:07:47 -05:00
William S. Moses 1d1791572c [MLIR][MemRef] Ensure alloca_scope is inlined with no allocating ops
Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D120841
2022-03-04 11:58:59 -05:00
Michel Weber 21dc4ad56a [MLIR][Presburger] skip IntegerPolyhedrons with LocalIds in coalesce
This patch makes coalesce skip the comparison of all pairs of IntegerPolyhedrons with LocalIds rather than crash. The heuristics to handle these cases will be upstreamed later on.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D120995
2022-03-04 16:12:04 +00:00
William S. Moses 4a94a33ca6 [MLIR][LLVM] Fold extractvalue to ignore insertvalue at distinct index
We can simplify an extractvalue of an insertvalue to extract out of the base of the insertvalue, if the insert and extract are at distinct and non-prefix'd indices

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D120915
2022-03-04 11:03:34 -05:00
Michel Weber d1a051f926 [MLIR][Presburger] support a heuristic for the "cut case" in coalesce
This patch introduces the cut case. If one polytope has only cutting and
redundant inequalities for the other and the facet of the cutting
inequalities are contained within the other polytope, then the polytopes are
be combined into a polytope consisting only of their respective
redundant constraints.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D120614
2022-03-04 13:02:36 +05:30
River Riddle 05b8dda1f2 [PDLL] Attempt to fix shared libraries build
PDLLParser now depends on TableGen, which disables LLVM_DYLIB
2022-03-03 20:20:45 -08: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 99357f2ed3 [PDLL] Specify LLVM_LINK_COMPONENTS using LINK_COMPONENTS 2022-03-03 19:05:57 -08: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
Krzysztof Drewniak d7f9220bb6 [MLIR] [AMDGPU] Use correct flags when building SerializeToHsaco
The SerializeToHsaco pass does not depend on ROCm being available on
the build system - it only requires ROCm to be present at runtime.
However, the CMake file that built it tested for
MLIR_ENABLE_ROCM_RUNNER , which implies that ROCm is currently
available and is used to control building ROCm integration tests.

Referencing MLIR_ENABLE_ROCM_RUNNER instead of
MLIR_ENABLE_ROCM_CONVERSIONS in the SerializeToHsaco build therefore
causes problems for clients who wish to build projects that depend on
this pass on a system without an AMD GPU present.

Reviewed By: whchung

Differential Revision: https://reviews.llvm.org/D120663
2022-03-03 21:44:26 +00: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 6fc753adaf [mlir][bufferize] Always bufferize top-to-bottom
This ensures that we generate memref types with matching layout maps. (Especially when using partial bufferization passes.)

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

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

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

Reviewed By: shraiysh

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

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

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

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

Reviewed By: jpienaar

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

Reviewed By: ftynse

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

Reviewed By: ftynse

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

Reviewed By: ftynse

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

Reviewed By: ftynse

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

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

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

Reviewed By: arjunp

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

Depends On D120739

Reviewed By: wsmoses

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

Depends On D120737

Reviewed By: wsmoses

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

Reviewed By: wsmoses

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

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

Reviewed By: NimishMishra, rriddle

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

Reviewed By: bixia

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

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

Modify an existing test to test the situation.

Reviewed By: aartbik

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

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

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

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

Reviewed By: stella.stamenova

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

Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D120765
2022-03-01 14:52:56 -08:00
River Riddle 026fe5ffc3 [mlir][NFC] Remove several dead references to the old standard dialect 2022-03-01 14:02:24 -08:00
River Riddle 2f5715dc78 [mlir][NFC] Rename the old Standard dialect test directory to Func
The remanants of Standard was renamed to Func, but the test directory
remained named as Standard. In adidition to fixing the name, this commit
also moves the tests for operations not in the Func dialect to the proper
parent dialect test directory.
2022-03-01 13:48:34 -08:00
River Riddle 1f971e23f0 [mlir] Trim a huge number of unnecessary dependencies on the Func dialect
The Func has a large number of legacy dependencies carried over from the old
Standard dialect, which was pervasive and contained a large number of varied
operations. With the split of the standard dialect and its demise, a lot of lingering
dead dependencies have survived to the Func dialect. This commit removes a
large majority of then, greatly reducing the dependence surface area of the
Func dialect.
2022-03-01 12:10:04 -08:00
River Riddle 23aa5a7446 [mlir] Rename the Standard dialect to the Func dialect
The last remaining operations in the standard dialect all revolve around
FuncOp/function related constructs. This patch simply handles the initial
renaming (which by itself is already huge), but there are a large number
of cleanups unlocked/necessary afterwards:

* Removing a bunch of unnecessary dependencies on Func
* Cleaning up the From/ToStandard conversion passes
* Preparing for the move of FuncOp to the Func dialect

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

Differential Revision: https://reviews.llvm.org/D120624
2022-03-01 12:10:04 -08:00
rdzhabarov 2e32525d95 [mlir] Fix unused var warning in the IR/MemRefOps.cpp
Fix unused var compiler warning.

Reviewed By: Mogball

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

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

Modify PyTACO to reflect this change.

Reviewed By: aartbik

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

Reviewed By: ftynse

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

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

Reviewed By: wsmoses, bondhugula

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

Depends On D120110

Reviewed By: aartbik

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

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

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

Depends On D120109

Reviewed By: nicolasvasilache, aartbik

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

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

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

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

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

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

Reviewed By: ThomasRaoux

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

Reviewed By: ThomasRaoux

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

Reviewed By: quinnp, rdzhabarov

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

Reviewed By: nicolasvasilache

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

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D120533
2022-02-28 14:22:43 +05:30
Alexander Belyaev 1a829d2d06 [mlir] Purge linalg.tiled_loop.
Differential Revision: https://reviews.llvm.org/D119415
2022-02-28 09:05:18 +01:00
Mehdi Amini fdfe26ddbe Add explicit capture for `this` pointer in attempt to fix gcc5 build (NFC) 2022-02-27 21:41:23 +00:00