Commit Graph

11290 Commits

Author SHA1 Message Date
Benjamin Kramer e497871356 [mlir][complex] Add pow/sqrt/tanh ops and lowering to libm
Lowering through libm gives us a baseline version, even though it's not
going to be particularly fast. This is similar to what we do for some
math dialect ops.

Differential Revision: https://reviews.llvm.org/D125550
2022-05-18 14:03:14 +02:00
Frederik Gossen 6d36cfed3b [MLIR] Make `parseDimensionListRanked` configurable wrt parsing a trailing `x`
Differential Revision: https://reviews.llvm.org/D125797
2022-05-18 05:42:35 -04:00
River Riddle aa568e082b [mlir:GreedyDriver] Return WalkResult::skip after deleting a known constant
This avoids use-after-free when trying to access the regions after visiting
the operation.
2022-05-18 02:14:02 -07:00
rkayaith 7814b559bd [GreedyPatternRewriter] Avoid reversing constant order
The previous fix from af371f9f98 only applied when using a bottom-up
traversal. The change here applies the constant preprocessing logic to the
top-down case as well. This resolves the issue with the canonicalizer pass still
reordering constants, since it uses a top-down traversal by default.

Fixes #51892

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D125623
2022-05-18 00:55:59 -07:00
rkayaith ebad5fb309 [mlir][Canonicalize] Fix command-line options
The canonicalize command-line options currently have no effect, as the pass is
reading the pass options in its constructor, before they're actually
initialized. This results in the default values of the options always being used.

The change here moves the initialization of the `GreedyRewriteConfig` out of the
constructor, so that it runs after the pass options have been parsed.

Fixes #55466

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D125621
2022-05-18 00:28:18 -07:00
River Riddle 17e2e7b788 [mlir:PDLL] Don't append / for directory code completion
This allows for properly using / as a trigger character, i.e.
more easily allows chaining include directory completions.
2022-05-18 00:23:47 -07:00
River Riddle 6d4471efb0 [mlir:PDLL] Improve the location ranges of several expressions during parsing
This allows for the range to encompass more of the source associated
with the full expression, making diagnostics easier to see/tooling easier/etc.
2022-05-18 00:23:47 -07:00
River Riddle e213e5a999 [mlir:PDLL] Drop space as a completion commit character
This causes annoyances when attempting to use space as
a trigger character (to start a different completion).
2022-05-18 00:23:47 -07:00
Groverkss e00cbbec06 [MLIR][Presburger] Cleanup getMaybeValues in FACV
This patch cleans up multiple getMaybeValue functions to take an IdKind instead
of special functions.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D125617
2022-05-18 09:44:14 +05:30
Groverkss 862b5a5233 [MLIR][Presburger] Attach values only to non-local identifiers in FAVC
This patch changes `FlatAffineValueConstraints` to only allow attaching
values to non-local identifiers.

The reasoning for this change is:
1. Information attached to local identifiers can be lost since local identifiers
  can be removed for output size optimizations.
2. There are no current use cases for attaching values to Local identifiers.
3. Attaching a value to a local identifier does not make sense since a local
  identifier represents existential quantification.

This patch also adds some additional asserts to the affected functions.

Reviewed By: arjunp, bondhugula

Differential Revision: https://reviews.llvm.org/D125613
2022-05-18 09:17:23 +05:30
Robert Suderman 9294a1e9a8 [mlir][tosa] Rework tosa.apply_scale lowering for 32-bit
Added handling rounding behavior in 32-bits for when possible. This
avoids kernel compilation generating scalarized code on platforms where
64-bit vectors are not available.

As the 48-bit lowering requires 64-bit anyway, we added a full 64-bit
solution simplifying the old path.

Reviewed By: dcaballe, mravishankar

Differential Revision: https://reviews.llvm.org/D125583
2022-05-17 16:01:12 -07:00
Matthias Springer 996834e681 [mlir][SCF] Fix scf.while bufferization
Before this fix, the bufferization implementation made the incorrect assumption that the values yielded from the "before" region must match with the values yielded from the "after" region.

