[llvm-commits] [llvm] r60162 - in /llvm/trunk: include/llvm/Transforms/Utils/Local.h lib/Transforms/Scalar/JumpThreading.cpp lib/Transforms/Utils/Local.cpp
Chris Lattner
sabre at nondot.org
Wed Nov 26 23:43:12 PST 2008
Author: lattner
Date: Thu Nov 27 01:43:12 2008
New Revision: 60162
URL: http://llvm.org/viewvc/llvm-project?rev=60162&view=rev
Log:
move MergeBasicBlockIntoOnlyPred to Transforms/Utils.
Modified:
llvm/trunk/include/llvm/Transforms/Utils/Local.h
llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp
llvm/trunk/lib/Transforms/Utils/Local.cpp
Modified: llvm/trunk/include/llvm/Transforms/Utils/Local.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/Local.h?rev=60162&r1=60161&r2=60162&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/Local.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/Local.h Thu Nov 27 01:43:12 2008
@@ -62,6 +62,14 @@
// Control Flow Graph Restructuring...
//
+/// MergeBasicBlockIntoOnlyPred - BB is a block with one predecessor and its
+/// predecessor is known to have one successor (BB!). Eliminate the edge
+/// between them, moving the instructions in the predecessor into BB. This
+/// deletes the predecessor block.
+///
+void MergeBasicBlockIntoOnlyPred(BasicBlock *BB);
+
+
/// SimplifyCFG - This function is used to do simplification of a CFG. For
/// example, it adjusts branches to branches to eliminate the extra hop, it
/// eliminates unreachable basic blocks, and does other "peephole" optimization
Modified: llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp?rev=60162&r1=60161&r2=60162&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp Thu Nov 27 01:43:12 2008
@@ -156,37 +156,6 @@
return Size;
}
-/// MergeBasicBlockIntoOnlyPred - DestBB is a block with one predecessor and its
-/// predecessor is known to have one successor (DestBB!). Eliminate the edge
-/// between them, moving the instructions in the predecessor into DestBB and
-/// deleting the predecessor block.
-///
-/// FIXME: Move to TransformUtils to share with simplifycfg and codegenprepare.
-static void MergeBasicBlockIntoOnlyPred(BasicBlock *DestBB) {
- // If BB has single-entry PHI nodes, fold them.
- while (PHINode *PN = dyn_cast<PHINode>(DestBB->begin())) {
- Value *NewVal = PN->getIncomingValue(0);
- // Replace self referencing PHI with undef, it must be dead.
- if (NewVal == PN) NewVal = UndefValue::get(PN->getType());
- PN->replaceAllUsesWith(NewVal);
- PN->eraseFromParent();
- }
-
- BasicBlock *PredBB = DestBB->getSinglePredecessor();
- assert(PredBB && "Block doesn't have a single predecessor!");
-
- // Splice all the instructions from PredBB to DestBB.
- PredBB->getTerminator()->eraseFromParent();
- DestBB->getInstList().splice(DestBB->begin(), PredBB->getInstList());
-
- // Anything that branched to PredBB now branches to DestBB.
- PredBB->replaceAllUsesWith(DestBB);
-
- // Nuke BB.
- PredBB->eraseFromParent();
-}
-
-
/// ProcessBlock - If there are any predecessors whose control can be threaded
/// through to a successor, transform them now.
bool JumpThreading::ProcessBlock(BasicBlock *BB) {
Modified: llvm/trunk/lib/Transforms/Utils/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=60162&r1=60161&r2=60162&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/Local.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/Local.cpp Thu Nov 27 01:43:12 2008
@@ -200,3 +200,36 @@
}
return false;
}
+
+//===----------------------------------------------------------------------===//
+// Control Flow Graph Restructuring...
+//
+
+/// MergeBasicBlockIntoOnlyPred - DestBB is a block with one predecessor and its
+/// predecessor is known to have one successor (DestBB!). Eliminate the edge
+/// between them, moving the instructions in the predecessor into DestBB and
+/// deleting the predecessor block.
+///
+void llvm::MergeBasicBlockIntoOnlyPred(BasicBlock *DestBB) {
+ // If BB has single-entry PHI nodes, fold them.
+ while (PHINode *PN = dyn_cast<PHINode>(DestBB->begin())) {
+ Value *NewVal = PN->getIncomingValue(0);
+ // Replace self referencing PHI with undef, it must be dead.
+ if (NewVal == PN) NewVal = UndefValue::get(PN->getType());
+ PN->replaceAllUsesWith(NewVal);
+ PN->eraseFromParent();
+ }
+
+ BasicBlock *PredBB = DestBB->getSinglePredecessor();
+ assert(PredBB && "Block doesn't have a single predecessor!");
+
+ // Splice all the instructions from PredBB to DestBB.
+ PredBB->getTerminator()->eraseFromParent();
+ DestBB->getInstList().splice(DestBB->begin(), PredBB->getInstList());
+
+ // Anything that branched to PredBB now branches to DestBB.
+ PredBB->replaceAllUsesWith(DestBB);
+
+ // Nuke BB.
+ PredBB->eraseFromParent();
+}
More information about the llvm-commits
mailing list