Commit Graph

337 Commits

Author SHA1 Message Date
Jacques Pienaar 3f7439b280 [mlir][DRR] Add location directive
Summary:
Add directive to indicate the location to give to op being created. This
directive is optional and if unused the location will still be the fused
location of all source operations.

Currently this directive only works with other op locations, reusing an
existing op location or a fusion of op locations. But doesn't yet support
supplying metadata for the FusedLoc.

Based off initial revision by antiagainst@ and effectively mirrors GlobalIsel
debug_locations directive.

Differential Revision: https://reviews.llvm.org/D77649
2020-04-07 13:38:25 -07:00
Jacques Pienaar d3a31c4db4 Remove case in rewritergen unmatched opdefgen side
The rewriter generates a call to build that is not handled by opdef generator
and so will fail to compile. Also if this is a root node being replaced
(depth 0) then using the more generic build method in the rewrite suffices.
2020-04-06 16:03:49 -07:00
River Riddle 0359b86d8b [mlir][ODS] Add support for variadic regions.
Summary: This revision adds support for marking the last region as variadic in the ODS region list with the VariadicRegion directive.

Differential Revision: https://reviews.llvm.org/D77455
2020-04-05 01:03:38 -07:00
Kazuaki Ishizaki 5aacce3db2 [mlir] NFC: Fix trivial typo
Differential Revision: https://reviews.llvm.org/D77473
2020-04-05 11:30:30 +09:00
River Riddle e3bb36370d [mlir][DeclarativeParser] Emit an error if a `:` follows an attribute with a non-constant type.
Summary: The attribute grammar includes an optional trailing colon type, so for attributes without a constant buildable type this will generally lead to unexpected and undesired behavior. Given that, it's better to just error out on these cases.

