forked from OSchip/llvm-project
[SCCP] Remove duplicate code
SCCP has code identical to changeToUnreachable's behavior, switch it over to just call changeToUnreachable. No functionality change intended. llvm-svn: 258654
This commit is contained in:
parent
35c46d3e0b
commit
88542a0a69
|
@ -295,7 +295,7 @@ unsigned removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB);
|
|||
|
||||
/// \brief Insert an unreachable instruction before the specified
|
||||
/// instruction, making it and the rest of the code in the block dead.
|
||||
void changeToUnreachable(Instruction *I, bool UseLLVMTrap);
|
||||
unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap);
|
||||
|
||||
/// Replace 'BB's terminator with one that does not have an unwind successor
|
||||
/// block. Rewrites `invoke` to `call`, etc. Updates any PHIs in unwind
|
||||
|
|
|
@ -1564,14 +1564,6 @@ FunctionPass *llvm::createSCCPPass() {
|
|||
return new SCCP();
|
||||
}
|
||||
|
||||
static void DeleteInstructionInBlock(BasicBlock *BB) {
|
||||
DEBUG(dbgs() << " BasicBlock Dead:" << *BB);
|
||||
++NumDeadBlocks;
|
||||
|
||||
unsigned NumRemovedInBB = removeAllNonTerminatorAndEHPadInstructions(BB);
|
||||
NumInstRemoved += NumRemovedInBB;
|
||||
}
|
||||
|
||||
// runOnFunction() - Run the Sparse Conditional Constant Propagation algorithm,
|
||||
// and return true if the function was modified.
|
||||
//
|
||||
|
@ -1608,7 +1600,11 @@ bool SCCP::runOnFunction(Function &F) {
|
|||
|
||||
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
|
||||
if (!Solver.isBlockExecutable(&*BB)) {
|
||||
DeleteInstructionInBlock(&*BB);
|
||||
DEBUG(dbgs() << " BasicBlock Dead:" << *BB);
|
||||
|
||||
++NumDeadBlocks;
|
||||
NumInstRemoved += removeAllNonTerminatorAndEHPadInstructions(BB);
|
||||
|
||||
MadeChanges = true;
|
||||
continue;
|
||||
}
|
||||
|
@ -1806,18 +1802,13 @@ bool IPSCCP::runOnModule(Module &M) {
|
|||
|
||||
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
|
||||
if (!Solver.isBlockExecutable(&*BB)) {
|
||||
DeleteInstructionInBlock(&*BB);
|
||||
MadeChanges = true;
|
||||
DEBUG(dbgs() << " BasicBlock Dead:" << *BB);
|
||||
|
||||
TerminatorInst *TI = BB->getTerminator();
|
||||
for (BasicBlock *Succ : TI->successors()) {
|
||||
if (!Succ->empty() && isa<PHINode>(Succ->begin()))
|
||||
Succ->removePredecessor(&*BB);
|
||||
}
|
||||
if (!TI->use_empty())
|
||||
TI->replaceAllUsesWith(UndefValue::get(TI->getType()));
|
||||
TI->eraseFromParent();
|
||||
new UnreachableInst(M.getContext(), &*BB);
|
||||
++NumDeadBlocks;
|
||||
NumInstRemoved +=
|
||||
changeToUnreachable(&*BB->begin(), /*UseLLVMTrap=*/false);
|
||||
|
||||
MadeChanges = true;
|
||||
|
||||
if (&*BB != &F->front())
|
||||
BlocksToErase.push_back(&*BB);
|
||||
|
|
|
@ -1243,7 +1243,7 @@ unsigned llvm::removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB) {
|
|||
return NumDeadInst;
|
||||
}
|
||||
|
||||
void llvm::changeToUnreachable(Instruction *I, bool UseLLVMTrap) {
|
||||
unsigned llvm::changeToUnreachable(Instruction *I, bool UseLLVMTrap) {
|
||||
BasicBlock *BB = I->getParent();
|
||||
// Loop over all of the successors, removing BB's entry from any PHI
|
||||
// nodes.
|
||||
|
@ -1261,12 +1261,15 @@ void llvm::changeToUnreachable(Instruction *I, bool UseLLVMTrap) {
|
|||
new UnreachableInst(I->getContext(), I);
|
||||
|
||||
// All instructions after this are dead.
|
||||
unsigned NumInstrsRemoved = 0;
|
||||
BasicBlock::iterator BBI = I->getIterator(), BBE = BB->end();
|
||||
while (BBI != BBE) {
|
||||
if (!BBI->use_empty())
|
||||
BBI->replaceAllUsesWith(UndefValue::get(BBI->getType()));
|
||||
BB->getInstList().erase(BBI++);
|
||||
++NumInstrsRemoved;
|
||||
}
|
||||
return NumInstrsRemoved;
|
||||
}
|
||||
|
||||
/// changeToCall - Convert the specified invoke into a normal call.
|
||||
|
|
Loading…
Reference in New Issue