[NFC] Add unit tests for printing/parsing of variadic operands and results.

Differential Revision: https://reviews.llvm.org/D91557
This commit is contained in:
Rahul Joshi 2020-11-16 17:37:19 -08:00
parent f791ad7e1e
commit 8a4fe75d70
2 changed files with 40 additions and 0 deletions

View File

@ -1478,6 +1478,19 @@ def FormatResultCOp : FormatResultBase<"c", [{
functional-type($buildable_res, $result) attr-dict
}]>;
def FormatVariadicResult : TEST_Op<"format_variadic_result"> {
let results = (outs Variadic<I64>:$result);
let assemblyFormat = [{ `:` type($result) attr-dict}];
}
def FormatMultipleVariadicResults : TEST_Op<"format_multiple_variadic_results",
[AttrSizedResultSegments]> {
let results = (outs Variadic<I64>:$result0, Variadic<AnyType>:$result1);
let assemblyFormat = [{
`:` `(` type($result0) `)` `,` `(` type($result1) `)` attr-dict
}];
}
// Test various mixings of operand type formatting.
class FormatOperandBase<string suffix, string fmt>
: TEST_Op<"format_operand_" # suffix # "_op"> {
@ -1506,6 +1519,19 @@ def FormatSuccessorAOp : TEST_Op<"format_successor_a_op", [Terminator]> {
let assemblyFormat = "$targets attr-dict";
}
def FormatVariadicOperand : TEST_Op<"format_variadic_operand"> {
let arguments = (ins Variadic<I64>:$operand);
let assemblyFormat = [{ $operand `:` type($operand) attr-dict}];
}
def FormatMultipleVariadicOperands :
TEST_Op<"format_multiple_variadic_operands", [AttrSizedOperandSegments]> {
let arguments = (ins Variadic<I64>:$operand0, Variadic<AnyType>:$operand1);
let assemblyFormat = [{
` ` `(` $operand0 `)` `,` `(` $operand1 `:` type($operand1) `)` attr-dict
}];
}
// Test various mixings of optional operand and result type formatting.
class FormatOptionalOperandResultOpBase<string suffix, string fmt>
: TEST_Op<"format_optional_operand_result_" # suffix # "_op",

View File

@ -2,6 +2,8 @@
// CHECK: %[[I64:.*]] =
%i64 = "foo.op"() : () -> (i64)
// CHECK: %[[I32:.*]] =
%i32 = "foo.op"() : () -> (i32)
// CHECK: %[[MEMREF:.*]] =
%memref = "foo.op"() : () -> (memref<1xf64>)
@ -119,6 +121,12 @@ test.format_implicit_terminator_region_a_op {
// CHECK: test.format_result_c_op (i64) -> memref<1xf64>
%ignored_c:2 = test.format_result_c_op (i64) -> memref<1xf64>
// CHECK: test.format_variadic_result : i64, i64, i64
%ignored_v:3 = test.format_variadic_result : i64, i64, i64
// CHECK: test.format_multiple_variadic_results : (i64, i64, i64), (i32, i32)
%ignored_mv:5 = test.format_multiple_variadic_results : (i64, i64, i64), (i32, i32)
//===----------------------------------------------------------------------===//
// Format operands
//===----------------------------------------------------------------------===//
@ -138,6 +146,12 @@ test.format_operand_d_op %i64, %memref : memref<1xf64>
// CHECK: test.format_operand_e_op %[[I64]], %[[MEMREF]] : i64, memref<1xf64>
test.format_operand_e_op %i64, %memref : i64, memref<1xf64>
// CHECK: test.format_variadic_operand %[[I64]], %[[I64]], %[[I64]] : i64, i64, i64
test.format_variadic_operand %i64, %i64, %i64 : i64, i64, i64
// CHECK: test.format_multiple_variadic_operands (%[[I64]], %[[I64]], %[[I64]]), (%[[I64]], %[[I32]] : i64, i32)
test.format_multiple_variadic_operands (%i64, %i64, %i64), (%i64, %i32 : i64, i32)
//===----------------------------------------------------------------------===//
// Format successors
//===----------------------------------------------------------------------===//