llvm.org GIT mirror llvm / e5920b3
Revert r251680: Update the discriminator assignment algorithm * If a scope has already been assigned a discriminator, do not reassign a nested discriminator for it. * If the file and line both match, even if the column does not match, we should assign a new discriminator for the stmt. original code: ; #1 int foo(int i) { ; #2 if (i == 3 || i == 5) return 100; else return 99; ; #3 } ; i == 3: discriminator 0 ; i == 5: discriminator 2 ; return 100: discriminator 1 ; return 99: discriminator 3 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251685 91177308-0d34-0410-b5e6-96231b3b80d8 Dehao Chen 3 years ago
2 changed file(s) with 11 addition(s) and 110 deletion(s). Raw diff Collapse all Expand all
179179 BasicBlock *Succ = Last->getSuccessor(I);
180180 Instruction *First = Succ->getFirstNonPHIOrDbgOrLifetime();
181181 const DILocation *FirstDIL = First->getDebugLoc();
182 if (!FirstDIL || FirstDIL->getDiscriminator())
182 if (!FirstDIL)
183183 continue;
184184
185185 // If the first instruction (First) of Succ is at the same file
201201 unsigned Discriminator = FirstDIL->computeNewDiscriminator();
202202 auto *NewScope =
203203 Builder.createLexicalBlockFile(Scope, File, Discriminator);
204 auto *NewDIL =
205 DILocation::get(Ctx, FirstDIL->getLine(), FirstDIL->getColumn(),
206 NewScope, FirstDIL->getInlinedAt());
207 DebugLoc newDebugLoc = NewDIL;
204208
205209 // Attach this new debug location to First and every
206210 // instruction following First that shares the same location.
207211 for (BasicBlock::iterator I1(*First), E1 = Succ->end(); I1 != E1;
208212 ++I1) {
209 const DILocation *CurrentDIL = I1->getDebugLoc();
210 if (CurrentDIL && CurrentDIL->getLine() == FirstDIL->getLine() &&
211 CurrentDIL->getFilename() == FirstDIL->getFilename()) {
212 I1->setDebugLoc(DILocation::get(Ctx, CurrentDIL->getLine(),
213 CurrentDIL->getColumn(), NewScope,
214 CurrentDIL->getInlinedAt()));
215 DEBUG(dbgs() << CurrentDIL->getFilename() << ":"
216 << CurrentDIL->getLine() << ":"
217 << CurrentDIL->getColumn() << ":"
218 << CurrentDIL->getDiscriminator() << *I1 << "\n");
219 }
213 if (I1->getDebugLoc().get() != FirstDIL)
214 break;
215 I1->setDebugLoc(newDebugLoc);
216 DEBUG(dbgs() << NewDIL->getFilename() << ":" << NewDIL->getLine()
217 << ":" << NewDIL->getColumn() << ":"
218 << NewDIL->getDiscriminator() << *I1 << "\n");
220219 }
221220 DEBUG(dbgs() << "\n");
222221 Changed = true;
None ; RUN: opt < %s -add-discriminators -S | FileCheck %s
1
2 ; Discriminator support for code that is written in one line:
3 ; #1 int foo(int i) {
4 ; #2 if (i == 3 || i == 5) return 100; else return 99;
5 ; #3 }
6
7 ; i == 3: discriminator 0
8 ; i == 5: discriminator 2
9 ; return 100: discriminator 1
10 ; return 99: discriminator 3
11
12 define i32 @_Z3fooi(i32 %i) #0 {
13 %1 = alloca i32, align 4
14 %2 = alloca i32, align 4
15 store i32 %i, i32* %2, align 4, !tbaa !13
16 call void @llvm.dbg.declare(metadata i32* %2, metadata !9, metadata !17), !dbg !18
17 %3 = load i32, i32* %2, align 4, !dbg !19, !tbaa !13
18 %4 = icmp eq i32 %3, 3, !dbg !21
19 br i1 %4, label %8, label %5, !dbg !22
20
21 ;
22 %6 = load i32, i32* %2, align 4, !dbg !23, !tbaa !13
23 ; CHECK: %6 = load i32, i32* %2, align 4, !dbg ![[THEN1:[0-9]+]],{{.*}}
24
25 %7 = icmp eq i32 %6, 5, !dbg !24
26 ; CHECK: %7 = icmp eq i32 %6, 5, !dbg ![[THEN2:[0-9]+]]
27
28 br i1 %7, label %8, label %9, !dbg !25
29 ; CHECK: br i1 %7, label %8, label %9, !dbg ![[THEN3:[0-9]+]]
30
31 ;
32 store i32 100, i32* %1, align 4, !dbg !26
33 ; CHECK: store i32 100, i32* %1, align 4, !dbg ![[ELSE:[0-9]+]]
34
35 br label %10, !dbg !26
36 ; CHECK: br label %10, !dbg ![[ELSE]]
37
38 ;
39 store i32 99, i32* %1, align 4, !dbg !27
40 ; CHECK: store i32 99, i32* %1, align 4, !dbg ![[COMBINE:[0-9]+]]
41
42 br label %10, !dbg !27
43 ; CHECK: br label %10, !dbg ![[COMBINE]]
44
45 ;
46 %11 = load i32, i32* %1, align 4, !dbg !28
47 ret i32 %11, !dbg !28
48 }
49
50 ; Function Attrs: nounwind readnone
51 declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
52
53 attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
54 attributes #1 = { nounwind readnone }
55
56 !llvm.dbg.cu = !{!0}
57 !llvm.module.flags = !{!10, !11}
58 !llvm.ident = !{!12}
59
60 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.8.0 (trunk 250915)", isOptimized: true, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3)
61 !1 = !DIFile(filename: "a.cc", directory: "/usr/local/google/home/dehao/discr")
62 !2 = !{}
63 !3 = !{!4}
64 !4 = distinct !DISubprogram(name: "foo", linkageName: "_Z3fooi", scope: !1, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, function: i32 (i32)* @_Z3fooi, variables: !8)
65 !5 = !DISubroutineType(types: !6)
66 !6 = !{!7, !7}
67 !7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
68 !8 = !{!9}
69 !9 = !DILocalVariable(name: "i", arg: 1, scope: !4, file: !1, line: 1, type: !7)
70 !10 = !{i32 2, !"Dwarf Version", i32 4}
71 !11 = !{i32 2, !"Debug Info Version", i32 3}
72 !12 = !{!"clang version 3.8.0 (trunk 250915)"}
73 !13 = !{!14, !14, i64 0}
74 !14 = !{!"int", !15, i64 0}
75 !15 = !{!"omnipotent char", !16, i64 0}
76 !16 = !{!"Simple C/C++ TBAA"}
77 !17 = !DIExpression()
78 !18 = !DILocation(line: 1, column: 13, scope: !4)
79 !19 = !DILocation(line: 2, column: 7, scope: !20)
80 !20 = distinct !DILexicalBlock(scope: !4, file: !1, line: 2, column: 7)
81 !21 = !DILocation(line: 2, column: 9, scope: !20)
82 !22 = !DILocation(line: 2, column: 14, scope: !20)
83 !23 = !DILocation(line: 2, column: 17, scope: !20)
84 !24 = !DILocation(line: 2, column: 19, scope: !20)
85 !25 = !DILocation(line: 2, column: 7, scope: !4)
86 !26 = !DILocation(line: 2, column: 25, scope: !20)
87 !27 = !DILocation(line: 2, column: 42, scope: !20)
88 !28 = !DILocation(line: 3, column: 1, scope: !4)
89
90 ; CHECK: ![[THEN1]] = !DILocation(line: 2, column: 17, scope: ![[THENBLOCK:[0-9]+]])
91 ; CHECK: ![[THENBLOCK]] = !DILexicalBlockFile({{.*}} discriminator: 2)
92 ; CHECK: ![[THEN2]] = !DILocation(line: 2, column: 19, scope: ![[THENBLOCK]])
93 ; CHECK: ![[THEN3]] = !DILocation(line: 2, column: 7, scope: ![[THENBLOCK]])
94 ; CHECK: ![[ELSE]] = !DILocation(line: 2, column: 25, scope: ![[ELSEBLOCK:[0-9]+]])
95 ; CHECK: ![[ELSEBLOCK]] = !DILexicalBlockFile({{.*}} discriminator: 1)
96 ; CHECK: ![[COMBINE]] = !DILocation(line: 2, column: 42, scope: ![[COMBINEBLOCK:[0-9]+]])
97 ; CHECK: ![[COMBINEBLOCK]] = !DILexicalBlockFile({{.*}} discriminator: 3)