43class UnreachableBlockElimLegacyPass :
public FunctionPass {
50 UnreachableBlockElimLegacyPass() : FunctionPass(ID) {}
52 void getAnalysisUsage(AnalysisUsage &AU)
const override {
58char UnreachableBlockElimLegacyPass::ID = 0;
60 "Remove unreachable blocks from the CFG",
false,
false)
63 return new UnreachableBlockElimLegacyPass();
78class UnreachableMachineBlockElim {
87 : MDT(MDT), MPDT(MPDT), MLI(MLI) {}
92 bool runOnMachineFunction(MachineFunction &
F)
override;
93 void getAnalysisUsage(AnalysisUsage &AU)
const override;
97 UnreachableMachineBlockElimLegacy() : MachineFunctionPass(
ID) {}
101char UnreachableMachineBlockElimLegacy::ID = 0;
104 "unreachable-mbb-elimination",
105 "Remove unreachable machine basic blocks",
false,
false)
108 UnreachableMachineBlockElimLegacy::
ID;
110void UnreachableMachineBlockElimLegacy::getAnalysisUsage(
127 if (!UnreachableMachineBlockElim(MDT, MPDT, MLI).
run(MF))
132 .preserve<MachineDominatorTreeAnalysis>()
134 .preserve<MachineBlockFrequencyAnalysis>();
137bool UnreachableMachineBlockElimLegacy::runOnMachineFunction(
140 getAnalysisIfAvailable<MachineDominatorTreeWrapperPass>();
142 getAnalysisIfAvailable<MachinePostDominatorTreeWrapperPass>();
147 getAnalysisIfAvailable<MachineLoopInfoWrapperPass>();
150 return UnreachableMachineBlockElim(MDT, MPDT, MLI).run(MF);
155 bool ModifiedPHI =
false;
163 std::vector<MachineBasicBlock*> DeadBlocks;
166 if (!Reachable.count(&BB)) {
167 DeadBlocks.push_back(&BB);
172 if (MPDT && MPDT->
getNode(&BB))
175 while (!BB.succ_empty()) {
176 (*BB.succ_begin())->removePHIsIncomingValuesForPredecessor(BB);
177 BB.removeSuccessor(BB.succ_begin());
185 for (
auto &
I : BB->instrs())
186 if (
I.shouldUpdateAdditionalCallInfo())
187 BB->getParent()->eraseAdditionalCallInfo(&
I);
189 BB->eraseFromParent();
198 for (
unsigned i =
Phi.getNumOperands() - 1; i >= 2; i -= 2) {
199 if (!preds.count(
Phi.getOperand(i).getMBB())) {
200 Phi.removeOperand(i);
201 Phi.removeOperand(i - 1);
206 if (
Phi.getNumOperands() == 3) {
214 if (InputReg != OutputReg) {
227 BuildMI(BB, BB.getFirstNonPHI(),
Phi.getDebugLoc(),
228 TII->get(TargetOpcode::COPY), OutputReg)
231 Phi.eraseFromParent();
239 return (!DeadBlocks.empty() || ModifiedPHI);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file builds on the ADT/GraphTraits.h file to build generic depth first graph iterator.
static bool runOnFunction(Function &F, bool PostInlining)
const HexagonInstrInfo * TII
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file defines the SmallPtrSet class.
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
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.
void eraseNode(NodeT *BB)
eraseNode - Removes a node from the dominator tree.
DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
FunctionPass class - This class is used to implement most global optimizations.
void removeBlock(BlockT *BB)
This method completely removes BB from all data structures, including all of the Loop objects it is n...
Analysis pass which computes a MachineDominatorTree.
Analysis pass which computes a MachineDominatorTree.
MachineDominatorTree & getDomTree()
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
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, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
Analysis pass that exposes the MachineLoopInfo for a machine function.
MachineLoopInfo & getLI()
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
Register getReg() const
getReg - Returns the register number.
MachinePostDominatorTree & getPostDomTree()
MachinePostDominatorTree - an analysis pass wrapper for DominatorTree used to compute the post-domina...
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
LLVM_ABI 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...
LLVM_ABI void replaceRegWith(Register FromReg, Register ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
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.
PreservedAnalyses & preserve()
Mark an analysis as preserved.
Wrapper class representing virtual and physical registers.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
TargetInstrInfo - Interface to description of machine instruction set.
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
LLVM_ABI PreservedAnalyses run(MachineFunction &F, MachineFunctionAnalysisManager &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)
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
constexpr from_range_t from_range
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...
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
LLVM_ABI char & UnreachableMachineBlockElimID
UnreachableMachineBlockElimination - This pass removes unreachable machine basic blocks.
LLVM_ABI bool EliminateUnreachableBlocks(Function &F, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete all basic blocks from F that are not reachable from its entry node.
RegState getRegState(const MachineOperand &RegOp)
Get all register state flags from machine operand RegOp.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
LLVM_ABI FunctionPass * createUnreachableBlockEliminationPass()
createUnreachableBlockEliminationPass - The LLVM code generator does not work well with unreachable b...