[llvm] r359997 - [NFC] BasicBlock: generalize replaceSuccessorsPhiUsesWith(), take Old bb
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Sun May 5 11:59:45 PDT 2019
Author: lebedevri
Date: Sun May 5 11:59:45 2019
New Revision: 359997
URL: http://llvm.org/viewvc/llvm-project?rev=359997&view=rev
Log:
[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.
Modified:
llvm/trunk/include/llvm/IR/BasicBlock.h
llvm/trunk/lib/IR/BasicBlock.cpp
Modified: llvm/trunk/include/llvm/IR/BasicBlock.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/BasicBlock.h?rev=359997&r1=359996&r2=359997&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/BasicBlock.h (original)
+++ llvm/trunk/include/llvm/IR/BasicBlock.h Sun May 5 11:59:45 2019
@@ -395,6 +395,10 @@ public:
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
/// block \p New instead of to it.
void replaceSuccessorsPhiUsesWith(BasicBlock *New);
Modified: llvm/trunk/lib/IR/BasicBlock.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/BasicBlock.cpp?rev=359997&r1=359996&r2=359997&view=diff
==============================================================================
--- llvm/trunk/lib/IR/BasicBlock.cpp (original)
+++ llvm/trunk/lib/IR/BasicBlock.cpp Sun May 5 11:59:45 2019
@@ -425,11 +425,9 @@ BasicBlock *BasicBlock::splitBasicBlock(
// 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
// 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) {
- Succ->replacePhiUsesWith(this, New);
- });
+ New->replaceSuccessorsPhiUsesWith(this, New);
return New;
}
@@ -444,17 +442,22 @@ void BasicBlock::replacePhiUsesWith(Basi
}
}
-void BasicBlock::replaceSuccessorsPhiUsesWith(BasicBlock *New) {
+void BasicBlock::replaceSuccessorsPhiUsesWith(BasicBlock *Old,
+ BasicBlock *New) {
Instruction *TI = getTerminator();
if (!TI)
// Cope with being called on a BasicBlock that doesn't have a terminator
// yet. Clang's CodeGenFunction::EmitReturnBlock() likes to do this.
return;
- llvm::for_each(successors(TI), [this, New](BasicBlock *Succ) {
- Succ->replacePhiUsesWith(this, New);
+ llvm::for_each(successors(TI), [Old, New](BasicBlock *Succ) {
+ 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
/// the destination of the 'unwind' edge of an invoke instruction.
bool BasicBlock::isLandingPad() const {
More information about the llvm-commits
mailing list