Skip to content

Commit f30b2c9

Browse files
committed
[pa-combiner] Change worklist iteration to use a more canonical worklist form.
We generally do not use a for loop for worklist iteration since one runs into weird issues around always needing to recompute the worklist size since it may change per iteration. In contrast, using the while loop approach that just pops off the back avoids such implicit weirdness.
1 parent 89ff110 commit f30b2c9

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

lib/SILOptimizer/Utils/PartialApplyCombiner.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,10 @@ SILInstruction *PartialApplyCombiner::combine() {
291291
// and look for applies that use it as a callee.
292292

293293
// Worklist of operands.
294-
SmallVector<Operand *, 8> uses(pai->getUses());
294+
SmallVector<Operand *, 8> worklist(pai->getUses());
295295

296-
// Uses may grow in this loop.
297-
for (size_t useIndex = 0; useIndex < uses.size(); ++useIndex) {
298-
auto *use = uses[useIndex];
296+
while (!worklist.empty()) {
297+
auto *use = worklist.pop_back_val();
299298
auto *user = use->getUser();
300299

301300
// Recurse through conversions.
@@ -313,7 +312,7 @@ SILInstruction *PartialApplyCombiner::combine() {
313312
assert(use->get()->getType().castTo<SILFunctionType>() ==
314313
escapingCalleeTy);
315314
(void)escapingCalleeTy;
316-
llvm::copy(cfi->getUses(), std::back_inserter(uses));
315+
llvm::copy(cfi->getUses(), std::back_inserter(worklist));
317316
continue;
318317
}
319318

@@ -322,7 +321,7 @@ SILInstruction *PartialApplyCombiner::combine() {
322321
if (mdi->getValue() == use->get() &&
323322
mdi->getValue()->getType().is<SILFunctionType>() &&
324323
mdi->getValue()->getType().castTo<SILFunctionType>()->isNoEscape()) {
325-
llvm::copy(mdi->getUses(), std::back_inserter(uses));
324+
llvm::copy(mdi->getUses(), std::back_inserter(worklist));
326325
}
327326
continue;
328327
}

0 commit comments

Comments
 (0)