xref: /llvm-project/llvm/test/Transforms/SampleProfile/function_metadata.ll (revision 0271ae65a66367d802fa6866599d11e35f68450f)
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 -sample-profile-use-profi=0 -S | FileCheck %s
4
5;; Validate that with replay in effect, we import call sites even if they are below the threshold
6;; Baseline import decisions
7; RUN: opt < %s -passes='thinlto-pre-link<O2>' -pgo-kind=pgo-sample-use-pipeline -profile-summary-hot-count=2000 -profile-file=%S/Inputs/function_metadata.prof -S | FileCheck -check-prefix=THRESHOLD %s
8;; With replay decisions
9; RUN: opt < %s -passes='thinlto-pre-link<O2>' -pgo-kind=pgo-sample-use-pipeline -profile-summary-hot-count=2000 -profile-file=%S/Inputs/function_metadata.prof -S -sample-profile-inline-replay-scope=Function -sample-profile-inline-replay=%S/Inputs/function_metadata_replay.txt | FileCheck -check-prefix=THRESHOLD-REPLAY %s
10
11
12; Tests whether the functions in the inline stack are added to the
13; function_entry_count metadata.
14
15declare void @foo()
16
17declare void @bar()
18
19declare !dbg !13 void @bar_dbg()
20
21define void @bar_available() #0 !dbg !14 {
22  ret void
23}
24
25; CHECK: define void @test({{.*}} !prof ![[ENTRY_TEST:[0-9]+]]
26; THRESHOLD: define void @test({{.*}} !prof ![[ENTRY_THRESHOLD:[0-9]+]]
27; THRESHOLD-REPLAY: define void @test({{.*}} !prof ![[ENTRY_REPLAY_TEST:[0-9]+]]
28define void @test(ptr) #0 !dbg !7 {
29  %2 = alloca ptr
30  store ptr %0, ptr %2
31  %3 = load ptr, ptr %2
32  ; CHECK: call {{.*}}, !prof ![[PROF:[0-9]+]]
33  call void @foo(), !dbg !18
34  call void %3(), !dbg !19
35  ret void
36}
37
38; CHECK: define void @test_liveness({{.*}} !prof ![[ENTRY_TEST_LIVENESS:[0-9]+]]
39; THRESHOLD: define void @test_liveness({{.*}} !prof ![[ENTRY_THRESHOLD:[0-9]+]]
40; THRESHOLD-REPLAY: define void @test_liveness({{.*}} !prof ![[ENTRY_REPLAY_TEST_LIVENESS:[0-9]+]]
41define void @test_liveness() #0 !dbg !12 {
42  call void @foo(), !dbg !20
43  ret void
44}
45
46; GUIDs of foo, bar, foo1, foo2 and foo3 should be included in the metadata to
47; make sure hot inline stacks are imported. The total count of baz is lower
48; than the hot cutoff threshold and its GUID should not be included in the
49; metadata.
50; CHECK: ![[ENTRY_TEST]] = !{!"function_entry_count", i64 1, i64 2494702099028631698, i64 6699318081062747564, i64 7682762345278052905,  i64 -7908226060800700466, i64 -2012135647395072713}
51
52; Check GUIDs for foo, bar and bar_dbg are included in the metadata to
53; make sure the liveness analysis can capture the dependency from test_liveness
54; to bar. bar_available should not be included as it's within the same module.
55; CHECK: ![[ENTRY_TEST_LIVENESS]] = !{!"function_entry_count", i64 1, i64 6699318081062747564, i64 -2012135647395072713, i64 -1522495160813492905}
56
57; With high threshold, nothing should be imported
58; THRESHOLD: ![[ENTRY_THRESHOLD]] = !{!"function_entry_count", i64 1}
59
60; With high threshold and replay, sites that are in the replay (foo, and transitively bar and bar_dbg in function test_liveness) should be imported
61; THRESHOLD-REPLAY: ![[ENTRY_REPLAY_TEST]] = !{!"function_entry_count", i64 1}
62; THRESHOLD-REPLAY: ![[ENTRY_REPLAY_TEST_LIVENESS]] = !{!"function_entry_count", i64 1, i64 6699318081062747564, i64 -2012135647395072713, i64 -1522495160813492905}
63
64attributes #0 = {"use-sample-profile"}
65
66!llvm.dbg.cu = !{!0}
67!llvm.module.flags = !{!8, !9}
68!llvm.ident = !{!10}
69
70!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)
71!1 = !DIFile(filename: "calls.cc", directory: ".")
72!2 = !{}
73!6 = !DISubroutineType(types: !2)
74!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)
75!8 = !{i32 2, !"Dwarf Version", i32 4}
76!9 = !{i32 1, !"Debug Info Version", i32 3}
77!10 = !{!"clang version 3.5 "}
78!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)
79!13 = !DISubprogram(name: "bar_dbg", scope: !1, file: !1, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
80!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)
81!15 = !DILexicalBlockFile(discriminator: 1, file: !1, scope: !7)
82!17 = distinct !DILexicalBlock(line: 10, column: 0, file: !1, scope: !7)
83!18 = !DILocation(line: 10, scope: !17)
84!19 = !DILocation(line: 11, scope: !17)
85!20 = !DILocation(line: 8, scope: !12)
86