diff options
author | Chris Lattner <sabre@nondot.org> | 2010-01-12 19:40:54 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-01-12 19:40:54 +0000 |
commit | e234a30a282f1aaec4aa63460fe8bba6416832a8 (patch) | |
tree | a3de201469b3069649eb75fe2e125edba4e9991a | |
parent | d77fdba5737ee71b63681160fba5b2fc200583f4 (diff) | |
download | llvm-e234a30a282f1aaec4aa63460fe8bba6416832a8.tar.gz llvm-e234a30a282f1aaec4aa63460fe8bba6416832a8.tar.bz2 llvm-e234a30a282f1aaec4aa63460fe8bba6416832a8.tar.xz |
add a helper function.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93251 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/Transforms/Utils/Local.h | 8 | ||||
-rw-r--r-- | lib/Transforms/Utils/Local.cpp | 24 |
2 files changed, 32 insertions, 0 deletions
diff --git a/include/llvm/Transforms/Utils/Local.h b/include/llvm/Transforms/Utils/Local.h index 103d4cda41..0b8147e76d 100644 --- a/include/llvm/Transforms/Utils/Local.h +++ b/include/llvm/Transforms/Utils/Local.h @@ -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. // diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp index 1a7d27ad45..90e929e127 100644 --- a/lib/Transforms/Utils/Local.cpp +++ b/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. // |