summaryrefslogtreecommitdiffstats
path: root/mlir/lib/TableGen
diff options
context:
space:
mode:
authorLei Zhang <antiagainst@google.com>2019-07-16 04:33:54 -0700
committerMehdi Amini <joker.eph@gmail.com>2019-07-16 13:45:03 -0700
commit765b77cc70943759f8ee28d55cf19841b713ac5c (patch)
tree7f9f4e85c28733743bedf4d9136a4969b96d8bd4 /mlir/lib/TableGen
parente78ea03b24badc24bb1eec2c2bcccac5c8a1bd07 (diff)
downloadbcm5719-llvm-765b77cc70943759f8ee28d55cf19841b713ac5c.tar.gz
bcm5719-llvm-765b77cc70943759f8ee28d55cf19841b713ac5c.zip
Better support for attribute wrapper classes when getting def name
Unless we explicitly name a template instantiation in .td file, its def name will be "anonymous_<number>". We typically give base-level Attr template instantiation a name by writing `def AnAttr : Attr<...>`. But when `AnAttr` is further wrapped in classes like OptionalAttr, the name is lost unless explicitly def'ed again. These implicit-named template instantiation is fairly common when writing op definitions. Those wrapper classes are just essentially attaching more information to the attribute. Without a proper way to trace back to the original attribute def name can cause problems for consumers wanting to handle attributes according to their types. Previously we handled OptionalAttr and DefaultValuedAttr specifically, but Confined was not supported. And they can compose together to have Confined<OptionalAttr<...>, [...]>. So this CL moves the baseAttr field to main Attr class (like isOptional) and set it only on the innermost wrapper class. PiperOrigin-RevId: 258341646
Diffstat (limited to 'mlir/lib/TableGen')
-rw-r--r--mlir/lib/TableGen/Attribute.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/mlir/lib/TableGen/Attribute.cpp b/mlir/lib/TableGen/Attribute.cpp
index f5eb6d3bd9a..2daccc8e23f 100644
--- a/mlir/lib/TableGen/Attribute.cpp
+++ b/mlir/lib/TableGen/Attribute.cpp
@@ -96,6 +96,14 @@ StringRef tblgen::Attribute::getConstBuilderTemplate() const {
return getValueAsString(init);
}
+tblgen::Attribute tblgen::Attribute::getBaseAttr() const {
+ if (const auto *defInit =
+ llvm::dyn_cast<llvm::DefInit>(def->getValueInit("baseAttr"))) {
+ return Attribute(defInit).getBaseAttr();
+ }
+ return *this;
+}
+
bool tblgen::Attribute::hasDefaultValueInitializer() const {
const auto *init = def->getValueInit("defaultValue");
return !getValueAsString(init).empty();
@@ -111,8 +119,9 @@ bool tblgen::Attribute::isOptional() const {
}
StringRef tblgen::Attribute::getAttrDefName() const {
- if (def->isAnonymous() && (isOptional() || hasDefaultValueInitializer()))
- return getValueAsString(def->getValueInit("baseAttr"));
+ if (def->isAnonymous()) {
+ return getBaseAttr().def->getName();
+ }
return def->getName();
}
OpenPOWER on IntegriCloud