[Mlir-commits] [mlir] 92bf405 - [mlir][ods] Update doc regarding attribute definitions
Lei Zhang
llvmlistbot at llvm.org
Mon Apr 20 08:58:45 PDT 2020
Author: Lei Zhang
Date: 2020-04-20T11:58:12-04:00
New Revision: 92bf405ea60bdb5f289fc19d71fccfd626afab48
URL: https://github.com/llvm/llvm-project/commit/92bf405ea60bdb5f289fc19d71fccfd626afab48
DIFF: https://github.com/llvm/llvm-project/commit/92bf405ea60bdb5f289fc19d71fccfd626afab48.diff
LOG: [mlir][ods] Update doc regarding attribute definitions
Differential Revision: https://reviews.llvm.org/D78044
Added:
Modified:
mlir/docs/OpDefinitions.md
Removed:
################################################################################
diff --git a/mlir/docs/OpDefinitions.md b/mlir/docs/OpDefinitions.md
index 32a0d04572a1..9a9e18d79633 100644
--- a/mlir/docs/OpDefinitions.md
+++ b/mlir/docs/OpDefinitions.md
@@ -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
More information about the Mlir-commits
mailing list