xref: /llvm-project/llvm/test/Transforms/SampleProfile/csspgo-import-list-callee-samples.ll (revision bfefeeb13952f0ab47ccc186b63e0aadc6a4efe0)
1; RUN: opt < %s -passes='thinlto-pre-link<O2>' -pgo-kind=pgo-sample-use-pipeline -sample-profile-file=%S/Inputs/csspgo-import-list-callee-samples.prof  -S | FileCheck %s
2
3; Original source code:
4
5; file1.c:
6;
7; int a = 1;
8; int bar(int x);
9;
10; int(*foo())()  {
11;  a++;
12;  return bar;
13; };
14
15; __attribute__((noinline)) void func()
16; {
17;     int (*fptr)(int);
18;     fptr = foo();
19;     a +=  (*fptr)(10);
20; }
21
22; int main() {
23;   for(int i = 0; i < 1000 * 1000; i++)
24;     func();
25; }
26
27; file2.c:
28;
29; int bar(int x) { return x + 1;}
30
31
32
33; GUID for bar is -2012135647395072713, make sure bar is not imported.
34; CHECK: ![[#]] = !{!"function_entry_count", i64 1557}
35; CHECK-NOT: ![[#]] = !{!"function_entry_count", i64 1557, i64 -2012135647395072713}
36
37@a = dso_local global i32 1, align 4
38
39; Function Attrs: nounwind uwtable
40define dso_local ptr @foo() #0 !dbg !11 {
41entry:
42  call void @llvm.pseudoprobe(i64 6699318081062747564, i64 1, i32 0, i64 -1), !dbg !14
43  %0 = load volatile i32, ptr @a, align 4, !dbg !14, !tbaa !15
44  %inc = add nsw i32 %0, 1, !dbg !14
45  store volatile i32 %inc, ptr @a, align 4, !dbg !14, !tbaa !15
46  ret ptr @bar, !dbg !19
47}
48
49declare dso_local i32 @bar(i32 noundef) #1
50
51; Function Attrs: noinline nounwind uwtable
52define dso_local void @func() #2 !dbg !20 {
53entry:
54  call void @llvm.pseudoprobe(i64 7289175272376759421, i64 1, i32 0, i64 -1), !dbg !21
55  %call = call ptr @foo(), !dbg !22
56  %call1 = call i32 %call(i32 noundef 10), !dbg !24
57  %0 = load volatile i32, ptr @a, align 4, !dbg !26, !tbaa !15
58  %add = add nsw i32 %0, %call1, !dbg !26
59  store volatile i32 %add, ptr @a, align 4, !dbg !26, !tbaa !15
60  ret void, !dbg !27
61}
62
63; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
64declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #3
65
66; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
67declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #3
68
69; Function Attrs: nounwind uwtable
70define dso_local i32 @main() #0 !dbg !28 {
71entry:
72  call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 1, i32 0, i64 -1), !dbg !29
73  br label %for.cond, !dbg !30
74
75for.cond:                                         ; preds = %for.body, %entry
76  %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ], !dbg !31
77  call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 2, i32 0, i64 -1), !dbg !32
78  %cmp = icmp slt i32 %i.0, 1000000, !dbg !34
79  br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !36
80
81for.cond.cleanup:                                 ; preds = %for.cond
82  call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 3, i32 0, i64 -1), !dbg !37
83  call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 6, i32 0, i64 -1), !dbg !38
84  ret i32 0, !dbg !38
85
86for.body:                                         ; preds = %for.cond
87  call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 4, i32 0, i64 -1), !dbg !39
88  call void @func(), !dbg !40
89  call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 5, i32 0, i64 -1), !dbg !42
90  %inc = add nsw i32 %i.0, 1, !dbg !43
91  br label %for.cond, !dbg !45, !llvm.loop !46
92}
93
94; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite)
95declare void @llvm.pseudoprobe(i64, i64, i32, i64) #4
96
97attributes #0 = { nounwind uwtable "disable-tail-calls"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "use-sample-profile" }
98attributes #1 = { "disable-tail-calls"="true" "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
99attributes #2 = { noinline nounwind uwtable "disable-tail-calls"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "use-sample-profile" }
100attributes #3 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
101attributes #4 = { mustprogress nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite) }
102
103!llvm.dbg.cu = !{!0}
104!llvm.module.flags = !{!2, !3, !4, !5, !6}
105!llvm.ident = !{!7}
106!llvm.pseudo_probe_desc = !{!8, !9, !10}
107
108!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 17.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: NoDebug, splitDebugInlining: false, debugInfoForProfiling: true, nameTableKind: None)
109!1 = !DIFile(filename: "file.c", directory: "/tmp/")
110!2 = !{i32 2, !"Debug Info Version", i32 3}
111!3 = !{i32 1, !"wchar_size", i32 4}
112!4 = !{i32 7, !"uwtable", i32 2}
113!5 = !{i32 7, !"frame-pointer", i32 2}
114!6 = !{i32 1, !"EnableSplitLTOUnit", i32 0}
115!7 = !{!"clang version 17.0.0"}
116!8 = !{i64 6699318081062747564, i64 4294967295, !"foo"}
117!9 = !{i64 7289175272376759421, i64 562954248388607, !"func"}
118!10 = !{i64 -2624081020897602054, i64 281582081721716, !"main"}
119!11 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 6, type: !12, scopeLine: 6, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
120!12 = !DISubroutineType(types: !13)
121!13 = !{}
122!14 = !DILocation(line: 7, column: 4, scope: !11)
123!15 = !{!16, !16, i64 0}
124!16 = !{!"int", !17, i64 0}
125!17 = !{!"omnipotent char", !18, i64 0}
126!18 = !{!"Simple C/C++ TBAA"}
127!19 = !DILocation(line: 8, column: 3, scope: !11)
128!20 = distinct !DISubprogram(name: "func", scope: !1, file: !1, line: 11, type: !12, scopeLine: 12, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
129!21 = !DILocation(line: 14, column: 12, scope: !20)
130!22 = !DILocation(line: 14, column: 12, scope: !23)
131!23 = !DILexicalBlockFile(scope: !20, file: !1, discriminator: 186646551)
132!24 = !DILocation(line: 15, column: 11, scope: !25)
133!25 = !DILexicalBlockFile(scope: !20, file: !1, discriminator: 119537695)
134!26 = !DILocation(line: 15, column: 7, scope: !20)
135!27 = !DILocation(line: 16, column: 1, scope: !20)
136!28 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 18, type: !12, scopeLine: 18, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
137!29 = !DILocation(line: 19, column: 11, scope: !28)
138!30 = !DILocation(line: 19, column: 7, scope: !28)
139!31 = !DILocation(line: 19, scope: !28)
140!32 = !DILocation(line: 19, column: 18, scope: !33)
141!33 = !DILexicalBlockFile(scope: !28, file: !1, discriminator: 0)
142!34 = !DILocation(line: 19, column: 20, scope: !35)
143!35 = !DILexicalBlockFile(scope: !28, file: !1, discriminator: 2)
144!36 = !DILocation(line: 19, column: 3, scope: !35)
145!37 = !DILocation(line: 0, scope: !28)
146!38 = !DILocation(line: 21, column: 1, scope: !28)
147!39 = !DILocation(line: 20, column: 5, scope: !28)
148!40 = !DILocation(line: 20, column: 5, scope: !41)
149!41 = !DILexicalBlockFile(scope: !28, file: !1, discriminator: 186646591)
150!42 = !DILocation(line: 19, column: 36, scope: !33)
151!43 = !DILocation(line: 19, column: 36, scope: !44)
152!44 = !DILexicalBlockFile(scope: !28, file: !1, discriminator: 4)
153!45 = !DILocation(line: 19, column: 3, scope: !44)
154!46 = distinct !{!46, !47, !48, !49}
155!47 = !DILocation(line: 19, column: 3, scope: !28)
156!48 = !DILocation(line: 20, column: 10, scope: !28)
157!49 = !{!"llvm.loop.mustprogress"}
158