mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
SIL: simplify deleting instruction while iterating over instructions.
Add `deletableInstructions()` and `reverseDeletableInstructions()` in SILBasicBlock. It allows deleting instructions while iterating over all instructions of the block. This is a replacement for `InstructionDeleter::updatingRange()`. It's a simpler implementation than the existing `UpdatingListIterator` and `UpdatingInstructionIteratorRegistry`, because it just needs to keep the prev/next pointers for "deleted" instructions instead of the iterator-registration machinery. It's also safer, because it doesn't require to delete instructions via a specific instance of an InstructionDeleter (which can be missed easily).
This commit is contained in:
@@ -291,8 +291,8 @@ bool MandatoryGenericSpecializer::optimize(SILFunction *func,
|
||||
if (!rrBlocks.reachesReturn(&block) || !neBlocks.isNonErrorHandling(&block))
|
||||
continue;
|
||||
|
||||
for (SILInstruction *inst : deleter.updatingReverseRange(&block)) {
|
||||
changed |= optimizeInst(inst, funcBuilder, deleter, cha, invalidatedStackNesting);
|
||||
for (SILInstruction &inst : block.reverseDeletableInstructions()) {
|
||||
changed |= optimizeInst(&inst, funcBuilder, deleter, cha, invalidatedStackNesting);
|
||||
}
|
||||
}
|
||||
deleter.cleanupDeadInstructions();
|
||||
|
||||
Reference in New Issue
Block a user