45 class UnreachableBlockElimLegacyPass :
public FunctionPass {
64 "Remove unreachable blocks from the CFG",
false,
false)
67 return new UnreachableBlockElimLegacyPass();
92 INITIALIZE_PASS(UnreachableMachineBlockElim,
"unreachable-mbb-elimination",
93 "Remove unreachable machine basic blocks",
false,
false)
97 void UnreachableMachineBlockElim::getAnalysisUsage(
AnalysisUsage &AU)
const {
103 bool UnreachableMachineBlockElim::runOnMachineFunction(
MachineFunction &
F) {
105 bool ModifiedPHI =
false;
107 auto *MMIWP = getAnalysisIfAvailable<MachineModuleInfoWrapperPass>();
108 MMI = MMIWP ? &MMIWP->getMMI() :
nullptr;
118 std::vector<MachineBasicBlock*> DeadBlocks;
123 if (!Reachable.
count(BB)) {
124 DeadBlocks.push_back(BB);
127 if (MLI) MLI->removeBlock(BB);
134 while (start != succ->
end() && start->isPHI()) {
135 for (
unsigned i = start->getNumOperands() - 1; i >= 2; i-=2)
136 if (start->getOperand(i).isMBB() &&
137 start->getOperand(i).getMBB() == BB) {
138 start->RemoveOperand(i);
139 start->RemoveOperand(i-1);
151 for (
unsigned i = 0,
e = DeadBlocks.size(); i !=
e; ++i) {
153 for (
auto &
I : DeadBlocks[i]->instrs())
155 DeadBlocks[i]->
getParent()->eraseCallSiteInfo(&
I);
167 while (phi != BB->
end() && phi->isPHI()) {
168 for (
unsigned i = phi->getNumOperands() - 1; i >= 2; i-=2)
169 if (!preds.count(phi->getOperand(i).getMBB())) {
170 phi->RemoveOperand(i);
171 phi->RemoveOperand(i-1);
175 if (phi->getNumOperands() == 3) {
183 if (InputReg != OutputReg) {
197 TII->
get(TargetOpcode::COPY), OutputReg)
200 phi++->eraseFromParent();
211 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...
MachineDomTreeNode * getNode(MachineBasicBlock *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
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 getSubReg() const
Analysis pass which computes a DominatorTree.
void initializeUnreachableBlockElimLegacyPassPass(PassRegistry &)
void eraseNode(MachineBasicBlock *BB)
eraseNode - Removes a node from the dominator tree.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
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...
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
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()
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.
bool EliminateUnreachableBlocks(Function &F, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete all basic blocks from F that are not reachable from its entry node.
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.
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
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())
static const Function * getParent(const Value *V)
A container for analyses that lazily runs them and caches their results.
Legacy analysis pass which computes a DominatorTree.
Register getReg() const
getReg - Returns the register number.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
Wrapper class representing virtual and physical registers.
INITIALIZE_PASS(UnreachableBlockElimLegacyPass, "unreachableblockelim", "Remove unreachable blocks from the CFG", false, false) FunctionPass *llvm
This class contains meta information specific to a module.