xref: /llvm-project/mlir/test/mlir-tblgen/rewriter-errors.td (revision 471a6128901747130ae11ce87b6e0095f862ed9a)
1// RUN: not mlir-tblgen -gen-rewriters -I %S/../../include -DERROR1 %s 2>&1 | FileCheck --check-prefix=ERROR1 %s
2// RUN: not mlir-tblgen -gen-rewriters -I %S/../../include -DERROR2 %s 2>&1 | FileCheck --check-prefix=ERROR2 %s
3// RUN: not mlir-tblgen -gen-rewriters -I %S/../../include -DERROR3 %s 2>&1 | FileCheck --check-prefix=ERROR3 %s
4// RUN: not mlir-tblgen -gen-rewriters -I %S/../../include -DERROR4 %s 2>&1 | FileCheck --check-prefix=ERROR4 %s
5// RUN: not mlir-tblgen -gen-rewriters -I %S/../../include -DERROR5 %s 2>&1 | FileCheck --check-prefix=ERROR5 %s
6// RUN: not mlir-tblgen -gen-rewriters -I %S/../../include -DERROR6 %s 2>&1 | FileCheck --check-prefix=ERROR6 %s
7// RUN: not mlir-tblgen -gen-rewriters -I %S/../../include -DERROR7 %s 2>&1 | FileCheck --check-prefix=ERROR7 %s
8// RUN: not mlir-tblgen -gen-rewriters -I %S/../../include -DERROR8 %s 2>&1 | FileCheck --check-prefix=ERROR8 %s
9
10include "mlir/IR/OpBase.td"
11include "mlir/IR/PatternBase.td"
12
13// Check using the dialect name as the namespace
14def A_Dialect : Dialect {
15  let name = "a";
16}
17
18class A_Op<string mnemonic, list<Trait> traits = []> :
19    Op<A_Dialect, mnemonic, traits>;
20
21def OpA : A_Op<"op_a">, Arguments<(ins AnyInteger, AnyInteger)>, Results<(outs AnyInteger)>;
22def OpB : A_Op<"op_b">, Arguments<(ins AnyInteger, AnyAttr:$value)>, Results<(outs AnyInteger)>;
23
24#ifdef ERROR1
25def NativeMatcher : NativeCodeCall<"success(nativeCall($0, $1))">;
26// ERROR1: [[@LINE+1]]:1: error: NativeCodeCall must have $_self as argument for passing the defining Operation
27def : Pat<(OpA (NativeMatcher $val), AnyI32Attr:$arg),
28          (OpB $val, $arg)>;
29#endif
30
31#ifdef ERROR2
32def NativeMatcher : NativeCodeCall<"success(nativeCall($_self, &$0))">;
33// ERROR2: [[@LINE+1]]:1: error: binding symbol 'error' to NativecodeCall in MatchPattern is not supported
34def : Pat<(OpA (NativeMatcher:$error $val), AnyI32Attr:$arg),
35          (OpB $val, $arg)>;
36#endif
37
38#ifdef ERROR3
39def NativeMatcher : NativeCodeCall<"success(nativeCall($_self, $0, $1))">;
40// ERROR3: [[@LINE+1]]:1: error: Matching nested tree in NativeCodecall not support for
41def : Pat<(OpA (NativeMatcher (OpB $val, $unused)), AnyI32Attr:$arg),
42          (OpB $val, $arg)>;
43#endif
44
45#ifdef ERROR4
46// Check trying to pass op as DAG node inside ReturnTypeFunc fails.
47// ERROR4: [[@LINE+1]]:1: error: nested DAG in `returnType` must be a native code
48def : Pat<(OpB $val, AnyI32Attr:$attr), (OpA (OpA $val, $val, (returnType (OpA $val, $val))), $val)>;
49#endif
50
51#ifdef ERROR5
52// Check that trying to specify explicit types at the root node fails.
53// ERROR5: [[@LINE+1]]:1: error: Cannot specify explicit return types in an op
54def : Pat<(OpB $val, AnyI32Attr:$attr), (OpA $val, $val, (returnType "someType()"))>;
55#endif
56
57#ifdef ERROR6
58// Check that type constraint has one argument
59// ERROR6: [[@LINE+1]]:1: error: type constraint requires exactly one argument
60def : Pat<(OpB:$result $val, $attr), (OpA $val, $val), [(AnyInteger:$result)]>;
61#endif
62
63#ifdef ERROR7
64// Check that type constraint has one argument
65// ERROR7: [[@LINE+1]]:1: error: type constraint requires exactly one argument
66def : Pat<(OpB:$opB $val, $attr), (OpA $val, $val), [(AnyInteger $opB, $val)]>;
67#endif
68
69def OpC : A_Op<"op_c">, Results<(outs AnyInteger)>;
70def OpD : A_Op<"op_d">, Arguments<(ins Variadic<AnyInteger>:$vargs)>, Results<(outs AnyInteger)>;
71
72#ifdef ERROR8
73// Check that op with variadic operand gets variadic operand in target,
74//
75// FIXME: this should be an error.
76def : Pat<(OpB:$opB $val, $attr), (OpD $val)>;
77
78// ERROR8: [[@LINE+2]]
79// ERROR8-SAME: op expects variadic operand `vargs`, while provided is non-variadic
80def : Pat<(OpB:$opB $val, $attr), (OpD (OpC))>;
81#endif
82