15#include "llvm/TableGen/Record.h"
23using 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")
60 const auto *init =
def->getValueInit(
"storageType");
63 return "::mlir::Attribute";
68 const auto *init =
def->getValueInit(
"returnType");
75 if (
const auto *defInit = dyn_cast<DefInit>(
def->getValueInit(
"valueType")))
76 return Type(defInit->getDef());
81 const auto *init =
def->getValueInit(
"convertFromStorage");
86 const auto *init =
def->getValueInit(
"constBuilderCall");
91 const auto *init =
def->getValueInit(
"constBuilderCall");
96 if (
const auto *defInit = dyn_cast<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 (
const 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");
static StringRef getValueAsString(const Init *init)
Attributes are known-constant values of operations.
constexpr Attribute()=default
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.