Avoid creating redundant PHIs in SSAUpdater::GetValueInMiddleOfBlock.
[oota-llvm.git] / lib / Transforms / Utils / Local.cpp
index 1a7d27ad45c75455a7d8662a35b0cec94b3abafd..92bdf2de449ea2168ff636aaec4d122602ce36b3 100644 (file)
@@ -335,6 +335,30 @@ llvm::RecursivelyDeleteDeadPHINode(PHINode *PN) {
   return Changed;
 }
 
+/// SimplifyInstructionsInBlock - Scan the specified basic block and try to
+/// simplify any instructions in it and recursively delete dead instructions.
+///
+/// This returns true if it changed the code, note that it can delete
+/// instructions in other blocks as well in this block.
+bool llvm::SimplifyInstructionsInBlock(BasicBlock *BB, const TargetData *TD) {
+  bool MadeChange = false;
+  for (BasicBlock::iterator BI = BB->begin(), E = BB->end(); BI != E; ) {
+    Instruction *Inst = BI++;
+    
+    if (Value *V = SimplifyInstruction(Inst, TD)) {
+      WeakVH BIHandle(BI);
+      ReplaceAndSimplifyAllUses(Inst, V, TD);
+      MadeChange = true;
+      if (BIHandle == 0)
+        BI = BB->begin();
+      continue;
+    }
+    
+    MadeChange |= RecursivelyDeleteTriviallyDeadInstructions(Inst);
+  }
+  return MadeChange;
+}
+
 //===----------------------------------------------------------------------===//
 //  Control Flow Graph Restructuring.
 //
@@ -585,30 +609,6 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB) {
   return true;
 }
 
-
-
-/// OnlyUsedByDbgIntrinsics - Return true if the instruction I is only used
-/// by DbgIntrinsics. If DbgInUses is specified then the vector is filled 
-/// with the DbgInfoIntrinsic that use the instruction I.
-bool llvm::OnlyUsedByDbgInfoIntrinsics(Instruction *I, 
-                               SmallVectorImpl<DbgInfoIntrinsic *> *DbgInUses) {
-  if (DbgInUses)
-    DbgInUses->clear();
-
-  for (Value::use_iterator UI = I->use_begin(), UE = I->use_end(); UI != UE; 
-       ++UI) {
-    if (DbgInfoIntrinsic *DI = dyn_cast<DbgInfoIntrinsic>(*UI)) {
-      if (DbgInUses)
-        DbgInUses->push_back(DI);
-    } else {
-      if (DbgInUses)
-        DbgInUses->clear();
-      return false;
-    }
-  }
-  return true;
-}
-
 /// EliminateDuplicatePHINodes - Check for and eliminate duplicate PHI
 /// nodes in this block. This doesn't try to be clever about PHI nodes
 /// which differ only in the order of the incoming values, but instcombine