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:
Erik Eckstein
2022-12-02 15:21:23 +01:00
parent 05a63c70c5
commit c180d1363e
12 changed files with 143 additions and 339 deletions

View File

@@ -29,8 +29,8 @@ void findAndDeleteTraceValues(SILFunction *function,
SmallVectorImpl<SILValue> &values) {
InstructionDeleter deleter;
for (auto &block : *function) {
for (SILInstruction *inst : deleter.updatingRange(&block)) {
if (auto *debugValue = dyn_cast<DebugValueInst>(inst)) {
for (SILInstruction &inst : block.deletableInstructions()) {
if (auto *debugValue = dyn_cast<DebugValueInst>(&inst)) {
if (!debugValue->hasTrace())
continue;
values.push_back(debugValue->getOperand());
@@ -591,8 +591,8 @@ void swift::test::getTestSpecifications(
SmallVectorImpl<UnparsedSpecification> &specifications) {
InstructionDeleter deleter;
for (auto &block : *function) {
for (SILInstruction *inst : deleter.updatingRange(&block)) {
if (auto *tsi = dyn_cast<TestSpecificationInst>(inst)) {
for (SILInstruction &inst : block.deletableInstructions()) {
if (auto *tsi = dyn_cast<TestSpecificationInst>(&inst)) {
auto ref = tsi->getArgumentsSpecification();
auto *anchor = findAnchorInstructionAfter(tsi);
specifications.push_back({std::string(ref.begin(), ref.end()), anchor});