Skip to content

Commit

Permalink
Add instruction list manipulation functions to SILBasicBlock.
Browse files Browse the repository at this point in the history
Begin using these functions to encapsulate the instruction list rather
than directly accessing it via getInstList().

Swift SVN r32298
  • Loading branch information
rudkx committed Sep 29, 2015
1 parent 19a88e3 commit 46b2de0
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
4 changes: 4 additions & 0 deletions include/swift/SIL/SILBasicBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public llvm::ilist_node<SILBasicBlock>, public SILAllocated<SILBasicBlock> {
using reverse_iterator = InstListType::reverse_iterator;
using const_reverse_iterator = InstListType::const_reverse_iterator;

void insert(iterator InsertPt, SILInstruction *I);
void remove(SILInstruction *I);
void erase(SILInstruction *I);

bool empty() const { return InstList.empty(); }
iterator begin() { return InstList.begin(); }
iterator end() { return InstList.end(); }
Expand Down
2 changes: 1 addition & 1 deletion include/swift/SIL/SILBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ class SILBuilder {
if (InsertedInstrs)
InsertedInstrs->push_back(TheInst);

BB->getInstList().insert(InsertPt, TheInst);
BB->insert(InsertPt, TheInst);
}
};

Expand Down
12 changes: 12 additions & 0 deletions lib/SIL/SILBasicBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ SILModule &SILBasicBlock::getModule() const {
return getParent()->getModule();
}

void SILBasicBlock::insert(iterator InsertPt, SILInstruction *I) {
getInstList().insert(InsertPt, I);
}

void SILBasicBlock::remove(SILInstruction *I) {
getInstList().remove(I);
}

void SILBasicBlock::erase(SILInstruction *I) {
getInstList().erase(I);
}

/// This method unlinks 'self' from the containing SILFunction and deletes it.
void SILBasicBlock::eraseFromParent() {
getParent()->getBlocks().erase(this);
Expand Down
6 changes: 3 additions & 3 deletions lib/SIL/SILInstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ SILModule &SILInstruction::getModule() const {
/// block, but does not delete it.
///
void SILInstruction::removeFromParent() {
getParent()->getInstList().remove(this);
getParent()->remove(this);
}

/// eraseFromParent - This method unlinks 'self' from the containing basic
/// block and deletes it.
///
void SILInstruction::eraseFromParent() {
assert(use_empty() && "There are uses of instruction being deleted.");
getParent()->getInstList().erase(this);
getParent()->erase(this);
}

/// Unlink this instruction from its current basic block and insert it into
Expand Down Expand Up @@ -756,7 +756,7 @@ SILInstruction *SILInstruction::clone(SILInstruction *InsertPt) {
SILInstruction *NewInst = TrivialCloner::doIt(this);

if (NewInst && InsertPt)
InsertPt->getParent()->getInstList().insert(InsertPt, NewInst);
InsertPt->getParent()->insert(InsertPt, NewInst);
return NewInst;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/SILGen/SILGenEpilog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ SILGenFunction::emitEpilogBB(SILLocation TopLevel) {
}

// Kill the branch to the now-dead epilog BB.
pred->getInstList().erase(predBranch);
pred->erase(predBranch);

// Move any instructions from the EpilogBB to the end of the 'pred' block.
pred->getInstList().splice(pred->end(), epilogBB->getInstList());
Expand Down Expand Up @@ -220,7 +220,7 @@ void SILGenFunction::emitRethrowEpilog(SILLocation topLevel) {
// then destroy it.
throwLoc = branch->getLoc();
exn = branch->getArgs()[0];
predBB->getInstList().erase(branch);
predBB->erase(branch);

// Erase the rethrow block.
eraseBasicBlock(rethrowBB);
Expand Down
2 changes: 1 addition & 1 deletion lib/SILPasses/SILCombine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ SILInstruction *SILCombiner::insertNewInstBefore(SILInstruction *New,
assert(New && New->getParent() == 0 &&
"New instruction already inserted into a basic block!");
SILBasicBlock *BB = Old.getParent();
BB->getInstList().insert(&Old, New); // Insert inst
BB->insert(&Old, New); // Insert inst
Worklist.add(New);
return New;
}
Expand Down

0 comments on commit 46b2de0

Please sign in to comment.