X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FCodeGen%2FUnreachableBlockElim.cpp;h=2e220820b9211d8c815a08f9663bd5dc3b0889bd;hb=285133714f0d995e0e14a77e23a0abe5dfc32d17;hp=c0d4494d5b950c3f81eb9892e5c160fd5804ecd5;hpb=fc6e69bcb2c8b9157164adfaa0c86115e7356cd0;p=oota-llvm.git diff --git a/lib/CodeGen/UnreachableBlockElim.cpp b/lib/CodeGen/UnreachableBlockElim.cpp index c0d4494d5b9..2e220820b92 100644 --- a/lib/CodeGen/UnreachableBlockElim.cpp +++ b/lib/CodeGen/UnreachableBlockElim.cpp @@ -21,62 +21,52 @@ //===----------------------------------------------------------------------===// #include "llvm/CodeGen/Passes.h" -#include "llvm/Constant.h" -#include "llvm/Instructions.h" -#include "llvm/Function.h" -#include "llvm/Pass.h" -#include "llvm/Type.h" -#include "llvm/Analysis/ProfileInfo.h" +#include "llvm/ADT/DepthFirstIterator.h" +#include "llvm/ADT/SmallPtrSet.h" #include "llvm/CodeGen/MachineDominators.h" #include "llvm/CodeGen/MachineFunctionPass.h" -#include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/CodeGen/MachineLoopInfo.h" +#include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/CodeGen/MachineRegisterInfo.h" -#include "llvm/Support/CFG.h" +#include "llvm/IR/CFG.h" +#include "llvm/IR/Constant.h" +#include "llvm/IR/Dominators.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/Instructions.h" +#include "llvm/IR/Type.h" +#include "llvm/Pass.h" #include "llvm/Target/TargetInstrInfo.h" -#include "llvm/ADT/DepthFirstIterator.h" -#include "llvm/ADT/SmallPtrSet.h" using namespace llvm; namespace { class UnreachableBlockElim : public FunctionPass { - virtual bool runOnFunction(Function &F); + bool runOnFunction(Function &F) override; public: static char ID; // Pass identification, replacement for typeid - UnreachableBlockElim() : FunctionPass(&ID) {} + UnreachableBlockElim() : FunctionPass(ID) { + initializeUnreachableBlockElimPass(*PassRegistry::getPassRegistry()); + } - virtual void getAnalysisUsage(AnalysisUsage &AU) const { - AU.addPreserved(); + void getAnalysisUsage(AnalysisUsage &AU) const override { + AU.addPreserved(); } }; } char UnreachableBlockElim::ID = 0; -static RegisterPass -X("unreachableblockelim", "Remove unreachable blocks from the CFG"); +INITIALIZE_PASS(UnreachableBlockElim, "unreachableblockelim", + "Remove unreachable blocks from the CFG", false, false) FunctionPass *llvm::createUnreachableBlockEliminationPass() { return new UnreachableBlockElim(); } -static void MarkReachableFrom(BasicBlock *BB, - SmallPtrSet &Reachable) { - for (df_ext_iterator > I = - df_ext_begin(BB, Reachable), E = df_ext_end(BB, Reachable); I != E; ++I) - ; // Mark all reachable blocks. -} - bool UnreachableBlockElim::runOnFunction(Function &F) { SmallPtrSet Reachable; // Mark all reachable blocks. - MarkReachableFrom(&F.getEntryBlock(), Reachable); - - // Mark any address-taken blocks. We don't want codegen to delete these - // because the address may already be referenced by another function and the - // label may be referenced. - for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) - if (I->hasAddressTaken() && !Reachable.count(I)) - MarkReachableFrom(I, Reachable); + for (df_ext_iterator > I = + df_ext_begin(&F, Reachable), E = df_ext_end(&F, Reachable); I != E; ++I) + /* Mark all reachable blocks */; // Loop over all dead blocks, remembering them and deleting all instructions // in them. @@ -95,9 +85,7 @@ bool UnreachableBlockElim::runOnFunction(Function &F) { } // Actually remove the blocks now. - ProfileInfo *PI = getAnalysisIfAvailable(); for (unsigned i = 0, e = DeadBlocks.size(); i != e; ++i) { - if (PI) PI->removeBlock(DeadBlocks[i]); DeadBlocks[i]->eraseFromParent(); } @@ -107,21 +95,20 @@ bool UnreachableBlockElim::runOnFunction(Function &F) { namespace { class UnreachableMachineBlockElim : public MachineFunctionPass { - virtual bool runOnMachineFunction(MachineFunction &F); - virtual void getAnalysisUsage(AnalysisUsage &AU) const; + bool runOnMachineFunction(MachineFunction &F) override; + void getAnalysisUsage(AnalysisUsage &AU) const override; MachineModuleInfo *MMI; public: static char ID; // Pass identification, replacement for typeid - UnreachableMachineBlockElim() : MachineFunctionPass(&ID) {} + UnreachableMachineBlockElim() : MachineFunctionPass(ID) {} }; } char UnreachableMachineBlockElim::ID = 0; -static RegisterPass -Y("unreachable-mbb-elimination", - "Remove unreachable machine basic blocks"); +INITIALIZE_PASS(UnreachableMachineBlockElim, "unreachable-mbb-elimination", + "Remove unreachable machine basic blocks", false, false) -const PassInfo *const llvm::UnreachableMachineBlockElimID = &Y; +char &llvm::UnreachableMachineBlockElimID = UnreachableMachineBlockElim::ID; void UnreachableMachineBlockElim::getAnalysisUsage(AnalysisUsage &AU) const { AU.addPreserved(); @@ -131,6 +118,7 @@ void UnreachableMachineBlockElim::getAnalysisUsage(AnalysisUsage &AU) const { bool UnreachableMachineBlockElim::runOnMachineFunction(MachineFunction &F) { SmallPtrSet Reachable; + bool ModifiedPHI = false; MMI = getAnalysisIfAvailable(); MachineDominatorTree *MDT = getAnalysisIfAvailable(); @@ -192,6 +180,7 @@ bool UnreachableMachineBlockElim::runOnMachineFunction(MachineFunction &F) { if (!preds.count(phi->getOperand(i).getMBB())) { phi->RemoveOperand(i); phi->RemoveOperand(i-1); + ModifiedPHI = true; } if (phi->getNumOperands() == 3) { @@ -201,9 +190,13 @@ bool UnreachableMachineBlockElim::runOnMachineFunction(MachineFunction &F) { MachineInstr* temp = phi; ++phi; temp->eraseFromParent(); + ModifiedPHI = true; - if (Input != Output) - F.getRegInfo().replaceRegWith(Output, Input); + if (Input != Output) { + MachineRegisterInfo &MRI = F.getRegInfo(); + MRI.constrainRegClass(Input, MRI.getRegClass(Output)); + MRI.replaceRegWith(Output, Input); + } continue; } @@ -214,5 +207,5 @@ bool UnreachableMachineBlockElim::runOnMachineFunction(MachineFunction &F) { F.RenumberBlocks(); - return DeadBlocks.size(); + return (DeadBlocks.size() || ModifiedPHI); }