diff --git a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td --- a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td +++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td @@ -639,6 +639,21 @@ }]; } +def Shape_ValueOfOp : Shape_Op<"value_of", [NoSideEffect]> { + let summary = "Returns value of a !shape.value_shape operand"; + + let description = [{ + The operation takes !shape.value_shape, a.k.a. (value, shape) tuple as an + argument, and returns its value. The behavior is undefined for unknown and + invalid arguments. + }]; + + let arguments = (ins Shape_ValueShapeType:$arg); + let results = (outs AnyShaped:$result); + + let assemblyFormat = "$arg attr-dict `:` type($result)"; +} + def Shape_SizeToIndexOp : Shape_Op<"size_to_index", [ DeclareOpInterfaceMethods, NoSideEffect ]> { diff --git a/mlir/test/Dialect/Shape/ops.mlir b/mlir/test/Dialect/Shape/ops.mlir --- a/mlir/test/Dialect/Shape/ops.mlir +++ b/mlir/test/Dialect/Shape/ops.mlir @@ -97,6 +97,11 @@ return %0 : tensor } +func.func @test_value_of(%arg0: !shape.value_shape) -> tensor { + %0 = shape.value_of %arg0 : tensor + return %0 : tensor +} + func.func @test_constraints() { %0 = shape.const_shape [] : !shape.shape %1 = shape.const_shape [1, 2, 3] : !shape.shape