Skip to content

Commit 93ab97e

Browse files
sndmitrievbader
authored andcommitted
[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 <serguei.n.dmitriev@intel.com>
1 parent 7daf0c0 commit 93ab97e

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
@@ -5012,9 +5012,13 @@ InputInfo Driver::BuildJobsForActionNoCache(
50125012
bool IsMSVCEnv =
50135013
C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment();
50145014
if (C.getInputArgs().hasArg(options::OPT_foffload_static_lib_EQ) &&
5015-
UI.DependentOffloadKind != Action::OFK_Host &&
5016-
((JA->getType() == types::TY_Object && !IsMSVCEnv) ||
5017-
(JA->getType() == types::TY_Archive && IsMSVCEnv))) {
5015+
((JA->getType() == types::TY_Archive && IsMSVCEnv) ||
5016+
(UI.DependentOffloadKind != Action::OFK_Host &&
5017+
(JA->getType() == types::TY_Object && !IsMSVCEnv)))) {
5018+
// Host part of the unbundled static archive is not used.
5019+
if (UI.DependentOffloadKind == Action::OFK_Host &&
5020+
JA->getType() == types::TY_Archive && IsMSVCEnv)
5021+
continue;
50185022
std::string TmpFileName =
50195023
C.getDriver().GetTemporaryPath(llvm::sys::path::stem(BaseInput),
50205024
"txt");

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6628,7 +6628,7 @@ void OffloadBundler::ConstructJobMultipleOutputs(
66286628
SmallString<128> Triples;
66296629
Triples += "-targets=";
66306630
auto DepInfo = UA.getDependentActionsInfo();
6631-
for (unsigned I = 0; I < DepInfo.size(); ++I) {
6631+
for (unsigned I = 0, J = 0; I < DepInfo.size(); ++I) {
66326632
auto &Dep = DepInfo[I];
66336633
// FPGA device triples are 'transformed' for the bundler when creating
66346634
// aocx or aocr type bundles. Also, we only do a specific target
@@ -6654,8 +6654,14 @@ void OffloadBundler::ConstructJobMultipleOutputs(
66546654
Triples += Dep.DependentToolChain->getTriple().normalize();
66556655
}
66566656
continue;
6657+
} else if (Input.getType() == types::TY_Archive) {
6658+
// Do not extract host part if we are unbundling archive on Windows
6659+
// because it is not needed. Static offload libraries are added to the
6660+
// host link command just as normal libraries.
6661+
if (Dep.DependentOffloadKind == Action::OFK_Host)
6662+
continue;
66576663
}
6658-
if (I)
6664+
if (J++)
66596665
Triples += ',';
66606666
Triples += Action::GetOffloadKindName(Dep.DependentOffloadKind);
66616667
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)