Skip to content

Commit 54777c0

Browse files
authored
[Driver][SYCL] Fix issue using -fsycl-force-target with offload dependencies (#7025)
When using performing offloading with archives, an additional clang-offload-deps step is taken that determines the device dependencies during the link. When using -fsycl-force-target, we need to be sure that the target in which the dependency information is associated with matches so the proper device objects are referenced and pulled out.
1 parent c44a84a commit 54777c0

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9407,9 +9407,19 @@ void OffloadDeps::constructJob(Compilation &C, const JobAction &JA,
94079407
Targets += ',';
94089408
Targets += Action::GetOffloadKindName(Dep.DependentOffloadKind);
94099409
Targets += '-';
9410-
std::string NormalizedTriple =
9411-
Dep.DependentToolChain->getTriple().normalize();
9412-
Targets += NormalizedTriple;
9410+
// When -fsycl-force-target is used, this value overrides the expected
9411+
// output type we are creating deps for.
9412+
if (Dep.DependentOffloadKind == Action::OFK_SYCL &&
9413+
TCArgs.hasArg(options::OPT_fsycl_force_target_EQ)) {
9414+
StringRef Val(
9415+
TCArgs.getLastArg(options::OPT_fsycl_force_target_EQ)->getValue());
9416+
llvm::Triple TT(C.getDriver().MakeSYCLDeviceTriple(Val));
9417+
Targets += TT.normalize();
9418+
} else {
9419+
std::string NormalizedTriple =
9420+
Dep.DependentToolChain->getTriple().normalize();
9421+
Targets += NormalizedTriple;
9422+
}
94139423
if ((Dep.DependentOffloadKind == Action::OFK_HIP ||
94149424
Dep.DependentOffloadKind == Action::OFK_SYCL) &&
94159425
!Dep.DependentBoundArch.empty()) {

clang/test/Driver/sycl-force-target.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@
2121
// CHECK_FORCE_TARGET_GEN: llvm-foreach{{.*}} {{.*}}ocloc{{.*}}
2222
// CHECK_FORCE_TARGET_CPU: llvm-foreach{{.*}} {{.*}}opencl-aot{{.*}}
2323

24+
/// Verify the usage of -fsycl-force-target applies to all expected unbundlings
25+
/// and also applies to clang-offload-deps step
26+
// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen -fsycl-force-target=spir64 \
27+
// RUN: -target x86_64-unknown-linux-gnu -fno-sycl-device-lib=all \
28+
// RUN: %s %S/Inputs/SYCL/liblin64.a -### 2>&1 \
29+
// RUN: | FileCheck %s -check-prefix=CHECK_FORCE_TARGET_ARCHIVE
30+
// CHECK_FORCE_TARGET_ARCHIVE: clang-offload-deps{{.*}} "-targets=sycl-spir64-unknown-unknown" "-outputs={{.*}}"
31+
// CHECK_FORCE_TARGET_ARCHIVE: clang-offload-bundler{{.*}} "-type=aoo" "-targets=sycl-spir64-unknown-unknown" "-input={{.*}}liblin64.a" "-output=[[DEVICELISTOUT:.+]]" "-unbundle" "-allow-missing-bundles"
32+
// CHECK_FORCE_TARGET_ARCHIVE: spirv-to-ir-wrapper{{.*}} "[[DEVICELISTOUT]]" "-o" "[[DEVICELISTBC:.+\.txt]]"
33+
// CHECK_FORCE_TARGET_ARCHIVE: llvm-link{{.*}} "@[[DEVICELISTBC]]"{{.*}} "-o" "[[DEVICEARCHIVELINKED:.+\.bc]]" "--suppress-warnings"
34+
// CHECK_FORCE_TARGET_ARCHIVE: llvm-foreach{{.*}} {{.*}}ocloc{{.*}}
35+
2436
/// -fsycl-force-target is only valid with -fsycl-target with single targets
2537
// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen,spir64_x86_64 \
2638
// RUN: -fsycl-force-target=spir64 %s -### 2>&1 \

0 commit comments

Comments
 (0)