1 ; RUN: llvm-as %s -o %t1
2 ; RUN: opt %t1 -insert-optimal-edge-profiling -o %t2
4 ; FIXME: These parts of the test are disabled for now, they aren't working on
5 ; llvm-gcc-x86_64-darwin10-selfhost.
7 ; RUX: llvm-dis < %t2 | FileCheck --check-prefix=INST %s
8 ; RUX: rm -f llvmprof.out
9 ; RUX: lli -load %llvmlibsdir/profile_rt%shlibext %t2
10 ; RUX: lli -load %llvmlibsdir/profile_rt%shlibext %t2 1 2
11 ; RUX: llvm-prof -print-all-code %t1 | FileCheck --check-prefix=PROF %s
13 ; PROF: 1. 2/4 oneblock
15 ; PROF: 1. 15.7895% 12/76 main() - bb6
16 ; PROF: 2. 11.8421% 9/76 main() - bb2
17 ; PROF: 3. 11.8421% 9/76 main() - bb3
18 ; PROF: 4. 11.8421% 9/76 main() - bb5
19 ; PROF: 5. 10.5263% 8/76 main() - bb10
20 ; PROF: 6. 7.89474% 6/76 main() - bb
21 ; PROF: 7. 7.89474% 6/76 main() - bb9
22 ; PROF: 8. 3.94737% 3/76 main() - bb1
23 ; PROF: 9. 3.94737% 3/76 main() - bb7
24 ; PROF: 10. 3.94737% 3/76 main() - bb8
25 ; PROF: 11. 2.63158% 2/76 oneblock() - entry
26 ; PROF: 12. 2.63158% 2/76 main() - entry
27 ; PROF: 13. 2.63158% 2/76 main() - bb11
28 ; PROF: 14. 2.63158% 2/76 main() - return
30 ; ModuleID = '<stdin>'
32 @.str = private constant [12 x i8] c"hello world\00", align 1 ; <[12 x i8]*> [#uses=1]
33 @.str1 = private constant [6 x i8] c"franz\00", align 1 ; <[6 x i8]*> [#uses=1]
34 @.str2 = private constant [9 x i8] c"argc > 2\00", align 1 ; <[9 x i8]*> [#uses=1]
35 @.str3 = private constant [9 x i8] c"argc = 1\00", align 1 ; <[9 x i8]*> [#uses=1]
36 @.str4 = private constant [6 x i8] c"fritz\00", align 1 ; <[6 x i8]*> [#uses=1]
37 @.str5 = private constant [10 x i8] c"argc <= 1\00", align 1 ; <[10 x i8]*> [#uses=1]
38 ; INST:@OptEdgeProfCounters
62 ; PROF:;;; %oneblock called 2 times.
64 define void @oneblock() nounwind {
67 ; PROF: ;;; Basic block executed 2 times.
68 %0 = call i32 @puts(i8* getelementptr inbounds ([12 x i8]* @.str, i64 0, i64 0)) nounwind ; <i32> [#uses=0]
72 declare i32 @puts(i8*)
74 ; PROF:;;; %main called 2 times.
76 define i32 @main(i32 %argc, i8** %argv) nounwind {
79 ; PROF: ;;; Basic block executed 2 times.
80 %argc_addr = alloca i32 ; <i32*> [#uses=4]
81 %argv_addr = alloca i8** ; <i8***> [#uses=1]
82 %retval = alloca i32 ; <i32*> [#uses=2]
83 %j = alloca i32 ; <i32*> [#uses=4]
84 %i = alloca i32 ; <i32*> [#uses=4]
85 %0 = alloca i32 ; <i32*> [#uses=2]
87 ; INST:@llvm_start_opt_edge_profiling
88 ; INST:@OptEdgeProfCounters
89 %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
90 store i32 %argc, i32* %argc_addr
91 store i8** %argv, i8*** %argv_addr
92 store i32 0, i32* %i, align 4
94 ; PROF: ;;; Out-edge counts: [2.000000e+00 -> bb10]
98 ; PROF: ;;; Basic block executed 6 times.
99 %1 = load i32* %argc_addr, align 4 ; <i32> [#uses=1]
100 %2 = icmp sgt i32 %1, 1 ; <i1> [#uses=1]
101 br i1 %2, label %bb1, label %bb8
102 ; PROF: ;;; Out-edge counts: [3.000000e+00 -> bb1] [3.000000e+00 -> bb8]
106 ; PROF: ;;; Basic block executed 3 times.
107 store i32 0, i32* %j, align 4
109 ; PROF: ;;; Out-edge counts: [3.000000e+00 -> bb6]
113 ; PROF: ;;; Basic block executed 9 times.
114 %3 = call i32 @puts(i8* getelementptr inbounds ([6 x i8]* @.str1, i64 0, i64 0)) nounwind ; <i32> [#uses=0]
115 %4 = load i32* %argc_addr, align 4 ; <i32> [#uses=1]
116 %5 = icmp sgt i32 %4, 2 ; <i1> [#uses=1]
117 br i1 %5, label %bb3, label %bb4
118 ; PROF: ;;; Out-edge counts: [9.000000e+00 -> bb3]
122 ; PROF: ;;; Basic block executed 9 times.
123 %6 = call i32 @puts(i8* getelementptr inbounds ([9 x i8]* @.str2, i64 0, i64 0)) nounwind ; <i32> [#uses=0]
125 ; PROF: ;;; Out-edge counts: [9.000000e+00 -> bb5]
129 ; PROF: ;;; Never executed!
130 %7 = call i32 @puts(i8* getelementptr inbounds ([9 x i8]* @.str3, i64 0, i64 0)) nounwind ; <i32> [#uses=0]
135 ; PROF: ;;; Basic block executed 9 times.
136 %8 = call i32 @puts(i8* getelementptr inbounds ([6 x i8]* @.str4, i64 0, i64 0)) nounwind ; <i32> [#uses=0]
137 %9 = load i32* %j, align 4 ; <i32> [#uses=1]
138 %10 = add nsw i32 %9, 1 ; <i32> [#uses=1]
139 store i32 %10, i32* %j, align 4
141 ; PROF: ;;; Out-edge counts: [9.000000e+00 -> bb6]
143 bb6: ; preds = %bb5, %bb1
145 ; PROF: ;;; Basic block executed 12 times.
146 %11 = load i32* %j, align 4 ; <i32> [#uses=1]
147 %12 = load i32* %argc_addr, align 4 ; <i32> [#uses=1]
148 %13 = icmp slt i32 %11, %12 ; <i1> [#uses=1]
149 br i1 %13, label %bb2, label %bb7
150 ; PROF: ;;; Out-edge counts: [9.000000e+00 -> bb2] [3.000000e+00 -> bb7]
154 ; PROF: ;;; Basic block executed 3 times.
156 ; PROF: ;;; Out-edge counts: [3.000000e+00 -> bb9]
160 ; PROF: ;;; Basic block executed 3 times.
161 %14 = call i32 @puts(i8* getelementptr inbounds ([10 x i8]* @.str5, i64 0, i64 0)) nounwind ; <i32> [#uses=0]
163 ; PROF: ;;; Out-edge counts: [3.000000e+00 -> bb9]
165 bb9: ; preds = %bb8, %bb7
167 ; PROF: ;;; Basic block executed 6 times.
168 %15 = load i32* %i, align 4 ; <i32> [#uses=1]
169 %16 = add nsw i32 %15, 1 ; <i32> [#uses=1]
170 store i32 %16, i32* %i, align 4
172 ; PROF: ;;; Out-edge counts: [6.000000e+00 -> bb10]
174 bb10: ; preds = %bb9, %entry
176 ; PROF: ;;; Basic block executed 8 times.
177 %17 = load i32* %i, align 4 ; <i32> [#uses=1]
178 %18 = icmp ne i32 %17, 3 ; <i1> [#uses=1]
179 br i1 %18, label %bb, label %bb11
181 ; INST:label %bb10.bb11_crit_edge
182 ; PROF: ;;; Out-edge counts: [6.000000e+00 -> bb] [2.000000e+00 -> bb11]
184 ; INST:bb10.bb11_crit_edge:
188 bb11: ; preds = %bb10, %bb4
190 ; PROF: ;;; Basic block executed 2 times.
191 call void @oneblock() nounwind
192 store i32 0, i32* %0, align 4
193 %19 = load i32* %0, align 4 ; <i32> [#uses=1]
194 store i32 %19, i32* %retval, align 4
196 ; PROF: ;;; Out-edge counts: [2.000000e+00 -> return]
198 return: ; preds = %bb11
200 ; PROF: ;;; Basic block executed 2 times.
201 %retval12 = load i32* %retval ; <i32> [#uses=1]