move MergeBasicBlockIntoOnlyPred to Transforms/Utils.
authorChris Lattner <sabre@nondot.org>
Thu, 27 Nov 2008 07:43:12 +0000 (07:43 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 27 Nov 2008 07:43:12 +0000 (07:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60162 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Transforms/Utils/Local.h
lib/Transforms/Scalar/JumpThreading.cpp
lib/Transforms/Utils/Local.cpp

index e65638d94a02b2f9adb793be1b9fbfc619f8ea6d..42927297565768befaa8596d3f9642c98311ddf7 100644 (file)
@@ -62,6 +62,14 @@ bool dceInstruction(BasicBlock::iterator &BBI);
 //  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
index b6d8ff6b35e29755e7e140b682cef507cfa11ba8..eb4a873a464d91e42b1b3c860a65bf9b5b8b2cb5 100644 (file)
@@ -156,37 +156,6 @@ static unsigned getJumpThreadDuplicationCost(const BasicBlock *BB) {
   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) {
index ed67c5eaaaee080b502c160cad82f08a7e9cfa71..efb902267d99d835b746e7219c91389fbd5efe82 100644 (file)
@@ -200,3 +200,36 @@ bool llvm::dceInstruction(BasicBlock::iterator &BBI) {
   }
   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();
+}