1; RUN: opt < %s -passes='thinlto-pre-link<O2>' -pgo-kind=pgo-sample-use-pipeline -profile-file=%S/Inputs/function_metadata.prof -S | FileCheck %s
2; RUN: opt < %s -passes='thinlto-pre-link<O2>' -pgo-kind=pgo-sample-use-pipeline -profile-file=%S/Inputs/function_metadata.compact.afdo -S | FileCheck %s
3; RUN: opt < %s -passes='pseudo-probe,thinlto-pre-link<O2>' -pgo-kind=pgo-sample-use-pipeline -profile-file=%S/Inputs/pseudo-probe-func-metadata.prof -S | FileCheck %s
4
5; Tests whether the functions in the inline stack are added to the
6; function_entry_count metadata.
7
8declare void @foo()
9
10declare void @bar()
11
12declare !dbg !13 void @bar_dbg()
13
14define void @bar_available() #0 !dbg !14 {
15  ret void
16}
17
18; CHECK: define void @test({{.*}} !prof ![[ENTRY_TEST:[0-9]+]]
19define void @test(void ()*) #0 !dbg !7 {
20  %2 = alloca void ()*
21  store void ()* %0, void ()** %2
22  %3 = load void ()*, void ()** %2
23  ; CHECK: call {{.*}}, !prof ![[PROF:[0-9]+]]
24  call void @foo(), !dbg !18
25  call void %3(), !dbg !19
26  ret void
27}
28
29; CHECK: define void @test_liveness({{.*}} !prof ![[ENTRY_TEST_LIVENESS:[0-9]+]]
30define void @test_liveness() #0 !dbg !12 {
31  call void @foo(), !dbg !20
32  ret void
33}
34
35; GUIDs of foo, bar, foo1, foo2 and foo3 should be included in the metadata to
36; make sure hot inline stacks are imported. The total count of baz is lower
37; than the hot cutoff threshold and its GUID should not be included in the
38; metadata.
39; CHECK: ![[ENTRY_TEST]] = !{!"function_entry_count", i64 1, i64 2494702099028631698, i64 6699318081062747564, i64 7682762345278052905,  i64 -7908226060800700466, i64 -2012135647395072713}
40
41; Check GUIDs for foo, bar and bar_dbg are included in the metadata to
42; make sure the liveness analysis can capture the dependency from test_liveness
43; to bar. bar_available should not be included as it's within the same module.
44; CHECK: ![[ENTRY_TEST_LIVENESS]] = !{!"function_entry_count", i64 1, i64 6699318081062747564, i64 -2012135647395072713, i64 -1522495160813492905}
45
46attributes #0 = {"use-sample-profile"}
47
48!llvm.dbg.cu = !{!0}
49!llvm.module.flags = !{!8, !9}
50!llvm.ident = !{!10}
51
52!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5 ", isOptimized: false, emissionKind: NoDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
53!1 = !DIFile(filename: "calls.cc", directory: ".")
54!2 = !{}
55!6 = !DISubroutineType(types: !2)
56!7 = distinct !DISubprogram(name: "test", line: 7, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 7, file: !1, scope: !1, type: !6, retainedNodes: !2)
57!8 = !{i32 2, !"Dwarf Version", i32 4}
58!9 = !{i32 1, !"Debug Info Version", i32 3}
59!10 = !{!"clang version 3.5 "}
60!12 = distinct !DISubprogram(name: "test_liveness", line: 7, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 7, file: !1, scope: !1, type: !6, retainedNodes: !2)
61!13 = !DISubprogram(name: "bar_dbg", scope: !1, file: !1, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
62!14 = distinct !DISubprogram(name: "bar_available", line: 7, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 7, file: !1, scope: !1, type: !6, retainedNodes: !2)
63!15 = !DILexicalBlockFile(discriminator: 1, file: !1, scope: !7)
64!17 = distinct !DILexicalBlock(line: 10, column: 0, file: !1, scope: !7)
65!18 = !DILocation(line: 10, scope: !17)
66!19 = !DILocation(line: 11, scope: !17)
67!20 = !DILocation(line: 8, scope: !12)
68