llvm.org GIT mirror llvm / b16171e
Add discriminators for call instructions that are from the same line and same basic block. Summary: Call instructions that are from the same line and same basic block needs to have separate discriminators to distinguish between different callsites. Reviewers: davidxl, dnovillo, dblaikie Subscribers: dblaikie, probinson, llvm-commits Differential Revision: http://reviews.llvm.org/D14464 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252492 91177308-0d34-0410-b5e6-96231b3b80d8 Dehao Chen 3 years ago
2 changed file(s) with 80 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
223223 }
224224 }
225225 }
226
227 // Traverse all instructions and assign new discriminators to call
228 // instructions with the same lineno that are in the same basic block.
229 // Sample base profile needs to distinguish different function calls within
230 // a same source line for correct profile annotation.
231 for (BasicBlock &B : F) {
232 const DILocation *FirstDIL = NULL;
233 for (auto &I : B.getInstList()) {
234 CallInst *Current = dyn_cast(&I);
235 if (Current) {
236 DILocation *CurrentDIL = Current->getDebugLoc();
237 if (FirstDIL) {
238 if (CurrentDIL && CurrentDIL->getLine() == FirstDIL->getLine() &&
239 CurrentDIL->getFilename() == FirstDIL->getFilename()) {
240 auto *Scope = FirstDIL->getScope();
241 auto *File = Builder.createFile(FirstDIL->getFilename(),
242 Scope->getDirectory());
243 auto *NewScope = Builder.createLexicalBlockFile(
244 Scope, File, FirstDIL->computeNewDiscriminator());
245 Current->setDebugLoc(DILocation::get(
246 Ctx, CurrentDIL->getLine(), CurrentDIL->getColumn(), NewScope,
247 CurrentDIL->getInlinedAt()));
248 Changed = true;
249 } else {
250 FirstDIL = CurrentDIL;
251 }
252 } else {
253 FirstDIL = CurrentDIL;
254 }
255 }
256 }
257 }
226258 return Changed;
227259 }
0 ; RUN: opt < %s -add-discriminators -S | FileCheck %s
1
2 ; Discriminator support for calls that are defined in one line:
3 ; #1 void bar();
4 ; #2
5 ; #3 void foo() {
6 ; #4 bar();bar()/*discriminator 1*/;bar()/*discriminator 2*/;
7 ; #5 }
8
9 ; Function Attrs: uwtable
10 define void @_Z3foov() #0 {
11 call void @_Z3barv(), !dbg !10
12 ; CHECK: call void @_Z3barv(), !dbg ![[CALL0:[0-9]+]]
13 call void @_Z3barv(), !dbg !11
14 ; CHECK: call void @_Z3barv(), !dbg ![[CALL1:[0-9]+]]
15 call void @_Z3barv(), !dbg !12
16 ; CHECK: call void @_Z3barv(), !dbg ![[CALL2:[0-9]+]]
17 ret void, !dbg !13
18 }
19
20 declare void @_Z3barv() #1
21
22 attributes #0 = { uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "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" }
23 attributes #1 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "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" }
24
25 !llvm.dbg.cu = !{!0}
26 !llvm.module.flags = !{!7, !8}
27 !llvm.ident = !{!9}
28
29 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.8.0 (trunk 250915) (llvm/trunk 251830)", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3)
30 !1 = !DIFile(filename: "c.cc", directory: "/tmp")
31 !2 = !{}
32 !3 = !{!4}
33 !4 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !1, file: !1, line: 3, type: !5, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: false, variables: !2)
34 !5 = !DISubroutineType(types: !6)
35 !6 = !{null}
36 !7 = !{i32 2, !"Dwarf Version", i32 4}
37 !8 = !{i32 2, !"Debug Info Version", i32 3}
38 !9 = !{!"clang version 3.8.0 (trunk 250915) (llvm/trunk 251830)"}
39 !10 = !DILocation(line: 4, column: 3, scope: !4)
40 !11 = !DILocation(line: 4, column: 9, scope: !4)
41 !12 = !DILocation(line: 4, column: 15, scope: !4)
42 !13 = !DILocation(line: 5, column: 1, scope: !4)
43
44 ; CHECK: ![[CALL1]] = !DILocation(line: 4, column: 9, scope: ![[CALL1BLOCK:[0-9]+]])
45 ; CHECK: ![[CALL1BLOCK]] = !DILexicalBlockFile({{.*}} discriminator: 1)
46 ; CHECK: ![[CALL2]] = !DILocation(line: 4, column: 15, scope: ![[CALL2BLOCK:[0-9]+]])
47 ; CHECK: ![[CALL2BLOCK]] = !DILexicalBlockFile({{.*}} discriminator: 2)