Skip to content

Commit 08222ca

Browse files
authored
[Flang][OpenMP] Move char box bounds generation for Maps to DirectiveCommons.h (llvm#165918)
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 b7423af commit 08222ca

File tree

3 files changed

+29
-34
lines changed

3 files changed

+29
-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
@@ -943,38 +943,6 @@ class MapInfoFinalizationPass
943943
localBoxAllocas.clear();
944944
deferrableDesc.clear();
945945

946-
// First, walk `omp.map.info` ops to see if any of them have varPtrs
947-
// with an underlying type of fir.char<k, ?>, i.e a character
948-
// with dynamic length. If so, check if they need bounds added.
949-
func->walk([&](mlir::omp::MapInfoOp op) {
950-
if (!op.getBounds().empty())
951-
return;
952-
953-
mlir::Value varPtr = op.getVarPtr();
954-
mlir::Type underlyingVarType = fir::unwrapRefType(varPtr.getType());
955-
956-
if (!fir::characterWithDynamicLen(underlyingVarType))
957-
return;
958-
959-
fir::factory::AddrAndBoundsInfo info =
960-
fir::factory::getDataOperandBaseAddr(
961-
builder, varPtr, /*isOptional=*/false, varPtr.getLoc());
962-
963-
fir::ExtendedValue extendedValue =
964-
hlfir::translateToExtendedValue(varPtr.getLoc(), builder,
965-
hlfir::Entity{info.addr},
966-
/*continguousHint=*/true)
967-
.first;
968-
builder.setInsertionPoint(op);
969-
llvm::SmallVector<mlir::Value> boundsOps =
970-
fir::factory::genImplicitBoundsOps<mlir::omp::MapBoundsOp,
971-
mlir::omp::MapBoundsType>(
972-
builder, info, extendedValue,
973-
/*dataExvIsAssumedSize=*/false, varPtr.getLoc());
974-
975-
op.getBoundsMutable().append(boundsOps);
976-
});
977-
978946
// Next, walk `omp.map.info` ops to see if any record members should be
979947
// implicitly mapped.
980948
func->walk([&](mlir::omp::MapInfoOp op) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
! RUN: %flang_fc1 -emit-hlfir -fopenmp -o - %s 2>&1 | FileCheck %s
2+
3+
subroutine TestCharLenBounds(clen)
4+
5+
character(len=*) :: clen
6+
7+
!$omp target map(clen)
8+
!$omp end target
9+
end subroutine TestCharLenBounds
10+
11+
!CHECK: %[[DUMMY:.*]] = fir.dummy_scope : !fir.dscope
12+
!CHECK: %[[UNBOX:.*]]:2 = fir.unboxchar %{{.*}} : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
13+
!CHECK: %[[DECLARE:.*]]:2 = hlfir.declare %[[UNBOX]]#0 typeparams %2#1 dummy_scope %[[DUMMY]] {uniq_name = "_QFtestcharlenboundsEclen"} : (!fir.ref<!fir.char<1,?>>, index, !fir.dscope) -> (!fir.boxchar<1>, !fir.ref<!fir.char<1,?>>)
14+
!CHECK: %[[LB_START_IDX:.*]] = arith.constant 0 : index
15+
!CHECK: %[[STRIDE:.*]] = arith.constant 1 : index
16+
!CHECK: %[[EXTENT:.*]]:2 = fir.unboxchar %[[DECLARE]]#0 : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
17+
!CHECK: %[[UB:.*]] = arith.subi %[[EXTENT]]#1, %[[STRIDE]] : index
18+
!CHECK: %[[BOUNDS:.*]] = omp.map.bounds lower_bound(%[[LB_START_IDX]] : index) upper_bound(%[[UB]] : index) extent(%[[EXTENT]]#1 : index) stride(%[[STRIDE]] : index) start_idx(%[[LB_START_IDX]] : index) {stride_in_bytes = true}
19+
!CHECK: %{{.*}} = omp.map.info {{.*}} bounds(%[[BOUNDS]]) {{.*}}

0 commit comments

Comments
 (0)