summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore/BasicBlock.cpp
diff options
context:
space:
mode:
authorJay Foad <jay.foad@gmail.com>2011-06-20 14:38:01 +0000
committerJay Foad <jay.foad@gmail.com>2011-06-20 14:38:01 +0000
commite03c05c35a769ce8b074b0278fdc7b602f3527f7 (patch)
treec1e78fbbb2c8c46a1fc5f539e69d0f4e78e3c12d /llvm/lib/VMCore/BasicBlock.cpp
parent372ad64b4db770404805a5ca88ab9d78bea3c386 (diff)
downloadbcm5719-llvm-e03c05c35a769ce8b074b0278fdc7b602f3527f7.tar.gz
bcm5719-llvm-e03c05c35a769ce8b074b0278fdc7b602f3527f7.zip
Change how PHINodes store their operands.
Change PHINodes to store simple pointers to their incoming basic blocks, instead of full-blown Uses. Note that this loses an optimization in SplitCriticalEdge(), because we can no longer walk the use list of a BasicBlock to find phi nodes. See the comment I removed starting "However, the foreach loop is slow for blocks with lots of predecessors". Extend replaceAllUsesWith() on a BasicBlock to also update any phi nodes in the block's successors. This mimics what would have happened when PHINodes were proper Users of their incoming blocks. (Note that this only works if OldBB->replaceAllUsesWith(NewBB) is called when OldBB still has a terminator instruction, so it still has some successors.) llvm-svn: 133435
Diffstat (limited to 'llvm/lib/VMCore/BasicBlock.cpp')
-rw-r--r--llvm/lib/VMCore/BasicBlock.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/BasicBlock.cpp b/llvm/lib/VMCore/BasicBlock.cpp
index 3f1a6a99b64..7d470440aff 100644
--- a/llvm/lib/VMCore/BasicBlock.cpp
+++ b/llvm/lib/VMCore/BasicBlock.cpp
@@ -308,3 +308,19 @@ BasicBlock *BasicBlock::splitBasicBlock(iterator I, const Twine &BBName) {
return New;
}
+void BasicBlock::replaceSuccessorsPhiUsesWith(BasicBlock *New) {
+ TerminatorInst *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;
+ for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i) {
+ BasicBlock *Succ = TI->getSuccessor(i);
+ for (iterator II = Succ->begin(); PHINode *PN = dyn_cast<PHINode>(II);
+ ++II) {
+ int i;
+ while ((i = PN->getBasicBlockIndex(this)) >= 0)
+ PN->setIncomingBlock(i, New);
+ }
+ }
+}
OpenPOWER on IntegriCloud