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 std::optional<StringRef> name =
114 def->getValueAsOptionalString(
"cppFunctionName");
115 if (!name || *name ==
"")
121 llvm::StringRef
self,
122 std::vector<std::string> &&entities)
123 : constraint(constraint), self(std::string(self)),
124 entities(std::move(entities)) {}
127 return Constraint(RecordDenseMapInfo::getEmptyKey(),
132 return Constraint(RecordDenseMapInfo::getTombstoneKey(),
137 if (constraint == getEmptyKey())
138 return RecordDenseMapInfo::getHashValue(RecordDenseMapInfo::getEmptyKey());
139 if (constraint == getTombstoneKey()) {
140 return RecordDenseMapInfo::getHashValue(
141 RecordDenseMapInfo::getTombstoneKey());
149 if (lhs == getEmptyKey() || lhs == getTombstoneKey())
151 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)