Skip to content

Commit 6c87cd2

Browse files
committed
[Flang][OpenMP] Move char box bounds generation for Maps to DirectiveCommons.h
Currently we generate these bounds in the MapInfoFinalization.cpp pass as it seems there's a missing case for character strings/arrays (length parameter) in the DirectiveCommons bounds generation functionality OpenMP uses for it's map operations. This PR tries to add this case to the DirectiveCommons function and remove the need for the bounds generation in the MapInfoFinalization pass, so that we are generating the bounds in the same place most other bounds are generated.
1 parent c620d07 commit 6c87cd2

File tree

2 files changed

+10
-34
lines changed

2 files changed

+10
-34
lines changed

flang/include/flang/Lower/DirectivesCommon.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,11 +512,19 @@ fir::factory::AddrAndBoundsInfo gatherDataOperandAddrAndBounds(
512512
}
513513
bool dataExvIsAssumedSize =
514514
Fortran::semantics::IsAssumedSizeArray(symRef->get().GetUltimate());
515-
if (genDefaultBounds &&
516-
mlir::isa<fir::SequenceType>(fir::unwrapRefType(info.addr.getType())))
515+
if (genDefaultBounds && mlir::isa<fir::SequenceType>(
516+
fir::unwrapRefType(info.addr.getType()))) {
517517
bounds = fir::factory::genBaseBoundsOps<BoundsOp, BoundsType>(
518518
builder, operandLocation, dataExv, dataExvIsAssumedSize,
519519
strideIncludeLowerExtent);
520+
}
521+
if (genDefaultBounds && fir::characterWithDynamicLen(
522+
fir::unwrapRefType(info.addr.getType())) ||
523+
mlir::isa<fir::BoxCharType>(
524+
fir::unwrapRefType(info.addr.getType()))) {
525+
bounds = {fir::factory::genBoundsOpFromBoxChar<BoundsOp, BoundsType>(
526+
builder, operandLocation, dataExv, info)};
527+
}
520528
asFortran << symRef->get().name().ToString();
521529
} else { // Unsupported
522530
llvm::report_fatal_error("Unsupported type of OpenACC operand");

flang/lib/Optimizer/OpenMP/MapInfoFinalization.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -987,38 +987,6 @@ class MapInfoFinalizationPass
987987
localBoxAllocas.clear();
988988
deferrableDesc.clear();
989989

990-
// First, walk `omp.map.info` ops to see if any of them have varPtrs
991-
// with an underlying type of fir.char<k, ?>, i.e a character
992-
// with dynamic length. If so, check if they need bounds added.
993-
func->walk([&](mlir::omp::MapInfoOp op) {
994-
if (!op.getBounds().empty())
995-
return;
996-
997-
mlir::Value varPtr = op.getVarPtr();
998-
mlir::Type underlyingVarType = fir::unwrapRefType(varPtr.getType());
999-
1000-
if (!fir::characterWithDynamicLen(underlyingVarType))
1001-
return;
1002-
1003-
fir::factory::AddrAndBoundsInfo info =
1004-
fir::factory::getDataOperandBaseAddr(
1005-
builder, varPtr, /*isOptional=*/false, varPtr.getLoc());
1006-
1007-
fir::ExtendedValue extendedValue =
1008-
hlfir::translateToExtendedValue(varPtr.getLoc(), builder,
1009-
hlfir::Entity{info.addr},
1010-
/*continguousHint=*/true)
1011-
.first;
1012-
builder.setInsertionPoint(op);
1013-
llvm::SmallVector<mlir::Value> boundsOps =
1014-
fir::factory::genImplicitBoundsOps<mlir::omp::MapBoundsOp,
1015-
mlir::omp::MapBoundsType>(
1016-
builder, info, extendedValue,
1017-
/*dataExvIsAssumedSize=*/false, varPtr.getLoc());
1018-
1019-
op.getBoundsMutable().append(boundsOps);
1020-
});
1021-
1022990
// Next, walk `omp.map.info` ops to see if any record members should be
1023991
// implicitly mapped.
1024992
func->walk([&](mlir::omp::MapInfoOp op) {

0 commit comments

Comments
 (0)