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 | a1f6e648bed9d6eb28d6f292a3ac4e3e5bcedd2e (patch) | |
tree | f938a5ca9333c8481e189dac7ce6a6860be4f11c /lib | |
parent | fd0375bf86c838aa20095f2e5d14dca03422d00b (diff) | |
download | external_llvm-a1f6e648bed9d6eb28d6f292a3ac4e3e5bcedd2e.zip external_llvm-a1f6e648bed9d6eb28d6f292a3ac4e3e5bcedd2e.tar.gz external_llvm-a1f6e648bed9d6eb28d6f292a3ac4e3e5bcedd2e.tar.bz2 |
Expose the low level DCE mechanism to external users
Refactor code to support it
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1083 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/Scalar/DCE.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/lib/Transforms/Scalar/DCE.cpp b/lib/Transforms/Scalar/DCE.cpp index 71a7f5a..ac3ae7b 100644 --- a/lib/Transforms/Scalar/DCE.cpp +++ b/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; } |