Commit Graph

675 Commits

Author SHA1 Message Date
Kazu Hirata 192d9dd731 [mlir] Use std::nullopt instead of None in comments (NFC)
This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-04 19:58:32 -08:00
River Riddle 1294fa6971 [mlir][docs] Group the docs for defining dialect components
This moves the documentation for defining dialects, attributes/types,
and operations into a new `DefiningDialects` folder. This helps to
keep the documentation grouped together, making it easier to find
related documentation.

Differential Revision: https://reviews.llvm.org/D137594
2022-12-02 13:38:14 -08:00
River Riddle b74192b7ae [mlir] Remove support for non-prefixed accessors
This finishes off a year long pursuit to LLVMify the generated
operation accessors, prefixing them with get/set. Support for
any other accessor naming is fully removed after this commit.

https://discourse.llvm.org/t/psa-raw-accessors-are-being-removed/65629

Differential Revision: https://reviews.llvm.org/D136727
2022-12-02 13:32:36 -08:00
River Riddle df5ea69105 [mlir] Don't include the attribute self type in a `params` directive
The self type is handled separately from normal parameters, and
the use of the params directive currently breaks attributes that
want to use it (e.g. in a struct directive).

Differential Revision: https://reviews.llvm.org/D137732
2022-11-12 14:38:45 -08:00
River Riddle 38c219b4a8 [mlir] Infer SubElementInterface implementations using the storage KeyTy
The KeyTy of attribute/type storage classes provide enough information for
automatically implementing the necessary sub element interface methods. This
removes the need for derived classes to do it themselves, which is both much
nicer and easier to handle certain invariants (e.g. null handling). In cases where
explicitly handling for parameter types is necessary, they can provide an implementation
of `AttrTypeSubElementHandler` to opt-in to support.

This tickles a few things alias wise, which annoyingly messes with tests that hard
code specific affine map numbers.

Differential Revision: https://reviews.llvm.org/D137374
2022-11-04 18:15:03 -07:00
Oleksandr "Alex" Zinenko 2bbafe04fe
Add TOC to GPU.md 2022-11-04 01:03:01 +01:00
rkayaith d511a5d471 [mlir] Include anchor op in reproducer pipeline string
Including the anchor op ensures that all pass manager settings are fully
specified, and makes the string consistent with the printed form.

Depends on D134622

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D134623
2022-11-03 11:44:57 -04:00
rkayaith 13bd410962 [mlir][Pass] Include anchor op in -pass-pipeline
In D134622 the printed form of a pass manager is changed to include the
name of the op that the pass manager is anchored on. This updates the
`-pass-pipeline` argument format to include the anchor op as well, so
that the printed form of a pipeline can be directly passed to
`-pass-pipeline`. In most cases this requires updating
`-pass-pipeline='pipeline'` to
`-pass-pipeline='builtin.module(pipeline)'`.

This also fixes an outdated assert that prevented running a
`PassManager` anchored on `'any'`.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D134900
2022-11-03 11:36:12 -04:00
rkayaith e44a3c3d7f [mlir][doc] Update op optional-group asm format doc
Update docs to describe the behaviour when a default-valued attribute is
used as an optional-group's anchor after D134993.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D136987
2022-10-31 10:34:53 -04:00
Emilio Cota 17dbd80ff7 [mlir] Fix typo s/utilties/utilities/ (including in file name)
Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D136887
2022-10-27 17:14:33 -04:00
River Riddle 9af92ed8a0 [mlir:LLVM] Rewrite the LLVMIR export to use the debug info attributes
This has been a long standing TODO, and actually enables users to generate
debug information for LLVM using the LLVM dialect; as opposed to our
dummy placeholder that generated just enough for line table information.

Differential Revision: https://reviews.llvm.org/D136543
2022-10-24 22:31:41 -07:00
Sanjoy Das 49e2d361c9 Add a document on side effects & speculation in MLIR
Differential Revision: https://reviews.llvm.org/D136316
2022-10-24 22:03:29 -07:00
Tomás Longeri 0580901bbb Fix #58322: Handlers for debug actions with equal parameter types must not override each other
Also clean up redundant public access specifiers.

Reviewed By: mehdi_amini, rriddle

