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-decls -I %S/../../include %s -o=%t
// This file contains tests for the specification of the declarative op format.
include "mlir/IR/OpBase.td"
include "mlir/Interfaces/InferTypeOpInterface.td"
def TestDialect : Dialect {
let name = "test";
}
class TestFormat_Op<string fmt, list<Trait> traits = []>
: Op<TestDialect, "format_op", traits> {
let assemblyFormat = fmt;
}
//===----------------------------------------------------------------------===//
// Directives
//===----------------------------------------------------------------------===//
//===----------------------------------------------------------------------===//
// attr-dict
// CHECK-NOT: error
def DirectiveAttrDictValidA : TestFormat_Op<[{
attr-dict
}]>;
def DirectiveAttrDictValidB : TestFormat_Op<[{
attr-dict-with-keyword
}]>;
//===----------------------------------------------------------------------===//
// custom
// CHECK-NOT: error
def DirectiveCustomValidA : TestFormat_Op<[{
custom<MyDirective>($operand) attr-dict
}]>, Arguments<(ins Optional<I64>:$operand)>;
def DirectiveCustomValidB : TestFormat_Op<[{
custom<MyDirective>($operand, type($operand), type($result)) attr-dict
}]>, Arguments<(ins I64:$operand)>, Results<(outs I64:$result)>;
def DirectiveCustomValidC : TestFormat_Op<[{
custom<MyDirective>($attr) attr-dict
}]>, Arguments<(ins I64Attr:$attr)>;
//===----------------------------------------------------------------------===//
// functional-type
// CHECK-NOT: error
def DirectiveFunctionalTypeValid : TestFormat_Op<[{
functional-type(operands, results) attr-dict
}]>;
//===----------------------------------------------------------------------===//
// operands
// CHECK-NOT: error:
def DirectiveOperandsValid : TestFormat_Op<[{
operands attr-dict
}]>;
//===----------------------------------------------------------------------===//
// regions
// CHECK-NOT: error:
def DirectiveRegionsValid : TestFormat_Op<[{
regions attr-dict
}]>;
//===----------------------------------------------------------------------===//
// results
// CHECK-NOT: error:
def DirectiveResultsInvalidA : TestFormat_Op<[{
type(results) attr-dict
}]>;
//===----------------------------------------------------------------------===//
// successors
// CHECK-NOT: error:
def DirectiveSuccessorsInvalidA : TestFormat_Op<[{
successors attr-dict
}]>;
//===----------------------------------------------------------------------===//
// type
// CHECK-NOT: error:
def DirectiveTypeValid : TestFormat_Op<[{
type(operands) attr-dict
}]>;
//===----------------------------------------------------------------------===//
// Literals
//===----------------------------------------------------------------------===//
// CHECK-NOT: error
def LiteralValid : TestFormat_Op<[{
`_` `:` `,` `=` `<` `>` `(` `)` `[` `]` `?` `+` `*` ` ` `` `->` `\n` `abc$._`
attr-dict
}]>;
//===----------------------------------------------------------------------===//
// OIList Element
//===----------------------------------------------------------------------===//
// CHECK-NOT: error
def OIListTrivial : TestFormat_Op<[{
oilist(`keyword` `(` `)` | `otherkeyword` `(` `)`) attr-dict
}]>;
def OIListSimple : TestFormat_Op<[{
oilist( `keyword` $arg0 `:` type($arg0)
| `otherkeyword` $arg1 `:` type($arg1)
| `thirdkeyword` $arg2 `:` type($arg2) )
attr-dict
}], [AttrSizedOperandSegments]>, Arguments<(ins Optional<AnyType>:$arg0, Optional<AnyType>:$arg1, Optional<AnyType>:$arg2)>;
def OIListVariadic : TestFormat_Op<[{
oilist( `keyword` `(` $args0 `:` type($args0) `)`
| `otherkeyword` `(` $args1 `:` type($args1) `)`
| `thirdkeyword` `(` $args2 `:` type($args2) `)`)
attr-dict
}], [AttrSizedOperandSegments]>, Arguments<(ins Variadic<AnyType>:$args0, Variadic<AnyType>:$args1, Variadic<AnyType>:$args2)>;
def OIListCustom : TestFormat_Op<[{
oilist( `private` `(` $arg0 `:` type($arg0) `)`
| `nowait`
| `reduction` custom<ReductionClause>($arg1, type($arg1))) attr-dict
}], [AttrSizedOperandSegments]>, Arguments<(ins Optional<AnyType>:$arg0, Optional<AnyType>:$arg1)>;
//===----------------------------------------------------------------------===//
// Optional Groups
//===----------------------------------------------------------------------===//
// CHECK-NOT: error
def OptionalValidA : TestFormat_Op<[{
(` ` `` $arg^)? attr-dict
}]>, Arguments<(ins Optional<I32>:$arg)>;
//===----------------------------------------------------------------------===//
// Strings
//===----------------------------------------------------------------------===//
// CHECK-NOT: error
def StringInvalidA : TestFormat_Op<[{ custom<Foo>("foo") attr-dict }]>;
//===----------------------------------------------------------------------===//
// Variables
//===----------------------------------------------------------------------===//
// CHECK-NOT: error:
def VariableValidA : TestFormat_Op<[{
$attr `:` attr-dict
}]>, Arguments<(ins OptionalAttr<I1Attr>:$attr)>;
def VariableValidB : TestFormat_Op<[{
(`foo` $attr^)? `:` attr-dict
}]>, Arguments<(ins OptionalAttr<I1Attr>:$attr)>;
//===----------------------------------------------------------------------===//
// Coverage Checks
//===----------------------------------------------------------------------===//
// CHECK-NOT: error
def ZCoverageValidA : TestFormat_Op<[{
$operand type($operand) type($result) attr-dict
}]>, Arguments<(ins AnyMemRef:$operand)>, Results<(outs AnyMemRef:$result)>;
def ZCoverageValidB : TestFormat_Op<[{
$operand type(operands) type(results) attr-dict
}]>, Arguments<(ins AnyMemRef:$operand)>, Results<(outs AnyMemRef:$result)>;
def ZCoverageValidC : TestFormat_Op<[{
operands functional-type(operands, results) attr-dict
}]>, Arguments<(ins AnyMemRef:$operand)>, Results<(outs AnyMemRef:$result)>;
// Check that we can infer type equalities from certain traits.
def ZCoverageValidD : TestFormat_Op<[{
operands type($result) attr-dict
}], [SameOperandsAndResultType]>, Arguments<(ins AnyMemRef)>,
Results<(outs AnyMemRef:$result)>;
def ZCoverageValidE : TestFormat_Op<[{
$operand type($operand) attr-dict
}], [SameOperandsAndResultType]>, Arguments<(ins AnyMemRef:$operand)>,
Results<(outs AnyMemRef)>;
def ZCoverageValidF : TestFormat_Op<[{
operands type($other) attr-dict
}], [SameTypeOperands]>, Arguments<(ins AnyMemRef:$operand, AnyMemRef:$other)>;
def ZCoverageValidG : TestFormat_Op<[{
operands type($other) attr-dict
}], [AllTypesMatch<["operand", "other"]>]>,
Arguments<(ins AnyMemRef:$operand, AnyMemRef:$other)>;
def ZCoverageValidH : TestFormat_Op<[{
operands type($result) attr-dict
}], [AllTypesMatch<["operand", "result"]>]>,
Arguments<(ins AnyMemRef:$operand)>, Results<(outs AnyMemRef:$result)>;
def ZCoverageValidI : TestFormat_Op<[{
operands type(operands) attr-dict
}], [InferTypeOpInterface]>, Arguments<(ins Variadic<I64>:$inputs)>, Results<(outs I64:$result)>;
|