let convertFromStorage = attr.convertFromStorage;
let constBuilderCall = attr.constBuilderCall;
let defaultValue = val;
+
+ // Remember `attr`'s def name.
+ // TOOD(b/132458159): consider embedding Attr as a field.
+ string baseAttr = !cast<string>(attr);
}
// Decorates an attribute as optional. The return type of the generated
let convertFromStorage = "$_self ? " # returnType # "(" #
attr.convertFromStorage # ") : (llvm::None)";
let isOptional = 0b1;
+
+ // Remember `attr`'s def name.
+ // TOOD(b/132458159): consider embedding Attr as a field.
+ string baseAttr = !cast<string>(attr);
}
// A generic attribute that must be constructed around a specific type
// Returns whether this attribute is optional.
bool isOptional() const;
- StringRef getTableGenDefName() const;
+ // Returns this attribute's TableGen def name. If this is an `OptionalAttr`
+ // or `DefaultValuedAttr` without explicit name, returns the base attribute's
+ // name.
+ StringRef getAttrDefName() const;
// Returns the code body for derived attribute. Aborts if this is not a
// derived attribute.
return def->getValueAsBit("isOptional");
}
-StringRef tblgen::Attribute::getTableGenDefName() const {
+StringRef tblgen::Attribute::getAttrDefName() const {
+ if (def->isAnonymous() && (isOptional() || hasDefaultValueInitializer()))
+ return getValueAsString(def->getValueInit("baseAttr"));
return def->getName();
}
std::string PatternEmitter::handleConstantAttr(Attribute attr,
StringRef value) {
if (!attr.isConstBuildable())
- PrintFatalError(loc, "Attribute " + attr.getTableGenDefName() +
+ PrintFatalError(loc, "Attribute " + attr.getAttrDefName() +
" does not have the 'constBuilderCall' field");
// TODO(jpienaar): Verify the constants here