diff options
author | Roman Lebedev <lebedev.ri@gmail.com> | 2019-05-05 18:59:30 +0000 |
---|---|---|
committer | Roman Lebedev <lebedev.ri@gmail.com> | 2019-05-05 18:59:30 +0000 |
commit | e3b1d82b5302102c17ea465ca609cde2a49da314 (patch) | |
tree | 3bdbf877cf939a560ed3b6891f3826bd38f0d159 /llvm/lib/IR/BasicBlock.cpp | |
parent | 7ad5d14f3a2c916277e25737de9ff3f605131d1a (diff) | |
download | llvm-e3b1d82b5302102c17ea465ca609cde2a49da314.zip llvm-e3b1d82b5302102c17ea465ca609cde2a49da314.tar.gz llvm-e3b1d82b5302102c17ea465ca609cde2a49da314.tar.bz2 |
[NFC] PHINode: introduce replaceIncomingBlockWith() function, use it
Summary:
There is `PHINode::getBasicBlockIndex()`, `PHINode::setIncomingBlock()`
and `PHINode::getNumOperands()`, but no function to replace every
specified `BasicBlock*` predecessor with some other specified `BasicBlock*`.
Clearly, there are a lot of places that could use that functionality.
Reviewers: chandlerc, craig.topper, spatel, danielcdh
Reviewed By: craig.topper
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D61011
llvm-svn: 359995
Diffstat (limited to 'llvm/lib/IR/BasicBlock.cpp')
-rw-r--r-- | llvm/lib/IR/BasicBlock.cpp | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp index 18e2fd89..8dde864 100644 --- a/llvm/lib/IR/BasicBlock.cpp +++ b/llvm/lib/IR/BasicBlock.cpp @@ -431,13 +431,8 @@ BasicBlock *BasicBlock::splitBasicBlock(iterator I, const Twine &BBName) { // Loop over any phi nodes in the basic block, updating the BB field of // incoming values... BasicBlock *Successor = *I; - for (auto &PN : Successor->phis()) { - int Idx = PN.getBasicBlockIndex(this); - while (Idx != -1) { - PN.setIncomingBlock((unsigned)Idx, New); - Idx = PN.getBasicBlockIndex(this); - } - } + for (auto &PN : Successor->phis()) + PN.replaceIncomingBlockWith(this, New); } return New; } @@ -455,9 +450,7 @@ void BasicBlock::replaceSuccessorsPhiUsesWith(BasicBlock *New) { PHINode *PN = dyn_cast<PHINode>(II); if (!PN) break; - int i; - while ((i = PN->getBasicBlockIndex(this)) >= 0) - PN->setIncomingBlock(i, New); + PN->replaceIncomingBlockWith(this, New); } } } |