37 #define DEBUG_TYPE "ppc-early-ret"
38 STATISTIC(NumBCLR,
"Number of early conditional returns");
39 STATISTIC(NumBLR,
"Number of early returns");
65 if (I == ReturnMBB.
end() ||
66 (I->getOpcode() != PPC::BLR && I->getOpcode() != PPC::BLR8) ||
72 PIE = ReturnMBB.
pred_end(); PI != PIE; ++PI) {
73 bool OtherReference =
false, BlockChanged =
false;
76 if (J->getOpcode() == PPC::B) {
77 if (J->getOperand(0).getMBB() == &ReturnMBB) {
81 BuildMI(**PI, J, J->getDebugLoc(),
TII->get(I->getOpcode()));
89 }
else if (J->getOpcode() == PPC::BCC) {
90 if (J->getOperand(2).getMBB() == &ReturnMBB) {
93 MIB =
BuildMI(**PI, J, J->getDebugLoc(),
TII->get(PPC::BCCLR))
94 .addImm(J->getOperand(0).getImm())
95 .addReg(J->getOperand(1).getReg());
103 }
else if (J->getOpcode() == PPC::BC || J->getOpcode() == PPC::BCn) {
104 if (J->getOperand(1).getMBB() == &ReturnMBB) {
107 MIB =
BuildMI(**PI, J, J->getDebugLoc(),
108 TII->get(J->getOpcode() == PPC::BC ?
109 PPC::BCLR : PPC::BCLRn))
110 .
addReg(J->getOperand(0).getReg());
118 }
else if (J->isBranch()) {
119 if (J->isIndirectBranch()) {
121 OtherReference =
true;
123 for (
unsigned i = 0; i < J->getNumOperands(); ++i)
124 if (J->getOperand(i).isMBB() &&
125 J->getOperand(i).getMBB() == &ReturnMBB)
126 OtherReference =
true;
127 }
else if (!J->isTerminator() && !J->isDebugValue())
130 if (J == (*PI)->begin())
136 if ((*PI)->canFallThrough() && (*PI)->isLayoutSuccessor(&ReturnMBB))
137 OtherReference =
true;
140 if (!OtherReference && BlockChanged) {
148 for (
unsigned i = 0, ie = PredToRemove.
size(); i != ie; ++i)
149 PredToRemove[i]->removeSuccessor(&ReturnMBB);
174 bool Changed =
false;
197 "PowerPC Early-Return Creation",
false,
false)
199 char PPCEarlyReturn::
ID = 0;
void push_back(const T &Elt)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
STATISTIC(NumFunctions,"Total number of functions")
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing function and deletes it...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
bool canFallThrough()
canFallThrough - Return true if the block can implicitly transfer control to the block after it by fa...
iterator getLastNonDebugInstr()
getLastNonDebugInstr - returns an iterator to the last non-debug instruction in the basic block...
std::vector< MachineBasicBlock * >::iterator pred_iterator
TargetInstrInfo - Interface to description of machine instruction set.
bundle_iterator< MachineInstr, instr_iterator > iterator
iterator SkipPHIsAndLabels(iterator I)
SkipPHIsAndLabels - Return the first instruction in MBB after I that is not a PHI or a label...
FunctionPass * createPPCEarlyReturnPass()
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
MachineInstrBuilder BuildMI(MachineFunction &MF, DebugLoc DL, const MCInstrDesc &MCID)
BuildMI - Builder interface.
void removeSuccessor(MachineBasicBlock *succ)
removeSuccessor - Remove successor from the successors list of this MachineBasicBlock.
pred_iterator pred_begin()
void initializePPCEarlyReturnPass(PassRegistry &)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool hasAddressTaken() const
hasAddressTaken - Test whether this block is potentially the target of an indirect branch...
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 '...
const MachineInstrBuilder & copyImplicitOps(const MachineInstr *OtherMI)
Copy all the implicit operands from OtherMI onto this one.
virtual const TargetInstrInfo * getInstrInfo() const
BasicBlockListType::iterator iterator
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
bool isLayoutSuccessor(const MachineBasicBlock *MBB) const
isLayoutSuccessor - Return true if the specified MBB will be emitted immediately after this block...
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
addReg - Add a new virtual register operand...
unsigned pred_size() const