Differential Revision: https://reviews.llvm.org/D135924
2022-10-22 14:18:00 -07:00
Jeremy Furtek f6ee194b68 [mlir][ods] Do not print default-valued attributes when the value is equal to the default
This diff causes the `tblgen`-erated print() function to skip printing a
`DefaultValuedAttr` attribute when the value is equal to the default.

This feature will reduce the amount of custom printing code that needs to be
written by users a relatively common scenario. As a motivating example, for the
fastmath flags in the LLVMIR dialect, we would prefer to print this:

```
%0 = llvm.fadd %arg0, %arg1 : f32
```

instead of this:

```
%0 = llvm.fadd %arg0, %arg1 {fastmathFlags = #llvm.fastmath<none>} : f32
```

This diff makes the handling of print functionality for default-valued attributes
standard.

This is an updated version of https://reviews.llvm.org/D135398, without the per-attribute bit to control printing.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D135993
2022-10-17 13:57:36 -07:00
Jeff Niu e936c3bb48 [mlir][ods] Allow custom directives in optional groups
Attributes and types only (so far). Since `struct` and `params` are
allowed, it makes sense to allow custom directives as long as their
arguments contain at least one bound argument.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D135001
2022-10-12 17:55:51 -07:00
Sanjoy Das 86771d0b65 Introduce a ConditionallySpeculatable op interface
This patch takes the first step towards a more principled modeling of undefined behavior in MLIR as discussed in the following discourse threads:

 1. https://discourse.llvm.org/t/semantics-modeling-undefined-behavior-and-side-effects/4812
 2. https://discourse.llvm.org/t/rfc-mark-tensor-dim-and-memref-dim-as-side-effecting/65729

This patch in particular does the following:

 1. Introduces a ConditionallySpeculatable OpInterface that dynamically determines whether an Operation can be speculated.
 2. Re-defines `NoSideEffect` to allow undefined behavior, making it necessary but not sufficient for speculation.  Also renames it to `NoMemoryEffect`.
 3. Makes LICM respect the above semantics.
 4. Changes all ops tagged with `NoSideEffect` today to additionally implement ConditionallySpeculatable and mark themselves as always speculatable.  This combined trait is named `Pure`.  This makes this change NFC.

For out of tree dialects:

 1. Replace `NoSideEffect` with `Pure` if the operation does not have any memory effects, undefined behavior or infinite loops.
 2. Replace `NoSideEffect` with `NoSideEffect` otherwise.

