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 -thinlto-bc %s >%t.o
46 ; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \
47 ; RUN: -supports-hot-cold-new \
48 ; RUN: -r=%t.o,main,plx \
49 ; RUN: -r=%t.o,_Z3barv,plx \
50 ; RUN: -r=%t.o,_Z3bazv,plx \
51 ; RUN: -r=%t.o,_Z3foov,plx \
52 ; RUN: -r=%t.o,_ZdaPv, \
53 ; RUN: -r=%t.o,sleep, \
54 ; RUN: -r=%t.o,_Znam, \
55 ; RUN: -memprof-verify-ccg -memprof-verify-nodes -memprof-dump-ccg \
56 ; RUN: -o %t.out 2>&1 | FileCheck %s --check-prefix=DUMP
59 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
60 target triple = "x86_64-unknown-linux-gnu"
62 define ptr @_Z3barv() {
64 %call = call ptr @_Znam(i64 0), !memprof !0, !callsite !5
68 declare ptr @_Znam(i64)
70 declare ptr @_Z3bazv()
72 declare ptr @_Z3foov()
76 %call.i.i = call ptr @_Z3barv(), !callsite !6
77 %call.i.i8 = call ptr @_Z3barv(), !callsite !7
81 declare void @_ZdaPv()
86 !1 = !{!2, !"notcold"}
87 !2 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 8632435727821051414}
89 !4 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 -3421689549917153178}
90 !5 = !{i64 9086428284934609951}
91 !6 = !{i64 -5964873800580613432, i64 2732490490862098848, i64 8632435727821051414}
92 !7 = !{i64 -5964873800580613432, i64 2732490490862098848, i64 -3421689549917153178}
95 ; DUMP: CCG before cloning:
96 ; DUMP: Callsite Context Graph:
97 ; DUMP: Node [[BAR:0x[a-z0-9]+]]
98 ; DUMP: Versions: 1 MIB:
99 ; DUMP: AllocType 1 StackIds: 0, 1, 2
100 ; DUMP: AllocType 2 StackIds: 0, 1, 3
102 ; DUMP: AllocTypes: NotColdCold
103 ; DUMP: ContextIds: 1 2
106 ; DUMP: Edge from Callee [[BAR]] to Caller: [[MAIN1:0x[a-z0-9]+]] AllocTypes: NotCold ContextIds: 1
107 ; DUMP: Edge from Callee [[BAR]] to Caller: [[MAIN2:0x[a-z0-9]+]] AllocTypes: Cold ContextIds: 2
109 ;; This is the node synthesized for the first inlined call chain of main->foo->baz
110 ; DUMP: Node [[MAIN1]]
111 ; DUMP: Callee: 17377440600225628772 (_Z3barv) Clones: 0 StackIds: 0, 1, 2 (clone 0)
112 ; DUMP: AllocTypes: NotCold
113 ; DUMP: ContextIds: 1
115 ; DUMP: Edge from Callee [[BAR]] to Caller: [[MAIN1]] AllocTypes: NotCold ContextIds: 1
118 ;; This is the node synthesized for the second inlined call chain of main->foo->baz
119 ; DUMP: Node [[MAIN2]]
120 ; DUMP: Callee: 17377440600225628772 (_Z3barv) Clones: 0 StackIds: 0, 1, 3 (clone 0)
121 ; DUMP: AllocTypes: Cold
122 ; DUMP: ContextIds: 2
124 ; DUMP: Edge from Callee [[BAR]] to Caller: [[MAIN2]] AllocTypes: Cold ContextIds: 2