File: op-interface.td

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (194 lines) | stat: -rw-r--r-- 7,251 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// RUN: mlir-tblgen -gen-op-interface-decls -I %S/../../include %s | FileCheck %s --check-prefix=DECL
// RUN: mlir-tblgen -gen-op-interface-defs -I %S/../../include %s | FileCheck %s --check-prefix=DEF
// RUN: mlir-tblgen -gen-op-decls -I %S/../../include %s | FileCheck %s --check-prefix=OP_DECL
// RUN: mlir-tblgen -gen-op-interface-docs -I %S/../../include %s | FileCheck %s --check-prefix=DOCS

include "mlir/IR/OpBase.td"

def ExtraClassOfInterface : OpInterface<"ExtraClassOfInterface"> {
  let extraClassOf = "return $_op->someOtherMethod();";
}

// DECL: class ExtraClassOfInterface
// DECL:   static bool classof(::mlir::Operation * base) {
// DECL-NEXT:     if (!getInterfaceFor(base))
// DECL-NEXT:       return false;
// DECL-NEXT:     return base->someOtherMethod();
// DECL-NEXT:   }

def ExtraShardDeclsInterface : OpInterface<"ExtraShardDeclsInterface"> {
  let extraSharedClassDeclaration = [{
    bool sharedMethodDeclaration() {
      return $_op.someOtherMethod();
    }
  }];
}

// DECL: class ExtraShardDeclsInterface
// DECL:      bool sharedMethodDeclaration() {
// DECL-NEXT:   return (*this).someOtherMethod();
// DECL-NEXT: }

// DECL: struct ExtraShardDeclsInterfaceTrait
// DECL:      bool sharedMethodDeclaration() {
// DECL-NEXT:   return (*static_cast<ConcreteOp *>(this)).someOtherMethod();
// DECL-NEXT: }

def TestInheritanceBaseInterface : OpInterface<"TestInheritanceBaseInterface"> {
  let methods = [
    InterfaceMethod<
      /*desc=*/[{some function comment}],
      /*retTy=*/"int",
      /*methodName=*/"foo",
      /*args=*/(ins "int":$input)
    >
  ];
}
def TestInheritanceMiddleBaseInterface
 : OpInterface<"TestInheritanceMiddleBaseInterface", [TestInheritanceBaseInterface]> {
  let methods = [
    InterfaceMethod<
      /*desc=*/[{some function comment}],
      /*retTy=*/"int",
      /*methodName=*/"bar",
      /*args=*/(ins "int":$input)
    >
  ];
}
def TestInheritanceZDerivedInterface
  : OpInterface<"TestInheritanceZDerivedInterface", [TestInheritanceMiddleBaseInterface]>;

// DECL: class TestInheritanceZDerivedInterface
// DECL: struct Concept {
// DECL:     const TestInheritanceBaseInterface::Concept *implTestInheritanceBaseInterface = nullptr;
// DECL:     const TestInheritanceMiddleBaseInterface::Concept *implTestInheritanceMiddleBaseInterface = nullptr;

// DECL:     void initializeInterfaceConcept(::mlir::detail::InterfaceMap &interfaceMap) {
// DECL:       implTestInheritanceBaseInterface = interfaceMap.lookup<TestInheritanceBaseInterface>();
// DECL:       assert(implTestInheritanceBaseInterface && "`TestInheritanceZDerivedInterface` expected its base interface `TestInheritanceBaseInterface` to be registered");
// DECL:       implTestInheritanceMiddleBaseInterface = interfaceMap.lookup<TestInheritanceMiddleBaseInterface>();
// DECL:       assert(implTestInheritanceMiddleBaseInterface
// DECL:     }

// DECL:    //===----------------------------------------------------------------===//
// DECL:    // Inherited from TestInheritanceBaseInterface
// DECL:    //===----------------------------------------------------------------===//
// DECL:    operator TestInheritanceBaseInterface () const {
// DECL:      return TestInheritanceBaseInterface(*this, getImpl()->implTestInheritanceBaseInterface);
// DECL:    }
// DECL:    /// some function comment
// DECL:    int foo(int input);

// DECL:    //===----------------------------------------------------------------===//
// DECL:    // Inherited from TestInheritanceMiddleBaseInterface
// DECL:    //===----------------------------------------------------------------===//
// DECL:    operator TestInheritanceMiddleBaseInterface () const {
// DECL:      return TestInheritanceMiddleBaseInterface(*this, getImpl()->implTestInheritanceMiddleBaseInterface);
// DECL:    }
// DECL:    /// some function comment
// DECL:    int bar(int input);

