Go to the documentation of this file.
39 class UnreachableBlockElimLegacyPass :
public FunctionPass {
58 "Remove unreachable blocks from the CFG",
false,
false)
61 return new UnreachableBlockElimLegacyPass();
86 INITIALIZE_PASS(UnreachableMachineBlockElim,
"unreachable-mbb-elimination",
87 "Remove unreachable machine basic blocks",
false,
false)
91 void UnreachableMachineBlockElim::getAnalysisUsage(
AnalysisUsage &AU)
const {
99 bool ModifiedPHI =
false;
110 std::vector<MachineBasicBlock*> DeadBlocks;
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) {
169 assert(
Output.getSubReg() == 0 &&
"Cannot have output subregister");
172 if (InputReg != OutputReg) {
174 unsigned InputSub =
Input.getSubReg();
186 TII->get(TargetOpcode::COPY), OutputReg)
189 phi++->eraseFromParent();
200 return (!DeadBlocks.empty() || ModifiedPHI);
A set of analyses that are preserved following a run of a transformation pass.
This is an optimization pass for GlobalISel generic memory operations.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
FunctionPass * createUnreachableBlockEliminationPass()
createUnreachableBlockEliminationPass - The LLVM code generator does not work well with unreachable b...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
TargetInstrInfo - Interface to description of machine instruction set.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Represent the analysis usage information of a pass.
const HexagonInstrInfo * TII
MachineOperand class - Representation of each machine instruction operand.
iterator_range< df_ext_iterator< T, SetTy > > depth_first_ext(const T &G, SetTy &S)
Legacy analysis pass which computes a DominatorTree.
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 ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
unsigned getRegState(const MachineOperand &RegOp)
Get all register state flags from machine operand RegOp.
void preserve()
Mark an analysis as preserved.
MachineDomTreeNode * getNode(MachineBasicBlock *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
void eraseNode(MachineBasicBlock *BB)
eraseNode - Removes a node from the dominator tree.
char & UnreachableMachineBlockElimID
UnreachableMachineBlockElimination - This pass removes unreachable machine basic blocks.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
unsigned const MachineRegisterInfo * MRI
Wrapper class representing virtual and physical registers.
void replaceRegWith(Register FromReg, Register ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
static bool runOnFunction(Function &F, bool PostInlining)
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Analysis pass which computes a DominatorTree.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
void removeBlock(MachineBasicBlock *BB)
This method completely removes BB from all data structures, including all of the Loop objects it is n...
INITIALIZE_PASS(UnreachableBlockElimLegacyPass, "unreachableblockelim", "Remove unreachable blocks from the CFG", false, false) FunctionPass *llvm
const TargetRegisterClass * constrainRegClass(Register Reg, const TargetRegisterClass *RC, unsigned MinNumRegs=0)
constrainRegClass - Constrain the register class of the specified virtual register to be a common sub...
A container for analyses that lazily runs them and caches their results.
FunctionPass class - This class is used to implement most global optimizations.
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
void initializeUnreachableBlockElimLegacyPassPass(PassRegistry &)