1 ;; Test callsite context graph generation for simple call graph with
2 ;; two memprof contexts and no inlining.
4 ;; Original code looks like:
7 ;; return new char[10];
18 ;; int main(int argc, char **argv) {
29 ;; Code compiled with -mllvm -memprof-ave-lifetime-cold-threshold=5 so that the
30 ;; memory freed after sleep(10) results in cold lifetimes.
32 ;; The IR was then reduced using llvm-reduce with the expected FileCheck input.
34 ;; -stats requires asserts
37 ; RUN: opt -thinlto-bc -memprof-report-hinted-sizes %s >%t.o
38 ; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \
39 ; RUN: -supports-hot-cold-new \
40 ; RUN: -r=%t.o,main,plx \
41 ; RUN: -r=%t.o,_ZdaPv, \
42 ; RUN: -r=%t.o,sleep, \
43 ; RUN: -r=%t.o,_Znam, \
44 ; RUN: -memprof-verify-ccg -memprof-verify-nodes -memprof-dump-ccg \
45 ; RUN: -memprof-export-to-dot -memprof-dot-file-path-prefix=%t. \
46 ; RUN: -memprof-report-hinted-sizes \
47 ; RUN: -stats -pass-remarks=memprof-context-disambiguation -save-temps \
48 ; RUN: -o %t.out 2>&1 | FileCheck %s --check-prefix=DUMP \
49 ; RUN: --check-prefix=STATS --check-prefix=STATS-BE --check-prefix=REMARKS \
50 ; RUN: --check-prefix=SIZES
52 ; RUN: cat %t.ccg.postbuild.dot | FileCheck %s --check-prefix=DOT
53 ;; We should have cloned bar, baz, and foo, for the cold memory allocation.
54 ; RUN: cat %t.ccg.cloned.dot | FileCheck %s --check-prefix=DOTCLONED
56 ; RUN: llvm-dis %t.out.1.4.opt.bc -o - | FileCheck %s --check-prefix=IR
59 ;; Try again but with distributed ThinLTO
60 ; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \
61 ; RUN: -supports-hot-cold-new \
62 ; RUN: -thinlto-distributed-indexes \
63 ; RUN: -r=%t.o,main,plx \
64 ; RUN: -r=%t.o,_ZdaPv, \
65 ; RUN: -r=%t.o,sleep, \
66 ; RUN: -r=%t.o,_Znam, \
67 ; RUN: -memprof-verify-ccg -memprof-verify-nodes -memprof-dump-ccg \
68 ; RUN: -memprof-export-to-dot -memprof-dot-file-path-prefix=%t2. \
69 ; RUN: -memprof-report-hinted-sizes \
70 ; RUN: -stats -pass-remarks=memprof-context-disambiguation \
71 ; RUN: -o %t2.out 2>&1 | FileCheck %s --check-prefix=DUMP \
72 ; RUN: --check-prefix=STATS --check-prefix=SIZES
74 ; RUN: cat %t2.ccg.postbuild.dot | FileCheck %s --check-prefix=DOT
75 ;; We should have cloned bar, baz, and foo, for the cold memory allocation.
76 ; RUN: cat %t2.ccg.cloned.dot | FileCheck %s --check-prefix=DOTCLONED
78 ;; Check distributed index
79 ; RUN: llvm-dis %t.o.thinlto.bc -o - | FileCheck %s --check-prefix=DISTRIB
81 ;; Run ThinLTO backend
82 ; RUN: opt -passes=memprof-context-disambiguation \
83 ; RUN: -memprof-import-summary=%t.o.thinlto.bc \
84 ; RUN: -stats -pass-remarks=memprof-context-disambiguation \
85 ; RUN: %t.o -S 2>&1 | FileCheck %s --check-prefix=IR \
86 ; RUN: --check-prefix=STATS-BE --check-prefix=REMARKS
88 source_filename = "memprof-basic.ll"
89 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
90 target triple = "x86_64-unknown-linux-gnu"
92 define i32 @main() #0 {
94 %call = call ptr @_Z3foov(), !callsite !0
95 %call1 = call ptr @_Z3foov(), !callsite !1
99 declare void @_ZdaPv()
103 define internal ptr @_Z3barv() #0 {
105 %call = call ptr @_Znam(i64 0), !memprof !2, !callsite !7
109 declare ptr @_Znam(i64)
111 define internal ptr @_Z3bazv() #0 {
113 %call = call ptr @_Z3barv(), !callsite !8
117 define internal ptr @_Z3foov() #0 {
119 %call = call ptr @_Z3bazv(), !callsite !9
123 ; uselistorder directives
124 uselistorder ptr @_Z3foov, { 1, 0 }
126 attributes #0 = { noinline optnone }
128 !0 = !{i64 8632435727821051414}
129 !1 = !{i64 -3421689549917153178}
131 !3 = !{!4, !"notcold", i64 100}
132 !4 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 8632435727821051414}
133 !5 = !{!6, !"cold", i64 400}
134 !6 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 -3421689549917153178}
135 !7 = !{i64 9086428284934609951}
136 !8 = !{i64 -5964873800580613432}
137 !9 = !{i64 2732490490862098848}
140 ; DUMP: CCG before cloning:
141 ; DUMP: Callsite Context Graph:
142 ; DUMP: Node [[BAR:0x[a-z0-9]+]]
143 ; DUMP: Versions: 1 MIB:
144 ; DUMP: AllocType 1 StackIds: 2, 3, 0
145 ; DUMP: AllocType 2 StackIds: 2, 3, 1
147 ; DUMP: AllocTypes: NotColdCold
148 ; DUMP: ContextIds: 1 2
151 ; DUMP: Edge from Callee [[BAR]] to Caller: [[BAZ:0x[a-z0-9]+]] AllocTypes: NotColdCold ContextIds: 1 2
154 ; DUMP: Callee: 11481133863268513686 (_Z3barv) Clones: 0 StackIds: 2 (clone 0)
155 ; DUMP: AllocTypes: NotColdCold
156 ; DUMP: ContextIds: 1 2
158 ; DUMP: Edge from Callee [[BAR]] to Caller: [[BAZ]] AllocTypes: NotColdCold ContextIds: 1 2
160 ; DUMP: Edge from Callee [[BAZ]] to Caller: [[FOO:0x[a-z0-9]+]] AllocTypes: NotColdCold ContextIds: 1 2
163 ; DUMP: Callee: 1807954217441101578 (_Z3bazv) Clones: 0 StackIds: 3 (clone 0)
164 ; DUMP: AllocTypes: NotColdCold
165 ; DUMP: ContextIds: 1 2
167 ; DUMP: Edge from Callee [[BAZ]] to Caller: [[FOO]] AllocTypes: NotColdCold ContextIds: 1 2
169 ; DUMP: Edge from Callee [[FOO]] to Caller: [[MAIN1:0x[a-z0-9]+]] AllocTypes: NotCold ContextIds: 1
170 ; DUMP: Edge from Callee [[FOO]] to Caller: [[MAIN2:0x[a-z0-9]+]] AllocTypes: Cold ContextIds: 2
172 ; DUMP: Node [[MAIN1]]
173 ; DUMP: Callee: 8107868197919466657 (_Z3foov) Clones: 0 StackIds: 0 (clone 0)
174 ; DUMP: AllocTypes: NotCold
175 ; DUMP: ContextIds: 1
177 ; DUMP: Edge from Callee [[FOO]] to Caller: [[MAIN1]] AllocTypes: NotCold ContextIds: 1
180 ; DUMP: Node [[MAIN2]]
181 ; DUMP: Callee: 8107868197919466657 (_Z3foov) Clones: 0 StackIds: 1 (clone 0)
182 ; DUMP: AllocTypes: Cold
183 ; DUMP: ContextIds: 2
185 ; DUMP: Edge from Callee [[FOO]] to Caller: [[MAIN2]] AllocTypes: Cold ContextIds: 2
188 ; DUMP: CCG after cloning:
189 ; DUMP: Callsite Context Graph:
191 ; DUMP: Versions: 1 MIB:
192 ; DUMP: AllocType 1 StackIds: 2, 3, 0
193 ; DUMP: AllocType 2 StackIds: 2, 3, 1
195 ; DUMP: AllocTypes: NotCold
196 ; DUMP: ContextIds: 1
199 ; DUMP: Edge from Callee [[BAR]] to Caller: [[BAZ]] AllocTypes: NotCold ContextIds: 1
200 ; DUMP: Clones: [[BAR2:0x[a-z0-9]+]]
203 ; DUMP: Callee: 11481133863268513686 (_Z3barv) Clones: 0 StackIds: 2 (clone 0)
204 ; DUMP: AllocTypes: NotCold
205 ; DUMP: ContextIds: 1
207 ; DUMP: Edge from Callee [[BAR]] to Caller: [[BAZ]] AllocTypes: NotCold ContextIds: 1
209 ; DUMP: Edge from Callee [[BAZ]] to Caller: [[FOO]] AllocTypes: NotCold ContextIds: 1
210 ; DUMP: Clones: [[BAZ2:0x[a-z0-9]+]]
213 ; DUMP: Callee: 1807954217441101578 (_Z3bazv) Clones: 0 StackIds: 3 (clone 0)
214 ; DUMP: AllocTypes: NotCold
215 ; DUMP: ContextIds: 1
217 ; DUMP: Edge from Callee [[BAZ]] to Caller: [[FOO]] AllocTypes: NotCold ContextIds: 1
219 ; DUMP: Edge from Callee [[FOO]] to Caller: [[MAIN1]] AllocTypes: NotCold ContextIds: 1
220 ; DUMP: Clones: [[FOO2:0x[a-z0-9]+]]
222 ; DUMP: Node [[MAIN1]]
223 ; DUMP: Callee: 8107868197919466657 (_Z3foov) Clones: 0 StackIds: 0 (clone 0)
224 ; DUMP: AllocTypes: NotCold
225 ; DUMP: ContextIds: 1
227 ; DUMP: Edge from Callee [[FOO]] to Caller: [[MAIN1]] AllocTypes: NotCold ContextIds: 1
230 ; DUMP: Node [[MAIN2]]
231 ; DUMP: Callee: 8107868197919466657 (_Z3foov) Clones: 0 StackIds: 1 (clone 0)
232 ; DUMP: AllocTypes: Cold
233 ; DUMP: ContextIds: 2
235 ; DUMP: Edge from Callee [[FOO2]] to Caller: [[MAIN2]] AllocTypes: Cold ContextIds: 2
238 ; DUMP: Node [[FOO2]]
239 ; DUMP: Callee: 1807954217441101578 (_Z3bazv) Clones: 0 StackIds: 3 (clone 0)
240 ; DUMP: AllocTypes: Cold
241 ; DUMP: ContextIds: 2
243 ; DUMP: Edge from Callee [[BAZ2]] to Caller: [[FOO2]] AllocTypes: Cold ContextIds: 2
245 ; DUMP: Edge from Callee [[FOO2]] to Caller: [[MAIN2]] AllocTypes: Cold ContextIds: 2
246 ; DUMP: Clone of [[FOO]]
248 ; DUMP: Node [[BAZ2]]
249 ; DUMP: Callee: 11481133863268513686 (_Z3barv) Clones: 0 StackIds: 2 (clone 0)
250 ; DUMP: AllocTypes: Cold
251 ; DUMP: ContextIds: 2
253 ; DUMP: Edge from Callee [[BAR2]] to Caller: [[BAZ2]] AllocTypes: Cold ContextIds: 2
255 ; DUMP: Edge from Callee [[BAZ2]] to Caller: [[FOO2]] AllocTypes: Cold ContextIds: 2
256 ; DUMP: Clone of [[BAZ]]
258 ; DUMP: Node [[BAR2]]
259 ; DUMP: Versions: 1 MIB:
260 ; DUMP: AllocType 1 StackIds: 2, 3, 0
261 ; DUMP: AllocType 2 StackIds: 2, 3, 1
263 ; DUMP: AllocTypes: Cold
264 ; DUMP: ContextIds: 2
267 ; DUMP: Edge from Callee [[BAR2]] to Caller: [[BAZ2]] AllocTypes: Cold ContextIds: 2
268 ; DUMP: Clone of [[BAR]]
270 ; SIZES: NotCold context 1 with total size 100 is NotCold after cloning
271 ; SIZES: Cold context 2 with total size 400 is Cold after cloning
273 ; REMARKS: call in clone main assigned to call function clone _Z3foov.memprof.1
274 ; REMARKS: created clone _Z3barv.memprof.1
275 ; REMARKS: call in clone _Z3barv marked with memprof allocation attribute notcold
276 ; REMARKS: call in clone _Z3barv.memprof.1 marked with memprof allocation attribute cold
277 ; REMARKS: created clone _Z3bazv.memprof.1
278 ; REMARKS: call in clone _Z3bazv.memprof.1 assigned to call function clone _Z3barv.memprof.1
279 ; REMARKS: created clone _Z3foov.memprof.1
280 ; REMARKS: call in clone _Z3foov.memprof.1 assigned to call function clone _Z3bazv.memprof.1
283 ; IR: define {{.*}} @main
284 ;; The first call to foo does not allocate cold memory. It should call the
285 ;; original functions, which ultimately call the original allocation decorated
286 ;; with a "notcold" attribute.
287 ; IR: call {{.*}} @_Z3foov()
288 ;; The second call to foo allocates cold memory. It should call cloned functions
289 ;; which ultimately call a cloned allocation decorated with a "cold" attribute.
290 ; IR: call {{.*}} @_Z3foov.memprof.1()
291 ; IR: define internal {{.*}} @_Z3barv()
292 ; IR: call {{.*}} @_Znam(i64 0) #[[NOTCOLD:[0-9]+]]
293 ; IR: define internal {{.*}} @_Z3bazv()
294 ; IR: call {{.*}} @_Z3barv()
295 ; IR: define internal {{.*}} @_Z3foov()
296 ; IR: call {{.*}} @_Z3bazv()
297 ; IR: define internal {{.*}} @_Z3barv.memprof.1()
298 ; IR: call {{.*}} @_Znam(i64 0) #[[COLD:[0-9]+]]
299 ; IR: define internal {{.*}} @_Z3bazv.memprof.1()
300 ; IR: call {{.*}} @_Z3barv.memprof.1()
301 ; IR: define internal {{.*}} @_Z3foov.memprof.1()
302 ; IR: call {{.*}} @_Z3bazv.memprof.1()
303 ; IR: attributes #[[NOTCOLD]] = { "memprof"="notcold" }
304 ; IR: attributes #[[COLD]] = { "memprof"="cold" }
307 ; STATS: 1 memprof-context-disambiguation - Number of cold static allocations (possibly cloned)
308 ; STATS-BE: 1 memprof-context-disambiguation - Number of cold static allocations (possibly cloned) during ThinLTO backend
309 ; STATS: 1 memprof-context-disambiguation - Number of not cold static allocations (possibly cloned)
310 ; STATS-BE: 1 memprof-context-disambiguation - Number of not cold static allocations (possibly cloned) during ThinLTO backend
311 ; STATS-BE: 2 memprof-context-disambiguation - Number of allocation versions (including clones) during ThinLTO backend
312 ; STATS: 3 memprof-context-disambiguation - Number of function clones created during whole program analysis
313 ; STATS-BE: 3 memprof-context-disambiguation - Number of function clones created during ThinLTO backend
314 ; STATS-BE: 3 memprof-context-disambiguation - Number of functions that had clones created during ThinLTO backend
315 ; STATS-BE: 2 memprof-context-disambiguation - Maximum number of allocation versions created for an original allocation during ThinLTO backend
316 ; STATS-BE: 1 memprof-context-disambiguation - Number of original (not cloned) allocations with memprof profiles during ThinLTO backend
319 ; DOT: digraph "postbuild" {
320 ; DOT: label="postbuild";
321 ; DOT: Node[[BAR:0x[a-z0-9]+]] [shape=record,tooltip="N[[BAR]] ContextIds: 1 2",fillcolor="mediumorchid1",style="filled",style="filled",label="{OrigId: Alloc0\n_Z3barv -\> alloc}"];
322 ; DOT: Node[[BAZ:0x[a-z0-9]+]] [shape=record,tooltip="N[[BAZ]] ContextIds: 1 2",fillcolor="mediumorchid1",style="filled",style="filled",label="{OrigId: 12481870273128938184\n_Z3bazv -\> _Z3barv}"];
323 ; DOT: Node[[BAZ]] -> Node[[BAR]][tooltip="ContextIds: 1 2",fillcolor="mediumorchid1"];
324 ; DOT: Node[[FOO:0x[a-z0-9]+]] [shape=record,tooltip="N[[FOO]] ContextIds: 1 2",fillcolor="mediumorchid1",style="filled",style="filled",label="{OrigId: 2732490490862098848\n_Z3foov -\> _Z3bazv}"];
325 ; DOT: Node[[FOO]] -> Node[[BAZ]][tooltip="ContextIds: 1 2",fillcolor="mediumorchid1"];
326 ; DOT: Node[[MAIN1:0x[a-z0-9]+]] [shape=record,tooltip="N[[MAIN1]] ContextIds: 1",fillcolor="brown1",style="filled",style="filled",label="{OrigId: 8632435727821051414\nmain -\> _Z3foov}"];
327 ; DOT: Node[[MAIN1]] -> Node[[FOO]][tooltip="ContextIds: 1",fillcolor="brown1"];
328 ; DOT: Node[[MAIN2:0x[a-z0-9]+]] [shape=record,tooltip="N[[MAIN2]] ContextIds: 2",fillcolor="cyan",style="filled",style="filled",label="{OrigId: 15025054523792398438\nmain -\> _Z3foov}"];
329 ; DOT: Node[[MAIN2]] -> Node[[FOO]][tooltip="ContextIds: 2",fillcolor="cyan"];
333 ; DOTCLONED: digraph "cloned" {
334 ; DOTCLONED: label="cloned";
335 ; DOTCLONED: Node[[BAR:0x[a-z0-9]+]] [shape=record,tooltip="N[[BAR]] ContextIds: 1",fillcolor="brown1",style="filled",style="filled",label="{OrigId: Alloc0\n_Z3barv -\> alloc}"];
336 ; DOTCLONED: Node[[BAZ:0x[a-z0-9]+]] [shape=record,tooltip="N[[BAZ]] ContextIds: 1",fillcolor="brown1",style="filled",style="filled",label="{OrigId: 12481870273128938184\n_Z3bazv -\> _Z3barv}"];
337 ; DOTCLONED: Node[[BAZ]] -> Node[[BAR]][tooltip="ContextIds: 1",fillcolor="brown1"];
338 ; DOTCLONED: Node[[FOO:0x[a-z0-9]+]] [shape=record,tooltip="N[[FOO]] ContextIds: 1",fillcolor="brown1",style="filled",style="filled",label="{OrigId: 2732490490862098848\n_Z3foov -\> _Z3bazv}"];
339 ; DOTCLONED: Node[[FOO]] -> Node[[BAZ]][tooltip="ContextIds: 1",fillcolor="brown1"];
340 ; DOTCLONED: Node[[MAIN1:0x[a-z0-9]+]] [shape=record,tooltip="N[[MAIN1]] ContextIds: 1",fillcolor="brown1",style="filled",style="filled",label="{OrigId: 8632435727821051414\nmain -\> _Z3foov}"];
341 ; DOTCLONED: Node[[MAIN1]] -> Node[[FOO]][tooltip="ContextIds: 1",fillcolor="brown1"];
342 ; DOTCLONED: Node[[MAIN2:0x[a-z0-9]+]] [shape=record,tooltip="N[[MAIN2]] ContextIds: 2",fillcolor="cyan",style="filled",style="filled",label="{OrigId: 15025054523792398438\nmain -\> _Z3foov}"];
343 ; DOTCLONED: Node[[MAIN2]] -> Node[[FOO2:0x[a-z0-9]+]][tooltip="ContextIds: 2",fillcolor="cyan"];
344 ; DOTCLONED: Node[[FOO2]] [shape=record,tooltip="N[[FOO2]] ContextIds: 2",fillcolor="cyan",style="filled",color="blue",style="filled,bold,dashed",label="{OrigId: 0\n_Z3foov -\> _Z3bazv}"];
345 ; DOTCLONED: Node[[FOO2]] -> Node[[BAZ2:0x[a-z0-9]+]][tooltip="ContextIds: 2",fillcolor="cyan"];
346 ; DOTCLONED: Node[[BAZ2]] [shape=record,tooltip="N[[BAZ2]] ContextIds: 2",fillcolor="cyan",style="filled",color="blue",style="filled,bold,dashed",label="{OrigId: 0\n_Z3bazv -\> _Z3barv}"];
347 ; DOTCLONED: Node[[BAZ2]] -> Node[[BAR2:0x[a-z0-9]+]][tooltip="ContextIds: 2",fillcolor="cyan"];
348 ; DOTCLONED: Node[[BAR2]] [shape=record,tooltip="N[[BAR2]] ContextIds: 2",fillcolor="cyan",style="filled",color="blue",style="filled,bold,dashed",label="{OrigId: Alloc0\n_Z3barv -\> alloc}"];
352 ; DISTRIB: ^[[BAZ:[0-9]+]] = gv: (guid: 1807954217441101578, {{.*}} callsites: ((callee: ^[[BAR:[0-9]+]], clones: (0, 1)
353 ; DISTRIB: ^[[FOO:[0-9]+]] = gv: (guid: 8107868197919466657, {{.*}} callsites: ((callee: ^[[BAZ]], clones: (0, 1)
354 ; DISTRIB: ^[[BAR]] = gv: (guid: 11481133863268513686, {{.*}} allocs: ((versions: (notcold, cold)
355 ; DISTRIB: ^[[MAIN:[0-9]+]] = gv: (guid: 15822663052811949562, {{.*}} callsites: ((callee: ^[[FOO]], clones: (0), {{.*}} (callee: ^[[FOO]], clones: (1)