[llvm-commits] [llvm] r138890 - /llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
Duncan Sands
baldrick at free.fr
Thu Sep 1 00:03:39 PDT 2011
Hi Bill, why do you need a worklist? Basic blocks can be big, so pushing the
whole basic block into a worklist seems like a bad idea to me if it can be
avoided. Here I think you can get the same effect without a work list by
moving the iterator appropriately when you see a landingpad instruction.
Ciao, Duncan.
> Make sure we aren't deleting the landingpad instruction.
>
> The landingpad instruction is required in the landing pad block. Because we're
> not deleting terminating instructions, the invoke may still jump to here (see
> Transforms/SCCP/2004-11-16-DeadInvoke.ll). Remove all uses of the landingpad
> instruction, but keep it around until code-gen can remove the basic block.
>
> Modified:
> llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
>
> Modified: llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SCCP.cpp?rev=138890&r1=138889&r2=138890&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/SCCP.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/SCCP.cpp Wed Aug 31 15:55:20 2011
> @@ -1681,15 +1681,31 @@
> static void DeleteInstructionInBlock(BasicBlock *BB) {
> DEBUG(dbgs()<< " BasicBlock Dead:"<< *BB);
> ++NumDeadBlocks;
> -
> +
> + // Check to see if there are non-terminating instructions to delete.
> + if (isa<TerminatorInst>(BB->begin()))
> + return;
> +
> // 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());
> -
> + std::vector<Instruction*> WorkList;
> + WorkList.reserve(BB->size());
> + BasicBlock::iterator I = --BasicBlock::iterator(BB->getTerminator());
> +
> + while (true) {
> if (!I->use_empty())
> I->replaceAllUsesWith(UndefValue::get(I->getType()));
> - BB->getInstList().erase(I);
> + WorkList.push_back(I);
> + if (I == BB->begin())
> + break;
> + --I;
> + }
> +
> + for (std::vector<Instruction*>::iterator
> + II = WorkList.begin(), IE = WorkList.end(); II != IE; ++II) {
> + if (isa<LandingPadInst>(*II))
> + continue;
> + BB->getInstList().erase(*II);
> ++NumInstRemoved;
> }
> }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list