[Mlir-commits] [mlir] 153c298 - [mlir][shape] Add value_as_shape op

Jacques Pienaar llvmlistbot at llvm.org
Fri Nov 12 11:53:48 PST 2021


Author: Jacques Pienaar
Date: 2021-11-12T11:53:27-08:00
New Revision: 153c2983422e6c5840efc4bbe73b7b9bf0658d0d

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

LOG: [mlir][shape] Add value_as_shape op

Part of the very first discussion here, but didn't upstream it before as we
didn't use it yet. Fix that for pending updates. Just adding the op here,
follow up will add the lowering to codegen.

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
index a05f7f30dd170..d2ef51acbfe07 100644
--- a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
+++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
@@ -643,6 +643,31 @@ def Shape_SizeToIndexOp : Shape_Op<"size_to_index", [NoSideEffect]> {
   let hasCanonicalizer = 1;
 }
 
+def Shape_ValueAsShapeOp : Shape_Op<"value_as_shape", [NoSideEffect]> {
+  let summary = "Returns value as a shape";
+
+  let description = [{
+    The operations takes a ValueShape and returns a Shape corresponding to the value.
+    If the input value cannot be shape (e.g., not a 1D tensor of integral value
+    representing sizes) then this propagages the error shape. E.g.,
+
+    ```mlir
+    // The following
+    %0 = arith.constant dense<[1,2]> : tensor<2xi32>
+    %shape = shape.value_as_shape %0 : tensor<2xi32> -> !shape.shape
+    // is equivalent to
+    %shape' = shape.const_shape [1, 2] : !shape.shape
+    ```
+
+    This operation is the compliment of `shape_of` wrt ValueShape values.
+  }];
+
+  let arguments = (ins AnyTypeOf<[1DTensorOf<[AnyInteger, Index]>, Shape_ValueShapeType]>:$arg);
+  let results = (outs Shape_ShapeOrExtentTensorType:$result);
+
+  let assemblyFormat = "$arg attr-dict `:` type($arg) `->` type($result)";
+}
+
 def Shape_WithOp : Shape_Op<"with_shape", [NoSideEffect]> {
   let summary = "Returns ValueShape with given shape";
   let description = [{


        


More information about the Mlir-commits mailing list