2019-03-21 08:25:34 +08:00
|
|
|
// RUN: mlir-tblgen -gen-op-defs -I %S/../../include %s | FileCheck %s
|
2019-02-28 00:40:07 +08:00
|
|
|
|
2019-03-02 05:48:24 +08:00
|
|
|
include "mlir/IR/OpBase.td"
|
2020-06-30 07:40:52 +08:00
|
|
|
include "mlir/Interfaces/InferTypeOpInterface.td"
|
2019-02-28 00:40:07 +08:00
|
|
|
|
2019-04-30 00:24:09 +08:00
|
|
|
def Test_Dialect : Dialect {
|
|
|
|
let name = "test";
|
|
|
|
}
|
|
|
|
class NS_Op<string mnemonic, list<OpTrait> traits> :
|
|
|
|
Op<Test_Dialect, mnemonic, traits>;
|
|
|
|
|
|
|
|
def OpA : NS_Op<"one_normal_result_op", []> {
|
2019-03-07 04:50:01 +08:00
|
|
|
let results = (outs I32:$result);
|
|
|
|
}
|
|
|
|
|
2019-04-26 05:45:37 +08:00
|
|
|
// CHECK-LABEL: void OpA::build
|
2020-09-23 11:58:30 +08:00
|
|
|
// CHECK: ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands
|
2019-04-04 00:29:25 +08:00
|
|
|
// CHECK: assert(resultTypes.size() == 1u && "mismatched number of return types");
|
2020-01-09 10:48:38 +08:00
|
|
|
// CHECK-NEXT: odsState.addTypes(resultTypes);
|
2019-04-04 00:29:25 +08:00
|
|
|
|
2019-05-28 12:18:19 +08:00
|
|
|
def OpB : NS_Op<"same_input_output_type_op", [SameOperandsAndResultType]> {
|
2019-02-28 00:40:07 +08:00
|
|
|
let arguments = (ins I32:$x);
|
|
|
|
let results = (outs I32:$y);
|
|
|
|
}
|
|
|
|
|
2019-04-26 05:45:37 +08:00
|
|
|
// CHECK-LABEL: OpB definitions
|
2020-06-26 19:20:44 +08:00
|
|
|
// CHECK: void OpB::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type y, ::mlir::Value x)
|
2020-01-09 10:48:38 +08:00
|
|
|
// CHECK: odsState.addTypes(y);
|
2020-06-26 19:20:44 +08:00
|
|
|
// CHECK: void OpB::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value x)
|
2020-01-09 10:48:38 +08:00
|
|
|
// CHECK: odsState.addTypes({x.getType()});
|
2019-02-28 00:40:07 +08:00
|
|
|
|
2019-04-30 00:24:09 +08:00
|
|
|
def OpC : NS_Op<"three_normal_result_op", []> {
|
2019-02-28 00:40:07 +08:00
|
|
|
let results = (outs I32:$x, /*unnamed*/I32, I32:$z);
|
|
|
|
}
|
|
|
|
|
2019-04-26 05:45:37 +08:00
|
|
|
// CHECK-LABEL: OpC definitions
|
2020-06-26 19:20:44 +08:00
|
|
|
// CHECK: void OpC::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type x, ::mlir::Type resultType1, ::mlir::Type z)
|
2020-01-09 10:48:38 +08:00
|
|
|
// CHECK-NEXT: odsState.addTypes(x)
|
|
|
|
// CHECK-NEXT: odsState.addTypes(resultType1)
|
|
|
|
// CHECK-NEXT: odsState.addTypes(z)
|
2019-02-28 00:40:07 +08:00
|
|
|
|
2020-09-23 11:58:30 +08:00
|
|
|
// CHECK: void OpC::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes) {
|
2020-03-27 05:57:01 +08:00
|
|
|
// CHECK-NEXT: assert(resultTypes.size() == 3u && "mismatched number of results");
|
|
|
|
// CHECK-NEXT: odsState.addTypes(resultTypes);
|
|
|
|
|
2019-03-27 06:31:15 +08:00
|
|
|
def IntegerTypeAttr : TypeAttrBase<"IntegerType", "Integer type attribute">;
|
2019-04-30 00:24:09 +08:00
|
|
|
def OpD : NS_Op<"type_attr_as_result_type", [FirstAttrDerivedResultType]> {
|
2019-03-27 06:31:15 +08:00
|
|
|
let arguments = (ins I32:$x, IntegerTypeAttr:$attr, F32Attr:$f32);
|
2019-05-18 10:45:45 +08:00
|
|
|
let results = (outs AnyTensor:$y);
|
2019-03-27 06:31:15 +08:00
|
|
|
}
|
|
|
|
|
2019-04-26 05:45:37 +08:00
|
|
|
// CHECK-LABEL: OpD definitions
|
2020-06-26 19:20:44 +08:00
|
|
|
// CHECK: void OpD::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes)
|
|
|
|
// CHECK: odsState.addTypes({attr.second.cast<::mlir::TypeAttr>().getValue()});
|
2019-03-27 06:31:15 +08:00
|
|
|
|
2019-04-30 00:24:09 +08:00
|
|
|
def OpE : NS_Op<"value_attr_as_result_type", [FirstAttrDerivedResultType]> {
|
2019-03-27 06:31:15 +08:00
|
|
|
let arguments = (ins I32:$x, F32Attr:$attr);
|
2019-05-18 10:45:45 +08:00
|
|
|
let results = (outs AnyTensor:$y);
|
2019-03-27 06:31:15 +08:00
|
|
|
}
|
|
|
|
|
2019-04-26 05:45:37 +08:00
|
|
|
// CHECK-LABEL: OpE definitions
|
2020-06-26 19:20:44 +08:00
|
|
|
// CHECK: void OpE::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes)
|
2020-01-09 10:48:38 +08:00
|
|
|
// CHECK: odsState.addTypes({attr.second.getType()});
|
2019-03-27 06:31:15 +08:00
|
|
|
|
2019-04-30 00:24:09 +08:00
|
|
|
def OpF : NS_Op<"one_variadic_result_op", []> {
|
2019-04-10 23:00:34 +08:00
|
|
|
let results = (outs Variadic<I32>:$x);
|
|
|
|
}
|
|
|
|
|
2019-04-26 05:45:37 +08:00
|
|
|
// CHECK-LABEL: void OpF::build
|
2020-09-23 11:58:30 +08:00
|
|
|
// CHECK-SAME: ::mlir::TypeRange x
|
2019-04-26 05:45:37 +08:00
|
|
|
// CHECK-NOT: assert
|
2020-01-09 10:48:38 +08:00
|
|
|
// CHECK: odsState.addTypes(x);
|
2019-04-10 23:00:34 +08:00
|
|
|
|
2019-04-30 00:24:09 +08:00
|
|
|
def OpG : NS_Op<"one_normal_and_one_variadic_result_op", []> {
|
2019-04-10 23:00:34 +08:00
|
|
|
|
2019-02-28 00:40:07 +08:00
|
|
|
let results = (outs I32:$x, Variadic<I32>:$y);
|
|
|
|
}
|
|
|
|
|
2019-04-26 05:45:37 +08:00
|
|
|
// CHECK-LABEL: OpG definitions
|
2019-04-04 00:29:25 +08:00
|
|
|
|
2020-09-23 11:58:30 +08:00
|
|
|
// CHECK: void OpG::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type x, ::mlir::TypeRange y)
|
2020-01-09 10:48:38 +08:00
|
|
|
// CHECK-NEXT: odsState.addTypes(x);
|
|
|
|
// CHECK-NEXT: odsState.addTypes(y);
|
2019-04-04 00:29:25 +08:00
|
|
|
|
2019-06-09 20:50:09 +08:00
|
|
|
// CHECK: void OpG::build
|
2020-09-23 11:58:30 +08:00
|
|
|
// CHECK: ::mlir::TypeRange resultTypes
|
2019-04-04 00:29:25 +08:00
|
|
|
// CHECK: assert(resultTypes.size() >= 1u && "mismatched number of return types");
|
2020-01-09 10:48:38 +08:00
|
|
|
// CHECK-NEXT: odsState.addTypes(resultTypes);
|
2019-04-26 05:45:37 +08:00
|
|
|
|
2019-06-09 20:50:09 +08:00
|
|
|
def OpI : NS_Op<"mix_variadic_and_normal_results_op", [SameVariadicResultSize]> {
|
|
|
|
let results = (outs Variadic<AnyTensor>:$output1, AnyTensor:$output2, Variadic<AnyTensor>:$output3);
|
2019-04-26 05:45:37 +08:00
|
|
|
}
|
|
|
|
|
2020-06-26 19:20:44 +08:00
|
|
|
// CHECK-LABEL: ::mlir::Operation::result_range OpI::output1
|
2019-06-09 20:50:09 +08:00
|
|
|
// CHECK-NEXT: return getODSResults(0);
|
2019-04-26 05:45:37 +08:00
|
|
|
|
2020-06-26 19:20:44 +08:00
|
|
|
// CHECK-LABEL: ::mlir::Value OpI::output2
|
2019-06-09 20:50:09 +08:00
|
|
|
// CHECK-NEXT: return *getODSResults(1).begin();
|
2019-04-26 05:45:37 +08:00
|
|
|
|
|
|
|
// CHECK-LABEL: OpI::build
|
2020-01-09 10:48:38 +08:00
|
|
|
// CHECK-NEXT: odsState.addTypes(output1);
|
|
|
|
// CHECK-NEXT: odsState.addTypes(output2);
|
|
|
|
// CHECK-NEXT: odsState.addTypes(output3);
|
2019-04-26 05:45:37 +08:00
|
|
|
|
2019-10-21 00:44:06 +08:00
|
|
|
// Test that if the only operand is variadic, we access the first value in the
|
2019-04-26 05:45:37 +08:00
|
|
|
// pack to set result type
|
|
|
|
// ---
|
2019-05-28 12:18:19 +08:00
|
|
|
def OpK : NS_Op<"only_input_is_variadic_with_same_value_type_op", [SameOperandsAndResultType]> {
|
2019-05-18 10:45:45 +08:00
|
|
|
let arguments = (ins Variadic<AnyTensor>:$input);
|
|
|
|
let results = (outs AnyTensor:$result);
|
2019-04-26 05:45:37 +08:00
|
|
|
}
|
|
|
|
|
2020-09-18 04:18:09 +08:00
|
|
|
// CHECK-LABEL: OpK::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes)
|
2020-08-08 05:02:19 +08:00
|
|
|
// CHECK: odsState.addTypes({operands[0].getType()});
|
2020-06-30 07:40:52 +08:00
|
|
|
|
|
|
|
// Test with inferred shapes and interleaved with operands/attributes.
|
|
|
|
//
|
|
|
|
def OpL : NS_Op<"op_with_all_types_constraint",
|
|
|
|
[AllTypesMatch<["a", "b"]>]> {
|
|
|
|
let arguments = (ins I32Attr:$attr1, AnyType:$a);
|
|
|
|
let results = (outs Res<AnyType, "output b", []>:$b);
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: LogicalResult OpL::inferReturnTypes
|
|
|
|
// CHECK-NOT: }
|
|
|
|
// CHECK: inferredReturnTypes[0] = operands[0].getType();
|