|
| 1 | +;; This test ensures that the logic which assigns calls to stack nodes |
| 2 | +;; correctly handles a case where multiple nodes have stack ids that |
| 3 | +;; overlap with each other but have different last nodes (can happen with |
| 4 | +;; inlining into various levels of a call chain). Specifically, when we |
| 5 | +;; have one that is duplicated (e.g. unrolling), we need to correctly |
| 6 | +;; handle the case where the context id has already been assigned to |
| 7 | +;; a different call with a different last node. |
| 8 | + |
| 9 | +;; -stats requires asserts |
| 10 | +; REQUIRES: asserts |
| 11 | + |
| 12 | +; RUN: opt -passes=memprof-context-disambiguation -supports-hot-cold-new \ |
| 13 | +; RUN: -memprof-verify-ccg -memprof-verify-nodes \ |
| 14 | +; RUN: -stats -pass-remarks=memprof-context-disambiguation \ |
| 15 | +; RUN: %s -S 2>&1 | FileCheck %s --check-prefix=IR \ |
| 16 | +; RUN: --check-prefix=STATS --check-prefix=REMARKS |
| 17 | + |
| 18 | +; REMARKS: created clone _Z1Ab.memprof.1 |
| 19 | +; REMARKS: created clone _Z3XZNv.memprof.1 |
| 20 | +; REMARKS: call in clone main assigned to call function clone _Z3XZNv.memprof.1 |
| 21 | +;; Make sure the inlined context in _Z3XZNv, which partially overlaps the stack |
| 22 | +;; ids in the shorter inlined context of Z2XZv, correctly calls a cloned |
| 23 | +;; version of Z1Ab, which will call the cold annotated allocation. |
| 24 | +; REMARKS: call in clone _Z3XZNv.memprof.1 assigned to call function clone _Z1Ab.memprof.1 |
| 25 | +; REMARKS: call in clone _Z1Ab.memprof.1 marked with memprof allocation attribute cold |
| 26 | +; REMARKS: call in clone main assigned to call function clone _Z3XZNv |
| 27 | +; REMARKS: call in clone _Z3XZNv assigned to call function clone _Z1Ab |
| 28 | +; REMARKS: call in clone _Z1Ab marked with memprof allocation attribute notcold |
| 29 | + |
| 30 | + |
| 31 | +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" |
| 32 | +target triple = "x86_64-unknown-linux-gnu" |
| 33 | + |
| 34 | +define dso_local void @_Z1Ab() { |
| 35 | +entry: |
| 36 | + %call = call noalias noundef nonnull ptr @_Znam(i64 noundef 10) #1, !memprof !0, !callsite !5 |
| 37 | + ret void |
| 38 | +} |
| 39 | + |
| 40 | +; Function Attrs: nobuiltin |
| 41 | +declare ptr @_Znam(i64) #0 |
| 42 | + |
| 43 | +;; Inlining of stack id 2 into 3. Assume this is called from somewhere else. |
| 44 | +define dso_local void @_Z2XZv() local_unnamed_addr #0 { |
| 45 | +entry: |
| 46 | + ;; Simulate duplication of the callsite (e.g. unrolling). |
| 47 | + tail call void @_Z1Ab(), !callsite !6 |
| 48 | + tail call void @_Z1Ab(), !callsite !6 |
| 49 | + ret void |
| 50 | +} |
| 51 | + |
| 52 | +;; Inlining of stack id 2 into 3 into 4. Called by main below. |
| 53 | +define dso_local void @_Z3XZNv() local_unnamed_addr { |
| 54 | +entry: |
| 55 | + tail call void @_Z1Ab(), !callsite !7 |
| 56 | + ret void |
| 57 | +} |
| 58 | + |
| 59 | +define dso_local noundef i32 @main() local_unnamed_addr { |
| 60 | +entry: |
| 61 | + tail call void @_Z3XZNv(), !callsite !8 ;; Not cold context |
| 62 | + tail call void @_Z3XZNv(), !callsite !9 ;; Cold context |
| 63 | + ret i32 0 |
| 64 | +} |
| 65 | + |
| 66 | +attributes #0 = { nobuiltin } |
| 67 | +attributes #7 = { builtin } |
| 68 | + |
| 69 | +!0 = !{!1, !3} |
| 70 | +;; Not cold context via first call to _Z3XZNv in main |
| 71 | +!1 = !{!2, !"notcold"} |
| 72 | +!2 = !{i64 1, i64 2, i64 3, i64 4, i64 5} |
| 73 | +;; Cold context via second call to _Z3XZNv in main |
| 74 | +!3 = !{!4, !"cold"} |
| 75 | +!4 = !{i64 1, i64 2, i64 3, i64 4, i64 6} |
| 76 | +!5 = !{i64 1} |
| 77 | +!6 = !{i64 2, i64 3} |
| 78 | +!7 = !{i64 2, i64 3, i64 4} |
| 79 | +!8 = !{i64 5} |
| 80 | +!9 = !{i64 6} |
| 81 | + |
| 82 | +; IR: define {{.*}} @_Z1Ab() |
| 83 | +; IR: call {{.*}} @_Znam(i64 noundef 10) #[[NOTCOLD:[0-9]+]] |
| 84 | +; IR: define {{.*}} @_Z2XZv() |
| 85 | +; IR: call {{.*}} @_Z1Ab() |
| 86 | +; IR: call {{.*}} @_Z1Ab() |
| 87 | +; IR: define {{.*}} @_Z3XZNv() |
| 88 | +; IR: call {{.*}} @_Z1Ab() |
| 89 | +; IR: define {{.*}} @main() |
| 90 | +; IR: call {{.*}} @_Z3XZNv() |
| 91 | +; IR: call {{.*}} @_Z3XZNv.memprof.1() |
| 92 | +; IR: define {{.*}} @_Z1Ab.memprof.1() |
| 93 | +; IR: call {{.*}} @_Znam(i64 noundef 10) #[[COLD:[0-9]+]] |
| 94 | +; IR: define {{.*}} @_Z3XZNv.memprof.1() |
| 95 | +; IR: call {{.*}} @_Z1Ab.memprof.1() |
| 96 | + |
| 97 | +; IR: attributes #[[NOTCOLD]] = { "memprof"="notcold" } |
| 98 | +; IR: attributes #[[COLD]] = { "memprof"="cold" } |
| 99 | + |
| 100 | +; STATS: 1 memprof-context-disambiguation - Number of cold static allocations (possibly cloned) |
| 101 | +; STATS: 1 memprof-context-disambiguation - Number of not cold static allocations (possibly cloned) |
| 102 | +; STATS: 2 memprof-context-disambiguation - Number of function clones created during whole program analysis |
0 commit comments