xref: /llvm-project/llvm/test/Transforms/SampleProfile/function_metadata.ll (revision 0271ae65a66367d802fa6866599d11e35f68450f)
1cee313d2SEric Christopher; RUN: opt < %s -passes='thinlto-pre-link<O2>' -pgo-kind=pgo-sample-use-pipeline -profile-file=%S/Inputs/function_metadata.prof -S | FileCheck %s
2cee313d2SEric Christopher; 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
37a316c0aSHongtao Yu; 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
4cee313d2SEric Christopher
551ce567bSmodimo;; Validate that with replay in effect, we import call sites even if they are below the threshold
651ce567bSmodimo;; Baseline import decisions
751ce567bSmodimo; 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
851ce567bSmodimo;; With replay decisions
951ce567bSmodimo; 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
1051ce567bSmodimo
1151ce567bSmodimo
12cee313d2SEric Christopher; Tests whether the functions in the inline stack are added to the
13cee313d2SEric Christopher; function_entry_count metadata.
14cee313d2SEric Christopher
15cee313d2SEric Christopherdeclare void @foo()
16cee313d2SEric Christopher
1747c1f274SHongtao Yudeclare void @bar()
1847c1f274SHongtao Yu
1947c1f274SHongtao Yudeclare !dbg !13 void @bar_dbg()
2047c1f274SHongtao Yu
217a6c8942SWei Midefine void @bar_available() #0 !dbg !14 {
22cee313d2SEric Christopher  ret void
23cee313d2SEric Christopher}
24cee313d2SEric Christopher
25cee313d2SEric Christopher; CHECK: define void @test({{.*}} !prof ![[ENTRY_TEST:[0-9]+]]
2651ce567bSmodimo; THRESHOLD: define void @test({{.*}} !prof ![[ENTRY_THRESHOLD:[0-9]+]]
2751ce567bSmodimo; THRESHOLD-REPLAY: define void @test({{.*}} !prof ![[ENTRY_REPLAY_TEST:[0-9]+]]
28*0271ae65SFangrui Songdefine void @test(ptr) #0 !dbg !7 {
29*0271ae65SFangrui Song  %2 = alloca ptr
30*0271ae65SFangrui Song  store ptr %0, ptr %2
31*0271ae65SFangrui Song  %3 = load ptr, ptr %2
32cee313d2SEric Christopher  ; CHECK: call {{.*}}, !prof ![[PROF:[0-9]+]]
33cee313d2SEric Christopher  call void @foo(), !dbg !18
34cee313d2SEric Christopher  call void %3(), !dbg !19
35cee313d2SEric Christopher  ret void
36cee313d2SEric Christopher}
37cee313d2SEric Christopher
38cee313d2SEric Christopher; CHECK: define void @test_liveness({{.*}} !prof ![[ENTRY_TEST_LIVENESS:[0-9]+]]
3951ce567bSmodimo; THRESHOLD: define void @test_liveness({{.*}} !prof ![[ENTRY_THRESHOLD:[0-9]+]]
4051ce567bSmodimo; THRESHOLD-REPLAY: define void @test_liveness({{.*}} !prof ![[ENTRY_REPLAY_TEST_LIVENESS:[0-9]+]]
417a6c8942SWei Midefine void @test_liveness() #0 !dbg !12 {
42cee313d2SEric Christopher  call void @foo(), !dbg !20
43cee313d2SEric Christopher  ret void
44cee313d2SEric Christopher}
45cee313d2SEric Christopher
46cee313d2SEric Christopher; GUIDs of foo, bar, foo1, foo2 and foo3 should be included in the metadata to
47cee313d2SEric Christopher; make sure hot inline stacks are imported. The total count of baz is lower
48cee313d2SEric Christopher; than the hot cutoff threshold and its GUID should not be included in the
49cee313d2SEric Christopher; metadata.
50cee313d2SEric Christopher; CHECK: ![[ENTRY_TEST]] = !{!"function_entry_count", i64 1, i64 2494702099028631698, i64 6699318081062747564, i64 7682762345278052905,  i64 -7908226060800700466, i64 -2012135647395072713}
51cee313d2SEric Christopher
5247c1f274SHongtao Yu; Check GUIDs for foo, bar and bar_dbg are included in the metadata to
53cee313d2SEric Christopher; make sure the liveness analysis can capture the dependency from test_liveness
5447c1f274SHongtao Yu; to bar. bar_available should not be included as it's within the same module.
5547c1f274SHongtao Yu; CHECK: ![[ENTRY_TEST_LIVENESS]] = !{!"function_entry_count", i64 1, i64 6699318081062747564, i64 -2012135647395072713, i64 -1522495160813492905}
56cee313d2SEric Christopher
5751ce567bSmodimo; With high threshold, nothing should be imported
5851ce567bSmodimo; THRESHOLD: ![[ENTRY_THRESHOLD]] = !{!"function_entry_count", i64 1}
5951ce567bSmodimo
6051ce567bSmodimo; 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
6151ce567bSmodimo; THRESHOLD-REPLAY: ![[ENTRY_REPLAY_TEST]] = !{!"function_entry_count", i64 1}
6251ce567bSmodimo; THRESHOLD-REPLAY: ![[ENTRY_REPLAY_TEST_LIVENESS]] = !{!"function_entry_count", i64 1, i64 6699318081062747564, i64 -2012135647395072713, i64 -1522495160813492905}
6351ce567bSmodimo
647a6c8942SWei Miattributes #0 = {"use-sample-profile"}
657a6c8942SWei Mi
66cee313d2SEric Christopher!llvm.dbg.cu = !{!0}
67cee313d2SEric Christopher!llvm.module.flags = !{!8, !9}
68cee313d2SEric Christopher!llvm.ident = !{!10}
69cee313d2SEric Christopher
70cee313d2SEric Christopher!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)
71cee313d2SEric Christopher!1 = !DIFile(filename: "calls.cc", directory: ".")
72cee313d2SEric Christopher!2 = !{}
73cee313d2SEric Christopher!6 = !DISubroutineType(types: !2)
74cee313d2SEric Christopher!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)
75cee313d2SEric Christopher!8 = !{i32 2, !"Dwarf Version", i32 4}
76cee313d2SEric Christopher!9 = !{i32 1, !"Debug Info Version", i32 3}
77cee313d2SEric Christopher!10 = !{!"clang version 3.5 "}
78cee313d2SEric Christopher!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)
7947c1f274SHongtao Yu!13 = !DISubprogram(name: "bar_dbg", scope: !1, file: !1, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
8047c1f274SHongtao Yu!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)
81cee313d2SEric Christopher!15 = !DILexicalBlockFile(discriminator: 1, file: !1, scope: !7)
82cee313d2SEric Christopher!17 = distinct !DILexicalBlock(line: 10, column: 0, file: !1, scope: !7)
83cee313d2SEric Christopher!18 = !DILocation(line: 10, scope: !17)
84cee313d2SEric Christopher!19 = !DILocation(line: 11, scope: !17)
85cee313d2SEric Christopher!20 = !DILocation(line: 8, scope: !12)
86