aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Optimizer/Builder/FIRBuilder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'flang/lib/Optimizer/Builder/FIRBuilder.cpp')
-rw-r--r--flang/lib/Optimizer/Builder/FIRBuilder.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp b/flang/lib/Optimizer/Builder/FIRBuilder.cpp
index b6501fd..5e6e208 100644
--- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp
+++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp
@@ -1974,3 +1974,25 @@ void fir::factory::genLifetimeEnd(mlir::OpBuilder &builder, mlir::Location loc,
mlir::Value cast) {
mlir::LLVM::LifetimeEndOp::create(builder, loc, cast);
}
+
+mlir::Value fir::factory::getDescriptorWithNewBaseAddress(
+ fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value box,
+ mlir::Value newAddr) {
+ auto boxType = llvm::dyn_cast<fir::BaseBoxType>(box.getType());
+ assert(boxType &&
+ "expected a box type input in getDescriptorWithNewBaseAddress");
+ if (boxType.isAssumedRank())
+ TODO(loc, "changing descriptor base address for an assumed rank entity");
+ llvm::SmallVector<mlir::Value> lbounds;
+ fir::factory::genDimInfoFromBox(builder, loc, box, &lbounds,
+ /*extents=*/nullptr, /*strides=*/nullptr);
+ fir::BoxValue inputBoxValue(box, lbounds, /*explicitParams=*/{});
+ fir::ExtendedValue openedInput =
+ fir::factory::readBoxValue(builder, loc, inputBoxValue);
+ mlir::Value shape = fir::isArray(openedInput)
+ ? builder.createShape(loc, openedInput)
+ : mlir::Value{};
+ mlir::Value typeMold = fir::isPolymorphicType(boxType) ? box : mlir::Value{};
+ return builder.createBox(loc, boxType, newAddr, shape, /*slice=*/{},
+ fir::getTypeParams(openedInput), typeMold);
+}