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 %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: -stats -pass-remarks=memprof-context-disambiguation -save-temps \
47 ; RUN: -o %t.out 2>&1 | FileCheck %s --check-prefix=DUMP \
48 ; RUN: --check-prefix=STATS --check-prefix=STATS-BE --check-prefix=REMARKS
50 ; RUN: cat %t.ccg.postbuild.dot | FileCheck %s --check-prefix=DOT
51 ;; We should have cloned bar, baz, and foo, for the cold memory allocation.
52 ; RUN: cat %t.ccg.cloned.dot | FileCheck %s --check-prefix=DOTCLONED
54 ; RUN: llvm-dis %t.out.1.4.opt.bc -o - | FileCheck %s --check-prefix=IR
57 ;; Try again but with distributed ThinLTO
58 ; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \
59 ; RUN: -supports-hot-cold-new \
60 ; RUN: -thinlto-distributed-indexes \
61 ; RUN: -r=%t.o,main,plx \
62 ; RUN: -r=%t.o,_ZdaPv, \
63 ; RUN: -r=%t.o,sleep, \
64 ; RUN: -r=%t.o,_Znam, \
65 ; RUN: -memprof-verify-ccg -memprof-verify-nodes -memprof-dump-ccg \
66 ; RUN: -memprof-export-to-dot -memprof-dot-file-path-prefix=%t2. \
67 ; RUN: -stats -pass-remarks=memprof-context-disambiguation \
68 ; RUN: -o %t2.out 2>&1 | FileCheck %s --check-prefix=DUMP \
69 ; RUN: --check-prefix=STATS
71 ; RUN: cat %t2.ccg.postbuild.dot | FileCheck %s --check-prefix=DOT
72 ;; We should have cloned bar, baz, and foo, for the cold memory allocation.
73 ; RUN: cat %t2.ccg.cloned.dot | FileCheck %s --check-prefix=DOTCLONED
75 ;; Check distributed index
76 ; RUN: llvm-dis %t.o.thinlto.bc -o - | FileCheck %s --check-prefix=DISTRIB
78 ;; Run ThinLTO backend
79 ; RUN: opt -passes=memprof-context-disambiguation \
80 ; RUN: -memprof-import-summary=%t.o.thinlto.bc \
81 ; RUN: -stats -pass-remarks=memprof-context-disambiguation \
82 ; RUN: %t.o -S 2>&1 | FileCheck %s --check-prefix=IR \
83 ; RUN: --check-prefix=STATS-BE --check-prefix=REMARKS
85 source_filename = "memprof-basic.ll"
86 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
87 target triple = "x86_64-unknown-linux-gnu"
89 define i32 @main() #0 {
91 %call = call ptr @_Z3foov(), !callsite !0
92 %call1 = call ptr @_Z3foov(), !callsite !1
96 declare void @_ZdaPv()
100 define internal ptr @_Z3barv() #0 {
102 %call = call ptr @_Znam(i64 0), !memprof !2, !callsite !7
106 declare ptr @_Znam(i64)
108 define internal ptr @_Z3bazv() #0 {
110 %call = call ptr @_Z3barv(), !callsite !8
114 define internal ptr @_Z3foov() #0 {
116 %call = call ptr @_Z3bazv(), !callsite !9
120 ; uselistorder directives
121 uselistorder ptr @_Z3foov, { 1, 0 }
123 attributes #0 = { noinline optnone }
125 !0 = !{i64 8632435727821051414}
126 !1 = !{i64 -3421689549917153178}
128 !3 = !{!4, !"notcold"}
129 !4 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 8632435727821051414}
131 !6 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 -3421689549917153178}
132 !7 = !{i64 9086428284934609951}
133 !8 = !{i64 -5964873800580613432}
134 !9 = !{i64 2732490490862098848}
137 ; DUMP: CCG before cloning:
138 ; DUMP: Callsite Context Graph:
139 ; DUMP: Node [[BAR:0x[a-z0-9]+]]
140 ; DUMP: Versions: 1 MIB:
141 ; DUMP: AllocType 1 StackIds: 2, 3, 0
142 ; DUMP: AllocType 2 StackIds: 2, 3, 1
144 ; DUMP: AllocTypes: NotColdCold
145 ; DUMP: ContextIds: 1 2
148 ; DUMP: Edge from Callee [[BAR]] to Caller: [[BAZ:0x[a-z0-9]+]] AllocTypes: NotColdCold ContextIds: 1 2
151 ; DUMP: Callee: 9832687305761716512 (_Z3barv) Clones: 0 StackIds: 2 (clone 0)
152 ; DUMP: AllocTypes: NotColdCold
153 ; DUMP: ContextIds: 1 2
155 ; DUMP: Edge from Callee [[BAR]] to Caller: [[BAZ]] AllocTypes: NotColdCold ContextIds: 1 2
157 ; DUMP: Edge from Callee [[BAZ]] to Caller: [[FOO:0x[a-z0-9]+]] AllocTypes: NotColdCold ContextIds: 1 2
160 ; DUMP: Callee: 5878270615442837395 (_Z3bazv) Clones: 0 StackIds: 3 (clone 0)
161 ; DUMP: AllocTypes: NotColdCold
162 ; DUMP: ContextIds: 1 2
164 ; DUMP: Edge from Callee [[BAZ]] to Caller: [[FOO]] AllocTypes: NotColdCold ContextIds: 1 2
166 ; DUMP: Edge from Callee [[FOO]] to Caller: [[MAIN1:0x[a-z0-9]+]] AllocTypes: NotCold ContextIds: 1
167 ; DUMP: Edge from Callee [[FOO]] to Caller: [[MAIN2:0x[a-z0-9]+]] AllocTypes: Cold ContextIds: 2
169 ; DUMP: Node [[MAIN1]]
170 ; DUMP: Callee: 6731117468105397038 (_Z3foov) Clones: 0 StackIds: 0 (clone 0)
171 ; DUMP: AllocTypes: NotCold
172 ; DUMP: ContextIds: 1
174 ; DUMP: Edge from Callee [[FOO]] to Caller: [[MAIN1]] AllocTypes: NotCold ContextIds: 1
177 ; DUMP: Node [[MAIN2]]
178 ; DUMP: Callee: 6731117468105397038 (_Z3foov) Clones: 0 StackIds: 1 (clone 0)
179 ; DUMP: AllocTypes: Cold
180 ; DUMP: ContextIds: 2
182 ; DUMP: Edge from Callee [[FOO]] to Caller: [[MAIN2]] AllocTypes: Cold ContextIds: 2
185 ; DUMP: CCG after cloning:
186 ; DUMP: Callsite Context Graph:
188 ; DUMP: Versions: 1 MIB:
189 ; DUMP: AllocType 1 StackIds: 2, 3, 0
190 ; DUMP: AllocType 2 StackIds: 2, 3, 1
192 ; DUMP: AllocTypes: NotCold
193 ; DUMP: ContextIds: 1
196 ; DUMP: Edge from Callee [[BAR]] to Caller: [[BAZ]] AllocTypes: NotCold ContextIds: 1
197 ; DUMP: Clones: [[BAR2:0x[a-z0-9]+]]
200 ; DUMP: Callee: 9832687305761716512 (_Z3barv) Clones: 0 StackIds: 2 (clone 0)
201 ; DUMP: AllocTypes: NotCold
202 ; DUMP: ContextIds: 1
204 ; DUMP: Edge from Callee [[BAR]] to Caller: [[BAZ]] AllocTypes: NotCold ContextIds: 1
206 ; DUMP: Edge from Callee [[BAZ]] to Caller: [[FOO]] AllocTypes: NotCold ContextIds: 1
207 ; DUMP: Clones: [[BAZ2:0x[a-z0-9]+]]
210 ; DUMP: Callee: 5878270615442837395 (_Z3bazv) Clones: 0 StackIds: 3 (clone 0)
211 ; DUMP: AllocTypes: NotCold
212 ; DUMP: ContextIds: 1
214 ; DUMP: Edge from Callee [[BAZ]] to Caller: [[FOO]] AllocTypes: NotCold ContextIds: 1
216 ; DUMP: Edge from Callee [[FOO]] to Caller: [[MAIN1]] AllocTypes: NotCold ContextIds: 1
217 ; DUMP: Clones: [[FOO2:0x[a-z0-9]+]]
219 ; DUMP: Node [[MAIN1]]
220 ; DUMP: Callee: 6731117468105397038 (_Z3foov) Clones: 0 StackIds: 0 (clone 0)
221 ; DUMP: AllocTypes: NotCold
222 ; DUMP: ContextIds: 1
224 ; DUMP: Edge from Callee [[FOO]] to Caller: [[MAIN1]] AllocTypes: NotCold ContextIds: 1
227 ; DUMP: Node [[MAIN2]]
228 ; DUMP: Callee: 6731117468105397038 (_Z3foov) Clones: 0 StackIds: 1 (clone 0)
229 ; DUMP: AllocTypes: Cold
230 ; DUMP: ContextIds: 2
232 ; DUMP: Edge from Callee [[FOO2]] to Caller: [[MAIN2]] AllocTypes: Cold ContextIds: 2
235 ; DUMP: Node [[FOO2]]
236 ; DUMP: Callee: 5878270615442837395 (_Z3bazv) Clones: 0 StackIds: 3 (clone 0)
237 ; DUMP: AllocTypes: Cold
238 ; DUMP: ContextIds: 2
240 ; DUMP: Edge from Callee [[BAZ2]] to Caller: [[FOO2]] AllocTypes: Cold ContextIds: 2
242 ; DUMP: Edge from Callee [[FOO2]] to Caller: [[MAIN2]] AllocTypes: Cold ContextIds: 2
243 ; DUMP: Clone of [[FOO]]
245 ; DUMP: Node [[BAZ2]]
246 ; DUMP: Callee: 9832687305761716512 (_Z3barv) Clones: 0 StackIds: 2 (clone 0)
247 ; DUMP: AllocTypes: Cold
248 ; DUMP: ContextIds: 2
250 ; DUMP: Edge from Callee [[BAR2]] to Caller: [[BAZ2]] AllocTypes: Cold ContextIds: 2
252 ; DUMP: Edge from Callee [[BAZ2]] to Caller: [[FOO2]] AllocTypes: Cold ContextIds: 2
253 ; DUMP: Clone of [[BAZ]]
255 ; DUMP: Node [[BAR2]]
256 ; DUMP: Versions: 1 MIB:
257 ; DUMP: AllocType 1 StackIds: 2, 3, 0
258 ; DUMP: AllocType 2 StackIds: 2, 3, 1
260 ; DUMP: AllocTypes: Cold
261 ; DUMP: ContextIds: 2
264 ; DUMP: Edge from Callee [[BAR2]] to Caller: [[BAZ2]] AllocTypes: Cold ContextIds: 2
265 ; DUMP: Clone of [[BAR]]
268 ; REMARKS: call in clone main assigned to call function clone _Z3foov.memprof.1
269 ; REMARKS: created clone _Z3barv.memprof.1
270 ; REMARKS: call in clone _Z3barv marked with memprof allocation attribute notcold
271 ; REMARKS: call in clone _Z3barv.memprof.1 marked with memprof allocation attribute cold
272 ; REMARKS: created clone _Z3bazv.memprof.1
273 ; REMARKS: call in clone _Z3bazv.memprof.1 assigned to call function clone _Z3barv.memprof.1
274 ; REMARKS: created clone _Z3foov.memprof.1
275 ; REMARKS: call in clone _Z3foov.memprof.1 assigned to call function clone _Z3bazv.memprof.1
278 ; IR: define {{.*}} @main
279 ;; The first call to foo does not allocate cold memory. It should call the
280 ;; original functions, which ultimately call the original allocation decorated
281 ;; with a "notcold" attribute.
282 ; IR: call {{.*}} @_Z3foov()
283 ;; The second call to foo allocates cold memory. It should call cloned functions
284 ;; which ultimately call a cloned allocation decorated with a "cold" attribute.
285 ; IR: call {{.*}} @_Z3foov.memprof.1()
286 ; IR: define internal {{.*}} @_Z3barv()
287 ; IR: call {{.*}} @_Znam(i64 0) #[[NOTCOLD:[0-9]+]]
288 ; IR: define internal {{.*}} @_Z3bazv()
289 ; IR: call {{.*}} @_Z3barv()
290 ; IR: define internal {{.*}} @_Z3foov()
291 ; IR: call {{.*}} @_Z3bazv()
292 ; IR: define internal {{.*}} @_Z3barv.memprof.1()
293 ; IR: call {{.*}} @_Znam(i64 0) #[[COLD:[0-9]+]]
294 ; IR: define internal {{.*}} @_Z3bazv.memprof.1()
295 ; IR: call {{.*}} @_Z3barv.memprof.1()
296 ; IR: define internal {{.*}} @_Z3foov.memprof.1()
297 ; IR: call {{.*}} @_Z3bazv.memprof.1()
298 ; IR: attributes #[[NOTCOLD]] = { "memprof"="notcold" }
299 ; IR: attributes #[[COLD]] = { "memprof"="cold" }
302 ; STATS: 1 memprof-context-disambiguation - Number of cold static allocations (possibly cloned)
303 ; STATS-BE: 1 memprof-context-disambiguation - Number of cold static allocations (possibly cloned) during ThinLTO backend
304 ; STATS: 1 memprof-context-disambiguation - Number of not cold static allocations (possibly cloned)
305 ; STATS-BE: 1 memprof-context-disambiguation - Number of not cold static allocations (possibly cloned) during ThinLTO backend
306 ; STATS-BE: 2 memprof-context-disambiguation - Number of allocation versions (including clones) during ThinLTO backend
307 ; STATS: 3 memprof-context-disambiguation - Number of function clones created during whole program analysis
308 ; STATS-BE: 3 memprof-context-disambiguation - Number of function clones created during ThinLTO backend
309 ; STATS-BE: 3 memprof-context-disambiguation - Number of functions that had clones created during ThinLTO backend
310 ; STATS-BE: 2 memprof-context-disambiguation - Maximum number of allocation versions created for an original allocation during ThinLTO backend
311 ; STATS-BE: 1 memprof-context-disambiguation - Number of original (not cloned) allocations with memprof profiles during ThinLTO backend
314 ; DOT: digraph "postbuild" {
315 ; DOT: label="postbuild";
316 ; 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}"];
317 ; 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}"];
318 ; DOT: Node[[BAZ]] -> Node[[BAR]][tooltip="ContextIds: 1 2",fillcolor="mediumorchid1"];
319 ; 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}"];
320 ; DOT: Node[[FOO]] -> Node[[BAZ]][tooltip="ContextIds: 1 2",fillcolor="mediumorchid1"];
321 ; 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}"];
322 ; DOT: Node[[MAIN1]] -> Node[[FOO]][tooltip="ContextIds: 1",fillcolor="brown1"];
323 ; 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}"];
324 ; DOT: Node[[MAIN2]] -> Node[[FOO]][tooltip="ContextIds: 2",fillcolor="cyan"];
328 ; DOTCLONED: digraph "cloned" {
329 ; DOTCLONED: label="cloned";
330 ; 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}"];
331 ; 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}"];
332 ; DOTCLONED: Node[[BAZ]] -> Node[[BAR]][tooltip="ContextIds: 1",fillcolor="brown1"];
333 ; 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}"];
334 ; DOTCLONED: Node[[FOO]] -> Node[[BAZ]][tooltip="ContextIds: 1",fillcolor="brown1"];
335 ; 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}"];
336 ; DOTCLONED: Node[[MAIN1]] -> Node[[FOO]][tooltip="ContextIds: 1",fillcolor="brown1"];
337 ; 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}"];
338 ; DOTCLONED: Node[[MAIN2]] -> Node[[FOO2:0x[a-z0-9]+]][tooltip="ContextIds: 2",fillcolor="cyan"];
339 ; 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}"];
340 ; DOTCLONED: Node[[FOO2]] -> Node[[BAZ2:0x[a-z0-9]+]][tooltip="ContextIds: 2",fillcolor="cyan"];
341 ; 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}"];
342 ; DOTCLONED: Node[[BAZ2]] -> Node[[BAR2:0x[a-z0-9]+]][tooltip="ContextIds: 2",fillcolor="cyan"];
343 ; 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}"];
347 ; DISTRIB: ^[[BAZ:[0-9]+]] = gv: (guid: 5878270615442837395, {{.*}} callsites: ((callee: ^[[BAR:[0-9]+]], clones: (0, 1)
348 ; DISTRIB: ^[[FOO:[0-9]+]] = gv: (guid: 6731117468105397038, {{.*}} callsites: ((callee: ^[[BAZ]], clones: (0, 1)
349 ; DISTRIB: ^[[BAR]] = gv: (guid: 9832687305761716512, {{.*}} allocs: ((versions: (notcold, cold)
350 ; DISTRIB: ^[[MAIN:[0-9]+]] = gv: (guid: 15822663052811949562, {{.*}} callsites: ((callee: ^[[FOO]], clones: (0), {{.*}} (callee: ^[[FOO]], clones: (1)