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");
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.