Skip to content

[Driver] Let all offload builders add inputs to host link job action #2919

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
Dec 22, 2020
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
12 changes: 5 additions & 7 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4780,7 +4780,7 @@ class OffloadingActionBuilder final {
return false;
}

Action* makeHostLinkAction() {
void makeHostLinkAction(ActionList &LinkerInputs) {
// Build a list of device linking actions.
ActionList DeviceAL;
for (DeviceActionBuilder *SB : SpecializedBuilders) {
Expand All @@ -4790,16 +4790,15 @@ class OffloadingActionBuilder final {
}

if (DeviceAL.empty())
return nullptr;
return;

// Let builders add host linking actions.
Action* HA;
for (DeviceActionBuilder *SB : SpecializedBuilders) {
if (!SB->isValid())
continue;
HA = SB->appendLinkHostActions(DeviceAL);
if (Action *HA = SB->appendLinkHostActions(DeviceAL))
LinkerInputs.push_back(HA);
}
return HA;
}

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

// Add a link action if necessary.
if (!LinkerInputs.empty()) {
if (Action *Wrapper = OffloadBuilder.makeHostLinkAction())
LinkerInputs.push_back(Wrapper);
OffloadBuilder.makeHostLinkAction(LinkerInputs);
types::ID LinkType(types::TY_Image);
if (Args.hasArg(options::OPT_fsycl_link_EQ))
LinkType = types::TY_Archive;
Expand Down
14 changes: 14 additions & 0 deletions clang/test/Driver/openmp-sycl-interop.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// Check that OpenMP and SYCL device binaries are wrapped and linked to the host
/// image when program uses both OpenMP and SYCL offloading models.

// REQUIRES: clang-driver
// REQUIRES: x86-registered-target

// RUN: touch %t.o
// RUN: %clang --target=x86_64-host-linux-gnu -fsycl -fopenmp -fopenmp-targets=x86_64-device-linux-gnu -### %t.o 2>&1 \
// RUN: | FileCheck %s
// CHECK: clang-offload-wrapper{{(.exe)?}}" {{.*}}"-o=[[SYCLBC:.+\.bc]]" {{.*}}"-target=spir64" "-kind=sycl"
// CHECK: llc{{.*}}" {{.*}}"-o" "[[SYCLOBJ:.+]]" "[[SYCLBC]]"
// CHECK: clang-offload-wrapper{{(.exe)?}}" {{.*}}"-o" "[[OMPBC:.*\.bc]]" {{.*}}"-kind=openmp" "-target=x86_64-device-linux-gnu"
// CHECK: clang{{.*}}" {{.*}}"-o" "[[OMPOBJ:.+]]" "-x" "ir" "[[OMPBC]]"
// CHECK: ld{{.*}}" "[[OMPOBJ]]" "[[SYCLOBJ]]"