Commit Graph

12231 Commits

Author SHA1 Message Date
Kazu Hirata 5c4674d67b [mlir] Deprecate OptionalParseResult::{hasValue,getValue}
This patch deprecates hasValue and getValue for consistency with
std::optional and llvm::Optional.  Note that I've migrated all known
uses of them to has_value and value, respectively.

Differential Revision: https://reviews.llvm.org/D131366
2022-08-12 19:19:24 -07:00
Kazu Hirata 7082e1506d [mlir] Use has_value instead of hasValue (NFC) 2022-08-12 19:19:23 -07:00
Jeff Niu 60d2769239 [mlir][ods] OpFormat: ensure that regions don't follow `attr-dict`
An optional attribute dictionary before a region in an assembly format
is a potential format ambiguity because they both start with `{`.

Fixes #53077

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D131636
2022-08-12 21:00:25 -04:00
Jeff Niu a2ad3ec7ac [mlir][ods] Support string literals in `custom` directives
This patch adds support for string literals as `custom` directive
arguments. This can be useful for re-using custom parsers and printers
when arguments have a known value. For example:

```
ParseResult parseTypedAttr(AsmParser &parser, Attribute &attr, Type type) {
  return parser.parseAttribute(attr, type);
}

void printTypedAttr(AsmPrinter &printer, Attribute attr, Type type) {
  return parser.printAttributeWithoutType(attr);
}
```

And in TableGen:

```
def FooOp : ... {
  let arguments = (ins AnyAttr:$a);
  let assemblyFormat = [{ custom<TypedAttr>($a, "$_builder.getI1Type()")
                          attr-dict }];
}

def BarOp : ... {
  let arguments = (ins AnyAttr:$a);
  let assemblyFormat = [{ custom<TypedAttr>($a, "$_builder.getIndexType()")
                          attr-dict }];
}
```

Instead of writing two separate sets of custom parsers and printers.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D131603
2022-08-12 20:55:11 -04:00
Jeff Niu 58a47508f0 (Reland) [mlir] Switch segment size attributes to DenseI32ArrayAttr
This reland includes changes to the Python bindings.

Switch variadic operand and result segment size attributes to use the
dense i32 array. Dense integer arrays were introduced primarily to
represent index lists. They are a better fit for segment sizes than
dense elements attrs.

Depends on D131801

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D131803
2022-08-12 19:44:52 -04:00
Jeff Niu 619fd8c2ab [mlir][python] Add python bindings for DenseArrayAttr
This patch adds python bindings for the dense array variants.

Fixes #56975

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D131801
2022-08-12 19:44:49 -04:00
Eric Kunze 9dec80be72 [MLIR][TOSA] Remove ReluN operator from TOSA dialect
ReluN has been removed from the TOSA specification. It can be replaced
in all instances with Clamp(0,N)

Signed-off-by: Eric Kunze <eric.kunze@arm.com>

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D128683
2022-08-12 16:00:11 -07:00
Jeff Niu 8a3481b958 [mlir] Add AllOfType and ConfinedType constraints
`AllOfType` is a type constraint that satisfies all given type
constraints and `ConfinedType` is a type that satisfies additional
predicates. These shorthands simplify type constraint definition mostly
by removing the need to deal with `myType.predicate` manipulation.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D131788
2022-08-12 16:25:36 -04:00
Jacques Pienaar d6f2e32fc1 [mlir] Flip Tensor dialect and ViewLike (NFC)
Also requires updating view like interface to use prefixed form.

Differential Revision: https://reviews.llvm.org/D131361
2022-08-12 12:41:32 -07:00
Frederik Gossen 2c3ca3b684 [MLIR] Add utility function to create values for all dimensions of a tensor value
This is a variant of the already provided `createDynamicDimValues` helper.

Differential Revision: https://reviews.llvm.org/D131798
2022-08-12 14:42:27 -04:00
Aart Bik 8dd07e36ca [mlir][sparse] enable integral abs recognition
The end-to-end test for this new feature also exposed a bug
in LLVM IR lowering (since then, fixed), where we need to account
for the min-poison bit as extra argument.

    declare i32 @llvm.abs.i32(i32 <src>, i1 <is_int_min_poison>)

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D131712
2022-08-12 11:36:40 -07:00
Jacques Pienaar 2f025e0e78 [mlir][shape] Add dim op
Convenience op that allows for simple expression of common crossing of
value/shape divide.

