sccp-callgraph.mlir
7.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
// RUN: mlir-opt -allow-unregistered-dialect %s -sccp -split-input-file | FileCheck %s
// RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline="module(sccp)" -split-input-file | FileCheck %s --check-prefix=NESTED
/// Check that a constant is properly propagated through the arguments and
/// results of a private function.
// CHECK-LABEL: func @private(
func @private(%arg0 : i32) -> i32 attributes { sym_visibility = "private" } {
// CHECK: %[[CST:.*]] = constant 1 : i32
// CHECK: return %[[CST]] : i32
return %arg0 : i32
}
// CHECK-LABEL: func @simple_private(
func @simple_private() -> i32 {
// CHECK: %[[CST:.*]] = constant 1 : i32
// CHECK: return %[[CST]] : i32
%1 = constant 1 : i32
%result = call @private(%1) : (i32) -> i32
return %result : i32
}
// -----
/// Check that a constant is properly propagated through the arguments and
/// results of a visible nested function.
// CHECK: func @nested(
func @nested(%arg0 : i32) -> i32 attributes { sym_visibility = "nested" } {
// CHECK: %[[CST:.*]] = constant 1 : i32
// CHECK: return %[[CST]] : i32
return %arg0 : i32
}
// CHECK-LABEL: func @simple_nested(
func @simple_nested() -> i32 {
// CHECK: %[[CST:.*]] = constant 1 : i32
// CHECK: return %[[CST]] : i32
%1 = constant 1 : i32
%result = call @nested(%1) : (i32) -> i32
return %result : i32
}
// -----
/// Check that non-visible nested functions do not track arguments.
module {
// NESTED-LABEL: module @nested_module
module @nested_module attributes { sym_visibility = "public" } {
// NESTED: func @nested(
func @nested(%arg0 : i32) -> (i32, i32) attributes { sym_visibility = "nested" } {
// NESTED: %[[CST:.*]] = constant 1 : i32
// NESTED: return %[[CST]], %arg0 : i32, i32
%1 = constant 1 : i32
return %1, %arg0 : i32, i32
}
// NESTED: func @nested_not_all_uses_visible(
func @nested_not_all_uses_visible() -> (i32, i32) {
// NESTED: %[[CST:.*]] = constant 1 : i32
// NESTED: %[[CALL:.*]]:2 = call @nested
// NESTED: return %[[CST]], %[[CALL]]#1 : i32, i32
%1 = constant 1 : i32
%result:2 = call @nested(%1) : (i32) -> (i32, i32)
return %result#0, %result#1 : i32, i32
}
}
}
// -----
/// Check that public functions do not track arguments.
// CHECK-LABEL: func @public(
func @public(%arg0 : i32) -> (i32, i32) attributes { sym_visibility = "public" } {
%1 = constant 1 : i32
return %1, %arg0 : i32, i32
}
// CHECK-LABEL: func @simple_public(
func @simple_public() -> (i32, i32) {
// CHECK: %[[CST:.*]] = constant 1 : i32
// CHECK: %[[CALL:.*]]:2 = call @public
// CHECK: return %[[CST]], %[[CALL]]#1 : i32, i32
%1 = constant 1 : i32
%result:2 = call @public(%1) : (i32) -> (i32, i32)
return %result#0, %result#1 : i32, i32
}
// -----
/// Check that functions with non-call users don't have arguments tracked.
func @callable(%arg0 : i32) -> (i32, i32) attributes { sym_visibility = "private" } {
%1 = constant 1 : i32
return %1, %arg0 : i32, i32
}
// CHECK-LABEL: func @non_call_users(
func @non_call_users() -> (i32, i32) {
// CHECK: %[[CST:.*]] = constant 1 : i32
// CHECK: %[[CALL:.*]]:2 = call @callable
// CHECK: return %[[CST]], %[[CALL]]#1 : i32, i32
%1 = constant 1 : i32
%result:2 = call @callable(%1) : (i32) -> (i32, i32)
return %result#0, %result#1 : i32, i32
}
"live.user"() {uses = [@callable]} : () -> ()
// -----
/// Check that return values are overdefined in the presence of an unknown terminator.
func @callable(%arg0 : i32) -> i32 attributes { sym_visibility = "private" } {
"unknown.return"(%arg0) : (i32) -> ()
}
// CHECK-LABEL: func @unknown_terminator(
func @unknown_terminator() -> i32 {
// CHECK: %[[CALL:.*]] = call @callable
// CHECK: return %[[CALL]] : i32
%1 = constant 1 : i32
%result = call @callable(%1) : (i32) -> i32
return %result : i32
}
// -----
/// Check that return values are overdefined when the constant conflicts.
func @callable(%arg0 : i32) -> i32 attributes { sym_visibility = "private" } {
"unknown.return"(%arg0) : (i32) -> ()
}
// CHECK-LABEL: func @conflicting_constant(
func @conflicting_constant() -> (i32, i32) {
// CHECK: %[[CALL1:.*]] = call @callable
// CHECK: %[[CALL2:.*]] = call @callable
// CHECK: return %[[CALL1]], %[[CALL2]] : i32, i32
%1 = constant 1 : i32
%2 = constant 2 : i32
%result = call @callable(%1) : (i32) -> i32
%result2 = call @callable(%2) : (i32) -> i32
return %result, %result2 : i32, i32
}
// -----
/// Check that return values are overdefined when the constant conflicts with a
/// non-constant.
func @callable(%arg0 : i32) -> i32 attributes { sym_visibility = "private" } {
"unknown.return"(%arg0) : (i32) -> ()
}
// CHECK-LABEL: func @conflicting_constant(
func @conflicting_constant(%arg0 : i32) -> (i32, i32) {
// CHECK: %[[CALL1:.*]] = call @callable
// CHECK: %[[CALL2:.*]] = call @callable
// CHECK: return %[[CALL1]], %[[CALL2]] : i32, i32
%1 = constant 1 : i32
%result = call @callable(%1) : (i32) -> i32
%result2 = call @callable(%arg0) : (i32) -> i32
return %result, %result2 : i32, i32
}
// -----
/// Check a more complex interaction with calls and control flow.
// CHECK-LABEL: func @complex_inner_if(
func @complex_inner_if(%arg0 : i32) -> i32 attributes { sym_visibility = "private" } {
// CHECK-DAG: %[[TRUE:.*]] = constant true
// CHECK-DAG: %[[CST:.*]] = constant 1 : i32
// CHECK: cond_br %[[TRUE]], ^bb1
%cst_20 = constant 20 : i32
%cond = cmpi "ult", %arg0, %cst_20 : i32
cond_br %cond, ^bb1, ^bb2
^bb1:
// CHECK: ^bb1:
// CHECK: return %[[CST]] : i32
%cst_1 = constant 1 : i32
return %cst_1 : i32
^bb2:
%cst_1_2 = constant 1 : i32
%arg_inc = addi %arg0, %cst_1_2 : i32
return %arg_inc : i32
}
func @complex_cond() -> i1
// CHECK-LABEL: func @complex_callee(
func @complex_callee(%arg0 : i32) -> i32 attributes { sym_visibility = "private" } {
// CHECK: %[[CST:.*]] = constant 1 : i32
%loop_cond = call @complex_cond() : () -> i1
cond_br %loop_cond, ^bb1, ^bb2
^bb1:
// CHECK: ^bb1:
// CHECK-NEXT: return %[[CST]] : i32
return %arg0 : i32
^bb2:
// CHECK: ^bb2:
// CHECK: call @complex_inner_if(%[[CST]]) : (i32) -> i32
// CHECK: call @complex_callee(%[[CST]]) : (i32) -> i32
// CHECK: return %[[CST]] : i32
%updated_arg = call @complex_inner_if(%arg0) : (i32) -> i32
%res = call @complex_callee(%updated_arg) : (i32) -> i32
return %res : i32
}
// CHECK-LABEL: func @complex_caller(
func @complex_caller(%arg0 : i32) -> i32 {
// CHECK: %[[CST:.*]] = constant 1 : i32
// CHECK: return %[[CST]] : i32
%1 = constant 1 : i32
%result = call @complex_callee(%1) : (i32) -> i32
return %result : i32
}
// -----
/// Check that non-symbol defining callables currently go to overdefined.
// CHECK-LABEL: func @non_symbol_defining_callable
func @non_symbol_defining_callable() -> i32 {
// CHECK: %[[RES:.*]] = call_indirect
// CHECK: return %[[RES]] : i32
%fn = "test.functional_region_op"() ({
%1 = constant 1 : i32
"test.return"(%1) : (i32) -> ()
}) : () -> (() -> i32)
%res = call_indirect %fn() : () -> (i32)
return %res : i32
}