mirror of
https://github.com/RPCSX/llvm.git
synced 2025-02-13 17:20:28 +00:00
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
This commit is contained in:
parent
fd0375bf86
commit
a1f6e648be
@ -34,20 +34,30 @@
|
|||||||
#include "llvm/Assembly/Writer.h"
|
#include "llvm/Assembly/Writer.h"
|
||||||
#include <algorithm>
|
#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;
|
bool Changed = false;
|
||||||
for (BasicBlock::InstListType::iterator DI = Vals.begin();
|
for (BasicBlock::InstListType::iterator DI = Vals.begin();
|
||||||
DI != Vals.end()-1; ) {
|
DI != Vals.end(); )
|
||||||
// Look for un"used" definitions...
|
if (opt::DeadCodeElimination::dceInstruction(Vals, DI))
|
||||||
if ((*DI)->use_empty() && !(*DI)->hasSideEffects()) {
|
|
||||||
// Bye bye
|
|
||||||
//cerr << "Removing: " << *DI;
|
|
||||||
delete Vals.remove(DI);
|
|
||||||
Changed = true;
|
Changed = true;
|
||||||
} else {
|
else
|
||||||
++DI;
|
++DI;
|
||||||
}
|
|
||||||
}
|
|
||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user