mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
factor duplicated code into a new DeleteInstructionInBlock
function, eliminate temporary (and pointless) smallvector. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85776 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
2f09625a9f
commit
cc4f60b113
@ -47,7 +47,6 @@ STATISTIC(NumInstRemoved, "Number of instructions removed");
|
||||
STATISTIC(NumDeadBlocks , "Number of basic blocks unreachable");
|
||||
|
||||
STATISTIC(IPNumInstRemoved, "Number of instructions removed by IPSCCP");
|
||||
STATISTIC(IPNumDeadBlocks , "Number of basic blocks unreachable by IPSCCP");
|
||||
STATISTIC(IPNumArgsElimed ,"Number of arguments constant propagated by IPSCCP");
|
||||
STATISTIC(IPNumGlobalConst, "Number of globals found to be constant by IPSCCP");
|
||||
|
||||
@ -136,6 +135,10 @@ public:
|
||||
Val.setPointer(V);
|
||||
}
|
||||
};
|
||||
} // end anonymous namespace.
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
@ -380,7 +383,6 @@ private:
|
||||
// visit implementations - Something changed in this instruction. Either an
|
||||
// operand made a transition, or the instruction is newly executable. Change
|
||||
// the value type of I to reflect these changes if appropriate.
|
||||
//
|
||||
void visitPHINode(PHINode &I);
|
||||
|
||||
// Terminators
|
||||
@ -1566,6 +1568,21 @@ FunctionPass *llvm::createSCCPPass() {
|
||||
return new SCCP();
|
||||
}
|
||||
|
||||
static void DeleteInstructionInBlock(BasicBlock *BB) {
|
||||
DEBUG(errs() << " BasicBlock Dead:" << *BB);
|
||||
++NumDeadBlocks;
|
||||
|
||||
// Delete the instructions backwards, as it has a reduced likelihood of
|
||||
// having to update as many def-use and use-def chains.
|
||||
while (!isa<TerminatorInst>(BB->begin())) {
|
||||
Instruction *I = --BasicBlock::iterator(BB->getTerminator());
|
||||
|
||||
if (!I->use_empty())
|
||||
I->replaceAllUsesWith(UndefValue::get(I->getType()));
|
||||
BB->getInstList().erase(I);
|
||||
++NumInstRemoved;
|
||||
}
|
||||
}
|
||||
|
||||
// runOnFunction() - Run the Sparse Conditional Constant Propagation algorithm,
|
||||
// and return true if the function was modified.
|
||||
@ -1595,29 +1612,15 @@ bool SCCP::runOnFunction(Function &F) {
|
||||
// delete their contents now. Note that we cannot actually delete the blocks,
|
||||
// as we cannot modify the CFG of the function.
|
||||
//
|
||||
SmallVector<Instruction*, 512> Insts;
|
||||
std::map<Value*, LatticeVal> &Values = Solver.getValueMapping();
|
||||
|
||||
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
|
||||
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
|
||||
if (!Solver.isBlockExecutable(BB)) {
|
||||
DEBUG(errs() << " BasicBlock Dead:" << *BB);
|
||||
++NumDeadBlocks;
|
||||
|
||||
// Delete the instructions backwards, as it has a reduced likelihood of
|
||||
// having to update as many def-use and use-def chains.
|
||||
for (BasicBlock::iterator I = BB->begin(), E = BB->getTerminator();
|
||||
I != E; ++I)
|
||||
Insts.push_back(I);
|
||||
while (!Insts.empty()) {
|
||||
Instruction *I = Insts.back();
|
||||
Insts.pop_back();
|
||||
if (!I->use_empty())
|
||||
I->replaceAllUsesWith(UndefValue::get(I->getType()));
|
||||
BB->getInstList().erase(I);
|
||||
DeleteInstructionInBlock(BB);
|
||||
MadeChanges = true;
|
||||
++NumInstRemoved;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
|
||||
// Iterate over all of the instructions in a function, replacing them with
|
||||
// constants if we have found them to be of constant values.
|
||||
//
|
||||
@ -1738,7 +1741,6 @@ bool IPSCCP::runOnModule(Module &M) {
|
||||
// Iterate over all of the instructions in the module, replacing them with
|
||||
// constants if we have found them to be of constant values.
|
||||
//
|
||||
SmallVector<Instruction*, 512> Insts;
|
||||
SmallVector<BasicBlock*, 512> BlocksToErase;
|
||||
std::map<Value*, LatticeVal> &Values = Solver.getValueMapping();
|
||||
|
||||
@ -1759,27 +1761,12 @@ bool IPSCCP::runOnModule(Module &M) {
|
||||
}
|
||||
}
|
||||
|
||||
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
|
||||
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
|
||||
if (!Solver.isBlockExecutable(BB)) {
|
||||
DEBUG(errs() << " BasicBlock Dead:" << *BB);
|
||||
++IPNumDeadBlocks;
|
||||
|
||||
// Delete the instructions backwards, as it has a reduced likelihood of
|
||||
// having to update as many def-use and use-def chains.
|
||||
TerminatorInst *TI = BB->getTerminator();
|
||||
for (BasicBlock::iterator I = BB->begin(), E = TI; I != E; ++I)
|
||||
Insts.push_back(I);
|
||||
|
||||
while (!Insts.empty()) {
|
||||
Instruction *I = Insts.back();
|
||||
Insts.pop_back();
|
||||
if (!I->use_empty())
|
||||
I->replaceAllUsesWith(UndefValue::get(I->getType()));
|
||||
BB->getInstList().erase(I);
|
||||
DeleteInstructionInBlock(BB);
|
||||
MadeChanges = true;
|
||||
++IPNumInstRemoved;
|
||||
}
|
||||
|
||||
TerminatorInst *TI = BB->getTerminator();
|
||||
for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i) {
|
||||
BasicBlock *Succ = TI->getSuccessor(i);
|
||||
if (!Succ->empty() && isa<PHINode>(Succ->begin()))
|
||||
@ -1787,14 +1774,15 @@ bool IPSCCP::runOnModule(Module &M) {
|
||||
}
|
||||
if (!TI->use_empty())
|
||||
TI->replaceAllUsesWith(UndefValue::get(TI->getType()));
|
||||
BB->getInstList().erase(TI);
|
||||
TI->eraseFromParent();
|
||||
|
||||
if (&*BB != &F->front())
|
||||
BlocksToErase.push_back(BB);
|
||||
else
|
||||
new UnreachableInst(M.getContext(), BB);
|
||||
continue;
|
||||
}
|
||||
|
||||
} else {
|
||||
for (BasicBlock::iterator BI = BB->begin(), E = BB->end(); BI != E; ) {
|
||||
Instruction *Inst = BI++;
|
||||
if (Inst->getType()->isVoidTy())
|
||||
|
Loading…
Reference in New Issue
Block a user