36 #define DEBUG_TYPE "ppc-early-ret"
37 STATISTIC(NumBCLR,
"Number of early conditional returns");
38 STATISTIC(NumBLR,
"Number of early returns");
64 if (I == ReturnMBB.
end() ||
65 (I->getOpcode() != PPC::BLR && I->getOpcode() != PPC::BLR8) ||
71 PIE = ReturnMBB.
pred_end(); PI != PIE; ++PI) {
72 bool OtherReference =
false, BlockChanged =
false;
78 if (J == (*PI)->end())
81 if (J->getOpcode() ==
PPC::B) {
82 if (J->getOperand(0).getMBB() == &ReturnMBB) {
85 BuildMI(**PI, J, J->getDebugLoc(),
TII->get(I->getOpcode()))
93 }
else if (J->getOpcode() == PPC::BCC) {
94 if (J->getOperand(2).getMBB() == &ReturnMBB) {
97 BuildMI(**PI, J, J->getDebugLoc(),
TII->get(PPC::BCCLR))
98 .addImm(J->getOperand(0).getImm())
99 .addReg(J->getOperand(1).getReg())
100 .copyImplicitOps(*I);
102 K->eraseFromParent();
107 }
else if (J->getOpcode() == PPC::BC || J->getOpcode() == PPC::BCn) {
108 if (J->getOperand(1).getMBB() == &ReturnMBB) {
112 **PI, J, J->getDebugLoc(),
113 TII->get(J->getOpcode() == PPC::BC ? PPC::BCLR : PPC::BCLRn))
114 .
addReg(J->getOperand(0).getReg())
115 .copyImplicitOps(*I);
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->isDebugValue())
134 if (J == (*PI)->begin())
140 if ((*PI)->canFallThrough() && (*PI)->isLayoutSuccessor(&ReturnMBB))
141 OtherReference =
true;
144 if (!OtherReference && BlockChanged) {
152 for (
unsigned i = 0, ie = PredToRemove.
size();
i != ie; ++
i)
153 PredToRemove[
i]->removeSuccessor(&ReturnMBB,
true);
181 bool Changed =
false;
209 "PowerPC Early-Return Creation",
false,
false)
211 char PPCEarlyReturn::
ID = 0;
void push_back(const T &Elt)
const MachineInstrBuilder & copyImplicitOps(const MachineInstr &OtherMI) const
Copy all the implicit operands from OtherMI onto this one.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
STATISTIC(NumFunctions,"Total number of functions")
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
void 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
bool canFallThrough()
Return true if the block can implicitly transfer control to the block after it by falling off the end...
iterator getLastNonDebugInstr()
Returns an iterator to the last non-debug instruction in the basic block, or end().
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
std::vector< MachineBasicBlock * >::iterator pred_iterator
TargetInstrInfo - Interface to description of machine instruction set.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
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.
pred_iterator pred_begin()
void initializePPCEarlyReturnPass(PassRegistry &)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Iterator for intrusive lists based on ilist_node.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
MachineFunctionProperties & set(Property P)
bool hasAddressTaken() const
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 '...
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
void removeSuccessor(MachineBasicBlock *Succ, bool NormalizeSuccProbs=false)
Remove successor from the successors list of this MachineBasicBlock.
virtual const TargetInstrInfo * getInstrInfo() const
iterator SkipPHIsLabelsAndDebug(iterator I)
Return the first instruction in MBB after I that is not a PHI, label or debug.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
bool isLayoutSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB will be emitted immediately after this block, such that if this bloc...
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
unsigned pred_size() const
Properties which a MachineFunction may have at a given point in time.