16 #include "llvm/TableGen/Record.h"
24 using llvm::StringInit;
29 if (
const auto *str = dyn_cast<StringInit>(init))
30 return str->getValue().trim();
35 return def->isSubClassOf(className);
39 assert(record->isSubClassOf(
"Attr") &&
40 "must be subclass of TableGen 'Attr' class");
50 StringRef defName =
def->getName();
51 if (defName ==
"SymbolRefAttr" || defName ==
"FlatSymbolRefAttr")
59 const auto *init =
def->getValueInit(
"storageType");
62 return "::mlir::Attribute";
67 const auto *init =
def->getValueInit(
"returnType");
74 if (
const auto *defInit = dyn_cast<DefInit>(
def->getValueInit(
"valueType")))
75 return Type(defInit->getDef());
80 const auto *init =
def->getValueInit(
"convertFromStorage");
85 const auto *init =
def->getValueInit(
"constBuilderCall");
90 const auto *init =
def->getValueInit(
"constBuilderCall");
95 if (
const auto *defInit = dyn_cast<DefInit>(
def->getValueInit(
"baseAttr"))) {
102 const auto *init =
def->getValueInit(
"defaultValue");
107 const auto *init =
def->getValueInit(
"defaultValue");
114 if (
def->isAnonymous()) {
117 return def->getName();
121 assert(
isDerivedAttr() &&
"only derived attribute has 'body' field");
122 return def->getValueAsString(
"body");
126 const llvm::RecordVal *record =
def->getValue(
"dialect");
127 if (record && record->getValue()) {
128 if (
const DefInit *init = dyn_cast<DefInit>(record->getValue()))
129 return Dialect(init->getDef());
137 assert(def->isSubClassOf(
"ConstantAttr") &&
138 "must be subclass of TableGen 'ConstantAttr' class");
142 return Attribute(def->getValueAsDef(
"attr"));
146 return def->getValueAsString(
"value");
150 assert(isSubClassOf(
"EnumAttrCaseInfo") &&
151 "must be subclass of TableGen 'EnumAttrInfo' class");
158 return def->getValueAsString(
"symbol");
169 "must be subclass of TableGen 'EnumAttr' class");
183 return def->getValueAsString(
"className");
187 return def->getValueAsString(
"cppNamespace");
191 return def->getValueAsString(
"underlyingType");
195 return def->getValueAsString(
"underlyingToSymbolFnName");
199 return def->getValueAsString(
"stringToSymbolFnName");
203 return def->getValueAsString(
"symbolToStringFnName");
207 return def->getValueAsString(
"symbolToStringFnRetType");
211 return def->getValueAsString(
"maxEnumValFnName");
215 const auto *inits =
def->getValueAsListInit(
"enumerants");
217 std::vector<EnumAttrCase> cases;
218 cases.reserve(inits->size());
220 for (
const Init *init : *inits) {
221 cases.emplace_back(cast<DefInit>(init));
228 return def->getValueAsBit(
"genSpecializedAttr");
232 return def->getValueAsDef(
"baseAttrClass");
236 return def->getValueAsString(
"specializedAttrClassName");
240 return def->getValueAsBit(
"printBitEnumPrimaryGroups");
static StringRef getValueAsString(const Init *init)
Attributes are known-constant values of operations.
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
bool isSubClassOf(StringRef className) const
StringRef getConstBuilderTemplate() const
bool isConstBuildable() const
StringRef getConvertFromStorageCall() const
StringRef getStorageType() const
bool hasDefaultValue() const
StringRef getDefaultValue() const
Attribute(const llvm::Record *record)
const llvm::Record & getDef() const
StringRef getAttrDefName() const
StringRef getDerivedCodeBody() const
StringRef getReturnType() const
bool isDerivedAttr() const
std::optional< Type > getValueType() const
bool isSymbolRefAttr() const
Dialect getDialect() const
Attribute getBaseAttr() const
ConstantAttr(const llvm::DefInit *init)
StringRef getConstantValue() const
Attribute getAttribute() const
StringRef getSymbol() const
const llvm::Record & getDef() const
EnumAttrCase(const llvm::Record *record)
StringRef getStringToSymbolFnName() const
StringRef getSpecializedAttrClassName() const
StringRef getEnumClassName() const
StringRef getSymbolToStringFnRetType() const
bool printBitEnumPrimaryGroups() const
EnumAttr(const llvm::Record *record)
StringRef getCppNamespace() const
StringRef getSymbolToStringFnName() const
static bool classof(const Attribute *attr)
bool genSpecializedAttr() const
StringRef getUnderlyingToSymbolFnName() const
StringRef getUnderlyingType() const
StringRef getMaxEnumValFnName() const
std::vector< EnumAttrCase > getAllCases() const
const llvm::Record * getBaseAttrClass() const
const char * inferTypeOpInterface
Include the generated interface declarations.