Go to the documentation of this file.
35 #define DEBUG_TYPE "ppc-early-ret"
36 STATISTIC(NumBCLR,
"Number of early conditional returns");
37 STATISTIC(NumBLR,
"Number of early returns");
59 if (
I == ReturnMBB.
end() ||
60 (
I->getOpcode() != PPC::BLR &&
I->getOpcode() != PPC::BLR8) ||
66 bool OtherReference =
false, BlockChanged =
false;
75 if (J->getOpcode() ==
PPC::B) {
76 if (J->getOperand(0).getMBB() == &ReturnMBB) {
88 }
else if (J->getOpcode() == PPC::BCC) {
89 if (J->getOperand(2).getMBB() == &ReturnMBB) {
93 MI->setDesc(
TII->get(PPC::BCCLR));
95 .
add(J->getOperand(0))
96 .
add(J->getOperand(1));
100 K->eraseFromParent();
105 }
else if (J->getOpcode() == PPC::BC || J->getOpcode() == PPC::BCn) {
106 if (J->getOperand(1).getMBB() == &ReturnMBB) {
111 TII->get(J->getOpcode() == PPC::BC ? PPC::BCLR : PPC::BCLRn));
113 .
add(J->getOperand(0));
117 K->eraseFromParent();
122 }
else if (J->isBranch()) {
123 if (J->isIndirectBranch()) {
125 OtherReference =
true;
127 for (
unsigned i = 0;
i < J->getNumOperands(); ++
i)
128 if (J->getOperand(
i).isMBB() &&
129 J->getOperand(
i).getMBB() == &ReturnMBB)
130 OtherReference =
true;
131 }
else if (!J->isTerminator() && !J->isDebugInstr())
134 if (J == Pred->begin())
140 if (Pred->canFallThrough() && Pred->isLayoutSuccessor(&ReturnMBB))
141 OtherReference =
true;
144 if (!OtherReference && BlockChanged) {
145 PredToRemove.push_back(Pred);
152 for (
unsigned i = 0, ie = PredToRemove.size();
i != ie; ++
i)
153 PredToRemove[
i]->removeSuccessor(&ReturnMBB,
true);
181 bool Changed =
false;
189 Changed |= processBlock(
B);
206 "PowerPC Early-Return Creation",
false,
false)
208 char PPCEarlyReturn::
ID = 0;
pred_iterator pred_begin()
This is an optimization pass for GlobalISel generic memory operations.
const MachineInstrBuilder & add(const MachineOperand &MO) const
virtual const TargetInstrInfo * getInstrInfo() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Properties which a MachineFunction may have at a given point in time.
FunctionPass * createPPCEarlyReturnPass()
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
unsigned pred_size() const
TargetInstrInfo - Interface to description of machine instruction set.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
void eraseFromParent()
This method unlinks 'this' from the containing function and deletes it.
Represent the analysis usage information of a pass.
const HexagonInstrInfo * TII
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
MachineFunctionProperties & set(Property P)
STATISTIC(NumFunctions, "Total number of functions")
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Representation of each machine instruction.
bool hasAddressTaken() const
Test whether this block is potentially the target of an indirect branch.
MachineInstr * CloneMachineInstr(const MachineInstr *Orig)
Create a new MachineInstr which is a copy of Orig, identical in all ways except the instruction has n...
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...
iterator getLastNonDebugInstr(bool SkipPseudoOp=true)
Returns an iterator to the last non-debug instruction in the basic block, or end().
bool canFallThrough()
Return true if the block can implicitly transfer control to the block after it by falling off the end...
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
iterator_range< pred_iterator > predecessors()
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
Function & getFunction()
Return the LLVM function that this machine code represents.
void removeSuccessor(MachineBasicBlock *Succ, bool NormalizeSuccProbs=false)
Remove successor from the successors list of this MachineBasicBlock.
bool isLayoutSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB will be emitted immediately after this block, such that if this bloc...
void initializePPCEarlyReturnPass(PassRegistry &)
FunctionPass class - This class is used to implement most global optimizations.
iterator SkipPHIsLabelsAndDebug(iterator I, bool SkipPseudoOp=true)
Return the first instruction in MBB after I that is not a PHI, label or debug.