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.
7 ;; Original code looks like:
9 ;; char *bar() __attribute__((noinline)) {
10 ;; return new char[10];
21 ;; int main(int argc, char **argv) {
32 ;; Code compiled with -mllvm -memprof-ave-lifetime-cold-threshold=5 so that the
33 ;; memory freed after sleep(10) results in cold lifetimes.
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
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.
43 ;; The IR was then reduced using llvm-reduce with the expected FileCheck input.
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
50 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
51 target triple = "x86_64-unknown-linux-gnu"
53 define ptr @_Z3barv() #0 {
55 %call = call noalias noundef nonnull dereferenceable(10) ptr @_Znam(i64 noundef 10) #7, !memprof !7, !callsite !12, !heapallocsite !13
59 ; Function Attrs: nobuiltin
60 declare ptr @_Znam(i64) #1
62 ; Function Attrs: mustprogress
63 declare ptr @_Z3bazv() #2
65 define i32 @main() #3 {
67 %call.i.i = call noundef ptr @_Z3barv(), !callsite !14
68 %call.i.i8 = call noundef ptr @_Z3barv(), !callsite !15
72 ; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
73 declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4
75 declare void @_ZdaPv() #5
77 declare i32 @sleep() #6
79 attributes #0 = { "stack-protector-buffer-size"="8" }
80 attributes #1 = { nobuiltin }
81 attributes #2 = { mustprogress }
82 attributes #3 = { "tune-cpu"="generic" }
83 attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
84 attributes #5 = { "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" }
85 attributes #6 = { "disable-tail-calls"="true" }
86 attributes #7 = { builtin }
88 !llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6}
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}
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}
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
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
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
125 ; DUMP: Edge from Callee [[BAR]] to Caller: [[MAIN1]] AllocTypes: NotCold ContextIds: 1
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
134 ; DUMP: Edge from Callee [[BAR]] to Caller: [[MAIN2]] AllocTypes: Cold ContextIds: 2