[mlir][shape] Tidy up shape.shape_of
authorSean Silva <silvasean@google.com>
Sun, 10 May 2020 02:17:41 +0000 (19:17 -0700)
committerSean Silva <silvasean@google.com>
Mon, 11 May 2020 19:55:31 +0000 (12:55 -0700)
Summary:
- Mark it NoSideEffect
- Add custom parser/printer

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

mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
mlir/test/Dialect/Shape/ops.mlir

index 6b64bb7..3753213 100644 (file)
@@ -226,12 +226,14 @@ def Shape_ReduceOp : Shape_Op<"reduce", []> {
 }
 
 def Shape_ShapeOfOp : Shape_Op<"shape_of",
-    [DeclareOpInterfaceMethods<InferTypeOpInterface>]> {
+    [NoSideEffect, DeclareOpInterfaceMethods<InferTypeOpInterface>]> {
   let summary = "Returns shape of a value or shaped type operand";
 
   let arguments = (ins AnyTypeOf<[AnyShaped, Shape_ValueShapeType]>:$arg);
   let results = (outs Shape_ShapeType:$result);
 
+  let assemblyFormat = "attr-dict $arg `:` type($arg)";
+
   let hasFolder = 1;
 }
 
index 5ca3b0f..81c9afc 100644 (file)
@@ -62,3 +62,8 @@ func @test_parse_const_shape() {
   %1 = shape.const_shape [1, 2, 3]
   return
 }
+
+func @test_shape_of(%arg0: tensor<?xf32>) -> !shape.shape {
+  %0 = shape.shape_of %arg0 : tensor<?xf32>
+  return %0 : !shape.shape
+}