[Mlir-commits] [mlir] 0203558 - [mlir] Add custom assembly formats to shape.witness ops.

Tres Popp llvmlistbot at llvm.org
Wed May 20 04:25:44 PDT 2020


Author: Tres Popp
Date: 2020-05-20T13:25:33+02:00
New Revision: 02035580d3b5a4dad081704a70ceb269e9264619

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

LOG: [mlir] Add custom assembly formats to shape.witness ops.

The assembly formats are essentially the generic forms without
quotations and type information.

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

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
    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 2e521db736dd..7d62cebff8e6 100644
--- a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
+++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
@@ -381,13 +381,15 @@ def Shape_AnyOp : Shape_Op<"any",
 
     Example:
     ```mlir
-      %s0 = shape.any([2,?], [?,3]) // [2,3]
-      %s1 = shape.any([?,?], [1,2]) // [1,2]
+      %s0 = shape.any [2,?], [?,3] // [2,3]
+      %s1 = shape.any [?,?], [1,2] // [1,2]
     ```
   }];
 
   let arguments = (ins Variadic<Shape_ShapeType>:$inputs);
   let results = (outs Shape_ShapeType:$result);
+
+  let assemblyFormat = "$inputs attr-dict";
 }
 
 def Shape_AssumingAllOp : Shape_Op<"assuming_all", [NoSideEffect]> {
@@ -403,16 +405,18 @@ def Shape_AssumingAllOp : Shape_Op<"assuming_all", [NoSideEffect]> {
 
     Example:
     ```mlir
-      %w0 = shape.cstr_broadcastable([2,2], [3,1,2]) // Success
-      %w1 = shape.cstr_broadcastable([2,2], [3,2])    // Failure
-      %w2 = shape.cstr_eq([1,2], [1,2], [1,2]) // Success
-      %wf = shape.assume_all(%w0, %w1) // Failure
-      %wt = shape.assume_all(%w0, %w2) // Success
+      %w0 = shape.cstr_broadcastable [2,2], [3,1,2] // Success
+      %w1 = shape.cstr_broadcastable [2,2], [3,2] // Failure
+      %w2 = shape.cstr_eq [1,2], [1,2], [1,2] // Success
+      %wf = shape.assuming_all %w0, %w1 // Failure
+      %wt = shape.assuming_all %w0, %w2 // Success
     ```
   }];
 
   let arguments = (ins Variadic<Shape_WitnessType>:$inputs);
   let results = (outs Shape_WitnessType:$result);
+
+  let assemblyFormat = "$inputs attr-dict";
 }
 
 def Shape_AssumingOp : Shape_Op<"assuming",
@@ -451,6 +455,8 @@ def Shape_AssumingYieldOp : Shape_Op<"assuming_yield",
     OpBuilder<"OpBuilder &builder, OperationState &result",
     [{ /* nothing to do */ }]>
   ];
+
+  let assemblyFormat = "attr-dict ($operands^ `:` type($operands))?";
 }
 
 def Shape_CstrBroadcastableOp : Shape_Op<"cstr_broadcastable", []> {
@@ -463,13 +469,15 @@ def Shape_CstrBroadcastableOp : Shape_Op<"cstr_broadcastable", []> {
 
     Example:
     ```mlir
-      %w0 = shape.cstr_broadcastable([2,2], [3,1,2])  // Success
-      %w1 = shape.cstr_broadcastable([2,2], [3,2])    // Failure
+      %w0 = shape.cstr_broadcastable [2,2], [3,1,2] // Success
+      %w1 = shape.cstr_broadcastable [2,2], [3,2] // Failure
     ```
   }];
 
   let arguments = (ins Shape_ShapeType:$lhs, Shape_ShapeType:$rhs);
   let results = (outs Shape_WitnessType:$result);
+
+  let assemblyFormat = "$lhs `,` $rhs attr-dict";
 }
 
 def Shape_CstrEqOp : Shape_Op<"cstr_eq", []> {
@@ -481,12 +489,14 @@ def Shape_CstrEqOp : Shape_Op<"cstr_eq", []> {
 
     Example:
     ```mlir
-      %w0 = shape.cstr_eq([1,2], [1,2], [1,2]) // Success
-      %w1 = shape.cstr_eq([2,2], [1,2])        // Failure
+      %w0 = shape.cstr_eq [1,2], [1,2], [1,2] // Success
+      %w1 = shape.cstr_eq [2,2], [1,2] // Failure
     ```
   }];
   let arguments = (ins Variadic<Shape_ShapeType>:$inputs);
   let results = (outs Shape_WitnessType:$result);
+
+  let assemblyFormat = "$inputs attr-dict";
 }
 
 

diff  --git a/mlir/test/Dialect/Shape/ops.mlir b/mlir/test/Dialect/Shape/ops.mlir
index 7934f4ee0d6d..42eaf58a87ac 100644
--- a/mlir/test/Dialect/Shape/ops.mlir
+++ b/mlir/test/Dialect/Shape/ops.mlir
@@ -71,12 +71,12 @@ func @test_shape_of(%arg0: tensor<?xf32>) -> !shape.shape {
 func @test_constraints() {
   %0 = shape.const_shape []
   %1 = shape.const_shape [1, 2, 3]
-  %w0 = "shape.cstr_broadcastable"(%0, %1) : (!shape.shape, !shape.shape) -> !shape.witness
-  %w1 = "shape.cstr_eq"(%0, %1) : (!shape.shape, !shape.shape) -> !shape.witness
-  %w3 = "shape.assuming_all"(%w0, %w1) : (!shape.witness, !shape.witness) -> !shape.witness
+  %w0 = shape.cstr_broadcastable %0, %1
+  %w1 = shape.cstr_eq %0, %1
+  %w3 = shape.assuming_all %w0, %w1
   shape.assuming %w3 -> !shape.shape {
-    %2 = "shape.any"(%0, %1)  : (!shape.shape, !shape.shape) -> !shape.shape
-    "shape.assuming_yield"(%2) : (!shape.shape) -> ()
+    %2 = shape.any %0, %1
+    shape.assuming_yield %2 : !shape.shape
   }
   return
 }


        


More information about the Mlir-commits mailing list