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->isDebugInstr())
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;
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
void push_back(const T &Elt)
STATISTIC(NumFunctions, "Total number of functions")
void eraseFromParent()
This method unlinks 'this' from the containing function and deletes it.
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().
virtual const TargetInstrInfo * getInstrInfo() const
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.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
FunctionPass * createPPCEarlyReturnPass()
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
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.
std::vector< MachineBasicBlock * >::iterator pred_iterator
bool hasAddressTaken() const
Test whether this block is potentially the target of an indirect branch.
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...
unsigned pred_size() const
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 Function & getFunction() const
Return the LLVM function that this machine code represents.
const MachineInstrBuilder & copyImplicitOps(const MachineInstr &OtherMI) const
Copy all the implicit operands from OtherMI onto this one.
MachineFunctionProperties & set(Property P)
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 MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
void removeSuccessor(MachineBasicBlock *Succ, bool NormalizeSuccProbs=false)
Remove successor from the successors list of this MachineBasicBlock.
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...
Properties which a MachineFunction may have at a given point in time.