|
| 1 | +;; Test context disambiguation for a callgraph containing multiple memprof |
| 2 | +;; contexts and no inlining, where we need to perform additional cloning |
| 3 | +;; during function assignment/cloning to handle the combination of contexts |
| 4 | +;; to 2 different allocations. |
| 5 | +;; |
| 6 | +;; void E(char **buf1, char **buf2) { |
| 7 | +;; *buf1 = new char[10]; |
| 8 | +;; *buf2 = new char[10]; |
| 9 | +;; } |
| 10 | +;; |
| 11 | +;; void B(char **buf1, char **buf2) { |
| 12 | +;; E(buf1, buf2); |
| 13 | +;; } |
| 14 | +;; |
| 15 | +;; void C(char **buf1, char **buf2) { |
| 16 | +;; E(buf1, buf2); |
| 17 | +;; } |
| 18 | +;; |
| 19 | +;; void D(char **buf1, char **buf2) { |
| 20 | +;; E(buf1, buf2); |
| 21 | +;; } |
| 22 | +;; int main(int argc, char **argv) { |
| 23 | +;; char *cold1, *cold2, *default1, *default2, *default3, *default4; |
| 24 | +;; B(&default1, &default2); |
| 25 | +;; C(&default3, &cold1); |
| 26 | +;; D(&cold2, &default4); |
| 27 | +;; memset(cold1, 0, 10); |
| 28 | +;; memset(cold2, 0, 10); |
| 29 | +;; memset(default1, 0, 10); |
| 30 | +;; memset(default2, 0, 10); |
| 31 | +;; memset(default3, 0, 10); |
| 32 | +;; memset(default4, 0, 10); |
| 33 | +;; delete[] default1; |
| 34 | +;; delete[] default2; |
| 35 | +;; delete[] default3; |
| 36 | +;; delete[] default4; |
| 37 | +;; sleep(10); |
| 38 | +;; delete[] cold1; |
| 39 | +;; delete[] cold2; |
| 40 | +;; return 0; |
| 41 | +;; } |
| 42 | +;; |
| 43 | +;; Code compiled with -mllvm -memprof-min-lifetime-cold-threshold=5 so that the |
| 44 | +;; memory freed after sleep(10) results in cold lifetimes. |
| 45 | +;; |
| 46 | +;; The IR was then reduced using llvm-reduce with the expected FileCheck input. |
| 47 | + |
| 48 | + |
| 49 | +; RUN: opt -thinlto-bc %s >%t.o |
| 50 | +; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \ |
| 51 | +; RUN: -r=%t.o,main,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: -stats -pass-remarks=memprof-context-disambiguation -save-temps \ |
| 57 | +; RUN: -o %t.out 2>&1 | FileCheck %s --check-prefix=DUMP \ |
| 58 | +; RUN: --check-prefix=STATS |
| 59 | + |
| 60 | + |
| 61 | +;; Try again but with distributed ThinLTO |
| 62 | +; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \ |
| 63 | +; RUN: -thinlto-distributed-indexes \ |
| 64 | +; RUN: -r=%t.o,main,plx \ |
| 65 | +; RUN: -r=%t.o,_ZdaPv, \ |
| 66 | +; RUN: -r=%t.o,sleep, \ |
| 67 | +; RUN: -r=%t.o,_Znam, \ |
| 68 | +; RUN: -memprof-verify-ccg -memprof-verify-nodes -memprof-dump-ccg \ |
| 69 | +; RUN: -stats -pass-remarks=memprof-context-disambiguation \ |
| 70 | +; RUN: -o %t2.out 2>&1 | FileCheck %s --check-prefix=DUMP \ |
| 71 | +; RUN: --check-prefix=STATS |
| 72 | + |
| 73 | + |
| 74 | +source_filename = "funcassigncloning.ll" |
| 75 | +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" |
| 76 | +target triple = "x86_64-unknown-linux-gnu" |
| 77 | + |
| 78 | +; Function Attrs: noinline optnone |
| 79 | +define internal void @_Z1EPPcS0_(ptr %buf1, ptr %buf2) { |
| 80 | +entry: |
| 81 | + %call = call ptr @_Znam(i64 noundef 10), !memprof !0, !callsite !7 |
| 82 | + %call1 = call ptr @_Znam(i64 noundef 10), !memprof !8, !callsite !15 |
| 83 | + ret void |
| 84 | +} |
| 85 | + |
| 86 | +declare ptr @_Znam(i64) |
| 87 | + |
| 88 | +define internal void @_Z1BPPcS0_() { |
| 89 | +entry: |
| 90 | + call void @_Z1EPPcS0_(ptr null, ptr null), !callsite !16 |
| 91 | + ret void |
| 92 | +} |
| 93 | + |
| 94 | +define internal void @_Z1CPPcS0_() { |
| 95 | +entry: |
| 96 | + call void @_Z1EPPcS0_(ptr null, ptr null), !callsite !17 |
| 97 | + ret void |
| 98 | +} |
| 99 | + |
| 100 | +define internal void @_Z1DPPcS0_() { |
| 101 | +entry: |
| 102 | + call void @_Z1EPPcS0_(ptr null, ptr null), !callsite !18 |
| 103 | + ret void |
| 104 | +} |
| 105 | + |
| 106 | +; Function Attrs: noinline optnone |
| 107 | +define i32 @main() { |
| 108 | +entry: |
| 109 | + call void @_Z1BPPcS0_() |
| 110 | + call void @_Z1CPPcS0_() |
| 111 | + call void @_Z1DPPcS0_() |
| 112 | + ret i32 0 |
| 113 | +} |
| 114 | + |
| 115 | +declare void @_ZdaPv() |
| 116 | + |
| 117 | +declare i32 @sleep() |
| 118 | + |
| 119 | +; uselistorder directives |
| 120 | +uselistorder ptr @_Znam, { 1, 0 } |
| 121 | + |
| 122 | +!0 = !{!1, !3, !5} |
| 123 | +!1 = !{!2, !"cold"} |
| 124 | +!2 = !{i64 -3461278137325233666, i64 -7799663586031895603} |
| 125 | +!3 = !{!4, !"notcold"} |
| 126 | +!4 = !{i64 -3461278137325233666, i64 -3483158674395044949} |
| 127 | +!5 = !{!6, !"notcold"} |
| 128 | +!6 = !{i64 -3461278137325233666, i64 -2441057035866683071} |
| 129 | +!7 = !{i64 -3461278137325233666} |
| 130 | +!8 = !{!9, !11, !13} |
| 131 | +!9 = !{!10, !"notcold"} |
| 132 | +!10 = !{i64 -1415475215210681400, i64 -2441057035866683071} |
| 133 | +!11 = !{!12, !"cold"} |
| 134 | +!12 = !{i64 -1415475215210681400, i64 -3483158674395044949} |
| 135 | +!13 = !{!14, !"notcold"} |
| 136 | +!14 = !{i64 -1415475215210681400, i64 -7799663586031895603} |
| 137 | +!15 = !{i64 -1415475215210681400} |
| 138 | +!16 = !{i64 -2441057035866683071} |
| 139 | +!17 = !{i64 -3483158674395044949} |
| 140 | +!18 = !{i64 -7799663586031895603} |
| 141 | + |
| 142 | + |
| 143 | +;; Originally we create a single clone of each call to new from E, since each |
| 144 | +;; allocates cold memory for a single caller. |
| 145 | + |
| 146 | +; DUMP: CCG after cloning: |
| 147 | +; DUMP: Callsite Context Graph: |
| 148 | +; DUMP: Node [[ENEW1ORIG:0x[a-z0-9]+]] |
| 149 | +; DUMP: Versions: 1 MIB: |
| 150 | +; DUMP: AllocType 2 StackIds: 0 |
| 151 | +; DUMP: AllocType 1 StackIds: 1 |
| 152 | +; DUMP: AllocType 1 StackIds: 2 |
| 153 | +; DUMP: (clone 0) |
| 154 | +; DUMP: AllocTypes: NotCold |
| 155 | +; DUMP: ContextIds: 2 3 |
| 156 | +; DUMP: CalleeEdges: |
| 157 | +; DUMP: CallerEdges: |
| 158 | +; DUMP: Edge from Callee [[ENEW1ORIG]] to Caller: [[C:0x[a-z0-9]+]] AllocTypes: NotCold ContextIds: 2 |
| 159 | +; DUMP: Edge from Callee [[ENEW1ORIG]] to Caller: [[B:0x[a-z0-9]+]] AllocTypes: NotCold ContextIds: 3 |
| 160 | +; DUMP: Clones: [[ENEW1CLONE:0x[a-z0-9]+]] |
| 161 | + |
| 162 | +; DUMP: Node [[D:0x[a-z0-9]+]] |
| 163 | +; DUMP: Callee: 10758063066234039248 (_Z1EPPcS0_) Clones: 0 StackIds: 0 (clone 0) |
| 164 | +; DUMP: AllocTypes: NotColdCold |
| 165 | +; DUMP: ContextIds: 1 6 |
| 166 | +; DUMP: CalleeEdges: |
| 167 | +; DUMP: Edge from Callee [[ENEW1CLONE]] to Caller: [[D]] AllocTypes: Cold ContextIds: 1 |
| 168 | +; DUMP: Edge from Callee [[ENEW2ORIG:0x[a-z0-9]+]] to Caller: [[D]] AllocTypes: NotCold ContextIds: 6 |
| 169 | +; DUMP: CallerEdges: |
| 170 | + |
| 171 | +; DUMP: Node [[C]] |
| 172 | +; DUMP: Callee: 10758063066234039248 (_Z1EPPcS0_) Clones: 0 StackIds: 1 (clone 0) |
| 173 | +; DUMP: AllocTypes: NotColdCold |
| 174 | +; DUMP: ContextIds: 2 5 |
| 175 | +; DUMP: CalleeEdges: |
| 176 | +; DUMP: Edge from Callee [[ENEW1ORIG]] to Caller: [[C]] AllocTypes: NotCold ContextIds: 2 |
| 177 | +; DUMP: Edge from Callee [[ENEW2CLONE:0x[a-z0-9]+]] to Caller: [[C]] AllocTypes: Cold ContextIds: 5 |
| 178 | +; DUMP: CallerEdges: |
| 179 | + |
| 180 | +; DUMP: Node [[B]] |
| 181 | +; DUMP: Callee: 10758063066234039248 (_Z1EPPcS0_) Clones: 0 StackIds: 2 (clone 0) |
| 182 | +; DUMP: AllocTypes: NotCold |
| 183 | +; DUMP: ContextIds: 3 4 |
| 184 | +; DUMP: CalleeEdges: |
| 185 | +; DUMP: Edge from Callee [[ENEW1ORIG]] to Caller: [[B]] AllocTypes: NotCold ContextIds: 3 |
| 186 | +; DUMP: Edge from Callee [[ENEW2ORIG]] to Caller: [[B]] AllocTypes: NotCold ContextIds: 4 |
| 187 | +; DUMP: CallerEdges: |
| 188 | + |
| 189 | +; DUMP: Node [[ENEW2ORIG]] |
| 190 | +; DUMP: Versions: 1 MIB: |
| 191 | +; DUMP: AllocType 1 StackIds: 2 |
| 192 | +; DUMP: AllocType 2 StackIds: 1 |
| 193 | +; DUMP: AllocType 1 StackIds: 0 |
| 194 | +; DUMP: (clone 0) |
| 195 | +; DUMP: AllocTypes: NotCold |
| 196 | +; DUMP: ContextIds: 4 6 |
| 197 | +; DUMP: CalleeEdges: |
| 198 | +; DUMP: CallerEdges: |
| 199 | +; DUMP: Edge from Callee [[ENEW2ORIG]] to Caller: [[B]] AllocTypes: NotCold ContextIds: 4 |
| 200 | +; DUMP: Edge from Callee [[ENEW2ORIG]] to Caller: [[D]] AllocTypes: NotCold ContextIds: 6 |
| 201 | +; DUMP: Clones: [[ENEW2CLONE]] |
| 202 | + |
| 203 | +; DUMP: Node [[ENEW1CLONE]] |
| 204 | +; DUMP: Versions: 1 MIB: |
| 205 | +; DUMP: AllocType 2 StackIds: 0 |
| 206 | +; DUMP: AllocType 1 StackIds: 1 |
| 207 | +; DUMP: AllocType 1 StackIds: 2 |
| 208 | +; DUMP: (clone 0) |
| 209 | +; DUMP: AllocTypes: Cold |
| 210 | +; DUMP: ContextIds: 1 |
| 211 | +; DUMP: CalleeEdges: |
| 212 | +; DUMP: CallerEdges: |
| 213 | +; DUMP: Edge from Callee [[ENEW1CLONE]] to Caller: [[D]] AllocTypes: Cold ContextIds: 1 |
| 214 | +; DUMP: Clone of [[ENEW1ORIG]] |
| 215 | + |
| 216 | +; DUMP: Node [[ENEW2CLONE]] |
| 217 | +; DUMP: Versions: 1 MIB: |
| 218 | +; DUMP: AllocType 1 StackIds: 2 |
| 219 | +; DUMP: AllocType 2 StackIds: 1 |
| 220 | +; DUMP: AllocType 1 StackIds: 0 |
| 221 | +; DUMP: (clone 0) |
| 222 | +; DUMP: AllocTypes: Cold |
| 223 | +; DUMP: ContextIds: 5 |
| 224 | +; DUMP: CalleeEdges: |
| 225 | +; DUMP: CallerEdges: |
| 226 | +; DUMP: Edge from Callee [[ENEW2CLONE]] to Caller: [[C]] AllocTypes: Cold ContextIds: 5 |
| 227 | +; DUMP: Clone of [[ENEW2ORIG]] |
| 228 | + |
| 229 | + |
| 230 | +; STATS: 2 memprof-context-disambiguation - Number of cold static allocations (possibly cloned) |
| 231 | +; STATS: 4 memprof-context-disambiguation - Number of not cold static allocations (possibly cloned) |
| 232 | +; STATS: 3 memprof-context-disambiguation - Number of function clones created during whole program analysis |
0 commit comments