35#define DEBUG_TYPE "ppc-early-ret"
36STATISTIC(NumBCLR,
"Number of early conditional 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) {
181 bool Changed =
false;
189 Changed |= processBlock(
B);
196 MachineFunctionProperties::Property::NoVRegs);
206 "PowerPC Early-Return Creation",
false,
false)
208char PPCEarlyReturn::
ID = 0;
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
const HexagonInstrInfo * TII
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
bool skipFunction(const Function &F) const
Optional passes call this function to check whether the pass should be skipped.
unsigned pred_size() const
iterator SkipPHIsLabelsAndDebug(iterator I, Register Reg=Register(), bool SkipPseudoOp=true)
Return the first instruction in MBB after I that is not a PHI, label or debug.
bool canFallThrough()
Return true if the block can implicitly transfer control to the block after it by falling off the end...
bool hasAddressTaken() const
Test whether this block is used as something other than the target of a terminator,...
void removeSuccessor(MachineBasicBlock *Succ, bool NormalizeSuccProbs=false)
Remove successor from the successors list of this MachineBasicBlock.
pred_iterator pred_begin()
iterator getLastNonDebugInstr(bool SkipPseudoOp=true)
Returns an iterator to the last non-debug instruction in the basic block, or end().
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 eraseFromParent()
This method unlinks 'this' from the containing function and deletes it.
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 '...
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.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
virtual MachineFunctionProperties getRequiredProperties() const
Properties which a MachineFunction may have at a given point in time.
MachineFunctionProperties & set(Property P)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Function & getFunction()
Return the LLVM function that this machine code represents.
MachineInstr * CloneMachineInstr(const MachineInstr *Orig)
Create a new MachineInstr which is a copy of Orig, identical in all ways except the instruction has n...
const MachineInstrBuilder & add(const MachineOperand &MO) const
Representation of each machine instruction.
void insert(mop_iterator InsertBefore, ArrayRef< MachineOperand > Ops)
Inserts Ops BEFORE It. Can untie/retie tied operands.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetInstrInfo - Interface to description of machine instruction set.
virtual const TargetInstrInfo * getInstrInfo() const
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< 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...
FunctionPass * createPPCEarlyReturnPass()
void initializePPCEarlyReturnPass(PassRegistry &)