ABataev created this revision. ABataev added reviewers: tra, jlebar. Herald added subscribers: JDevlieghere, aprantl.
NVPTX target supports debug info in DWARF-2 format. Patch adds emission of debug info in DWARF-2 by default. Repository: rC Clang https://reviews.llvm.org/D42581 Files: lib/Driver/ToolChains/Cuda.cpp lib/Driver/ToolChains/Cuda.h 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 @@ -142,3 +142,77 @@ // RUN: | FileCheck -check-prefix=CHK-NOLIBDEVICE %s // CHK-NOLIBDEVICE-NOT: error:{{.*}}sm_60 + +/// ########################################################################### + +/// Check that dbug 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 2>&1 \ +// RUN: | FileCheck -check-prefix=DEFAULT_DEBUG %s + +// DEFAULT_DEBUG: "-triple" "nvptx64-nvidia-cuda" +// DEFAULT_DEBUG-SAME: "-dwarf-version=2" +// DEFAULT_DEBUG-SAME: "-fopenmp-is-device" +// DEFAULT_DEBUG: ptxas +// DEFAULT_DEBUG-NOT: "-g" +// DEFAULT_DEBUG: nvlink +// DEFAULT_DEBUG-NOT: "-g" + +// 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=O0_NO_DEBUG %s + +// O0_NO_DEBUG: "-triple" "nvptx64-nvidia-cuda" +// O0_NO_DEBUG-SAME: "-dwarf-version=2" +// O0_NO_DEBUG-SAME: "-fopenmp-is-device" +// O0_NO_DEBUG: ptxas +// O0_NO_DEBUG-NOT: "-g" +// O0_NO_DEBUG: nvlink +// O0_NO_DEBUG-NOT: "-g" + +// 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=O0_DEBUG %s + +// O0_DEBUG: "-triple" "nvptx64-nvidia-cuda" +// O0_DEBUG-SAME: "-dwarf-version=2" +// O0_DEBUG-SAME: "-fopenmp-is-device" +// O0_DEBUG: ptxas +// O0_DEBUG-SAME: "-g" +// O0_DEBUG-SAME: "--dont-merge-basicblocks" +// O0_DEBUG-SAME: "--return-at-end" +// O0_DEBUG: nvlink +// O0_DEBUG-SAME: "-g" + +// 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=DEFAULT_O3_DEBUG %s + +// DEFAULT_O3_DEBUG: "-triple" "nvptx64-nvidia-cuda" +// DEFAULT_O3_DEBUG-SAME: "-dwarf-version=2" +// DEFAULT_O3_DEBUG-SAME: "-fopenmp-is-device" +// DEFAULT_O3_DEBUG: ptxas +// DEFAULT_O3_DEBUG-NOT: "-g" +// DEFAULT_O3_DEBUG: nvlink +// DEFAULT_O3_DEBUG-NOT: "-g" + +// 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=O3_NO_DEBUG %s + +// O3_NO_DEBUG: "-triple" "nvptx64-nvidia-cuda" +// O3_NO_DEBUG-SAME: "-dwarf-version=2" +// O3_NO_DEBUG-SAME: "-fopenmp-is-device" +// O3_NO_DEBUG: ptxas +// O3_NO_DEBUG-NOT: "-g" +// O3_NO_DEBUG: nvlink +// O3_NO_DEBUG-NOT: "-g" + +// 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=O3_DEBUG %s + +// O3_DEBUG: "-triple" "nvptx64-nvidia-cuda" +// O3_DEBUG-SAME: "-dwarf-version=2" +// O3_DEBUG-SAME: "-fopenmp-is-device" +// O3_DEBUG: ptxas +// O3_DEBUG-SAME: "-g" +// O3_DEBUG-SAME: "--dont-merge-basicblocks" +// O3_DEBUG-SAME: "--return-at-end" +// O3_DEBUG: nvlink +// O3_DEBUG-SAME: "-g" + Index: test/Driver/cuda-dwarf-2.cu =================================================================== --- /dev/null +++ test/Driver/cuda-dwarf-2.cu @@ -0,0 +1,66 @@ +// REQUIRES: clang-driver +// +// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 %s -g 2>&1 | \ +// RUN: FileCheck %s -check-prefix DEFAULT + +// DEFAULT: "-fcuda-is-device" +// DEFAULT-SAME: "-dwarf-version=2" +// DEFAULT: ptxas +// DEFAULT-NOT: "-g" +// DEFAULT: fatbinary +// DEFAULT-NOT: "-g" + +// 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 O0_NO_DEBUG + +// O0_NO_DEBUG: "-fcuda-is-device" +// O0_NO_DEBUG-SAME: "-dwarf-version=2" +// O0_NO_DEBUG: ptxas +// O0_NO_DEBUG-NOT: "-g" +// O0_NO_DEBUG: fatbinary +// O0_NO_DEBUG-NOT: "-g" + +// 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 O0_DEBUG + +// O0_DEBUG: "-fcuda-is-device" +// O0_DEBUG-SAME: "-dwarf-version=2" +// O0_DEBUG: ptxas +// O0_DEBUG-SAME: "-g" +// O0_DEBUG-SAME: "--dont-merge-basicblocks" +// O0_DEBUG-SAME: "--return-at-end" +// O0_DEBUG: fatbinary +// O0_DEBUG-SAME: "-g" + +// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 %s -g -O3 2>&1 | \ +// RUN: FileCheck %s -check-prefix O3_DEFAULT + +// O3_DEFAULT: "-fcuda-is-device" +// O3_DEFAULT-SAME: "-dwarf-version=2" +// O3_DEFAULT: ptxas +// O3_DEFAULT-NOT: "-g" +// O3_DEFAULT: fatbinary +// O3_DEFAULT-NOT: "-g" + +// 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 O3_NO_DEBUG + +// O3_NO_DEBUG: "-fcuda-is-device" +// O3_NO_DEBUG-SAME: "-dwarf-version=2" +// O3_NO_DEBUG: ptxas +// O3_NO_DEBUG-NOT: "-g" +// O3_NO_DEBUG: fatbinary +// O3_NO_DEBUG-NOT: "-g" + +// 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 O3_DEBUG + +// O3_DEBUG: "-fcuda-is-device" +// O3_DEBUG-SAME: "-dwarf-version=2" +// O3_DEBUG: ptxas +// O3_DEBUG-SAME: "-g" +// O3_DEBUG-SAME: "--dont-merge-basicblocks" +// O3_DEBUG-SAME: "--return-at-end" +// O3_DEBUG: fatbinary +// O3_DEBUG-SAME: "-g" + Index: lib/Driver/ToolChains/Cuda.h =================================================================== --- lib/Driver/ToolChains/Cuda.h +++ lib/Driver/ToolChains/Cuda.h @@ -180,6 +180,8 @@ computeMSVCVersion(const Driver *D, const llvm::opt::ArgList &Args) const override; + unsigned GetDefaultDwarfVersion() const override { return 2; } + const ToolChain &HostTC; CudaInstallationDetector CudaInstallation; Index: lib/Driver/ToolChains/Cuda.cpp =================================================================== --- lib/Driver/ToolChains/Cuda.cpp +++ lib/Driver/ToolChains/Cuda.cpp @@ -231,6 +231,11 @@ << CudaVersionToString(Version) << "\n"; } +static bool mustEmitDebugInfo(const ArgList &Args) { + return Args.hasFlag(options::OPT_cuda_noopt_device_debug, + options::OPT_no_cuda_noopt_device_debug, false); +} + void NVPTX::Assembler::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, @@ -262,8 +267,7 @@ 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)) { + if (mustEmitDebugInfo(Args)) { // 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"); @@ -346,6 +350,8 @@ CmdArgs.push_back(TC.getTriple().isArch64Bit() ? "-64" : "-32"); CmdArgs.push_back(Args.MakeArgString("--create")); CmdArgs.push_back(Args.MakeArgString(Output.getFilename())); + if (mustEmitDebugInfo(Args) && Args.hasArg(options::OPT_g_Flag)) + CmdArgs.push_back("-g"); for (const auto& II : Inputs) { auto *A = II.getAction(); @@ -394,7 +400,7 @@ CmdArgs.push_back(Output.getFilename()); } else assert(Output.isNothing() && "Invalid output."); - if (Args.hasArg(options::OPT_g_Flag)) + if (mustEmitDebugInfo(Args) && Args.hasArg(options::OPT_g_Flag)) CmdArgs.push_back("-g"); if (Args.hasArg(options::OPT_v))
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits