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")) {
33 }
else if(!
def->isSubClassOf(
"Constraint")) {
34 llvm::errs() <<
"Expected a constraint but got: \n" << *
def <<
"\n";
35 llvm::report_fatal_error(
"Abort");
40 auto *val =
def->getValue(
"predicate");
47 const auto *pred = dyn_cast<llvm::DefInit>(val->getValue());
56 if (std::optional<StringRef> summary =
57 def->getValueAsOptionalString(
"summary"))
59 return def->getName();
63 return def->getValueAsOptionalString(
"description").value_or(
"");
67 if (std::optional<StringRef> baseDefName = getBaseDefName())
69 return def->getName();
73 std::string defName =
def->getName().str();
76 if (!
def->isAnonymous())
82 if (std::optional<StringRef> baseDefName = getBaseDefName())
83 return (*baseDefName +
"(" + defName +
")").str();
87 std::optional<StringRef> Constraint::getBaseDefName()
const {
90 auto checkBaseDefFn = [&](StringRef baseName) -> std::optional<StringRef> {
91 if (
const auto *defValue =
def->getValue(baseName)) {
92 if (
const auto *defInit = dyn_cast<llvm::DefInit>(defValue->getValue()))
100 if (
def->isAnonymous())
101 return checkBaseDefFn(
"baseAttr");
104 if (
def->isAnonymous())
105 return checkBaseDefFn(
"baseType");
113 llvm::StringRef
self,
114 std::vector<std::string> &&entities)
115 : constraint(constraint), self(std::string(self)),
116 entities(std::move(entities)) {}
119 return Constraint(RecordDenseMapInfo::getEmptyKey(),
124 return Constraint(RecordDenseMapInfo::getTombstoneKey(),
129 if (constraint == getEmptyKey())
130 return RecordDenseMapInfo::getHashValue(RecordDenseMapInfo::getEmptyKey());
131 if (constraint == getTombstoneKey()) {
132 return RecordDenseMapInfo::getHashValue(
133 RecordDenseMapInfo::getTombstoneKey());
141 if (lhs == getEmptyKey() || lhs == getTombstoneKey())
143 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
Include the generated interface declarations.
AppliedConstraint(Constraint &&constraint, StringRef self, std::vector< std::string > &&entities)