52 std::vector<BasicBlock*> DeadBlocks;
54 if (!Reachable.
count(&*
I)) {
56 DeadBlocks.push_back(BB);
62 (*SI)->removePredecessor(BB);
67 for (
unsigned i = 0, e = DeadBlocks.size(); i != e; ++i) {
68 DeadBlocks[i]->eraseFromParent();
71 return !DeadBlocks.empty();
75 class UnreachableBlockElimLegacyPass :
public FunctionPass {
94 "Remove unreachable blocks from the CFG",
false,
false)
97 return new UnreachableBlockElimLegacyPass();
122 INITIALIZE_PASS(UnreachableMachineBlockElim,
"unreachable-mbb-elimination",
123 "Remove unreachable machine basic blocks",
false,
false)
127 void UnreachableMachineBlockElim::getAnalysisUsage(
AnalysisUsage &AU)
const {
133 bool UnreachableMachineBlockElim::runOnMachineFunction(
MachineFunction &
F) {
135 bool ModifiedPHI =
false;
137 MMI = getAnalysisIfAvailable<MachineModuleInfo>();
147 std::vector<MachineBasicBlock*> DeadBlocks;
152 if (!Reachable.
count(BB)) {
153 DeadBlocks.push_back(BB);
156 if (MLI) MLI->removeBlock(BB);
157 if (MDT && MDT->getNode(BB)) MDT->eraseNode(BB);
163 while (start != succ->
end() && start->isPHI()) {
164 for (
unsigned i = start->getNumOperands() - 1; i >= 2; i-=2)
165 if (start->getOperand(i).isMBB() &&
166 start->getOperand(i).getMBB() == BB) {
167 start->RemoveOperand(i);
168 start->RemoveOperand(i-1);
180 for (
unsigned i = 0, e = DeadBlocks.size(); i != e; ++i)
181 DeadBlocks[i]->eraseFromParent();
190 while (phi != BB->
end() && phi->isPHI()) {
191 for (
unsigned i = phi->getNumOperands() - 1; i >= 2; i-=2)
192 if (!preds.count(phi->getOperand(i).getMBB())) {
193 phi->RemoveOperand(i);
194 phi->RemoveOperand(i-1);
198 if (phi->getNumOperands() == 3) {
201 unsigned InputReg = Input.
getReg();
202 unsigned OutputReg = Output.
getReg();
206 if (InputReg != OutputReg) {
220 TII->
get(TargetOpcode::COPY), OutputReg)
223 phi++->eraseFromParent();
234 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...
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
unsigned getRegState(const MachineOperand &RegOp)
Get all register state flags from machine operand RegOp.
This class represents lattice values for constants.
void RenumberBlocks(MachineBasicBlock *MBBFrom=nullptr)
RenumberBlocks - This discards all of the MachineBasicBlock numbers and recomputes them...
unsigned getReg() const
getReg - Returns the register number.
unsigned getSubReg() const
Analysis pass which computes a DominatorTree.
void initializeUnreachableBlockElimLegacyPassPass(PassRegistry &)
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
iterator begin()
Instruction iterator methods.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
static bool eliminateUnreachableBlock(Function &F)
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...
virtual const TargetInstrInfo * getInstrInfo() const
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)
TargetInstrInfo - Interface to description of machine instruction set.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
static bool runOnFunction(Function &F, bool PostInlining)
A set of analyses that are preserved following a run of a transformation pass.
unsigned const MachineRegisterInfo * MRI
LLVM Basic Block Representation.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
iterator_range< df_ext_iterator< T, SetTy > > depth_first_ext(const T &G, SetTy &S)
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
succ_iterator succ_begin()
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
pred_iterator pred_begin()
const InstListType & getInstList() const
Return the underlying instruction list container.
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
MachineOperand class - Representation of each machine instruction operand.
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.
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
void preserve()
Mark an analysis as preserved.
iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
void removeSuccessor(MachineBasicBlock *Succ, bool NormalizeSuccProbs=false)
Remove successor from the successors list of this MachineBasicBlock.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A container for analyses that lazily runs them and caches their results.
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...
INITIALIZE_PASS(UnreachableBlockElimLegacyPass, "unreachableblockelim", "Remove unreachable blocks from the CFG", false, false) FunctionPass *llvm
This class contains meta information specific to a module.