Skip to content

Commit

Permalink
[flang][NFC] add builder to simplify fir.shape creation
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D140031
  • Loading branch information
jeanPerier committed Dec 15, 2022
1 parent 7d0429b commit b22fa86
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 9 deletions.
2 changes: 2 additions & 0 deletions flang/include/flang/Optimizer/Dialect/FIROps.td
Expand Up @@ -1773,6 +1773,8 @@ def fir_ShapeOp : fir_Op<"shape", [NoMemoryEffect]> {
}];

let hasVerifier = 1;

let builders = [OpBuilder<(ins "mlir::ValueRange":$extents)>];
}

def fir_ShapeShiftOp : fir_Op<"shape_shift", [NoMemoryEffect]> {
Expand Down
3 changes: 1 addition & 2 deletions flang/lib/Lower/ConvertExpr.cpp
Expand Up @@ -4375,8 +4375,7 @@ class ArrayExprLowering {
llvm::SmallVector<mlir::Value> 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<fir::ShapeOp>(loc, shapeTy, idxShape);
return builder.create<fir::ShapeOp>(loc, idxShape);
}

fir::ShapeOp genShapeOp(llvm::ArrayRef<mlir::Value> shape) {
Expand Down
3 changes: 1 addition & 2 deletions flang/lib/Optimizer/Builder/FIRBuilder.cpp
Expand Up @@ -379,8 +379,7 @@ fir::StringLitOp fir::FirOpBuilder::createStringLitOp(mlir::Location loc,

mlir::Value fir::FirOpBuilder::genShape(mlir::Location loc,
llvm::ArrayRef<mlir::Value> exts) {
auto shapeType = fir::ShapeType::get(getContext(), exts.size());
return create<fir::ShapeOp>(loc, shapeType, exts);
return create<fir::ShapeOp>(loc, exts);
}

mlir::Value fir::FirOpBuilder::genShape(mlir::Location loc,
Expand Down
4 changes: 1 addition & 3 deletions flang/lib/Optimizer/Builder/MutableBox.cpp
Expand Up @@ -34,9 +34,7 @@ createNewFirBox(fir::FirOpBuilder &builder, mlir::Location loc,
mlir::Value shape;
if (!extents.empty()) {
if (lbounds.empty()) {
auto shapeType =
fir::ShapeType::get(builder.getContext(), extents.size());
shape = builder.create<fir::ShapeOp>(loc, shapeType, extents);
shape = builder.create<fir::ShapeOp>(loc, extents);
} else {
llvm::SmallVector<mlir::Value> shapeShiftBounds;
for (auto [lb, extent] : llvm::zip(lbounds, extents)) {
Expand Down
6 changes: 6 additions & 0 deletions flang/lib/Optimizer/Dialect/FIROps.cpp
Expand Up @@ -3086,6 +3086,12 @@ mlir::LogicalResult fir::ShapeOp::verify() {
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
//===----------------------------------------------------------------------===//
Expand Down
3 changes: 1 addition & 2 deletions flang/unittests/Optimizer/FortranVariableTest.cpp
Expand Up @@ -36,8 +36,7 @@ struct FortranVariableTest : public testing::Test {
}

mlir::Value createShape(llvm::ArrayRef<mlir::Value> extents) {
mlir::Type shapeType = fir::ShapeType::get(&context, extents.size());
return builder->create<fir::ShapeOp>(getLoc(), shapeType, extents);
return builder->create<fir::ShapeOp>(getLoc(), extents);
}
mlir::MLIRContext context;
std::unique_ptr<mlir::OpBuilder> builder;
Expand Down

0 comments on commit b22fa86

Please sign in to comment.