add a helper function.
authorChris Lattner <sabre@nondot.org>
Tue, 12 Jan 2010 19:40:54 +0000 (19:40 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 12 Jan 2010 19:40:54 +0000 (19:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93251 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 103d4cda41a50554fa30c5a35283988f1ca121f5..0b8147e76dfd95865db9b34d4a62c63ead3ad88c 100644 (file)
@@ -74,6 +74,14 @@ bool RecursivelyDeleteTriviallyDeadInstructions(Value *V);
 /// too, recursively.  Return true if the PHI node is actually deleted.
 bool RecursivelyDeleteDeadPHINode(PHINode *PN);
 
+  
+/// 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 SimplifyInstructionsInBlock(BasicBlock *BB, const TargetData *TD = 0);
+    
 //===----------------------------------------------------------------------===//
 //  Control Flow Graph Restructuring.
 //
index 1a7d27ad45c75455a7d8662a35b0cec94b3abafd..90e929e127e23d48f22097463d646a88e8f8541d 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.
 //