Reapply profiling tests.
[oota-llvm.git] / test / Analysis / Profiling / profiling-tool-chain.ll
1 ; RUN: llvm-as %s -o %t1
2 ; RUN: opt %t1 -insert-optimal-edge-profiling -o %t2
3 ; RUN: llvm-dis < %t2 | FileCheck --check-prefix=INST %s
4 ; RUN: rm -f llvmprof.out
5 ; RUN: lli -load %llvmlibsdir/profile_rt%shlibext %t2
6 ; RUN: lli -load %llvmlibsdir/profile_rt%shlibext %t2 1 2
7 ; RUN: llvm-prof -print-all-code %t1 | FileCheck --check-prefix=PROF %s
8
9 ; PROF:  1.     2/4 oneblock
10 ; PROF:  2.     2/4 main
11 ; PROF:  1. 15.7895%    12/76   main() - bb6
12 ; PROF:  2. 11.8421%     9/76   main() - bb2
13 ; PROF:  3. 11.8421%     9/76   main() - bb3
14 ; PROF:  4. 11.8421%     9/76   main() - bb5
15 ; PROF:  5. 10.5263%     8/76   main() - bb10
16 ; PROF:  6. 7.89474%     6/76   main() - bb
17 ; PROF:  7. 7.89474%     6/76   main() - bb9
18 ; PROF:  8. 3.94737%     3/76   main() - bb1
19 ; PROF:  9. 3.94737%     3/76   main() - bb7
20 ; PROF: 10. 3.94737%     3/76   main() - bb8
21 ; PROF: 11. 2.63158%     2/76   oneblock() - entry
22 ; PROF: 12. 2.63158%     2/76   main() - entry
23 ; PROF: 13. 2.63158%     2/76   main() - bb11
24 ; PROF: 14. 2.63158%     2/76   main() - return
25
26 ; ModuleID = '<stdin>'
27
28 @.str = private constant [12 x i8] c"hello world\00", align 1 ; <[12 x i8]*> [#uses=1]
29 @.str1 = private constant [6 x i8] c"franz\00", align 1 ; <[6 x i8]*> [#uses=1]
30 @.str2 = private constant [9 x i8] c"argc > 2\00", align 1 ; <[9 x i8]*> [#uses=1]
31 @.str3 = private constant [9 x i8] c"argc = 1\00", align 1 ; <[9 x i8]*> [#uses=1]
32 @.str4 = private constant [6 x i8] c"fritz\00", align 1 ; <[6 x i8]*> [#uses=1]
33 @.str5 = private constant [10 x i8] c"argc <= 1\00", align 1 ; <[10 x i8]*> [#uses=1]
34 ; INST:@OptEdgeProfCounters
35 ; INST:[21 x i32]
36 ; INST:[i32 0,
37 ; INST:i32 -1,
38 ; INST:i32 -1,
39 ; INST:i32 -1,
40 ; INST:i32 -1,
41 ; INST:i32 -1,
42 ; INST:i32 -1,
43 ; INST:i32 -1,
44 ; INST:i32 -1,
45 ; INST:i32 0,
46 ; INST:i32 0,
47 ; INST:i32 -1,
48 ; INST:i32 -1,
49 ; INST:i32 -1,
50 ; INST:i32 0,
51 ; INST:i32 0,
52 ; INST:i32 -1,
53 ; INST:i32 -1,
54 ; INST:i32 0,
55 ; INST:i32 -1,
56 ; INST:i32 -1]
57
58 ; PROF:;;; %oneblock called 2 times.
59 ; PROF:;;;
60 define void @oneblock() nounwind {
61 entry:
62 ; PROF:entry:
63 ; PROF: ;;; Basic block executed 2 times.
64   %0 = call i32 @puts(i8* getelementptr inbounds ([12 x i8]* @.str, i64 0, i64 0)) nounwind ; <i32> [#uses=0]
65   ret void
66 }
67
68 declare i32 @puts(i8*)
69
70 ; PROF:;;; %main called 2 times.
71 ; PROF:;;;
72 define i32 @main(i32 %argc, i8** %argv) nounwind {
73 entry:
74 ; PROF:entry:
75 ; PROF: ;;; Basic block executed 2 times.
76   %argc_addr = alloca i32                         ; <i32*> [#uses=4]
77   %argv_addr = alloca i8**                        ; <i8***> [#uses=1]
78   %retval = alloca i32                            ; <i32*> [#uses=2]
79   %j = alloca i32                                 ; <i32*> [#uses=4]
80   %i = alloca i32                                 ; <i32*> [#uses=4]
81   %0 = alloca i32                                 ; <i32*> [#uses=2]
82 ; INST:call 
83 ; INST:@llvm_start_opt_edge_profiling
84 ; INST:@OptEdgeProfCounters
85   %"alloca point" = bitcast i32 0 to i32          ; <i32> [#uses=0]
86   store i32 %argc, i32* %argc_addr
87   store i8** %argv, i8*** %argv_addr
88   store i32 0, i32* %i, align 4
89   br label %bb10
90 ; PROF: ;;; Out-edge counts: [2.000000e+00 -> bb10]
91
92 bb:                                               ; preds = %bb10
93 ; PROF:bb:
94 ; PROF: ;;; Basic block executed 6 times.
95   %1 = load i32* %argc_addr, align 4              ; <i32> [#uses=1]
96   %2 = icmp sgt i32 %1, 1                         ; <i1> [#uses=1]
97   br i1 %2, label %bb1, label %bb8
98 ; PROF: ;;; Out-edge counts: [3.000000e+00 -> bb1] [3.000000e+00 -> bb8]
99
100 bb1:                                              ; preds = %bb
101 ; PROF:bb1:
102 ; PROF: ;;; Basic block executed 3 times.
103   store i32 0, i32* %j, align 4
104   br label %bb6
105 ; PROF: ;;; Out-edge counts: [3.000000e+00 -> bb6]
106
107 bb2:                                              ; preds = %bb6
108 ; PROF:bb2:
109 ; PROF: ;;; Basic block executed 9 times.
110   %3 = call i32 @puts(i8* getelementptr inbounds ([6 x i8]* @.str1, i64 0, i64 0)) nounwind ; <i32> [#uses=0]
111   %4 = load i32* %argc_addr, align 4              ; <i32> [#uses=1]
112   %5 = icmp sgt i32 %4, 2                         ; <i1> [#uses=1]
113   br i1 %5, label %bb3, label %bb4
114 ; PROF: ;;; Out-edge counts: [9.000000e+00 -> bb3]
115
116 bb3:                                              ; preds = %bb2
117 ; PROF:bb3:
118 ; PROF: ;;; Basic block executed 9 times.
119   %6 = call i32 @puts(i8* getelementptr inbounds ([9 x i8]* @.str2, i64 0, i64 0)) nounwind ; <i32> [#uses=0]
120   br label %bb5
121 ; PROF: ;;; Out-edge counts: [9.000000e+00 -> bb5]
122
123 bb4:                                              ; preds = %bb2
124 ; PROF:bb4:
125 ; PROF: ;;; Never executed!
126   %7 = call i32 @puts(i8* getelementptr inbounds ([9 x i8]* @.str3, i64 0, i64 0)) nounwind ; <i32> [#uses=0]
127   br label %bb11
128
129 bb5:                                              ; preds = %bb3
130 ; PROF:bb5:
131 ; PROF: ;;; Basic block executed 9 times.
132   %8 = call i32 @puts(i8* getelementptr inbounds ([6 x i8]* @.str4, i64 0, i64 0)) nounwind ; <i32> [#uses=0]
133   %9 = load i32* %j, align 4                      ; <i32> [#uses=1]
134   %10 = add nsw i32 %9, 1                         ; <i32> [#uses=1]
135   store i32 %10, i32* %j, align 4
136   br label %bb6
137 ; PROF: ;;; Out-edge counts: [9.000000e+00 -> bb6]
138
139 bb6:                                              ; preds = %bb5, %bb1
140 ; PROF:bb6:
141 ; PROF: ;;; Basic block executed 12 times.
142   %11 = load i32* %j, align 4                     ; <i32> [#uses=1]
143   %12 = load i32* %argc_addr, align 4             ; <i32> [#uses=1]
144   %13 = icmp slt i32 %11, %12                     ; <i1> [#uses=1]
145   br i1 %13, label %bb2, label %bb7
146 ; PROF: ;;; Out-edge counts: [9.000000e+00 -> bb2] [3.000000e+00 -> bb7]
147
148 bb7:                                              ; preds = %bb6
149 ; PROF:bb7:
150 ; PROF: ;;; Basic block executed 3 times.
151   br label %bb9
152 ; PROF: ;;; Out-edge counts: [3.000000e+00 -> bb9]
153
154 bb8:                                              ; preds = %bb
155 ; PROF:bb8:
156 ; PROF: ;;; Basic block executed 3 times.
157   %14 = call i32 @puts(i8* getelementptr inbounds ([10 x i8]* @.str5, i64 0, i64 0)) nounwind ; <i32> [#uses=0]
158   br label %bb9
159 ; PROF: ;;; Out-edge counts: [3.000000e+00 -> bb9]
160
161 bb9:                                              ; preds = %bb8, %bb7
162 ; PROF:bb9:
163 ; PROF: ;;; Basic block executed 6 times.
164   %15 = load i32* %i, align 4                     ; <i32> [#uses=1]
165   %16 = add nsw i32 %15, 1                        ; <i32> [#uses=1]
166   store i32 %16, i32* %i, align 4
167   br label %bb10
168 ; PROF: ;;; Out-edge counts: [6.000000e+00 -> bb10]
169
170 bb10:                                             ; preds = %bb9, %entry
171 ; PROF:bb10:
172 ; PROF: ;;; Basic block executed 8 times.
173   %17 = load i32* %i, align 4                     ; <i32> [#uses=1]
174   %18 = icmp ne i32 %17, 3                        ; <i1> [#uses=1]
175   br i1 %18, label %bb, label %bb11
176 ; INST:br
177 ; INST:label %bb10.bb11_crit_edge
178 ; PROF: ;;; Out-edge counts: [6.000000e+00 -> bb] [2.000000e+00 -> bb11]
179
180 ; INST:bb10.bb11_crit_edge:
181 ; INST:br
182 ; INST:label %bb11
183
184 bb11:                                             ; preds = %bb10, %bb4
185 ; PROF:bb11:
186 ; PROF: ;;; Basic block executed 2 times.
187   call void @oneblock() nounwind
188   store i32 0, i32* %0, align 4
189   %19 = load i32* %0, align 4                     ; <i32> [#uses=1]
190   store i32 %19, i32* %retval, align 4
191   br label %return
192 ; PROF: ;;; Out-edge counts: [2.000000e+00 -> return]
193
194 return:                                           ; preds = %bb11
195 ; PROF:return:
196 ; PROF: ;;; Basic block executed 2 times.
197   %retval12 = load i32* %retval                   ; <i32> [#uses=1]
198   ret i32 %retval12
199 }