// DEF: int TestInheritanceZDerivedInterface::foo(int input) {
// DEF-NEXT:    getImpl()->implTestInheritanceBaseInterface->foo(getImpl()->implTestInheritanceBaseInterface, getOperation(), input);

// DEF: int TestInheritanceZDerivedInterface::bar(int input) {
// DEF-NEXT:   return getImpl()->implTestInheritanceMiddleBaseInterface->bar(getImpl()->implTestInheritanceMiddleBaseInterface, getOperation(), input);

def TestOpInterface : OpInterface<"TestOpInterface"> {
  let description = [{some op interface description}];

  let methods = [
    InterfaceMethod<
      /*desc=*/[{some function comment}],
      /*retTy=*/"int",
      /*methodName=*/"foo",
      /*args=*/(ins "int":$input)
    >,
    InterfaceMethod<
      /*desc=*/[{some function comment}],
      /*retTy=*/"int",
      /*methodName=*/"body_foo",
      /*args=*/(ins "int":$input),
      /*body=*/[{ return 0; }]
    >,
    InterfaceMethod<
      /*desc=*/[{some function comment}],
      /*retTy=*/"int",
      /*methodName=*/"default_foo",
      /*args=*/(ins "int":$input),
      /*body=*/[{}],
      /*defaultBody=*/[{ return 0; }]
    >,
  ];
}

def TestOpInterfaceVerify : OpInterface<"TestOpInterfaceVerify"> {
  let verify = [{
    return foo();
  }];
}

def TestOpInterfaceVerifyRegion : OpInterface<"TestOpInterfaceVerifyRegion"> {
  let verify = [{
    return foo();
  }];
  let verifyWithRegions = 1;
}

// Define Ops with TestOpInterface and
// DeclareOpInterfaceMethods<TestOpInterface> traits to check that there
// are not duplicated C++ classes generated.
def TestDialect : Dialect {
  let name = "test";
}

def OpInterfaceOp : Op<TestDialect, "op_interface_op", [TestOpInterface]>;

def OpInterfaceInterfacesOp : Op<TestDialect, "op_inherit_interface_op", [TestInheritanceZDerivedInterface]>;

def DeclareMethodsOp : Op<TestDialect, "declare_methods_op",
                          [DeclareOpInterfaceMethods<TestOpInterface>]>;

def DeclareMethodsWithDefaultOp : Op<TestDialect, "declare_methods_op",
      [DeclareOpInterfaceMethods<TestOpInterface, ["default_foo"]>]>;

// DECL-LABEL: TestOpInterfaceInterfaceTraits
// DECL: class TestOpInterface : public ::mlir::OpInterface<TestOpInterface, detail::TestOpInterfaceInterfaceTraits>

// DECL: /// some function comment
// DECL: int foo(int input);

// DECL-LABEL: struct TestOpInterfaceVerifyTrait
// DECL: verifyTrait

// DECL-LABEL: struct TestOpInterfaceVerifyRegionTrait
// DECL: verifyRegionTrait

// Method implementations come last, after all class definitions.
// DECL: template<typename ConcreteOp>
// DECL: int detail::TestOpInterfaceInterfaceTraits::Model<ConcreteOp>::foo

// OP_DECL-LABEL: class DeclareMethodsOp : public
// OP_DECL: int foo(int input);
// OP_DECL-NOT: int default_foo(int input);

// OP_DECL-LABEL: class DeclareMethodsWithDefaultOp : public
// OP_DECL: int foo(int input);
// OP_DECL: int default_foo(int input);

// OP_DECL: class OpInterfaceInterfacesOp :
// OP_DECL-SAME: TestInheritanceBaseInterface::Trait, TestInheritanceMiddleBaseInterface::Trait, TestInheritanceZDerivedInterface::Trait

// DOCS-LABEL: {{^}}## TestOpInterface (`TestOpInterface`)
// DOCS: some op interface description

// DOCS: {{^}}### Methods:

// DOCS: {{^}}#### `foo`
// DOCS: some function comment

// DOCS: {{^}}#### `body_foo`
// DOCS: some function comment

// DOCS: {{^}}#### `default_foo`
// DOCS: some function comment