llvm.org GIT mirror llvm / 478b1ec
[codeview] Use the first valid source location at the top of every MBB If the instructions at the beginning of the block have no location, we're better off using the location of the first instruction in the current basic block. At the very least, that instruction post-dominates this one, whereas if we don't emit a .cv_loc directive, we end up using the potentially invalid location that falls through from the previous block. We could probably do better here by emitting some kind of ".cv_loc end" directive that stops the line table entry of the previous .cv_loc directive from bleeding out of its basic block. This would improve the line table when an entire MBB has no valid location info. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306889 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 2 years ago
4 changed file(s) with 116 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
364364 void CodeViewDebug::maybeRecordLocation(const DebugLoc &DL,
365365 const MachineFunction *MF) {
366366 // Skip this instruction if it has the same location as the previous one.
367 if (DL == CurFn->LastLoc)
367 if (!DL || DL == PrevInstLoc)
368368 return;
369369
370370 const DIScope *Scope = DL.get()->getScope();
384384 if (!CurFn->HaveLineInfo)
385385 CurFn->HaveLineInfo = true;
386386 unsigned FileId = 0;
387 if (CurFn->LastLoc.get() && CurFn->LastLoc->getFile() == DL->getFile())
387 if (PrevInstLoc.get() && PrevInstLoc->getFile() == DL->getFile())
388388 FileId = CurFn->LastFileId;
389389 else
390390 FileId = CurFn->LastFileId = maybeRecordFile(DL->getFile());
391 CurFn->LastLoc = DL;
391 PrevInstLoc = DL;
392392
393393 unsigned FuncId = CurFn->FuncId;
394394 if (const DILocation *SiteLoc = DL->getInlinedAt()) {
21492149 if (!Asm || !CurFn || MI->isDebugValue() ||
21502150 MI->getFlag(MachineInstr::FrameSetup))
21512151 return;
2152
2153 // If the first instruction of a new MBB has no location, find the first
2154 // instruction with a location and use that.
21522155 DebugLoc DL = MI->getDebugLoc();
2153 if (DL == PrevInstLoc || !DL)
2156 if (!DL && MI->getParent() != PrevInstBB) {
2157 for (const auto &NextMI : *MI->getParent()) {
2158 DL = NextMI.getDebugLoc();
2159 if (DL)
2160 break;
2161 }
2162 }
2163 PrevInstBB = MI->getParent();
2164
2165 // If we still don't have a debug location, don't record a location.
2166 if (!DL)
21542167 return;
2168
21552169 maybeRecordLocation(DL, Asm->MF);
21562170 }
21572171
117117
118118 SmallVector Locals;
119119
120 DebugLoc LastLoc;
121120 const MCSymbol *Begin = nullptr;
122121 const MCSymbol *End = nullptr;
123122 unsigned FuncId = 0;
0 ; RUN: llc -O0 < %s | FileCheck %s
1
2 source_filename = "t.c"
3 target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
4 target triple = "i386-pc-windows-msvc19.0.24215"
5
6 @str_const = internal unnamed_addr constant [4 x i8] c"str\00", align 1
7
8 declare i32 @puts(i8*)
9
10 ; We had a line info quality issue where the LEA for the string constant had no
11 ; location info, so the .cv_loc directive appeared after it. Now we have logic
12 ; that tries to emit the first valid location to the top of each MBB.
13
14 define void @lea_str_loc(i1 %cond) !dbg !8 {
15 entry:
16 br i1 %cond, label %if.then, label %if.end, !dbg !17
17
18 if.then: ; preds = %entry
19 br label %return, !dbg !18
20
21 if.end: ; preds = %entry
22 %call = call i32 @puts(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @str_const, i32 0, i32 0)), !dbg !19
23 br label %return, !dbg !20
24
25 return: ; preds = %if.end, %if.then
26 ret void, !dbg !20
27 }
28
29 ; The t.c:5 line marker should appear immediately after the BB label.
30
31 ; CHECK-LABEL: _lea_str_loc:
32 ; CHECK: .cv_loc {{.*}} # t.c:4:5
33 ; CHECK: jmp LBB{{.*}}
34 ; CHECK: LBB0_{{.*}}: # %if.end
35 ; CHECK-NEXT: .cv_loc {{.*}} # t.c:5:3
36 ; CHECK-NEXT: leal _str_const, %[[reg:[^ ]*]]
37 ; CHECK-NEXT: movl %[[reg]], (%esp)
38 ; CHECK-NEXT: calll _puts
39
40 define void @instr_no_loc(i1 %cond) !dbg !21 {
41 entry:
42 br i1 %cond, label %if.then, label %if.end, !dbg !22
43
44 if.then: ; preds = %entry
45 br label %return, !dbg !23
46
47 if.end: ; preds = %entry
48 call void asm sideeffect "nop", ""()
49 %call = call i32 @puts(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @str_const, i32 0, i32 0)), !dbg !24
50 br label %return, !dbg !25
51
52 return: ; preds = %if.end, %if.then
53 ret void, !dbg !25
54 }
55
56 ; CHECK-LABEL: _instr_no_loc:
57 ; CHECK: .cv_loc {{.*}} # t.c:4:5
58 ; CHECK: jmp LBB{{.*}}
59 ; CHECK: LBB1_{{.*}}: # %if.end
60 ; CHECK-NEXT: .cv_loc {{.*}} # t.c:5:3
61 ; CHECK-NEXT: #APP
62 ; CHECK-NEXT: nop
63 ; CHECK-NEXT: #NO_APP
64 ; CHECK-NEXT: leal _str_const, %[[reg:[^ ]*]]
65 ; CHECK-NEXT: movl %[[reg]], (%esp)
66 ; CHECK-NEXT: calll _puts
67
68 !llvm.dbg.cu = !{!0}
69 !llvm.module.flags = !{!3, !4, !5, !6}
70 !llvm.ident = !{!7}
71
72 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 5.0.0 ", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
73 !1 = !DIFile(filename: "t.c", directory: "C:\5Csrc\5Cllvm-project\5Cbuild", checksumkind: CSK_MD5, checksum: "b32df088e991f1996b4e4deb3855c14b")
74 !2 = !{}
75 !3 = !{i32 1, !"NumRegisterParameters", i32 0}
76 !4 = !{i32 2, !"CodeView", i32 1}
77 !5 = !{i32 2, !"Debug Info Version", i32 3}
78 !6 = !{i32 1, !"wchar_size", i32 2}
79 !7 = !{!"clang version 5.0.0 "}
80 !8 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 2, type: !9, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
81 !9 = !DISubroutineType(types: !10)
82 !10 = !{null, !11}
83 !11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
84 !13 = !DIExpression()
85 !14 = !DILocation(line: 2, column: 12, scope: !8)
86 !15 = !DILocation(line: 3, column: 7, scope: !16)
87 !16 = distinct !DILexicalBlock(scope: !8, file: !1, line: 3, column: 7)
88 !17 = !DILocation(line: 3, column: 7, scope: !8)
89 !18 = !DILocation(line: 4, column: 5, scope: !16)
90 !19 = !DILocation(line: 5, column: 3, scope: !8)
91 !20 = !DILocation(line: 6, column: 1, scope: !8)
92 !21 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 2, type: !9, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
93 !22 = !DILocation(line: 3, column: 7, scope: !21)
94 !23 = !DILocation(line: 4, column: 5, scope: !21)
95 !24 = !DILocation(line: 5, column: 3, scope: !21)
96 !25 = !DILocation(line: 6, column: 1, scope: !21)
192192 ; OBJ: ChangeLineOffset: 1
193193 ; OBJ: ChangeCodeOffset: 0x35
194194 ; OBJ: ChangeCodeOffsetAndLineOffset: {CodeOffset: 0xD, LineOffset: 1}
195 ; OBJ: ChangeCodeLength: 0xF
195 ; OBJ: ChangeCodeLength: 0xA
196196 ; OBJ: ]
197197 ; OBJ: }
198198 ; OBJ: Local {