[Mlir-commits] [mlir] a9a6f0f - [MLIR][Shape] Add custom assembly format for `shape.any`

Frederik Gossen llvmlistbot at llvm.org
Fri Aug 14 02:15:41 PDT 2020


Author: Frederik Gossen
Date: 2020-08-14T09:15:15Z
New Revision: a9a6f0fe1d65346ad86021af727058a31594a6b8

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

LOG: [MLIR][Shape] Add custom assembly format for `shape.any`

Add custom assembly format for `shape.any` with variadic operands.

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

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
    mlir/test/Dialect/Shape/canonicalize.mlir
    mlir/test/Dialect/Shape/ops.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
index ac077439be3c..2e8f03237039 100644
--- a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
+++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
@@ -581,6 +581,8 @@ def Shape_AnyOp : Shape_Op<"any", [Commutative,
   let arguments = (ins Variadic<Shape_ShapeOrExtentTensorType>:$inputs);
   let results = (outs Shape_ShapeOrExtentTensorType:$result);
 
+  let assemblyFormat = "$inputs attr-dict `:` type($inputs) `->` type($result)";
+
   let hasFolder = 1;
 }
 

diff  --git a/mlir/test/Dialect/Shape/canonicalize.mlir b/mlir/test/Dialect/Shape/canonicalize.mlir
index 8a38b42c5a71..670d207a5f47 100644
--- a/mlir/test/Dialect/Shape/canonicalize.mlir
+++ b/mlir/test/Dialect/Shape/canonicalize.mlir
@@ -428,7 +428,7 @@ func @f(%arg : !shape.shape) -> !shape.shape {
   // CHECK-NEXT: %[[CS:.*]] = shape.const_shape
   // CHECK-NEXT: return %[[CS]]
   %0 = shape.const_shape [2, 3, 4] : !shape.shape
-  %1 = "shape.any"(%0, %arg) : (!shape.shape, !shape.shape) -> !shape.shape
+  %1 = shape.any %0, %arg : !shape.shape, !shape.shape -> !shape.shape
   return %1 : !shape.shape
 }
 
@@ -440,7 +440,7 @@ func @f(%arg : tensor<?xindex>) -> tensor<?xindex> {
   // CHECK-NEXT: %[[CS:.*]] = shape.const_shape [2, 3, 4] : tensor<?xindex>
   // CHECK-NEXT: return %[[CS]] : tensor<?xindex>
   %0 = shape.const_shape [2, 3, 4] : tensor<?xindex>
-  %1 = "shape.any"(%0, %arg) : (tensor<?xindex>, tensor<?xindex>) -> tensor<?xindex>
+  %1 = shape.any %0, %arg : tensor<?xindex>, tensor<?xindex> -> tensor<?xindex>
   return %1 : tensor<?xindex>
 }
 
@@ -449,9 +449,9 @@ func @f(%arg : tensor<?xindex>) -> tensor<?xindex> {
 // Folding of any with partially constant operands is not yet implemented.
 // CHECK-LABEL: func @f
 func @f(%arg0 : !shape.shape, %arg1 : !shape.shape) -> !shape.shape {
-  // CHECK-NEXT: %[[CS:.*]] = "shape.any"
+  // CHECK-NEXT: %[[CS:.*]] = shape.any
   // CHECK-NEXT: return %[[CS]]
-  %1 = "shape.any"(%arg0, %arg1) : (!shape.shape, !shape.shape) -> !shape.shape
+  %1 = shape.any %arg0, %arg1 : !shape.shape, !shape.shape -> !shape.shape
   return %1 : !shape.shape
 }
 

diff  --git a/mlir/test/Dialect/Shape/ops.mlir b/mlir/test/Dialect/Shape/ops.mlir
index 172835a2c6d5..c13f89d1af02 100644
--- a/mlir/test/Dialect/Shape/ops.mlir
+++ b/mlir/test/Dialect/Shape/ops.mlir
@@ -235,3 +235,26 @@ func @shape_with_shape(%a : !shape.value_shape, %b : !shape.value_shape) -> !sha
   %2 = call @shape_equal_shapes(%a, %1) : (!shape.value_shape, !shape.value_shape) -> !shape.shape
   return %2 : !shape.shape
 }
+
+func @any_on_shape(%a : !shape.shape, %b : !shape.shape, %c : !shape.shape)
+    -> !shape.shape {
+  %result = shape.any %a, %b, %c
+      : !shape.shape, !shape.shape, !shape.shape -> !shape.shape
+  return %result : !shape.shape
+}
+
+func @any_on_mixed(%a : tensor<?xindex>,
+                   %b : tensor<?xindex>,
+                   %c : !shape.shape) -> !shape.shape {
+  %result = shape.any %a, %b, %c
+      : tensor<?xindex>, tensor<?xindex>, !shape.shape -> !shape.shape
+  return %result : !shape.shape
+}
+
+func @any_on_extent_tensors(%a : tensor<?xindex>,
+                            %b : tensor<?xindex>,
+                            %c : tensor<?xindex>) -> tensor<?xindex> {
+  %result = shape.any %a, %b, %c
+      : tensor<?xindex>, tensor<?xindex>, tensor<?xindex> -> tensor<?xindex>
+  return %result : tensor<?xindex>
+}


        


More information about the Mlir-commits mailing list