• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: mlir-tblgen -gen-op-defs -I %S/../../include %s | FileCheck %s
2
3include "mlir/IR/OpBase.td"
4
5def Test_Dialect : Dialect {
6  let name = "test";
7}
8class NS_Op<string mnemonic, list<OpTrait> traits> :
9    Op<Test_Dialect, mnemonic, traits>;
10
11def OpA : NS_Op<"one_normal_operand_op", []> {
12  let arguments = (ins I32:$input);
13}
14
15// CHECK-LABEL: OpA definitions
16
17// CHECK:      OpAAdaptor::OpAAdaptor
18// CHECK-SAME: odsOperands(values), odsAttrs(attrs)
19
20// CHECK:      void OpA::build
21// CHECK:        ::mlir::Value input
22// CHECK:        odsState.addOperands(input);
23
24// CHECK:      void OpA::build
25// CHECK:        ::mlir::ValueRange operands
26// CHECK:        assert(operands.size() == 1u && "mismatched number of parameters");
27// CHECK:        odsState.addOperands(operands);
28
29def OpB : NS_Op<"one_variadic_operand_op", []> {
30  let arguments = (ins Variadic<I32>:$input);
31}
32
33// CHECK-LABEL: OpB::build
34// CHECK:         ::mlir::ValueRange input
35// CHECK-NOT:     assert
36// CHECK:         odsState.addOperands(input);
37
38def OpD : NS_Op<"mix_variadic_and_normal_inputs_op", [SameVariadicOperandSize]> {
39  let arguments = (ins Variadic<AnyTensor>:$input1, AnyTensor:$input2, Variadic<AnyTensor>:$input3);
40}
41
42// CHECK-LABEL: ::mlir::ValueRange OpDAdaptor::input1
43// CHECK-NEXT:    return getODSOperands(0);
44
45// CHECK-LABEL: ::mlir::Value OpDAdaptor::input2
46// CHECK-NEXT:    return *getODSOperands(1).begin();
47
48// CHECK-LABEL: ::mlir::ValueRange OpDAdaptor::input3
49// CHECK-NEXT:    return getODSOperands(2);
50
51// CHECK-LABEL: ::mlir::Operation::operand_range OpD::input1
52// CHECK-NEXT: return getODSOperands(0);
53
54// CHECK-LABEL: ::mlir::Value OpD::input2
55// CHECK-NEXT: return *getODSOperands(1).begin();
56
57// CHECK-LABEL: OpD::build
58// CHECK-NEXT: odsState.addOperands(input1);
59// CHECK-NEXT: odsState.addOperands(input2);
60// CHECK-NEXT: odsState.addOperands(input3);
61