Skip to content

Commit 68ba040

Browse files
committed
Add a SIL test for optimizer counters
1 parent df40807 commit 68ba040

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -O -sil-stats-modules 2>&1 | %FileCheck --check-prefix=CHECK-SIL-STATS-MODULES %s
2+
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -O -sil-stats-functions 2>&1 | %FileCheck --check-prefix=CHECK-SIL-STATS-FUNCTIONS %s
3+
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -O -sil-stats-dump-all 2>&1 | %FileCheck --check-prefix=CHECK-SIL-STATS-ALL %s
4+
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -O -sil-stats-modules -sil-stats-only-instructions=integer_literal,builtin 2>&1 | %FileCheck --check-prefix=CHECK-SIL-STATS-ONLY-INSTRUCTIONS %s
5+
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -O -sil-stats-functions -sil-stats-only-function=test_simple 2>&1 | %FileCheck --check-prefix=CHECK-SIL-STATS-ONLY-FUNCTION %s
6+
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -O -sil-stats-functions -sil-stats-only-functions=test 2>&1 | %FileCheck --check-prefix=CHECK-SIL-STATS-ONLY-FUNCTIONS %s
7+
8+
9+
// Test different modes of optimizer counters statistics collection.
10+
11+
sil_stage canonical
12+
13+
import Builtin
14+
import Swift
15+
16+
sil @fatalError : $@convention(thin) () -> Never
17+
18+
// Check that module level statistics are produced.
19+
//
20+
// CHECK-SIL-STATS-MODULES: module, inst, HighLevel+EarlyLoopOpt, PerformanceConstantPropagation, {{.*}}, 15, 12
21+
// CHECK-SIL-STATS-MODULES: module, block, HighLevel+EarlyLoopOpt, SimplifyCFG, {{.*}}, 6, 3
22+
// CHECK-SIL-STATS-MODULES: module, inst, HighLevel+EarlyLoopOpt, SimplifyCFG, {{.*}}, 12, 6
23+
24+
// Check that module level statistics are produced.
25+
//
26+
// CHECK-SIL-STATS-FUNCTIONS: function_history, block,{{.*}}, test_multiply
27+
// CHECK-SIL-STATS-FUNCTIONS: function_history, inst,{{.*}}, test_multiply
28+
// CHECK-SIL-STATS-FUNCTIONS: function_history, block,{{.*}}, test_simple
29+
// CHECK-SIL-STATS-FUNCTIONS: function_history, inst,{{.*}}, test_simple
30+
// CHECK-SIL-STATS-FUNCTIONS: function_history, block,{{.*}}, another_simple_func
31+
// CHECK-SIL-STATS-FUNCTIONS: function_history, inst,{{.*}}, another_simple_func
32+
33+
34+
35+
// Check that -sil-stats-all produces module and function level statistics.
36+
//
37+
// CHECK-SIL-STATS-ALL: module, block,
38+
// CHECK-SIL-STATS-ALL: function, inst
39+
40+
// Check that -sil-stats-only-instructions=integer_literal,builtin produces stats about these instruction.
41+
//
42+
// CHECK-SIL-STATS-ONLY-INSTRUCTIONS: module, inst_integer_literal
43+
// CHECK-SIL-STATS-ONLY-INSTRUCTIONS: module, inst_builtin
44+
45+
sil @test_multiply : $@convention(thin) () -> Builtin.Int64 {
46+
bb0:
47+
%1 = integer_literal $Builtin.Int64, 10
48+
%2 = integer_literal $Builtin.Int1, 0
49+
%3 = builtin "umul_with_overflow_Int64"(%1 : $Builtin.Int64, %1 : $Builtin.Int64, %2 : $Builtin.Int1) : $(Builtin.Int64, Builtin.Int1)
50+
%4 = tuple_extract %3 : $(Builtin.Int64, Builtin.Int1), 1
51+
cond_br %4, bb1, bb2
52+
53+
bb1:
54+
%f = function_ref @fatalError : $@convention(thin) () -> Never
55+
apply %f() : $@convention(thin) () -> Never
56+
unreachable
57+
58+
bb2:
59+
%v = tuple_extract %3 : $(Builtin.Int64, Builtin.Int1), 0
60+
br bb3 (%v : $Builtin.Int64)
61+
62+
bb3(%r : $Builtin.Int64):
63+
return %r: $Builtin.Int64
64+
}
65+
66+
// Check that -sil-stats-only-function=test_simple produces stats only about test_simple
67+
//
68+
// CHECK-SIL-STATS-ONLY-FUNCTION-NOT: function_history, block,{{.*}}, test_multiply
69+
// CHECK-SIL-STATS-ONLY-FUNCTION-NOT: function_history, inst,{{.*}}, test_multiply
70+
// CHECK-SIL-STATS-ONLY-FUNCTION-NOT: function_history, block,{{.*}}, another_simple_func
71+
// CHECK-SIL-STATS-ONLY-FUNCTION-NOT: function_history, inst,{{.*}}, another_simple_func
72+
// CHECK-SIL-STATS-ONLY-FUNCTION: function_history, block,{{.*}}, test_simple
73+
// CHECK-SIL-STATS-ONLY-FUNCTION: function_history, inst,{{.*}}, test_simple
74+
// CHECK-SIL-STATS-ONLY-FUNCTION-NOT: function_history, block,{{.*}}, test_multiply
75+
// CHECK-SIL-STATS-ONLY-FUNCTION-NOT: function_history, inst,{{.*}}, test_multiply
76+
// CHECK-SIL-STATS-ONLY-FUNCTION-NOT: function_history, block,{{.*}}, another_simple_func
77+
// CHECK-SIL-STATS-ONLY-FUNCTION-NOT: function_history, inst,{{.*}}, another_simple_func
78+
79+
sil @test_simple : $@convention(thin) () -> Builtin.Int64 {
80+
%0 = integer_literal $Builtin.Int64, 10
81+
return %0 : $Builtin.Int64
82+
}
83+
84+
sil @another_simple_func : $@convention(thin) () -> Builtin.Int64 {
85+
%0 = integer_literal $Builtin.Int64, 10
86+
return %0 : $Builtin.Int64
87+
}
88+
89+
// Check that -sil-stats-only-functions=test produces stats only about functions,
90+
// whose name contains "test"
91+
//
92+
// CHECK-SIL-STATS-ONLY-FUNCTIONS-NOT: function_history, block,{{.*}}, another_simple_func
93+
// CHECK-SIL-STATS-ONLY-FUNCTIONS-NOT: function_history, inst,{{.*}}, another_simple_func
94+
// CHECK-SIL-STATS-ONLY-FUNCTIONS: function_history, block,{{.*}}, test_multiply
95+
// CHECK-SIL-STATS-ONLY-FUNCTIONS: function_history, inst,{{.*}}, test_multiply
96+
// CHECK-SIL-STATS-ONLY-FUNCTIONS: function_history, block,{{.*}}, test_simple
97+
// CHECK-SIL-STATS-ONLY-FUNCTIONS: function_history, inst,{{.*}}, test_simple
98+
// CHECK-SIL-STATS-ONLY-FUNCTIONS-NOT: function_history, block,{{.*}}, another_simple_func
99+
// CHECK-SIL-STATS-ONLY-FUNCTIONS-NOT: function_history, inst,{{.*}}, another_simple_func
100+
101+

0 commit comments

Comments
 (0)