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 (
auto *defInit = dyn_cast<llvm::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 =
96 llvm::dyn_cast<llvm::DefInit>(
def->getValueInit(
"baseAttr"))) {
103 const auto *init =
def->getValueInit(
"defaultValue");
108 const auto *init =
def->getValueInit(
"defaultValue");
115 if (
def->isAnonymous()) {
118 return def->getName();
122 assert(
isDerivedAttr() &&
"only derived attribute has 'body' field");
123 return def->getValueAsString(
"body");
127 const llvm::RecordVal *record =
def->getValue(
"dialect");
128 if (record && record->getValue()) {
129 if (DefInit *init = dyn_cast<DefInit>(record->getValue()))
130 return Dialect(init->getDef());
138 assert(def->isSubClassOf(
"ConstantAttr") &&
139 "must be subclass of TableGen 'ConstantAttr' class");
143 return Attribute(def->getValueAsDef(
"attr"));
147 return def->getValueAsString(
"value");
152 "must be subclass of TableGen 'EnumAttrInfo' class");
159 return def->getValueAsString(
"symbol");
170 "must be subclass of TableGen 'EnumAttr' class");
184 return def->getValueAsString(
"className");
188 return def->getValueAsString(
"cppNamespace");
192 return def->getValueAsString(
"underlyingType");
196 return def->getValueAsString(
"underlyingToSymbolFnName");
200 return def->getValueAsString(
"stringToSymbolFnName");
204 return def->getValueAsString(
"symbolToStringFnName");
208 return def->getValueAsString(
"symbolToStringFnRetType");
212 return def->getValueAsString(
"maxEnumValFnName");
216 const auto *inits =
def->getValueAsListInit(
"enumerants");
218 std::vector<EnumAttrCase> cases;
219 cases.reserve(inits->size());
221 for (
const llvm::Init *init : *inits) {
222 cases.emplace_back(cast<llvm::DefInit>(init));
229 return def->getValueAsBit(
"genSpecializedAttr");
233 return def->getValueAsDef(
"baseAttrClass");
237 return def->getValueAsString(
"specializedAttrClassName");
241 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)
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
const llvm::Record & getDef() const
ConstantAttr(const llvm::DefInit *init)
StringRef getConstantValue() const
Attribute getAttribute() const
StringRef getSymbol() const
EnumAttrCase(const llvm::Record *record)
const llvm::Record & getDef() const
llvm::Record * getBaseAttrClass() const
StringRef getStringToSymbolFnName() const
StringRef getSpecializedAttrClassName() const
StringRef getEnumClassName() const
StringRef getSymbolToStringFnRetType() const
bool printBitEnumPrimaryGroups() const
StringRef getCppNamespace() const
StringRef getSymbolToStringFnName() const
static bool classof(const Attribute *attr)
bool genSpecializedAttr() const
EnumAttr(const llvm::Record *record)
StringRef getUnderlyingToSymbolFnName() const
StringRef getUnderlyingType() const
StringRef getMaxEnumValFnName() const
std::vector< EnumAttrCase > getAllCases() const
const char * inferTypeOpInterface
This header declares functions that assit transformations in the MemRef dialect.