Skip to content

Commit 41dbf07

Browse files
committed
[SYCL] Do not extract host part when unbundling static libraries on Windows
Host output from unbundling action is not really used because static offload libraries are added to the host link command as normal libraries. Signed-off-by: Sergey Dmitriev <[email protected]>
1 parent 97f8a03 commit 41dbf07

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4986,9 +4986,13 @@ InputInfo Driver::BuildJobsForActionNoCache(
49864986
bool IsMSVCEnv =
49874987
C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment();
49884988
if (C.getInputArgs().hasArg(options::OPT_foffload_static_lib_EQ) &&
4989-
UI.DependentOffloadKind != Action::OFK_Host &&
4990-
((JA->getType() == types::TY_Object && !IsMSVCEnv) ||
4991-
(JA->getType() == types::TY_Archive && IsMSVCEnv))) {
4989+
((JA->getType() == types::TY_Archive && IsMSVCEnv) ||
4990+
(UI.DependentOffloadKind != Action::OFK_Host &&
4991+
(JA->getType() == types::TY_Object && !IsMSVCEnv)))) {
4992+
// Host part of the unbundled static archive is not used.
4993+
if (UI.DependentOffloadKind == Action::OFK_Host &&
4994+
JA->getType() == types::TY_Archive && IsMSVCEnv)
4995+
continue;
49924996
std::string TmpFileName =
49934997
C.getDriver().GetTemporaryPath(llvm::sys::path::stem(BaseInput),
49944998
"txt");

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6517,7 +6517,7 @@ void OffloadBundler::ConstructJobMultipleOutputs(
65176517
SmallString<128> Triples;
65186518
Triples += "-targets=";
65196519
auto DepInfo = UA.getDependentActionsInfo();
6520-
for (unsigned I = 0; I < DepInfo.size(); ++I) {
6520+
for (unsigned I = 0, J = 0; I < DepInfo.size(); ++I) {
65216521
auto &Dep = DepInfo[I];
65226522
// FPGA device triples are 'transformed' for the bundler when creating
65236523
// aocx or aocr type bundles. Also, we only do a specific target
@@ -6543,8 +6543,14 @@ void OffloadBundler::ConstructJobMultipleOutputs(
65436543
Triples += Dep.DependentToolChain->getTriple().normalize();
65446544
}
65456545
continue;
6546+
} else if (Input.getType() == types::TY_Archive) {
6547+
// Do not extract host part if we are unbundling archive on Windows
6548+
// because it is not needed. Static offload libraries are added to the
6549+
// host link command just as normal libraries.
6550+
if (Dep.DependentOffloadKind == Action::OFK_Host)
6551+
continue;
65466552
}
6547-
if (I)
6553+
if (J++)
65486554
Triples += ',';
65496555
Triples += Action::GetOffloadKindName(Dep.DependentOffloadKind);
65506556
Triples += '-';

clang/test/Driver/sycl-offload-win.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl -foffload-static-lib=%t.lib %t.obj -### 2>&1 \
1414
// RUN: | FileCheck -DOBJ=%t.obj -DLIB=%t.lib %s -check-prefix=FOFFLOAD_STATIC_LIB
1515
// FOFFLOAD_STATIC_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=o"{{.+}} "-inputs=[[OBJ]]"{{.+}} "-unbundle"
16-
// FOFFLOAD_STATIC_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=aoo"{{.+}} "-inputs=[[LIB]]"{{.+}} "-unbundle"
16+
// FOFFLOAD_STATIC_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=aoo" "-targets=sycl-spir64-{{.+}}-sycldevice" "-inputs=[[LIB]]"{{.+}} "-unbundle"
1717
// FOFFLOAD_STATIC_LIB: llvm-link{{(.exe)?}}{{.*}} "@{{.*}}"
1818
// FOFFLOAD_STATIC_LIB: link{{(.exe)?}}{{.+}} "-defaultlib:[[LIB]]"
1919

@@ -31,7 +31,7 @@
3131
// FOFFLOAD_STATIC_LIB_MULTI_O: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=o"{{.+}} "-inputs=[[OBJ1]]"{{.+}} "-unbundle"
3232
// FOFFLOAD_STATIC_LIB_MULTI_O: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=o"{{.+}} "-inputs=[[OBJ2]]"{{.+}} "-unbundle"
3333
// FOFFLOAD_STATIC_LIB_MULTI_O: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=o"{{.+}} "-inputs=[[OBJ3]]"{{.+}} "-unbundle"
34-
// FOFFLOAD_STATIC_LIB_MULTI_O: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=aoo"{{.+}} "-inputs=[[LIB]]"{{.+}} "-unbundle"
34+
// FOFFLOAD_STATIC_LIB_MULTI_O: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=aoo" "-targets=sycl-spir64-{{.+}}-sycldevice" "-inputs=[[LIB]]"{{.+}} "-unbundle"
3535
// FOFFLOAD_STATIC_LIB_MULTI_O: llvm-link{{(.exe)?}}{{.*}} "@{{.*}}"
3636
// FOFFLOAD_STATIC_LIB_MULTI_O: link{{(.exe)?}}{{.+}} "-defaultlib:[[LIB]]"
3737

@@ -46,8 +46,8 @@
4646
// RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl -foffload-static-lib=%t1.lib -foffload-static-lib=%t2.lib %t.obj -### 2>&1 \
4747
// RUN: | FileCheck -DOBJ=%t.obj -DLIB1=%t1.lib -DLIB2=%t2.lib %s -check-prefix=FOFFLOAD_STATIC_MULTI_LIB
4848
// FOFFLOAD_STATIC_MULTI_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=o"{{.+}} "-inputs=[[OBJ]]"{{.+}} "-unbundle"
49-
// FOFFLOAD_STATIC_MULTI_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=aoo"{{.+}} "-inputs=[[LIB1]]"{{.+}} "-unbundle"
50-
// FOFFLOAD_STATIC_MULTI_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=aoo"{{.+}} "-inputs=[[LIB2]]"{{.+}} "-unbundle"
49+
// FOFFLOAD_STATIC_MULTI_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=aoo" "-targets=sycl-spir64-{{.+}}-sycldevice" "-inputs=[[LIB1]]"{{.+}} "-unbundle"
50+
// FOFFLOAD_STATIC_MULTI_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=aoo" "-targets=sycl-spir64-{{.+}}-sycldevice" "-inputs=[[LIB2]]"{{.+}} "-unbundle"
5151
// FOFFLOAD_STATIC_MULTI_LIB: llvm-link{{(.exe)?}}{{.*}} "@{{.*}}" "@{{.*}}"
5252
// FOFFLOAD_STATIC_MULTI_LIB: link{{(.exe)?}}{{.+}} "-defaultlib:[[LIB1]]" "-defaultlib:[[LIB2]]"
5353

@@ -85,7 +85,7 @@
8585
// RUN: | FileCheck -DLIB=%t.lib %s -check-prefix=FOFFLOAD_STATIC_LIB_SRC2
8686
// RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl -foffload-static-lib=%t.lib %s -### 2>&1 \
8787
// RUN: | FileCheck -DLIB=%t.lib %s -check-prefix=FOFFLOAD_STATIC_LIB_SRC2
88-
// FOFFLOAD_STATIC_LIB_SRC2: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=aoo"{{.+}} "-inputs=[[LIB]]"{{.+}} "-unbundle"
88+
// FOFFLOAD_STATIC_LIB_SRC2: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=aoo" "-targets=sycl-spir64-{{.+}}-sycldevice" "-inputs=[[LIB]]"{{.+}} "-unbundle"
8989
// FOFFLOAD_STATIC_LIB_SRC2: llvm-link{{(.exe)?}}{{.*}} "@{{.*}}"
9090
// FOFFLOAD_STATIC_LIB_SRC2: link{{(.exe)?}}{{.+}} "-defaultlib:[[LIB]]"
9191

0 commit comments

Comments
 (0)