aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/Local.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-01-12 19:40:54 +0000
committerChris Lattner <sabre@nondot.org>2010-01-12 19:40:54 +0000
commit7c743f2c7474105654716a4398394b48d84c1e7f (patch)
tree1a21247eb349361e3a3e0250a4c0f7ee41957784 /llvm/lib/Transforms/Utils/Local.cpp
parent55e3e83b07660d89f70f20d0790c45c5f49c7f72 (diff)
downloadllvm-7c743f2c7474105654716a4398394b48d84c1e7f.zip
llvm-7c743f2c7474105654716a4398394b48d84c1e7f.tar.gz
llvm-7c743f2c7474105654716a4398394b48d84c1e7f.tar.bz2
add a helper function.
llvm-svn: 93251
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 1a7d27a..90e929e 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -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.
//