Skip to content

Commit a4be53c

Browse files
committed
Re-add missing non-contiguous hanlding code, update target update tests.
1 parent e5d22be commit a4be53c

File tree

3 files changed

+253
-212
lines changed

3 files changed

+253
-212
lines changed

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 61 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8616,42 +8616,70 @@ class MappableExprsHandler {
86168616
/// struct S {
86178617
/// int a;
86188618
/// int b[10];
8619+
/// int c[10][10];
86198620
/// int *p;
8621+
/// int **pp;
86208622
/// }
8621-
/// S s, *ps, **pps, *(pas[10]);
8623+
/// S s, *ps, **pps, *(pas[10]), ***ppps;
8624+
/// int i;
86228625
/// ```
86238626
/// The base-pointers for the following map operands would be:
8624-
/// map list-item | attach base-pointer
8625-
/// ----------------|---------------------
8626-
/// s | N/A
8627-
/// s.a | N/A
8628-
/// s.p | N/A
8629-
/// ps | N/A
8630-
/// ps->p | ps
8631-
/// ps[1] | ps
8632-
/// *(ps + 1) | ps
8633-
/// (ps + 1)[1] | ps
8634-
/// ps[1:10] | ps
8635-
/// ps->b[10] | ps
8636-
/// ps->p[10] | ps->p
8637-
/// pps[1][2] | pps[1]
8638-
/// pps[1:1][2] | pps[1:1]
8639-
/// pps[1]->p | pps[1]
8640-
/// pps[1]->p[10] | pps[1]
8641-
/// pas[1] | N/A
8642-
/// pas[1][2] | pas[1]
8627+
/// map list-item | attach base-pointer | attach base-pointer
8628+
/// | for directives except | target_update (if
8629+
/// | target_update | different)
8630+
/// ----------------|-----------------------|---------------------
8631+
/// s | N/A |
8632+
/// s.a | N/A |
8633+
/// s.p | N/A |
8634+
/// ps | N/A |
8635+
/// ps->p | ps |
8636+
/// ps[1] | ps |
8637+
/// *(ps + 1) | ps |
8638+
/// (ps + 1)[1] | ps |
8639+
/// ps[1:10] | ps |
8640+
/// ps->b[10] | ps |
8641+
/// ps->p[10] | ps->p |
8642+
/// ps->c[1][2] | ps |
8643+
/// ps->c[1:2][2] | (error diagnostic) | N/A, TODO: ps
8644+
/// ps->c[1:1][2] | ps | N/A, TODO: ps
8645+
/// pps[1][2] | pps[1] |
8646+
/// pps[1:1][2] | pps[1:1] | N/A, TODO: pps[1:1]
8647+
/// pps[1:i][2] | pps[1:i] | N/A, TODO: pps[1:i]
8648+
/// pps[1:2][2] | (error diagnostic) | N/A
8649+
/// pps[1]->p | pps[1] |
8650+
/// pps[1]->p[10] | pps[1] |
8651+
/// pas[1] | N/A |
8652+
/// pas[1][2] | pas[1] |
8653+
/// ppps[1][2] | ppps[1] |
8654+
/// ppps[1][2][3] | ppps[1][2] |
8655+
/// ppps[1][2:1][3] | ppps[1][2:1] | N/A, TODO: ppps[1][2:1]
8656+
/// ppps[1][2:2][3] | (error diagnostic) | N/A
86438657
/// Returns a pair of the attach pointer expression and its depth in the
86448658
/// component list.
86458659
/// TODO: This may need to be updated to handle ref_ptr/ptee cases for byref
86468660
/// map operands.
8661+
/// TODO: Handle cases for target-update, where the list-item is a
8662+
/// non-contiguous array-section that still has a base-pointer.
86478663
static std::pair<const Expr *, std::optional<size_t>> findAttachPtrExpr(
8648-
OMPClauseMappableExprCommon::MappableExprComponentListRef Components) {
8664+
OMPClauseMappableExprCommon::MappableExprComponentListRef Components,
8665+
llvm::PointerUnion<const OMPExecutableDirective *,
8666+
const OMPDeclareMapperDecl *>
8667+
CurDir) {
86498668

86508669
// If we only have a single component, we have a map like "map(p)", which
86518670
// cannot have a base-pointer.
86528671
if (Components.size() < 2)
86538672
return {nullptr, std::nullopt};
86548673

8674+
// Only check for non-contiguous sections on target_update,
8675+
// since we can assume array-sections are contiguous on maps on other
8676+
// constructs.
8677+
if (Components.back().isNonContiguous() &&
8678+
isa<const OMPExecutableDirective *>(CurDir) &&
8679+
isa<OMPTargetUpdateDirective>(
8680+
cast<const OMPExecutableDirective *>(CurDir)))
8681+
return {nullptr, std::nullopt};
8682+
86558683
// To find the attach base-pointer, we start with the second component,
86568684
// stripping away one component at a time, until we reach a pointer Expr
86578685
// (that is not a binary operator). The first such pointer should be the
@@ -9107,13 +9135,20 @@ class MappableExprsHandler {
91079135
}
91089136
}
91099137

9138+
// Unify entries in one list making sure the struct mapping precedes the
9139+
// individual fields:
9140+
MapCombinedInfoTy GroupUnionCurInfo;
9141+
GroupUnionCurInfo.append(GroupStructBaseCurInfo);
9142+
GroupUnionCurInfo.append(GroupCurInfo);
9143+
91109144
// If there is an entry in PartialStruct it means we have a struct with
91119145
// individual members mapped. Emit an extra combined entry.
91129146
MapCombinedInfoTy AttachCombinedInfo;
91139147
if (PartialStruct.Base.isValid()) {
9114-
CurInfo.append(PartialStruct.PreliminaryMapData);
9148+
GroupUnionCurInfo.NonContigInfo.Dims.push_back(0);
91159149
std::optional<size_t> CombinedEntryIndex = emitCombinedEntry(
9116-
CurInfo, AttachCombinedInfo, GroupCurInfo.Types, PartialStruct,
9150+
CurInfo, AttachCombinedInfo, GroupUnionCurInfo.Types,
9151+
PartialStruct,
91179152
/*IsMapThis*/ !VD, OMPBuilder, VD,
91189153
/*OffsetForMemberOfFlag=*/CombinedInfo.BasePointers.size(),
91199154
/*NotTargetParam=*/true);
@@ -9125,10 +9160,8 @@ class MappableExprsHandler {
91259160
}
91269161

91279162
// Append this group's results to the overall CurInfo in the correct
9128-
// order: combined-entry -> individual-field-entries -> attach-entry
9129-
// First append struct base info, then component info
9130-
CurInfo.append(GroupStructBaseCurInfo);
9131-
CurInfo.append(GroupCurInfo);
9163+
// order: combined-entry -> original-field-entries -> attach-entry
9164+
CurInfo.append(GroupUnionCurInfo);
91329165
CurInfo.append(AttachCombinedInfo);
91339166

91349167
IsFirstGroup = false;
@@ -9250,7 +9283,7 @@ class MappableExprsHandler {
92509283
OMPClauseMappableExprCommon::MappableExprComponentListRef Components =
92519284
std::get<1>(L);
92529285
if (!Components.empty()) {
9253-
auto [AttachPtrExpr, Depth] = findAttachPtrExpr(Components);
9286+
auto [AttachPtrExpr, Depth] = findAttachPtrExpr(Components, CurDir);
92549287
AttachPtrExprMap[Components] = AttachPtrExpr;
92559288
AttachPtrComponentDepthMap[AttachPtrExpr] = Depth;
92569289
}

0 commit comments

Comments
 (0)