Change over to use new style pass mechanism, now passes only expose small

creation functions in their public header file, unless they can help it.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1816 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2002-02-26 21:46:54 +00:00
parent 3b2541424f
commit bd0ef77cde
32 changed files with 528 additions and 512 deletions

View File

@ -32,6 +32,7 @@
#include "llvm/iPHINode.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/Support/CFG.h"
#include "llvm/Pass.h"
#include "Support/STLExtras.h"
#include <algorithm>
@ -40,8 +41,8 @@
// to point to the instruction that immediately succeeded the original
// instruction.
//
bool DeadCodeElimination::dceInstruction(BasicBlock::InstListType &BBIL,
BasicBlock::iterator &BBI) {
bool dceInstruction(BasicBlock::InstListType &BBIL,
BasicBlock::iterator &BBI) {
// Look for un"used" definitions...
if ((*BBI)->use_empty() && !(*BBI)->hasSideEffects() &&
!isa<TerminatorInst>(*BBI)) {
@ -55,15 +56,21 @@ static inline bool RemoveUnusedDefs(BasicBlock::InstListType &Vals) {
bool Changed = false;
for (BasicBlock::InstListType::iterator DI = Vals.begin();
DI != Vals.end(); )
if (DeadCodeElimination::dceInstruction(Vals, DI))
if (dceInstruction(Vals, DI))
Changed = true;
else
++DI;
return Changed;
}
bool DeadInstElimination::runOnBasicBlock(BasicBlock *BB) {
return RemoveUnusedDefs(BB->getInstList());
struct DeadInstElimination : public BasicBlockPass {
virtual bool runOnBasicBlock(BasicBlock *BB) {
return RemoveUnusedDefs(BB->getInstList());
}
};
Pass *createDeadInstEliminationPass() {
return new DeadInstElimination();
}
// RemoveSingularPHIs - This removes PHI nodes from basic blocks that have only
@ -297,17 +304,11 @@ static bool DoDCEPass(Method *M) {
return Changed;
}
// It is possible that we may require multiple passes over the code to fully
// eliminate dead code. Iterate until we are done.
// Remove unused global values - This removes unused global values of no
// possible value. This currently includes unused method prototypes and
// unitialized global variables.
//
bool DeadCodeElimination::doDCE(Method *M) {
bool Changed = false;
while (DoDCEPass(M)) Changed = true;
return Changed;
}
bool DeadCodeElimination::RemoveUnusedGlobalValues(Module *Mod) {
static bool RemoveUnusedGlobalValues(Module *Mod) {
bool Changed = false;
for (Module::iterator MI = Mod->begin(); MI != Mod->end(); ) {
@ -338,3 +339,30 @@ bool DeadCodeElimination::RemoveUnusedGlobalValues(Module *Mod) {
return Changed;
}
namespace {
struct DeadCodeElimination : public MethodPass {
// Pass Interface...
virtual bool doInitialization(Module *M) {
return RemoveUnusedGlobalValues(M);
}
// It is possible that we may require multiple passes over the code to fully
// eliminate dead code. Iterate until we are done.
//
virtual bool runOnMethod(Method *M) {
bool Changed = false;
while (DoDCEPass(M)) Changed = true;
return Changed;
}
virtual bool doFinalization(Module *M) {
return RemoveUnusedGlobalValues(M);
}
};
}
Pass *createDeadCodeEliminationPass() {
return new DeadCodeElimination();
}