[Mlir-commits] [mlir] 8a4fe75 - [NFC] Add unit tests for printing/parsing of variadic operands and results.

Rahul Joshi llvmlistbot at llvm.org
Tue Nov 17 09:22:49 PST 2020


Author: Rahul Joshi
Date: 2020-11-17T09:21:46-08:00
New Revision: 8a4fe75d70e1640078c464b9da76ffbe0a49c014

URL: https://github.com/llvm/llvm-project/commit/8a4fe75d70e1640078c464b9da76ffbe0a49c014
DIFF: https://github.com/llvm/llvm-project/commit/8a4fe75d70e1640078c464b9da76ffbe0a49c014.diff

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

Differential Revision: https://reviews.llvm.org/D91557

Added: 
    

Modified: 
    mlir/test/lib/Dialect/Test/TestOps.td
    mlir/test/mlir-tblgen/op-format.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td
index d50db48148a6..a1f3246075dd 100644
--- a/mlir/test/lib/Dialect/Test/TestOps.td
+++ b/mlir/test/lib/Dialect/Test/TestOps.td
@@ -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",

diff  --git a/mlir/test/mlir-tblgen/op-format.mlir b/mlir/test/mlir-tblgen/op-format.mlir
index 34919513aca6..d19d569729aa 100644
--- a/mlir/test/mlir-tblgen/op-format.mlir
+++ b/mlir/test/mlir-tblgen/op-format.mlir
@@ -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
 //===----------------------------------------------------------------------===//


        


More information about the Mlir-commits mailing list