Skip to content

Commit eb89f5e

Browse files
authored
[Driver] Let all offload builders add inputs to host link job action (#2919)
This patch fixes a problem with loosing OpenMP device binary when program uses both OpenMP and SYCL offloading models. Signed-off-by: Sergey Dmitriev <serguei.n.dmitriev@intel.com>
1 parent 0a61228 commit eb89f5e

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4779,7 +4779,7 @@ class OffloadingActionBuilder final {
47794779
return false;
47804780
}
47814781

4782-
Action* makeHostLinkAction() {
4782+
void makeHostLinkAction(ActionList &LinkerInputs) {
47834783
// Build a list of device linking actions.
47844784
ActionList DeviceAL;
47854785
for (DeviceActionBuilder *SB : SpecializedBuilders) {
@@ -4789,16 +4789,15 @@ class OffloadingActionBuilder final {
47894789
}
47904790

47914791
if (DeviceAL.empty())
4792-
return nullptr;
4792+
return;
47934793

47944794
// Let builders add host linking actions.
4795-
Action* HA;
47964795
for (DeviceActionBuilder *SB : SpecializedBuilders) {
47974796
if (!SB->isValid())
47984797
continue;
4799-
HA = SB->appendLinkHostActions(DeviceAL);
4798+
if (Action *HA = SB->appendLinkHostActions(DeviceAL))
4799+
LinkerInputs.push_back(HA);
48004800
}
4801-
return HA;
48024801
}
48034802

48044803
/// Processes the host linker action. This currently consists of replacing it
@@ -5183,8 +5182,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
51835182

51845183
// Add a link action if necessary.
51855184
if (!LinkerInputs.empty()) {
5186-
if (Action *Wrapper = OffloadBuilder.makeHostLinkAction())
5187-
LinkerInputs.push_back(Wrapper);
5185+
OffloadBuilder.makeHostLinkAction(LinkerInputs);
51885186
types::ID LinkType(types::TY_Image);
51895187
if (Args.hasArg(options::OPT_fsycl_link_EQ))
51905188
LinkType = types::TY_Archive;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// Check that OpenMP and SYCL device binaries are wrapped and linked to the host
2+
/// image when program uses both OpenMP and SYCL offloading models.
3+
4+
// REQUIRES: clang-driver
5+
// REQUIRES: x86-registered-target
6+
7+
// RUN: touch %t.o
8+
// RUN: %clang --target=x86_64-host-linux-gnu -fsycl -fopenmp -fopenmp-targets=x86_64-device-linux-gnu -### %t.o 2>&1 \
9+
// RUN: | FileCheck %s
10+
// CHECK: clang-offload-wrapper{{(.exe)?}}" {{.*}}"-o=[[SYCLBC:.+\.bc]]" {{.*}}"-target=spir64" "-kind=sycl"
11+
// CHECK: llc{{.*}}" {{.*}}"-o" "[[SYCLOBJ:.+]]" "[[SYCLBC]]"
12+
// CHECK: clang-offload-wrapper{{(.exe)?}}" {{.*}}"-o" "[[OMPBC:.*\.bc]]" {{.*}}"-kind=openmp" "-target=x86_64-device-linux-gnu"
13+
// CHECK: clang{{.*}}" {{.*}}"-o" "[[OMPOBJ:.+]]" "-x" "ir" "[[OMPBC]]"
14+
// CHECK: ld{{.*}}" "[[OMPOBJ]]" "[[SYCLOBJ]]"

0 commit comments

Comments
 (0)