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_begin() != BB.succ_end()) {
124 while (start != succ->
end() && start->isPHI()) {
125 for (
unsigned i = start->getNumOperands() - 1; i >= 2; i-=2)
126 if (start->getOperand(i).isMBB() &&
127 start->getOperand(i).getMBB() == &BB) {
128 start->removeOperand(i);
129 start->removeOperand(i-1);
135 BB.removeSuccessor(BB.succ_begin());
143 for (
auto &
I : BB->instrs())
144 if (
I.shouldUpdateCallSiteInfo())
145 BB->getParent()->eraseCallSiteInfo(&
I);
147 BB->eraseFromParent();
156 while (phi != BB.end() &&
phi->isPHI()) {
157 for (
unsigned i =
phi->getNumOperands() - 1; i >= 2; i-=2)
158 if (!preds.count(
phi->getOperand(i).getMBB())) {
159 phi->removeOperand(i);
160 phi->removeOperand(i-1);
164 if (
phi->getNumOperands() == 3) {
172 if (InputReg != OutputReg) {
176 MRI.constrainRegClass(InputReg,
MRI.getRegClass(OutputReg)) &&
178 MRI.replaceRegWith(OutputReg, InputReg);
185 BuildMI(BB, BB.getFirstNonPHI(),
phi->getDebugLoc(),
186 TII->get(TargetOpcode::COPY), OutputReg)
189 phi++->eraseFromParent();
200 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.
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.
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.
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.
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.