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;
110 std::vector<MachineBasicBlock*> DeadBlocks;
113 if (!Reachable.
count(&BB)) {
114 DeadBlocks.push_back(&BB);
120 while (!BB.succ_empty()) {
124 for (
unsigned i =
Phi.getNumOperands() - 1; i >= 2; i -= 2) {
125 if (
Phi.getOperand(i).isMBB() &&
126 Phi.getOperand(i).getMBB() == &BB) {
127 Phi.removeOperand(i);
128 Phi.removeOperand(i - 1);
133 BB.removeSuccessor(BB.succ_begin());
141 for (
auto &
I : BB->instrs())
142 if (
I.shouldUpdateCallSiteInfo())
143 BB->getParent()->eraseCallSiteInfo(&
I);
145 BB->eraseFromParent();
154 for (
unsigned i =
Phi.getNumOperands() - 1; i >= 2; i -= 2) {
155 if (!preds.count(
Phi.getOperand(i).getMBB())) {
156 Phi.removeOperand(i);
157 Phi.removeOperand(i - 1);
162 if (
Phi.getNumOperands() == 3) {
170 if (InputReg != OutputReg) {
174 MRI.constrainRegClass(InputReg,
MRI.getRegClass(OutputReg)) &&
176 MRI.replaceRegWith(OutputReg, InputReg);
183 BuildMI(BB, BB.getFirstNonPHI(),
Phi.getDebugLoc(),
184 TII->get(TargetOpcode::COPY), OutputReg)
187 Phi.eraseFromParent();
195 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.
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.
iterator_range< iterator > phis()
Returns a range that iterates over the phis in the basic block.
succ_iterator succ_begin()
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.
void removeBlock(MachineBasicBlock *BB)
This method completely removes BB from all data structures, including all of the Loop objects it is n...
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.