diff options
author | Chris Lattner <sabre@nondot.org> | 2001-11-01 07:00:27 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2001-11-01 07:00:27 +0000 |
commit | 7567f6c15fd73a33c51e474fdf68ca8c4b80f3f4 (patch) | |
tree | 1a62dd41cddbb4901b6e004637bcc2a54732a5ec /llvm | |
parent | 63ac2b335a833f6e788d370102b23048b4d984e4 (diff) | |
download | bcm5719-llvm-7567f6c15fd73a33c51e474fdf68ca8c4b80f3f4.tar.gz bcm5719-llvm-7567f6c15fd73a33c51e474fdf68ca8c4b80f3f4.zip |
Expose the low level DCE mechanism to external users
Refactor code to support it
llvm-svn: 1083
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/lib/Transforms/Scalar/DCE.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/Scalar/DCE.cpp b/llvm/lib/Transforms/Scalar/DCE.cpp index 71a7f5ae26b..ac3ae7b66ba 100644 --- a/llvm/lib/Transforms/Scalar/DCE.cpp +++ b/llvm/lib/Transforms/Scalar/DCE.cpp @@ -34,20 +34,30 @@ #include "llvm/Assembly/Writer.h" #include <algorithm> -static bool RemoveUnusedDefs(BasicBlock::InstListType &Vals) { +// dceInstruction - Inspect the instruction at *BBI and figure out if it's +// [trivially] dead. If so, remove the instruction and update the iterator +// to point to the instruction that immediately succeeded the original +// instruction. +// +bool opt::DeadCodeElimination::dceInstruction(BasicBlock::InstListType &BBIL, + BasicBlock::iterator &BBI) { + // Look for un"used" definitions... + if ((*BBI)->use_empty() && !(*BBI)->hasSideEffects() && + !isa<TerminatorInst>(*BBI)) { + delete BBIL.remove(BBI); // Bye bye + return true; + } + return false; +} + +static inline bool RemoveUnusedDefs(BasicBlock::InstListType &Vals) { bool Changed = false; for (BasicBlock::InstListType::iterator DI = Vals.begin(); - DI != Vals.end()-1; ) { - // Look for un"used" definitions... - if ((*DI)->use_empty() && !(*DI)->hasSideEffects()) { - // Bye bye - //cerr << "Removing: " << *DI; - delete Vals.remove(DI); + DI != Vals.end(); ) + if (opt::DeadCodeElimination::dceInstruction(Vals, DI)) Changed = true; - } else { + else ++DI; - } - } return Changed; } |