14 #include "llvm/TableGen/Record.h"
22 if (
def->isSubClassOf(
"OpVariable"))
23 def =
def->getValueAsDef(
"constraint");
25 if (
def->isSubClassOf(
"TypeConstraint")) {
27 }
else if (
def->isSubClassOf(
"AttrConstraint")) {
29 }
else if (
def->isSubClassOf(
"RegionConstraint")) {
31 }
else if (
def->isSubClassOf(
"SuccessorConstraint")) {
34 assert(
def->isSubClassOf(
"Constraint"));
39 auto *val =
def->getValue(
"predicate");
46 const auto *pred = dyn_cast<llvm::DefInit>(val->getValue());
55 if (std::optional<StringRef> summary =
56 def->getValueAsOptionalString(
"summary"))
58 return def->getName();
62 return def->getValueAsOptionalString(
"description").value_or(
"");
66 if (std::optional<StringRef> baseDefName = getBaseDefName())
68 return def->getName();
72 std::string defName =
def->getName().str();
75 if (!
def->isAnonymous())
81 if (std::optional<StringRef> baseDefName = getBaseDefName())
82 return (*baseDefName +
"(" + defName +
")").str();
86 std::optional<StringRef> Constraint::getBaseDefName()
const {
89 auto checkBaseDefFn = [&](StringRef baseName) -> std::optional<StringRef> {
90 if (
const auto *defValue =
def->getValue(baseName)) {
91 if (
const auto *defInit = dyn_cast<llvm::DefInit>(defValue->getValue()))
99 if (
def->isAnonymous())
100 return checkBaseDefFn(
"baseAttr");
103 if (
def->isAnonymous())
104 return checkBaseDefFn(
"baseType");
112 llvm::StringRef
self,
113 std::vector<std::string> &&entities)
114 : constraint(constraint), self(std::string(self)),
115 entities(std::move(entities)) {}
118 return Constraint(RecordDenseMapInfo::getEmptyKey(),
123 return Constraint(RecordDenseMapInfo::getTombstoneKey(),
128 if (constraint == getEmptyKey())
129 return RecordDenseMapInfo::getHashValue(RecordDenseMapInfo::getEmptyKey());
130 if (constraint == getTombstoneKey()) {
131 return RecordDenseMapInfo::getHashValue(
132 RecordDenseMapInfo::getTombstoneKey());
140 if (lhs == getEmptyKey() || lhs == getTombstoneKey())
142 if (rhs == getEmptyKey() || rhs == getTombstoneKey())
Pred getPredicate() const
StringRef getSummary() const
std::string getUniqueDefName() const
Returns a unique name for the TablGen def of this constraint.
StringRef getDescription() const
StringRef getDefName() const
Returns the name of the TablGen def of this constraint.
Constraint(const llvm::Record *record, Kind kind)
std::string getConditionTemplate() const
std::string getCondition() const
This header declares functions that assist transformations in the MemRef dialect.
AppliedConstraint(Constraint &&constraint, StringRef self, std::vector< std::string > &&entities)