[PATCH] D45783: [DEBUGINFO, NVPTX] Render `-no-cuda-debug` LLVM option when required.
Alexey Bataev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 18 11:43:20 PDT 2018
ABataev created this revision.
ABataev added reviewers: tra, jlebar, echristo.
Herald added a subscriber: JDevlieghere.
When emission of the lineinfo is requested for the NVPTX, render the
LLVM `-no-cuda-debug` option to disable emission of the `debug` option
in the `.target` directive. Required for the correct work of the ptxas
tool, which does not allow emission of the optimized code in presence of
the `debug` option.
Repository:
rC Clang
https://reviews.llvm.org/D45783
Files:
lib/Driver/ToolChains/Cuda.cpp
test/Driver/cuda-dwarf-2.cu
test/Driver/openmp-offload-gpu.c
Index: test/Driver/openmp-offload-gpu.c
===================================================================
--- test/Driver/openmp-offload-gpu.c
+++ test/Driver/openmp-offload-gpu.c
@@ -182,6 +182,8 @@
// RUN: %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -ggdb1 -O2 --cuda-noopt-device-debug 2>&1 \
// RUN: | FileCheck -check-prefix=NO_DEBUG -check-prefix=LINE_TABLE %s
+// LINE_TABLE: "-triple" "nvptx64-nvidia-cuda"
+// LINE_TABLE-SAME: "-mllvm" "-no-cuda-debug"
// NO_DEBUG: ptxas
// LINE_TABLE: "-lineinfo"
// NO_DEBUG-NOT: "-g"
Index: test/Driver/cuda-dwarf-2.cu
===================================================================
--- test/Driver/cuda-dwarf-2.cu
+++ test/Driver/cuda-dwarf-2.cu
@@ -15,6 +15,8 @@
// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 %s -gline-tables-only -O2 --cuda-noopt-device-debug 2>&1 | \
// RUN: FileCheck %s -check-prefix NO_DEBUG -check-prefix LINE_TABLE
+// LINE_TABLE: "-triple" "nvptx64-nvidia-cuda"
+// LINE_TABLE-SAME: "-mllvm" "-no-cuda-debug"
// NO_DEBUG: ptxas
// NO_DEBUG-NOT: "-g"
// LINE_TABLE: "-lineinfo"
Index: lib/Driver/ToolChains/Cuda.cpp
===================================================================
--- lib/Driver/ToolChains/Cuda.cpp
+++ lib/Driver/ToolChains/Cuda.cpp
@@ -283,23 +283,26 @@
} // anonymous namespace
static DebugInfoKind mustEmitDebugInfo(const ArgList &Args) {
- Arg *A = Args.getLastArg(options::OPT_O_Group);
- if (Args.hasFlag(options::OPT_cuda_noopt_device_debug,
- options::OPT_no_cuda_noopt_device_debug,
- !A || A->getOption().matches(options::OPT_O0))) {
- if (const Arg *A = Args.getLastArg(options::OPT_g_Group)) {
- const Option &Opt = A->getOption();
- if (Opt.matches(options::OPT_gN_Group)) {
- if (Opt.matches(options::OPT_g0) || Opt.matches(options::OPT_ggdb0))
- return NoDebug;
- if (Opt.matches(options::OPT_gline_tables_only) ||
- Opt.matches(options::OPT_ggdb1))
- return LineTableOnly;
- }
- return FullDebug;
+ const Arg *OptArg = Args.getLastArg(options::OPT_O_Group);
+ DebugInfoKind DIKind = NoDebug;
+ if (const Arg *DebugArg = Args.getLastArg(options::OPT_g_Group)) {
+ DIKind = FullDebug;
+ const Option &Opt = DebugArg->getOption();
+ if (Opt.matches(options::OPT_gN_Group)) {
+ if (Opt.matches(options::OPT_g0) || Opt.matches(options::OPT_ggdb0))
+ DIKind = NoDebug;
+ else if (Opt.matches(options::OPT_gline_tables_only) ||
+ Opt.matches(options::OPT_ggdb1))
+ DIKind = LineTableOnly;
}
}
- return NoDebug;
+ if (Args.hasFlag(options::OPT_cuda_noopt_device_debug,
+ options::OPT_no_cuda_noopt_device_debug,
+ !OptArg || OptArg->getOption().matches(options::OPT_O0)))
+ return DIKind;
+ // If --no-cuda-noopt-device-debug is provided and O>0 and debug info
+ // requested - generate lineinfo.
+ return DIKind == NoDebug ? NoDebug : LineTableOnly;
}
void NVPTX::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
@@ -634,6 +637,13 @@
CC1Args.push_back("+ptx42");
}
+ // Disable emission of the `debug` option in the `.target` if the lineinfo is
+ // requested.
+ if (mustEmitDebugInfo(DriverArgs) == LineTableOnly) {
+ CC1Args.push_back("-mllvm");
+ CC1Args.push_back("-no-cuda-debug");
+ }
+
if (DeviceOffloadingKind == Action::OFK_OpenMP) {
SmallVector<StringRef, 8> LibraryPaths;
// Add path to lib and/or lib64 folders.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45783.142976.patch
Type: text/x-patch
Size: 3606 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180418/613b1add/attachment.bin>
More information about the cfe-commits
mailing list