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-ave-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;; -stats requires asserts 35; REQUIRES: asserts 36 37; RUN: opt -thinlto-bc %s >%t.o 38; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \ 39; RUN: -r=%t.o,main,plx \ 40; RUN: -r=%t.o,_ZdaPv, \ 41; RUN: -r=%t.o,sleep, \ 42; RUN: -r=%t.o,_Znam, \ 43; RUN: -memprof-verify-ccg -memprof-verify-nodes -memprof-dump-ccg \ 44; RUN: -memprof-export-to-dot -memprof-dot-file-path-prefix=%t. \ 45; RUN: -stats -pass-remarks=memprof-context-disambiguation -save-temps \ 46; RUN: -o %t.out 2>&1 | FileCheck %s --check-prefix=DUMP \ 47; RUN: --check-prefix=STATS 48 49; RUN: cat %t.ccg.postbuild.dot | FileCheck %s --check-prefix=DOT 50;; We should have cloned bar, baz, and foo, for the cold memory allocation. 51; RUN: cat %t.ccg.cloned.dot | FileCheck %s --check-prefix=DOTCLONED 52 53 54;; Try again but with distributed ThinLTO 55; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \ 56; RUN: -thinlto-distributed-indexes \ 57; RUN: -r=%t.o,main,plx \ 58; RUN: -r=%t.o,_ZdaPv, \ 59; RUN: -r=%t.o,sleep, \ 60; RUN: -r=%t.o,_Znam, \ 61; RUN: -memprof-verify-ccg -memprof-verify-nodes -memprof-dump-ccg \ 62; RUN: -memprof-export-to-dot -memprof-dot-file-path-prefix=%t2. \ 63; RUN: -stats -pass-remarks=memprof-context-disambiguation \ 64; RUN: -o %t2.out 2>&1 | FileCheck %s --check-prefix=DUMP \ 65; RUN: --check-prefix=STATS 66 67; RUN: cat %t2.ccg.postbuild.dot | FileCheck %s --check-prefix=DOT 68;; We should have cloned bar, baz, and foo, for the cold memory allocation. 69; RUN: cat %t2.ccg.cloned.dot | FileCheck %s --check-prefix=DOTCLONED 70 71;; Check distributed index 72; RUN: llvm-dis %t.o.thinlto.bc -o - | FileCheck %s --check-prefix=DISTRIB 73 74source_filename = "memprof-basic.ll" 75target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 76target triple = "x86_64-unknown-linux-gnu" 77 78define i32 @main() { 79entry: 80 %call = call ptr @_Z3foov(), !callsite !0 81 %call1 = call ptr @_Z3foov(), !callsite !1 82 ret i32 0 83} 84 85declare void @_ZdaPv() 86 87declare i32 @sleep() 88 89define internal ptr @_Z3barv() { 90entry: 91 %call = call ptr @_Znam(i64 0), !memprof !2, !callsite !7 92 ret ptr null 93} 94 95declare ptr @_Znam(i64) 96 97define internal ptr @_Z3bazv() { 98entry: 99 %call = call ptr @_Z3barv(), !callsite !8 100 ret ptr null 101} 102 103define internal ptr @_Z3foov() { 104entry: 105 %call = call ptr @_Z3bazv(), !callsite !9 106 ret ptr null 107} 108 109; uselistorder directives 110uselistorder ptr @_Z3foov, { 1, 0 } 111 112!0 = !{i64 8632435727821051414} 113!1 = !{i64 -3421689549917153178} 114!2 = !{!3, !5} 115!3 = !{!4, !"notcold"} 116!4 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 8632435727821051414} 117!5 = !{!6, !"cold"} 118!6 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 -3421689549917153178} 119!7 = !{i64 9086428284934609951} 120!8 = !{i64 -5964873800580613432} 121!9 = !{i64 2732490490862098848} 122 123 124; DUMP: CCG before cloning: 125; DUMP: Callsite Context Graph: 126; DUMP: Node [[BAR:0x[a-z0-9]+]] 127; DUMP: Versions: 1 MIB: 128; DUMP: AllocType 1 StackIds: 2, 3, 0 129; DUMP: AllocType 2 StackIds: 2, 3, 1 130; DUMP: (clone 0) 131; DUMP: AllocTypes: NotColdCold 132; DUMP: ContextIds: 1 2 133; DUMP: CalleeEdges: 134; DUMP: CallerEdges: 135; DUMP: Edge from Callee [[BAR]] to Caller: [[BAZ:0x[a-z0-9]+]] AllocTypes: NotColdCold ContextIds: 1 2 136 137; DUMP: Node [[BAZ]] 138; DUMP: Callee: 9832687305761716512 (_Z3barv) Clones: 0 StackIds: 2 (clone 0) 139; DUMP: AllocTypes: NotColdCold 140; DUMP: ContextIds: 1 2 141; DUMP: CalleeEdges: 142; DUMP: Edge from Callee [[BAR]] to Caller: [[BAZ]] AllocTypes: NotColdCold ContextIds: 1 2 143; DUMP: CallerEdges: 144; DUMP: Edge from Callee [[BAZ]] to Caller: [[FOO:0x[a-z0-9]+]] AllocTypes: NotColdCold ContextIds: 1 2 145 146; DUMP: Node [[FOO]] 147; DUMP: Callee: 5878270615442837395 (_Z3bazv) Clones: 0 StackIds: 3 (clone 0) 148; DUMP: AllocTypes: NotColdCold 149; DUMP: ContextIds: 1 2 150; DUMP: CalleeEdges: 151; DUMP: Edge from Callee [[BAZ]] to Caller: [[FOO]] AllocTypes: NotColdCold ContextIds: 1 2 152; DUMP: CallerEdges: 153; DUMP: Edge from Callee [[FOO]] to Caller: [[MAIN1:0x[a-z0-9]+]] AllocTypes: NotCold ContextIds: 1 154; DUMP: Edge from Callee [[FOO]] to Caller: [[MAIN2:0x[a-z0-9]+]] AllocTypes: Cold ContextIds: 2 155 156; DUMP: Node [[MAIN1]] 157; DUMP: Callee: 6731117468105397038 (_Z3foov) Clones: 0 StackIds: 0 (clone 0) 158; DUMP: AllocTypes: NotCold 159; DUMP: ContextIds: 1 160; DUMP: CalleeEdges: 161; DUMP: Edge from Callee [[FOO]] to Caller: [[MAIN1]] AllocTypes: NotCold ContextIds: 1 162; DUMP: CallerEdges: 163 164; DUMP: Node [[MAIN2]] 165; DUMP: Callee: 6731117468105397038 (_Z3foov) Clones: 0 StackIds: 1 (clone 0) 166; DUMP: AllocTypes: Cold 167; DUMP: ContextIds: 2 168; DUMP: CalleeEdges: 169; DUMP: Edge from Callee [[FOO]] to Caller: [[MAIN2]] AllocTypes: Cold ContextIds: 2 170; DUMP: CallerEdges: 171 172; DUMP: CCG after cloning: 173; DUMP: Callsite Context Graph: 174; DUMP: Node [[BAR]] 175; DUMP: Versions: 1 MIB: 176; DUMP: AllocType 1 StackIds: 2, 3, 0 177; DUMP: AllocType 2 StackIds: 2, 3, 1 178; DUMP: (clone 0) 179; DUMP: AllocTypes: NotCold 180; DUMP: ContextIds: 1 181; DUMP: CalleeEdges: 182; DUMP: CallerEdges: 183; DUMP: Edge from Callee [[BAR]] to Caller: [[BAZ]] AllocTypes: NotCold ContextIds: 1 184; DUMP: Clones: [[BAR2:0x[a-z0-9]+]] 185 186; DUMP: Node [[BAZ]] 187; DUMP: Callee: 9832687305761716512 (_Z3barv) Clones: 0 StackIds: 2 (clone 0) 188; DUMP: AllocTypes: NotCold 189; DUMP: ContextIds: 1 190; DUMP: CalleeEdges: 191; DUMP: Edge from Callee [[BAR]] to Caller: [[BAZ]] AllocTypes: NotCold ContextIds: 1 192; DUMP: CallerEdges: 193; DUMP: Edge from Callee [[BAZ]] to Caller: [[FOO]] AllocTypes: NotCold ContextIds: 1 194; DUMP: Clones: [[BAZ2:0x[a-z0-9]+]] 195 196; DUMP: Node [[FOO]] 197; DUMP: Callee: 5878270615442837395 (_Z3bazv) Clones: 0 StackIds: 3 (clone 0) 198; DUMP: AllocTypes: NotCold 199; DUMP: ContextIds: 1 200; DUMP: CalleeEdges: 201; DUMP: Edge from Callee [[BAZ]] to Caller: [[FOO]] AllocTypes: NotCold ContextIds: 1 202; DUMP: CallerEdges: 203; DUMP: Edge from Callee [[FOO]] to Caller: [[MAIN1]] AllocTypes: NotCold ContextIds: 1 204; DUMP: Clones: [[FOO2:0x[a-z0-9]+]] 205 206; DUMP: Node [[MAIN1]] 207; DUMP: Callee: 6731117468105397038 (_Z3foov) Clones: 0 StackIds: 0 (clone 0) 208; DUMP: AllocTypes: NotCold 209; DUMP: ContextIds: 1 210; DUMP: CalleeEdges: 211; DUMP: Edge from Callee [[FOO]] to Caller: [[MAIN1]] AllocTypes: NotCold ContextIds: 1 212; DUMP: CallerEdges: 213 214; DUMP: Node [[MAIN2]] 215; DUMP: Callee: 6731117468105397038 (_Z3foov) Clones: 0 StackIds: 1 (clone 0) 216; DUMP: AllocTypes: Cold 217; DUMP: ContextIds: 2 218; DUMP: CalleeEdges: 219; DUMP: Edge from Callee [[FOO2]] to Caller: [[MAIN2]] AllocTypes: Cold ContextIds: 2 220; DUMP: CallerEdges: 221 222; DUMP: Node [[FOO2]] 223; DUMP: Callee: 5878270615442837395 (_Z3bazv) Clones: 0 StackIds: 3 (clone 0) 224; DUMP: AllocTypes: Cold 225; DUMP: ContextIds: 2 226; DUMP: CalleeEdges: 227; DUMP: Edge from Callee [[BAZ2]] to Caller: [[FOO2]] AllocTypes: Cold ContextIds: 2 228; DUMP: CallerEdges: 229; DUMP: Edge from Callee [[FOO2]] to Caller: [[MAIN2]] AllocTypes: Cold ContextIds: 2 230; DUMP: Clone of [[FOO]] 231 232; DUMP: Node [[BAZ2]] 233; DUMP: Callee: 9832687305761716512 (_Z3barv) Clones: 0 StackIds: 2 (clone 0) 234; DUMP: AllocTypes: Cold 235; DUMP: ContextIds: 2 236; DUMP: CalleeEdges: 237; DUMP: Edge from Callee [[BAR2]] to Caller: [[BAZ2]] AllocTypes: Cold ContextIds: 2 238; DUMP: CallerEdges: 239; DUMP: Edge from Callee [[BAZ2]] to Caller: [[FOO2]] AllocTypes: Cold ContextIds: 2 240; DUMP: Clone of [[BAZ]] 241 242; DUMP: Node [[BAR2]] 243; DUMP: Versions: 1 MIB: 244; DUMP: AllocType 1 StackIds: 2, 3, 0 245; DUMP: AllocType 2 StackIds: 2, 3, 1 246; DUMP: (clone 0) 247; DUMP: AllocTypes: Cold 248; DUMP: ContextIds: 2 249; DUMP: CalleeEdges: 250; DUMP: CallerEdges: 251; DUMP: Edge from Callee [[BAR2]] to Caller: [[BAZ2]] AllocTypes: Cold ContextIds: 2 252; DUMP: Clone of [[BAR]] 253 254 255; STATS: 1 memprof-context-disambiguation - Number of cold static allocations (possibly cloned) 256; STATS: 1 memprof-context-disambiguation - Number of not cold static allocations (possibly cloned) 257; STATS: 3 memprof-context-disambiguation - Number of function clones created during whole program analysis 258 259 260; DOT: digraph "postbuild" { 261; DOT: label="postbuild"; 262; 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}"]; 263; 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}"]; 264; DOT: Node[[BAZ]] -> Node[[BAR]][tooltip="ContextIds: 1 2",fillcolor="mediumorchid1"]; 265; 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}"]; 266; DOT: Node[[FOO]] -> Node[[BAZ]][tooltip="ContextIds: 1 2",fillcolor="mediumorchid1"]; 267; 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}"]; 268; DOT: Node[[MAIN1]] -> Node[[FOO]][tooltip="ContextIds: 1",fillcolor="brown1"]; 269; 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}"]; 270; DOT: Node[[MAIN2]] -> Node[[FOO]][tooltip="ContextIds: 2",fillcolor="cyan"]; 271; DOT: } 272 273 274; DOTCLONED: digraph "cloned" { 275; DOTCLONED: label="cloned"; 276; 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}"]; 277; 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}"]; 278; DOTCLONED: Node[[BAZ]] -> Node[[BAR]][tooltip="ContextIds: 1",fillcolor="brown1"]; 279; 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}"]; 280; DOTCLONED: Node[[FOO]] -> Node[[BAZ]][tooltip="ContextIds: 1",fillcolor="brown1"]; 281; 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}"]; 282; DOTCLONED: Node[[MAIN1]] -> Node[[FOO]][tooltip="ContextIds: 1",fillcolor="brown1"]; 283; 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}"]; 284; DOTCLONED: Node[[MAIN2]] -> Node[[FOO2:0x[a-z0-9]+]][tooltip="ContextIds: 2",fillcolor="cyan"]; 285; 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}"]; 286; DOTCLONED: Node[[FOO2]] -> Node[[BAZ2:0x[a-z0-9]+]][tooltip="ContextIds: 2",fillcolor="cyan"]; 287; 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}"]; 288; DOTCLONED: Node[[BAZ2]] -> Node[[BAR2:0x[a-z0-9]+]][tooltip="ContextIds: 2",fillcolor="cyan"]; 289; 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}"]; 290; DOTCLONED: } 291 292 293; DISTRIB: ^[[BAZ:[0-9]+]] = gv: (guid: 5878270615442837395, {{.*}} callsites: ((callee: ^[[BAR:[0-9]+]], clones: (0, 1) 294; DISTRIB: ^[[FOO:[0-9]+]] = gv: (guid: 6731117468105397038, {{.*}} callsites: ((callee: ^[[BAZ]], clones: (0, 1) 295; DISTRIB: ^[[BAR]] = gv: (guid: 9832687305761716512, {{.*}} allocs: ((versions: (notcold, cold) 296; DISTRIB: ^[[MAIN:[0-9]+]] = gv: (guid: 15822663052811949562, {{.*}} callsites: ((callee: ^[[FOO]], clones: (0), {{.*}} (callee: ^[[FOO]], clones: (1) 297