Skip to content

Commit 08b668a

Browse files
committed
MachineModuleInfo: Initialize DbgInfoAvailable depending on debug_cus existing
Before this patch DbgInfoAvailable was set to true in DwarfDebug::beginModule() or CodeViewDebug::CodeViewDebug(). This made MIR testing weird since passes would suddenly stop dealing with debug info just because we stopped the pipeline before the debug printers. This patch changes the logic to initialize DbgInfoAvailable based on the fact that debug_compile_units exist in the llvm Module. The debug printers may then override it with false in case of debug printing being disabled. Differential Revision: https://reviews.llvm.org/D53885 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345740 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 22968f7 commit 08b668a

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ CodeViewDebug::CodeViewDebug(AsmPrinter *AP)
117117
if (!MMI->getModule()->getNamedMetadata("llvm.dbg.cu") ||
118118
!AP->getObjFileLowering().getCOFFDebugSymbolsSection()) {
119119
Asm = nullptr;
120+
MMI->setDebugInfoAvailability(false);
120121
return;
121122
}
122123
// Tell MMI that we have debug info.

lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,15 +701,18 @@ sortGlobalExprs(SmallVectorImpl<DwarfCompileUnit::GlobalExpr> &GVEs) {
701701
void DwarfDebug::beginModule() {
702702
NamedRegionTimer T(DbgTimerName, DbgTimerDescription, DWARFGroupName,
703703
DWARFGroupDescription, TimePassesIsEnabled);
704-
if (DisableDebugInfoPrinting)
704+
if (DisableDebugInfoPrinting) {
705+
MMI->setDebugInfoAvailability(false);
705706
return;
707+
}
706708

707709
const Module *M = MMI->getModule();
708710

709711
unsigned NumDebugCUs = std::distance(M->debug_compile_units_begin(),
710712
M->debug_compile_units_end());
711713
// Tell MMI whether we have debug info.
712-
MMI->setDebugInfoAvailability(NumDebugCUs > 0);
714+
assert(MMI->hasDebugInfo() == (NumDebugCUs > 0) &&
715+
"DebugInfoAvailabilty initialized unexpectedly");
713716
SingleCU = NumDebugCUs == 1;
714717
DenseMap<DIGlobalVariable *, SmallVector<DwarfCompileUnit::GlobalExpr, 1>>
715718
GVMap;

lib/CodeGen/MachineModuleInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,11 @@ MachineModuleInfo::~MachineModuleInfo() = default;
206206
bool MachineModuleInfo::doInitialization(Module &M) {
207207
ObjFileMMI = nullptr;
208208
CurCallSite = 0;
209-
DbgInfoAvailable = UsesVAFloatArgument = UsesMorestackAddr = false;
209+
UsesVAFloatArgument = UsesMorestackAddr = false;
210210
HasSplitStack = HasNosplitStack = false;
211211
AddrLabelSymbols = nullptr;
212212
TheModule = &M;
213+
DbgInfoAvailable = !empty(M.debug_compile_units());
213214
return false;
214215
}
215216

test/CodeGen/AArch64/fast-isel-dbg.ll

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; RUN: llc -o - %s -fast-isel -stop-before=expand-isel-pseudos | FileCheck %s
2+
; Make sure fast-isel produces DBG_VALUE instructions even if no debug printer
3+
; is scheduled because of -stop-before.
4+
target triple="aarch64--"
5+
6+
; CHECK-LABEL: name: func
7+
; CHECK: DBG_VALUE
8+
define void @func(i32 %a) !dbg !4 {
9+
call void @llvm.dbg.declare(metadata i32 %a, metadata !5, metadata !DIExpression()), !dbg !7
10+
ret void
11+
}
12+
13+
declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
14+
attributes #0 = { nounwind readnone speculatable }
15+
16+
!llvm.dbg.cu = !{!0}
17+
!llvm.module.flags = !{!2, !3}
18+
19+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly)
20+
!1 = !DIFile(filename: "fast-isel-dbg.ll", directory: "/")
21+
!2 = !{i32 2, !"Dwarf Version", i32 4}
22+
!3 = !{i32 2, !"Debug Info Version", i32 3}
23+
!4 = distinct !DISubprogram(name: "func", scope: null, isLocal: false, isDefinition: true, isOptimized: false, unit: !0)
24+
!5 = !DILocalVariable(name: "a", arg: 1, scope: !4, file: !1, line: 17, type: !6)
25+
!6 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
26+
!7 = !DILocation(line: 17, scope: !4)

0 commit comments

Comments
 (0)