1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

[NFC] BasicBlock: generalize replaceSuccessorsPhiUsesWith(), take Old bb

Thus it does not assume that the old basic block is the basic block
for which we are looking at successors.

Not reviewed, but seems rather trivial, in line with the rest of
previous few patches.

llvm-svn: 359997
This commit is contained in:
Roman Lebedev 2019-05-05 18:59:45 +00:00
parent 31e17ece8e
commit c9aa17b183
2 changed files with 14 additions and 7 deletions

View File

@ -394,6 +394,10 @@ public:
/// instead of basic block \p Old. /// instead of basic block \p Old.
void replacePhiUsesWith(BasicBlock *Old, BasicBlock *New); void replacePhiUsesWith(BasicBlock *Old, BasicBlock *New);
/// Update all phi nodes in this basic block's successors to refer to basic
/// block \p New instead of basic block \p Old.
void replaceSuccessorsPhiUsesWith(BasicBlock *Old, BasicBlock *New);
/// Update all phi nodes in this basic block's successors to refer to basic /// Update all phi nodes in this basic block's successors to refer to basic
/// block \p New instead of to it. /// block \p New instead of to it.
void replaceSuccessorsPhiUsesWith(BasicBlock *New); void replaceSuccessorsPhiUsesWith(BasicBlock *New);

View File

@ -425,11 +425,9 @@ BasicBlock *BasicBlock::splitBasicBlock(iterator I, const Twine &BBName) {
// Now we must loop through all of the successors of the New block (which // Now we must loop through all of the successors of the New block (which
// _were_ the successors of the 'this' block), and update any PHI nodes in // _were_ the successors of the 'this' block), and update any PHI nodes in
// successors. If there were PHI nodes in the successors, then they need to // successors. If there were PHI nodes in the successors, then they need to
// know that incoming branches will be from New, not from Old. // know that incoming branches will be from New, not from Old (this).
// //
llvm::for_each(successors(New), [this, New](BasicBlock *Succ) { New->replaceSuccessorsPhiUsesWith(this, New);
Succ->replacePhiUsesWith(this, New);
});
return New; return New;
} }
@ -444,17 +442,22 @@ void BasicBlock::replacePhiUsesWith(BasicBlock *Old, BasicBlock *New) {
} }
} }
void BasicBlock::replaceSuccessorsPhiUsesWith(BasicBlock *New) { void BasicBlock::replaceSuccessorsPhiUsesWith(BasicBlock *Old,
BasicBlock *New) {
Instruction *TI = getTerminator(); Instruction *TI = getTerminator();
if (!TI) if (!TI)
// Cope with being called on a BasicBlock that doesn't have a terminator // Cope with being called on a BasicBlock that doesn't have a terminator
// yet. Clang's CodeGenFunction::EmitReturnBlock() likes to do this. // yet. Clang's CodeGenFunction::EmitReturnBlock() likes to do this.
return; return;
llvm::for_each(successors(TI), [this, New](BasicBlock *Succ) { llvm::for_each(successors(TI), [Old, New](BasicBlock *Succ) {
Succ->replacePhiUsesWith(this, New); Succ->replacePhiUsesWith(Old, New);
}); });
} }
void BasicBlock::replaceSuccessorsPhiUsesWith(BasicBlock *New) {
this->replaceSuccessorsPhiUsesWith(this, New);
}
/// Return true if this basic block is a landing pad. I.e., it's /// Return true if this basic block is a landing pad. I.e., it's
/// the destination of the 'unwind' edge of an invoke instruction. /// the destination of the 'unwind' edge of an invoke instruction.
bool BasicBlock::isLandingPad() const { bool BasicBlock::isLandingPad() const {