1d9830eb7SPiotr Padlewski; Test to check the callgraph in summary when there is PGO
2d9830eb7SPiotr Padlewski; RUN: opt -module-summary %s -o %t.o
3d9830eb7SPiotr Padlewski; RUN: llvm-bcanalyzer -dump %t.o | FileCheck %s
408d5b4efSTeresa Johnson; RUN: llvm-dis %t.o
508d5b4efSTeresa Johnson; RUN: cat %t.o.ll | FileCheck %s --check-prefix=DIS
608d5b4efSTeresa Johnson
708d5b4efSTeresa Johnson; Make sure the assembler doesn't error when parsing the summary
808d5b4efSTeresa Johnson; RUN: llvm-as %t.o.ll
963ee0e73STeresa Johnson
1063ee0e73STeresa Johnson; Check assembled summary.
1163ee0e73STeresa Johnson; RUN: llvm-dis %t.o.bc -o - | FileCheck %s --check-prefix=DIS
1208d5b4efSTeresa Johnson
13d9830eb7SPiotr Padlewski; RUN: opt -module-summary %p/Inputs/thinlto-function-summary-callgraph-profile-summary.ll -o %t2.o
14d9830eb7SPiotr Padlewski; RUN: llvm-lto -thinlto -o %t3 %t.o %t2.o
15d9830eb7SPiotr Padlewski; RUN: llvm-bcanalyzer -dump %t3.thinlto.bc | FileCheck %s --check-prefix=COMBINED
1608d5b4efSTeresa Johnson; RUN: llvm-dis %t3.thinlto.bc
1708d5b4efSTeresa Johnson; RUN: cat %t3.thinlto.ll | FileCheck %s --check-prefix=COMBINED-DIS
1863ee0e73STeresa Johnson; Round trip it through llvm-as
1963ee0e73STeresa Johnson; RUN: cat %t3.thinlto.ll | llvm-as -o - | llvm-dis -o - | FileCheck %s --check-prefix=COMBINED-DIS
2008d5b4efSTeresa Johnson
2108d5b4efSTeresa Johnson; Make sure the assembler doesn't error when parsing the combined summary
2208d5b4efSTeresa Johnson; RUN: llvm-as %t3.thinlto.ll -o %t3.thinlto.o
2363ee0e73STeresa Johnson
2463ee0e73STeresa Johnson; Check assembled combined summary.
2563ee0e73STeresa Johnson; RUN: llvm-dis %t3.thinlto.o -o - | FileCheck %s --check-prefix=COMBINED-DIS
26d9830eb7SPiotr Padlewski
27d9830eb7SPiotr Padlewski
28a0f371a1SPeter Collingbourne; CHECK: <SOURCE_FILENAME
29a0f371a1SPeter Collingbourne; "hot_function"
30a0f371a1SPeter Collingbourne; CHECK-NEXT: <FUNCTION op0=0 op1=12
31a0f371a1SPeter Collingbourne; "hot1"
32a0f371a1SPeter Collingbourne; CHECK-NEXT: <FUNCTION op0=12 op1=4
33a0f371a1SPeter Collingbourne; "hot2"
34a0f371a1SPeter Collingbourne; CHECK-NEXT: <FUNCTION op0=16 op1=4
35a0f371a1SPeter Collingbourne; "hot3"
36a0f371a1SPeter Collingbourne; CHECK-NEXT: <FUNCTION op0=20 op1=4
37a0f371a1SPeter Collingbourne; "hot4"
38a0f371a1SPeter Collingbourne; CHECK-NEXT: <FUNCTION op0=24 op1=4
39a0f371a1SPeter Collingbourne; "cold"
40a0f371a1SPeter Collingbourne; CHECK-NEXT: <FUNCTION op0=28 op1=4
41a0f371a1SPeter Collingbourne; "none1"
42a0f371a1SPeter Collingbourne; CHECK-NEXT: <FUNCTION op0=32 op1=5
43a0f371a1SPeter Collingbourne; "none2"
44a0f371a1SPeter Collingbourne; CHECK-NEXT: <FUNCTION op0=37 op1=5
45a0f371a1SPeter Collingbourne; "none3"
46a0f371a1SPeter Collingbourne; CHECK-NEXT: <FUNCTION op0=42 op1=5
47d9830eb7SPiotr Padlewski; CHECK-LABEL:       <GLOBALVAL_SUMMARY_BLOCK
48d9830eb7SPiotr Padlewski; CHECK-NEXT:    <VERSION
49290a8398STeresa Johnson; CHECK-NEXT:    <FLAGS
50a0f371a1SPeter Collingbourne; CHECK-NEXT:    <VALUE_GUID op0=25 op1=123/>
51a0f371a1SPeter Collingbourne; op4=hot1 op6=cold op8=hot2 op10=hot4 op12=none1 op14=hot3 op16=none2 op18=none3 op20=123
523aef3528SEugene Leviant; 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/>
53a7fa35a6SHiroshi Yamauchi; CHECK-NEXT:    <BLOCK_COUNT op0=6/>
54d9830eb7SPiotr Padlewski; CHECK-NEXT:  </GLOBALVAL_SUMMARY_BLOCK>
55a0f371a1SPeter Collingbourne
56a0f371a1SPeter Collingbourne; CHECK: <STRTAB_BLOCK
5792648c25SPeter Collingbourne; CHECK-NEXT: blob data = 'hot_functionhot1hot2hot3hot4coldnone1none2none3{{.*}}'
58d9830eb7SPiotr Padlewski
59d9830eb7SPiotr Padlewski; COMBINED:       <GLOBALVAL_SUMMARY_BLOCK
60d9830eb7SPiotr Padlewski; COMBINED-NEXT:    <VERSION
61f3681015STeresa Johnson; COMBINED-NEXT:    <FLAGS
62a0f371a1SPeter Collingbourne; COMBINED-NEXT:    <VALUE_GUID
63a0f371a1SPeter Collingbourne; COMBINED-NEXT:    <VALUE_GUID
64a0f371a1SPeter Collingbourne; COMBINED-NEXT:    <VALUE_GUID
65a0f371a1SPeter Collingbourne; COMBINED-NEXT:    <VALUE_GUID
66a0f371a1SPeter Collingbourne; COMBINED-NEXT:    <VALUE_GUID
67a0f371a1SPeter Collingbourne; COMBINED-NEXT:    <VALUE_GUID
68a0f371a1SPeter Collingbourne; COMBINED-NEXT:    <VALUE_GUID
69a0f371a1SPeter Collingbourne; COMBINED-NEXT:    <VALUE_GUID
70d9830eb7SPiotr Padlewski; COMBINED-NEXT:    <COMBINED abbrevid=
71d9830eb7SPiotr Padlewski; COMBINED-NEXT:    <COMBINED abbrevid=
72d9830eb7SPiotr Padlewski; COMBINED-NEXT:    <COMBINED abbrevid=
73d9830eb7SPiotr Padlewski; COMBINED-NEXT:    <COMBINED abbrevid=
74d9830eb7SPiotr Padlewski; COMBINED-NEXT:    <COMBINED abbrevid=
75d9830eb7SPiotr Padlewski; COMBINED-NEXT:    <COMBINED abbrevid=
763aef3528SEugene Leviant; 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/>
77a7fa35a6SHiroshi Yamauchi; COMBINED-NEXT:    <COMBINED abbrevid=
78a7fa35a6SHiroshi Yamauchi; COMBINED-NEXT:    <BLOCK_COUNT op0=13/>
79a7fa35a6SHiroshi Yamauchi; COMBINED-NEXT:  </GLOBALVAL_SUMMARY_BLOCK>
80d9830eb7SPiotr Padlewski
81d9830eb7SPiotr Padlewski
82d9830eb7SPiotr Padlewski; ModuleID = 'thinlto-function-summary-callgraph.ll'
83d9830eb7SPiotr Padlewskitarget datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
84d9830eb7SPiotr Padlewskitarget triple = "x86_64-unknown-linux-gnu"
85d9830eb7SPiotr Padlewski
86d9830eb7SPiotr Padlewski; This function have high profile count, so entry block is hot.
87d9830eb7SPiotr Padlewskidefine void @hot_function(i1 %a, i1 %a2) !prof !20 {
88d9830eb7SPiotr Padlewskientry:
89d9830eb7SPiotr Padlewski    call void @hot1()
90d9830eb7SPiotr Padlewski    br i1 %a, label %Cold, label %Hot, !prof !41
91d9830eb7SPiotr PadlewskiCold:           ; 1/1000 goes here
92d9830eb7SPiotr Padlewski  call void @cold()
93d9830eb7SPiotr Padlewski  call void @hot2()
94190f17caSDehao Chen  call void @hot4(), !prof !15
95d9830eb7SPiotr Padlewski  call void @none1()
96d9830eb7SPiotr Padlewski  br label %exit
97d9830eb7SPiotr PadlewskiHot:            ; 999/1000 goes here
98d9830eb7SPiotr Padlewski  call void @hot2()
99d9830eb7SPiotr Padlewski  call void @hot3()
100d9830eb7SPiotr Padlewski  br i1 %a2, label %None1, label %None2, !prof !42
101d9830eb7SPiotr PadlewskiNone1:          ; half goes here
102d9830eb7SPiotr Padlewski  call void @none1()
103d9830eb7SPiotr Padlewski  call void @none2()
104d9830eb7SPiotr Padlewski  br label %exit
105d9830eb7SPiotr PadlewskiNone2:          ; half goes here
106d9830eb7SPiotr Padlewski  call void @none3()
107d9830eb7SPiotr Padlewski  br label %exit
108d9830eb7SPiotr Padlewskiexit:
109d9830eb7SPiotr Padlewski  ret void
110d9830eb7SPiotr Padlewski}
111d9830eb7SPiotr Padlewski
112d9830eb7SPiotr Padlewskideclare void @hot1() #1
113d9830eb7SPiotr Padlewskideclare void @hot2() #1
114d9830eb7SPiotr Padlewskideclare void @hot3() #1
115190f17caSDehao Chendeclare void @hot4() #1
116d9830eb7SPiotr Padlewskideclare void @cold() #1
117d9830eb7SPiotr Padlewskideclare void @none1() #1
118d9830eb7SPiotr Padlewskideclare void @none2() #1
119d9830eb7SPiotr Padlewskideclare void @none3() #1
120d9830eb7SPiotr Padlewski
121d9830eb7SPiotr Padlewski
122d9830eb7SPiotr Padlewski!41 = !{!"branch_weights", i32 1, i32 1000}
123d9830eb7SPiotr Padlewski!42 = !{!"branch_weights", i32 1, i32 1}
124d9830eb7SPiotr Padlewski
125d9830eb7SPiotr Padlewski
126d9830eb7SPiotr Padlewski
127d9830eb7SPiotr Padlewski!llvm.module.flags = !{!1}
128a60cdd38SDehao Chen!20 = !{!"function_entry_count", i64 110, i64 123}
129d9830eb7SPiotr Padlewski
130d9830eb7SPiotr Padlewski!1 = !{i32 1, !"ProfileSummary", !2}
131d9830eb7SPiotr Padlewski!2 = !{!3, !4, !5, !6, !7, !8, !9, !10}
132d9830eb7SPiotr Padlewski!3 = !{!"ProfileFormat", !"InstrProf"}
133d9830eb7SPiotr Padlewski!4 = !{!"TotalCount", i64 10000}
134d9830eb7SPiotr Padlewski!5 = !{!"MaxCount", i64 10}
135d9830eb7SPiotr Padlewski!6 = !{!"MaxInternalCount", i64 1}
136d9830eb7SPiotr Padlewski!7 = !{!"MaxFunctionCount", i64 1000}
137d9830eb7SPiotr Padlewski!8 = !{!"NumCounts", i64 3}
138d9830eb7SPiotr Padlewski!9 = !{!"NumFunctions", i64 3}
139d9830eb7SPiotr Padlewski!10 = !{!"DetailedSummary", !11}
140d9830eb7SPiotr Padlewski!11 = !{!12, !13, !14}
141d9830eb7SPiotr Padlewski!12 = !{i32 10000, i64 100, i32 1}
142d9830eb7SPiotr Padlewski!13 = !{i32 999000, i64 100, i32 1}
143d9830eb7SPiotr Padlewski!14 = !{i32 999999, i64 1, i32 2}
144190f17caSDehao Chen!15 = !{!"branch_weights", i32 100}
14508d5b4efSTeresa Johnson
14663ee0e73STeresa Johnson; DIS: ^0 = module: (path: "{{.*}}thinlto-function-summary-callgraph-profile-summary.ll.tmp.o{{.*}}", hash: (0, 0, 0, 0, 0))
14708d5b4efSTeresa Johnson; DIS: ^1 = gv: (guid: 123)
14808d5b4efSTeresa Johnson; DIS: ^2 = gv: (name: "none2") ; guid = 3741006263754194003
14908d5b4efSTeresa Johnson; DIS: ^3 = gv: (name: "hot3") ; guid = 5026609803865204483
15008d5b4efSTeresa Johnson; DIS: ^4 = gv: (name: "hot2") ; guid = 8117347573235780485
15108d5b4efSTeresa Johnson; DIS: ^5 = gv: (name: "hot1") ; guid = 9453975128311291976
15208d5b4efSTeresa Johnson; DIS: ^6 = gv: (name: "cold") ; guid = 11668175513417606517
15308d5b4efSTeresa Johnson; DIS: ^7 = gv: (name: "hot4") ; guid = 13161834114071272798
15408d5b4efSTeresa Johnson; DIS: ^8 = gv: (name: "none3") ; guid = 16213681105727317812
155*54fb3ca9SFangrui Song; DIS: ^9 = gv: (name: "hot_function", summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, 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
15608d5b4efSTeresa Johnson; DIS: ^10 = gv: (name: "none1") ; guid = 17712061229457633252
15708d5b4efSTeresa Johnson
158fb89e7a9STeresa Johnson; COMBINED-DIS: ^0 = module: (path: "{{.*}}thinlto-function-summary-callgraph-profile-summary.ll.tmp.o", hash: (0, 0, 0, 0, 0))
159fb89e7a9STeresa Johnson; COMBINED-DIS: ^1 = module: (path: "{{.*}}thinlto-function-summary-callgraph-profile-summary.ll.tmp2.o", hash: (0, 0, 0, 0, 0))
160*54fb3ca9SFangrui Song; COMBINED-DIS: ^2 = gv: (guid: 3741006263754194003, summaries: (function: (module: ^1, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), insts: 1)))
161*54fb3ca9SFangrui Song; COMBINED-DIS: ^3 = gv: (guid: 5026609803865204483, summaries: (function: (module: ^1, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), insts: 1)))
162*54fb3ca9SFangrui Song; COMBINED-DIS: ^4 = gv: (guid: 8117347573235780485, summaries: (function: (module: ^1, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), insts: 1)))
163*54fb3ca9SFangrui Song; COMBINED-DIS: ^5 = gv: (guid: 9453975128311291976, summaries: (function: (module: ^1, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), insts: 1)))
164*54fb3ca9SFangrui Song; COMBINED-DIS: ^6 = gv: (guid: 11668175513417606517, summaries: (function: (module: ^1, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), insts: 1)))
165*54fb3ca9SFangrui Song; COMBINED-DIS: ^7 = gv: (guid: 16213681105727317812, summaries: (function: (module: ^1, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), insts: 1)))
166*54fb3ca9SFangrui Song; COMBINED-DIS: ^8 = gv: (guid: 17381606045411660303, summaries: (function: (module: ^0, flags: (linkage: external, visibility: default, 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*54fb3ca9SFangrui Song; COMBINED-DIS: ^9 = gv: (guid: 17712061229457633252, summaries: (function: (module: ^1, flags: (linkage: external, visibility: default, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), insts: 1)))
168