llvm.org GIT mirror llvm / c61d5f4
[codeview] Shrink inlined call site line info tables For a fully inlined call chain like a -> b -> c -> d, we were emitting line info for 'd' 3 separate times: once for d's actual InlineSite line table, and twice for 'b' and 'c'. This is particularly inefficient when all these functions are in different headers, because now we need to encode the file change. Windbg was coping with our suboptimal output, so this should not be noticeable from the debugger. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275502 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 4 years ago
5 changed file(s) with 189 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
7777 SmallVector InlinedLocals;
7878 SmallVector ChildSites;
7979 const DISubprogram *Inlinee = nullptr;
80
81 /// The ID of the inline site or function used with .cv_loc. Not a type
82 /// index.
8083 unsigned SiteFuncId = 0;
8184 };
8285
301301 StartLoc.setFileNum(Frag.StartFileId);
302302 StartLoc.setLine(Frag.StartLineNum);
303303 const MCCVLineEntry *LastLoc = &StartLoc;
304 bool WithinFunction = true;
304 bool HaveOpenRange = false;
305305
306306 SmallVectorImpl &Buffer = Frag.getContents();
307307 Buffer.clear(); // Clear old contents if we went through relaxation.
309309 if (!InlinedFuncIds.count(Loc.getFunctionId())) {
310310 // We've hit a cv_loc not attributed to this inline call site. Use this
311311 // label to end the PC range.
312 if (WithinFunction) {
312 if (HaveOpenRange) {
313313 unsigned Length =
314314 computeLabelDiff(Layout, LastLoc->getLabel(), Loc.getLabel());
315315 compressAnnotation(BinaryAnnotationsOpCode::ChangeCodeLength, Buffer);
316316 compressAnnotation(Length, Buffer);
317317 }
318 WithinFunction = false;
318 HaveOpenRange = false;
319319 continue;
320320 }
321 WithinFunction = true;
321
322 // If we've already opened the function and we're at an indirectly inlined
323 // location, continue until the next directly inlined location.
324 bool DirectlyInlined = Loc.getFunctionId() == Frag.SiteFuncId;
325 if (!DirectlyInlined && HaveOpenRange)
326 continue;
327 HaveOpenRange = true;
322328
323329 if (Loc.getFileNum() != LastLoc->getFileNum()) {
324330 // File ids are 1 based, and each file checksum table entry is 8 bytes
357363 LastLoc = &Loc;
358364 }
359365
360 assert(WithinFunction);
366 assert(HaveOpenRange);
361367
362368 unsigned EndSymLength =
363369 computeLabelDiff(Layout, LastLoc->getLabel(), Frag.getFnEndSym());
0 ; RUN: llc -mcpu=core2 -mtriple=i686-pc-win32 < %s | FileCheck %s --check-prefix=ASM
1 ; RUN: llc -mcpu=core2 -mtriple=i686-pc-win32 < %s -filetype=obj | llvm-readobj -codeview | FileCheck %s --check-prefix=OBJ
2
3 ; This C++ source should run and you should be able to step through the volatile
4 ; modifications to x in windbg.
5 ; # 1 "t.cpp" 2
6 ; volatile int x;
7 ;
8 ; # 1 "./t.h" 1
9 ; inline void f() {
10 ; x += 3;
11 ; }
12 ; # 3 "t.cpp" 2
13 ; inline __forceinline void g() {
14 ; x += 2;
15 ; f();
16 ; x += 2;
17 ; }
18 ; int main() {
19 ; x += 1;
20 ; g();
21 ; x += 1;
22 ; return x;
23 ; }
24
25 ; ASM: _main: # @main
26 ; ASM: Lfunc_begin0:
27 ; ASM: # BB#0: # %entry
28 ; ASM: .cv_file 1 "D:\\src\\llvm\\build\\t.cpp"
29 ; ASM: .cv_loc 0 1 9 5 is_stmt 0 # t.cpp:9:5
30 ; ASM: incl "?x@@3HC"
31 ; ASM: .cv_loc 1 1 4 5 # t.cpp:4:5
32 ; ASM: addl $2, "?x@@3HC"
33 ; ASM: .cv_file 2 "D:\\src\\llvm\\build\\t.h"
34 ; ASM: .cv_loc 2 2 2 5 # ./t.h:2:5
35 ; ASM: addl $3, "?x@@3HC"
36 ; ASM: .cv_loc 1 1 6 5 # t.cpp:6:5
37 ; ASM: addl $2, "?x@@3HC"
38 ; ASM: .cv_loc 0 1 11 5 # t.cpp:11:5
39 ; ASM: incl "?x@@3HC"
40 ; ASM: .cv_loc 0 1 12 10 # t.cpp:12:10
41 ; ASM: movl "?x@@3HC", %eax
42 ; ASM: .cv_loc 0 1 12 3 # t.cpp:12:3
43 ; ASM: retl
44
45 ; OBJ: Subsection [
46 ; OBJ: SubSectionType: InlineeLines (0xF6)
47 ; OBJ: SubSectionSize: 0x1C
48 ; OBJ: InlineeSourceLine {
49 ; OBJ: Inlinee: g (0x1002)
50 ; OBJ: FileID: D:\src\llvm\build\t.cpp (0x0)
51 ; OBJ: SourceLineNum: 3
52 ; OBJ: }
53 ; OBJ: InlineeSourceLine {
54 ; OBJ: Inlinee: f (0x1003)
55 ; OBJ: FileID: D:\src\llvm\build\t.h (0x8)
56 ; OBJ: SourceLineNum: 1
57 ; OBJ: }
58 ; OBJ: ]
59
60
61 ; OBJ: Subsection [
62 ; OBJ: SubSectionType: Symbols (0xF1)
63 ; OBJ: SubSectionSize: 0x62
64 ; OBJ: ProcStart {
65 ; OBJ: Kind: S_GPROC32_ID (0x1147)
66 ; OBJ: FunctionType: main (0x1005)
67 ; OBJ: CodeOffset: _main+0x0
68 ; OBJ: Segment: 0x0
69 ; OBJ: Flags [ (0x0)
70 ; OBJ: ]
71 ; OBJ: DisplayName: main
72 ; OBJ: LinkageName: _main
73 ; OBJ: }
74
75 ; Previously, g's InlineSite referenced t.h, which was wasteful.
76 ; OBJ: InlineSite {
77 ; OBJ: Inlinee: g (0x1002)
78 ; OBJ: BinaryAnnotations [
79 ; OBJ-NEXT: ChangeCodeOffsetAndLineOffset: {CodeOffset: 0x6, LineOffset: 1}
80 ; OBJ-NEXT: ChangeCodeOffsetAndLineOffset: {CodeOffset: 0xE, LineOffset: 2}
81 ; OBJ-NEXT: ChangeCodeLength: 0x7
82 ; OBJ-NEXT: ]
83 ; OBJ: }
84
85 ; OBJ: InlineSite {
86 ; OBJ: Inlinee: f (0x1003)
87 ; OBJ: BinaryAnnotations [
88 ; OBJ-NEXT: ChangeCodeOffsetAndLineOffset: {CodeOffset: 0xD, LineOffset: 1}
89 ; OBJ-NEXT: ChangeCodeLength: 0x7
90 ; OBJ-NEXT:]
91 ; OBJ: }
92 ; OBJ: InlineSiteEnd {
93 ; OBJ: }
94 ; OBJ: InlineSiteEnd {
95 ; OBJ: }
96 ; OBJ: ProcEnd {
97 ; OBJ: }
98 ; OBJ: ]
99
100 ; ModuleID = 't.cpp'
101 source_filename = "t.cpp"
102 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
103 target triple = "x86_64-pc-windows-msvc19.0.24210"
104
105 @"\01?x@@3HC" = global i32 0, align 4
106
107 ; Function Attrs: norecurse nounwind uwtable
108 define i32 @main() local_unnamed_addr #0 !dbg !11 {
109 entry:
110 %0 = load volatile i32, i32* @"\01?x@@3HC", align 4, !dbg !14, !tbaa !15
111 %add = add nsw i32 %0, 1, !dbg !14
112 store volatile i32 %add, i32* @"\01?x@@3HC", align 4, !dbg !14, !tbaa !15
113 %1 = load volatile i32, i32* @"\01?x@@3HC", align 4, !dbg !19, !tbaa !15
114 %add.i = add nsw i32 %1, 2, !dbg !19
115 store volatile i32 %add.i, i32* @"\01?x@@3HC", align 4, !dbg !19, !tbaa !15
116 %2 = load volatile i32, i32* @"\01?x@@3HC", align 4, !dbg !24, !tbaa !15
117 %add.i.i = add nsw i32 %2, 3, !dbg !24
118 store volatile i32 %add.i.i, i32* @"\01?x@@3HC", align 4, !dbg !24, !tbaa !15
119 %3 = load volatile i32, i32* @"\01?x@@3HC", align 4, !dbg !28, !tbaa !15
120 %add1.i = add nsw i32 %3, 2, !dbg !28
121 store volatile i32 %add1.i, i32* @"\01?x@@3HC", align 4, !dbg !28, !tbaa !15
122 %4 = load volatile i32, i32* @"\01?x@@3HC", align 4, !dbg !29, !tbaa !15
123 %add1 = add nsw i32 %4, 1, !dbg !29
124 store volatile i32 %add1, i32* @"\01?x@@3HC", align 4, !dbg !29, !tbaa !15
125 %5 = load volatile i32, i32* @"\01?x@@3HC", align 4, !dbg !30, !tbaa !15
126 ret i32 %5, !dbg !31
127 }
128
129 attributes #0 = { norecurse nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
130
131 !llvm.dbg.cu = !{!0}
132 !llvm.module.flags = !{!7, !8, !9}
133 !llvm.ident = !{!10}
134
135 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.9.0 (trunk 275430) (llvm/trunk 275433)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3)
136 !1 = !DIFile(filename: "t.cpp", directory: "D:\5Csrc\5Cllvm\5Cbuild")
137 !2 = !{}
138 !3 = !{!4}
139 !4 = distinct !DIGlobalVariable(name: "x", linkageName: "\01?x@@3HC", scope: !0, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true, variable: i32* @"\01?x@@3HC")
140 !5 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !6)
141 !6 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
142 !7 = !{i32 2, !"CodeView", i32 1}
143 !8 = !{i32 2, !"Debug Info Version", i32 3}
144 !9 = !{i32 1, !"PIC Level", i32 2}
145 !10 = !{!"clang version 3.9.0 (trunk 275430) (llvm/trunk 275433)"}
146 !11 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 8, type: !12, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !2)
147 !12 = !DISubroutineType(types: !13)
148 !13 = !{!6}
149 !14 = !DILocation(line: 9, column: 5, scope: !11)
150 !15 = !{!16, !16, i64 0}
151 !16 = !{!"int", !17, i64 0}
152 !17 = !{!"omnipotent char", !18, i64 0}
153 !18 = !{!"Simple C++ TBAA"}
154 !19 = !DILocation(line: 4, column: 5, scope: !20, inlinedAt: !23)
155 !20 = distinct !DISubprogram(name: "g", linkageName: "\01?g@@YAXXZ", scope: !1, file: !1, line: 3, type: !21, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !2)
156 !21 = !DISubroutineType(types: !22)
157 !22 = !{null}
158 !23 = distinct !DILocation(line: 10, column: 3, scope: !11)
159 !24 = !DILocation(line: 2, column: 5, scope: !25, inlinedAt: !27)
160 !25 = distinct !DISubprogram(name: "f", linkageName: "\01?f@@YAXXZ", scope: !26, file: !26, line: 1, type: !21, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !2)
161 !26 = !DIFile(filename: "./t.h", directory: "D:\5Csrc\5Cllvm\5Cbuild")
162 !27 = distinct !DILocation(line: 5, column: 3, scope: !20, inlinedAt: !23)
163 !28 = !DILocation(line: 6, column: 5, scope: !20, inlinedAt: !23)
164 !29 = !DILocation(line: 11, column: 5, scope: !11)
165 !30 = !DILocation(line: 12, column: 10, scope: !11)
166 !31 = !DILocation(line: 12, column: 3, scope: !11)
181181 ; OBJ: PtrParent: 0x0
182182 ; OBJ: PtrEnd: 0x0
183183 ; OBJ: Inlinee: bar (0x1002)
184 ; OBJ: BinaryAnnotations [
185 ; OBJ-NEXT: ChangeCodeOffsetAndLineOffset: {CodeOffset: 0x8, LineOffset: 1}
186 ; OBJ-NEXT: ChangeLineOffset: -6
187 ; OBJ-NEXT: ChangeCodeOffset: 0x7
188 ; OBJ-NEXT: ChangeCodeOffsetAndLineOffset: {CodeOffset: 0xA, LineOffset: 1}
189 ; OBJ-NEXT: ChangeCodeOffsetAndLineOffset: {CodeOffset: 0x6, LineOffset: 1}
190 ; OBJ-NEXT: ChangeCodeOffsetAndLineOffset: {CodeOffset: 0x7, LineOffset: 1}
191 ; OBJ-NEXT: ChangeLineOffset: 5
192 ; OBJ-NEXT: ChangeCodeOffset: 0x7
193 ; OBJ-NEXT: ChangeCodeLength: 0x7
194 ; OBJ: ]
184 ; OBJ: BinaryAnnotations [
185 ; OBJ-NEXT: ChangeCodeOffsetAndLineOffset: {CodeOffset: 0x8, LineOffset: 1}
186 ; OBJ-NEXT: ChangeLineOffset: 2
187 ; OBJ-NEXT: ChangeCodeOffset: 0x25
188 ; OBJ-NEXT: ChangeCodeLength: 0x7
189 ; OBJ: ]
195190 ; OBJ: }
196191 ; OBJ: InlineSite {
197192 ; OBJ: PtrParent: 0x0
8989 # CHECK: PtrEnd: 0x0
9090 # CHECK: Inlinee: bar (0x1003)
9191 # CHECK: BinaryAnnotations [
92 # CHECK: ChangeLineOffset: -6
93 # CHECK: ChangeCodeOffset: 0xF
94 # CHECK: ChangeCodeOffsetAndLineOffset: {CodeOffset: 0xA, LineOffset: 1}
95 # CHECK: ChangeCodeOffsetAndLineOffset: {CodeOffset: 0x6, LineOffset: 1}
96 # CHECK: ChangeCodeOffsetAndLineOffset: {CodeOffset: 0x7, LineOffset: 1}
97 # CHECK: ChangeLineOffset: 5
98 # CHECK: ChangeCodeOffset: 0x7
92 # CHECK: ChangeLineOffset: 2
93 # CHECK: ChangeCodeOffset: 0x2D
9994 # CHECK: ChangeCodeLength: 0x7
10095 # CHECK: ]
10196 # CHECK: }