40class UnreachableBlockElimLegacyPass :
public FunctionPass {
47 UnreachableBlockElimLegacyPass() : FunctionPass(ID) {
52 void getAnalysisUsage(AnalysisUsage &AU)
const override {
57char UnreachableBlockElimLegacyPass::ID = 0;
59 "Remove unreachable blocks from the CFG",
false,
false)
62 return new UnreachableBlockElimLegacyPass();
76class UnreachableMachineBlockElim {
82 : MDT(MDT), MLI(MLI) {}
87 bool runOnMachineFunction(MachineFunction &
F)
override;
88 void getAnalysisUsage(AnalysisUsage &AU)
const override;
92 UnreachableMachineBlockElimLegacy() : MachineFunctionPass(
ID) {}
96char UnreachableMachineBlockElimLegacy::ID = 0;
99 "unreachable-mbb-elimination",
100 "Remove unreachable machine basic blocks",
false,
false)
103 UnreachableMachineBlockElimLegacy::
ID;
105void UnreachableMachineBlockElimLegacy::getAnalysisUsage(
118 if (!UnreachableMachineBlockElim(MDT, MLI).
run(MF))
123 .preserve<MachineDominatorTreeAnalysis>();
126bool UnreachableMachineBlockElimLegacy::runOnMachineFunction(
129 getAnalysisIfAvailable<MachineDominatorTreeWrapperPass>();
132 getAnalysisIfAvailable<MachineLoopInfoWrapperPass>();
135 return UnreachableMachineBlockElim(MDT, MLI).run(MF);
140 bool ModifiedPHI =
false;
148 std::vector<MachineBasicBlock*> DeadBlocks;
151 if (!Reachable.count(&BB)) {
152 DeadBlocks.push_back(&BB);
158 while (!BB.succ_empty()) {
159 (*BB.succ_begin())->removePHIsIncomingValuesForPredecessor(BB);
160 BB.removeSuccessor(BB.succ_begin());
168 for (
auto &
I : BB->instrs())
169 if (
I.shouldUpdateAdditionalCallInfo())
170 BB->getParent()->eraseAdditionalCallInfo(&
I);
172 BB->eraseFromParent();
181 for (
unsigned i =
Phi.getNumOperands() - 1; i >= 2; i -= 2) {
182 if (!preds.count(
Phi.getOperand(i).getMBB())) {
183 Phi.removeOperand(i);
184 Phi.removeOperand(i - 1);
189 if (
Phi.getNumOperands() == 3) {
197 if (InputReg != OutputReg) {
201 MRI.constrainRegClass(InputReg,
MRI.getRegClass(OutputReg)) &&
203 MRI.replaceRegWith(OutputReg, InputReg);
210 BuildMI(BB, BB.getFirstNonPHI(),
Phi.getDebugLoc(),
211 TII->get(TargetOpcode::COPY), OutputReg)
214 Phi.eraseFromParent();
224 return (!DeadBlocks.empty() || ModifiedPHI);
unsigned const MachineRegisterInfo * MRI
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.
std::enable_if_t< GraphHasNodeNumbers< T * >, void > updateBlockNumbers()
Update dominator tree after renumbering blocks.
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, unsigned flags=0, 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.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
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.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
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 void initializeUnreachableBlockElimLegacyPassPass(PassRegistry &)
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.
unsigned 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...