diff options
author | Chris Lattner <sabre@nondot.org> | 2008-12-03 19:44:02 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-12-03 19:44:02 +0000 |
commit | dc3f6f2c124d3d062e76f4576e44e03f3777baaa (patch) | |
tree | 27a93e2e267c8d2f1fd5463d99bfe574b1a5fafe /llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | |
parent | 0c91a5f56c6183e5e28bb9dfe78e48248050fcc4 (diff) | |
download | bcm5719-llvm-dc3f6f2c124d3d062e76f4576e44e03f3777baaa.tar.gz bcm5719-llvm-dc3f6f2c124d3d062e76f4576e44e03f3777baaa.zip |
Factor some code into a new FoldSingleEntryPHINodes method.
llvm-svn: 60501
Diffstat (limited to 'llvm/lib/Transforms/Utils/BasicBlockUtils.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp index 45cfe8f181f..431424ee9f3 100644 --- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -54,6 +54,24 @@ void llvm::DeleteDeadBlock(BasicBlock *BB) { BB->eraseFromParent(); } +/// FoldSingleEntryPHINodes - We know that BB has one predecessor. If there are +/// any single-entry PHI nodes in it, fold them away. This handles the case +/// when all entries to the PHI nodes in a block are guaranteed equal, such as +/// when the block has exactly one predecessor. +void llvm::FoldSingleEntryPHINodes(BasicBlock *BB) { + if (!isa<PHINode>(BB->begin())) + return; + + while (PHINode *PN = dyn_cast<PHINode>(BB->begin())) { + if (PN->getIncomingValue(0) != PN) + PN->replaceAllUsesWith(PN->getIncomingValue(0)); + else + PN->replaceAllUsesWith(UndefValue::get(PN->getType())); + PN->eraseFromParent(); + } +} + + /// MergeBlockIntoPredecessor - Attempts to merge a block into its predecessor, /// if possible. The return value indicates success or failure. bool llvm::MergeBlockIntoPredecessor(BasicBlock* BB, Pass* P) { |