@@ -299,45 +299,55 @@ bool SILMoveOnlyWrappedTypeEliminator::process() {
299
299
llvm::SmallSetVector<SILArgument *, 8 > touchedArgs;
300
300
llvm::SmallSetVector<SILInstruction *, 8 > touchedInsts;
301
301
302
+ // For each value whose type is move-only wrapped:
303
+ // - rewrite the value's type
304
+ // - record its users for later visitation
305
+ auto visitValue = [&touchedInsts, fn = fn,
306
+ trivialOnly = trivialOnly](SILValue value) -> bool {
307
+ if (!value->getType ().hasAnyMoveOnlyWrapping (fn))
308
+ return false ;
309
+
310
+ // If we are looking at trivial only, skip non-trivial function args.
311
+ if (trivialOnly && !isMoveOnlyWrappedTrivial (value))
312
+ return false ;
313
+
314
+ for (auto *use : value->getNonTypeDependentUses ())
315
+ touchedInsts.insert (use->getUser ());
316
+
317
+ value->unsafelyEliminateMoveOnlyWrapper (fn);
318
+
319
+ return true ;
320
+ };
321
+
302
322
for (auto &bb : *fn) {
303
323
for (auto *arg : bb.getArguments ()) {
304
- if (!arg->getType ().hasAnyMoveOnlyWrapping (fn))
324
+ bool relevant = visitValue (arg);
325
+ if (!relevant)
305
326
continue ;
306
327
307
- // If we are looking at trivial only, skip non-trivial function args.
308
- if (trivialOnly &&
309
- !arg->getType ().removingMoveOnlyWrapper ().isTrivial (*fn))
310
- continue ;
311
-
312
- arg->unsafelyEliminateMoveOnlyWrapper (fn);
313
-
314
328
// If our new type is trivial, convert the arguments ownership to
315
329
// None. Otherwise, preserve the ownership kind of the argument.
316
330
if (arg->getType ().isTrivial (*fn))
317
331
arg->setOwnershipKind (OwnershipKind::None);
318
332
touchedArgs.insert (arg);
319
- for ( auto *use : arg-> getNonTypeDependentUses ())
320
- touchedInsts. insert (use-> getUser ()) ;
333
+
334
+ madeChange = true ;
321
335
}
322
336
323
337
for (auto &ii : bb) {
324
- for (SILValue v : ii.getResults ()) {
325
- if (!v->getType ().hasAnyMoveOnlyWrapping (fn))
326
- continue ;
327
-
328
- if (trivialOnly &&
329
- !isMoveOnlyWrappedTrivial (v))
338
+ bool touched = false ;
339
+ for (SILValue value : ii.getResults ()) {
340
+ bool relevant = visitValue (value);
341
+ if (!relevant)
330
342
continue ;
331
343
332
- v->unsafelyEliminateMoveOnlyWrapper (fn);
333
- touchedInsts.insert (&ii);
334
-
335
- // Add all users as well. This ensures we visit things like
336
- // destroy_value and end_borrow.
337
- for (auto *use : v->getNonTypeDependentUses ())
338
- touchedInsts.insert (use->getUser ());
339
- madeChange = true ;
344
+ touched = true ;
340
345
}
346
+ if (!touched)
347
+ continue ;
348
+ touchedInsts.insert (&ii);
349
+
350
+ madeChange = true ;
341
351
}
342
352
}
343
353
0 commit comments