Skip to content

Commit d1d1eb2

Browse files
authored
[Driver][SYCL] Differentiate host dependency link from regular host link (#4002)
When performing DPC++ compilation with static archives, there is additional work performed that gathers the host dependency information so we can determine what device code should be pulled in. Add an additional type that will allow us to make heads or tails over which link step is being performed. This is needed to be able to override any user /link [arg] input that the user may specify for MSVC compilations. We do not want to honor the -out:* information there during the host dependency link phase, as it will override our expected output file designation.
1 parent d5958eb commit d1d1eb2

File tree

10 files changed

+27
-10
lines changed

10 files changed

+27
-10
lines changed

clang/include/clang/Driver/Types.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,5 @@ TYPE("fpga_aocr_emu", FPGA_AOCR_EMU, INVALID, "aocr", phases
114114
TYPE("fpga_aoco", FPGA_AOCO, INVALID, "aoco", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
115115
TYPE("fpga_dep", FPGA_Dependencies, INVALID, "d", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
116116
TYPE("fpga_dep_list", FPGA_Dependencies_List, INVALID, "txt", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
117+
TYPE("host_dep_image", Host_Dependencies_Image, INVALID, "out", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
117118
TYPE("none", Nothing, INVALID, nullptr, phases::Compile, phases::Backend, phases::Assemble, phases::Link)

clang/lib/Driver/Driver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5015,7 +5015,8 @@ class OffloadingActionBuilder final {
50155015
/// they can add it to the device linker inputs.
50165016
void addDeviceLinkDependenciesFromHost(ActionList &LinkerInputs) {
50175017
// Link image for reading dependencies from it.
5018-
auto *LA = C.MakeAction<LinkJobAction>(LinkerInputs, types::TY_Image);
5018+
auto *LA = C.MakeAction<LinkJobAction>(LinkerInputs,
5019+
types::TY_Host_Dependencies_Image);
50195020

50205021
// Calculate all the offload kinds used in the current compilation.
50215022
unsigned ActiveOffloadKinds = 0u;

clang/lib/Driver/ToolChains/MSVC.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,14 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
571571

572572
Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
573573

574+
// A user can add the -out: option to the /link sequence on the command line
575+
// which we do not want to use when we are performing the host link when
576+
// gathering dependencies used for device compilation. Add an additional
577+
// -out: to override in case it was seen.
578+
if (JA.getType() == types::TY_Host_Dependencies_Image && Output.isFilename())
579+
CmdArgs.push_back(
580+
Args.MakeArgString(std::string("-out:") + Output.getFilename()));
581+
574582
// Control Flow Guard checks
575583
if (Arg *A = Args.getLastArg(options::OPT__SLASH_guard)) {
576584
StringRef GuardArgs = A->getValue();

clang/test/Driver/sycl-intelfpga-aoco-win.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// CHK-FPGA-AOCO-PHASES-WIN: 10: backend, {9}, assembler, (host-sycl)
2525
// CHK-FPGA-AOCO-PHASES-WIN: 11: assembler, {10}, object, (host-sycl)
2626
// CHK-FPGA-AOCO-PHASES-WIN: 12: linker, {0, 11}, image, (host-sycl)
27-
// CHK-FPGA-AOCO-PHASES-WIN: 13: linker, {0, 11}, image, (host-sycl)
27+
// CHK-FPGA-AOCO-PHASES-WIN: 13: linker, {0, 11}, host_dep_image, (host-sycl)
2828
// CHK-FPGA-AOCO-PHASES-WIN: 14: clang-offload-deps, {13}, ir, (host-sycl)
2929
// CHK-FPGA-AOCO-PHASES-WIN: 15: input, "[[INPUTA]]", archive
3030
// CHK-FPGA-AOCO-PHASES-WIN: 16: clang-offload-unbundler, {15}, archive

clang/test/Driver/sycl-intelfpga-aoco.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
// CHK-FPGA-AOCO-PHASES: 10: backend, {9}, assembler, (host-sycl)
2929
// CHK-FPGA-AOCO-PHASES: 11: assembler, {10}, object, (host-sycl)
3030
// CHK-FPGA-AOCO-PHASES: 12: linker, {0, 11}, image, (host-sycl)
31-
// CHK-FPGA-AOCO-PHASES: 13: linker, {0, 11}, image, (host-sycl)
31+
// CHK-FPGA-AOCO-PHASES: 13: linker, {0, 11}, host_dep_image, (host-sycl)
3232
// CHK-FPGA-AOCO-PHASES: 14: clang-offload-deps, {13}, ir, (host-sycl)
3333
// CHK-FPGA-AOCO-PHASES: 15: input, "[[INPUTA]]", archive
3434
// CHK-FPGA-AOCO-PHASES: 16: clang-offload-unbundler, {15}, archive
@@ -61,7 +61,7 @@
6161
// CHK-FPGA-AOCO-PHASES-WIN: 10: backend, {9}, assembler, (host-sycl)
6262
// CHK-FPGA-AOCO-PHASES-WIN: 11: assembler, {10}, object, (host-sycl)
6363
// CHK-FPGA-AOCO-PHASES-WIN: 12: linker, {0, 11}, image, (host-sycl)
64-
// CHK-FPGA-AOCO-PHASES-WIN: 13: linker, {0, 11}, image, (host-sycl)
64+
// CHK-FPGA-AOCO-PHASES-WIN: 13: linker, {0, 11}, host_dep_image, (host-sycl)
6565
// CHK-FPGA-AOCO-PHASES-WIN: 14: clang-offload-deps, {13}, ir, (host-sycl)
6666
// CHK-FPGA-AOCO-PHASES-WIN: 15: input, "[[INPUTA]]", archive
6767
// CHK-FPGA-AOCO-PHASES-WIN: 16: clang-offload-unbundler, {15}, archive

clang/test/Driver/sycl-intelfpga-static-lib-win.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// RUN: | FileCheck -check-prefix=CHECK_PHASES %s
1616
// CHECK_PHASES: 0: input, "[[INPUT:.+\.lib]]", object, (host-sycl)
1717
// CHECK_PHASES: 1: linker, {0}, image, (host-sycl)
18-
// CHECK_PHASES: 2: linker, {0}, image, (host-sycl)
18+
// CHECK_PHASES: 2: linker, {0}, host_dep_image, (host-sycl)
1919
// CHECK_PHASES: 3: clang-offload-deps, {2}, ir, (host-sycl)
2020
// CHECK_PHASES: 4: input, "[[INPUT]]", archive
2121
// CHECK_PHASES: 5: clang-offload-unbundler, {4}, archive

clang/test/Driver/sycl-intelfpga-static-lib.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// RUN: | FileCheck -check-prefix=CHECK_PHASES %s
1515
// CHECK_PHASES: 0: input, "[[INPUT:.+\.a]]", object, (host-sycl)
1616
// CHECK_PHASES: 1: linker, {0}, image, (host-sycl)
17-
// CHECK_PHASES: 2: linker, {0}, image, (host-sycl)
17+
// CHECK_PHASES: 2: linker, {0}, host_dep_image, (host-sycl)
1818
// CHECK_PHASES: 3: clang-offload-deps, {2}, ir, (host-sycl)
1919
// CHECK_PHASES: 4: input, "[[INPUT]]", archive
2020
// CHECK_PHASES: 5: clang-offload-unbundler, {4}, archive

clang/test/Driver/sycl-offload-static-lib-2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
// STATIC_LIB_SRC: 10: backend, {9}, assembler, (host-sycl)
6161
// STATIC_LIB_SRC: 11: assembler, {10}, object, (host-sycl)
6262
// STATIC_LIB_SRC: 12: linker, {0, 11}, image, (host-sycl)
63-
// STATIC_LIB_SRC: 13: linker, {0, 11}, image, (host-sycl)
63+
// STATIC_LIB_SRC: 13: linker, {0, 11}, host_dep_image, (host-sycl)
6464
// STATIC_LIB_SRC: 14: clang-offload-deps, {13}, ir, (host-sycl)
6565
// STATIC_LIB_SRC: 15: input, "[[INPUTA]]", archive
6666
// STATIC_LIB_SRC: 16: clang-offload-unbundler, {15}, archive

clang/test/Driver/sycl-offload-static-lib.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
// FOFFLOAD_STATIC_LIB_SRC: 10: backend, {9}, assembler, (host-sycl)
6565
// FOFFLOAD_STATIC_LIB_SRC: 11: assembler, {10}, object, (host-sycl)
6666
// FOFFLOAD_STATIC_LIB_SRC: 12: linker, {0, 11}, image, (host-sycl)
67-
// FOFFLOAD_STATIC_LIB_SRC: 13: linker, {0, 11}, image, (host-sycl)
67+
// FOFFLOAD_STATIC_LIB_SRC: 13: linker, {0, 11}, host_dep_image, (host-sycl)
6868
// FOFFLOAD_STATIC_LIB_SRC: 14: clang-offload-deps, {13}, ir, (host-sycl)
6969
// FOFFLOAD_STATIC_LIB_SRC: 15: input, "[[INPUTA]]", archive
7070
// FOFFLOAD_STATIC_LIB_SRC: 16: clang-offload-unbundler, {15}, archive
@@ -133,7 +133,7 @@
133133
// RUN: | FileCheck %s -check-prefix=FOFFLOAD_STATIC_LIB_NOSRC_PHASES
134134
// FOFFLOAD_STATIC_LIB_NOSRC_PHASES: 0: input, "[[INPUTA:.+\.a]]", object, (host-sycl)
135135
// FOFFLOAD_STATIC_LIB_NOSRC_PHASES: 1: linker, {0}, image, (host-sycl)
136-
// FOFFLOAD_STATIC_LIB_NOSRC_PHASES: 2: linker, {0}, image, (host-sycl)
136+
// FOFFLOAD_STATIC_LIB_NOSRC_PHASES: 2: linker, {0}, host_dep_image, (host-sycl)
137137
// FOFFLOAD_STATIC_LIB_NOSRC_PHASES: 3: clang-offload-deps, {2}, ir, (host-sycl)
138138
// FOFFLOAD_STATIC_LIB_NOSRC_PHASES: 4: input, "[[INPUTA]]", archive
139139
// FOFFLOAD_STATIC_LIB_NOSRC_PHASES: 5: clang-offload-unbundler, {4}, archive

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
// FOFFLOAD_STATIC_LIB_SRC: 10: backend, {9}, assembler, (host-sycl)
7575
// FOFFLOAD_STATIC_LIB_SRC: 11: assembler, {10}, object, (host-sycl)
7676
// FOFFLOAD_STATIC_LIB_SRC: 12: linker, {0, 11}, image, (host-sycl)
77-
// FOFFLOAD_STATIC_LIB_SRC: 13: linker, {0, 11}, image, (host-sycl)
77+
// FOFFLOAD_STATIC_LIB_SRC: 13: linker, {0, 11}, host_dep_image, (host-sycl)
7878
// FOFFLOAD_STATIC_LIB_SRC: 14: clang-offload-deps, {13}, ir, (host-sycl)
7979
// FOFFLOAD_STATIC_LIB_SRC: 15: input, "[[INPUTLIB]]", archive
8080
// FOFFLOAD_STATIC_LIB_SRC: 16: clang-offload-unbundler, {15}, archive
@@ -103,3 +103,10 @@
103103
// FSYCL_P: clang{{.*}} "-cc1" "-triple" "x86_64-pc-windows-msvc{{.*}}" {{.*}} "-E" {{.*}} "-o" "[[HOSTPP:.+\.ii]]"
104104
// FSYCL_P: clang-offload-bundler{{.*}} "-type=ii" "-targets=sycl-spir64-unknown-unknown-sycldevice,host-x86_64-pc-windows-msvc" {{.*}} "-inputs=[[DEVICEPP]],[[HOSTPP]]"
105105

106+
// RUN: touch %t-orig.lib
107+
// RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl %t-orig.lib %s -### /link -out:force_out_file 2>&1 \
108+
// RUN: | FileCheck %s -check-prefix=HOSTDEP_LINK_OVERRIDE
109+
// HOSTDEP_LINK_OVERRIDE: link{{.*}} "-out:[[HOSTDEP_LINK_OUT:.+\.out]]"{{.*}} "-out:force_out_file" "-out:[[HOSTDEP_LINK_OUT]]"
110+
// HOSTDEP_LINK_OVERRIDE: clang-offload-deps{{.*}}
111+
// HOSTDEP_LINK_OVERRIDE: link{{.*}} "-out:[[LINK_OUT:.+\.exe]]"{{.*}} "-out:force_out_file"
112+
// HOSTDEP_LINK_OVERRIDE-NOT: "-out:[[LINK_OUT]]"

0 commit comments

Comments
 (0)