Skip to content

Commit f2f898a

Browse files
committed
DebugInfo: Omit an empty CU when a subprogram was moved into its use
When the only use of a CU is for a subprogram that's only emitted into the using CU (to avoid cross-CU references in DWO files), avoid creating that CU at all. llvm-svn: 304111
1 parent 41119cd commit f2f898a

File tree

2 files changed

+64
-8
lines changed

2 files changed

+64
-8
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -374,14 +374,18 @@ void DwarfDebug::constructAbstractSubprogramScopeDIE(DwarfCompileUnit &SrcCU,
374374

375375
// Find the subprogram's DwarfCompileUnit in the SPMap in case the subprogram
376376
// was inlined from another compile unit.
377-
auto &CU = getOrCreateDwarfCompileUnit(SP->getUnit());
378-
if (auto *SkelCU = CU.getSkeleton()) {
379-
(shareAcrossDWOCUs() ? CU : SrcCU)
380-
.constructAbstractSubprogramScopeDIE(Scope);
381-
if (CU.getCUNode()->getSplitDebugInlining())
382-
SkelCU->constructAbstractSubprogramScopeDIE(Scope);
383-
} else {
384-
CU.constructAbstractSubprogramScopeDIE(Scope);
377+
if (useSplitDwarf() && !shareAcrossDWOCUs() && !SP->getUnit()->getSplitDebugInlining())
378+
// Avoid building the original CU if it won't be used
379+
SrcCU.constructAbstractSubprogramScopeDIE(Scope);
380+
else {
381+
auto &CU = getOrCreateDwarfCompileUnit(SP->getUnit());
382+
if (auto *SkelCU = CU.getSkeleton()) {
383+
(shareAcrossDWOCUs() ? CU : SrcCU)
384+
.constructAbstractSubprogramScopeDIE(Scope);
385+
if (CU.getCUNode()->getSplitDebugInlining())
386+
SkelCU->constructAbstractSubprogramScopeDIE(Scope);
387+
} else
388+
CU.constructAbstractSubprogramScopeDIE(Scope);
385389
}
386390
}
387391

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
; RUN: %llc_dwarf -split-dwarf-file=foo.dwo %s -filetype=obj -o - | llvm-dwarfdump -debug-dump=info - | FileCheck %s
2+
3+
; Created from:
4+
; a.cpp:
5+
; void f1();
6+
; inline __attribute__((always_inline)) __attribute__((used)) void f2() { f1(); }
7+
; b.cpp:
8+
; void f2();
9+
; void f3() {
10+
; f2();
11+
; }
12+
; $ clang++ -fno-split-dwarf-inlining {a,b}.cpp -emit-llvm -S -g
13+
; $ llvm-link {a,b}.ll -S -o ab.ll
14+
; Then strip out the @llvm.used global, so no out of line definition of 'f2'
15+
; will be emitted. This emulates something more like the available_externally
16+
; import performed by ThinLTO.
17+
18+
; CHECK: Compile Unit
19+
; CHECK-NOT: Compile Unit
20+
21+
declare void @_Z2f1v()
22+
23+
; Function Attrs: noinline norecurse uwtable
24+
define i32 @main() !dbg !9 {
25+
entry:
26+
call void @_Z2f1v(), !dbg !13
27+
ret i32 0, !dbg !18
28+
}
29+
30+
!llvm.dbg.cu = !{!0, !3}
31+
!llvm.ident = !{!5, !5}
32+
!llvm.module.flags = !{!6, !7, !8}
33+
34+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 5.0.0 (trunk 304054) (llvm/trunk 304080)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false)
35+
!1 = !DIFile(filename: "a.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch")
36+
!2 = !{}
37+
!3 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !4, producer: "clang version 5.0.0 (trunk 304054) (llvm/trunk 304080)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false)
38+
!4 = !DIFile(filename: "b.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch")
39+
!5 = !{!"clang version 5.0.0 (trunk 304054) (llvm/trunk 304080)"}
40+
!6 = !{i32 2, !"Dwarf Version", i32 4}
41+
!7 = !{i32 2, !"Debug Info Version", i32 3}
42+
!8 = !{i32 1, !"wchar_size", i32 4}
43+
!9 = distinct !DISubprogram(name: "main", scope: !4, file: !4, line: 2, type: !10, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !3, variables: !2)
44+
!10 = !DISubroutineType(types: !11)
45+
!11 = !{!12}
46+
!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
47+
!13 = !DILocation(line: 2, column: 73, scope: !14, inlinedAt: !17)
48+
!14 = distinct !DISubprogram(name: "f2", linkageName: "_Z2f2v", scope: !1, file: !1, line: 2, type: !15, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
49+
!15 = !DISubroutineType(types: !16)
50+
!16 = !{null}
51+
!17 = distinct !DILocation(line: 3, column: 3, scope: !9)
52+
!18 = !DILocation(line: 4, column: 1, scope: !9)

0 commit comments

Comments
 (0)