[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / mlir / test / mlir-tblgen / constraint-unique.td
blob0d377a454d6f5d363184052aeeb0551951e14572
1 // RUN: mlir-tblgen -gen-op-defs -I %S/../../include %s | FileCheck %s
3 include "mlir/IR/OpBase.td"
5 def Test_Dialect : Dialect {
6   let name = "test";
9 class NS_Op<string mnemonic, list<Trait> traits = []> :
10     Op<Test_Dialect, mnemonic, traits>;
12 /// Test unique'ing of type, attribute, successor, and region constraints.
14 def ATypePred : CPred<"typePred($_self, $_op)">;
15 def AType : Type<ATypePred, "a type">;
16 def OtherType : Type<ATypePred, "another type">;
18 def AnAttrPred : CPred<"attrPred($_self, $_op)">;
19 def AnAttr : Attr<AnAttrPred, "an attribute">;
20 def OtherAttr : Attr<AnAttrPred, "another attribute">;
22 def ASuccessorPred : CPred<"successorPred($_self, $_op)">;
23 def ASuccessor : Successor<ASuccessorPred, "a successor">;
24 def OtherSuccessor : Successor<ASuccessorPred, "another successor">;
26 def ARegionPred : CPred<"regionPred($_self, $_op)">;
27 def ARegion : Region<ARegionPred, "a region">;
28 def OtherRegion : Region<ARegionPred, "another region">;
30 // OpA and OpB have the same type, attribute, successor, and region constraints.
32 def OpA : NS_Op<"op_a"> {
33   let arguments = (ins AType:$a, AnAttr:$b);
34   let results = (outs AType:$ret);
35   let successors = (successor ASuccessor:$c);
36   let regions = (region ARegion:$d);
39 def OpB : NS_Op<"op_b"> {
40   let arguments = (ins AType:$a, AnAttr:$b);
41   let successors = (successor ASuccessor:$c);
42   let regions = (region ARegion:$d);
45 // OpC has the same type, attribute, successor, and region predicates but has
46 // difference descriptions for them.
48 def OpC : NS_Op<"op_c"> {
49   let arguments = (ins OtherType:$a, OtherAttr:$b);
50   let results = (outs OtherType:$ret);
51   let successors = (successor OtherSuccessor:$c);
52   let regions = (region OtherRegion:$d);
55 /// Test that a type contraint was generated.
56 // CHECK:    static ::mlir::LogicalResult [[$A_TYPE_CONSTRAINT:__mlir_ods_local_type_constraint.*]](
57 // CHECK:      if (!((typePred(type, *op)))) {
58 // CHECK-NEXT:   return op->emitOpError(valueKind) << " #" << valueIndex
59 // CHECK-NEXT:       << " must be a type, but got " << type;
61 /// Test that duplicate type constraint was not generated.
62 // CHECK-NOT:        << " must be a type, but got " << type;
64 /// Test that a type constraint with a different description was generated.
65 // CHECK:    static ::mlir::LogicalResult [[$O_TYPE_CONSTRAINT:__mlir_ods_local_type_constraint.*]](
66 // CHECK:      if (!((typePred(type, *op)))) {
67 // CHECK-NEXT:   return op->emitOpError(valueKind) << " #" << valueIndex
68 // CHECK-NEXT:       << " must be another type, but got " << type;
70 /// Test that an attribute contraint was generated.
71 // CHECK:    static ::mlir::LogicalResult [[$A_ATTR_CONSTRAINT:__mlir_ods_local_attr_constraint.*]](
72 // CHECK:      if (attr && !((attrPred(attr, *op)))) {
73 // CHECK-NEXT:   return op->emitOpError("attribute '") << attrName
74 // CHECK-NEXT:       << "' failed to satisfy constraint: an attribute";
76 /// Test that duplicate attribute constraint was not generated.
77 // CHECK-NOT:        << "' failed to satisfy constraint: an attribute";
79 /// Test that a attribute constraint with a different description was generated.
80 // CHECK:    static ::mlir::LogicalResult [[$O_ATTR_CONSTRAINT:__mlir_ods_local_attr_constraint.*]](
81 // CHECK:      if (attr && !((attrPred(attr, *op)))) {
82 // CHECK-NEXT:   return op->emitOpError("attribute '") << attrName
83 // CHECK-NEXT:       << "' failed to satisfy constraint: another attribute";
85 /// Test that a successor contraint was generated.
86 // CHECK:    static ::mlir::LogicalResult [[$A_SUCCESSOR_CONSTRAINT:__mlir_ods_local_successor_constraint.*]](
87 // CHECK:      if (!((successorPred(successor, *op)))) {
88 // CHECK-NEXT:   return op->emitOpError("successor #") << successorIndex << " ('"
89 // CHECK-NEXT:       << successorName << ")' failed to verify constraint: a successor";
91 /// Test that duplicate successor constraint was not generated.
92 // CHECK-NOT:        << successorName << ")' failed to verify constraint: a successor";
94 /// Test that a successor constraint with a different description was generated.
95 // CHECK:    static ::mlir::LogicalResult [[$O_SUCCESSOR_CONSTRAINT:__mlir_ods_local_successor_constraint.*]](
96 // CHECK:      if (!((successorPred(successor, *op)))) {
97 // CHECK-NEXT:   return op->emitOpError("successor #") << successorIndex << " ('"
98 // CHECK-NEXT:       << successorName << ")' failed to verify constraint: another successor";
100 /// Test that a region contraint was generated.
101 // CHECK:    static ::mlir::LogicalResult [[$A_REGION_CONSTRAINT:__mlir_ods_local_region_constraint.*]](
102 // CHECK:      if (!((regionPred(region, *op)))) {
103 // CHECK-NEXT:   return op->emitOpError("region #") << regionIndex
104 // CHECK-NEXT:       << (regionName.empty() ? " " : " ('" + regionName + "') ")
105 // CHECK-NEXT:       << "failed to verify constraint: a region";
107 /// Test that duplicate region constraint was not generated.
108 // CHECK-NOT:        << "failed to verify constraint: a region";
110 /// Test that a region constraint with a different description was generated.
111 // CHECK:    static ::mlir::LogicalResult [[$O_REGION_CONSTRAINT:__mlir_ods_local_region_constraint.*]](
112 // CHECK:      if (!((regionPred(region, *op)))) {
113 // CHECK-NEXT:   return op->emitOpError("region #") << regionIndex
114 // CHECK-NEXT:       << (regionName.empty() ? " " : " ('" + regionName + "') ")
115 // CHECK-NEXT:       << "failed to verify constraint: another region";
117 /// Test that the uniqued constraints are being used.
118 // CHECK-LABEL: OpA::verify
119 // CHECK:         ::mlir::Attribute [[$B_ATTR:.*b]];
120 // CHECK:         if (::mlir::failed([[$A_ATTR_CONSTRAINT]](*this, [[$B_ATTR]], "b")))
121 // CHECK-NEXT:      return ::mlir::failure();
122 // CHECK:         auto [[$A_VALUE_GROUP:.*]] = getODSOperands(0);
123 // CHECK:         for (auto [[$A_VALUE:.*]] : [[$A_VALUE_GROUP]])
124 // CHECK-NEXT:      if (::mlir::failed([[$A_TYPE_CONSTRAINT]](*this, [[$A_VALUE]].getType(), "operand", index++)))
125 // CHECK-NEXT:        return ::mlir::failure();
126 // CHECK:         auto [[$RET_VALUE_GROUP:.*]] = getODSResults(0);
127 // CHECK:         for (auto [[$RET_VALUE:.*]] : [[$RET_VALUE_GROUP]])
128 // CHECK-NEXT:      if (::mlir::failed([[$A_TYPE_CONSTRAINT]](*this, [[$RET_VALUE]].getType(), "result", index++)))
129 // CHECK-NEXT:        return ::mlir::failure();
130 // CHECK:         for (auto &region : ::llvm::MutableArrayRef((*this)->getRegion(0)))
131 // CHECK-NEXT:      if (::mlir::failed([[$A_REGION_CONSTRAINT]](*this, region, "d", index++)))
132 // CHECK-NEXT:        return ::mlir::failure();
133 // CHECK:         for (auto *successor : ::llvm::MutableArrayRef(c()))
134 // CHECK-NEXT:      if (::mlir::failed([[$A_SUCCESSOR_CONSTRAINT]](*this, successor, "c", index++)))
135 // CHECK-NEXT:        return ::mlir::failure();
137 /// Test that the op with the same predicates but different with descriptions
138 /// uses the different constraints.
139 // CHECK-LABEL: OpC::verify
140 // CHECK:         ::mlir::Attribute [[$B_ATTR:.*b]];
141 // CHECK:         if (::mlir::failed([[$O_ATTR_CONSTRAINT]](*this, [[$B_ATTR]], "b")))
142 // CHECK-NEXT:      return ::mlir::failure();
143 // CHECK:         auto [[$A_VALUE_GROUP:.*]] = getODSOperands(0);
144 // CHECK:         for (auto [[$A_VALUE:.*]] : [[$A_VALUE_GROUP]])
145 // CHECK-NEXT:      if (::mlir::failed([[$O_TYPE_CONSTRAINT]](*this, [[$A_VALUE]].getType(), "operand", index++)))
146 // CHECK-NEXT:        return ::mlir::failure();
147 // CHECK:         auto [[$RET_VALUE_GROUP:.*]] = getODSResults(0);
148 // CHECK:         for (auto [[$RET_VALUE:.*]] : [[$RET_VALUE_GROUP]])
149 // CHECK-NEXT:      if (::mlir::failed([[$O_TYPE_CONSTRAINT]](*this, [[$RET_VALUE]].getType(), "result", index++)))
150 // CHECK-NEXT:        return ::mlir::failure();
151 // CHECK:         for (auto &region : ::llvm::MutableArrayRef((*this)->getRegion(0)))
152 // CHECK-NEXT:      if (::mlir::failed([[$O_REGION_CONSTRAINT]](*this, region, "d", index++)))
153 // CHECK-NEXT:        return ::mlir::failure();
154 // CHECK:         for (auto *successor : ::llvm::MutableArrayRef(c()))
155 // CHECK-NEXT:      if (::mlir::failed([[$O_SUCCESSOR_CONSTRAINT]](*this, successor, "c", index++)))
156 // CHECK-NEXT:        return ::mlir::failure();