Skip to content

Commit e87a6a9

Browse files
committed
[WIP][OpenMP] Enable ATTACH-style maps for mappers.
This is a follow-up to llvm#153683. The change is experimental for now as it simply enables the `ATTACH`-style maps, and updates a few libomptarget tests. clang tests haven't been updated yet. Also, we might need to add some new "implicit" maps. It's not clear if/whether any implicit maps should be added for a list-item mapped via a mapper, either default or non-default.
1 parent 3db4fb3 commit e87a6a9

File tree

6 files changed

+29
-8
lines changed

6 files changed

+29
-8
lines changed

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9172,7 +9172,27 @@ class MappableExprsHandler {
91729172

91739173
/// Constructor for the declare mapper directive.
91749174
MappableExprsHandler(const OMPDeclareMapperDecl &Dir, CodeGenFunction &CGF)
9175-
: CurDir(&Dir), CGF(CGF), AttachPtrComparator(*this) {}
9175+
: CurDir(&Dir), CGF(CGF), AttachPtrComparator(*this) {
9176+
auto CollectAttachPtrExprsForClauseComponents = [this](const auto *C) {
9177+
for (auto L : C->component_lists()) {
9178+
OMPClauseMappableExprCommon::MappableExprComponentListRef Components =
9179+
std::get<1>(L);
9180+
if (!Components.empty())
9181+
collectAttachPtrExprInfo(Components, CurDir);
9182+
}
9183+
};
9184+
9185+
// Populate the AttachPtrExprMap for all component lists from map-related
9186+
// clauses in the declare mapper directive.
9187+
for (const auto *Cl : Dir.clauses()) {
9188+
if (const auto *C = dyn_cast<OMPMapClause>(Cl))
9189+
CollectAttachPtrExprsForClauseComponents(C);
9190+
else if (const auto *C = dyn_cast<OMPToClause>(Cl))
9191+
CollectAttachPtrExprsForClauseComponents(C);
9192+
else if (const auto *C = dyn_cast<OMPFromClause>(Cl))
9193+
CollectAttachPtrExprsForClauseComponents(C);
9194+
}
9195+
}
91769196

91779197
/// Generate code for the combined entry if we have a partially mapped struct
91789198
/// and take care of the mapping flags of the arguments corresponding to

offload/test/mapping/declare_mapper_nested_mappers.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ typedef struct {
77
int a;
88
double *b;
99
} C;
10-
#pragma omp declare mapper(id1 : C s) map(to : s.a) map(from : s.b[0 : 2])
10+
#pragma omp declare mapper(id1 : C s) map(to : s.a) map(alloc : s.b) \
11+
map(from : s.b[0 : 2])
1112

1213
typedef struct {
1314
int e;
@@ -16,7 +17,7 @@ typedef struct {
1617
short *g;
1718
} D;
1819
#pragma omp declare mapper(default : D r) map(from : r.e) \
19-
map(mapper(id1), tofrom : r.f) map(tofrom : r.g[0 : r.h])
20+
map(mapper(id1), tofrom : r.f) map(alloc : r.g) map(tofrom : r.g[0 : r.h])
2021

2122
int main() {
2223
constexpr int N = 10;
@@ -56,7 +57,7 @@ int main() {
5657
spp[0][0].f.b[1] = 40;
5758
spp[0][0].g[1] = 50;
5859
}
59-
printf("%d %d %d %d\n", spp00fa, spp00fb_r, spp00fg1, spp00fg_r);
60+
printf("%d %d %d %d\n", spp00fa, spp00fb_r, spp00fg1, spp00fg_r);
6061
// CHECK: 222 0 30 0
6162
printf("%d %d %4.5f %d %d %d\n", spp[0][0].e, spp[0][0].f.a, spp[0][0].f.b[1],
6263
spp[0][0].f.b == &x[0] ? 1 : 0, spp[0][0].g[1],

offload/test/mapping/declare_mapper_target.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class C {
1010
int *a;
1111
};
1212

13-
#pragma omp declare mapper(id : C s) map(s.a[0 : NUM])
13+
#pragma omp declare mapper(id : C s) map(alloc : s.a) map(s.a[0 : NUM])
1414

1515
int main() {
1616
C c;

offload/test/mapping/declare_mapper_target_data.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class C {
1010
int *a;
1111
};
1212

13-
#pragma omp declare mapper(id : C s) map(s.a[0 : NUM])
13+
#pragma omp declare mapper(id : C s) map(alloc : s.a) map(s.a[0 : NUM])
1414

1515
int main() {
1616
C c;

offload/test/mapping/declare_mapper_target_data_enter_exit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class C {
1010
int *a;
1111
};
1212

13-
#pragma omp declare mapper(id : C s) map(s.a[0 : NUM])
13+
#pragma omp declare mapper(id : C s) map(alloc : s.a) map(s.a[0 : NUM])
1414

1515
int main() {
1616
C c;

offload/test/mapping/declare_mapper_target_update.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class C {
1010
int *a;
1111
};
1212

13-
#pragma omp declare mapper(id : C s) map(s.a[0 : NUM])
13+
#pragma omp declare mapper(id : C s) map(alloc : s.a) map(s.a[0 : NUM])
1414

1515
int main() {
1616
C c;

0 commit comments

Comments
 (0)