diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td --- a/flang/include/flang/Optimizer/Dialect/FIROps.td +++ b/flang/include/flang/Optimizer/Dialect/FIROps.td @@ -1773,6 +1773,8 @@ }]; let hasVerifier = 1; + + let builders = [OpBuilder<(ins "mlir::ValueRange":$extents)>]; } def fir_ShapeShiftOp : fir_Op<"shape_shift", [NoMemoryEffect]> { diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp --- a/flang/lib/Lower/ConvertExpr.cpp +++ b/flang/lib/Lower/ConvertExpr.cpp @@ -4375,8 +4375,7 @@ llvm::SmallVector idxShape; for (auto s : shape) idxShape.push_back(builder.createConvert(loc, idxTy, s)); - auto shapeTy = fir::ShapeType::get(builder.getContext(), idxShape.size()); - return builder.create(loc, shapeTy, idxShape); + return builder.create(loc, idxShape); } fir::ShapeOp genShapeOp(llvm::ArrayRef shape) { diff --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp b/flang/lib/Optimizer/Builder/FIRBuilder.cpp --- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp +++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp @@ -379,8 +379,7 @@ mlir::Value fir::FirOpBuilder::genShape(mlir::Location loc, llvm::ArrayRef exts) { - auto shapeType = fir::ShapeType::get(getContext(), exts.size()); - return create(loc, shapeType, exts); + return create(loc, exts); } mlir::Value fir::FirOpBuilder::genShape(mlir::Location loc, diff --git a/flang/lib/Optimizer/Builder/MutableBox.cpp b/flang/lib/Optimizer/Builder/MutableBox.cpp --- a/flang/lib/Optimizer/Builder/MutableBox.cpp +++ b/flang/lib/Optimizer/Builder/MutableBox.cpp @@ -34,9 +34,7 @@ mlir::Value shape; if (!extents.empty()) { if (lbounds.empty()) { - auto shapeType = - fir::ShapeType::get(builder.getContext(), extents.size()); - shape = builder.create(loc, shapeType, extents); + shape = builder.create(loc, extents); } else { llvm::SmallVector shapeShiftBounds; for (auto [lb, extent] : llvm::zip(lbounds, extents)) { diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp --- a/flang/lib/Optimizer/Dialect/FIROps.cpp +++ b/flang/lib/Optimizer/Dialect/FIROps.cpp @@ -3086,6 +3086,12 @@ return mlir::success(); } +void fir::ShapeOp::build(mlir::OpBuilder &builder, mlir::OperationState &result, + mlir::ValueRange extents) { + auto type = fir::ShapeType::get(builder.getContext(), extents.size()); + build(builder, result, type, extents); +} + //===----------------------------------------------------------------------===// // ShapeShiftOp //===----------------------------------------------------------------------===// diff --git a/flang/unittests/Optimizer/FortranVariableTest.cpp b/flang/unittests/Optimizer/FortranVariableTest.cpp --- a/flang/unittests/Optimizer/FortranVariableTest.cpp +++ b/flang/unittests/Optimizer/FortranVariableTest.cpp @@ -36,8 +36,7 @@ } mlir::Value createShape(llvm::ArrayRef extents) { - mlir::Type shapeType = fir::ShapeType::get(&context, extents.size()); - return builder->create(getLoc(), shapeType, extents); + return builder->create(getLoc(), extents); } mlir::MLIRContext context; std::unique_ptr builder;