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 @@ -17,6 +17,7 @@ include "mlir/Interfaces/ControlFlowInterfaces.td" include "mlir/Interfaces/InferTypeOpInterface.td" include "mlir/Interfaces/SideEffectInterfaces.td" +include "mlir/IR/OpAsmInterface.td" def Shape_WitnessType : DialectType()">, "witness">, @@ -111,10 +112,12 @@ let hasFolder = 1; } -def Shape_ConstSizeOp : Shape_Op<"const_size", - [ConstantLike, - NoSideEffect, - DeclareOpInterfaceMethods]> { +def Shape_ConstSizeOp : Shape_Op<"const_size", [ + ConstantLike, + NoSideEffect, + DeclareOpInterfaceMethods, + DeclareOpInterfaceMethods + ]> { let summary = "Creates a constant of type `shape.size`"; let description = [{ Creates a `shape.size` type representing the constant size given by `value`. diff --git a/mlir/lib/Dialect/Shape/IR/Shape.cpp b/mlir/lib/Dialect/Shape/IR/Shape.cpp --- a/mlir/lib/Dialect/Shape/IR/Shape.cpp +++ b/mlir/lib/Dialect/Shape/IR/Shape.cpp @@ -13,6 +13,7 @@ #include "mlir/IR/DialectImplementation.h" #include "mlir/IR/PatternMatch.h" #include "mlir/IR/StandardTypes.h" +#include "llvm/ADT/SmallString.h" #include "llvm/Support/raw_ostream.h" using namespace mlir; @@ -266,6 +267,14 @@ OpFoldResult ConstSizeOp::fold(ArrayRef) { return valueAttr(); } +void ConstSizeOp::getAsmResultNames( + llvm::function_ref setNameFn) { + SmallString<4> buffer; + llvm::raw_svector_ostream os(buffer); + os << "c" << value(); + setNameFn(getResult(), os.str()); +} + //===----------------------------------------------------------------------===// // IndexToSizeOp //===----------------------------------------------------------------------===// 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 @@ -80,3 +80,13 @@ } return } + +func @const_size() { + // CHECK: %c1 = shape.const_size 1 + // CHECK: %c2 = shape.const_size 2 + // CHECK: %c2_0 = shape.const_size 2 + %0 = shape.const_size 1 + %1 = shape.const_size 2 + %2 = shape.const_size 2 + return +}