The next steps in this process are (I'm proposing to do these in upcoming patches):

 1. Update operations like `tensor.dim`, `memref.dim`, `scf.for`, `affine.for` to implement a correct hook for `ConditionallySpeculatable`.  I'm also happy to update ops in other dialects if the respective dialect owners would like to and can give me some pointers.
 2. Update other passes that speculate operations to consult `ConditionallySpeculatable` in addition to `NoMemoryEffect`.  I could not find any other than LICM on a quick skim, but I could have missed some.
 3. Add some documentation / FAQs detailing the differences between side effects, undefined behavior, speculatabilty.

Reviewed By: rriddle, mehdi_amini

Differential Revision: https://reviews.llvm.org/D135505
2022-10-12 10:56:12 -07:00
Alex Zinenko 209843e050 [mlir][doc] move transform dialect docs to .md, NFC
The description of the Transform dialect has become quite lengthy to be
kept as a Tablegen string literal. Move it to a proper Markdown file.
2022-10-12 11:02:01 +00:00
Alex Zinenko ad7aa09672 [mlir] document transform dialect types 2022-10-12 10:56:11 +00:00
Alex Zinenko 183bf9b34b [mlir] generate docs for GPU transform extension 2022-10-11 15:32:42 +00:00
Alex Zinenko bba85ebdfe [mlir] add types to the transform dialect
Introduce a type system for the transform dialect. A transform IR type
captures the expectations of the transform IR on the payload IR
operations that are being transformed, such as being of a certain kind
or implementing an interface that enables the transformation. This
provides stricter checking and better readability of the transform IR
than using the catch-all "handle" type.

This change implements the basic support for a type system amendable to
dialect extensions and adds a drop-in replacement for the unrestricted
"handle" type. The actual switch of transform dialect ops to that type
will happen in a separate commit.

See https://discourse.llvm.org/t/rfc-type-system-for-the-transform-dialect/65702

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D135164
2022-10-11 09:55:07 +00:00
Jacques Pienaar 9033e57ca5 [mlir][doc] Remove trailing whitespace (NFC) 2022-10-07 09:05:49 -07:00
Oleksandr "Alex" Zinenko d14a029222
[mlir] tweak declarative assembly doc
Change the formal argument of the `functional-type` directive from "results" to "outputs" to avoid confusion with the `results` directive.
2022-10-05 14:33:47 +02:00
Matthias Springer 81ca5aa452 [mlir][tensor][NFC] Rename linalg.init_tensor to tensor.empty
tensor.empty/linalg.init_tensor produces an uninititalized tensor that can be used as a destination operand for destination-style ops (ops that implement `DestinationStyleOpInterface`).

This change makes it possible to implement `TilingInterface` for non-destination-style ops without depending on the Linalg dialect.

RFC: https://discourse.llvm.org/t/rfc-add-tensor-from-shape-operation/65101

Differential Revision: https://reviews.llvm.org/D135129
2022-10-04 17:25:35 +09:00
Jakub Kuderski abc362a107 [mlir][arith] Change dialect name from Arithmetic to Arith
Suggested by @lattner in https://discourse.llvm.org/t/rfc-define-precise-arith-semantics/65507/22.

Tested with:
`ninja check-mlir check-mlir-integration check-mlir-mlir-spirv-cpu-runner check-mlir-mlir-vulkan-runner check-mlir-examples`

and `bazel build --config=generic_clang @llvm-project//mlir:all`.

Reviewed By: lattner, Mogball, rriddle, jpienaar, mehdi_amini

Differential Revision: https://reviews.llvm.org/D134762
2022-09-29 11:23:28 -04:00
rkayaith 868a8fd88f [mlir] Add macro for enabling all generated pass declarations
Currently the generated pass declarations have to be enabled per-pass
using multiple `GEN_PASS_DECL_{PASSNAME}` defines. This adds
`GEN_PASS_DECL`, which enables the declarations for all passes in the
group with a single macro. This is convenient for cases where a single
header is used for all passes in the group.

Reviewed By: mehdi_amini, mscuttari

Differential Revision: https://reviews.llvm.org/D134766
2022-09-28 11:49:28 -04:00
River Riddle f90c2acb5d [mlir:LSP] Add bullet for tablegen hover in the vscode section
This allows hover documentation to show up in the vscode extension.
2022-09-27 23:57:00 -07:00
River Riddle 18f954e715 [mlir:LSP] Add a doc blurb for bytecode editing support
This was missed when bytecode support was originally added.
2022-09-27 23:48:17 -07:00
River Riddle 3e2ad37679 [TableGen:LSP] Add hover support for records and recordvals
This provides hover information for classes, defs, fields, and template
arguments. Like PDLL, this pulls documentation from the source code
when hovering over fields and records.

Differential Revision: https://reviews.llvm.org/D134259
2022-09-27 23:48:16 -07:00
Lei Zhang 4c6683cd68 [mlir][spirv] Use "SPIR-V" in the doc after dialect renaming 2022-09-27 13:09:01 -04:00
Jakub Kuderski ce82530cd0 Revert "[mlir][spirv] Change td def/class prefix from SPV to SPIRV"
This reverts commit a2052b8794.

This commit renamed some Vulkan identifiers that shouldn't have been
renamed, e.g., `SPV_KHR_storage_buffer_storage_class`.
2022-09-26 12:40:35 -04:00
Jakub Kuderski a2052b8794 [mlir][spirv] Change td def/class prefix from SPV to SPIRV
Tested with `check-mlir` and `check-mlir-integration`.

Fixes: https://github.com/llvm/llvm-project/issues/56863

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D134649
2022-09-26 11:42:49 -04:00
Jakub Kuderski 5ab6ef758f [mlir][spirv] Change dialect name from 'spv' to 'spirv'
Tested with `check-mlir` and `check-mlir-integration`.

Issue: https://github.com/llvm/llvm-project/issues/56863

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D134620
2022-09-26 10:58:30 -04:00
Jeff Niu 4792f2ab21 [mlir][ods] Generalize default/optional parameters
This patch consolidates the notions of an optional parameter and a
default parameter. An optional parameter is a parameter equal to its
default value, which for a "purely optional" parameter is its "null"
value.

This allows the existing `comparator` and `defaultValue` fields to be
used enabled more complex "optional" parameters, such as empty arrays.

Depends on D133812

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D133816
2022-09-20 11:07:53 -07:00
Jeff Niu 95a33b455d [mlir][ods] Format: allow anchors in the else elements
This patch changes optional groups to allow anchors in the 'else'
element group. When printing, the optional condition is inverted to
decide which group to print. This is useful for parsing concrete
optional elements that don't have a `parseOptional*` method or some
other way to test whether it's present.

Depends on D133805

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D133812
2022-09-20 11:07:50 -07:00
Mathieu Fehr ba8424a251 [mlir] Add Dynamic Dialects
Dynamic dialects are dialects that can be defined at runtime.
Dynamic dialects are extensible by new operations, types, and
attributes at runtime.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D125201
2022-09-19 09:58:18 -07:00
Alex Zinenko f3fae035c7 [mlir] use strided layout in structured codegen-related tests
All relevant operations have been switched to primarily use the strided
layout, but still support the affine map layout. Update the relevant
tests to use the strided format instead for compatibility with how ops
now print by default.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D134045
2022-09-17 08:11:28 +02:00
River Riddle 6ab2bcffe4 [mlir:Bytecode] Add support for encoding resources
Resources are encoded in two separate sections similarly to
attributes/types, one for the actual data and one for the data
offsets. Unlike other sections, the resource sections are optional
given that in many cases they won't be present. For testing,
bytecode serialization is added for DenseResourceElementsAttr.

Differential Revision: https://reviews.llvm.org/D132729
2022-09-13 11:39:19 -07:00
Hanhan Wang aac844a4b1 [mlir] Improve bitEnumContains methods.
839b436c93
changes the behavior. Based on the discussion, we also want to support
"and" behavior. The revision changes it into two functions, bitEnumContainsAny
and bitEnumContainsAll.

Reviewed By: krzysz00, antiagainst

Differential Revision: https://reviews.llvm.org/D133507
2022-09-09 11:56:36 -07:00
River Riddle bb6d12b5ce [mlir] Flip default value of emitAccessorPrefix to kEmitAccessorPrefix_Prefixed
Most dialects have already flipped to prefixed, and the intention to switch
has been telegraphed for a while.

Differential Revision: https://reviews.llvm.org/D133179
2022-09-06 15:56:57 -07:00
Krzysztof Drewniak 839b436c93 [mlir] Improve BitEnumAttr, update documentation
- Add new operators to BitEnumAttr, mainly not (which only inverts
bits that can be valid bits for the attribute) and xor
- Add new bit enum utility functions: bitEnumClear(bits, bit) and
bitEnumSet(bits, bit, value=true) as they've come up in code I've been
writing that makes use of such enums
- Add rudimentary tests for the enum generator
- Update the OpDefinition documentation to make it contain a correct
example and to have it account for the changes mentioned above.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D133374
2022-09-06 21:36:34 +00:00
Alex Zinenko 519847fefc [mlir] materialize strided memref layout as attribute
Introduce a new attribute to represent the strided memref layout. Strided
layouts are omnipresent in code generation flows and are the only kind of
layouts produced and supported by a half of operation in the memref dialect
(view-related, shape-related). However, they are internally represented as
affine maps that require a somewhat fragile extraction of the strides from the
linear form that also comes with an overhead. Furthermore, textual
representation of strided layouts as affine maps is difficult to read: compare
`affine_map<(d0, d1, d2)[s0, s1] -> (d0*32 + d1*s0 + s1 + d2)>` with
`strides: [32, ?, 1], offset: ?`. While a rudimentary support for parsing a
syntactically sugared version of the strided layout has existed in the codebase
for a long time, it does not go as far as this commit to make the strided
layout a first-class attribute in the IR.

This introduces the attribute and updates the tests that using the pre-existing
sugared form to use the new attribute instead. Most memref created
programmatically, e.g., in passes, still use the affine form with further
extraction of strides and will be updated separately.

Update and clean-up the memref type documentation that has gotten stale and has
been referring to the details of affine map composition that are long gone.

See https://discourse.llvm.org/t/rfc-materialize-strided-memref-layout-as-an-attribute/64211.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D132864
2022-08-30 17:19:58 +02:00
Michele Scuttari 13ed6958df
[MLIR] Unique autogenerated file for tablegen passes
Being the generated code macro-guarded, the autogenerated `.cpp.inc` file has been merged into the `.h.inc` to reduce the build steps.

Reviewed By: mehdi_amini, rriddle

Differential Revision: https://reviews.llvm.org/D132884
2022-08-30 09:48:11 +02:00
Michele Scuttari 0815281ff2
[MLIR] Fix autogenerated pass constructors linkage
The patch addresses the linkage of the new autogenerated pass constructors, which, being declared as friend functions, resulted in having an inline nature and thus their implementations not being exported.

Reviewd By: mehdi_amini, rriddle

Differential Revision: https://reviews.llvm.org/D132572
2022-08-29 20:53:42 +02:00
River Riddle 2f90764ce8 [mlir:Bytecode] Add encoding support for a majority of the builtin attributes
This adds support for the non-location, non-elements, non-affine
builtin attributes.

Differential Revision: https://reviews.llvm.org/D132539
2022-08-26 13:31:05 -07:00
Michele Scuttari 32c5578bcd
[MLIR] Split autogenerated pass declarations & C++ controllable pass options
The pass tablegen backend has been reworked to remove the monolithic nature of the autogenerated declarations.
The pass public header can be generated with the -gen-pass-decls option. It contains options structs and registrations: the inclusion of options structs can be controlled individually for each pass by defining the GEN_PASS_DECL_PASSNAME macro; the declaration of the registrations have been kept together and can still be included by defining the GEN_PASS_REGISTRATION macro.
The private code used for the pass implementation (i.e. the pass base class and the constructors definitions, if missing from tablegen) can be generated with the -gen-pass-defs option. Similarly to the declarations file, the definitions of each pass can be enabled by defining the GEN_PASS_DEF_PASNAME variable.
While doing so, the pass base class has been enriched to also accept a the aformentioned struct of options and copy them to the actual pass options, thus allowing each pass to also be configurable within C++ and not only through command line.

Reviewed By: rriddle, mehdi_amini, Mogball, jpienaar

Differential Revision: https://reviews.llvm.org/D131839
2022-08-24 10:01:08 +02:00
River Riddle 02c2ecb9c6 [mlir:Bytecode] Add initial support for dialect defined attribute/type encodings
Dialects can opt-in to providing custom encodings by implementing the
`BytecodeDialectInterface`. This interface provides hooks, namely
`readAttribute`/`readType` and `writeAttribute`/`writeType`, that will be used
by the bytecode reader and writer. These hooks are provided a reader and writer
implementation that can be used to encode various constructs in the underlying
bytecode format. A unique feature of this interface is that dialects may choose
to only encode a subset of their attributes and types in a custom bytecode
format, which can simplify adding new or experimental components that aren't
fully baked.

Differential Revision: https://reviews.llvm.org/D132498
2022-08-23 16:56:04 -07:00
River Riddle f3acb54c1b [mlir] Add initial support for a binary serialization format
This commit adds a new bytecode serialization format for MLIR.
The actual serialization of MLIR to binary is relatively straightforward,
given the very very general structure of MLIR. The underlying basis for
this format is a variable-length encoding for integers, which gets heavily
used for nearly all aspects of the encoding (given that most of the encoding
is just indexing into lists).

The format currently does not provide support for custom attribute/type
serialization, and thus always uses an assembly format fallback. It also
doesn't provide support for resources. These will be added in followups,
the intention for this patch is to provide something that supports the
basic cases, and can be built on top of.

https://discourse.llvm.org/t/rfc-a-binary-serialization-format-for-mlir/63518

Differential Revision: https://reviews.llvm.org/D131747
2022-08-22 00:36:26 -07:00
Fangrui Song 35e56771ab [mlir][docs] Migrate away from deprecated llvm::Optional methods 2022-08-19 23:29:31 -07:00
Jeff Niu e35ca70eb3 [mlir][ods] Rename Confined and AllAttrConstraintsOf
Confined -> ConfinedAttr
AllAttrConstraintsOf -> AllOfAttr

To be in line with ConfinedType and AllOfType.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D131822
2022-08-12 22:36:17 -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