Differential Revision: https://reviews.llvm.org/D131497
2022-08-12 11:02:08 -07:00
Jeff Niu bc8d966433 [mlir][math] Fix lowering of AbsIOp
The LLVM intrinsic has a bool flag `is_int_min_poison` that needs to be
set.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D131785
2022-08-12 12:10:15 -04:00
Alex Zinenko 4b45999bdd [mlir] fix crossed transform dialect patches
One patch added a use of the IR syntax that was changed by another.
2022-08-12 15:48:15 +00:00
Alex Zinenko a60ed95419 [mlir][transform] failure propagation mode in sequence
Introduce two different failure propagation mode in the Transform
dialect's Sequence operation. These modes specify whether silenceable
errors produced by nested ops are immediately propagated, thus stopping
the sequence, or suppressed. The latter is useful in end-to-end
transform application scenarios where the user cannot correct the
transformation, but it is robust enough to silenceable failures. It
can be combined with the "alternatives" operation. There is
intentionally no default value to avoid favoring one mode over the
other.

Downstreams can update their tests using:

  S='s/sequence \(%.*\) {/sequence \1 failures(propagate) {/'
  T='s/sequence {/sequence failures(propagate) {/'
  git grep -l transform.sequence | xargs sed -i -e "$S"
  git grep -l transform.sequence | xargs sed -i -e "$T"

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D131774
2022-08-12 15:31:22 +00:00
Matthias Springer 0581ab65ea [mlir][linalg][transform] Support matching of attributes (and their values)
Do not just check if an attribute exists on the payload op. Also check its value.

Differential Revision: https://reviews.llvm.org/D131760
2022-08-12 14:55:00 +02:00
Jinyun Joey Ye 921b13f263 Missing climits header file in MemRefUtils.h
MemRefUtils.h uses UINT_MAX, which is not included in current header files list. This patch include climits to avoid compilation error in this header file.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D131529
2022-08-12 14:17:36 +02:00
Nicolas Vasilache a6bf6f25f0 [mlir][Linalg] Let FuseIntoContainingOp return success when nothing is fused.
This composes better when the op is applied in situations where it does not match.

Differential Revision: https://reviews.llvm.org/D131734
2022-08-12 02:18:31 -07:00
Matthias Springer bf1b9528ff [mlir][bufferize] Fix missing copy when bufferizing loops
Using a loop init_arg inside of the loop is not supported. This change adds a pre-processing pass that resolves such IR with copies.

Differential Revision: https://reviews.llvm.org/D131689
2022-08-12 10:44:55 +02:00
Marius Brehler f3547fd541 [mlir][emitc][nfc] Clean up tests
With https://reviews.llvm.org/D131666 the types were removed from the
EmitC opaque attributes. This cleans up the tests accordingly.
2022-08-12 08:25:31 +00:00
Alex Zinenko e8e718fa4b Revert "[mlir] Switch segment size attributes to DenseI32ArrayAttr"
This reverts commit 30171e76f0.

Breaks Python tests in MLIR, missing C API and Python changes.
2022-08-12 10:22:47 +02:00
Marius Brehler 90736babca [mlir][EmitC] Remove the type from the OpaqueAttr
This removes the type from EmitC's opaque attribute. The value provided
as a StringRefParameter can always be emitted as is. In consquence the
constant and variable ops explicitly need to opaque attributes which are
no longer typed attributes.

Co-authored-by: Simon Camphausen <simon.camphausen@iml.fraunhofer.de>

Reviewed By: Mogball, jpienaar

Differential Revision: https://reviews.llvm.org/D131666
2022-08-12 07:12:24 +00:00
Jeff Niu 30171e76f0 [mlir] Switch segment size attributes to DenseI32ArrayAttr
Switch variadic operand and result segment size attributes to use the
dense i32 array. Dense integer arrays were introduced primarily to
represent index lists. They are a better fit for segment sizes than
dense elements attrs.

Depends on D131738

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D131702
2022-08-11 20:56:45 -04:00
Jeff Niu 2092d1438c [mlir] Change the syntax of dense arrays
Follow-up to D123774, where the syntax of dense arrays was discussed. It
was included that the syntax should be changed to `array<i32: 1, 2>`.
This patch changes the syntax but importantly preserves the `[1, 2]`
syntax when embedding these attributes in assembly formats through ODS.

Reviewed By: mehdi_amini, jpienaar

Differential Revision: https://reviews.llvm.org/D131738
2022-08-11 20:56:42 -04:00
not-jenni 7ff0ca1a4d [mlir][tosa] Updates tosa.logical_not to use the SameOperandsAndResultType trait
Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D131496
2022-08-11 15:42:30 -07:00
Uday Bondhugula 0e54d9dfdc [MLIR] Fix hasNoInterveningEffect in the presence of ops from different affine scopes
Fix hasNoInterveningEffect in the presence of ops from different affine
scopes. Also, correctly check for dependence failures as well instead of
just for the existence of a dependence.

