Skip to content

Commit a8f3a2b

Browse files
committed
SIL: fix APIs for (re)moving instructions
Instructions can only be moved and erased, but never _removed_ from a block.
1 parent 7acbf55 commit a8f3a2b

File tree

5 files changed

+20
-27
lines changed

5 files changed

+20
-27
lines changed

include/swift/SIL/SILBasicBlock.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,10 @@ public SwiftObjectHeader {
148148

149149
void push_back(SILInstruction *I);
150150
void push_front(SILInstruction *I);
151-
void remove(SILInstruction *I);
152151
void erase(SILInstruction *I);
153152
void erase(SILInstruction *I, SILModule &module);
153+
static void moveInstruction(SILInstruction *inst, SILInstruction *beforeInst);
154+
void moveInstructionToFront(SILInstruction *inst);
154155

155156
void eraseAllInstructions(SILModule &module);
156157

include/swift/SIL/SILInstruction.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,6 @@ class SILInstruction : public llvm::ilist_node<SILInstruction> {
376376
NumCreatedInstructions++;
377377
}
378378

379-
/// This method unlinks 'self' from the containing basic block.
380-
void removeFromParent();
381-
382379
~SILInstruction() {
383380
NumDeletedInstructions++;
384381
}

lib/SIL/IR/SILBasicBlock.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ void SILBasicBlock::push_front(SILInstruction *I) {
9191
InstList.push_front(I);
9292
}
9393

94-
void SILBasicBlock::remove(SILInstruction *I) {
95-
InstList.remove(I);
96-
}
97-
9894
void SILBasicBlock::eraseAllInstructions(SILModule &module) {
9995
while (!empty()) {
10096
erase(&*begin(), module);
@@ -112,6 +108,21 @@ void SILBasicBlock::erase(SILInstruction *I, SILModule &module) {
112108
module.scheduleForDeletion(I);
113109
}
114110

111+
void SILBasicBlock::moveInstruction(SILInstruction *inst,
112+
SILInstruction *beforeInst) {
113+
if (inst == beforeInst)
114+
return;
115+
inst->getParent()->InstList.remove(inst);
116+
inst->ParentBB = nullptr;
117+
beforeInst->getParent()->insert(beforeInst->getIterator(), inst);
118+
}
119+
120+
void SILBasicBlock::moveInstructionToFront(SILInstruction *inst) {
121+
inst->getParent()->InstList.remove(inst);
122+
inst->ParentBB = nullptr;
123+
push_front(inst);
124+
}
125+
115126
/// This method unlinks 'self' from the containing SILFunction and deletes it.
116127
void SILBasicBlock::eraseFromParent() {
117128
getParent()->eraseBlock(this);

lib/SIL/IR/SILInstruction.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,6 @@ transferNodesFromList(llvm::ilist_traits<SILInstruction> &L2,
103103
ASSERT_IMPLEMENTS_STATIC(CLASS, PARENT, classof, bool(SILNodePointer));
104104
#include "swift/SIL/SILNodes.def"
105105

106-
void SILInstruction::removeFromParent() {
107-
#ifndef NDEBUG
108-
for (auto result : getResults()) {
109-
assert(result->use_empty() && "Uses of SILInstruction remain at deletion.");
110-
}
111-
#endif
112-
getParent()->remove(this);
113-
ParentBB = nullptr;
114-
}
115-
116106
/// eraseFromParent - This method unlinks 'self' from the containing basic
117107
/// block and deletes it.
118108
///
@@ -126,18 +116,13 @@ void SILInstruction::eraseFromParent() {
126116
}
127117

128118
void SILInstruction::moveFront(SILBasicBlock *Block) {
129-
getParent()->remove(this);
130-
Block->push_front(this);
119+
Block->moveInstructionToFront(this);
131120
}
132121

133122
/// Unlink this instruction from its current basic block and insert it into
134123
/// the basic block that Later lives in, right before Later.
135124
void SILInstruction::moveBefore(SILInstruction *Later) {
136-
if (this == Later)
137-
return;
138-
139-
getParent()->remove(this);
140-
Later->getParent()->insert(Later, this);
125+
SILBasicBlock::moveInstruction(this, Later);
141126
}
142127

143128
/// Unlink this instruction from its current basic block and insert it into

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3885,8 +3885,7 @@ static void deleteRewrittenInstructions(AddressLoweringState &pass) {
38853885
}
38863886
// willDeleteInstruction was already called for open_existential_value to
38873887
// update the registered type. Carry out the remaining deletion steps.
3888-
deadInst->getParent()->remove(deadInst);
3889-
pass.getModule()->scheduleForDeletion(deadInst);
3888+
deadInst->getParent()->erase(deadInst);
38903889
}
38913890

38923891
pass.valueStorageMap.clear();

0 commit comments

Comments
 (0)