aboutsummaryrefslogtreecommitdiff
path: root/mlir/lib/Rewrite/ByteCode.cpp
diff options
context:
space:
mode:
authorJeff Niu <jeff@modular.com>2022-07-18 21:32:38 -0700
committerJeff Niu <jeff@modular.com>2022-07-31 20:01:31 -0400
commite1795322844ca45ecbcdca8669929a46c666127e (patch)
tree38e552a9e3a129f5fd4ed242f0d99ce7a3163769 /mlir/lib/Rewrite/ByteCode.cpp
parentaf1328ef452b9eaa4e9f0bc115aeda8f40c4bbff (diff)
downloadllvm-e1795322844ca45ecbcdca8669929a46c666127e.zip
llvm-e1795322844ca45ecbcdca8669929a46c666127e.tar.gz
llvm-e1795322844ca45ecbcdca8669929a46c666127e.tar.bz2
[mlir] Remove types from attributes
This patch removes the `type` field from `Attribute` along with the `Attribute::getType` accessor. Going forward, this means that attributes in MLIR will no longer have types as a first-class concept. This patch lays the groundwork to incrementally remove or refactor code that relies on generic attributes being typed. The immediate impact will be on attributes that rely on `Attribute` containing a type, such as `IntegerAttr`, `DenseElementsAttr`, and `ml_program::ExternAttr`, which will now need to define a type parameter on their storage classes. This will save memory as all other attribute kinds will no longer contain a type. Moreover, it will not be possible to generically query the type of an attribute directly. This patch provides an attribute interface `TypedAttr` that implements only one method, `getType`, which can be used to generically query the types of attributes that implement the interface. This interface can be used to retain the concept of a "typed attribute". The ODS-generated accessor for a `type` parameter automatically implements this method. Next steps will be to refactor the assembly formats of certain operations that rely on `parseAttribute(type)` and `printAttributeWithoutType` to remove special handling of type elision until `type` can be removed from the dialect parsing hook entirely; and incrementally remove uses of `TypedAttr`. Reviewed By: lattner, rriddle, jpienaar Differential Revision: https://reviews.llvm.org/D130092
Diffstat (limited to 'mlir/lib/Rewrite/ByteCode.cpp')
-rw-r--r--mlir/lib/Rewrite/ByteCode.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/mlir/lib/Rewrite/ByteCode.cpp b/mlir/lib/Rewrite/ByteCode.cpp
index 7125dd3..d4ca8b2 100644
--- a/mlir/lib/Rewrite/ByteCode.cpp
+++ b/mlir/lib/Rewrite/ByteCode.cpp
@@ -1652,7 +1652,9 @@ void ByteCodeExecutor::executeGetAttributeType() {
LLVM_DEBUG(llvm::dbgs() << "Executing GetAttributeType:\n");
unsigned memIndex = read();
Attribute attr = read<Attribute>();
- Type type = attr ? attr.getType() : Type();
+ Type type;
+ if (auto typedAttr = attr.dyn_cast<TypedAttr>())
+ type = typedAttr.getType();
LLVM_DEBUG(llvm::dbgs() << " * Attribute: " << attr << "\n"
<< " * Result: " << type << "\n");