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());
59 if (!
def->getValue(
"cppIncludes"))
61 return def->getValueAsListOfStrings(
"cppIncludes");
65 if (std::optional<StringRef> summary =
66 def->getValueAsOptionalString(
"summary"))
68 return def->getName();
72 return def->getValueAsOptionalString(
"description").value_or(
"");
76 if (std::optional<StringRef> baseDefName = getBaseDefName())
78 return def->getName();
82 std::string defName =
def->getName().str();
85 if (!
def->isAnonymous())
91 if (std::optional<StringRef> baseDefName = getBaseDefName())
92 return (*baseDefName +
"(" + defName +
")").str();
96std::optional<StringRef> Constraint::getBaseDefName()
const {
99 auto checkBaseDefFn = [&](StringRef baseName) -> std::optional<StringRef> {
100 if (
const auto *defValue =
def->getValue(baseName)) {
101 if (
const auto *defInit = dyn_cast<llvm::DefInit>(defValue->getValue()))
102 return Constraint(defInit->getDef(), kind).getDefName();
109 if (
def->isAnonymous())
110 return checkBaseDefFn(
"baseAttr");
113 if (
def->isAnonymous())
114 return checkBaseDefFn(
"baseType");
122 std::optional<StringRef> name =
123 def->getValueAsOptionalString(
"cppFunctionName");
124 if (!name || *name ==
"")
130 llvm::StringRef
self,
131 std::vector<std::string> &&
entities)
142 return lhs.getPredicate() == rhs.getPredicate() &&
143 lhs.getSummary() == rhs.getSummary();
if(failed(verifyVectorMemoryOp(getOperation(), memrefType, getVectorType()))) return failure()
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::vector< StringRef > getCppIncludes() const
Returns the C++ headers declaring the C++ classes this type or attribute constraint refers to.
std::string getConditionTemplate() const
std::string getCondition() const
Include the generated interface declarations.
llvm::DenseMapInfo< T, Enable > DenseMapInfo
std::vector< std::string > entities
AppliedConstraint(Constraint &&constraint, StringRef self, std::vector< std::string > &&entities)