1;; Test callsite context graph generation for simple call graph with 2;; two memprof contexts and no inlining. 3;; 4;; Original code looks like: 5;; 6;; char *bar() { 7;; return new char[10]; 8;; } 9;; 10;; char *baz() { 11;; return bar(); 12;; } 13;; 14;; char *foo() { 15;; return baz(); 16;; } 17;; 18;; int main(int argc, char **argv) { 19;; char *x = foo(); 20;; char *y = foo(); 21;; memset(x, 0, 10); 22;; memset(y, 0, 10); 23;; delete[] x; 24;; sleep(10); 25;; delete[] y; 26;; return 0; 27;; } 28;; 29;; Code compiled with -mllvm -memprof-min-lifetime-cold-threshold=5 so that the 30;; memory freed after sleep(10) results in cold lifetimes. 31;; 32;; The IR was then reduced using llvm-reduce with the expected FileCheck input. 33 34; RUN: opt -thinlto-bc %s >%t.o 35; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \ 36; RUN: -r=%t.o,main,plx \ 37; RUN: -r=%t.o,_ZdaPv, \ 38; RUN: -r=%t.o,sleep, \ 39; RUN: -r=%t.o,_Znam, \ 40; RUN: -memprof-verify-ccg -memprof-verify-nodes -memprof-dump-ccg \ 41; RUN: -memprof-export-to-dot -memprof-dot-file-path-prefix=%t. \ 42; RUN: -o %t.out 2>&1 | FileCheck %s --check-prefix=DUMP 43 44; RUN: cat %t.ccg.postbuild.dot | FileCheck %s --check-prefix=DOT 45;; We should have cloned bar, baz, and foo, for the cold memory allocation. 46; RUN: cat %t.ccg.cloned.dot | FileCheck %s --check-prefix=DOTCLONED 47 48 49source_filename = "memprof-basic.ll" 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 i32 @main() { 54entry: 55 %call = call ptr @_Z3foov(), !callsite !0 56 %call1 = call ptr @_Z3foov(), !callsite !1 57 ret i32 0 58} 59 60declare void @_ZdaPv() 61 62declare i32 @sleep() 63 64define internal ptr @_Z3barv() { 65entry: 66 %call = call ptr @_Znam(i64 0), !memprof !2, !callsite !7 67 ret ptr null 68} 69 70declare ptr @_Znam(i64) 71 72define internal ptr @_Z3bazv() { 73entry: 74 %call = call ptr @_Z3barv(), !callsite !8 75 ret ptr null 76} 77 78define internal ptr @_Z3foov() { 79entry: 80 %call = call ptr @_Z3bazv(), !callsite !9 81 ret ptr null 82} 83 84; uselistorder directives 85uselistorder ptr @_Z3foov, { 1, 0 } 86 87!0 = !{i64 8632435727821051414} 88!1 = !{i64 -3421689549917153178} 89!2 = !{!3, !5} 90!3 = !{!4, !"notcold"} 91!4 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 8632435727821051414} 92!5 = !{!6, !"cold"} 93!6 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 -3421689549917153178} 94!7 = !{i64 9086428284934609951} 95!8 = !{i64 -5964873800580613432} 96!9 = !{i64 2732490490862098848} 97 98 99; DUMP: CCG before cloning: 100; DUMP: Callsite Context Graph: 101; DUMP: Node [[BAR:0x[a-z0-9]+]] 102; DUMP: Versions: 1 MIB: 103; DUMP: AllocType 1 StackIds: 2, 3, 0 104; DUMP: AllocType 2 StackIds: 2, 3, 1 105; DUMP: (clone 0) 106; DUMP: AllocTypes: NotColdCold 107; DUMP: ContextIds: 1 2 108; DUMP: CalleeEdges: 109; DUMP: CallerEdges: 110; DUMP: Edge from Callee [[BAR]] to Caller: [[BAZ:0x[a-z0-9]+]] AllocTypes: NotColdCold ContextIds: 1 2 111 112; DUMP: Node [[BAZ]] 113; DUMP: Callee: 9832687305761716512 (_Z3barv) Clones: 0 StackIds: 2 (clone 0) 114; DUMP: AllocTypes: NotColdCold 115; DUMP: ContextIds: 1 2 116; DUMP: CalleeEdges: 117; DUMP: Edge from Callee [[BAR]] to Caller: [[BAZ]] AllocTypes: NotColdCold ContextIds: 1 2 118; DUMP: CallerEdges: 119; DUMP: Edge from Callee [[BAZ]] to Caller: [[FOO:0x[a-z0-9]+]] AllocTypes: NotColdCold ContextIds: 1 2 120 121; DUMP: Node [[FOO]] 122; DUMP: Callee: 5878270615442837395 (_Z3bazv) Clones: 0 StackIds: 3 (clone 0) 123; DUMP: AllocTypes: NotColdCold 124; DUMP: ContextIds: 1 2 125; DUMP: CalleeEdges: 126; DUMP: Edge from Callee [[BAZ]] to Caller: [[FOO]] AllocTypes: NotColdCold ContextIds: 1 2 127; DUMP: CallerEdges: 128; DUMP: Edge from Callee [[FOO]] to Caller: [[MAIN1:0x[a-z0-9]+]] AllocTypes: NotCold ContextIds: 1 129; DUMP: Edge from Callee [[FOO]] to Caller: [[MAIN2:0x[a-z0-9]+]] AllocTypes: Cold ContextIds: 2 130 131; DUMP: Node [[MAIN1]] 132; DUMP: Callee: 6731117468105397038 (_Z3foov) Clones: 0 StackIds: 0 (clone 0) 133; DUMP: AllocTypes: NotCold 134; DUMP: ContextIds: 1 135; DUMP: CalleeEdges: 136; DUMP: Edge from Callee [[FOO]] to Caller: [[MAIN1]] AllocTypes: NotCold ContextIds: 1 137; DUMP: CallerEdges: 138 139; DUMP: Node [[MAIN2]] 140; DUMP: Callee: 6731117468105397038 (_Z3foov) Clones: 0 StackIds: 1 (clone 0) 141; DUMP: AllocTypes: Cold 142; DUMP: ContextIds: 2 143; DUMP: CalleeEdges: 144; DUMP: Edge from Callee [[FOO]] to Caller: [[MAIN2]] AllocTypes: Cold ContextIds: 2 145; DUMP: CallerEdges: 146 147; DUMP: CCG after cloning: 148; DUMP: Callsite Context Graph: 149; DUMP: Node [[BAR]] 150; DUMP: Versions: 1 MIB: 151; DUMP: AllocType 1 StackIds: 2, 3, 0 152; DUMP: AllocType 2 StackIds: 2, 3, 1 153; DUMP: (clone 0) 154; DUMP: AllocTypes: NotCold 155; DUMP: ContextIds: 1 156; DUMP: CalleeEdges: 157; DUMP: CallerEdges: 158; DUMP: Edge from Callee [[BAR]] to Caller: [[BAZ]] AllocTypes: NotCold ContextIds: 1 159; DUMP: Clones: [[BAR2:0x[a-z0-9]+]] 160 161; DUMP: Node [[BAZ]] 162; DUMP: Callee: 9832687305761716512 (_Z3barv) Clones: 0 StackIds: 2 (clone 0) 163; DUMP: AllocTypes: NotCold 164; DUMP: ContextIds: 1 165; DUMP: CalleeEdges: 166; DUMP: Edge from Callee [[BAR]] to Caller: [[BAZ]] AllocTypes: NotCold ContextIds: 1 167; DUMP: CallerEdges: 168; DUMP: Edge from Callee [[BAZ]] to Caller: [[FOO]] AllocTypes: NotCold ContextIds: 1 169; DUMP: Clones: [[BAZ2:0x[a-z0-9]+]] 170 171; DUMP: Node [[FOO]] 172; DUMP: Callee: 5878270615442837395 (_Z3bazv) Clones: 0 StackIds: 3 (clone 0) 173; DUMP: AllocTypes: NotCold 174; DUMP: ContextIds: 1 175; DUMP: CalleeEdges: 176; DUMP: Edge from Callee [[BAZ]] to Caller: [[FOO]] AllocTypes: NotCold ContextIds: 1 177; DUMP: CallerEdges: 178; DUMP: Edge from Callee [[FOO]] to Caller: [[MAIN1]] AllocTypes: NotCold ContextIds: 1 179; DUMP: Clones: [[FOO2:0x[a-z0-9]+]] 180 181; DUMP: Node [[MAIN1]] 182; DUMP: Callee: 6731117468105397038 (_Z3foov) Clones: 0 StackIds: 0 (clone 0) 183; DUMP: AllocTypes: NotCold 184; DUMP: ContextIds: 1 185; DUMP: CalleeEdges: 186; DUMP: Edge from Callee [[FOO]] to Caller: [[MAIN1]] AllocTypes: NotCold ContextIds: 1 187; DUMP: CallerEdges: 188 189; DUMP: Node [[MAIN2]] 190; DUMP: Callee: 6731117468105397038 (_Z3foov) Clones: 0 StackIds: 1 (clone 0) 191; DUMP: AllocTypes: Cold 192; DUMP: ContextIds: 2 193; DUMP: CalleeEdges: 194; DUMP: Edge from Callee [[FOO2]] to Caller: [[MAIN2]] AllocTypes: Cold ContextIds: 2 195; DUMP: CallerEdges: 196 197; DUMP: Node [[FOO2]] 198; DUMP: Callee: 5878270615442837395 (_Z3bazv) Clones: 0 StackIds: 3 (clone 0) 199; DUMP: AllocTypes: Cold 200; DUMP: ContextIds: 2 201; DUMP: CalleeEdges: 202; DUMP: Edge from Callee [[BAZ2]] to Caller: [[FOO2]] AllocTypes: Cold ContextIds: 2 203; DUMP: CallerEdges: 204; DUMP: Edge from Callee [[FOO2]] to Caller: [[MAIN2]] AllocTypes: Cold ContextIds: 2 205; DUMP: Clone of [[FOO]] 206 207; DUMP: Node [[BAZ2]] 208; DUMP: Callee: 9832687305761716512 (_Z3barv) Clones: 0 StackIds: 2 (clone 0) 209; DUMP: AllocTypes: Cold 210; DUMP: ContextIds: 2 211; DUMP: CalleeEdges: 212; DUMP: Edge from Callee [[BAR2]] to Caller: [[BAZ2]] AllocTypes: Cold ContextIds: 2 213; DUMP: CallerEdges: 214; DUMP: Edge from Callee [[BAZ2]] to Caller: [[FOO2]] AllocTypes: Cold ContextIds: 2 215; DUMP: Clone of [[BAZ]] 216 217; DUMP: Node [[BAR2]] 218; DUMP: Versions: 1 MIB: 219; DUMP: AllocType 1 StackIds: 2, 3, 0 220; DUMP: AllocType 2 StackIds: 2, 3, 1 221; DUMP: (clone 0) 222; DUMP: AllocTypes: Cold 223; DUMP: ContextIds: 2 224; DUMP: CalleeEdges: 225; DUMP: CallerEdges: 226; DUMP: Edge from Callee [[BAR2]] to Caller: [[BAZ2]] AllocTypes: Cold ContextIds: 2 227; DUMP: Clone of [[BAR]] 228 229 230; DOT: digraph "postbuild" { 231; DOT: label="postbuild"; 232; 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}"]; 233; 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}"]; 234; DOT: Node[[BAZ]] -> Node[[BAR]][tooltip="ContextIds: 1 2",fillcolor="mediumorchid1"]; 235; 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}"]; 236; DOT: Node[[FOO]] -> Node[[BAZ]][tooltip="ContextIds: 1 2",fillcolor="mediumorchid1"]; 237; 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}"]; 238; DOT: Node[[MAIN1]] -> Node[[FOO]][tooltip="ContextIds: 1",fillcolor="brown1"]; 239; 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}"]; 240; DOT: Node[[MAIN2]] -> Node[[FOO]][tooltip="ContextIds: 2",fillcolor="cyan"]; 241; DOT: } 242 243 244; DOTCLONED: digraph "cloned" { 245; DOTCLONED: label="cloned"; 246; 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}"]; 247; 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}"]; 248; DOTCLONED: Node[[BAZ]] -> Node[[BAR]][tooltip="ContextIds: 1",fillcolor="brown1"]; 249; 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}"]; 250; DOTCLONED: Node[[FOO]] -> Node[[BAZ]][tooltip="ContextIds: 1",fillcolor="brown1"]; 251; 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}"]; 252; DOTCLONED: Node[[MAIN1]] -> Node[[FOO]][tooltip="ContextIds: 1",fillcolor="brown1"]; 253; 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}"]; 254; DOTCLONED: Node[[MAIN2]] -> Node[[FOO2:0x[a-z0-9]+]][tooltip="ContextIds: 2",fillcolor="cyan"]; 255; 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}"]; 256; DOTCLONED: Node[[FOO2]] -> Node[[BAZ2:0x[a-z0-9]+]][tooltip="ContextIds: 2",fillcolor="cyan"]; 257; 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}"]; 258; DOTCLONED: Node[[BAZ2]] -> Node[[BAR2:0x[a-z0-9]+]][tooltip="ContextIds: 2",fillcolor="cyan"]; 259; 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}"]; 260; DOTCLONED: } 261