@@ -188,7 +188,11 @@ struct Precompute
188
188
}
189
189
// try to evaluate this into a const
190
190
Flow flow = precomputeExpression (curr);
191
- if (flow.value .type .isVector ()) {
191
+ if (flow.values .size () > 1 ) {
192
+ // TODO: handle multivalue types
193
+ return ;
194
+ }
195
+ if (flow.getSingleValue ().type .isVector ()) {
192
196
return ;
193
197
}
194
198
if (flow.breaking ()) {
@@ -199,25 +203,26 @@ struct Precompute
199
203
// this expression causes a return. if it's already a return, reuse the
200
204
// node
201
205
if (auto * ret = curr->dynCast <Return>()) {
202
- if (flow.value .type != Type::none) {
206
+ if (flow.getSingleValue () .type != Type::none) {
203
207
// reuse a const value if there is one
204
208
if (ret->value ) {
205
209
if (auto * value = ret->value ->dynCast <Const>()) {
206
- value->value = flow.value ;
210
+ value->value = flow.getSingleValue () ;
207
211
value->finalize ();
208
212
return ;
209
213
}
210
214
}
211
- ret->value = Builder (*getModule ()).makeConstExpression (flow.value );
215
+ ret->value =
216
+ Builder (*getModule ()).makeConstExpression (flow.getSingleValue ());
212
217
} else {
213
218
ret->value = nullptr ;
214
219
}
215
220
} else {
216
221
Builder builder (*getModule ());
217
- replaceCurrent (
218
- builder. makeReturn ( flow.value .type != Type::none
219
- ? builder.makeConstExpression (flow.value )
220
- : nullptr ));
222
+ replaceCurrent (builder. makeReturn (
223
+ flow.getSingleValue () .type != Type::none
224
+ ? builder.makeConstExpression (flow.getSingleValue () )
225
+ : nullptr ));
221
226
}
222
227
return ;
223
228
}
@@ -226,34 +231,36 @@ struct Precompute
226
231
if (auto * br = curr->dynCast <Break>()) {
227
232
br->name = flow.breakTo ;
228
233
br->condition = nullptr ;
229
- if (flow.value .type != Type::none) {
234
+ if (flow.getSingleValue () .type != Type::none) {
230
235
// reuse a const value if there is one
231
236
if (br->value ) {
232
237
if (auto * value = br->value ->dynCast <Const>()) {
233
- value->value = flow.value ;
238
+ value->value = flow.getSingleValue () ;
234
239
value->finalize ();
235
240
br->finalize ();
236
241
return ;
237
242
}
238
243
}
239
- br->value = Builder (*getModule ()).makeConstExpression (flow.value );
244
+ br->value =
245
+ Builder (*getModule ()).makeConstExpression (flow.getSingleValue ());
240
246
} else {
241
247
br->value = nullptr ;
242
248
}
243
249
br->finalize ();
244
250
} else {
245
251
Builder builder (*getModule ());
246
- replaceCurrent (
247
- builder. makeBreak ( flow.breakTo ,
248
- flow.value .type != Type::none
249
- ? builder.makeConstExpression (flow.value )
250
- : nullptr ));
252
+ replaceCurrent (builder. makeBreak (
253
+ flow.breakTo ,
254
+ flow.getSingleValue () .type != Type::none
255
+ ? builder.makeConstExpression (flow.getSingleValue () )
256
+ : nullptr ));
251
257
}
252
258
return ;
253
259
}
254
260
// this was precomputed
255
- if (flow.value .type .isConcrete ()) {
256
- replaceCurrent (Builder (*getModule ()).makeConstExpression (flow.value ));
261
+ if (flow.getSingleValue ().type .isConcrete ()) {
262
+ replaceCurrent (
263
+ Builder (*getModule ()).makeConstExpression (flow.getSingleValue ()));
257
264
worked = true ;
258
265
} else {
259
266
ExpressionManipulator::nop (curr);
@@ -292,7 +299,7 @@ struct Precompute
292
299
if (flow.breaking ()) {
293
300
return Literal ();
294
301
}
295
- return flow.value ;
302
+ return flow.getSingleValue () ;
296
303
}
297
304
298
305
// Propagates values around. Returns whether we propagated.
0 commit comments