xref: /llvm-project/llvm/test/Transforms/MemProfContextDisambiguation/inlined2.ll (revision 176889868024d98db032842bc47b416997d9e349)
1;; Test callsite context graph generation for call graph with two memprof
2;; contexts and multiple levels of inlining, requiring generation of new
3;; fused nodes to represent the inlined sequence while matching callsite
4;; nodes onto the graph. In particular this tests the case where a function
5;; has inlined a callee containing an inlined callee.
6;;
7;; Original code looks like:
8;;
9;; char *bar() __attribute__((noinline)) {
10;;   return new char[10];
11;; }
12;;
13;; char *baz() {
14;;   return bar();
15;; }
16;;
17;; char *foo() {
18;;   return baz();
19;; }
20;;
21;; int main(int argc, char **argv) {
22;;   char *x = foo();
23;;   char *y = foo();
24;;   memset(x, 0, 10);
25;;   memset(y, 0, 10);
26;;   delete[] x;
27;;   sleep(10);
28;;   delete[] y;
29;;   return 0;
30;; }
31;;
32;; Code compiled with -mllvm -memprof-ave-lifetime-cold-threshold=5 so that the
33;; memory freed after sleep(10) results in cold lifetimes.
34;;
35;; Both foo and baz are inlined into main, at both foo callsites.
36;; We should update the graph for new fused nodes for both of those inlined
37;; callsites to bar.
38;;
39;; Note that baz and bar are both dead due to the inlining, but have been left
40;; in the input IR to ensure that the MIB call chain is matched to the longer
41;; inline sequences from main.
42;;
43;; The IR was then reduced using llvm-reduce with the expected FileCheck input.
44
45; RUN: opt -passes=memprof-context-disambiguation -supports-hot-cold-new \
46; RUN:	-memprof-verify-ccg -memprof-verify-nodes -memprof-dump-ccg \
47; RUN:	%s -S 2>&1 | FileCheck %s --check-prefix=DUMP
48
49
50target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
51target triple = "x86_64-unknown-linux-gnu"
52
53define ptr @_Z3barv() #0 {
54entry:
55  %call = call noalias noundef nonnull dereferenceable(10) ptr @_Znam(i64 noundef 10) #7, !memprof !7, !callsite !12, !heapallocsite !13
56  ret ptr null
57}
58
59; Function Attrs: nobuiltin
60declare ptr @_Znam(i64) #1
61
62; Function Attrs: mustprogress
63declare ptr @_Z3bazv() #2
64
65define i32 @main() #3 {
66delete.end5:
67  %call.i.i = call noundef ptr @_Z3barv(), !callsite !14
68  %call.i.i8 = call noundef ptr @_Z3barv(), !callsite !15
69  ret i32 0
70}
71
72; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
73declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4
74
75declare void @_ZdaPv() #5
76
77declare i32 @sleep() #6
78
79attributes #0 = { "stack-protector-buffer-size"="8" }
80attributes #1 = { nobuiltin }
81attributes #2 = { mustprogress }
82attributes #3 = { "tune-cpu"="generic" }
83attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
84attributes #5 = { "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" }
85attributes #6 = { "disable-tail-calls"="true" }
86attributes #7 = { builtin }
87
88!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6}
89
90!0 = !{i32 7, !"Dwarf Version", i32 5}
91!1 = !{i32 2, !"Debug Info Version", i32 3}
92!2 = !{i32 1, !"wchar_size", i32 4}
93!3 = !{i32 8, !"PIC Level", i32 2}
94!4 = !{i32 7, !"PIE Level", i32 2}
95!5 = !{i32 7, !"uwtable", i32 2}
96!6 = !{i32 7, !"frame-pointer", i32 2}
97!7 = !{!8, !10}
98!8 = !{!9, !"notcold"}
99!9 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 8632435727821051414}
100!10 = !{!11, !"cold"}
101!11 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 -3421689549917153178}
102!12 = !{i64 9086428284934609951}
103!13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
104!14 = !{i64 -5964873800580613432, i64 2732490490862098848, i64 8632435727821051414}
105!15 = !{i64 -5964873800580613432, i64 2732490490862098848, i64 -3421689549917153178}
106
107
108; DUMP: CCG before cloning:
109; DUMP: Callsite Context Graph:
110; DUMP: Node [[BAR:0x[a-z0-9]+]]
111; DUMP: 	  %call = call noalias noundef nonnull dereferenceable(10) ptr @_Znam(i64 noundef 10) #7, !heapallocsite !7	(clone 0)
112; DUMP: 	AllocTypes: NotColdCold
113; DUMP: 	ContextIds: 1 2
114; DUMP: 	CalleeEdges:
115; DUMP: 	CallerEdges:
116; DUMP: 		Edge from Callee [[BAR]] to Caller: [[MAIN1:0x[a-z0-9]+]] AllocTypes: NotCold ContextIds: 1
117; DUMP: 		Edge from Callee [[BAR]] to Caller: [[MAIN2:0x[a-z0-9]+]] AllocTypes: Cold ContextIds: 2
118
119;; This is the node synthesized for the first inlined call chain of main->foo->baz
120; DUMP: Node [[MAIN1]]
121; DUMP: 	  %call.i.i = call noundef ptr @_Z3barv()	(clone 0)
122; DUMP: 	AllocTypes: NotCold
123; DUMP: 	ContextIds: 1
124; DUMP: 	CalleeEdges:
125; DUMP: 		Edge from Callee [[BAR]] to Caller: [[MAIN1]] AllocTypes: NotCold ContextIds: 1
126; DUMP: 	CallerEdges:
127
128;; This is the node synthesized for the second inlined call chain of main->foo->baz
129; DUMP: Node [[MAIN2]]
130; DUMP: 	  %call.i.i8 = call noundef ptr @_Z3barv()	(clone 0)
131; DUMP: 	AllocTypes: Cold
132; DUMP: 	ContextIds: 2
133; DUMP: 	CalleeEdges:
134; DUMP: 		Edge from Callee [[BAR]] to Caller: [[MAIN2]] AllocTypes: Cold ContextIds: 2
135; DUMP: 	CallerEdges:
136