[Mlir-commits] [mlir] 867bc41 - [MLIR] Add type conversion for `shape.shape`

Frederik Gossen llvmlistbot at llvm.org
Mon Jun 8 02:35:12 PDT 2020


Author: Frederik Gossen
Date: 2020-06-08T09:34:03Z
New Revision: 867bc41e85cb553b5aed827847ae59ed9c2e1248

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

LOG: [MLIR] Add type conversion for `shape.shape`

Convert `shape.shape` to `tensor<?xindex>` when lowering the `shape` to the
`std` dialect.

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

Added: 
    

Modified: 
    mlir/lib/Conversion/ShapeToStandard/ShapeToStandard.cpp
    mlir/test/Conversion/ShapeToStandard/shape-to-standard.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/ShapeToStandard/ShapeToStandard.cpp b/mlir/lib/Conversion/ShapeToStandard/ShapeToStandard.cpp
index 1ddd681ea675..8deb8b85c25e 100644
--- a/mlir/lib/Conversion/ShapeToStandard/ShapeToStandard.cpp
+++ b/mlir/lib/Conversion/ShapeToStandard/ShapeToStandard.cpp
@@ -56,6 +56,10 @@ class ShapeTypeConverter : public TypeConverter {
     // Add default pass-through conversion.
     addConversion([&](Type type) { return type; });
     addConversion([ctx](shape::SizeType type) { return IndexType::get(ctx); });
+    addConversion([ctx](shape::ShapeType type) {
+      return RankedTensorType::get({ShapedType::kDynamicSize},
+                                   IndexType::get(ctx));
+    });
   }
 };
 

diff  --git a/mlir/test/Conversion/ShapeToStandard/shape-to-standard.mlir b/mlir/test/Conversion/ShapeToStandard/shape-to-standard.mlir
index c27b408dfef1..138a9b2f1db1 100644
--- a/mlir/test/Conversion/ShapeToStandard/shape-to-standard.mlir
+++ b/mlir/test/Conversion/ShapeToStandard/shape-to-standard.mlir
@@ -29,3 +29,13 @@ func @index_to_size(%index : index) -> !shape.size {
   %size = shape.index_to_size %index
   return %size : !shape.size
 }
+
+// -----
+
+// Convert `shape` to `tensor<?xindex>` type.
+// CHECK-LABEL: @shape_id
+// CHECK-SAME: (%[[SHAPE:.*]]: tensor<?xindex>)
+func @shape_id(%shape : !shape.shape) -> !shape.shape {
+  // CHECK: return %[[SHAPE]] : tensor<?xindex>
+  return %shape : !shape.shape
+}


        


More information about the Mlir-commits mailing list