Differential Revision: https://reviews.llvm.org/D131641
2022-08-11 21:07:24 +05:30
Benjamin Kramer 726719e970 [mlir][sparse] Refine f695554a2a wording a bit and fix the double conversion I broke with aggressive copy&paste 2022-08-11 11:58:49 +02:00
Marius Brehler 91b6f76a58 [mlir] Fix calling the native mlir-pdll-tblgen
This sets the `MLIR_PDLL_TABLEGEN_EXE` and `MLIR_PDLL_TABLEGEN_TARGET`
as cache variables which is necessary for cross-compiling projects that
rely on MLIR and the mlir-pdll-tblgen tool.

The patch is similar to https://reviews.llvm.org/D130350.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D131596
2022-08-11 09:34:13 +00:00
Benjamin Kramer f695554a2a [mlir][sparse] Use the correct ABI on x86 and re-enable tests
c7ec6e19d5 made LLVM adhere to the x86
psABI and pass bf16 in SSE registers instead of GPRs. This breaks the
custom versions of runtime functions we have for bf16 conversion. A
great fix for this would be to use __bf16 types instead which carry the
right ABI, but that type isn't widely available.

Instead just pretend it's a 32 bit float on the ABI boundary and
carefully cast it to the right type.

Fixes #57042
2022-08-11 10:41:53 +02:00
Jeff Niu 5e0c3b4309 [mlir][LLVMIR] Clean up the definitions of ReturnOp/CallOp 2022-08-11 00:35:02 -04:00
Uday Bondhugula 3d93885f7c [MLIR][NFC] Refactor affine analysis helpers
Refactor affine analysis helpers: the existing ones were using
unnecessary or improperly named arguments. NFC.

Differential Revision: https://reviews.llvm.org/D131557
2022-08-11 06:28:59 +05:30
Uday Bondhugula b6164ec9c2 [MLIR] Add missing check for unsupported affine dependence analysis
Add missing check in affine dependence analysis when dependence analysis
isn't possible due to the ops being in different affine scopes.  The
lack of such a check could lead to a crash or incorrect behavior in
several dependent utilities.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D131556
2022-08-11 06:02:39 +05:30
Uday Bondhugula 82973067ac [MLIR] Fix build breakage due to 5c5af910fe
Fix build breakage due to 5c5af910fe.

```commit 5c5af910fe
Author: Jeff Niu <jeff@modular.com>
Date:   Tue Aug 9 22:07:35 2022 -0400

    [mlir][LLVMIR] "Modernize" Insert/ExtractValueOp ```

results in

