1; Test to check the callgraph in summary when there is PGO
2; RUN: opt -module-summary %s -o %t.o
3; RUN: llvm-bcanalyzer -dump %t.o | FileCheck %s
4; RUN: llvm-dis %t.o
5; RUN: cat %t.o.ll | FileCheck %s --check-prefix=DIS
6
7; Make sure the assembler doesn't error when parsing the summary
8; RUN: llvm-as %t.o.ll
9
10; Check assembled summary.
11; RUN: llvm-dis %t.o.bc -o - | FileCheck %s --check-prefix=DIS
12
13; RUN: opt -module-summary %p/Inputs/thinlto-function-summary-callgraph-profile-summary.ll -o %t2.o
14; RUN: llvm-lto -thinlto -o %t3 %t.o %t2.o
15; RUN: llvm-bcanalyzer -dump %t3.thinlto.bc | FileCheck %s --check-prefix=COMBINED
16; RUN: llvm-dis %t3.thinlto.bc
17; RUN: cat %t3.thinlto.ll | FileCheck %s --check-prefix=COMBINED-DIS
18; Round trip it through llvm-as
19; RUN: cat %t3.thinlto.ll | llvm-as -o - | llvm-dis -o - | FileCheck %s --check-prefix=COMBINED-DIS
20
21; Make sure the assembler doesn't error when parsing the combined summary
22; RUN: llvm-as %t3.thinlto.ll -o %t3.thinlto.o
23
24; Check assembled combined summary.
25; RUN: llvm-dis %t3.thinlto.o -o - | FileCheck %s --check-prefix=COMBINED-DIS
26
27
28; CHECK: <SOURCE_FILENAME
29; "hot_function"
30; CHECK-NEXT: <FUNCTION op0=0 op1=12
31; "hot1"
32; CHECK-NEXT: <FUNCTION op0=12 op1=4
33; "hot2"
34; CHECK-NEXT: <FUNCTION op0=16 op1=4
35; "hot3"
36; CHECK-NEXT: <FUNCTION op0=20 op1=4
37; "hot4"
38; CHECK-NEXT: <FUNCTION op0=24 op1=4
39; "cold"
40; CHECK-NEXT: <FUNCTION op0=28 op1=4
41; "none1"
42; CHECK-NEXT: <FUNCTION op0=32 op1=5
43; "none2"
44; CHECK-NEXT: <FUNCTION op0=37 op1=5
45; "none3"
46; CHECK-NEXT: <FUNCTION op0=42 op1=5
47; CHECK-LABEL:       <GLOBALVAL_SUMMARY_BLOCK
48; CHECK-NEXT:    <VERSION
49; CHECK-NEXT:    <FLAGS
50; CHECK-NEXT:    <VALUE_GUID op0=25 op1=123/>
51; op4=hot1 op6=cold op8=hot2 op10=hot4 op12=none1 op14=hot3 op16=none2 op18=none3 op20=123
52; CHECK-NEXT:    <PERMODULE_PROFILE {{.*}} op7=1 op8=3 op9=5 op10=1 op11=2 op12=3 op13=4 op14=1 op15=6 op16=2 op17=3 op18=3 op19=7 op20=2 op21=8 op22=2 op23=25 op24=4/>
53; CHECK-NEXT:    <BLOCK_COUNT op0=6/>
54; CHECK-NEXT:  </GLOBALVAL_SUMMARY_BLOCK>
55
56; CHECK: <STRTAB_BLOCK
57; CHECK-NEXT: blob data = 'hot_functionhot1hot2hot3hot4coldnone1none2none3{{.*}}'
58
59; COMBINED:       <GLOBALVAL_SUMMARY_BLOCK
60; COMBINED-NEXT:    <VERSION
61; COMBINED-NEXT:    <FLAGS
62; COMBINED-NEXT:    <VALUE_GUID
63; COMBINED-NEXT:    <VALUE_GUID
64; COMBINED-NEXT:    <VALUE_GUID
65; COMBINED-NEXT:    <VALUE_GUID
66; COMBINED-NEXT:    <VALUE_GUID
67; COMBINED-NEXT:    <VALUE_GUID
68; COMBINED-NEXT:    <VALUE_GUID
69; COMBINED-NEXT:    <VALUE_GUID
70; COMBINED-NEXT:    <COMBINED abbrevid=
71; COMBINED-NEXT:    <COMBINED abbrevid=
72; COMBINED-NEXT:    <COMBINED abbrevid=
73; COMBINED-NEXT:    <COMBINED abbrevid=
74; COMBINED-NEXT:    <COMBINED abbrevid=
75; COMBINED-NEXT:    <COMBINED abbrevid=
76; COMBINED-NEXT:    <COMBINED_PROFILE {{.*}} op9=[[HOT1:.*]] op10=3 op11=[[COLD:.*]] op12=1 op13=[[HOT2:.*]] op14=3 op15=[[NONE1:.*]] op16=2 op17=[[HOT3:.*]] op18=3 op19=[[NONE2:.*]] op20=2 op21=[[NONE3:.*]] op22=2/>
77; COMBINED-NEXT:    <COMBINED abbrevid=
78; COMBINED-NEXT:    <BLOCK_COUNT op0=13/>
79; COMBINED-NEXT:  </GLOBALVAL_SUMMARY_BLOCK>
80
81
82; ModuleID = 'thinlto-function-summary-callgraph.ll'
83target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
84target triple = "x86_64-unknown-linux-gnu"
85
86; This function have high profile count, so entry block is hot.
87define void @hot_function(i1 %a, i1 %a2) !prof !20 {
88entry:
89    call void @hot1()
90    br i1 %a, label %Cold, label %Hot, !prof !41
91Cold:           ; 1/1000 goes here
92  call void @cold()
93  call void @hot2()
94  call void @hot4(), !prof !15
95  call void @none1()
96  br label %exit
97Hot:            ; 999/1000 goes here
98  call void @hot2()
99  call void @hot3()
100  br i1 %a2, label %None1, label %None2, !prof !42
101None1:          ; half goes here
102  call void @none1()
103  call void @none2()
104  br label %exit
105None2:          ; half goes here
106  call void @none3()
107  br label %exit
108exit:
109  ret void
110}
111
112declare void @hot1() #1
113declare void @hot2() #1
114declare void @hot3() #1
115declare void @hot4() #1
116declare void @cold() #1
117declare void @none1() #1
118declare void @none2() #1
119declare void @none3() #1
120
121
122!41 = !{!"branch_weights", i32 1, i32 1000}
123!42 = !{!"branch_weights", i32 1, i32 1}
124
125
126
127!llvm.module.flags = !{!1}
128!20 = !{!"function_entry_count", i64 110, i64 123}
129
130!1 = !{i32 1, !"ProfileSummary", !2}
131!2 = !{!3, !4, !5, !6, !7, !8, !9, !10}
132!3 = !{!"ProfileFormat", !"InstrProf"}
133!4 = !{!"TotalCount", i64 10000}
134!5 = !{!"MaxCount", i64 10}
135!6 = !{!"MaxInternalCount", i64 1}
136!7 = !{!"MaxFunctionCount", i64 1000}
137!8 = !{!"NumCounts", i64 3}
138!9 = !{!"NumFunctions", i64 3}
139!10 = !{!"DetailedSummary", !11}
140!11 = !{!12, !13, !14}
141!12 = !{i32 10000, i64 100, i32 1}
142!13 = !{i32 999000, i64 100, i32 1}
143!14 = !{i32 999999, i64 1, i32 2}
144!15 = !{!"branch_weights", i32 100}
145
146; DIS: ^0 = module: (path: "{{.*}}thinlto-function-summary-callgraph-profile-summary.ll.tmp.o{{.*}}", hash: (0, 0, 0, 0, 0))
147; DIS: ^1 = gv: (guid: 123)
148; DIS: ^2 = gv: (name: "none2") ; guid = 3741006263754194003
149; DIS: ^3 = gv: (name: "hot3") ; guid = 5026609803865204483
150; DIS: ^4 = gv: (name: "hot2") ; guid = 8117347573235780485
151; DIS: ^5 = gv: (name: "hot1") ; guid = 9453975128311291976
152; DIS: ^6 = gv: (name: "cold") ; guid = 11668175513417606517
153; DIS: ^7 = gv: (name: "hot4") ; guid = 13161834114071272798
154; DIS: ^8 = gv: (name: "none3") ; guid = 16213681105727317812
155; DIS: ^9 = gv: (name: "hot_function", summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), insts: 16, calls: ((callee: ^5, hotness: hot), (callee: ^6, hotness: cold), (callee: ^4, hotness: hot), (callee: ^7, hotness: cold), (callee: ^10, hotness: none), (callee: ^3, hotness: hot), (callee: ^2, hotness: none), (callee: ^8, hotness: none), (callee: ^1, hotness: critical))))) ; guid = 17381606045411660303
156; DIS: ^10 = gv: (name: "none1") ; guid = 17712061229457633252
157
158; COMBINED-DIS: ^0 = module: (path: "{{.*}}thinlto-function-summary-callgraph-profile-summary.ll.tmp.o", hash: (0, 0, 0, 0, 0))
159; COMBINED-DIS: ^1 = module: (path: "{{.*}}thinlto-function-summary-callgraph-profile-summary.ll.tmp2.o", hash: (0, 0, 0, 0, 0))
160; COMBINED-DIS: ^2 = gv: (guid: 3741006263754194003, summaries: (function: (module: ^1, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), insts: 1)))
161; COMBINED-DIS: ^3 = gv: (guid: 5026609803865204483, summaries: (function: (module: ^1, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), insts: 1)))
162; COMBINED-DIS: ^4 = gv: (guid: 8117347573235780485, summaries: (function: (module: ^1, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), insts: 1)))
163; COMBINED-DIS: ^5 = gv: (guid: 9453975128311291976, summaries: (function: (module: ^1, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), insts: 1)))
164; COMBINED-DIS: ^6 = gv: (guid: 11668175513417606517, summaries: (function: (module: ^1, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), insts: 1)))
165; COMBINED-DIS: ^7 = gv: (guid: 16213681105727317812, summaries: (function: (module: ^1, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), insts: 1)))
166; COMBINED-DIS: ^8 = gv: (guid: 17381606045411660303, summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), insts: 16, calls: ((callee: ^5, hotness: hot), (callee: ^6, hotness: cold), (callee: ^4, hotness: hot), (callee: ^9, hotness: none), (callee: ^3, hotness: hot), (callee: ^2, hotness: none), (callee: ^7, hotness: none)))))
167; COMBINED-DIS: ^9 = gv: (guid: 17712061229457633252, summaries: (function: (module: ^1, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), insts: 1)))
168