xref: /llvm-project/llvm/test/ThinLTO/X86/memprof-recursive.ll (revision 3055e86c719c6cc72e50bb74a0e3b9cffebb41b5)
1b8ad6fb0STeresa Johnson;; Test recursion handling during cloning.
2b8ad6fb0STeresa Johnson;;
3b8ad6fb0STeresa Johnson;; See llvm/test/Transforms/MemProfContextDisambiguation/recursive.ll for
4b8ad6fb0STeresa Johnson;; information on how the test was created.
5b8ad6fb0STeresa Johnson
6b8ad6fb0STeresa Johnson; RUN: opt -thinlto-bc %s >%t.o
7b8ad6fb0STeresa Johnson
8*3055e86cSTeresa Johnson;; Check behavior when we enable cloning of contexts involved with recursive
9b8ad6fb0STeresa Johnson;; cycles, but not through the cycle itself. I.e. until full support for
10b8ad6fb0STeresa Johnson;; recursion is added, the cloned recursive call from C back to B (line 12) will
11b8ad6fb0STeresa Johnson;; not be updated to call a clone.
12b8ad6fb0STeresa Johnson; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \
13b8ad6fb0STeresa Johnson; RUN:  -supports-hot-cold-new \
14b8ad6fb0STeresa Johnson; RUN:  -r=%t.o,_Z1Dv,plx \
15b8ad6fb0STeresa Johnson; RUN:  -r=%t.o,_Z1Ci,plx \
16b8ad6fb0STeresa Johnson; RUN:  -r=%t.o,_Z1Bi,plx \
17b8ad6fb0STeresa Johnson; RUN:  -r=%t.o,main,plx \
18b8ad6fb0STeresa Johnson; RUN:  -r=%t.o,_Znam, \
19b8ad6fb0STeresa Johnson; RUN:  -memprof-verify-ccg -memprof-verify-nodes \
20b8ad6fb0STeresa Johnson; RUN:  -pass-remarks=memprof-context-disambiguation \
21*3055e86cSTeresa Johnson; RUN:	-memprof-allow-recursive-callsites=true \
22b8ad6fb0STeresa Johnson; RUN:  -o %t.out 2>&1 | FileCheck %s \
23b8ad6fb0STeresa Johnson; RUN:  --implicit-check-not "memprof_recursive3.cc:12:10: call in clone _Z1Ci.memprof.1 assigned" \
24b8ad6fb0STeresa Johnson; RUN:  --check-prefix=ALLOW-RECUR-CALLSITES --check-prefix=ALLOW-RECUR-CONTEXTS
25b8ad6fb0STeresa Johnson
26b8ad6fb0STeresa Johnson;; Skipping recursive callsites should result in no cloning.
27b8ad6fb0STeresa Johnson; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \
28b8ad6fb0STeresa Johnson; RUN:  -supports-hot-cold-new \
29b8ad6fb0STeresa Johnson; RUN:  -r=%t.o,_Z1Dv,plx \
30b8ad6fb0STeresa Johnson; RUN:  -r=%t.o,_Z1Ci,plx \
31b8ad6fb0STeresa Johnson; RUN:  -r=%t.o,_Z1Bi,plx \
32b8ad6fb0STeresa Johnson; RUN:  -r=%t.o,main,plx \
33b8ad6fb0STeresa Johnson; RUN:  -r=%t.o,_Znam, \
34b8ad6fb0STeresa Johnson; RUN:  -memprof-verify-ccg -memprof-verify-nodes \
35b8ad6fb0STeresa Johnson; RUN:  -pass-remarks=memprof-context-disambiguation \
36b8ad6fb0STeresa Johnson; RUN:	-memprof-allow-recursive-callsites=false \
37b8ad6fb0STeresa Johnson; RUN:  -o %t.out 2>&1 | FileCheck %s --allow-empty \
38b8ad6fb0STeresa Johnson; RUN:  --implicit-check-not "memprof_recursive3.cc:12:10: call in clone _Z1Ci.memprof.1 assigned" \
39b8ad6fb0STeresa Johnson; RUN:  --implicit-check-not="created clone" \
40b8ad6fb0STeresa Johnson; RUN:	--implicit-check-not="marked with memprof allocation attribute cold"
41b8ad6fb0STeresa Johnson
42*3055e86cSTeresa Johnson;; Check the default behavior (disabled recursive callsites).
43*3055e86cSTeresa Johnson; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \
44*3055e86cSTeresa Johnson; RUN:  -supports-hot-cold-new \
45*3055e86cSTeresa Johnson; RUN:  -r=%t.o,_Z1Dv,plx \
46*3055e86cSTeresa Johnson; RUN:  -r=%t.o,_Z1Ci,plx \
47*3055e86cSTeresa Johnson; RUN:  -r=%t.o,_Z1Bi,plx \
48*3055e86cSTeresa Johnson; RUN:  -r=%t.o,main,plx \
49*3055e86cSTeresa Johnson; RUN:  -r=%t.o,_Znam, \
50*3055e86cSTeresa Johnson; RUN:  -memprof-verify-ccg -memprof-verify-nodes \
51*3055e86cSTeresa Johnson; RUN:  -pass-remarks=memprof-context-disambiguation \
52*3055e86cSTeresa Johnson; RUN:  -o %t.out 2>&1 | FileCheck %s --allow-empty \
53*3055e86cSTeresa Johnson; RUN:  --implicit-check-not "memprof_recursive3.cc:12:10: call in clone _Z1Ci.memprof.1 assigned" \
54*3055e86cSTeresa Johnson; RUN:  --implicit-check-not="created clone" \
55*3055e86cSTeresa Johnson; RUN:	--implicit-check-not="marked with memprof allocation attribute cold"
56*3055e86cSTeresa Johnson
57b8ad6fb0STeresa Johnson;; Skipping recursive contexts should prevent spurious call to cloned version of
58b8ad6fb0STeresa Johnson;; B from the context starting at memprof_recursive.cc:19:13, which is actually
59b8ad6fb0STeresa Johnson;; recursive (until that support is added).
60b8ad6fb0STeresa Johnson; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \
61b8ad6fb0STeresa Johnson; RUN:  -supports-hot-cold-new \
62b8ad6fb0STeresa Johnson; RUN:  -r=%t.o,_Z1Dv,plx \
63b8ad6fb0STeresa Johnson; RUN:  -r=%t.o,_Z1Ci,plx \
64b8ad6fb0STeresa Johnson; RUN:  -r=%t.o,_Z1Bi,plx \
65b8ad6fb0STeresa Johnson; RUN:  -r=%t.o,main,plx \
66b8ad6fb0STeresa Johnson; RUN:  -r=%t.o,_Znam, \
67b8ad6fb0STeresa Johnson; RUN:  -memprof-verify-ccg -memprof-verify-nodes \
68b8ad6fb0STeresa Johnson; RUN:  -pass-remarks=memprof-context-disambiguation \
69*3055e86cSTeresa Johnson; RUN:	-memprof-allow-recursive-callsites=true \
70b8ad6fb0STeresa Johnson; RUN:	-memprof-allow-recursive-contexts=false \
71b8ad6fb0STeresa Johnson; RUN:  -o %t.out 2>&1 | FileCheck %s \
72b8ad6fb0STeresa Johnson; RUN:  --implicit-check-not "memprof_recursive3.cc:12:10: call in clone _Z1Ci.memprof.1 assigned" \
73b8ad6fb0STeresa Johnson; RUN:  --check-prefix=ALLOW-RECUR-CALLSITES --check-prefix=SKIP-RECUR-CONTEXTS
74b8ad6fb0STeresa Johnson
75b8ad6fb0STeresa Johnson; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:4:0: created clone _Z1Dv.memprof.1
76b8ad6fb0STeresa Johnson; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:5:10: call in clone _Z1Dv marked with memprof allocation attribute notcold
77b8ad6fb0STeresa Johnson; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:5:10: call in clone _Z1Dv.memprof.1 marked with memprof allocation attribute cold
78b8ad6fb0STeresa Johnson; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:8:0: created clone _Z1Ci.memprof.1
79b8ad6fb0STeresa Johnson; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:10:12: call in clone _Z1Ci.memprof.1 assigned to call function clone _Z1Dv.memprof.1
80b8ad6fb0STeresa Johnson; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:14:0: created clone _Z1Bi.memprof.1
81b8ad6fb0STeresa Johnson; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:15:10: call in clone _Z1Bi.memprof.1 assigned to call function clone _Z1Ci.memprof.1
82b8ad6fb0STeresa Johnson;; We should only call the cold clone for the recursive context if we enabled
83b8ad6fb0STeresa Johnson;; recursive contexts via -memprof-allow-recursive-contexts=true (default).
84b8ad6fb0STeresa Johnson; ALLOW-RECUR-CONTEXTS: memprof_recursive.cc:19:13: call in clone main assigned to call function clone _Z1Bi.memprof.1
85b8ad6fb0STeresa Johnson; SKIP-RECUR-CONTEXTS-NOT: memprof_recursive.cc:19:13: call in clone main assigned to call function clone _Z1Bi.memprof.1
86b8ad6fb0STeresa Johnson; ALLOW-RECUR-CALLSITES: memprof_recursive.cc:20:13: call in clone main assigned to call function clone _Z1Bi.memprof.1
87b8ad6fb0STeresa Johnson
88b8ad6fb0STeresa Johnsontarget datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
89b8ad6fb0STeresa Johnsontarget triple = "x86_64-unknown-linux-gnu"
90b8ad6fb0STeresa Johnson
91b8ad6fb0STeresa Johnsondefine ptr @_Z1Dv() !dbg !3 {
92b8ad6fb0STeresa Johnsonentry:
93b8ad6fb0STeresa Johnson  %call = tail call ptr @_Znam(i64 10), !dbg !6, !memprof !7, !callsite !14
94b8ad6fb0STeresa Johnson  ret ptr null
95b8ad6fb0STeresa Johnson}
96b8ad6fb0STeresa Johnson
97b8ad6fb0STeresa Johnsondefine ptr @_Z1Ci(i32 %n) !dbg !15 {
98b8ad6fb0STeresa Johnsonentry:
99b8ad6fb0STeresa Johnson  %call = tail call ptr @_Z1Dv(), !dbg !16, !callsite !17
100b8ad6fb0STeresa Johnson  br label %return
101b8ad6fb0STeresa Johnson
102b8ad6fb0STeresa Johnsonif.end:                                           ; No predecessors!
103b8ad6fb0STeresa Johnson  %call1 = tail call ptr @_Z1Bi(i32 0), !dbg !18, !callsite !19
104b8ad6fb0STeresa Johnson  br label %return
105b8ad6fb0STeresa Johnson
106b8ad6fb0STeresa Johnsonreturn:                                           ; preds = %if.end, %entry
107b8ad6fb0STeresa Johnson  ret ptr null
108b8ad6fb0STeresa Johnson}
109b8ad6fb0STeresa Johnson
110b8ad6fb0STeresa Johnsondefine ptr @_Z1Bi(i32 %n) !dbg !20 {
111b8ad6fb0STeresa Johnsonentry:
112b8ad6fb0STeresa Johnson  %call = tail call ptr @_Z1Ci(i32 0), !dbg !21, !callsite !22
113b8ad6fb0STeresa Johnson  ret ptr null
114b8ad6fb0STeresa Johnson}
115b8ad6fb0STeresa Johnson
116b8ad6fb0STeresa Johnsondefine i32 @main() {
117b8ad6fb0STeresa Johnsonentry:
118b8ad6fb0STeresa Johnson  %call = tail call ptr @_Z1Bi(i32 0), !dbg !23, !callsite !25
119b8ad6fb0STeresa Johnson  %call1 = tail call ptr @_Z1Bi(i32 0), !dbg !26, !callsite !27
120b8ad6fb0STeresa Johnson  %call2 = tail call ptr @_Z1Bi(i32 0), !dbg !28, !callsite !29
121b8ad6fb0STeresa Johnson  ret i32 0
122b8ad6fb0STeresa Johnson}
123b8ad6fb0STeresa Johnson
124b8ad6fb0STeresa Johnsondeclare ptr @_Znam(i64)
125b8ad6fb0STeresa Johnson
126b8ad6fb0STeresa Johnson!llvm.dbg.cu = !{!0}
127b8ad6fb0STeresa Johnson!llvm.module.flags = !{!2}
128b8ad6fb0STeresa Johnson
129b8ad6fb0STeresa Johnson!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 20.0.0git (https://github.com/llvm/llvm-project.git 7aec6dc477f8148ed066d10dfc7a012a51b6599c)", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, debugInfoForProfiling: true, nameTableKind: None)
130b8ad6fb0STeresa Johnson!1 = !DIFile(filename: "memprof_recursive.cc", directory: ".", checksumkind: CSK_MD5, checksum: "2f15f63b187a0e0d40e7fdd18b10576a")
131b8ad6fb0STeresa Johnson!2 = !{i32 2, !"Debug Info Version", i32 3}
132b8ad6fb0STeresa Johnson!3 = distinct !DISubprogram(name: "D", linkageName: "_Z1Dv", scope: !1, file: !1, line: 4, type: !4, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
133b8ad6fb0STeresa Johnson!4 = !DISubroutineType(types: !5)
134b8ad6fb0STeresa Johnson!5 = !{}
135b8ad6fb0STeresa Johnson!6 = !DILocation(line: 5, column: 10, scope: !3)
136b8ad6fb0STeresa Johnson!7 = !{!8, !10, !12}
137b8ad6fb0STeresa Johnson!8 = !{!9, !"cold"}
138b8ad6fb0STeresa Johnson!9 = !{i64 6541423618768552252, i64 -200552803509692312, i64 -2954124005641725917, i64 6307901912192269588}
139b8ad6fb0STeresa Johnson!10 = !{!11, !"notcold"}
140b8ad6fb0STeresa Johnson!11 = !{i64 6541423618768552252, i64 -200552803509692312, i64 -2954124005641725917, i64 -7155190423157709404, i64 -2954124005641725917, i64 8632435727821051414}
141b8ad6fb0STeresa Johnson!12 = !{!13, !"cold"}
142b8ad6fb0STeresa Johnson!13 = !{i64 6541423618768552252, i64 -200552803509692312, i64 -2954124005641725917, i64 -7155190423157709404, i64 -2954124005641725917, i64 -3421689549917153178}
143b8ad6fb0STeresa Johnson!14 = !{i64 6541423618768552252}
144b8ad6fb0STeresa Johnson!15 = distinct !DISubprogram(name: "C", linkageName: "_Z1Ci", scope: !1, file: !1, line: 8, type: !4, scopeLine: 8, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
145b8ad6fb0STeresa Johnson!16 = !DILocation(line: 10, column: 12, scope: !15)
146b8ad6fb0STeresa Johnson!17 = !{i64 -200552803509692312}
147b8ad6fb0STeresa Johnson!18 = !DILocation(line: 12, column: 10, scope: !15)
148b8ad6fb0STeresa Johnson!19 = !{i64 -7155190423157709404}
149b8ad6fb0STeresa Johnson!20 = distinct !DISubprogram(name: "B", linkageName: "_Z1Bi", scope: !1, file: !1, line: 14, type: !4, scopeLine: 14, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
150b8ad6fb0STeresa Johnson!21 = !DILocation(line: 15, column: 10, scope: !20)
151b8ad6fb0STeresa Johnson!22 = !{i64 -2954124005641725917}
152b8ad6fb0STeresa Johnson!23 = !DILocation(line: 18, column: 13, scope: !24)
153b8ad6fb0STeresa Johnson!24 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 17, type: !4, scopeLine: 17, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
154b8ad6fb0STeresa Johnson!25 = !{i64 8632435727821051414}
155b8ad6fb0STeresa Johnson!26 = !DILocation(line: 19, column: 13, scope: !24)
156b8ad6fb0STeresa Johnson!27 = !{i64 -3421689549917153178}
157b8ad6fb0STeresa Johnson!28 = !DILocation(line: 20, column: 13, scope: !24)
158b8ad6fb0STeresa Johnson!29 = !{i64 6307901912192269588}
159