-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[mlir] Add property combinators, initial ODS support #94732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5d25c52
[mlir] Add property combinators, initial ODS support
krzysz00 6f502de
Update mlir/docs/DefiningDialects/Operations.md to fix typo
krzysz00 f0a8656
Fix typos
krzysz00 cfac51a
Merge branch 'main' into general-property-builders
krzysz00 66f5843
Fix typos
krzysz00 97a48b1
Update comment
krzysz00 80610bb
Merge branch 'main' into general-property-builders
krzysz00 9e9f15f
Merge branch 'main' into general-property-builders
krzysz00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,6 +101,9 @@ their semantics via a special [TableGen backend][TableGenBackend]: | |
| * The `AttrConstraint` class hierarchy: They are used to specify the | ||
| constraints over attributes. A notable subclass hierarchy is `Attr`, which | ||
| stands for constraints for attributes whose values are of common types. | ||
| * The `Property` class hierarchy: They are used to specify non-attribute-backed | ||
| properties that are inherent to operations. This will be expanded to a | ||
| `PropertyConstraint` class or something similar in the future. | ||
|
|
||
| An operation is defined by specializing the `Op` class with concrete contents | ||
| for all the fields it requires. For example, `tf.AvgPool` is defined as | ||
|
|
@@ -172,9 +175,9 @@ understanding the operation. | |
|
|
||
| ### Operation arguments | ||
|
|
||
| There are two kinds of arguments: operands and attributes. Operands are runtime | ||
| values produced by other ops; while attributes are compile-time known constant | ||
| values, including two categories: | ||
| There are three kinds of arguments: operands, attributes, and properties. | ||
| Operands are runtime values produced by other ops; while attributes and properties | ||
| are compile-time known constant values, including two categories: | ||
|
|
||
| 1. Natural attributes: these attributes affect the behavior of the operations | ||
| (e.g., padding for convolution); | ||
|
|
@@ -187,22 +190,27 @@ values, including two categories: | |
| even though they are not materialized, it should be possible to store as an | ||
| attribute. | ||
|
|
||
| Both operands and attributes are specified inside the `dag`-typed `arguments`, | ||
| led by `ins`: | ||
| Properties are similar to attributes, except that they are not stored within | ||
| the MLIR context but are stored inline with the operation. | ||
|
|
||
| Operands, attributes, and properties are specified inside the `dag`-typed | ||
| `arguments`, led by `ins`: | ||
|
|
||
| ```tablegen | ||
| let arguments = (ins | ||
| <type-constraint>:$<operand-name>, | ||
| ... | ||
| <attr-constraint>:$<attr-name>, | ||
| ... | ||
| <property-constraint>:$<property-name>, | ||
| ); | ||
| ``` | ||
|
|
||
| Here `<type-constraint>` is a TableGen `def` from the `TypeConstraint` class | ||
| hierarchy. Similarly, `<attr-constraint>` is a TableGen `def` from the | ||
| `AttrConstraint` class hierarchy. See [Constraints](#constraints) for more | ||
| information. | ||
| `AttrConstraint` class hierarchy and `<property-constraint>` is a subclass | ||
| of `Property` (though a `PropertyConstraint` hierarchy is planned). | ||
| See [Constraints](#constraints) for more information. | ||
|
|
||
| There is no requirements on the relative order of operands and attributes; they | ||
| can mix freely. The relative order of operands themselves matters. From each | ||
|
|
@@ -324,6 +332,18 @@ Right now, the following primitive constraints are supported: | |
|
|
||
| TODO: Design and implement more primitive constraints | ||
|
|
||
| #### Optional and default-valued properties | ||
|
|
||
| To declare a property with a default value, use `DefaultValuedProperty<..., "...">`. | ||
| If the property's storage data type is different from its interface type, | ||
| for example, in the case of array properties (which are stored as `SmallVector`s | ||
| but use `ArrayRef` as an interface type), add the storage-type equivalent | ||
| of the default value as the third argument. | ||
|
|
||
| To declare an optional property, use `OptionalProperty<...>`. | ||
| This wraps the underlying property in an `std::optional` and gives it a | ||
| default value of `std::nullopt`. | ||
|
|
||
| #### Combining constraints | ||
|
|
||
| `AllAttrOf` is provided to allow combination of multiple constraints which | ||
|
|
@@ -429,6 +449,8 @@ def MyOp : ... { | |
| I32Attr:$i32_attr, | ||
| F32Attr:$f32_attr, | ||
| ... | ||
| I32Property:$i32_prop, | ||
| ... | ||
| ); | ||
|
|
||
| let results = (outs | ||
|
|
@@ -453,7 +475,8 @@ static void build(OpBuilder &odsBuilder, OperationState &odsState, | |
| static void build(OpBuilder &odsBuilder, OperationState &odsState, | ||
| Type i32_result, Type f32_result, ..., | ||
| Value i32_operand, Value f32_operand, ..., | ||
| IntegerAttr i32_attr, FloatAttr f32_attr, ...); | ||
| IntegerAttr i32_attr, FloatAttr f32_attr, ..., | ||
| int32_t i32_prop); | ||
|
|
||
| // Each result-type/operand/attribute has a separate parameter. The parameters | ||
| // for attributes are raw values unwrapped with mlir::Attribute instances. | ||
|
|
@@ -462,13 +485,15 @@ static void build(OpBuilder &odsBuilder, OperationState &odsState, | |
| static void build(OpBuilder &odsBuilder, OperationState &odsState, | ||
| Type i32_result, Type f32_result, ..., | ||
| Value i32_operand, Value f32_operand, ..., | ||
| APInt i32_attr, StringRef f32_attr, ...); | ||
| APInt i32_attr, StringRef f32_attr, ..., | ||
| int32_t i32_prop, ...); | ||
|
|
||
| // Each operand/attribute has a separate parameter but result type is aggregate. | ||
| static void build(OpBuilder &odsBuilder, OperationState &odsState, | ||
| TypeRange resultTypes, | ||
| Value i32_operand, Value f32_operand, ..., | ||
| IntegerAttr i32_attr, FloatAttr f32_attr, ...); | ||
| IntegerAttr i32_attr, FloatAttr f32_attr, ..., | ||
| int32_t i32_prop, ...); | ||
|
|
||
| // All operands/attributes have aggregate parameters. | ||
| // Generated if return type can be inferred. | ||
|
|
@@ -921,8 +946,10 @@ optional-group: `(` then-elements `)` (`:` `(` else-elements `)`)? `?` | |
| The elements of an optional group have the following requirements: | ||
|
|
||
| * The first element of `then-elements` must either be a attribute, literal, | ||
| operand, or region. | ||
| operand, property, or region. | ||
| - This is because the first element must be optionally parsable. | ||
| - If a property is used, it must have an `optionalParser` defined and have a | ||
| default value. | ||
| * Exactly one argument variable or type directive within either | ||
| `then-elements` or `else-elements` must be marked as the anchor of the | ||
| group. | ||
|
|
@@ -984,6 +1011,8 @@ foo.op is_read_only | |
| foo.op | ||
| ``` | ||
|
|
||
| The same logic applies to a `UnitProperty`. | ||
|
|
||
| ##### Optional "else" Group | ||
|
|
||
| Optional groups also have support for an "else" group of elements. These are | ||
|
|
@@ -1026,6 +1055,8 @@ to: | |
| 1. All operand and result types must appear within the format using the various | ||
| `type` directives, either individually or with the `operands` or `results` | ||
| directives. | ||
| 1. Unless all non-attribute properties appear in the format, the `prop-dict` | ||
| directive must be present. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm actually working on a patch to go further in the proper separation of discardable and inherent attribute to force prop-dict to be present when some inherent attributes aren't present in the format (just a comment passing by, nothing blocking your work of course) |
||
| 1. The `attr-dict` directive must always be present. | ||
| 1. Must not contain overlapping information; e.g. multiple instances of | ||
| 'attr-dict', types, operands, etc. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.