57 "Remove unreachable blocks from the CFG",
false,
false)
60 return new UnreachableBlockElim();
63 bool UnreachableBlockElim::runOnFunction(
Function &
F) {
72 std::vector<BasicBlock*> DeadBlocks;
76 DeadBlocks.push_back(BB);
82 (*SI)->removePredecessor(BB);
87 for (
unsigned i = 0, e = DeadBlocks.size(); i != e; ++i) {
88 DeadBlocks[i]->eraseFromParent();
91 return !DeadBlocks.empty();
107 INITIALIZE_PASS(UnreachableMachineBlockElim,
"unreachable-mbb-elimination",
108 "Remove unreachable machine basic blocks",
false,
false)
112 void UnreachableMachineBlockElim::getAnalysisUsage(
AnalysisUsage &AU)
const {
118 bool UnreachableMachineBlockElim::runOnMachineFunction(
MachineFunction &F) {
120 bool ModifiedPHI =
false;
122 MMI = getAnalysisIfAvailable<MachineModuleInfo>();
132 std::vector<MachineBasicBlock*> DeadBlocks;
137 if (!Reachable.
count(BB)) {
138 DeadBlocks.push_back(BB);
141 if (MLI) MLI->removeBlock(BB);
142 if (MDT && MDT->getNode(BB)) MDT->eraseNode(BB);
148 while (start != succ->
end() && start->isPHI()) {
149 for (
unsigned i = start->getNumOperands() - 1; i >= 2; i-=2)
150 if (start->getOperand(i).isMBB() &&
151 start->getOperand(i).getMBB() == BB) {
152 start->RemoveOperand(i);
153 start->RemoveOperand(i-1);
165 for (
unsigned i = 0, e = DeadBlocks.size(); i != e; ++i)
166 DeadBlocks[i]->eraseFromParent();
175 while (phi != BB->
end() && phi->isPHI()) {
176 for (
unsigned i = phi->getNumOperands() - 1; i >= 2; i-=2)
177 if (!preds.count(phi->getOperand(i).getMBB())) {
178 phi->RemoveOperand(i);
179 phi->RemoveOperand(i-1);
183 if (phi->getNumOperands() == 3) {
184 unsigned Input = phi->getOperand(1).getReg();
185 unsigned Output = phi->getOperand(0).getReg();
192 if (Input != Output) {
207 return (!DeadBlocks.empty() || ModifiedPHI);
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
void RenumberBlocks(MachineBasicBlock *MBBFrom=nullptr)
RenumberBlocks - This discards all of the MachineBasicBlock numbers and recomputes them...
size_type count(PtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
static Constant * getNullValue(Type *Ty)
iterator begin()
Instruction iterator methods.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
const TargetRegisterClass * getRegClass(unsigned Reg) const
getRegClass - Return the register class of the specified virtual register.
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
char & UnreachableMachineBlockElimID
UnreachableMachineBlockElimination - This pass removes unreachable machine basic blocks.
FunctionPass * createUnreachableBlockEliminationPass()
createUnreachableBlockEliminationPass - The LLVM code generator does not work well with unreachable b...
const TargetRegisterClass * constrainRegClass(unsigned Reg, const TargetRegisterClass *RC, unsigned MinNumRegs=0)
constrainRegClass - Constrain the register class of the specified virtual register to be a common sub...
Interval::succ_iterator succ_end(Interval *I)
bundle_iterator< MachineInstr, instr_iterator > iterator
LLVM Basic Block Representation.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
iterator_range< df_ext_iterator< T, SetTy > > depth_first_ext(const T &G, SetTy &S)
Represent the analysis usage information of a pass.
const InstListType & getInstList() const
Return the underlying instruction list container.
void initializeUnreachableBlockElimPass(PassRegistry &)
FunctionPass class - This class is used to implement most global optimizations.
succ_iterator succ_begin()
void removeSuccessor(MachineBasicBlock *succ)
removeSuccessor - Remove successor from the successors list of this MachineBasicBlock.
pred_iterator pred_begin()
INITIALIZE_PASS(UnreachableBlockElim,"unreachableblockelim","Remove unreachable blocks from the CFG", false, false) FunctionPass *llvm
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
void replaceRegWith(unsigned FromReg, unsigned ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
BasicBlockListType::iterator iterator
Legacy analysis pass which computes a DominatorTree.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
void dropAllReferences()
Cause all subinstructions to "let go" of all the references that said subinstructions are maintaining...
MachineModuleInfo - This class contains meta information specific to a module.