brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.2 KiB · 1ac2311 Raw
222 lines · plain
1// RUN: mlir-tblgen -gen-op-decls -I %S/../../include %s -o=%t2 3// This file contains tests for the specification of the declarative op format.4 5include "mlir/IR/OpBase.td"6include "mlir/Interfaces/InferTypeOpInterface.td"7 8def TestDialect : Dialect {9  let name = "test";10}11class TestFormat_Op<string fmt, list<Trait> traits = []>12    : Op<TestDialect, "format_op", traits> {13  let assemblyFormat = fmt;14}15 16//===----------------------------------------------------------------------===//17// Directives18//===----------------------------------------------------------------------===//19 20//===----------------------------------------------------------------------===//21// attr-dict22//===----------------------------------------------------------------------===//23 24// CHECK-NOT: error25def DirectiveAttrDictValidA : TestFormat_Op<[{26  attr-dict27}]>;28def DirectiveAttrDictValidB : TestFormat_Op<[{29  attr-dict-with-keyword30}]>;31 32//===----------------------------------------------------------------------===//33// custom34//===----------------------------------------------------------------------===//35 36// CHECK-NOT: error37def DirectiveCustomValidA : TestFormat_Op<[{38  custom<MyDirective>($operand) attr-dict39}]>, Arguments<(ins Optional<I64>:$operand)>;40def DirectiveCustomValidB : TestFormat_Op<[{41  custom<MyDirective>($operand, type($operand), type($result)) attr-dict42}]>, Arguments<(ins I64:$operand)>, Results<(outs I64:$result)>;43def DirectiveCustomValidC : TestFormat_Op<[{44  custom<MyDirective>($attr) attr-dict45}]>, Arguments<(ins I64Attr:$attr)>;46def DirectiveCustomValidD : TestFormat_Op<[{47  (`(` custom<MyDirective>($operand)^ `)`)? attr-dict48}]>, Arguments<(ins Optional<I64>:$operand)>;49def DirectiveCustomValidE : TestFormat_Op<[{50  custom<MyDirective>(prop-dict) attr-dict51}]>, Arguments<(ins UnitAttr:$flag)>;52def DirectiveCustomValidF : TestFormat_Op<[{53  $operand custom<MyDirective>(ref($operand)) attr-dict54}]>, Arguments<(ins Optional<I64>:$operand)>;55def DirectiveCustomValidG : TestFormat_Op<[{56  $body custom<MyDirective>(ref($body)) attr-dict57}]> {58  let regions = (region AnyRegion:$body);59}60def DirectiveCustomValidH : TestFormat_Op<[{61  $successor custom<MyDirective>(ref($successor)) attr-dict62}]> {63  let successors = (successor AnySuccessor:$successor);64}65 66//===----------------------------------------------------------------------===//67// functional-type68//===----------------------------------------------------------------------===//69 70// CHECK-NOT: error71def DirectiveFunctionalTypeValid : TestFormat_Op<[{72  functional-type(operands, results) attr-dict73}]>;74 75//===----------------------------------------------------------------------===//76// operands77//===----------------------------------------------------------------------===//78 79// CHECK-NOT: error:80def DirectiveOperandsValid : TestFormat_Op<[{81  operands attr-dict82}]>;83 84//===----------------------------------------------------------------------===//85// regions86//===----------------------------------------------------------------------===//87 88// CHECK-NOT: error:89def DirectiveRegionsValid : TestFormat_Op<[{90  regions attr-dict91}]>;92 93//===----------------------------------------------------------------------===//94// results95//===----------------------------------------------------------------------===//96 97// CHECK-NOT: error:98def DirectiveResultsValid : TestFormat_Op<[{99  type(results) attr-dict100}]>;101 102//===----------------------------------------------------------------------===//103// successors104//===----------------------------------------------------------------------===//105 106// CHECK-NOT: error:107def DirectiveSuccessorsValid : TestFormat_Op<[{108  successors attr-dict109}]>;110 111//===----------------------------------------------------------------------===//112// type113//===----------------------------------------------------------------------===//114 115// CHECK-NOT: error:116def DirectiveTypeValid : TestFormat_Op<[{117  type(operands) attr-dict118}]>;119 120//===----------------------------------------------------------------------===//121// Literals122//===----------------------------------------------------------------------===//123 124// CHECK-NOT: error125def LiteralValid : TestFormat_Op<[{126  `_` `:` `,` `=` `<` `>` `(` `)` `[` `]` `?` `+` `-` `*` ` ` `` `->` `\n` `abc$._`127  attr-dict128}]>;129 130//===----------------------------------------------------------------------===//131// OIList Element132//===----------------------------------------------------------------------===//133 134// CHECK-NOT: error135def OIListTrivial : TestFormat_Op<[{136  oilist(`keyword` `(` `)` | `otherkeyword` `(` `)`) attr-dict137}]>;138def OIListSimple : TestFormat_Op<[{139  oilist( `keyword` $arg0 `:` type($arg0)140        | `otherkeyword` $arg1 `:` type($arg1)141        | `thirdkeyword` $arg2 `:` type($arg2) )142  attr-dict143}], [AttrSizedOperandSegments]>, Arguments<(ins Optional<AnyType>:$arg0, Optional<AnyType>:$arg1, Optional<AnyType>:$arg2)>;144def OIListVariadic : TestFormat_Op<[{145  oilist( `keyword` `(` $args0 `:` type($args0) `)`146        | `otherkeyword` `(` $args1 `:` type($args1) `)`147        | `thirdkeyword` `(` $args2 `:` type($args2) `)`)148  attr-dict149}], [AttrSizedOperandSegments]>, Arguments<(ins Variadic<AnyType>:$args0, Variadic<AnyType>:$args1, Variadic<AnyType>:$args2)>;150def OIListCustom : TestFormat_Op<[{151  oilist( `private` `(` $arg0 `:` type($arg0) `)`152        | `nowait`153        | `reduction` custom<ReductionClause>($arg1, type($arg1))) attr-dict154}], [AttrSizedOperandSegments]>, Arguments<(ins Optional<AnyType>:$arg0, Optional<AnyType>:$arg1)>;155 156//===----------------------------------------------------------------------===//157// Optional Groups158//===----------------------------------------------------------------------===//159 160// CHECK-NOT: error161def OptionalValidA : TestFormat_Op<[{162  (` ` `` $arg^)? attr-dict163}]>, Arguments<(ins Optional<I32>:$arg)>;164 165//===----------------------------------------------------------------------===//166// Strings167//===----------------------------------------------------------------------===//168 169// CHECK-NOT: error170def StringValid : TestFormat_Op<[{ custom<Foo>("foo") attr-dict }]>;171 172//===----------------------------------------------------------------------===//173// Variables174//===----------------------------------------------------------------------===//175 176// CHECK-NOT: error:177def VariableValidA : TestFormat_Op<[{178  $attr `:` attr-dict179}]>, Arguments<(ins OptionalAttr<I1Attr>:$attr)>;180def VariableValidB : TestFormat_Op<[{181  (`foo` $attr^)? `:` attr-dict182}]>, Arguments<(ins OptionalAttr<I1Attr>:$attr)>;183 184//===----------------------------------------------------------------------===//185// Coverage Checks186//===----------------------------------------------------------------------===//187 188// CHECK-NOT: error189def ZCoverageValidA : TestFormat_Op<[{190  $operand type($operand) type($result) attr-dict191}]>, Arguments<(ins AnyMemRef:$operand)>, Results<(outs AnyMemRef:$result)>;192def ZCoverageValidB : TestFormat_Op<[{193  $operand type(operands) type(results) attr-dict194}]>, Arguments<(ins AnyMemRef:$operand)>, Results<(outs AnyMemRef:$result)>;195def ZCoverageValidC : TestFormat_Op<[{196  operands functional-type(operands, results) attr-dict197}]>, Arguments<(ins AnyMemRef:$operand)>, Results<(outs AnyMemRef:$result)>;198 199// Check that we can infer type equalities from certain traits.200def ZCoverageValidD : TestFormat_Op<[{201  operands type($result) attr-dict202}], [SameOperandsAndResultType]>, Arguments<(ins AnyMemRef)>,203     Results<(outs AnyMemRef:$result)>;204def ZCoverageValidE : TestFormat_Op<[{205  $operand type($operand) attr-dict206}], [SameOperandsAndResultType]>, Arguments<(ins AnyMemRef:$operand)>,207     Results<(outs AnyMemRef)>;208def ZCoverageValidF : TestFormat_Op<[{209  operands type($other) attr-dict210}], [SameTypeOperands]>, Arguments<(ins AnyMemRef:$operand, AnyMemRef:$other)>;211def ZCoverageValidG : TestFormat_Op<[{212  operands type($other) attr-dict213}], [AllTypesMatch<["operand", "other"]>]>,214     Arguments<(ins AnyMemRef:$operand, AnyMemRef:$other)>;215def ZCoverageValidH : TestFormat_Op<[{216  operands type($result) attr-dict217}], [AllTypesMatch<["operand", "result"]>]>,218     Arguments<(ins AnyMemRef:$operand)>, Results<(outs AnyMemRef:$result)>;219def ZCoverageValidI : TestFormat_Op<[{220  operands type(operands) attr-dict221}], [InferTypeOpInterface]>, Arguments<(ins Variadic<I64>:$inputs)>, Results<(outs I64:$result)>;222