Add DCE as integral part of the level raising to avoid processing instructions that are dead

llvm-svn: 1084
This commit is contained in:
Chris Lattner 2001-11-01 07:00:51 +00:00
parent 7567f6c15f
commit 71c842cddf
1 changed files with 9 additions and 4 deletions

View File

@ -37,6 +37,7 @@
#include "llvm/ConstPoolVals.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Optimizations/ConstantHandling.h"
#include "llvm/Optimizations/DCE.h"
#include <map>
#include <algorithm>
@ -137,7 +138,8 @@ static const Type *getStructOffsetType(const Type *Ty, unsigned &Offset,
if (Offset >= SL->MemberOffsets[i] && Offset < SL->MemberOffsets[i+1])
break;
assert(Offset >= SL->MemberOffsets[i] && Offset < SL->MemberOffsets[i+1]);
assert(Offset >= SL->MemberOffsets[i] &&
(i == SL->MemberOffsets.size()-1 || Offset < SL->MemberOffsets[i+1]));
// Make sure to save the current index...
Offsets.push_back(ConstPoolUInt::get(Type::UByteTy, i));
@ -459,8 +461,6 @@ static bool PeepholeMallocInst(BasicBlock *BB, BasicBlock::iterator &BI) {
static bool PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) {
Instruction *I = *BI;
// TODO: replace this with a DCE call
if (I->use_size() == 0 && I->getType() != Type::VoidTy) return false;
if (CastInst *CI = dyn_cast<CastInst>(I)) {
Value *Src = CI->getOperand(0);
@ -642,7 +642,8 @@ static bool DoRaisePass(Method *M) {
BasicBlock::InstListType &BIL = BB->getInstList();
for (BasicBlock::iterator BI = BB->begin(); BI != BB->end();) {
if (PeepholeOptimize(BB, BI))
if (opt::DeadCodeElimination::dceInstruction(BIL, BI) ||
PeepholeOptimize(BB, BI))
Changed = true;
else
++BI;
@ -659,6 +660,10 @@ bool RaisePointerReferences::doit(Method *M) {
if (M->isExternal()) return false;
bool Changed = false;
#ifdef DEBUG_PEEPHOLE_INSTS
cerr << "\n\n\nStarting to work on Method '" << M->getName() << "'\n";
#endif
while (DoRaisePass(M)) Changed = true;
// PtrCasts - Keep a mapping between the pointer values (the key of the