[Clang] Suppress missing architecture error when doing LTO (#100652)
Summary: The `nvlink-wrapper` can do LTO now, which means we can still create some LLVM-IR without needing an architecture. In the case that we try to invoke `nvlink` internally, that will still fail. This patch simply defers the error until later so we can use `--lto-emit-llvm` to get the IR without specifying an architecture.
This commit is contained in:
@@ -596,14 +596,16 @@ void NVPTX::Linker::ConstructJob(Compilation &C, const JobAction &JA,
|
||||
CmdArgs.push_back("-v");
|
||||
|
||||
StringRef GPUArch = Args.getLastArgValue(options::OPT_march_EQ);
|
||||
if (GPUArch.empty()) {
|
||||
if (GPUArch.empty() && !C.getDriver().isUsingLTO()) {
|
||||
C.getDriver().Diag(diag::err_drv_offload_missing_gpu_arch)
|
||||
<< getToolChain().getArchName() << getShortName();
|
||||
return;
|
||||
}
|
||||
|
||||
CmdArgs.push_back("-arch");
|
||||
CmdArgs.push_back(Args.MakeArgString(GPUArch));
|
||||
if (!GPUArch.empty()) {
|
||||
CmdArgs.push_back("-arch");
|
||||
CmdArgs.push_back(Args.MakeArgString(GPUArch));
|
||||
}
|
||||
|
||||
if (Args.hasArg(options::OPT_ptxas_path_EQ))
|
||||
CmdArgs.push_back(Args.MakeArgString(
|
||||
|
||||
@@ -84,6 +84,13 @@
|
||||
// MISSING: error: must pass in an explicit nvptx64 gpu architecture to 'ptxas'
|
||||
// MISSING: error: must pass in an explicit nvptx64 gpu architecture to 'nvlink'
|
||||
|
||||
// Do not error when performing LTO.
|
||||
//
|
||||
// RUN: %clang -target nvptx64-nvidia-cuda -flto %s -### 2>&1 \
|
||||
// RUN: | FileCheck -check-prefix=MISSING-LTO %s
|
||||
|
||||
// MISSING-LTO-NOT: error: must pass in an explicit nvptx64 gpu architecture to 'nvlink'
|
||||
|
||||
// RUN: %clang -target nvptx64-nvidia-cuda -flto -c %s -### 2>&1 \
|
||||
// RUN: | FileCheck -check-prefix=GENERIC %s
|
||||
// RUN: %clang -target nvptx64-nvidia-cuda -march=sm_52 -march=generic -flto -c %s -### 2>&1 \
|
||||
|
||||
@@ -302,6 +302,9 @@ Expected<StringRef> runPTXAs(StringRef File, const ArgList &Args) {
|
||||
findProgram(Args, "ptxas", {CudaPath + "/bin", GivenPath});
|
||||
if (!PTXAsPath)
|
||||
return PTXAsPath.takeError();
|
||||
if (!Args.hasArg(OPT_arch))
|
||||
return createStringError(
|
||||
"must pass in an explicit nvptx64 gpu architecture to 'ptxas'");
|
||||
|
||||
auto TempFileOrErr = createTempFile(
|
||||
Args, sys::path::stem(Args.getLastArgValue(OPT_o, "a.out")), "cubin");
|
||||
@@ -694,6 +697,10 @@ Error runNVLink(ArrayRef<StringRef> Files, const ArgList &Args) {
|
||||
if (!NVLinkPath)
|
||||
return NVLinkPath.takeError();
|
||||
|
||||
if (!Args.hasArg(OPT_arch))
|
||||
return createStringError(
|
||||
"must pass in an explicit nvptx64 gpu architecture to 'nvlink'");
|
||||
|
||||
ArgStringList NewLinkerArgs;
|
||||
for (const opt::Arg *Arg : Args) {
|
||||
// Do not forward arguments only intended for the linker wrapper.
|
||||
|
||||
@@ -113,7 +113,7 @@ function(add_bitcode_entrypoint_library target_name base_target_name)
|
||||
|
||||
add_executable(${target_name} ${objects})
|
||||
target_link_options(${target_name} PRIVATE
|
||||
"-r" "-nostdlib" "-flto" "-Wl,--lto-emit-llvm" "-march= ")
|
||||
"-r" "-nostdlib" "-flto" "-Wl,--lto-emit-llvm")
|
||||
endfunction(add_bitcode_entrypoint_library)
|
||||
|
||||
# A rule to build a library from a collection of entrypoint objects.
|
||||
|
||||
@@ -34,7 +34,7 @@ function(add_startup_object name)
|
||||
RUNTIME_OUTPUT_DIRECTORY ${LIBC_LIBRARY_DIR}
|
||||
RUNTIME_OUTPUT_NAME ${name}.o)
|
||||
target_link_options(${fq_target_name}.exe PRIVATE
|
||||
"-nostdlib" "-flto" "-Wl,--lto-emit-llvm" "-march= ")
|
||||
"-nostdlib" "-flto" "-Wl,--lto-emit-llvm")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user