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(
"PropConstraint")) {
31 }
else if (
def->isSubClassOf(
"RegionConstraint")) {
33 }
else if (
def->isSubClassOf(
"SuccessorConstraint")) {
35 }
else if (!
def->isSubClassOf(
"Constraint")) {
36 llvm::errs() <<
"Expected a constraint but got: \n" << *
def <<
"\n";
37 llvm::report_fatal_error(
"Abort");
42 auto *val =
def->getValue(
"predicate");
49 const auto *pred = dyn_cast<llvm::DefInit>(val->getValue());
58 if (std::optional<StringRef> summary =
59 def->getValueAsOptionalString(
"summary"))
61 return def->getName();
65 return def->getValueAsOptionalString(
"description").value_or(
"");
69 if (std::optional<StringRef> baseDefName = getBaseDefName())
71 return def->getName();
75 std::string defName =
def->getName().str();
78 if (!
def->isAnonymous())
84 if (std::optional<StringRef> baseDefName = getBaseDefName())
85 return (*baseDefName +
"(" + defName +
")").str();
89 std::optional<StringRef> Constraint::getBaseDefName()
const {
92 auto checkBaseDefFn = [&](StringRef baseName) -> std::optional<StringRef> {
93 if (
const auto *defValue =
def->getValue(baseName)) {
94 if (
const auto *defInit = dyn_cast<llvm::DefInit>(defValue->getValue()))
102 if (
def->isAnonymous())
103 return checkBaseDefFn(
"baseAttr");
106 if (
def->isAnonymous())
107 return checkBaseDefFn(
"baseType");
115 std::optional<StringRef> name =
116 def->getValueAsOptionalString(
"cppFunctionName");
117 if (!name || *name ==
"")
123 llvm::StringRef
self,
124 std::vector<std::string> &&entities)
125 : constraint(constraint), self(std::string(self)),
126 entities(std::move(entities)) {}
129 return Constraint(RecordDenseMapInfo::getEmptyKey(),
134 return Constraint(RecordDenseMapInfo::getTombstoneKey(),
139 if (constraint == getEmptyKey())
140 return RecordDenseMapInfo::getHashValue(RecordDenseMapInfo::getEmptyKey());
141 if (constraint == getTombstoneKey()) {
142 return RecordDenseMapInfo::getHashValue(
143 RecordDenseMapInfo::getTombstoneKey());
151 if (lhs == getEmptyKey() || lhs == getTombstoneKey())
153 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.
std::optional< StringRef > getCppFunctionName() const
Returns the name of the C++ function that should be generated for 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)