30#define DEBUG_TYPE "ppc-branch-select"
32STATISTIC(NumExpanded,
"Number of branches expanded to long format");
33STATISTIC(NumPrefixed,
"Number of prefixed instructions");
35 "Number of prefixed instructions that have been aligned");
47 std::vector<std::pair<unsigned, unsigned>> BlockSizes;
50 int FirstImpreciseBlock = -1;
64 MachineFunctionProperties::Property::NoVRegs);
87 if (Alignment ==
Align(1))
92 if (Alignment <= ParentAlign)
97 if (FirstImpreciseBlock < 0)
109 unsigned InitialOffset = 0;
113 return InitialOffset;
126 unsigned AlignExtra = GetAlignmentAdjustment(
MBB, FuncSize);
129 BS.first += AlignExtra;
130 BS.second = AlignExtra;
132 FuncSize += AlignExtra;
136 unsigned UnalignedBytesRemaining = 0;
138 unsigned MINumBytes =
TII->getInstSizeInBytes(
MI);
139 if (
MI.isInlineAsm() && (FirstImpreciseBlock < 0))
141 if (
TII->isPrefixed(
MI.getOpcode())) {
160 if (!UnalignedBytesRemaining) {
162 UnalignedBytesRemaining = 60;
163 NumPrefixedAligned++;
166 UnalignedBytesRemaining -= std::min(UnalignedBytesRemaining, MINumBytes);
183 BS.first -= BS.second;
186 unsigned AlignExtra = GetAlignmentAdjustment(
MBB,
Offset);
188 BS.first += AlignExtra;
189 BS.second = AlignExtra;
206 bool NeedExtraAdjustment =
false;
207 if (Dest->
getNumber() <= Src->getNumber()) {
211 BranchSize = BrOffset;
212 MaxAlign = std::max(MaxAlign, Src->getAlignment());
215 BranchSize += BlockSizes[DestBlock].first;
216 for (
unsigned i = DestBlock+1, e = Src->getNumber(); i < e; ++i) {
217 BranchSize += BlockSizes[i].first;
221 NeedExtraAdjustment = (FirstImpreciseBlock >= 0) &&
222 (DestBlock >= FirstImpreciseBlock);
226 unsigned StartBlock = Src->getNumber();
227 BranchSize = BlockSizes[StartBlock].first - BrOffset;
230 for (
unsigned i = StartBlock+1, e = Dest->
getNumber(); i != e; ++i) {
231 BranchSize += BlockSizes[i].first;
235 NeedExtraAdjustment = (FirstImpreciseBlock >= 0) &&
236 (Src->getNumber() >= FirstImpreciseBlock);
281 if (NeedExtraAdjustment)
282 BranchSize += MaxAlign.
value() - 4;
293 FirstImpreciseBlock = -1;
296 unsigned FuncSize = ComputeBlockSizes(Fn);
301 if (FuncSize < (1 << 15)) {
315 bool MadeChange =
true;
316 bool EverMadeChange =
false;
324 unsigned MBBStartOffset = 0;
328 if (
I->getOpcode() == PPC::BCC && !
I->getOperand(2).isImm())
329 Dest =
I->getOperand(2).getMBB();
330 else if ((
I->getOpcode() == PPC::BC ||
I->getOpcode() == PPC::BCn) &&
331 !
I->getOperand(1).isImm())
332 Dest =
I->getOperand(1).getMBB();
333 else if ((
I->getOpcode() == PPC::BDNZ8 ||
I->getOpcode() == PPC::BDNZ ||
334 I->getOpcode() == PPC::BDZ8 ||
I->getOpcode() == PPC::BDZ) &&
335 !
I->getOperand(0).isImm())
336 Dest =
I->getOperand(0).getMBB();
339 MBBStartOffset +=
TII->getInstSizeInBytes(*
I);
345 int BranchSize = computeBranchSize(Fn, &
MBB, Dest, MBBStartOffset);
348 if (isInt<16>(BranchSize)) {
357 if (
I->getOpcode() == PPC::BCC) {
363 Register CRReg =
I->getOperand(1).getReg();
368 }
else if (
I->getOpcode() == PPC::BC) {
369 Register CRBit =
I->getOperand(0).getReg();
371 }
else if (
I->getOpcode() == PPC::BCn) {
372 Register CRBit =
I->getOperand(0).getReg();
374 }
else if (
I->getOpcode() == PPC::BDNZ) {
376 }
else if (
I->getOpcode() == PPC::BDNZ8) {
378 }
else if (
I->getOpcode() == PPC::BDZ) {
380 }
else if (
I->getOpcode() == PPC::BDZ8) {
404 modifyAdjustment(Fn);
407 EverMadeChange |= MadeChange;
411 return EverMadeChange;
const HexagonInstrInfo * TII
static unsigned GetInitialOffset(MachineFunction &Fn)
We need to be careful about the offset of the first block in the function because it might not have t...
#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)
static const int BlockSize
FunctionPass class - This class is used to implement most global optimizations.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
Align getAlignment() const
Return alignment of the basic block.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
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.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
MachineBasicBlock * getBlockNumbered(unsigned N) const
getBlockNumbered - MachineBasicBlocks are automatically numbered when they are inserted into the mach...
Align getAlignment() const
getAlignment - Return the alignment of the function.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
void RenumberBlocks(MachineBasicBlock *MBBFrom=nullptr)
RenumberBlocks - This discards all of the MachineBasicBlock numbers and recomputes them.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
Representation of each machine instruction.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
bool use_empty(Register RegNo) const
use_empty - Return true if there are no instructions using the specified register.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Wrapper class representing virtual and physical registers.
StringRef - Represent a constant reference to a string, i.e.
virtual const TargetInstrInfo * getInstrInfo() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
Predicate InvertPredicate(Predicate Opcode)
Invert the specified predicate. != -> ==, < -> >=.
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
uint64_t offsetToAlignment(uint64_t Value, Align Alignment)
Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...
void initializePPCBSelPass(PassRegistry &)
FunctionPass * createPPCBranchSelectionPass()
This struct is a compact representation of a valid (non-zero power of two) alignment.
uint64_t value() const
This is a hole in the type system and should not be abused.