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