57 "Remove unreachable blocks from the CFG",
false,
false)
60 return new UnreachableBlockElim();
63 bool UnreachableBlockElim::runOnFunction(
Function &
F) {
73 std::vector<BasicBlock*> DeadBlocks;
77 DeadBlocks.push_back(BB);
83 (*SI)->removePredecessor(BB);
88 for (
unsigned i = 0, e = DeadBlocks.size(); i != e; ++i) {
89 DeadBlocks[i]->eraseFromParent();
92 return DeadBlocks.size();
108 INITIALIZE_PASS(UnreachableMachineBlockElim,
"unreachable-mbb-elimination",
109 "Remove unreachable machine basic blocks",
false,
false)
113 void UnreachableMachineBlockElim::getAnalysisUsage(
AnalysisUsage &AU)
const {
119 bool UnreachableMachineBlockElim::runOnMachineFunction(
MachineFunction &F) {
121 bool ModifiedPHI =
false;
123 MMI = getAnalysisIfAvailable<MachineModuleInfo>();
135 std::vector<MachineBasicBlock*> DeadBlocks;
140 if (!Reachable.
count(BB)) {
141 DeadBlocks.push_back(BB);
144 if (MLI) MLI->removeBlock(BB);
145 if (MDT && MDT->getNode(BB)) MDT->eraseNode(BB);
151 while (start != succ->
end() && start->isPHI()) {
152 for (
unsigned i = start->getNumOperands() - 1; i >= 2; i-=2)
153 if (start->getOperand(i).isMBB() &&
154 start->getOperand(i).getMBB() == BB) {
155 start->RemoveOperand(i);
156 start->RemoveOperand(i-1);
168 for (
unsigned i = 0, e = DeadBlocks.size(); i != e; ++i)
169 DeadBlocks[i]->eraseFromParent();
178 while (phi != BB->
end() && phi->isPHI()) {
179 for (
unsigned i = phi->getNumOperands() - 1; i >= 2; i-=2)
180 if (!preds.count(phi->getOperand(i).getMBB())) {
181 phi->RemoveOperand(i);
182 phi->RemoveOperand(i-1);
186 if (phi->getNumOperands() == 3) {
187 unsigned Input = phi->getOperand(1).getReg();
188 unsigned Output = phi->getOperand(0).getReg();
195 if (Input != Output) {
210 return (DeadBlocks.size() || ModifiedPHI);
AnalysisUsage & addPreserved()
static PassRegistry * getPassRegistry()
static Constant * getNullValue(Type *Ty)
const TargetRegisterClass * getRegClass(unsigned Reg) const
ID
LLVM Calling Convention Representation.
Interval::succ_iterator succ_begin(Interval *I)
char & UnreachableMachineBlockElimID
bool count(PtrType Ptr) const
count - Return true if the specified pointer is in the set.
void RenumberBlocks(MachineBasicBlock *MBBFrom=0)
FunctionPass * createUnreachableBlockEliminationPass()
const TargetRegisterClass * constrainRegClass(unsigned Reg, const TargetRegisterClass *RC, unsigned MinNumRegs=0)
Interval::succ_iterator succ_end(Interval *I)
bundle_iterator< MachineInstr, instr_iterator > iterator
LLVM Basic Block Representation.
df_ext_iterator< T, SetTy > df_ext_end(const T &G, SetTy &S)
df_ext_iterator< T, SetTy > df_ext_begin(const T &G, SetTy &S)
const InstListType & getInstList() const
Return the underlying instruction list container.
void initializeUnreachableBlockElimPass(PassRegistry &)
succ_iterator succ_begin()
void removeSuccessor(MachineBasicBlock *succ)
pred_iterator pred_begin()
INITIALIZE_PASS(UnreachableBlockElim,"unreachableblockelim","Remove unreachable blocks from the CFG", false, false) FunctionPass *llvm
void replaceRegWith(unsigned FromReg, unsigned ToReg)
MachineRegisterInfo & getRegInfo()
virtual void getAnalysisUsage(AnalysisUsage &AU) const
BasicBlockListType::iterator iterator
const MCRegisterInfo & MRI
void dropAllReferences()
Cause all subinstructions to "let go" of all the references that said subinstructions are maintaining...