MLIR: lib/TableGen/Constraint.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

14#include "llvm/TableGen/Record.h"

15

16using namespace mlir;

18

21

22 if (def->isSubClassOf("OpVariable"))

23 def = def->getValueAsDef("constraint");

24

25 if (def->isSubClassOf("TypeConstraint")) {

26 kind = CK_Type;

27 } else if (def->isSubClassOf("AttrConstraint")) {

28 kind = CK_Attr;

29 } else if (def->isSubClassOf("PropConstraint")) {

30 kind = CK_Prop;

31 } else if (def->isSubClassOf("RegionConstraint")) {

32 kind = CK_Region;

33 } else if (def->isSubClassOf("SuccessorConstraint")) {

34 kind = CK_Successor;

35 } else if (def->isSubClassOf("Constraint")) {

36 llvm::errs() << "Expected a constraint but got: \n" << *def << "\n";

37 llvm::report_fatal_error("Abort");

38 }

39}

40

42 auto *val = def->getValue("predicate");

43

44

45

46 if (!val)

47 return Pred();

48

49 const auto *pred = dyn_castllvm::DefInit(val->getValue());

50 return Pred(pred);

51}

52

56

58 if (std::optional summary =

59 def->getValueAsOptionalString("summary"))

60 return *summary;

61 return def->getName();

62}

63

65 return def->getValueAsOptionalString("description").value_or("");

66}

67

69 if (std::optional baseDefName = getBaseDefName())

70 return *baseDefName;

71 return def->getName();

72}

73

75 std::string defName = def->getName().str();

76

77

78 if (def->isAnonymous())

79 return defName;

80

81

82

83

84 if (std::optional baseDefName = getBaseDefName())

85 return (*baseDefName + "(" + defName + ")").str();

86 return defName;

87}

88

89std::optional Constraint::getBaseDefName() const {

90

91

92 auto checkBaseDefFn = [&](StringRef baseName) -> std::optional {

93 if (const auto *defValue = def->getValue(baseName)) {

94 if (const auto *defInit = dyn_castllvm::DefInit(defValue->getValue()))

95 return Constraint(defInit->getDef(), kind).getDefName();

96 }

97 return std::nullopt;

98 };

99

100 switch (kind) {

102 if (def->isAnonymous())

103 return checkBaseDefFn("baseAttr");

104 return std::nullopt;

106 if (def->isAnonymous())

107 return checkBaseDefFn("baseType");

108 return std::nullopt;

109 default:

110 return std::nullopt;

111 }

112}

113

115 std::optional name =

116 def->getValueAsOptionalString("cppFunctionName");

117 if (!name || *name == "")

118 return std::nullopt;

119 return name;

120}

121

123 llvm::StringRef self,

124 std::vectorstd::string &&entities)

127

129 return Constraint(RecordDenseMapInfo::getEmptyKey(),

131}

132

134 return Constraint(RecordDenseMapInfo::getTombstoneKey(),

136}

137

139 if (constraint == getEmptyKey())

140 return RecordDenseMapInfo::getHashValue(RecordDenseMapInfo::getEmptyKey());

141 if (constraint == getTombstoneKey()) {

142 return RecordDenseMapInfo::getHashValue(

143 RecordDenseMapInfo::getTombstoneKey());

144 }

146}

147

150 return true;

151 if (lhs == getEmptyKey() || lhs == getTombstoneKey())

152 return false;

153 if (rhs == getEmptyKey() || rhs == getTombstoneKey())

154 return false;

155 return lhs.getPredicate() == rhs.getPredicate() &&

156 lhs.getSummary() == rhs.getSummary();

157}

Pred getPredicate() const

Definition Constraint.cpp:41

StringRef getSummary() const

Definition Constraint.cpp:57

std::string getUniqueDefName() const

Returns a unique name for the TablGen def of this constraint.

Definition Constraint.cpp:74

StringRef getDescription() const

Definition Constraint.cpp:64

StringRef getDefName() const

Returns the name of the TablGen def of this constraint.

Definition Constraint.cpp:68

std::optional< StringRef > getCppFunctionName() const

Returns the name of the C++ function that should be generated for this constraint,...

Definition Constraint.cpp:114

Constraint(const llvm::Record *record, Kind kind)

std::string getConditionTemplate() const

Definition Constraint.cpp:53

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)

Definition Constraint.cpp:122