xref: /llvm-project/llvm/test/ThinLTO/X86/memprof-tailcall.ll (revision 26a8664ed4573ef1559c4edc7b254a10d186d428)
1;; Test to make sure that missing tail call frames in memprof profiles are
2;; identified and cloned as needed for regular LTO.
3
4;; -stats requires asserts
5; REQUIRES: asserts
6
7; RUN: opt -thinlto-bc %s >%t.o
8; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \
9; RUN:  -supports-hot-cold-new \
10; RUN:  -r=%t.o,_Z3barv,plx \
11; RUN:  -r=%t.o,_Z3bazv,plx \
12; RUN:  -r=%t.o,_Z3foov,plx \
13; RUN:  -r=%t.o,main,plx \
14; RUN:  -r=%t.o,_Znam, \
15; RUN:  -stats -save-temps \
16; RUN:  -o %t.out 2>&1 | FileCheck %s --check-prefix=STATS
17
18; RUN: llvm-dis %t.out.1.4.opt.bc -o - | FileCheck %s --check-prefix=IR
19
20;; Try again but with distributed ThinLTO
21; RUN: llvm-lto2 run %t.o -enable-memprof-context-disambiguation \
22; RUN:  -supports-hot-cold-new \
23; RUN:  -thinlto-distributed-indexes \
24; RUN:  -r=%t.o,_Z3barv,plx \
25; RUN:  -r=%t.o,_Z3bazv,plx \
26; RUN:  -r=%t.o,_Z3foov,plx \
27; RUN:  -r=%t.o,main,plx \
28; RUN:  -r=%t.o,_Znam, \
29; RUN:  -stats \
30; RUN:  -o %t2.out 2>&1 | FileCheck %s --check-prefix=STATS
31
32;; Run ThinLTO backend
33; RUN: opt -passes=memprof-context-disambiguation \
34; RUN:  -memprof-import-summary=%t.o.thinlto.bc \
35; RUN:  -stats %t.o -S 2>&1 | FileCheck %s --check-prefix=IR
36
37; STATS: 2 memprof-context-disambiguation - Number of profiled callees found via tail calls
38; STATS: 4 memprof-context-disambiguation - Aggregate depth of profiled callees found via tail calls
39; STATS: 2 memprof-context-disambiguation - Maximum depth of profiled callees found via tail calls
40
41source_filename = "memprof-tailcall.cc"
42target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
43target triple = "x86_64-unknown-linux-gnu"
44
45; Function Attrs: noinline
46; IR-LABEL: @_Z3barv()
47define ptr @_Z3barv() local_unnamed_addr #0 {
48entry:
49  ; IR: call {{.*}} @_Znam(i64 10) #[[NOTCOLD:[0-9]+]]
50  %call = tail call ptr @_Znam(i64 10) #2, !memprof !0, !callsite !5
51  ret ptr %call
52}
53
54; Function Attrs: nobuiltin allocsize(0)
55declare ptr @_Znam(i64) #1
56
57; Function Attrs: noinline
58; IR-LABEL: @_Z3bazv()
59define ptr @_Z3bazv() #0 {
60entry:
61  ; IR: call ptr @_Z3barv()
62  %call = tail call ptr @_Z3barv()
63  ret ptr %call
64}
65
66; Function Attrs: noinline
67; IR-LABEL: @_Z3foov()
68define ptr @_Z3foov() #0 {
69entry:
70  ; IR: call ptr @_Z3bazv()
71  %call = tail call ptr @_Z3bazv()
72  ret ptr %call
73}
74
75; Function Attrs: noinline
76; IR-LABEL: @main()
77define i32 @main() #0 {
78  ;; The first call to foo is part of a cold context, and should use the
79  ;; original functions.
80  ; IR: call ptr @_Z3foov()
81  %call = tail call ptr @_Z3foov(), !callsite !6
82  ;; The second call to foo is part of a cold context, and should call the
83  ;; cloned functions.
84  ; IR: call ptr @_Z3foov.memprof.1()
85  %call1 = tail call ptr @_Z3foov(), !callsite !7
86  ret i32 0
87}
88
89; IR-LABEL: @_Z3barv.memprof.1()
90; IR: call {{.*}} @_Znam(i64 10) #[[COLD:[0-9]+]]
91; IR-LABEL: @_Z3bazv.memprof.1()
92; IR: call ptr @_Z3barv.memprof.1()
93; IR-LABEL: @_Z3foov.memprof.1()
94; IR: call ptr @_Z3bazv.memprof.1()
95
96; IR: attributes #[[NOTCOLD]] = { builtin allocsize(0) "memprof"="notcold" }
97; IR: attributes #[[COLD]] = { builtin allocsize(0) "memprof"="cold" }
98
99attributes #0 = { noinline }
100attributes #1 = { nobuiltin allocsize(0) }
101attributes #2 = { builtin allocsize(0) }
102
103!0 = !{!1, !3}
104!1 = !{!2, !"notcold"}
105!2 = !{i64 3186456655321080972, i64 8632435727821051414}
106!3 = !{!4, !"cold"}
107!4 = !{i64 3186456655321080972, i64 -3421689549917153178}
108!5 = !{i64 3186456655321080972}
109!6 = !{i64 8632435727821051414}
110!7 = !{i64 -3421689549917153178}
111