1 // RUN: mlir-tblgen -gen-op-defs -I %S/../../include %s | FileCheck %s
3 include "mlir/IR/OpBase.td"
5 def Test_Dialect : Dialect {
8 class NS_Op<string mnemonic, list<Trait> traits> :
9 Op<Test_Dialect, mnemonic, traits>;
11 def I32OrF32 : Type<CPred<"$_self.isInteger(32) || $_self.isF32()">,
12 "32-bit integer or floating-point type">;
14 def OpA : NS_Op<"op_for_CPred_containing_multiple_same_placeholder", []> {
15 let arguments = (ins I32OrF32:$x);
16 let results = (outs Variadic<I32OrF32>:$y);
19 // CHECK: static ::llvm::LogicalResult [[$INTEGER_FLOAT_CONSTRAINT:__mlir_ods_local_type_constraint.*]](
20 // CHECK: if (!((type.isInteger(32) || type.isF32()))) {
21 // CHECK-NEXT: return op->emitOpError(valueKind) << " #" << valueIndex
22 // CHECK-NEXT: << " must be 32-bit integer or floating-point type, but got " << type;
24 // Check there is no verifier with same predicate generated.
25 // CHECK-NOT: if (!((type.isInteger(32) || type.isF32()))) {
26 // CHECK-NOT: return op->emitOpError(valueKind) << " #" << valueIndex
27 // CHECK-NOT. << " must be 32-bit integer or floating-point type, but got " << type;
29 // CHECK: static ::llvm::LogicalResult [[$TENSOR_CONSTRAINT:__mlir_ods_local_type_constraint.*]](
30 // CHECK: if (!(((::llvm::isa<::mlir::TensorType>(type))) && ([](::mlir::Type elementType) { return (true); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) {
31 // CHECK-NEXT: return op->emitOpError(valueKind) << " #" << valueIndex
32 // CHECK-NEXT: << " must be tensor of any type values, but got " << type;
34 // CHECK: static ::llvm::LogicalResult [[$TENSOR_INTEGER_FLOAT_CONSTRAINT:__mlir_ods_local_type_constraint.*]](
35 // CHECK: if (!(((::llvm::isa<::mlir::TensorType>(type))) && ([](::mlir::Type elementType) { return ((elementType.isF32())) || ((elementType.isSignlessInteger(32))); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) {
36 // CHECK-NEXT: return op->emitOpError(valueKind) << " #" << valueIndex
37 // CHECK-NEXT: << " must be tensor of 32-bit float or 32-bit signless integer values, but got " << type;
39 // CHECK-LABEL: OpA::verify
40 // CHECK: auto valueGroup0 = getODSOperands(0);
41 // CHECK: for (auto v : valueGroup0) {
42 // CHECK: if (::mlir::failed([[$INTEGER_FLOAT_CONSTRAINT]]
44 def OpB : NS_Op<"op_for_And_PredOpTrait", [
45 PredOpTrait<"both first and second holds",
46 And<[CPred<"first">, CPred<"second">]>>]> {
49 // CHECK-LABEL: OpB::verify
50 // CHECK: if (!(((first)) && ((second))))
52 def OpF : NS_Op<"op_for_int_min_val", []> {
53 let arguments = (ins ConfinedAttr<I32Attr, [IntMinValue<10>]>:$attr);
56 // CHECK-LABEL: OpFAdaptor::verify
57 // CHECK: (::llvm::cast<::mlir::IntegerAttr>(tblgen_attr).getInt() >= 10)
58 // CHECK-NEXT: "attribute 'attr' failed to satisfy constraint: 32-bit signless integer attribute whose minimum value is 10"
60 def OpFX : NS_Op<"op_for_int_max_val", []> {
61 let arguments = (ins ConfinedAttr<I32Attr, [IntMaxValue<10>]>:$attr);
64 // CHECK-LABEL: OpFXAdaptor::verify
65 // CHECK: (::llvm::cast<::mlir::IntegerAttr>(tblgen_attr).getInt() <= 10)
66 // CHECK-NEXT: "attribute 'attr' failed to satisfy constraint: 32-bit signless integer attribute whose maximum value is 10"
68 def OpG : NS_Op<"op_for_arr_min_count", []> {
69 let arguments = (ins ConfinedAttr<ArrayAttr, [ArrayMinCount<8>]>:$attr);
72 // CHECK-LABEL: OpGAdaptor::verify
73 // CHECK: (::llvm::cast<::mlir::ArrayAttr>(tblgen_attr).size() >= 8)
74 // CHECK-NEXT: "attribute 'attr' failed to satisfy constraint: array attribute with at least 8 elements"
76 def OpH : NS_Op<"op_for_arr_value_at_index", []> {
77 let arguments = (ins ConfinedAttr<ArrayAttr, [IntArrayNthElemEq<0, 8>]>:$attr);
80 // CHECK-LABEL: OpHAdaptor::verify
81 // CHECK: (((::llvm::cast<::mlir::ArrayAttr>(tblgen_attr).size() > 0)) && ((::llvm::cast<::mlir::IntegerAttr>(::llvm::cast<::mlir::ArrayAttr>(tblgen_attr)[0]).getInt() == 8)))))
82 // CHECK-NEXT: "attribute 'attr' failed to satisfy constraint: array attribute whose 0-th element must be 8"
84 def OpI: NS_Op<"op_for_arr_min_value_at_index", []> {
85 let arguments = (ins ConfinedAttr<ArrayAttr, [IntArrayNthElemMinValue<0, 8>]>:$attr);
88 // CHECK-LABEL: OpIAdaptor::verify
89 // CHECK: (((::llvm::cast<::mlir::ArrayAttr>(tblgen_attr).size() > 0)) && ((::llvm::cast<::mlir::IntegerAttr>(::llvm::cast<::mlir::ArrayAttr>(tblgen_attr)[0]).getInt() >= 8)))))
90 // CHECK-NEXT: "attribute 'attr' failed to satisfy constraint: array attribute whose 0-th element must be at least 8"
92 def OpJ: NS_Op<"op_for_arr_max_value_at_index", []> {
93 let arguments = (ins ConfinedAttr<ArrayAttr, [IntArrayNthElemMaxValue<0, 8>]>:$attr);
96 // CHECK-LABEL: OpJAdaptor::verify
97 // CHECK: (((::llvm::cast<::mlir::ArrayAttr>(tblgen_attr).size() > 0)) && ((::llvm::cast<::mlir::IntegerAttr>(::llvm::cast<::mlir::ArrayAttr>(tblgen_attr)[0]).getInt() <= 8)))))
98 // CHECK-NEXT: "attribute 'attr' failed to satisfy constraint: array attribute whose 0-th element must be at most 8"
100 def OpK: NS_Op<"op_for_arr_in_range_at_index", []> {
101 let arguments = (ins ConfinedAttr<ArrayAttr, [IntArrayNthElemInRange<0, 4, 8>]>:$attr);
104 // CHECK-LABEL: OpKAdaptor::verify
105 // CHECK: (((::llvm::cast<::mlir::ArrayAttr>(tblgen_attr).size() > 0)) && ((::llvm::cast<::mlir::IntegerAttr>(::llvm::cast<::mlir::ArrayAttr>(tblgen_attr)[0]).getInt() >= 4)) && ((::llvm::cast<::mlir::IntegerAttr>(::llvm::cast<::mlir::ArrayAttr>(tblgen_attr)[0]).getInt() <= 8)))))
106 // CHECK-NEXT: "attribute 'attr' failed to satisfy constraint: array attribute whose 0-th element must be at least 4 and at most 8"
108 def OpL: NS_Op<"op_for_TCopVTEtAreSameAt", [
109 PredOpTrait<"operands indexed at 0, 2, 3 should all have "
110 "the same type", TCopVTEtAreSameAt<[0, 2, 3]>>]> {
120 // CHECK-LABEL: OpLAdaptor::verify
121 // CHECK: ::llvm::all_equal(::llvm::map_range(
122 // CHECK-SAME: ::mlir::ArrayRef<unsigned>({0, 2, 3}),
123 // CHECK-SAME: [this](unsigned i) { return getElementTypeOrSelf(this->getOperand(i)); }))
124 // CHECK: "failed to verify that operands indexed at 0, 2, 3 should all have the same type"
126 def OpM : NS_Op<"op_for_AnyTensorOf", []> {
127 let arguments = (ins TensorOf<[F32, I32]>:$x);
130 // CHECK-LABEL: OpM::verify
131 // CHECK: auto valueGroup0 = getODSOperands(0);
132 // CHECK: for (auto v : valueGroup0) {
133 // CHECK: if (::mlir::failed([[$TENSOR_INTEGER_FLOAT_CONSTRAINT]]
135 def OpN : NS_Op<"op_for_StringEscaping", []> {
137 StringBasedAttr<CPred<"::llvm::cast<StringAttr>($_self).getValue() == \"foo\"">,
138 "only value \"foo\" is allowed">:$s
142 // CHECK-LABEL: OpNAdaptor::verify
143 // CHECK: getValue() == "foo"
144 // CHECK-NEXT: only value \"foo\" is allowed