-
Notifications
You must be signed in to change notification settings - Fork 798
[NewOffloadModel] Remove compiler backend option and linker option to be passed as argument for ClangLinkerWrapper #20691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: sycl
Are you sure you want to change the base?
Changes from 8 commits
2ee12b0
1488454
da1c270
0452eb7
71c475b
2993152
7d0ee38
e88a3fb
f4730f1
2f11978
fe390ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5232,7 +5232,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, | |
| (JA.isHostOffloading(C.getActiveOffloadKinds()) && | ||
| Args.hasFlag(options::OPT_offload_new_driver, | ||
| options::OPT_no_offload_new_driver, | ||
| C.isOffloadingHostKind(Action::OFK_Cuda))); | ||
| C.isOffloadingHostKind(Action::OFK_Cuda))) || | ||
| (JA.isHostOffloading(Action::OFK_SYCL) && | ||
| C.getDriver().GetUseNewOffloadDriverForSYCLOffload(C, Args)); | ||
|
|
||
| bool IsRDCMode = | ||
| Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, IsSYCL); | ||
|
|
@@ -11245,14 +11247,16 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA, | |
| if (Kind == Action::OFK_OpenMP && !Args.hasArg(OPT_no_offloadlib) && | ||
| (TC->getTriple().isAMDGPU() || TC->getTriple().isNVPTX())) | ||
| LinkerArgs.emplace_back("-lompdevice"); | ||
|
|
||
| // Forward all of these to the appropriate toolchain. | ||
| for (StringRef Arg : CompilerArgs) | ||
| CmdArgs.push_back(Args.MakeArgString( | ||
| "--device-compiler=" + TC->getTripleString() + "=" + Arg)); | ||
| for (StringRef Arg : LinkerArgs) | ||
| CmdArgs.push_back(Args.MakeArgString( | ||
| "--device-linker=" + TC->getTripleString() + "=" + Arg)); | ||
| if (!C.hasOffloadToolChain<Action::OFK_SYCL>()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to avoid this SYCL-specific customization? What happens if we keep this for SYCL as well?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where does |
||
| for (StringRef Arg : CompilerArgs) | ||
| CmdArgs.push_back(Args.MakeArgString( | ||
| "--device-compiler=" + TC->getTripleString() + "=" + Arg)); | ||
| for (StringRef Arg : LinkerArgs) | ||
| CmdArgs.push_back(Args.MakeArgString( | ||
| "--device-linker=" + TC->getTripleString() + "=" + Arg)); | ||
| } | ||
|
|
||
| // Forward the LTO mode relying on the Driver's parsing. | ||
| if (C.getDriver().getOffloadLTOMode() == LTOK_Full) | ||
|
|
@@ -11458,57 +11462,27 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA, | |
| CmdArgs.push_back( | ||
| Args.MakeArgString("-sycl-allow-device-image-dependencies")); | ||
|
|
||
| // Formulate and add any offload-wrapper and AOT specific options. These | ||
| // are additional options passed in via -Xsycl-target-linker and | ||
| // -Xsycl-target-backend. | ||
| // For AOT, pass along backend target args via --device-compiler options | ||
| // to the clang-linker-wrapper. | ||
| const toolchains::SYCLToolChain &SYCLTC = | ||
| static_cast<const toolchains::SYCLToolChain &>(getToolChain()); | ||
| // Only store compile/link opts in the image descriptor for the SPIR-V | ||
| // target. For AOT, pass along the addition options via GPU or CPU | ||
| // specific clang-linker-wrapper options. | ||
| const ArgList &Args = | ||
| C.getArgsForToolChain(nullptr, StringRef(), Action::OFK_SYCL); | ||
| for (auto &ToolChainMember : | ||
| llvm::make_range(ToolChainRange.first, ToolChainRange.second)) { | ||
| const ToolChain *TC = ToolChainMember.second; | ||
| bool IsJIT = false; | ||
| StringRef WrapperOption; | ||
| StringRef WrapperLinkOption; | ||
| if (TC->getTriple().isSPIROrSPIRV()) { | ||
| if (TC->getTriple().getSubArch() == llvm::Triple::NoSubArch) { | ||
| IsJIT = true; | ||
| WrapperOption = "--sycl-backend-compile-options="; | ||
| } | ||
| if (TC->getTriple().getSubArch() == llvm::Triple::SPIRSubArch_gen) | ||
| WrapperOption = "--gpu-tool-arg="; | ||
| if (TC->getTriple().getSubArch() == llvm::Triple::SPIRSubArch_x86_64) | ||
| WrapperOption = "--cpu-tool-arg="; | ||
| } else | ||
| continue; | ||
| ArgStringList BuildArgs; | ||
| SmallString<128> BackendOptString; | ||
| SmallString<128> LinkOptString; | ||
| SYCLTC.TranslateBackendTargetArgs(TC->getTriple(), Args, BuildArgs); | ||
| for (const auto &A : BuildArgs) | ||
| appendOption(BackendOptString, A); | ||
|
|
||
| BuildArgs.clear(); | ||
| SYCLTC.TranslateLinkerTargetArgs(TC->getTriple(), Args, BuildArgs); | ||
| for (const auto &A : BuildArgs) { | ||
| if (IsJIT) | ||
| appendOption(LinkOptString, A); | ||
| else | ||
| // For AOT, combine the Backend and Linker strings into one. | ||
| SmallString<128> BackendOptString; | ||
| if (TC->getTriple().getSubArch() == llvm::Triple::SPIRSubArch_gen || (TC->getTriple().getSubArch() == llvm::Triple::SPIRSubArch_x86_64)) { | ||
| for (const auto &A : BuildArgs) | ||
| appendOption(BackendOptString, A); | ||
| CmdArgs.push_back(Args.MakeArgString( | ||
| "--device-compiler=" + TC->getTripleString() + "=" + BackendOptString)); | ||
| } | ||
| if (!BackendOptString.empty()) | ||
| CmdArgs.push_back( | ||
| Args.MakeArgString(Twine(WrapperOption) + BackendOptString)); | ||
| if (!LinkOptString.empty()) | ||
| CmdArgs.push_back( | ||
| Args.MakeArgString("--sycl-target-link-options=" + LinkOptString)); | ||
| } | ||
|
|
||
| // Add option to enable creating of the .syclbin file. | ||
| const ArgList &Args = | ||
| C.getArgsForToolChain(nullptr, StringRef(), Action::OFK_SYCL); | ||
| if (Arg *A = Args.getLastArg(options::OPT_fsyclbin_EQ)) | ||
| CmdArgs.push_back( | ||
| Args.MakeArgString("--syclbin=" + StringRef{A->getValue()})); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,27 +141,14 @@ | |
| // MULT_TARG_PHASES: 15: backend, {14}, assembler, (host-sycl) | ||
| // MULT_TARG_PHASES: 16: assembler, {15}, object, (host-sycl) | ||
|
|
||
| /// Test option passing behavior for clang-offload-wrapper options. | ||
| // RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --offload-new-driver \ | ||
| // RUN: -Xsycl-target-backend -backend-opt -### %s 2>&1 \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per my understanding, we still need to pass
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for pointing this out! I think for backend option and linker option that are passed at compile time, they are stored in the Only the Therefore, for this test and the one got deleted below,
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I understand how it works with your implementation. And I challenge that. Despite we extracted and put options to SYCLImage on compile stage, we still want to pass these options to link stage as well. |
||
| // RUN: | FileCheck -check-prefix WRAPPER_OPTIONS_BACKEND %s | ||
| // WRAPPER_OPTIONS_BACKEND: clang-linker-wrapper{{.*}} "--sycl-backend-compile-options={{.*}}-backend-opt{{.*}}" | ||
|
|
||
| // RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --offload-new-driver \ | ||
| // RUN: -Xsycl-target-linker -link-opt -### %s 2>&1 \ | ||
| // RUN: | FileCheck -check-prefix WRAPPER_OPTIONS_LINK %s | ||
| // WRAPPER_OPTIONS_LINK: clang-linker-wrapper{{.*}} "--sycl-target-link-options={{.*}}-link-opt{{.*}}" | ||
|
|
||
| /// Test option passing behavior for clang-offload-wrapper options for AOT. | ||
| /// Test option passing behavior for clang-offload-wrapper options for AOT | ||
| // RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --offload-new-driver \ | ||
| // RUN: -fsycl-targets=spir64_gen,spir64_x86_64 \ | ||
| // RUN: -Xsycl-target-backend=spir64_gen -backend-gen-opt \ | ||
| // RUN: -Xsycl-target-backend=spir64_x86_64 -backend-cpu-opt \ | ||
| // RUN: -### %s 2>&1 \ | ||
| // RUN: | FileCheck -check-prefix WRAPPER_OPTIONS_BACKEND_AOT %s | ||
| // WRAPPER_OPTIONS_BACKEND_AOT: clang-linker-wrapper{{.*}} "--host-triple=x86_64-unknown-linux-gnu" | ||
| // WRAPPER_OPTIONS_BACKEND_AOT-SAME: "--gpu-tool-arg=-backend-gen-opt" | ||
| // WRAPPER_OPTIONS_BACKEND_AOT-SAME: "--cpu-tool-arg=-backend-cpu-opt" | ||
| // WRAPPER_OPTIONS_BACKEND_AOT: clang-linker-wrapper{{.*}} "--host-triple=x86_64-unknown-linux-gnu" {{.*}} "--device-compiler=spir64_gen-unknown-unknown=-backend-gen-opt" "--device-compiler=spir64_x86_64-unknown-unknown=-backend-cpu-opt" | ||
|
|
||
| /// Verify arch settings for nvptx and amdgcn targets | ||
| // RUN: %clangxx -fsycl -### -fsycl-targets=amdgcn-amd-amdhsa -fno-sycl-libspirv \ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -325,11 +325,6 @@ | |
| // CHK-NO-FSYCL-TARGET-ERROR-NOT: clang{{.*}} error: cannot deduce implicit triple value for '-Xsycl-target-frontend', specify triple using '-Xsycl-target-frontend=<triple>' | ||
|
|
||
| /// ########################################################################### | ||
|
|
||
| // RUN: %clang -### -target x86_64-unknown-linux-gnu -fsycl --offload-new-driver -fsycl-targets=spir64-unknown-unknown -Xsycl-target-backend "-DFOO1 -DFOO2" %s 2>&1 \ | ||
| // RUN: | FileCheck -check-prefix=CHK-TOOLS-OPTS %s | ||
| // CHK-TOOLS-OPTS: clang-linker-wrapper{{.*}} "--sycl-backend-compile-options=-DFOO1 -DFOO2" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similar here, per my understanding, need to pass options using |
||
|
|
||
| /// Check for implied options (-g -O0) | ||
| // RUN: %clang -### -target x86_64-unknown-linux-gnu -fsycl --offload-new-driver -fsycl-targets=spir64-unknown-unknown -g -O0 -Xsycl-target-backend "-DFOO1 -DFOO2" %s 2>&1 \ | ||
| // RUN: | FileCheck -check-prefix=CHK-TOOLS-IMPLIED-OPTS %s | ||
|
|
@@ -346,10 +341,6 @@ | |
| // RUN: | FileCheck -check-prefix=CHK-TOOLS-IMPLIED-OPTS-O0 %s | ||
| // CHK-TOOLS-IMPLIED-OPTS-O0-NOT: llvm-offload-binary{{.*}} {{.*}}compile-opts={{.*}}-cl-opt-disable" | ||
|
|
||
| // RUN: %clang -### -target x86_64-unknown-linux-gnu -fsycl --offload-new-driver -fsycl-targets=spir64-unknown-unknown -Xsycl-target-linker "-DFOO1 -DFOO2" %s 2>&1 \ | ||
| // RUN: | FileCheck -check-prefix=CHK-TOOLS-OPTS2 %s | ||
| // CHK-TOOLS-OPTS2: clang-linker-wrapper{{.*}} "--sycl-target-link-options=-DFOO1 -DFOO2" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, but for device-linker |
||
|
|
||
| /// -fsycl-range-rounding settings | ||
| /// | ||
| /// // Check that driver flag is passed to cc1 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,21 +52,13 @@ | |
| // RUN: | FileCheck -check-prefix DEFAULT_LINK %s | ||
| // DEFAULT_LINK: clang-linker-wrapper{{.*}} | ||
|
|
||
| /// Passing in the default triple should allow for -Xsycl-target options, both the | ||
| /// "=<triple>" and the default spelling | ||
| // RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl --offload-new-driver -fsycl-targets=spir64 -Xsycl-target-backend=spir64 -DFOO -Xsycl-target-linker=spir64 -DFOO2 %S/Inputs/SYCL/objlin64.o 2>&1 \ | ||
| // RUN: | FileCheck -check-prefixes=SYCL_TARGET_OPT %s | ||
| // RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl --offload-new-driver -Xsycl-target-backend=spir64 -DFOO -Xsycl-target-linker=spir64 -DFOO2 %S/Inputs/SYCL/objlin64.o 2>&1 \ | ||
| // RUN: | FileCheck -check-prefixes=SYCL_TARGET_OPT %s | ||
| // SYCL_TARGET_OPT: clang-linker-wrapper{{.*}} "--sycl-backend-compile-options=-DFOO" "--sycl-target-link-options=-DFOO2" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here... |
||
|
|
||
| // RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl --offload-new-driver -fsycl-targets=spir64_x86_64 -Xsycl-target-backend -DFOO %S/Inputs/SYCL/objlin64.o 2>&1 \ | ||
| // RUN: | FileCheck -check-prefixes=SYCL_TARGET_OPT_AOT,SYCL_TARGET_OPT_CPU %s | ||
| // RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl --offload-new-driver -fsycl-targets=spir64_gen -Xsycl-target-backend -DFOO %S/Inputs/SYCL/objlin64.o 2>&1 \ | ||
| // RUN: | FileCheck -check-prefixes=SYCL_TARGET_OPT_AOT,SYCL_TARGET_OPT_GPU %s | ||
| // SYCL_TARGET_OPT_AOT-NOT: error: cannot deduce implicit triple value for '-Xsycl-target-backend' | ||
| // SYCL_TARGET_OPT_CPU: clang-linker-wrapper{{.*}} "--cpu-tool-arg=-DFOO" | ||
| // SYCL_TARGET_OPT_GPU: clang-linker-wrapper{{.*}} "--gpu-tool-arg=-DFOO" | ||
| // SYCL_TARGET_OPT_CPU: clang-linker-wrapper{{.*}} "--device-compiler=spir64_x86_64-unknown-unknown=-DFOO" | ||
| // SYCL_TARGET_OPT_GPU: clang-linker-wrapper{{.*}} "--device-compiler=spir64_gen-unknown-unknown=-DFOO" | ||
|
|
||
| /// Check -fsycl-targets=spir64 enables addition of -ffine-grained-bitfield-accesses option | ||
| // RUN: %clangxx -### -fsycl-device-only --offload-new-driver %s 2>&1 | FileCheck -check-prefixes=CHECK_BITFIELD_OPTION %s | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -716,7 +716,7 @@ getTripleBasedSYCLPostLinkOpts(const ArgList &Args, | |
| /// code and will be parsed to generate options required to be passed into the | ||
| /// sycl-post-link tool. | ||
| static Expected<std::vector<module_split::SplitModule>> | ||
| runSYCLPostLinkTool(ArrayRef<StringRef> InputFiles, const ArgList &Args) { | ||
| runSYCLPostLinkTool(ArrayRef<StringRef> InputFiles, const ArgList &Args, bool HasGPUTool) { | ||
| Expected<std::string> SYCLPostLinkPath = | ||
| findProgram("sycl-post-link", {getMainExecutable("sycl-post-link")}); | ||
| if (!SYCLPostLinkPath) | ||
|
|
@@ -731,14 +731,13 @@ runSYCLPostLinkTool(ArrayRef<StringRef> InputFiles, const ArgList &Args) { | |
|
|
||
| // Enable the driver to invoke sycl-post-link with the device architecture | ||
| // when Intel GPU targets are passed in -fsycl-targets. | ||
| // OPT_gpu_tool_arg_EQ is checked to ensure the device architecture is not | ||
| // HasGPUTool is checked to ensure the device architecture is not | ||
| // passed through -Xsycl-target-backend=spir64_gen "-device <arch>" format | ||
| const llvm::Triple Triple(Args.getLastArgValue(OPT_triple_EQ)); | ||
| StringRef Arch = Args.getLastArgValue(OPT_arch_EQ); | ||
| StringRef IsGPUTool = Args.getLastArgValue(OPT_gpu_tool_arg_EQ); | ||
|
|
||
| if (Triple.getSubArch() == llvm::Triple::SPIRSubArch_gen && !Arch.empty() && | ||
| IsGPUTool.empty() && Arch != "*") | ||
| !HasGPUTool && Arch != "*") | ||
| OutputPathWithArch = "intel_gpu_" + Arch.str() + "," + OutputPathWithArch; | ||
| else if (Triple.getSubArch() == llvm::Triple::SPIRSubArch_x86_64) | ||
| OutputPathWithArch = "spir64_x86_64," + OutputPathWithArch; | ||
|
|
@@ -982,10 +981,6 @@ static void addSYCLBackendOptions(const ArgList &Args, | |
| CmdArgs.push_back(Args.MakeArgString(JoinedOptions)); | ||
| } | ||
| } | ||
|
|
||
| StringRef OptTool = (IsCPU) ? Args.getLastArgValue(OPT_cpu_tool_arg_EQ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Args parameter is not used anymore in this function and can be removed.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or maybe we need to handle
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the suggestion! The reason I didn't move the handling of Therefore, to avoid processing
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, now I see that order of options did not change. So, I guess, just remove the |
||
| : Args.getLastArgValue(OPT_gpu_tool_arg_EQ); | ||
| OptTool.split(CmdArgs, " ", /*MaxSplit=*/-1, /*KeepEmpty=*/false); | ||
| return; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this return is also unnecessary, right? |
||
| } | ||
|
|
||
|
|
@@ -2222,6 +2217,15 @@ linkAndWrapDeviceFiles(ArrayRef<SmallVector<OffloadFile>> LinkerInputFiles, | |
| extractSYCLCompileLinkOptions(Input); | ||
| if (!CompileLinkOptionsOrErr) | ||
| return CompileLinkOptionsOrErr.takeError(); | ||
|
|
||
| // Append any additional backend compiler options specified at link time. | ||
| const llvm::Triple Triple(LinkerArgs.getLastArgValue(OPT_triple_EQ)); | ||
YuriPlyakhin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| for (StringRef Arg : LinkerArgs.getAllArgValues(OPT_device_compiler_args_EQ)) { | ||
| auto [ArgTriple, ArgValue] = Arg.split('='); | ||
| if (ArgTriple == Triple.getTriple() && !ArgValue.empty()) { | ||
| CompileLinkOptionsOrErr->first += Twine(" ", ArgValue).str(); | ||
| } | ||
| } | ||
|
|
||
| SmallVector<StringRef> InputFiles; | ||
| // Write device inputs to an output file for the linker. | ||
|
|
@@ -2238,16 +2242,19 @@ linkAndWrapDeviceFiles(ArrayRef<SmallVector<OffloadFile>> LinkerInputFiles, | |
| return TmpOutputOrErr.takeError(); | ||
| SmallVector<StringRef> InputFilesSYCL; | ||
| InputFilesSYCL.emplace_back(*TmpOutputOrErr); | ||
|
|
||
| SmallVector<StringRef, 16> Args; | ||
| StringRef(CompileLinkOptionsOrErr->first).split(Args, ' '); | ||
| bool HasGPUTool = std::find(Args.begin(), Args.end(), "-device") != Args.end(); | ||
YixingZhang007 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| auto SplitModulesOrErr = | ||
| UseSYCLPostLinkTool | ||
| ? sycl::runSYCLPostLinkTool(InputFilesSYCL, LinkerArgs) | ||
| ? sycl::runSYCLPostLinkTool(InputFilesSYCL, LinkerArgs, HasGPUTool) | ||
| : sycl::runSYCLSplitLibrary(InputFilesSYCL, LinkerArgs, | ||
| *SYCLModuleSplitMode); | ||
| if (!SplitModulesOrErr) | ||
| return SplitModulesOrErr.takeError(); | ||
|
|
||
| auto &SplitModules = *SplitModulesOrErr; | ||
| const llvm::Triple Triple(LinkerArgs.getLastArgValue(OPT_triple_EQ)); | ||
| bool IsJIT = Triple.isSPIROrSPIRV() && | ||
| Triple.getSubArch() == llvm::Triple::NoSubArch; | ||
| if ((Triple.isNVPTX() || Triple.isAMDGCN()) && | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.