Skip to content

Commit 032d36a

Browse files
authored
[SYCL][ClangLinkerWrapper] Add -use-sycl-post-link-tool command line option to clang-linker-wrapper (#15374)
Previously clang-linker-wrapper used -sycl-module-split-mode option to decide whether to use sycl-post-link tool or not to use. This patch adds options for a explicit specifiyng usage of tool and library.
1 parent 22fbb79 commit 032d36a

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

clang/test/Driver/linker-wrapper-sycl.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
// Check sycl-module-split-mode command line option.
2727
// This option uses split library instead of sycl-post-link tool.
28-
// RUN: clang-linker-wrapper -sycl-module-split-mode=auto -sycl-device-libraries=%t.devicelib.o -sycl-post-link-options="SYCL_POST_LINK_OPTIONS" -llvm-spirv-options="LLVM_SPIRV_OPTIONS" "--host-triple=x86_64-unknown-linux-gnu" "--triple=spir64" "--linker-path=/usr/bin/ld" "--" HOST_LINKER_FLAGS "-dynamic-linker" HOST_DYN_LIB "-o" "a.out" HOST_LIB_PATH HOST_STAT_LIB %t.o --dry-run 2>&1 | FileCheck -check-prefix=CHK-SPLIT-CMDS %s
28+
// RUN: clang-linker-wrapper -no-use-sycl-post-link-tool -sycl-module-split-mode=auto -sycl-device-libraries=%t.devicelib.o -sycl-post-link-options="SYCL_POST_LINK_OPTIONS" -llvm-spirv-options="LLVM_SPIRV_OPTIONS" "--host-triple=x86_64-unknown-linux-gnu" "--triple=spir64" "--linker-path=/usr/bin/ld" "--" HOST_LINKER_FLAGS "-dynamic-linker" HOST_DYN_LIB "-o" "a.out" HOST_LIB_PATH HOST_STAT_LIB %t.o --dry-run 2>&1 | FileCheck -check-prefix=CHK-SPLIT-CMDS %s
2929
// CHK-SPLIT-CMDS: "{{.*}}spirv-to-ir-wrapper" {{.*}} -o [[FIRSTLLVMLINKIN:.*]].bc --llvm-spirv-opts --spirv-preserve-auxdata --spirv-target-env=SPV-IR --spirv-builtin-format=global
3030
// CHK-SPLIT-CMDS-NEXT: "{{.*}}llvm-link" [[FIRSTLLVMLINKIN]].bc -o [[FIRSTLLVMLINKOUT:.*]].bc --suppress-warnings
3131
// CHK-SPLIT-CMDS-NEXT: "{{.*}}llvm-link" -only-needed [[FIRSTLLVMLINKOUT]].bc {{.*}}.bc -o [[SECONDLLVMLINKOUT:.*]].bc --suppress-warnings
@@ -36,6 +36,13 @@
3636
// CHK-SPLIT-CMDS-NEXT: "{{.*}}clang"{{.*}} -c -o [[LLCOUT:.*]] [[WRAPPEROUT]].bc
3737
// CHK-SPLIT-CMDS-NEXT: "{{.*}}/ld" -- HOST_LINKER_FLAGS -dynamic-linker HOST_DYN_LIB -o a.out [[LLCOUT]] HOST_LIB_PATH HOST_STAT_LIB {{.*}}.o
3838

39+
// Check errors with -[no-]use-sycl-post-link-tool.
40+
// RUN: not clang-linker-wrapper -sycl-module-split-mode=auto -sycl-device-libraries=%t.devicelib.o -sycl-post-link-options="SYCL_POST_LINK_OPTIONS" -llvm-spirv-options="LLVM_SPIRV_OPTIONS" "--host-triple=x86_64-unknown-linux-gnu" "--triple=spir64" "--linker-path=/usr/bin/ld" "--" HOST_LINKER_FLAGS "-dynamic-linker" HOST_DYN_LIB "-o" "a.out" HOST_LIB_PATH HOST_STAT_LIB %t.o --dry-run 2>&1 | FileCheck -check-prefix=CHK-SYCL-POST-LINK-TOOL-ERROR %s
41+
// CHK-SYCL-POST-LINK-TOOL-ERROR: error: -sycl-module-split-mode should be used with the -no-use-sycl-post-link-tool command line option.
42+
43+
// RUN: not clang-linker-wrapper -use-sycl-post-link-tool -no-use-sycl-post-link-tool -sycl-module-split-mode=auto -sycl-device-libraries=%t.devicelib.o -sycl-post-link-options="SYCL_POST_LINK_OPTIONS" -llvm-spirv-options="LLVM_SPIRV_OPTIONS" "--host-triple=x86_64-unknown-linux-gnu" "--triple=spir64" "--linker-path=/usr/bin/ld" "--" HOST_LINKER_FLAGS "-dynamic-linker" HOST_DYN_LIB "-o" "a.out" HOST_LIB_PATH HOST_STAT_LIB %t.o --dry-run 2>&1 | FileCheck -check-prefix=CHK-SYCL-POST-LINK-TOOL-ERROR2 %s
44+
// CHK-SYCL-POST-LINK-TOOL-ERROR2: error: -use-sycl-post-link-tool and -no-use-sycl-post-link-tool options can't be used together.
45+
3946
/// check for PIC for device wrap compilation when using -shared
4047
// RUN: clang-linker-wrapper -sycl-device-libraries=%t.devicelib.o -sycl-post-link-options="SYCL_POST_LINK_OPTIONS" -llvm-spirv-options="LLVM_SPIRV_OPTIONS" "--host-triple=x86_64-unknown-linux-gnu" "--triple=spir64" "--linker-path=/usr/bin/ld" -shared "--" HOST_LINKER_FLAGS "-dynamic-linker" HOST_DYN_LIB "-o" "a.out" HOST_LIB_PATH HOST_STAT_LIB %t.o --dry-run 2>&1 | FileCheck -check-prefix=CHK-SHARED %s
4148
// CHK-SHARED: "{{.*}}clang"{{.*}} -fPIC

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ static std::atomic<bool> LTOError;
154154

155155
static std::optional<llvm::module_split::IRSplitMode> SYCLModuleSplitMode;
156156

157+
static bool UseSYCLPostLinkTool;
158+
157159
SmallString<128> SPIRVDumpDir;
158160

159161
using OffloadingImage = OffloadBinary::OffloadingImage;
@@ -2392,10 +2394,10 @@ Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles(
23922394
SmallVector<StringRef> InputFilesSYCL;
23932395
InputFilesSYCL.emplace_back(*TmpOutputOrErr);
23942396
auto SplitModulesOrErr =
2395-
SYCLModuleSplitMode
2396-
? sycl::runSYCLSplitLibrary(InputFilesSYCL, LinkerArgs,
2397-
*SYCLModuleSplitMode)
2398-
: sycl::runSYCLPostLinkTool(InputFilesSYCL, LinkerArgs);
2397+
UseSYCLPostLinkTool
2398+
? sycl::runSYCLPostLinkTool(InputFilesSYCL, LinkerArgs)
2399+
: sycl::runSYCLSplitLibrary(InputFilesSYCL, LinkerArgs,
2400+
*SYCLModuleSplitMode);
23992401
if (!SplitModulesOrErr)
24002402
return SplitModulesOrErr.takeError();
24012403

@@ -2961,7 +2963,19 @@ int main(int Argc, char **Argv) {
29612963
timeTraceProfilerInitialize(Granularity, Argv[0]);
29622964
}
29632965

2966+
UseSYCLPostLinkTool = Args.hasFlag(OPT_use_sycl_post_link_tool,
2967+
OPT_no_use_sycl_post_link_tool, true);
2968+
if (!UseSYCLPostLinkTool && Args.hasArg(OPT_use_sycl_post_link_tool))
2969+
reportError(createStringError("-use-sycl-post-link-tool and "
2970+
"-no-use-sycl-post-link-tool options can't "
2971+
"be used together."));
2972+
29642973
if (Args.hasArg(OPT_sycl_module_split_mode_EQ)) {
2974+
if (UseSYCLPostLinkTool)
2975+
reportError(createStringError(
2976+
"-sycl-module-split-mode should be used with "
2977+
"the -no-use-sycl-post-link-tool command line option."));
2978+
29652979
StringRef StrMode = Args.getLastArgValue(OPT_sycl_module_split_mode_EQ);
29662980
SYCLModuleSplitMode = module_split::convertStringToSplitMode(StrMode);
29672981
if (!SYCLModuleSplitMode)

clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,15 @@ def sycl_module_split_mode_EQ :
184184
Flags<[WrapperOnlyOption]>,
185185
HelpText<"Option that turns on split library with the given split mode">;
186186

187+
// TODO: Options will be removed when the sycl-post-link tool becomes removed.
188+
def use_sycl_post_link_tool : Flag<["--", "-"], "use-sycl-post-link-tool">,
189+
Flags<[WrapperOnlyOption]>,
190+
HelpText<"Use the sycl-post-link tool. On by default">;
191+
192+
def no_use_sycl_post_link_tool : Flag<["--", "-"], "no-use-sycl-post-link-tool">,
193+
Flags<[WrapperOnlyOption]>,
194+
HelpText<"Use a SYCL library instead of sycl-post-link tool. (experimental)">;
195+
187196
// Special option to pass in llvm-spirv options
188197
def llvm_spirv_options_EQ : Joined<["--", "-"], "llvm-spirv-options=">,
189198
Flags<[WrapperOnlyOption]>,

0 commit comments

Comments
 (0)