summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/BasicBlock.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2017-05-26 03:10:00 +0000
committerChandler Carruth <chandlerc@gmail.com>2017-05-26 03:10:00 +0000
commit8fa1e3734267a71b8bca39e6d3fa42516a1da924 (patch)
tree4255c461b4f504e82c37e710611d48ad0fffda6f /llvm/lib/IR/BasicBlock.cpp
parent997a391466504e5d40929b6e8af88a054f44ab3d (diff)
downloadbcm5719-llvm-8fa1e3734267a71b8bca39e6d3fa42516a1da924.tar.gz
bcm5719-llvm-8fa1e3734267a71b8bca39e6d3fa42516a1da924.zip
[IR] Add an iterator and range accessor for the PHI nodes of a basic
block. This allows writing much more natural and readable range based for loops directly over the PHI nodes. It also takes advantage of the same tricks for terminating the sequence as the hand coded versions. I've replaced one example of this mostly to showcase the difference and I've added a unit test to make sure the facilities really work the way they're intended. I want to use this inside of SimpleLoopUnswitch but it seems generally nice. Differential Revision: https://reviews.llvm.org/D33533 llvm-svn: 303964
Diffstat (limited to 'llvm/lib/IR/BasicBlock.cpp')
-rw-r--r--llvm/lib/IR/BasicBlock.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index 90ca21ab91f..1f8659d4e2c 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/lib/IR/BasicBlock.cpp
@@ -263,6 +263,10 @@ const BasicBlock *BasicBlock::getUniqueSuccessor() const {
return SuccBB;
}
+iterator_range<BasicBlock::phi_iterator> BasicBlock::phis() {
+ return make_range<phi_iterator>(dyn_cast<PHINode>(&front()), nullptr);
+}
+
/// This method is used to notify a BasicBlock that the
/// specified Predecessor of the block is no longer able to reach it. This is
/// actually not used to update the Predecessor list, but is actually used to
@@ -389,13 +393,11 @@ 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;
- PHINode *PN;
- for (BasicBlock::iterator II = Successor->begin();
- (PN = dyn_cast<PHINode>(II)); ++II) {
- int IDX = PN->getBasicBlockIndex(this);
- while (IDX != -1) {
- PN->setIncomingBlock((unsigned)IDX, New);
- IDX = PN->getBasicBlockIndex(this);
+ for (auto &PN : Successor->phis()) {
+ int Idx = PN.getBasicBlockIndex(this);
+ while (Idx != -1) {
+ PN.setIncomingBlock((unsigned)Idx, New);
+ Idx = PN.getBasicBlockIndex(this);
}
}
}
OpenPOWER on IntegriCloud