From 93ab97e907ce046ac4dd8e15c179531b4c71b1e2 Mon Sep 17 00:00:00 2001 From: Sergey Dmitriev Date: Fri, 20 Sep 2019 15:00:45 -0700 Subject: [PATCH] [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 --- clang/lib/Driver/Driver.cpp | 10 +++++++--- clang/lib/Driver/ToolChains/Clang.cpp | 10 ++++++++-- clang/test/Driver/sycl-offload-win.c | 10 +++++----- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 85743417ccfe0..6ae43153d5dd8 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -5012,9 +5012,13 @@ InputInfo Driver::BuildJobsForActionNoCache( bool IsMSVCEnv = C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment(); if (C.getInputArgs().hasArg(options::OPT_foffload_static_lib_EQ) && - UI.DependentOffloadKind != Action::OFK_Host && - ((JA->getType() == types::TY_Object && !IsMSVCEnv) || - (JA->getType() == types::TY_Archive && IsMSVCEnv))) { + ((JA->getType() == types::TY_Archive && IsMSVCEnv) || + (UI.DependentOffloadKind != Action::OFK_Host && + (JA->getType() == types::TY_Object && !IsMSVCEnv)))) { + // Host part of the unbundled static archive is not used. + if (UI.DependentOffloadKind == Action::OFK_Host && + JA->getType() == types::TY_Archive && IsMSVCEnv) + continue; std::string TmpFileName = C.getDriver().GetTemporaryPath(llvm::sys::path::stem(BaseInput), "txt"); diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index ca9a3579dfc6c..1d40f4e01ba4a 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -6628,7 +6628,7 @@ void OffloadBundler::ConstructJobMultipleOutputs( SmallString<128> Triples; Triples += "-targets="; auto DepInfo = UA.getDependentActionsInfo(); - for (unsigned I = 0; I < DepInfo.size(); ++I) { + for (unsigned I = 0, J = 0; I < DepInfo.size(); ++I) { auto &Dep = DepInfo[I]; // FPGA device triples are 'transformed' for the bundler when creating // aocx or aocr type bundles. Also, we only do a specific target @@ -6654,8 +6654,14 @@ void OffloadBundler::ConstructJobMultipleOutputs( Triples += Dep.DependentToolChain->getTriple().normalize(); } continue; + } else if (Input.getType() == types::TY_Archive) { + // Do not extract host part if we are unbundling archive on Windows + // because it is not needed. Static offload libraries are added to the + // host link command just as normal libraries. + if (Dep.DependentOffloadKind == Action::OFK_Host) + continue; } - if (I) + if (J++) Triples += ','; Triples += Action::GetOffloadKindName(Dep.DependentOffloadKind); Triples += '-'; diff --git a/clang/test/Driver/sycl-offload-win.c b/clang/test/Driver/sycl-offload-win.c index e681bc48c1ce4..6a5cb8cb7af53 100644 --- a/clang/test/Driver/sycl-offload-win.c +++ b/clang/test/Driver/sycl-offload-win.c @@ -13,7 +13,7 @@ // RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl -foffload-static-lib=%t.lib %t.obj -### 2>&1 \ // RUN: | FileCheck -DOBJ=%t.obj -DLIB=%t.lib %s -check-prefix=FOFFLOAD_STATIC_LIB // FOFFLOAD_STATIC_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=o"{{.+}} "-inputs=[[OBJ]]"{{.+}} "-unbundle" -// FOFFLOAD_STATIC_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=aoo"{{.+}} "-inputs=[[LIB]]"{{.+}} "-unbundle" +// FOFFLOAD_STATIC_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=aoo" "-targets=sycl-spir64-{{.+}}-sycldevice" "-inputs=[[LIB]]"{{.+}} "-unbundle" // FOFFLOAD_STATIC_LIB: llvm-link{{(.exe)?}}{{.*}} "@{{.*}}" // FOFFLOAD_STATIC_LIB: link{{(.exe)?}}{{.+}} "-defaultlib:[[LIB]]" @@ -31,7 +31,7 @@ // FOFFLOAD_STATIC_LIB_MULTI_O: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=o"{{.+}} "-inputs=[[OBJ1]]"{{.+}} "-unbundle" // FOFFLOAD_STATIC_LIB_MULTI_O: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=o"{{.+}} "-inputs=[[OBJ2]]"{{.+}} "-unbundle" // FOFFLOAD_STATIC_LIB_MULTI_O: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=o"{{.+}} "-inputs=[[OBJ3]]"{{.+}} "-unbundle" -// FOFFLOAD_STATIC_LIB_MULTI_O: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=aoo"{{.+}} "-inputs=[[LIB]]"{{.+}} "-unbundle" +// FOFFLOAD_STATIC_LIB_MULTI_O: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=aoo" "-targets=sycl-spir64-{{.+}}-sycldevice" "-inputs=[[LIB]]"{{.+}} "-unbundle" // FOFFLOAD_STATIC_LIB_MULTI_O: llvm-link{{(.exe)?}}{{.*}} "@{{.*}}" // FOFFLOAD_STATIC_LIB_MULTI_O: link{{(.exe)?}}{{.+}} "-defaultlib:[[LIB]]" @@ -46,8 +46,8 @@ // RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl -foffload-static-lib=%t1.lib -foffload-static-lib=%t2.lib %t.obj -### 2>&1 \ // RUN: | FileCheck -DOBJ=%t.obj -DLIB1=%t1.lib -DLIB2=%t2.lib %s -check-prefix=FOFFLOAD_STATIC_MULTI_LIB // FOFFLOAD_STATIC_MULTI_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=o"{{.+}} "-inputs=[[OBJ]]"{{.+}} "-unbundle" -// FOFFLOAD_STATIC_MULTI_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=aoo"{{.+}} "-inputs=[[LIB1]]"{{.+}} "-unbundle" -// FOFFLOAD_STATIC_MULTI_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=aoo"{{.+}} "-inputs=[[LIB2]]"{{.+}} "-unbundle" +// FOFFLOAD_STATIC_MULTI_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=aoo" "-targets=sycl-spir64-{{.+}}-sycldevice" "-inputs=[[LIB1]]"{{.+}} "-unbundle" +// FOFFLOAD_STATIC_MULTI_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=aoo" "-targets=sycl-spir64-{{.+}}-sycldevice" "-inputs=[[LIB2]]"{{.+}} "-unbundle" // FOFFLOAD_STATIC_MULTI_LIB: llvm-link{{(.exe)?}}{{.*}} "@{{.*}}" "@{{.*}}" // FOFFLOAD_STATIC_MULTI_LIB: link{{(.exe)?}}{{.+}} "-defaultlib:[[LIB1]]" "-defaultlib:[[LIB2]]" @@ -85,7 +85,7 @@ // RUN: | FileCheck -DLIB=%t.lib %s -check-prefix=FOFFLOAD_STATIC_LIB_SRC2 // RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl -foffload-static-lib=%t.lib %s -### 2>&1 \ // RUN: | FileCheck -DLIB=%t.lib %s -check-prefix=FOFFLOAD_STATIC_LIB_SRC2 -// FOFFLOAD_STATIC_LIB_SRC2: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=aoo"{{.+}} "-inputs=[[LIB]]"{{.+}} "-unbundle" +// FOFFLOAD_STATIC_LIB_SRC2: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=aoo" "-targets=sycl-spir64-{{.+}}-sycldevice" "-inputs=[[LIB]]"{{.+}} "-unbundle" // FOFFLOAD_STATIC_LIB_SRC2: llvm-link{{(.exe)?}}{{.*}} "@{{.*}}" // FOFFLOAD_STATIC_LIB_SRC2: link{{(.exe)?}}{{.+}} "-defaultlib:[[LIB]]"