```lib/Conversion/LLVMCommon/MemRefBuilder.cpp:170:70: error: call of overloaded ‘makeArrayRef<int64_t>(<brace-enclosed initializer list>)’ is ambiguous
       llvm::makeArrayRef<int64_t>({kStridePosInMemRefDescriptor,
       pos}));

llvm/include/llvm/ADT/ArrayRef.h:505:15: note: candidate: ‘llvm::ArrayRef<T> llvm::makeArrayRef(const std::vector<T>&) [with T = long int]’
   ArrayRef<T> makeArrayRef(const std::vector<T> &Vec) {
               ^~~~~~~~~~~~
llvm/include/llvm/ADT/ArrayRef.h:516:37: note: candidate: ‘llvm::ArrayRef<T> llvm::makeArrayRef(const llvm::ArrayRef<T>&) [with T = long int]’
   template <typename T> ArrayRef<T> makeArrayRef(const ArrayRef<T> &Vec) {
                                                                      ^

Differential Revision: https://reviews.llvm.org/D131637
2022-08-11 05:58:38 +05:30
Aart Bik 6b7459115f [mlir][sparse][bf16] disable two bf16 tests
Supposedly our ABI issues were fixed, per issue:
https://github.com/llvm/llvm-project/issues/55992

However, with a recent changes to bf16, these tests
fail again; not sure why yet:
https://reviews.llvm.org/D130832
https://lab.llvm.org/buildbot/#/builders/61/builds/30600

So we disable the tests for now. Issue is tracked in:
https://github.com/llvm/llvm-project/issues/57042

Differential Revision: https://reviews.llvm.org/D131621
2022-08-10 15:50:27 -07:00
Jeff Niu aa543b8094 [mlir][ods] (NFC) split out erroring format tests 2022-08-10 15:36:12 -04:00
jackalcooper f230d91592 [mlir][spirv] Turn various passes to plain OperationPass
Made passes converting ops from other dialects to spirv OperationPass,
so that downstream compiler could put them in a proper nested pass
manager to lower device code only.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D131591
2022-08-10 13:50:07 -04:00
Slava Zakharin 08b4cf3620 [mlir][math] Added basic support for IPowI operation.
The operation computes pow(b, p), where 'b' and 'p' are signed integers
of the same width. The result's type matches the operands' type.

Differential Revision: https://reviews.llvm.org/D129809
2022-08-10 10:11:53 -07:00
Jeff Niu 5c5af910fe [mlir][LLVMIR] "Modernize" Insert/ExtractValueOp
This patch "modernizes" the LLVM `insertvalue` and `extractvalue`
operations to use DenseI64ArrayAttr, since they only require an array of
indices and previously there was confusion about whether to use i32 or
i64 arrays, and to use assembly format.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D131537
2022-08-10 12:51:11 -04:00
Alexander Belyaev 47cf004076 [mlir] Fix win build by using has_value() instead of hasValue() for Optional. 2022-08-10 17:48:35 +02:00
Alexander Belyaev 42f32f69ad [mlir] Extract offsets-sizes-strides computation from `makeTiledShape(s)`.
This change separates computation of the actual parameters of the subset and
the materialization of subview/extract_slice. That way the users can still use
Linalg tiling logic even if they use different operations to materialize the
subsets.

Differential Revision: https://reviews.llvm.org/D131053
2022-08-10 15:37:38 +02:00
Alex Zinenko 2e2ad53979 [mlir] Generate C++ doc comments for interfaces
When emitting the declarations for interface methods defined in ODS,
also emit their descriptions as C++ comments. This makes the
documentation accessible to C++ tooling such as IDEs that offers better
usability than reading it form the .td or the website.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D130478
2022-08-10 15:12:29 +02:00
Jacques Pienaar 1f02ad7131 [mlir][shape] Update meet to handle all size & shape types
Also tighten up return type inference & compatibility functions.

Differential Revision: https://reviews.llvm.org/D130866
2022-08-10 05:08:24 -07:00
Dominik Adamski 98ed6e1069 [Flang][OpenMP] Fix conversion of nested loops for SIMD directive
Flang was not able to convert simd directive which contains nested
Fortran loops. The nested Fortran loops inside SIMD directive
are modelled as FIR loops and they need to be translated into LLVM
MLIR dialect.

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

Reviewed by: peixin

Signed-off-by: Dominik Adamski <dominik.adamski@amd.com>
2022-08-10 03:54:30 -05:00
John Demme d44f8a50d5 [MLIR] [Python] Fix the Windows build broken by d747a17
Windows builds require all control paths return. Since we don't have
`llvm_unreachable` in the Python bindings, just return `None`.
2022-08-09 20:07:33 -07:00
John Demme d747a170a4 [MLIR] [Python] Fix `Value.owner` to handle BlockArgs
Previously, calling `Value.owner()` would C++ assert in debug builds if
`Value` was a block argument. Additionally, the behavior was just wrong
in release builds. This patch adds support for BlockArg Values.
2022-08-09 19:37:04 -07:00
Aart Bik 5110eb8b67 [mlir][sparse] fix doc
Reviewed By: Peiming

Differential Revision: https://reviews.llvm.org/D131527
2022-08-09 17:19:39 -07:00
Jeff Niu 2f0e50c69b [mlir] Fix build of toyc-ch6 (NFC) 2022-08-09 15:58:49 -04:00
Jeff Niu f201476518 [mlir] Cleanup DenseArrayAttrBase definition and expose raw API
This patch cleans up the definition of `DenseArrayAttrBase` by relying
more on ODS-generated methods. It also exposes an API for using the raw
data of a dense array, similar to `DenseIntOrFPElementsAttr::getRaw`.

Reviewed By: lattner, mehdi_amini

Differential Revision: https://reviews.llvm.org/D131450
2022-08-09 15:43:45 -04:00
Jeff Niu 0af643f3ce [mlir][LLVMIR] (NFC) Add convenience builders for ConstantOp
And clean up some of the user code
2022-08-09 15:34:36 -04:00
Aart Bik 60076a9eaf [mlir][sparse] fix switch statement bug on two binary ops
They appeared at the wrong place in the switch, treating
them as unary op rather than binary op.

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D131509
2022-08-09 11:58:05 -07:00