15 #include "llvm/TableGen/Record.h"
23 using llvm::StringInit;
28 if (
const auto *str = dyn_cast<StringInit>(init))
29 return str->getValue().trim();
34 return def->isSubClassOf(className);
38 assert(record->isSubClassOf(
"Attr") &&
39 "must be subclass of TableGen 'Attr' class");
49 StringRef defName =
def->getName();
50 if (defName ==
"SymbolRefAttr" || defName ==
"FlatSymbolRefAttr")
58 const auto *init =
def->getValueInit(
"storageType");
61 return "::mlir::Attribute";
66 const auto *init =
def->getValueInit(
"returnType");
73 if (
const auto *defInit = dyn_cast<DefInit>(
def->getValueInit(
"valueType")))
74 return Type(defInit->getDef());
79 const auto *init =
def->getValueInit(
"convertFromStorage");
84 const auto *init =
def->getValueInit(
"constBuilderCall");
89 const auto *init =
def->getValueInit(
"constBuilderCall");
94 if (
const auto *defInit = dyn_cast<DefInit>(
def->getValueInit(
"baseAttr"))) {
101 const auto *init =
def->getValueInit(
"defaultValue");
106 const auto *init =
def->getValueInit(
"defaultValue");
113 if (
def->isAnonymous()) {
116 return def->getName();
120 assert(
isDerivedAttr() &&
"only derived attribute has 'body' field");
121 return def->getValueAsString(
"body");
125 const llvm::RecordVal *record =
def->getValue(
"dialect");
126 if (record && record->getValue()) {
127 if (
const DefInit *init = dyn_cast<DefInit>(record->getValue()))
128 return Dialect(init->getDef());
136 assert(def->isSubClassOf(
"ConstantAttr") &&
137 "must be subclass of TableGen 'ConstantAttr' class");
141 return Attribute(def->getValueAsDef(
"attr"));
145 return def->getValueAsString(
"value");
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
const char * inferTypeOpInterface
Include the generated interface declarations.