39class UnreachableBlockElimLegacyPass :
public FunctionPass {
56char UnreachableBlockElimLegacyPass::ID = 0;
58 "Remove unreachable blocks from the CFG",
false,
false)
61 return new UnreachableBlockElimLegacyPass();
84char UnreachableMachineBlockElim::ID = 0;
86INITIALIZE_PASS(UnreachableMachineBlockElim,
"unreachable-mbb-elimination",
87 "Remove unreachable machine basic blocks",
false,
false)
91void UnreachableMachineBlockElim::getAnalysisUsage(
AnalysisUsage &AU)
const {
99 bool ModifiedPHI =
false;
102 getAnalysisIfAvailable<MachineDominatorTreeWrapperPass>();
105 getAnalysisIfAvailable<MachineLoopInfoWrapperPass>();
114 std::vector<MachineBasicBlock*> DeadBlocks;
117 if (!Reachable.
count(&BB)) {
118 DeadBlocks.push_back(&BB);
124 while (!BB.succ_empty()) {
128 for (
unsigned i =
Phi.getNumOperands() - 1; i >= 2; i -= 2) {
129 if (
Phi.getOperand(i).isMBB() &&
130 Phi.getOperand(i).getMBB() == &BB) {
131 Phi.removeOperand(i);
132 Phi.removeOperand(i - 1);
137 BB.removeSuccessor(BB.succ_begin());
145 for (
auto &
I : BB->instrs())
146 if (
I.shouldUpdateCallSiteInfo())
147 BB->getParent()->eraseCallSiteInfo(&
I);
149 BB->eraseFromParent();
158 for (
unsigned i =
Phi.getNumOperands() - 1; i >= 2; i -= 2) {
159 if (!preds.count(
Phi.getOperand(i).getMBB())) {
160 Phi.removeOperand(i);
161 Phi.removeOperand(i - 1);
166 if (
Phi.getNumOperands() == 3) {
174 if (InputReg != OutputReg) {
178 MRI.constrainRegClass(InputReg,
MRI.getRegClass(OutputReg)) &&
180 MRI.replaceRegWith(OutputReg, InputReg);
187 BuildMI(BB, BB.getFirstNonPHI(),
Phi.getDebugLoc(),
188 TII->get(TargetOpcode::COPY), OutputReg)
191 Phi.eraseFromParent();
201 return (!DeadBlocks.empty() || ModifiedPHI);
unsigned const MachineRegisterInfo * MRI
This file builds on the ADT/GraphTraits.h file to build generic depth first graph iterator.
const HexagonInstrInfo * TII
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallPtrSet class.
A container for analyses that lazily runs them and caches their results.
Represent the analysis usage information of a pass.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
Analysis pass which computes a DominatorTree.
std::enable_if_t< GraphHasNodeNumbers< T * >, void > updateBlockNumbers()
Update dominator tree after renumbering blocks.
Legacy analysis pass which computes a DominatorTree.
FunctionPass class - This class is used to implement most global optimizations.
virtual bool runOnFunction(Function &F)=0
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
void removeBlock(BlockT *BB)
This method completely removes BB from all data structures, including all of the Loop objects it is n...
iterator_range< iterator > phis()
Returns a range that iterates over the phis in the basic block.
succ_iterator succ_begin()
Analysis pass which computes a MachineDominatorTree.
MachineDominatorTree & getDomTree()
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
MachineDomTreeNode * getNode(MachineBasicBlock *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
void eraseNode(MachineBasicBlock *BB)
eraseNode - Removes a node from the dominator tree.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
MachineLoopInfo & getLI()
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void preserve()
Mark an analysis as preserved.
Wrapper class representing virtual and physical registers.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
TargetInstrInfo - Interface to description of machine instruction set.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
NodeAddr< PhiNode * > Phi
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< df_ext_iterator< T, SetTy > > depth_first_ext(const T &G, SetTy &S)
FunctionPass * createUnreachableBlockEliminationPass()
createUnreachableBlockEliminationPass - The LLVM code generator does not work well with unreachable b...
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
void initializeUnreachableBlockElimLegacyPassPass(PassRegistry &)
bool EliminateUnreachableBlocks(Function &F, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete all basic blocks from F that are not reachable from its entry node.
unsigned getRegState(const MachineOperand &RegOp)
Get all register state flags from machine operand RegOp.
char & UnreachableMachineBlockElimID
UnreachableMachineBlockElimination - This pass removes unreachable machine basic blocks.