[mlir][ods] Update doc regarding attribute definitions

Differential Revision: https://reviews.llvm.org/D78044
This commit is contained in:
Lei Zhang 2020-04-13 14:54:09 -04:00
parent f83d502feb
commit 92bf405ea6

View file

@ -1016,6 +1016,33 @@ duplication, which is being worked on right now.
## Attribute Definition
An attribute is a compile-time known constant of an operation.
ODS provides attribute wrappers over C++ attribute classes. There are a few
common C++ [attribute classes][AttrClasses] defined in MLIR's core IR library
and one is free to define dialect-specific attribute classes. ODS allows one
to use these attributes in TableGen to define operations, potentially with
more fine-grained constraints. For example, `StrAttr` directly maps to
`StringAttr`; `F32Attr`/`F64Attr` requires the `FloatAttr` to additionally
be of a certain bitwidth.
ODS attributes are defined as having a storage type (corresponding to a backing
`mlir::Attribute` that _stores_ the attribute), a return type (corresponding to
the C++ _return_ type of the generated of the helper getters) as well as method
to convert between the internal storage and the helper method.
### Attribute decorators
There are a few important attribute adapters/decorators/modifers that can be
applied to ODS attributes to specify common additional properties like
optionality, default values, etc.:
* `DefaultValuedAttr`: specifies the
[default value](#attributes-with-default-values) for an attribute.
* `OptionalAttr`: specfies an attribute as [optional](#optional-attributes).
* `Confined`: adapts an attribute with
[further constraints](#confining-attributes).
### Enum attributes
Some attributes can only take values from an predefined enum, e.g., the
@ -1228,19 +1255,6 @@ llvm::Optional<MyBitEnum> symbolizeMyBitEnum(uint32_t value) {
}
```
TODO(b/132506080): This following is outdated. Update it.
An attribute is a compile time known constant of an operation. Attributes are
required to be known to construct an operation (e.g., the padding behavior is
required to fully define the `conv2d` op).
Attributes are defined as having a storage type (corresponding to a derived
class of `mlir::Attribute`), a return type (that corresponds to the C++ type to
use in the generation of the helper accessors) as well as method to convert
between the internal storage and the helper method. Derived attributes are a
special class of attributes that do not have storage but are instead calculated
based on the operation and its attributes.
## Debugging Tips
### Run `mlir-tblgen` to see the generated content
@ -1344,3 +1358,4 @@ requirements that were desirable:
[EnumsGen]: https://github.com/llvm/llvm-project/blob/master/mlir/tools/mlir-tblgen/EnumsGen.cpp
[StringAttr]: LangRef.md#string-attribute
[IntegerAttr]: LangRef.md#integer-attribute
[AttrClasses]: https://github.com/llvm/llvm-project/blob/master/mlir/include/mlir/IR/Attributes.h