Differential Revision: https://reviews.llvm.org/D77293
2020-04-03 19:23:56 -07:00
Mehdi Amini ee4d034277 Change pass registration generated code to allow users to selectively register passes
This slightly tweaks the generated code from:

  #ifdef GEN_PASS_REGISTRATION
  ::mlir::registerPass("flag1", ...
  ::mlir::registerPass("flag2", ...
  #endif // GEN_PASS_REGISTRATION

to:

  #ifdef GEN_PASS_REGISTRATION
  #define GEN_PASS_REGISTRATION_Pass1
  #define GEN_PASS_REGISTRATION_Pass2
  #endif // GEN_PASS_REGISTRATION

  #ifdef GEN_PASS_REGISTRATION_Pass1
  ::mlir::registerPass("flag1", ...
  #endif
  #ifdef GEN_PASS_REGISTRATION_Pass1
  ::mlir::registerPass("flag2", ...
  #endif

That way the generated code can be included by defining the
`GEN_PASS_REGISTRATION` macro as currenty and register all the passes,
but one can also define only `GEN_PASS_REGISTRATION_Pass1` to register a
subset of the passes.

Differential Revision: https://reviews.llvm.org/D77322
2020-04-02 18:58:47 +00:00
River Riddle 9be4be3e53 [mlir][Pass] Add support for generating pass documention from the tablegen definition
Summary:
This revision adds support for auto-generating pass documentation, replacing the need to manually keep Passes.md up-to-date. This matches the behavior already in place for dialect and interface documentation.

Differential Revision: https://reviews.llvm.org/D76660
2020-04-01 02:10:46 -07:00
River Riddle 9a277af2d4 [mlir][Pass] Add support for generating pass utilities via tablegen
This revision adds support for generating utilities for passes such as options/statistics/etc. that can be inferred from the tablegen definition. This removes additional boilerplate from the pass, and also makes it easier to remove the reliance on the pass registry to provide certain things(e.g. the pass argument).

Differential Revision: https://reviews.llvm.org/D76659
2020-04-01 02:10:46 -07:00
River Riddle 8155e41ac6 [mlir][Pass] Add a tablegen backend for defining Pass information
This will greatly simplify a number of things related to passes:
* Enables generation of pass registration
* Enables generation of boiler plate pass utilities
* Enables generation of pass documentation

This revision focuses on adding the basic structure and adds support for generating the registration for passes in the Transforms/ directory. Future revisions will add more support and move more passes over.

Differential Revision: https://reviews.llvm.org/D76656
2020-04-01 02:10:46 -07:00
Sean Silva 6677477190 Verify number of result types in generated builder.
Summary: This just bit me and is nasty to debug.

Differential Revision: https://reviews.llvm.org/D76888
2020-03-27 20:05:42 -07:00
Kazuaki Ishizaki e5a8512655 [mlir] NFC: fix trivial typo in source files
Summary: fix trivial typos in the source files

Reviewers: mravishankar, antiagainst, nicolasvasilache, herhut, rriddle, aartbik

Reviewed By: antiagainst, rriddle

Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, csigg, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, Joonsoo, bader, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D76876
2020-03-28 10:12:49 +09:00
River Riddle 1a083f027f [mlir] Revamp operation documentation generation
Summary:
This revisions performs several cleanups to the generated dialect documentation:
* Standardizes format of attributes/operands/results sections
* Splits out operation/type/dialect documentation generation to allow for composing generated and hand-written documentation
* Add section for declarative assembly syntax and successors
* General cleanup

Differential Revision: https://reviews.llvm.org/D76573
2020-03-24 12:05:18 -07:00
River Riddle bd0ca2627c [mlir] Update DRR patterns to notify the rewriter why a pattern fails to match.
Summary:
This adds support in RewriterGen for calling into the new `PatternRewriter::notifyMatchFailure` hook. This lets derived pattern rewriters display this information to users, an example from DialectConversion is shown below:

```

Legalizing operation : 'std.and'(0x60e0000066a0) {
  * Fold {
  } -> FAILURE : unable to fold

  * Pattern : 'std.and -> (spv.BitwiseAnd)' {
    ** Failure : operand 0 of op 'std.and' failed to satisfy constraint: '8/16/32/64-bit integer or vector of 8/16/32/64-bit integer values of length 2/3/4'
  } -> FAILURE : pattern failed to match

  * Pattern : 'std.and -> (spv.LogicalAnd)' {
    ** Failure : operand 0 of op 'std.and' failed to satisfy constraint: 'bool or vector of bool values of length 2/3/4'
  } -> FAILURE : pattern failed to match
} -> FAILURE : no matched legalization pattern

```

Differential Revision: https://reviews.llvm.org/D76335
2020-03-17 20:22:00 -07:00
River Riddle 3145427dd7 [mlir][NFC] Replace all usages of PatternMatchResult with LogicalResult
This also replaces usages of matchSuccess/matchFailure with success/failure respectively.

Differential Revision: https://reviews.llvm.org/D76313
2020-03-17 20:21:32 -07:00
River Riddle 032743e18f [mlir] Add support for the attribute verifiers in the dialect declaration generator.
Summary: This adds bitfields that map to the dialect attribute verifier hooks. This also moves over the Test dialect to have its declaration generated.

Differential Revision: https://reviews.llvm.org/D76254
2020-03-16 18:32:23 -07:00
River Riddle 2d723d4ad5 [mlir] Avoid the use of auto in templates to fix MSVC build
MSVC is unable to deduce template types when the type involves auto.
2020-03-16 13:55:16 -07:00
River Riddle 429d792f23 [mlir] Add support for generating dialect declarations via tablegen.
Summary: This generates the class declarations for dialects using the existing 'Dialect' tablegen classes.

Differential Revision: https://reviews.llvm.org/D76185
2020-03-14 20:36:44 -07:00
Jacques Pienaar b2bb8b6cd6 [mlir] Automatically add DerivedAttribute op interface
Summary: When an operation has derived attributes, add the DerivedAttribute op interface.

Differential Revision: https://reviews.llvm.org/D76144
2020-03-13 14:26:30 -07:00
Lei Zhang 2ae5e472e6 [mlir][spirv] Use SmallVector<ArrayRef> for availability queries
Previously extensions and capabilities requirements are returned as
SmallVector<SmallVector>. It's an anti-pattern; this commit improves
a bit by returning as SmallVector<ArrayRef>. This is possible because
the internal sequence is always known statically (from the spec)
so that we can use a static constant array for it and get an ArrayRef.

Differential Revision: https://reviews.llvm.org/D75874
2020-03-12 19:37:45 -04:00
Jacques Pienaar 69ce2fd2df [mlir] Remove unused generator
This was a previous experiment that didn't pan out and needs to be
replaced, given no current use or tests, deleting instead and can start
new version fresh.
2020-03-12 16:35:33 -07:00
River Riddle 0ddba0bd59 [mlir][SideEffects] Replace HasNoSideEffect with the memory effect interfaces.
HasNoSideEffect can now be implemented using the MemoryEffectInterface, removing the need to check multiple things for the same information. This also removes an easy foot-gun for users as 'Operation::hasNoSideEffect' would ignore operations that dynamically, or recursively, have no side effects. This also leads to an immediate improvement in some of the existing users, such as DCE, now that they have access to more information.

Differential Revision: https://reviews.llvm.org/D76036
2020-03-12 14:26:15 -07:00
River Riddle 907403f342 [mlir] Add a new `ConstantLike` trait to better identify operations that represent a "constant".
The current mechanism for identifying is a bit hacky and extremely adhoc, i.e. we explicit check 1-result, 0-operand, no side-effect, and always foldable and then assume that this is a constant. Adding a trait adds structure to this, and makes checking for a constant much more efficient as we can guarantee that all of these things have already been verified.

Differential Revision: https://reviews.llvm.org/D76020
2020-03-12 14:26:15 -07:00
River Riddle 483f82b146 [mlir][SideEffects][NFC] Move the .td definitions for NoSideEffect/RecursiveSideEffect to SideEffects.td
This matches the location of these traits within the source files.

Differential Revision: https://reviews.llvm.org/D75968
2020-03-12 14:26:15 -07:00
River Riddle 320f0b0036 [mlir] Change EffectKind in unsigned for bitfield to avoid miscompile in
MSVC

MSVC has problems if the type of the bitfield is different, leading to
invalid code generation.
2020-03-06 23:01:49 -08:00
River Riddle 20dca52288 [mlir][SideEffects] Enable specifying side effects directly on the arguments/results of an operation.
Summary:
New classes are added to ODS to enable specifying additional information on the arguments and results of an operation. These classes, `Arg` and `Res` allow for adding a description and a set of 'decorators' along with the constraint. This enables specifying the side effects of an operation directly on the arguments and results themselves.

Example:
```
def LoadOp : Std_Op<"load"> {
  let arguments = (ins Arg<AnyMemRef, "the MemRef to load from",
                           [MemRead]>:$memref,
                       Variadic<Index>:$indices);
}
```

Differential Revision: https://reviews.llvm.org/D74440
2020-03-06 14:04:36 -08:00
River Riddle cb1777127c [mlir] Remove successor operands from the Operation class
Summary:
This revision removes all of the functionality related to successor operands on the core Operation class. This greatly simplifies a lot of handling of operands, as well as successors. For example, DialectConversion no longer needs a special "matchAndRewrite" for branching terminator operations.(Note, the existing method was also broken for operations with variadic successors!!)

This also enables terminator operations to define their own relationships with successor arguments, instead of the hardcoded "pass-through" behavior that exists today.

Differential Revision: https://reviews.llvm.org/D75318
2020-03-05 12:53:02 -08:00
River Riddle c98cff5ae4 [mlir] Automatically populate `operand_segment_sizes` in the auto-generated build methods.
This greatly simplifies the requirements for builders using this mechanism for managing variadic operands.

Differential Revision: https://reviews.llvm.org/D75317
2020-03-05 12:52:22 -08:00
River Riddle 01f7431b5b [mlir][DeclarativeParser] Add support for formatting operations with AttrSizedOperandSegments.
This attribute details the segment sizes for operand groups within the operation. This revision add support for automatically populating this attribute in the declarative parser.

Differential Revision: https://reviews.llvm.org/D75315
2020-03-05 12:51:28 -08:00
River Riddle 621d7cca37 [mlir] Add a new BranchOpInterface to allow for opaquely interfacing with branching terminator operations.
This interface contains the necessary components to provide the same builtin behavior that terminators have. This will be used in future revisions to remove many of the hardcoded constraints placed on successors and successor operands. The interface initially contains three methods:

```c++
// Return a set of values corresponding to the operands for successor 'index', or None if the operands do not correspond to materialized values.
Optional<OperandRange> getSuccessorOperands(unsigned index);

// Return true if this terminator can have it's successor operands erased.
bool canEraseSuccessorOperand();

// Erase the operand of a successor. This is only valid to call if 'canEraseSuccessorOperand' returns true.
void eraseSuccessorOperand(unsigned succIdx, unsigned opIdx);
```

Differential Revision: https://reviews.llvm.org/D75314
2020-03-05 12:50:35 -08:00
River Riddle c0fd5e657e [mlir] Add traits for verifying the number of successors and providing relevant accessors.
This allows for simplifying OpDefGen, as well providing specializing accessors for the different successor counts. This mirrors the existing traits for operands and results.

Differential Revision: https://reviews.llvm.org/D75313
2020-03-05 12:49:59 -08:00
Jacques Pienaar 1bedb23407 [mlir][ods] Add query for derived attribute
For ODS generated operations enable querying whether there is a derived
attribute with a given name.

Rollforward of commit 5aa57c2 without using llvm::is_contained.
2020-03-03 12:04:16 -08:00
Stephan Herhut 57b8b2cc50 Revert "[mlir][ods] Add query for derived attribute"
This reverts commit 5aa57c2812.

The source code generated due to this ods change does not compile,
as it passes to few arguments to llvm::is_contained.
2020-03-03 10:23:38 +01:00
Jacques Pienaar 5aa57c2812 [mlir][ods] Add query for derived attribute
For ODS generated operations enable querying whether there is a derived
attribute with a given name.
2020-03-02 13:31:35 -08:00
Jacques Pienaar 4dc39ae752 [mlir] Fix typo 2020-02-28 10:59:52 -08:00
Alex Zinenko 3a1b34ff69 [mlir] Intrinsics generator: use TableGen-defined builder function
Originally, intrinsics generator for the LLVM dialect has been producing
customized code fragments for the translation of MLIR operations to LLVM IR
intrinsics. LLVM dialect ODS now provides a generalized version of the
translation code, parameterizable with the properties of the operation.
Generate ODS that uses this version of the translation code instead of
generating a new version of it for each intrinsic.

Differential Revision: https://reviews.llvm.org/D74893
2020-02-25 11:59:04 +01:00
River Riddle 42060c0a98 [mlir][DeclarativeParser][NFC] Use explicit type names in TypeSwitch to
appease older GCC.

Older versions of GCC are unable to properly capture 'this' in template lambdas,
resulting in errors.
2020-02-21 16:14:13 -08:00
River Riddle 9eb436feaa [mlir][DeclarativeParser] Add support for formatting the successors of an operation.
This revision add support for formatting successor variables in a similar way to operands, attributes, etc.

Differential Revision: https://reviews.llvm.org/D74789
2020-02-21 15:15:32 -08:00
River Riddle b1de971ba8 [mlir][ODS] Add support for specifying the successors of an operation.
This revision add support in ODS for specifying the successors of an operation. Successors are specified via the `successors` list:
```
let successors = (successor AnySuccessor:$target, AnySuccessor:$otherTarget);
```

Differential Revision: https://reviews.llvm.org/D74783
2020-02-21 15:15:32 -08:00
River Riddle ca4ea51c0a [mlir][DeclarativeParser] Add an 'attr-dict-with-keyword' directive
This matches the '(print|parse)OptionalAttrDictWithKeyword' functionality provided by the assembly parser/printer.

Differential Revision: https://reviews.llvm.org/D74682
2020-02-21 15:15:32 -08:00
River Riddle 2d0477a003 [mlir][DeclarativeParser] Add basic support for optional groups in the assembly format.
When operations have optional attributes, or optional operands(i.e. empty variadic operands), the assembly format often has an optional section to represent these arguments. This revision adds basic support for defining an "optional group" in the assembly format to support this. An optional group is defined by wrapping a set of elements in `()` followed by `?` and requires the following:

* The first element of the group must be either a literal or an operand argument.
  - This is because the first element must be optionally parsable.
* There must be exactly one argument variable within the group that is marked as the anchor of the group. The anchor is the element whose presence controls whether the group should be printed/parsed. An element is marked as the anchor by adding a trailing `^`.
* The group must only contain literals, variables, and type directives.
  - Any attribute variables may be used, but only optional attributes can be marked as the anchor.
  - Only variadic, i.e. optional, operand arguments can be used.
  - The elements of a type directive must be defined within the same optional group.

An example of this can be seen with the assembly format for ReturnOp, which has a variadic number of operands.

```
def ReturnOp : ... {
  let arguments = (ins Variadic<AnyType>:$operands);

  // We only print the operands+types if there are a non-zero number
  // of operands.
  let assemblyFormat = "attr-dict ($operands^ `:` type($operands))?";
}
```

Differential Revision: https://reviews.llvm.org/D74681
2020-02-21 15:15:31 -08:00
River Riddle 26222db01b [mlir][DeclarativeParser] Add support for the TypesMatchWith trait.
This allows for injecting type constraints that are not direct 1-1 mappings, for example when one type is equal to the element type of another. This allows for moving over several more parsers to the declarative form.

Differential Revision: https://reviews.llvm.org/D74648
2020-02-21 15:15:31 -08:00
River Riddle c32c8fd143 [mlir] Use getOperation()->setAttr when generating attribute set
methods.

This avoids the need to resolve overloads when the current operation
also defines a 'setAttr' method.
2020-02-20 20:08:33 -08:00
River Riddle 6b6c96695c [mlir][ODS] Add a new trait `TypesMatchWith`
Summary:
This trait takes three arguments: lhs, rhs, transformer. It verifies that the type of 'rhs' matches the type of 'lhs' when the given 'transformer' is applied to 'lhs'. This allows for adding constraints like: "the type of 'a' must match the element type of 'b'". A followup revision will add support in the declarative parser for using these equality constraints to port more c++ parsers to the declarative form.

Differential Revision: https://reviews.llvm.org/D74647
2020-02-19 10:18:58 -08:00
Alexandre Eichenberger 476ca094c8 [mlir][ods] Adding attribute setters generation
In some dialects, attributes may have default values that may be
determined only after shape inference. For example, attributes that
are dependent on the rank of the input cannot be assigned a default
value until the rank of the tensor is inferred.

While we can set attributes without explicit setters, referring to
the attributes via accessors instead of having to use the string
interface is better for compile time verification.

The proposed patch add one method per operation attribute that let us
set its value. The code is a very small modification of the existing
getter methods.

Differential Revision: https://reviews.llvm.org/D74143
2020-02-19 11:49:34 -05:00
Tamas Berghammer 066a76a234 Support OptionalAttr inside a StructAttr
Differential revision: https://reviews.llvm.org/D74768
2020-02-19 12:47:04 +00:00
riverriddle@google.com 857b655d7a [mlir] Allow adding extra class declarations to interfaces.
Summary: This matches the similar feature on operation definitions.

Reviewers: jpienaar, antiagainst

Reviewed By: jpienaar, antiagainst

Subscribers: mehdi_amini, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D74438
2020-02-15 23:54:42 -08:00
River Riddle 5756bc4382 [mlir][DeclarativeParser] Add support for formatting enum attributes in the string form.
Summary: This revision adds support to the declarative parser for formatting enum attributes in the symbolized form. It uses this new functionality to port several of the SPIRV parsers over to the declarative form.

Differential Revision: https://reviews.llvm.org/D74525
2020-02-13 17:11:48 -08:00
River Riddle a134ccbbeb [mlir][DeclarativeParser] Move operand type resolution into a functor to
share code.

This reduces the duplication for the two different cases.
2020-02-12 23:56:07 -08:00
River Riddle 1b2c16f2ae [mlir][DeclarativeParser] Add support for attributes with buildable types.
This revision adds support in the declarative assembly form for printing attributes with buildable types without the type, and moves several more parsers over to the declarative form.

Differential Revision: https://reviews.llvm.org/D74276
2020-02-08 15:46:46 -08:00
River Riddle abe6d1174d [mlir] Emit a fatal error when the assembly format is invalid
This revision makes sure that errors emitted outside of testing are treated as fatal errors. This avoids the current silent failures that occur when the format is invalid.
2020-02-03 22:14:33 -08:00