forked from OSchip/llvm-project
[NVPTX] Emit debug info in DWARF-2 by default for Cuda devices.
Summary: NVPTX target supports debug info in DWARF-2 format. Patch adds emission of debug info in DWARF-2 by default. Reviewers: tra, jlebar Subscribers: aprantl, JDevlieghere, cfe-commits Differential Revision: https://reviews.llvm.org/D42581 llvm-svn: 330272
This commit is contained in:
parent
242706b8d1
commit
e36c67b35c
|
@ -273,6 +273,35 @@ void CudaInstallationDetector::print(raw_ostream &OS) const {
|
||||||
<< CudaVersionToString(Version) << "\n";
|
<< CudaVersionToString(Version) << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
/// Debug info kind.
|
||||||
|
enum DebugInfoKind {
|
||||||
|
NoDebug, /// No debug info.
|
||||||
|
LineTableOnly, /// Line tables only.
|
||||||
|
FullDebug /// Full debug info.
|
||||||
|
};
|
||||||
|
} // 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NoDebug;
|
||||||
|
}
|
||||||
|
|
||||||
void NVPTX::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
|
void NVPTX::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
|
||||||
const InputInfo &Output,
|
const InputInfo &Output,
|
||||||
const InputInfoList &Inputs,
|
const InputInfoList &Inputs,
|
||||||
|
@ -304,8 +333,8 @@ void NVPTX::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
|
||||||
|
|
||||||
ArgStringList CmdArgs;
|
ArgStringList CmdArgs;
|
||||||
CmdArgs.push_back(TC.getTriple().isArch64Bit() ? "-m64" : "-m32");
|
CmdArgs.push_back(TC.getTriple().isArch64Bit() ? "-m64" : "-m32");
|
||||||
if (Args.hasFlag(options::OPT_cuda_noopt_device_debug,
|
DebugInfoKind DIKind = mustEmitDebugInfo(Args);
|
||||||
options::OPT_no_cuda_noopt_device_debug, false)) {
|
if (DIKind == FullDebug) {
|
||||||
// ptxas does not accept -g option if optimization is enabled, so
|
// ptxas does not accept -g option if optimization is enabled, so
|
||||||
// we ignore the compiler's -O* options if we want debug info.
|
// we ignore the compiler's -O* options if we want debug info.
|
||||||
CmdArgs.push_back("-g");
|
CmdArgs.push_back("-g");
|
||||||
|
@ -341,6 +370,8 @@ void NVPTX::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
|
||||||
// to no optimizations, but ptxas's default is -O3.
|
// to no optimizations, but ptxas's default is -O3.
|
||||||
CmdArgs.push_back("-O0");
|
CmdArgs.push_back("-O0");
|
||||||
}
|
}
|
||||||
|
if (DIKind == LineTableOnly)
|
||||||
|
CmdArgs.push_back("-lineinfo");
|
||||||
|
|
||||||
// Pass -v to ptxas if it was passed to the driver.
|
// Pass -v to ptxas if it was passed to the driver.
|
||||||
if (Args.hasArg(options::OPT_v))
|
if (Args.hasArg(options::OPT_v))
|
||||||
|
@ -410,6 +441,8 @@ void NVPTX::Linker::ConstructJob(Compilation &C, const JobAction &JA,
|
||||||
CmdArgs.push_back(TC.getTriple().isArch64Bit() ? "-64" : "-32");
|
CmdArgs.push_back(TC.getTriple().isArch64Bit() ? "-64" : "-32");
|
||||||
CmdArgs.push_back(Args.MakeArgString("--create"));
|
CmdArgs.push_back(Args.MakeArgString("--create"));
|
||||||
CmdArgs.push_back(Args.MakeArgString(Output.getFilename()));
|
CmdArgs.push_back(Args.MakeArgString(Output.getFilename()));
|
||||||
|
if (mustEmitDebugInfo(Args) == FullDebug)
|
||||||
|
CmdArgs.push_back("-g");
|
||||||
|
|
||||||
for (const auto& II : Inputs) {
|
for (const auto& II : Inputs) {
|
||||||
auto *A = II.getAction();
|
auto *A = II.getAction();
|
||||||
|
@ -461,7 +494,7 @@ void NVPTX::OpenMPLinker::ConstructJob(Compilation &C, const JobAction &JA,
|
||||||
CmdArgs.push_back(Output.getFilename());
|
CmdArgs.push_back(Output.getFilename());
|
||||||
} else
|
} else
|
||||||
assert(Output.isNothing() && "Invalid output.");
|
assert(Output.isNothing() && "Invalid output.");
|
||||||
if (Args.hasArg(options::OPT_g_Flag))
|
if (mustEmitDebugInfo(Args) == FullDebug)
|
||||||
CmdArgs.push_back("-g");
|
CmdArgs.push_back("-g");
|
||||||
|
|
||||||
if (Args.hasArg(options::OPT_v))
|
if (Args.hasArg(options::OPT_v))
|
||||||
|
|
|
@ -180,6 +180,8 @@ public:
|
||||||
computeMSVCVersion(const Driver *D,
|
computeMSVCVersion(const Driver *D,
|
||||||
const llvm::opt::ArgList &Args) const override;
|
const llvm::opt::ArgList &Args) const override;
|
||||||
|
|
||||||
|
unsigned GetDefaultDwarfVersion() const override { return 2; }
|
||||||
|
|
||||||
const ToolChain &HostTC;
|
const ToolChain &HostTC;
|
||||||
CudaInstallationDetector CudaInstallation;
|
CudaInstallationDetector CudaInstallation;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
// REQUIRES: clang-driver
|
||||||
|
//
|
||||||
|
// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 %s -g -O0 --no-cuda-noopt-device-debug 2>&1 | \
|
||||||
|
// RUN: FileCheck %s -check-prefix NO_DEBUG
|
||||||
|
// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 %s -g -O3 2>&1 | \
|
||||||
|
// RUN: FileCheck %s -check-prefix NO_DEBUG
|
||||||
|
// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 %s -g -O3 --no-cuda-noopt-device-debug 2>&1 | \
|
||||||
|
// RUN: FileCheck %s -check-prefix NO_DEBUG
|
||||||
|
// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 %s -g0 2>&1 | \
|
||||||
|
// RUN: FileCheck %s -check-prefix NO_DEBUG
|
||||||
|
// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 %s -ggdb0 -O3 --cuda-noopt-device-debug 2>&1 | \
|
||||||
|
// RUN: FileCheck %s -check-prefix NO_DEBUG
|
||||||
|
// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 %s -ggdb1 2>&1 | \
|
||||||
|
// RUN: FileCheck %s -check-prefix NO_DEBUG -check-prefix LINE_TABLE
|
||||||
|
// 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
|
||||||
|
|
||||||
|
// NO_DEBUG: ptxas
|
||||||
|
// NO_DEBUG-NOT: "-g"
|
||||||
|
// LINE_TABLE: "-lineinfo"
|
||||||
|
// NO_DEBUG: fatbinary
|
||||||
|
// NO_DEBUG-NOT: "-g"
|
||||||
|
|
||||||
|
// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 %s -g 2>&1 | \
|
||||||
|
// RUN: FileCheck %s -check-prefix HAS_DEBUG
|
||||||
|
// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 %s -g -O0 --cuda-noopt-device-debug 2>&1 | \
|
||||||
|
// RUN: FileCheck %s -check-prefix HAS_DEBUG
|
||||||
|
// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 %s -g -O3 --cuda-noopt-device-debug 2>&1 | \
|
||||||
|
// RUN: FileCheck %s -check-prefix HAS_DEBUG
|
||||||
|
// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 %s -g2 2>&1 | \
|
||||||
|
// RUN: FileCheck %s -check-prefix HAS_DEBUG
|
||||||
|
// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 %s -ggdb2 -O0 2>&1 | \
|
||||||
|
// RUN: FileCheck %s -check-prefix HAS_DEBUG
|
||||||
|
// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 %s -g3 -O2 --cuda-noopt-device-debug 2>&1 | \
|
||||||
|
// RUN: FileCheck %s -check-prefix HAS_DEBUG
|
||||||
|
// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 %s -ggdb3 -O3 --cuda-noopt-device-debug 2>&1 | \
|
||||||
|
// RUN: FileCheck %s -check-prefix HAS_DEBUG
|
||||||
|
|
||||||
|
// HAS_DEBUG: "-fcuda-is-device"
|
||||||
|
// HAS_DEBUG-SAME: "-dwarf-version=2"
|
||||||
|
// HAS_DEBUG: ptxas
|
||||||
|
// HAS_DEBUG-SAME: "-g"
|
||||||
|
// HAS_DEBUG-SAME: "--dont-merge-basicblocks"
|
||||||
|
// HAS_DEBUG-SAME: "--return-at-end"
|
||||||
|
// HAS_DEBUG: fatbinary
|
||||||
|
// HAS_DEBUG-SAME: "-g"
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
// RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,RDC %s
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,RDC %s
|
||||||
|
|
||||||
// With debugging enabled, ptxas should be run with with no ptxas optimizations.
|
// With debugging enabled, ptxas should be run with with no ptxas optimizations.
|
||||||
// RUN: %clang -### -target x86_64-linux-gnu --cuda-noopt-device-debug -O2 -c %s 2>&1 \
|
// RUN: %clang -### -target x86_64-linux-gnu --cuda-noopt-device-debug -O2 -g -c %s 2>&1 \
|
||||||
// RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,DBG %s
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,DBG %s
|
||||||
|
|
||||||
// --no-cuda-noopt-device-debug overrides --cuda-noopt-device-debug.
|
// --no-cuda-noopt-device-debug overrides --cuda-noopt-device-debug.
|
||||||
|
|
|
@ -165,3 +165,51 @@
|
||||||
// RUN: | FileCheck -check-prefix=CHK-BCLIB-WARN %s
|
// RUN: | FileCheck -check-prefix=CHK-BCLIB-WARN %s
|
||||||
|
|
||||||
// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-sm_20.bc' found in the default clang lib directory or in LIBRARY_PATH. Expect degraded performance due to no inlining of runtime functions on target devices.
|
// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-sm_20.bc' found in the default clang lib directory or in LIBRARY_PATH. Expect degraded performance due to no inlining of runtime functions on target devices.
|
||||||
|
|
||||||
|
/// Check that debug info is emitted in dwarf-2
|
||||||
|
// RUN: %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O0 --no-cuda-noopt-device-debug 2>&1 \
|
||||||
|
// RUN: | FileCheck -check-prefix=NO_DEBUG %s
|
||||||
|
// RUN: %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O3 2>&1 \
|
||||||
|
// RUN: | FileCheck -check-prefix=NO_DEBUG %s
|
||||||
|
// RUN: %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O3 --no-cuda-noopt-device-debug 2>&1 \
|
||||||
|
// RUN: | FileCheck -check-prefix=NO_DEBUG %s
|
||||||
|
// RUN: %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g0 2>&1 \
|
||||||
|
// RUN: | FileCheck -check-prefix=NO_DEBUG %s
|
||||||
|
// RUN: %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -ggdb0 -O3 --cuda-noopt-device-debug 2>&1 \
|
||||||
|
// RUN: | FileCheck -check-prefix=NO_DEBUG %s
|
||||||
|
// RUN: %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -gline-tables-only 2>&1 \
|
||||||
|
// RUN: | FileCheck -check-prefix=NO_DEBUG -check-prefix=LINE_TABLE %s
|
||||||
|
// 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
|
||||||
|
|
||||||
|
// NO_DEBUG: ptxas
|
||||||
|
// LINE_TABLE: "-lineinfo"
|
||||||
|
// NO_DEBUG-NOT: "-g"
|
||||||
|
// NO_DEBUG: nvlink
|
||||||
|
// NO_DEBUG-NOT: "-g"
|
||||||
|
|
||||||
|
// RUN: %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g 2>&1 \
|
||||||
|
// RUN: | FileCheck -check-prefix=HAS_DEBUG %s
|
||||||
|
// RUN: %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O0 --cuda-noopt-device-debug 2>&1 \
|
||||||
|
// RUN: | FileCheck -check-prefix=HAS_DEBUG %s
|
||||||
|
// RUN: %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O3 --cuda-noopt-device-debug 2>&1 \
|
||||||
|
// RUN: | FileCheck -check-prefix=HAS_DEBUG %s
|
||||||
|
// RUN: %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g2 2>&1 \
|
||||||
|
// RUN: | FileCheck -check-prefix=HAS_DEBUG %s
|
||||||
|
// RUN: %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -ggdb2 -O0 --cuda-noopt-device-debug 2>&1 \
|
||||||
|
// RUN: | FileCheck -check-prefix=HAS_DEBUG %s
|
||||||
|
// RUN: %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g3 -O3 --cuda-noopt-device-debug 2>&1 \
|
||||||
|
// RUN: | FileCheck -check-prefix=HAS_DEBUG %s
|
||||||
|
// RUN: %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -ggdb3 -O2 --cuda-noopt-device-debug 2>&1 \
|
||||||
|
// RUN: | FileCheck -check-prefix=HAS_DEBUG %s
|
||||||
|
|
||||||
|
// HAS_DEBUG: "-triple" "nvptx64-nvidia-cuda"
|
||||||
|
// HAS_DEBUG-SAME: "-dwarf-version=2"
|
||||||
|
// HAS_DEBUG-SAME: "-fopenmp-is-device"
|
||||||
|
// HAS_DEBUG: ptxas
|
||||||
|
// HAS_DEBUG-SAME: "-g"
|
||||||
|
// HAS_DEBUG-SAME: "--dont-merge-basicblocks"
|
||||||
|
// HAS_DEBUG-SAME: "--return-at-end"
|
||||||
|
// HAS_DEBUG: nvlink
|
||||||
|
// HAS_DEBUG-SAME: "-g"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue