1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
|
;; This test ensures that the logic which assigns calls to stack nodes
;; correctly handles cloning of a callsite for a trimmed cold context
;; that partially overlaps with a longer context for a different allocation.
;; The profile data and call stacks were all manually added, but the code
;; would be structured something like the following (fairly contrived to
;; result in the type of control flow needed to test):
;; void A(bool b) {
;; if (b)
;; // cold: stack ids 10, 12, 13, 15 (trimmed ids 19, 20)
;; // not cold: stack ids 10, 12, 13, 14 (trimmed id 21)
;; new char[10]; // stack id 10
;; else
;; // not cold: stack ids 11, 12, 13, 15, 16, 17 (trimmed id 22)
;; // cold: stack ids 11, 12, 13, 15, 16, 18 (trimmed id 23)
;; new char[10]; // stack id 11
;; }
;;
;; void X(bool b) {
;; A(b); // stack ids 12
;; }
;;
;; void B(bool b) {
;; X(b); // stack id 13
;; }
;;
;; void D() {
;; B(true); // stack id 14
;; }
;;
;; void C(bool b) {
;; B(b); // stack id 15
;; }
;;
;; void E(bool b) {
;; C(b); // stack id 16
;; }
;;
;; void F() {
;; E(false); // stack id 17
;; }
;;
;; void G() {
;; E(false); // stack id 18
;; }
;;
;; void M() {
;; C(true); // stack id 19
;; }
;;
;; int main() {
;; D(); // stack id 20 (leads to not cold allocation)
;; M(); // stack id 21 (leads to cold allocation)
;; F(); // stack id 22 (leads to not cold allocation)
;; G(); // stack id 23 (leads to cold allocation)
;; }
;; -stats requires asserts
; REQUIRES: asserts
; RUN: opt -passes=memprof-context-disambiguation -supports-hot-cold-new \
; RUN: -memprof-verify-ccg -memprof-verify-nodes \
; RUN: -stats -pass-remarks=memprof-context-disambiguation \
; RUN: %s -S 2>&1 | FileCheck %s --check-prefix=IR \
; RUN: --check-prefix=STATS --check-prefix=REMARKS
; REMARKS: created clone _Z1Ab.memprof.1
; REMARKS: created clone _Z1Xb.memprof.1
; REMARKS: created clone _Z1Bb.memprof.1
; REMARKS: created clone _Z1Cb.memprof.1
; REMARKS: created clone _Z1Eb.memprof.1
; REMARKS: call in clone _Z1Gv assigned to call function clone _Z1Eb.memprof.1
; REMARKS: call in clone _Z1Eb.memprof.1 assigned to call function clone _Z1Cb.memprof.1
;; If we don't perform cloning for each allocation separately, we will miss
;; cloning _Z1Cb for the trimmed cold allocation context leading to the
;; allocation at stack id 10.
; REMARKS: call in clone _Z1Cb.memprof.1 assigned to call function clone _Z1Bb.memprof.1
; REMARKS: call in clone _Z1Fv assigned to call function clone _Z1Eb
; REMARKS: call in clone _Z1Eb assigned to call function clone _Z1Cb
; REMARKS: call in clone _Z1Cb assigned to call function clone _Z1Bb.memprof.1
; REMARKS: call in clone _Z1Bb.memprof.1 assigned to call function clone _Z1Xb.memprof.1
; REMARKS: call in clone _Z1Xb.memprof.1 assigned to call function clone _Z1Ab.memprof.1
; REMARKS: call in clone _Z1Ab.memprof.1 marked with memprof allocation attribute cold
; REMARKS: call in clone _Z1Bb.memprof.1 assigned to call function clone _Z1Xb
; REMARKS: call in clone _Z1Dv assigned to call function clone _Z1Bb
; REMARKS: call in clone _Z1Bb assigned to call function clone _Z1Xb
; REMARKS: call in clone _Z1Xb assigned to call function clone _Z1Ab
; REMARKS: call in clone _Z1Ab marked with memprof allocation attribute notcold
; REMARKS: call in clone _Z1Ab.memprof.1 marked with memprof allocation attribute cold
; REMARKS: call in clone _Z1Ab marked with memprof allocation attribute notcold
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
define dso_local void @_Z1Ab(i1 noundef zeroext %b) {
entry:
br i1 %b, label %if.then, label %if.else
if.then:
%call = call noalias noundef nonnull ptr @_Znam(i64 noundef 10) #7, !memprof !0, !callsite !10
br label %if.end
if.else:
%call2 = call noalias noundef nonnull ptr @_Znam(i64 noundef 10) #7, !memprof !5, !callsite !11
br label %if.end
if.end:
ret void
}
; Function Attrs: nobuiltin
declare ptr @_Znam(i64) #0
define dso_local void @_Z1Xb(i1 noundef zeroext %b) {
entry:
tail call void @_Z1Ab(i1 noundef zeroext %b), !callsite !12
ret void
}
define dso_local void @_Z1Bb(i1 noundef zeroext %b) {
entry:
tail call void @_Z1Xb(i1 noundef zeroext %b), !callsite !13
ret void
}
define dso_local void @_Z1Dv() {
entry:
tail call void @_Z1Bb(i1 noundef zeroext true), !callsite !14
ret void
}
define dso_local void @_Z1Cb(i1 noundef zeroext %b) {
entry:
tail call void @_Z1Bb(i1 noundef zeroext %b), !callsite !15
ret void
}
define dso_local void @_Z1Eb(i1 noundef zeroext %b) {
entry:
tail call void @_Z1Cb(i1 noundef zeroext %b), !callsite !16
ret void
}
define dso_local void @_Z1Fv() {
entry:
tail call void @_Z1Eb(i1 noundef zeroext false), !callsite !17
ret void
}
define dso_local void @_Z1Gv() {
entry:
tail call void @_Z1Eb(i1 noundef zeroext false), !callsite !18
ret void
}
define dso_local void @_Z1Mv() {
entry:
tail call void @_Z1Cb(i1 noundef zeroext true), !callsite !19
ret void
}
define dso_local noundef i32 @main() local_unnamed_addr {
entry:
tail call void @_Z1Dv(), !callsite !20 ;; Not cold context
tail call void @_Z1Mv(), !callsite !21 ;; Cold context
tail call void @_Z1Fv(), !callsite !22 ;; Not cold context
tail call void @_Z1Gv(), !callsite !23 ;; Cold context
ret i32 0
}
attributes #0 = { nobuiltin }
attributes #7 = { builtin }
!0 = !{!1, !3}
;; Cold (trimmed) context via call to _Z1Dv in main
!1 = !{!2, !"cold"}
!2 = !{i64 10, i64 12, i64 13, i64 15}
;; Not cold (trimmed) context via call to _Z1Mv in main
!3 = !{!4, !"notcold"}
!4 = !{i64 10, i64 12, i64 13, i64 14}
!5 = !{!6, !8}
;; Not cold (trimmed) context via call to _Z1Fv in main
!6 = !{!7, !"notcold"}
!7 = !{i64 11, i64 12, i64 13, i64 15, i64 16, i64 17}
;; Cold (trimmed) context via call to _Z1Gv in main
!8 = !{!9, !"cold"}
!9 = !{i64 11, i64 12, i64 13, i64 15, i64 16, i64 18}
!10 = !{i64 10}
!11 = !{i64 11}
!12 = !{i64 12}
!13 = !{i64 13}
!14 = !{i64 14}
!15 = !{i64 15}
!16 = !{i64 16}
!17 = !{i64 17}
!18 = !{i64 18}
!19 = !{i64 19}
!20 = !{i64 20}
!21 = !{i64 21}
!22 = !{i64 22}
!23 = !{i64 23}
; IR: define {{.*}} @_Z1Cb(i1 noundef zeroext %b)
; IR-NEXT: entry:
; IR-NEXT: call {{.*}} @_Z1Bb.memprof.1(i1 noundef zeroext %b)
; IR: define {{.*}} @_Z1Ab.memprof.1(i1 noundef zeroext %b)
; IR-NEXT: entry:
; IR-NEXT: br i1 %b, label %if.then, label %if.else
; IR-EMPTY:
; IR-NEXT: if.then:
; IR-NEXT: call {{.*}} @_Znam(i64 noundef 10) #[[COLD:[0-9]+]]
; IR-NEXT: br label %if.end
; IR-EMPTY:
; IR-NEXT: if.else:
; IR-NEXT: call {{.*}} @_Znam(i64 noundef 10) #[[COLD]]
; IR: define {{.*}} @_Z1Xb.memprof.1(i1 noundef zeroext %b)
; IR-NEXT: entry:
; IR-NEXT: call {{.*}} @_Z1Ab.memprof.1(i1 noundef zeroext %b)
; IR: define {{.*}} @_Z1Bb.memprof.1(i1 noundef zeroext %b)
; IR-NEXT: entry:
; IR-NEXT: call {{.*}} @_Z1Xb.memprof.1(i1 noundef zeroext %b)
; IR: attributes #[[COLD]] = { builtin "memprof"="cold" }
; STATS: 2 memprof-context-disambiguation - Number of cold static allocations (possibly cloned)
; STATS: 2 memprof-context-disambiguation - Number of not cold static allocations (possibly cloned)
; STATS: 5 memprof-context-disambiguation - Number of function clones created during whole program analysis
|