Differential Revision: https://reviews.llvm.org/D125835
2022-05-18 00:35:50 +02:00
jfurtek 5c3b20520b [mlir] Update LLVMIR Fastmath flags use of MLIR BitEnum functionality
This diff updates the LLVMIR dialect Fastmath flags attribute to use recently
added features of `BitEnum` attributes. Specifically, this diff uses the bit
enum "group" case to represent the `fast` value as an alias for a combination
of other values (`ninf`, `nnan`, ...), instead of using a separate integer
value. (This is in line with LLVM's fastmath flags representation.) This diff
also leverages the `printBitEnumPrimaryGroups` `tblgen` field for concise
enum printing.

The `BitEnum` features were developed for an upcoming diff that adds `fastmath`
support to the arithmetic dialect. This diff simply applies some of the relevant
new features to the LLVM dialect attribute.

Reviewed By: ftynse, Mogball

Differential Revision: https://reviews.llvm.org/D124720
2022-05-17 18:19:14 +00:00
Min-Yih Hsu 0b168a49bf [mlir][LLVMIR] Use a new way to verify GEPOp indices
Previously, GEPOp relies on `findKnownStructIndices` to check if a GEP
index should be static. The truth is, `findKnownStructIndices` can only
tell you a GEP index _might_ be indexing into a struct (which should use
a static GEP index). But GEPOp::build and GEPOp::verify are falsely
taking this information as a certain answer, which creates many false
alarms like the one depicted in
`test/Target/LLVMIR/Import/dynamic-gep-index.ll`.

The solution presented here adopts a new verification scheme: When we're
recursively checking the child element types of a struct type, instead
of checking every child types, we only check the one dictated by the
(static) GEP index value. We also combine "refinement" logics --
refine/promote struct index mlir::Value into constants -- into the very
verification process since they have lots of logics in common. The
resulting code is more concise and less brittle.

We also hide GEPOp::findKnownStructIndices since most of the
aforementioned logics are already encapsulated within GEPOp::build and
GEPOp::verify, we found little reason for findKnownStructIndices (or the
new findStructIndices) to be public.

Differential Revision: https://reviews.llvm.org/D124935
2022-05-17 10:28:44 -07:00
Cullen Rhodes 6ad6b00f6a [mlir] vim: add bf16 type 2022-05-17 13:28:31 +00:00
Cullen Rhodes 9bb0f4616a [mlir][licm] Fix debug output with newlines 2022-05-17 13:28:30 +00:00
David Spickett 9e469ced42 [mlir][Tablegen-LSP] Don't link with llvm dylib
This updates 5de12bb703
to not link with the dylib since that does not include
the tablegen library.

Should fix flang dylib build failures:
https://lab.llvm.org/buildbot/#/builders/177/builds/5120
2022-05-17 11:03:01 +00:00
Alex Zinenko 1075c8ca49 [mlir] support isa/cast/dyn_cast<Operation *>(operation) again
The support for this has been added by 946311b893
but then ignored by bc22b5c9a2.

This enables one to write generic code that can be instantiated for both
specific operation classes and the common base class without
specialization. Examples include functions that take/return ops, such
as:

```mlir
template <typename FnTy>
void applyIf(FnTy &&lambda, ...) {
  for (Operation *op : ...) {
    auto specific = dyn_cast<function_traits<FnTy>::template arg_t<0>>(op);
    if (specific)
      lambda(specific);
  }
}
```

that would otherwise need to rely on template specialization to support
lambdas that take specific operations and those that take `Operation *`.

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

Reviewed by: rriddle
2022-05-17 11:15:17 +02:00
jacquesguan 9b519f416b [mlir][LLVMIR] Add support for translating insertelement/extractelement.
Add support for translating llvm::InsertElement and llvm::ExtractElement.

Differential Revision: https://reviews.llvm.org/D125674
2022-05-17 03:18:31 +00:00
wren romano bfadd13df4 [mlir][sparse] Moved _mlir_ciface_newSparseTensor closer to its macros
This is a followup to D125431, to keep from confusing the machinery that generates diffs (since combining these two changes into one would obfuscate the changes actually made in the previous differential).

Depends On D125431

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D125432
2022-05-16 17:53:25 -07:00
River Riddle 6593886a35 [mlir][NFC] Fix the tags for various doc code blocks 2022-05-16 16:46:13 -07:00
River Riddle 1febbd67aa [mlir][PDLL] Tweak the grammar to highlight partial code better
This commit enables proper highlighting when inner statements are
outside of a constraint/pattern/etc. This shouldn't really happen in
actual code, but can happen in documentation (which uses the same
syntax grammar).
2022-05-16 16:46:13 -07:00
wren romano 1313f5d307 [mlir][sparse] Restyling macros in the runtime library
In addition to reducing code repetition, this also helps ensure that the various API functions follow the naming convention of mlir::sparse_tensor::primaryTypeFunctionSuffix (e.g., due to typos in the repetitious code).

Depends On D125428

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D125431
2022-05-16 16:43:39 -07:00
River Riddle 9f39867b10 [mlir][NFC] Fix a few langref typos 2022-05-16 16:23:01 -07:00
River Riddle 5de12bb703 [mlir][Tablegen-LSP] Add support for a basic TableGen language server
This follows the same general structure of the MLIR and PDLL language
servers. This commits adds the basic functionality for setting up the server,
and initially only supports providing diagnostics. Followon commits will
build out more comprehensive behavior.

Realistically this should eventually live in llvm/, but building in MLIR is an easier
initial step given that:
* All of the necessary LSP functionality is already here
* It allows for proving out useful language features (e.g. compilation databases)
  without affecting wider scale tablegen users
* MLIR has a vscode extension that can immediately take advantage of it

Differential Revision: https://reviews.llvm.org/D125440
2022-05-16 16:03:51 -07:00
wren romano 7694442011 [mlir][sparse] Adding "final" keyword wherever appropriate
This enables the compiler to perform devirtualization.  And benchmarks
indicate devirtualization can sometimes give considerable speedup.

Depends On D122061

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D125428
2022-05-16 15:43:37 -07:00
wren romano 8cb332406c [mlir][sparse] Enhancing sparse=>sparse conversion.
Fixes: https://github.com/llvm/llvm-project/issues/51652

Depends On D122060

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D122061
2022-05-16 15:42:19 -07:00
River Riddle e0c3b94c80 [mlir] Restrict dialect doc gen to a single dialect
In the overwhelmingly majority of cases only one dialect is generated at a time
anyways, and this restriction more easily catches user error when multiple
dialects might be generated. We hit this semi-recently with the PDL dialect,
and circt+other downstream users are also actively hitting this as well.

Differential Revision: https://reviews.llvm.org/D125651
2022-05-16 15:35:07 -07:00
Alex Zinenko 18fc395909 [mlir] allow for re-registering extension ops
Op registration mechanism does not allow for ops with the same name to be
re-registered. This is okay to avoid name conflicts and debug
double-registration, but may be problematic for dialect extensions that may get
registered several times (unlike dialects that are deduplicated in the
registry). When registering ops through the Transform dialect extension
mechanism, check first if the ops are already registered and only complain in
the case of repeated registration with the same name but different TypeID.

Differential Revision: https://reviews.llvm.org/D125554
2022-05-17 00:03:40 +02:00
Matthias Springer 0b293bf045 [mlir][bufferize] Better propagation of errors
Return immediately when an op bufferization patterns fails.

Differential Revision: https://reviews.llvm.org/D125087
2022-05-16 23:17:01 +02:00
Mogball 67f0e8eec3 [mlir][ods] Fix verification of attribute + colon type ambiguity
An attribute without a type builder followed by a colon in an assembly format is potentially ambiguous because the parser will read ahead to parse the colon-type and pass this as the type argument to the attribute's constructor.

However, the previous verifier that checks for this ambiguity erroneously produces an error in the case of

```
let assemblyFormat = "( `(` $attr `)` )? `:`";
```

This patch fixes the bug by implementing a checker that correctly handles all edge cases, including very strange assembly formats like:

```
let assemblyFormat = "( `(` $attr ) : (`>`)? attr-dict (`>` $a^) : (`<`)? `:`";
```

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D125445
2022-05-16 21:15:27 +00:00
River Riddle a6cef03f66 [mlir] Remove the `type` keyword from type alias definitions
This was carry over from LLVM IR where the alias definition can
be ambiguous, but MLIR type aliases have no such problems.
Having the `type` keyword is superfluous and doesn't add anything.
This commit drops it, which also nicely aligns with the syntax for
attribute aliases (which doesn't have a keyword).

Differential Revision: https://reviews.llvm.org/D125501
2022-05-16 13:54:02 -07:00
Mogball c8457eb532 [mlir][transforms] Add a topological sort utility and pass
This patch adds a topological sort utility and pass. A topological sort reorders
the operations in a block without SSA dominance such that, as much as possible,
users of values come after their producers.

The utility function sorts topologically the operation range in a given block
with an optional user-provided callback that can be used to virtually break cycles.
The toposort pass itself recursively sorts graph regions under the target op.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D125063
2022-05-16 20:47:30 +00:00
Mogball 0533253d81 [mlir][ods] Ignore AttributeSelfTypeParameter in assembly formats
The attribute self type parameter is currently treated like any other attribute parameter in the assembly format. The self type parameter should be handled by the operation parser and printer and play no role in the generated parsers and printers of attributes.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D125724
2022-05-16 20:23:54 +00:00
Aart Bik 736c1b66ef [mlir][sparse] introduce complex type to sparse tensor support
This is the first implementation of complex (f64 and f32) support
in the sparse compiler, with complex add/mul as first operations.
Note that various features are still TBD, such as other ops, and
reading in complex values from file. Also, note that the
std::complex<float> had a bit of an ABI issue when passed as
single argument. It is still TBD if better solutions are possible.

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D125596
2022-05-16 13:17:36 -07:00
Robert Suderman cb4a5eae1e [mlir][tosa] Use math.ctlz intrinsic for tosa.clz
We were custom counting per bit for the clz instruction. Math dialect
now has an intrinsic to do this in one instruction. Migrated to this
instruction and fixed a minor bug math-to-llvm for the intrinsic.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D125592
2022-05-16 11:31:35 -07:00
Jakub Kuderski ffc3a0db00 [mlir:toy][NFC] Remove unnecessary trailing return type
In this instance, the trailing return type does not improve readability
as it repeats what is returned in the same line.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D125697
2022-05-16 13:46:00 -04:00
Matthias Springer f287da8a15 [mlir][bufferize] Better user control of layout maps
This changes replaces the `fully-dynamic-layout-maps` options (which was badly named) with two new options:

* `unknown-type-conversion` controls the layout maps on buffer types for which no layout map can be inferred.
* `function-boundary-type-conversion` controls the layout maps on buffer types inside of function signatures.

Differential Revision: https://reviews.llvm.org/D125615
2022-05-16 18:06:13 +02:00
Mehdi Amini 08482fa058 Apply clang-tidy fixes for llvm-qualified-auto in LinalgInterfaces.cpp (NFC) 2022-05-16 13:58:49 +00:00
Mehdi Amini 59c3be748f Apply clang-tidy fixes for performance-move-const-arg in SerializeToHsaco.cpp (NFC) 2022-05-16 13:58:49 +00:00
Matthias Springer 12e41d9264 [mlir][bufferize] Infer memref types when possible
Instead of recomputing memref types from tensor types, try to infer them when possible. This results in more precise layout maps.

Differential Revision: https://reviews.llvm.org/D125614
2022-05-16 02:02:08 +02:00
Min-Yih Hsu 3da65c4c0b [mlir][LLVMIR] Add support for translating shufflevector
Add support for translating llvm::ShuffleVectorInst

Differential Revision: https://reviews.llvm.org/D125030
2022-05-14 15:14:40 -07:00
Min-Yih Hsu b8f52c08f8 [mlir][LLVMIR] Add support for translating insert/extractvalue
Add support for translating llvm::InsertValue and llvm::ExtractValue.

Differential Revision: https://reviews.llvm.org/D125028
2022-05-14 15:14:40 -07:00
Arnab Dutta 16219f8c94 [MLIR][GPU] Add canonicalizer for gpu.memcpy
Erase gpu.memcpy op when only uses of dest are
the memcpy op in question, its allocation and deallocation
ops.

Reviewed By: bondhugula, csigg

Differential Revision: https://reviews.llvm.org/D124257
2022-05-14 19:01:04 +05:30
Christian Sigg 0e3d1ca54a [MLIR][GPU] NFC: simplify kernel operand accessor implementations.
Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D125112
2022-05-14 14:14:42 +02:00
Chris Lattner 5ac9d66209 [DenseElementsAttr] Teach isValidRawBuffer that 1-elt values are splats.
We want getRaw() on tensors with i1 element type with a zero or 1 value
to be treated as a splat.  This fixes:
https://github.com/llvm/llvm-project/issues/55440
2022-05-14 11:49:43 +01:00
Mogball bf8049dc48 [mlir][ods] (NFC) remove erroneous trait 2022-05-14 00:37:34 +00:00
Mogball 70b69c54fa [mlir] Rename Zero* traits to Zero*s
Rename
ZeroResult -> ZeroResults
ZeroSuccessor -> ZeroSuccessors
ZeroRegion -> ZeroRegions

to be in line with ZeroOperands and grammatically correct.
2022-05-14 00:20:28 +00:00
Chris Lattner 27478872fd [ParseResult] Fix warning in flang build, incorporate feedback from River.
The warning caused build errors on a couple flang testers that are
building with -Werror.  The diagnostic change makes the generated
error correct.

This is a followup to https://reviews.llvm.org/D125549

Differential Revision: https://reviews.llvm.org/D125587
2022-05-13 23:30:27 +01:00
Chris Lattner 1d7b5cd5bf [ParseResult] Mark this as LLVM_NODISCARD (like LogicalResult) and fix issues.
There are a lot of cases where we accidentally ignored the result of some
parsing hook.  Mark ParseResult as LLVM_NODISCARD just like ParseResult is.
This exposed some stuff to clean up, so do.

Differential Revision: https://reviews.llvm.org/D125549
2022-05-13 16:28:53 +01:00