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 @@ -105,7 +105,7 @@ %1 = shape.const_shape [1, 2, 3] ``` }]; - let arguments = (ins I64ElementsAttr:$shape); + let arguments = (ins IndexElementsAttr:$shape); let results = (outs Shape_ShapeType:$result); // TODO: Move this to main so that all shape ops implement these. @@ -209,13 +209,8 @@ let builders = [ // Builder that allows passing a simple integer instead of an IntegerAttr. OpBuilder< - [{ - OpBuilder &builder, OperationState &result, - Value shape, int64_t dim - }], - [{ - build(builder, result, shape, builder.getI64IntegerAttr(dim)); - }] + [{OpBuilder &builder, OperationState &result, Value shape, int64_t dim}], + [{build(builder, result, shape, builder.getI64IntegerAttr(dim));}] > ]; 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 @@ -177,7 +177,7 @@ if (!OpTrait::util::getBroadcastedShape(lhsShape, rhsShape, resultShape)) return nullptr; Builder builder(getContext()); - return builder.getI64TensorAttr(resultShape); + return builder.getIndexTensorAttr(resultShape); } //===----------------------------------------------------------------------===// @@ -215,7 +215,7 @@ ints.push_back(attr.getInt()); } Builder &builder = parser.getBuilder(); - result.addAttribute("shape", builder.getI64TensorAttr(ints)); + result.addAttribute("shape", builder.getIndexTensorAttr(ints)); result.types.push_back(ShapeType::get(builder.getContext())); return success(); @@ -266,7 +266,7 @@ for (auto attr : operands) extents.push_back(attr.cast().getInt()); Builder builder(getContext()); - return builder.getI64TensorAttr(extents); + return builder.getIndexTensorAttr(extents); } //===----------------------------------------------------------------------===// @@ -290,14 +290,7 @@ // TODO: Constant fold this to some kind of constant error. if (dimToGet >= (uint64_t)elements.getNumElements()) return nullptr; - // This is a little inconvenient because getValue returns an IntegerAttr - // that is not of IndexType, but the result here needs to be of - // IndexType. - // TODO: Make ConstShapeOp hold an tensor of index instead of i64. - Builder builder(getContext()); - return builder.getIntegerAttr( - builder.getIndexType(), - elements.getValue({dimToGet}).getInt()); + return elements.getValue({dimToGet}); } //===----------------------------------------------------------------------===// @@ -318,7 +311,7 @@ if (!type || !type.hasStaticShape()) return nullptr; Builder builder(getContext()); - return builder.getI64TensorAttr(type.getShape()); + return builder.getIndexTensorAttr(type.getShape()); } //===----------------------------------------------------------------------===// @@ -352,8 +345,8 @@ if (splitPoint < 0) splitPoint += shape.size(); Builder builder(operands[0].getContext()); - results.push_back(builder.getI64TensorAttr(shape.take_front(splitPoint))); - results.push_back(builder.getI64TensorAttr(shape.drop_front(splitPoint))); + results.push_back(builder.getIndexTensorAttr(shape.take_front(splitPoint))); + results.push_back(builder.getIndexTensorAttr(shape.drop_front(splitPoint))); return success(); } @@ -382,7 +375,7 @@ resultShape.append(lhsShape.begin(), lhsShape.end()); resultShape.append(rhsShape.begin(), rhsShape.end()); Builder builder(getContext()); - return builder.getI64TensorAttr(resultShape); + return builder.getIndexTensorAttr(resultShape); } //===----------------------------------------------------------------------===// diff --git a/mlir/test/Dialect/Shape/canonicalize.mlir b/mlir/test/Dialect/Shape/canonicalize.mlir --- a/mlir/test/Dialect/Shape/canonicalize.mlir +++ b/mlir/test/Dialect/Shape/canonicalize.mlir @@ -15,7 +15,7 @@ // CHECK: shape.const_shape [2, 3] // CHECK: shape.const_shape [4, 5] %c2 = constant 2 : i32 - %0 = "shape.const_shape"() {shape = dense<[2, 3, 4, 5]> : tensor<4xi64>} : () -> !shape.shape + %0 = shape.const_shape [2, 3, 4, 5] %head, %tail = "shape.split_at"(%0, %c2) : (!shape.shape, i32) -> (!shape.shape, !shape.shape) return %head, %tail : !shape.shape, !shape.shape @@ -28,7 +28,7 @@ // CHECK: shape.const_shape [2, 3, 4] // CHECK: shape.const_shape [5] %c-1 = constant -1 : i32 - %0 = "shape.const_shape"() {shape = dense<[2, 3, 4, 5]> : tensor<4xi64>} : () -> !shape.shape + %0 = shape.const_shape [2, 3, 4, 5] %head, %tail = "shape.split_at"(%0, %c-1) : (!shape.shape, i32) -> (!shape.shape, !shape.shape) return %head, %tail : !shape.shape, !shape.shape } @@ -39,7 +39,7 @@ func @f() -> (!shape.shape, !shape.shape) { // CHECK: shape.split_at %c5 = constant 5 : i32 - %0 = "shape.const_shape"() {shape = dense<[2, 3, 4, 5]> : tensor<4xi64>} : () -> !shape.shape + %0 = shape.const_shape [2, 3, 4, 5] %head, %tail = "shape.split_at"(%0, %c5) : (!shape.shape, i32) -> (!shape.shape, !shape.shape) return %head, %tail : !shape.shape, !shape.shape }