From: Alexey Bataev Date: Wed, 18 Apr 2018 16:31:09 +0000 (+0000) Subject: [NVPTX] Emit debug info in DWARF-2 by default for Cuda devices. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c16c83ef6c8fc32195774870a2112f3fe106e1ce;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@330272 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/ToolChains/Cuda.cpp b/lib/Driver/ToolChains/Cuda.cpp index c83d066fa2..fc74a8ebbf 100644 --- a/lib/Driver/ToolChains/Cuda.cpp +++ b/lib/Driver/ToolChains/Cuda.cpp @@ -273,6 +273,35 @@ void CudaInstallationDetector::print(raw_ostream &OS) const { << 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, const InputInfo &Output, const InputInfoList &Inputs, @@ -304,8 +333,8 @@ void NVPTX::Assembler::ConstructJob(Compilation &C, const JobAction &JA, ArgStringList CmdArgs; CmdArgs.push_back(TC.getTriple().isArch64Bit() ? "-m64" : "-m32"); - if (Args.hasFlag(options::OPT_cuda_noopt_device_debug, - options::OPT_no_cuda_noopt_device_debug, false)) { + DebugInfoKind DIKind = mustEmitDebugInfo(Args); + if (DIKind == FullDebug) { // ptxas does not accept -g option if optimization is enabled, so // we ignore the compiler's -O* options if we want debug info. 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. CmdArgs.push_back("-O0"); } + if (DIKind == LineTableOnly) + CmdArgs.push_back("-lineinfo"); // Pass -v to ptxas if it was passed to the driver. 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(Args.MakeArgString("--create")); CmdArgs.push_back(Args.MakeArgString(Output.getFilename())); + if (mustEmitDebugInfo(Args) == FullDebug) + CmdArgs.push_back("-g"); for (const auto& II : Inputs) { auto *A = II.getAction(); @@ -461,7 +494,7 @@ void NVPTX::OpenMPLinker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(Output.getFilename()); } else assert(Output.isNothing() && "Invalid output."); - if (Args.hasArg(options::OPT_g_Flag)) + if (mustEmitDebugInfo(Args) == FullDebug) CmdArgs.push_back("-g"); if (Args.hasArg(options::OPT_v)) diff --git a/lib/Driver/ToolChains/Cuda.h b/lib/Driver/ToolChains/Cuda.h index 3d08cec164..9b34fa589e 100644 --- a/lib/Driver/ToolChains/Cuda.h +++ b/lib/Driver/ToolChains/Cuda.h @@ -180,6 +180,8 @@ public: computeMSVCVersion(const Driver *D, const llvm::opt::ArgList &Args) const override; + unsigned GetDefaultDwarfVersion() const override { return 2; } + const ToolChain &HostTC; CudaInstallationDetector CudaInstallation; diff --git a/test/Driver/cuda-dwarf-2.cu b/test/Driver/cuda-dwarf-2.cu new file mode 100644 index 0000000000..b6c7f500f5 --- /dev/null +++ b/test/Driver/cuda-dwarf-2.cu @@ -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" + diff --git a/test/Driver/cuda-external-tools.cu b/test/Driver/cuda-external-tools.cu index c15cc05a7d..367c6997ea 100644 --- a/test/Driver/cuda-external-tools.cu +++ b/test/Driver/cuda-external-tools.cu @@ -23,7 +23,7 @@ // RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,RDC %s // 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 // --no-cuda-noopt-device-debug overrides --cuda-noopt-device-debug. diff --git a/test/Driver/openmp-offload-gpu.c b/test/Driver/openmp-offload-gpu.c index 152e03a57c..3d14041a13 100644 --- a/test/Driver/openmp-offload-gpu.c +++ b/test/Driver/openmp-offload-gpu.c @@ -165,3 +165,51 @@ // 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. + +/// 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" +