xref: /llvm-project/mlir/test/mlir-tblgen/interfaces-as-constraints.td (revision db791b278a414fb6df1acc1799adcf11d8fb9169)
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}
8
9def TopLevelTypeInterface : TypeInterface<"TopLevelTypeInterface">;
10
11def TypeInterfaceInNamespace : TypeInterface<"TypeInterfaceInNamespace"> {
12	let cppNamespace = "test";
13}
14
15def TopLevelAttrInterface : AttrInterface<"TopLevelAttrInterface">;
16
17def AttrInterfaceInNamespace : AttrInterface<"AttrInterfaceInNamespace"> {
18	let cppNamespace = "test";
19}
20
21def OpUsingAllOfThose : Op<Test_Dialect, "OpUsingAllOfThose"> {
22	let arguments = (ins TopLevelAttrInterface:$attr1, AttrInterfaceInNamespace:$attr2);
23	let results = (outs TopLevelTypeInterface:$res1, TypeInterfaceInNamespace:$res2);
24}
25
26// CHECK: static ::llvm::LogicalResult {{__mlir_ods_local_type_constraint.*}}(
27// CHECK:   if (!((::llvm::isa<TopLevelTypeInterface>(type)))) {
28// CHECK-NEXT:    return op->emitOpError(valueKind) << " #" << valueIndex
29// CHECK-NEXT:        << " must be TopLevelTypeInterface instance, but got " << type;
30
31// CHECK: static ::llvm::LogicalResult {{__mlir_ods_local_type_constraint.*}}(
32// CHECK:   if (!((::llvm::isa<test::TypeInterfaceInNamespace>(type)))) {
33// CHECK-NEXT:    return op->emitOpError(valueKind) << " #" << valueIndex
34// CHECK-NEXT:        << " must be TypeInterfaceInNamespace instance, but got " << type;
35
36// CHECK: static ::llvm::LogicalResult {{__mlir_ods_local_attr_constraint.*}}(
37// CHECK:   if (attr && !((::llvm::isa<TopLevelAttrInterface>(attr))))
38// CHECK-NEXT:     return emitError() << "attribute '" << attrName
39// CHECK-NEXT:        << "' failed to satisfy constraint: TopLevelAttrInterface instance";
40
41// CHECK: static ::llvm::LogicalResult {{__mlir_ods_local_attr_constraint.*}}(
42// CHECK:   if (attr && !((::llvm::isa<test::AttrInterfaceInNamespace>(attr))))
43// CHECK-NEXT:    return emitError() << "attribute '" << attrName
44// CHECK-NEXT:        << "' failed to satisfy constraint: AttrInterfaceInNamespace instance";
45
46// CHECK: TopLevelAttrInterface OpUsingAllOfThose::getAttr1()
47// CHECK: test::AttrInterfaceInNamespace OpUsingAllOfThose::getAttr2()
48