[NVPTX] Disable DWARF .file directory for PTX

Default behavior for .file directory was changed in D105856, but
ptxas (CUDA 11.5 release) refuses to parse it:

    $ llc -march=nvptx64 llvm/test/DebugInfo/NVPTX/debug-file-loc.ll
    $ ptxas debug-file-loc.s
    ptxas debug-file-loc.s, line 42; fatal   : Parsing error near
    '"foo.h"': syntax error

Added a new field to MCAsmInfo to control default value of
UseDwarfDirectory. This value is used if -dwarf-directory command line
option is not specified.

Differential Revision: https://reviews.llvm.org/D121299
This commit is contained in:
Andrew Savonichev
2022-04-26 18:45:09 +03:00
parent 903aa5e0f8
commit 0a27622a1d
12 changed files with 92 additions and 16 deletions

View File

@@ -455,7 +455,10 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile;
Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;
Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels;
Options.MCOptions.MCUseDwarfDirectory = !CodeGenOpts.NoDwarfDirectoryAsm;
Options.MCOptions.MCUseDwarfDirectory =
CodeGenOpts.NoDwarfDirectoryAsm
? llvm::MCTargetOptions::DisableDwarfDirectory
: llvm::MCTargetOptions::EnableDwarfDirectory;
Options.MCOptions.MCNoExecStack = CodeGenOpts.NoExecStack;
Options.MCOptions.MCIncrementalLinkerCompatible =
CodeGenOpts.IncrementalLinkerCompatible;

View File

@@ -466,6 +466,10 @@ protected:
/// 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;
@@ -808,6 +812,10 @@ public:
return DwarfSectionSizeRequired;
}
bool enableDwarfFileDirectoryDefault() const {
return EnableDwarfFileDirectoryDefault;
}
void addInitialFrameState(const MCCFIInstruction &Inst);
const std::vector<MCCFIInstruction> &getInitialFrameState() const {

View File

@@ -47,7 +47,6 @@ public:
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 @@ public:
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;

View File

@@ -165,13 +165,26 @@ Expected<std::unique_ptr<MCStreamer>> LLVMTargetMachine::createMCStreamer(
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<MCAsmBackend> MAB(
getTarget().createMCAsmBackend(STI, MRI, Options.MCOptions));
auto FOut = std::make_unique<formatted_raw_ostream>(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;
}

View File

@@ -13,11 +13,11 @@ using namespace llvm;
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;

View File

@@ -58,4 +58,8 @@ NVPTXMCAsmInfo::NVPTXMCAsmInfo(const Triple &TheTriple,
// Avoid using parens for identifiers starting with $ - ptxas does
// not expect them.
UseParensForDollarSignNames = false;
// ptxas does not support DWARF `.file fileno directory filename'
// syntax as of v11.X.
EnableDwarfFileDirectoryDefault = false;
}

View File

@@ -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

View File

@@ -27,8 +27,8 @@ bb:
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{{.*}}

View File

@@ -27,8 +27,8 @@ bb:
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

View File

@@ -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

View File

@@ -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}

View File

@@ -503,11 +503,22 @@ static int compileModule(char **argv, LLVMContext &Context) {
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<Reloc::Model> RM = codegen::getExplicitRelocModel();