29 #define DEBUG_TYPE "ppc-branch-select"
31 STATISTIC(NumExpanded,
"Number of branches expanded to long format");
45 std::vector<unsigned> BlockSizes;
49 const char *getPassName()
const override {
50 return "PowerPC Branch Selector";
73 auto GetAlignmentAdjustment =
79 unsigned AlignAmt = 1 <<
Align;
82 if (Align <= ParentAlign)
91 unsigned FuncSize = 0;
99 unsigned AlignExtra = GetAlignmentAdjustment(*MBB, FuncSize);
100 BlockSizes[MBB->
getNumber()-1] += AlignExtra;
101 FuncSize += AlignExtra;
104 unsigned BlockSize = 0;
109 BlockSizes[MBB->
getNumber()] = BlockSize;
110 FuncSize += BlockSize;
116 if (FuncSize < (1 << 15)) {
130 bool MadeChange =
true;
131 bool EverMadeChange =
false;
139 unsigned MBBStartOffset = 0;
143 if (
I->getOpcode() == PPC::BCC && !
I->getOperand(2).isImm())
144 Dest =
I->getOperand(2).getMBB();
145 else if ((
I->getOpcode() == PPC::BC ||
I->getOpcode() == PPC::BCn) &&
146 !
I->getOperand(1).isImm())
147 Dest =
I->getOperand(1).getMBB();
148 else if ((
I->getOpcode() == PPC::BDNZ8 ||
I->getOpcode() ==
PPC::BDNZ ||
149 I->getOpcode() == PPC::BDZ8 ||
I->getOpcode() ==
PPC::BDZ) &&
150 !
I->getOperand(0).isImm())
151 Dest =
I->getOperand(0).getMBB();
165 BranchSize = MBBStartOffset;
168 BranchSize += BlockSizes[i];
172 BranchSize = -MBBStartOffset;
175 BranchSize += BlockSizes[i];
188 if (
I->getOpcode() == PPC::BCC) {
194 unsigned CRReg =
I->getOperand(1).getReg();
197 BuildMI(MBB,
I, dl, TII->get(PPC::BCC))
199 }
else if (
I->getOpcode() == PPC::BC) {
200 unsigned CRBit =
I->getOperand(0).getReg();
202 }
else if (
I->getOpcode() == PPC::BCn) {
203 unsigned CRBit =
I->getOperand(0).getReg();
207 }
else if (
I->getOpcode() == PPC::BDNZ8) {
208 BuildMI(MBB,
I, dl, TII->get(PPC::BDZ8)).addImm(2);
211 }
else if (
I->getOpcode() == PPC::BDZ8) {
212 BuildMI(MBB,
I, dl, TII->get(PPC::BDNZ8)).addImm(2);
218 I =
BuildMI(MBB,
I, dl, TII->get(PPC::B)).addMBB(Dest);
231 EverMadeChange |= MadeChange;
const MachineFunction * getParent() const
getParent - Return the MachineFunction containing this basic block.
unsigned getAlignment() const
getAlignment - Return the alignment (log2, not bytes) of the function.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
STATISTIC(NumFunctions,"Total number of functions")
void RenumberBlocks(MachineBasicBlock *MBBFrom=nullptr)
RenumberBlocks - This discards all of the MachineBasicBlock numbers and recomputes them...
int getNumber() const
getNumber - MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a M...
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
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 initializePPCBSelPass(PassRegistry &)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
const MachineInstrBuilder & addImm(int64_t Val) const
addImm - Add a new immediate operand.
CHAIN = BDNZ CHAIN, DESTBB - These are used to create counter-based loops.
FunctionPass * createPPCBranchSelectionPass()
bundle_iterator< MachineInstr, instr_iterator > iterator
INITIALIZE_PASS(PPCBSel,"ppc-branch-select","PowerPC Branch Selector", false, false) FunctionPass *llvm
createPPCBranchSelectionPass - returns an instance of the Branch Selection Pass
FunctionPass class - This class is used to implement most global optimizations.
MachineInstrBuilder BuildMI(MachineFunction &MF, DebugLoc DL, const MCInstrDesc &MCID)
BuildMI - Builder interface.
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(NoStrictAlign), cl::values(clEnumValN(StrictAlign,"aarch64-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"aarch64-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
Representation of each machine instruction.
Predicate InvertPredicate(Predicate Opcode)
Invert the specified predicate. != -> ==, < -> >=.
bool isInt< 16 >(int64_t x)
unsigned GetInstSizeInBytes(const MachineInstr *MI) const
GetInstSize - Return the number of bytes of code the specified instruction may be.
virtual const TargetInstrInfo * getInstrInfo() const
uint64_t OffsetToAlignment(uint64_t Value, uint64_t Align)
Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...
BasicBlockListType::iterator iterator
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
unsigned getAlignment() const
getAlignment - Return alignment of the basic block.