Skip to content

[OpenMP] Clang Codegen Interop : Accept multiple use & destroy clauses #83398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions clang/lib/CodeGen/CGStmtOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7042,18 +7042,28 @@ void CodeGenFunction::EmitOMPInteropDirective(const OMPInteropDirective &S) {
Device, NumDependences, DependenceList,
Data.HasNowaitClause);
}
} else if (const auto *C = S.getSingleClause<OMPDestroyClause>()) {
llvm::Value *InteropvarPtr =
EmitLValue(C->getInteropVar()).getPointer(*this);
OMPBuilder.createOMPInteropDestroy(Builder, InteropvarPtr, Device,
NumDependences, DependenceList,
Data.HasNowaitClause);
} else if (const auto *C = S.getSingleClause<OMPUseClause>()) {
llvm::Value *InteropvarPtr =
EmitLValue(C->getInteropVar()).getPointer(*this);
OMPBuilder.createOMPInteropUse(Builder, InteropvarPtr, Device,
NumDependences, DependenceList,
Data.HasNowaitClause);
}
auto ItOMPDestroyClause = S.getClausesOfKind<OMPDestroyClause>();
if (!ItOMPDestroyClause.empty()) {
// Look at the multiple destroy clauses
for (const OMPDestroyClause *C : ItOMPDestroyClause) {
llvm::Value *InteropvarPtr =
EmitLValue(C->getInteropVar()).getPointer(*this);
OMPBuilder.createOMPInteropDestroy(Builder, InteropvarPtr, Device,
NumDependences, DependenceList,
Data.HasNowaitClause);
}
}
auto ItOMPUseClause = S.getClausesOfKind<OMPUseClause>();
if (!ItOMPUseClause.empty()) {
// Look at the multiple use clauses
for (const OMPUseClause *C : ItOMPUseClause) {
llvm::Value *InteropvarPtr =
EmitLValue(C->getInteropVar()).getPointer(*this);
OMPBuilder.createOMPInteropUse(Builder, InteropvarPtr, Device,
NumDependences, DependenceList,
Data.HasNowaitClause);
}
}
}

Expand Down
22 changes: 16 additions & 6 deletions clang/test/OpenMP/interop_codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,31 @@ typedef long omp_intptr_t;
extern omp_intptr_t omp_get_interop_int(const omp_interop_t, int, int *);

int main() {
omp_interop_t obj = omp_interop_none;
omp_interop_t obj1 = omp_interop_none;
omp_interop_t obj2 = omp_interop_none;
omp_interop_t i1 = omp_interop_none;
omp_interop_t i2 = omp_interop_none;
omp_interop_t i3 = omp_interop_none;
omp_interop_t i4 = omp_interop_none;
omp_interop_t i5 = omp_interop_none;

#pragma omp interop init(targetsync: i1) init(targetsync: obj)
int id = (int )omp_get_interop_int(obj, omp_ipr_fr_id, NULL);
int id1 = (int )omp_get_interop_int(i1, omp_ipr_fr_id, NULL);
#pragma omp interop init(targetsync: obj1) init(targetsync: obj2)
int id = (int )omp_get_interop_int(obj1, omp_ipr_fr_id, NULL);
int id1 = (int )omp_get_interop_int(obj2, omp_ipr_fr_id, NULL);

#pragma omp interop init(target,targetsync: i1) use(i2) use(i3) destroy(i4) destroy(i5)
int id2 = (int )omp_get_interop_int(i1, omp_ipr_fr_id, NULL);
int id3 = (int )omp_get_interop_int(i2, omp_ipr_fr_id, NULL);


}
#endif

// CHECK-LABEL: define {{.+}}main{{.+}}
// CHECK-LABEL: define {{.+}}main{{.+}}
// CHECK: call {{.+}}__tgt_interop_init({{.+}}obj1{{.*}})
// CHECK: call {{.+}}__tgt_interop_init({{.+}}obj2{{.*}})
// CHECK: call {{.+}}__tgt_interop_init({{.+}}i1{{.*}})
// CHECK: call {{.+}}__tgt_interop_init({{.+}}obj{{.*}})
// CHECK: call {{.+}}__tgt_interop_destroy({{.+}}i4{{.*}})
// CHECK: call {{.+}}__tgt_interop_destroy({{.+}}i5{{.*}})
// CHECK: call {{.+}}__tgt_interop_use({{.+}}i2{{.*}})
// CHECK: call {{.+}}__tgt_interop_use({{.+}}i3{{.*}})