diff --git a/llvm/include/llvm/MC/MCAsmInfo.h b/llvm/include/llvm/MC/MCAsmInfo.h --- a/llvm/include/llvm/MC/MCAsmInfo.h +++ b/llvm/include/llvm/MC/MCAsmInfo.h @@ -466,6 +466,10 @@ /// the .loc/.file directives. Defaults to true. bool UsesDwarfFileAndLocDirectives = true; + /// True if DWARF `.file directory' directive syntax is used by + /// default. + bool EnableDwarfFileDirectoryDefault = true; + /// True if the target needs the DWARF section length in the header (if any) /// of the DWARF section in the assembly file. Defaults to true. bool DwarfSectionSizeRequired = true; @@ -800,6 +804,10 @@ return DwarfSectionSizeRequired; } + bool enableDwarfFileDirectoryDefault() const { + return EnableDwarfFileDirectoryDefault; + } + void addInitialFrameState(const MCCFIInstruction &Inst); const std::vector &getInitialFrameState() const { diff --git a/llvm/include/llvm/MC/MCTargetOptions.h b/llvm/include/llvm/MC/MCTargetOptions.h --- a/llvm/include/llvm/MC/MCTargetOptions.h +++ b/llvm/include/llvm/MC/MCTargetOptions.h @@ -47,7 +47,6 @@ bool MCNoDeprecatedWarn : 1; bool MCNoTypeCheck : 1; bool MCSaveTempLabels : 1; - bool MCUseDwarfDirectory : 1; bool MCIncrementalLinkerCompatible : 1; bool ShowMCEncoding : 1; bool ShowMCInst : 1; @@ -59,6 +58,17 @@ bool Dwarf64 : 1; int DwarfVersion = 0; + enum DwarfDirectory { + // Force disable + DisableDwarfDirectory, + // Force enable, for assemblers that support + // `.file fileno directory filename' syntax + EnableDwarfDirectory, + // Default is based on the target + DefaultDwarfDirectory + }; + DwarfDirectory MCUseDwarfDirectory; + std::string ABIName; std::string AssemblyLanguage; std::string SplitDwarfFile; diff --git a/llvm/lib/CodeGen/LLVMTargetMachine.cpp b/llvm/lib/CodeGen/LLVMTargetMachine.cpp --- a/llvm/lib/CodeGen/LLVMTargetMachine.cpp +++ b/llvm/lib/CodeGen/LLVMTargetMachine.cpp @@ -167,13 +167,26 @@ if (Options.MCOptions.ShowMCEncoding) MCE.reset(getTarget().createMCCodeEmitter(MII, Context)); + bool UseDwarfDirectory = false; + switch (Options.MCOptions.MCUseDwarfDirectory) { + case MCTargetOptions::DisableDwarfDirectory: + UseDwarfDirectory = false; + break; + case MCTargetOptions::EnableDwarfDirectory: + UseDwarfDirectory = true; + break; + case MCTargetOptions::DefaultDwarfDirectory: + UseDwarfDirectory = MAI.enableDwarfFileDirectoryDefault(); + break; + } + std::unique_ptr MAB( getTarget().createMCAsmBackend(STI, MRI, Options.MCOptions)); auto FOut = std::make_unique(Out); MCStreamer *S = getTarget().createAsmStreamer( Context, std::move(FOut), Options.MCOptions.AsmVerbose, - Options.MCOptions.MCUseDwarfDirectory, InstPrinter, std::move(MCE), - std::move(MAB), Options.MCOptions.ShowMCInst); + UseDwarfDirectory, InstPrinter, std::move(MCE), std::move(MAB), + Options.MCOptions.ShowMCInst); AsmStreamer.reset(S); break; } diff --git a/llvm/lib/MC/MCTargetOptions.cpp b/llvm/lib/MC/MCTargetOptions.cpp --- a/llvm/lib/MC/MCTargetOptions.cpp +++ b/llvm/lib/MC/MCTargetOptions.cpp @@ -13,11 +13,11 @@ MCTargetOptions::MCTargetOptions() : MCRelaxAll(false), MCNoExecStack(false), MCFatalWarnings(false), - MCNoWarn(false), MCNoDeprecatedWarn(false), - MCNoTypeCheck(false), MCSaveTempLabels(false), - MCUseDwarfDirectory(false), MCIncrementalLinkerCompatible(false), - ShowMCEncoding(false), ShowMCInst(false), AsmVerbose(false), - PreserveAsmComments(true), Dwarf64(false) {} + MCNoWarn(false), MCNoDeprecatedWarn(false), MCNoTypeCheck(false), + MCSaveTempLabels(false), MCUseDwarfDirectory(DefaultDwarfDirectory), + MCIncrementalLinkerCompatible(false), ShowMCEncoding(false), + ShowMCInst(false), AsmVerbose(false), PreserveAsmComments(true), + Dwarf64(false) {} StringRef MCTargetOptions::getABIName() const { return ABIName; diff --git a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp --- a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp +++ b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp @@ -54,4 +54,8 @@ GlobalDirective = "\t// .globl\t"; UseIntegratedAssembler = false; + + // ptxas does not support DWARF `.file fileno directory filename' + // syntax as of v11.X. + EnableDwarfFileDirectoryDefault = false; } diff --git a/llvm/test/DebugInfo/NVPTX/dbg-declare-alloca.ll b/llvm/test/DebugInfo/NVPTX/dbg-declare-alloca.ll --- a/llvm/test/DebugInfo/NVPTX/dbg-declare-alloca.ll +++ b/llvm/test/DebugInfo/NVPTX/dbg-declare-alloca.ll @@ -1,4 +1,4 @@ -; RUN: llc < %s -mtriple=nvptx64-nvidia-cuda -dwarf-directory=0 | FileCheck %s +; RUN: llc < %s -mtriple=nvptx64-nvidia-cuda | FileCheck %s ; CHECK: .target sm_20, debug diff --git a/llvm/test/DebugInfo/NVPTX/debug-file-loc-only.ll b/llvm/test/DebugInfo/NVPTX/debug-file-loc-only.ll --- a/llvm/test/DebugInfo/NVPTX/debug-file-loc-only.ll +++ b/llvm/test/DebugInfo/NVPTX/debug-file-loc-only.ll @@ -27,8 +27,8 @@ ret void, !dbg !11 } -; CHECK-DAG: .file [[FOO]] "{{.*}}foo.h" -; CHECK-DAG: .file [[BAR]] "{{.*}}bar.cu" +; CHECK-DAG: .file [[FOO]] "/source/dir/foo.h" +; CHECK-DAG: .file [[BAR]] "/source/dir/bar.cu" ; CHECK-NOT: .section .debug{{.*}} diff --git a/llvm/test/DebugInfo/NVPTX/debug-file-loc.ll b/llvm/test/DebugInfo/NVPTX/debug-file-loc.ll --- a/llvm/test/DebugInfo/NVPTX/debug-file-loc.ll +++ b/llvm/test/DebugInfo/NVPTX/debug-file-loc.ll @@ -27,8 +27,8 @@ ret void, !dbg !11 } -; CHECK-DAG: .file [[FOO]] "{{.*}}foo.h" -; CHECK-DAG: .file [[BAR]] "{{.*}}bar.cu" +; CHECK-DAG: .file [[FOO]] "/source/dir/foo.h" +; CHECK-DAG: .file [[BAR]] "/source/dir/bar.cu" ; CHECK: .section .debug_abbrev ; CHECK-NEXT: { ; CHECK-NEXT: .b8 1 // Abbreviation Code diff --git a/llvm/test/DebugInfo/NVPTX/debug-loc-offset.ll b/llvm/test/DebugInfo/NVPTX/debug-loc-offset.ll --- a/llvm/test/DebugInfo/NVPTX/debug-loc-offset.ll +++ b/llvm/test/DebugInfo/NVPTX/debug-loc-offset.ll @@ -1,4 +1,4 @@ -; RUN: llc -mtriple=nvptx64-nvidia-cuda -dwarf-directory=0 < %s | FileCheck %s +; RUN: llc -mtriple=nvptx64-nvidia-cuda < %s | FileCheck %s ; CHECK: .target sm_{{[0-9]+}}, debug diff --git a/llvm/test/DebugInfo/NVPTX/dwarf-file-dir.ll b/llvm/test/DebugInfo/NVPTX/dwarf-file-dir.ll new file mode 100644 --- /dev/null +++ b/llvm/test/DebugInfo/NVPTX/dwarf-file-dir.ll @@ -0,0 +1,27 @@ +; RUN: llc < %s -mtriple=nvptx64-nvidia-cuda | FileCheck --check-prefix=CHECK-NODIR %s +; RUN: llc < %s -mtriple=nvptx64-nvidia-cuda -dwarf-directory=1 | FileCheck --check-prefix=CHECK-DIR %s + +; CHECK-NODIR: .file {{[0-9]+}} "/tmp/dbginfo/a/a.cpp" +; +; ptxas does not support .file directory syntax, but it can still be +; forced by -dwarf-directory=1 +; CHECK-DIR: .file {{[0-9]+}} "/tmp/dbginfo/a" "a.cpp" + +define void @_Z4funcv() !dbg !4 { +entry: + ret void, !dbg !5 +} + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!8, !9} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5.0 ", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2) +!1 = !DIFile(filename: "a.cpp", directory: "/tmp/dbginfo/a") +!2 = !{} +!4 = distinct !DISubprogram(name: "func", linkageName: "_Z4funcv", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 1, file: !1, scope: !1, type: !6, retainedNodes: !2) +!5 = !DILocation(line: 2, scope: !4) +!6 = !DISubroutineType(types: !7) +!7 = !{null} +!8 = !{i32 2, !"Dwarf Version", i32 4} +!9 = !{i32 1, !"Debug Info Version", i32 3} + diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp --- a/llvm/tools/llc/llc.cpp +++ b/llvm/tools/llc/llc.cpp @@ -502,11 +502,22 @@ TargetMachine::parseBinutilsVersion(BinutilsVersion); Options.DisableIntegratedAS = NoIntegratedAssembler; Options.MCOptions.ShowMCEncoding = ShowMCEncoding; - Options.MCOptions.MCUseDwarfDirectory = DwarfDirectory; Options.MCOptions.AsmVerbose = AsmVerbose; Options.MCOptions.PreserveAsmComments = PreserveComments; Options.MCOptions.IASSearchPaths = IncludeDirs; Options.MCOptions.SplitDwarfFile = SplitDwarfFile; + if (DwarfDirectory.getPosition()) { + Options.MCOptions.MCUseDwarfDirectory = + DwarfDirectory ? MCTargetOptions::EnableDwarfDirectory + : MCTargetOptions::DisableDwarfDirectory; + } else { + // -dwarf-directory is not set explicitly. Some assemblers + // (e.g. GNU as or ptxas) do not support `.file directory' + // syntax prior to DWARFv5. Let the target decide the default + // value. + Options.MCOptions.MCUseDwarfDirectory = + MCTargetOptions::DefaultDwarfDirectory; + } }; Optional RM = codegen::getExplicitRelocModel();