[llvm] 0a27622 - [NVPTX] Disable DWARF .file directory for PTX
Andrew Savonichev via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 26 11:43:57 PDT 2022
Author: Andrew Savonichev
Date: 2022-04-26T21:40:36+03:00
New Revision: 0a27622a1d625f179a17f3a22a547d50b042b76e
URL: https://github.com/llvm/llvm-project/commit/0a27622a1d625f179a17f3a22a547d50b042b76e
DIFF: https://github.com/llvm/llvm-project/commit/0a27622a1d625f179a17f3a22a547d50b042b76e.diff
LOG: [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
Added:
llvm/test/DebugInfo/NVPTX/dwarf-file-dir.ll
Modified:
clang/lib/CodeGen/BackendUtil.cpp
llvm/include/llvm/MC/MCAsmInfo.h
llvm/include/llvm/MC/MCTargetOptions.h
llvm/lib/CodeGen/LLVMTargetMachine.cpp
llvm/lib/MC/MCTargetOptions.cpp
llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp
llvm/test/DebugInfo/NVPTX/dbg-declare-alloca.ll
llvm/test/DebugInfo/NVPTX/debug-file-loc-only.ll
llvm/test/DebugInfo/NVPTX/debug-file-loc.ll
llvm/test/DebugInfo/NVPTX/debug-loc-offset.ll
llvm/tools/llc/llc.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index ed7bd8f838ee0..c802f74bb2db1 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -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;
diff --git a/llvm/include/llvm/MC/MCAsmInfo.h b/llvm/include/llvm/MC/MCAsmInfo.h
index 578518e6dc80a..08b5b3ebd355f 100644
--- a/llvm/include/llvm/MC/MCAsmInfo.h
+++ b/llvm/include/llvm/MC/MCAsmInfo.h
@@ -466,6 +466,10 @@ class MCAsmInfo {
/// 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 @@ class MCAsmInfo {
return DwarfSectionSizeRequired;
}
+ bool enableDwarfFileDirectoryDefault() const {
+ return EnableDwarfFileDirectoryDefault;
+ }
+
void addInitialFrameState(const MCCFIInstruction &Inst);
const std::vector<MCCFIInstruction> &getInitialFrameState() const {
diff --git a/llvm/include/llvm/MC/MCTargetOptions.h b/llvm/include/llvm/MC/MCTargetOptions.h
index db50dc6749e2e..93712a6b7d44b 100644
--- a/llvm/include/llvm/MC/MCTargetOptions.h
+++ b/llvm/include/llvm/MC/MCTargetOptions.h
@@ -47,7 +47,6 @@ class MCTargetOptions {
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 @@ class MCTargetOptions {
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
index 495efc6c05145..ee6c46212a68f 100644
--- a/llvm/lib/CodeGen/LLVMTargetMachine.cpp
+++ b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
@@ -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;
}
diff --git a/llvm/lib/MC/MCTargetOptions.cpp b/llvm/lib/MC/MCTargetOptions.cpp
index eb57917ee8fd5..4e51ab75527f7 100644
--- a/llvm/lib/MC/MCTargetOptions.cpp
+++ b/llvm/lib/MC/MCTargetOptions.cpp
@@ -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;
diff --git a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp
index 6bc3e43db1d6f..ae39be2325140 100644
--- a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp
+++ b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp
@@ -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;
}
diff --git a/llvm/test/DebugInfo/NVPTX/dbg-declare-alloca.ll b/llvm/test/DebugInfo/NVPTX/dbg-declare-alloca.ll
index d5bd573c3b86d..6bfc3d1e94c48 100644
--- 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
index f47e95624a20f..adb1e40f92d1d 100644
--- a/llvm/test/DebugInfo/NVPTX/debug-file-loc-only.ll
+++ b/llvm/test/DebugInfo/NVPTX/debug-file-loc-only.ll
@@ -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{{.*}}
diff --git a/llvm/test/DebugInfo/NVPTX/debug-file-loc.ll b/llvm/test/DebugInfo/NVPTX/debug-file-loc.ll
index 09d47b3847a83..2e69c6b546673 100644
--- a/llvm/test/DebugInfo/NVPTX/debug-file-loc.ll
+++ b/llvm/test/DebugInfo/NVPTX/debug-file-loc.ll
@@ -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
diff --git a/llvm/test/DebugInfo/NVPTX/debug-loc-offset.ll b/llvm/test/DebugInfo/NVPTX/debug-loc-offset.ll
index 43cc586fff198..c932ea0af460c 100644
--- 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
index 0000000000000..2225eeabd8882
--- /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
index a79ca928fb4f3..17dd6dfb673f9 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -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();
More information about the llvm-commits
mailing list