31#define DEBUG_TYPE "ppc-branch-select"
33STATISTIC(NumExpanded,
"Number of branches expanded to long format");
34STATISTIC(NumPrefixed,
"Number of prefixed instructions");
36 "Number of prefixed instructions that have been aligned");
48 std::vector<std::pair<unsigned, unsigned>> BlockSizes;
51 int FirstImpreciseBlock = -1;
65 MachineFunctionProperties::Property::NoVRegs);
88 if (Alignment ==
Align(1))
93 if (Alignment <= ParentAlign)
98 if (FirstImpreciseBlock < 0)
110 unsigned InitialOffset = 0;
114 return InitialOffset;
127 unsigned AlignExtra = GetAlignmentAdjustment(
MBB, FuncSize);
130 BS.first += AlignExtra;
131 BS.second = AlignExtra;
133 FuncSize += AlignExtra;
137 unsigned UnalignedBytesRemaining = 0;
139 unsigned MINumBytes =
TII->getInstSizeInBytes(
MI);
140 if (
MI.isInlineAsm() && (FirstImpreciseBlock < 0))
142 if (
TII->isPrefixed(
MI.getOpcode())) {
161 if (!UnalignedBytesRemaining) {
163 UnalignedBytesRemaining = 60;
164 NumPrefixedAligned++;
167 UnalignedBytesRemaining -= std::min(UnalignedBytesRemaining, MINumBytes);
184 BS.first -= BS.second;
187 unsigned AlignExtra = GetAlignmentAdjustment(
MBB,
Offset);
189 BS.first += AlignExtra;
190 BS.second = AlignExtra;
207 bool NeedExtraAdjustment =
false;
208 if (Dest->
getNumber() <= Src->getNumber()) {
212 BranchSize = BrOffset;
213 MaxAlign = std::max(MaxAlign, Src->getAlignment());
216 BranchSize += BlockSizes[DestBlock].first;
217 for (
unsigned i = DestBlock+1, e = Src->getNumber(); i < e; ++i) {
218 BranchSize += BlockSizes[i].first;
222 NeedExtraAdjustment = (FirstImpreciseBlock >= 0) &&
223 (DestBlock >= FirstImpreciseBlock);
227 unsigned StartBlock = Src->getNumber();
228 BranchSize = BlockSizes[StartBlock].first - BrOffset;
231 for (
unsigned i = StartBlock+1, e = Dest->
getNumber(); i != e; ++i) {
232 BranchSize += BlockSizes[i].first;
236 NeedExtraAdjustment = (FirstImpreciseBlock >= 0) &&
237 (Src->getNumber() >= FirstImpreciseBlock);
282 if (NeedExtraAdjustment)
283 BranchSize += MaxAlign.
value() - 4;
294 FirstImpreciseBlock = -1;
297 unsigned FuncSize = ComputeBlockSizes(Fn);
302 if (FuncSize < (1 << 15)) {
316 bool MadeChange =
true;
317 bool EverMadeChange =
false;
325 unsigned MBBStartOffset = 0;
329 if (
I->getOpcode() == PPC::BCC && !
I->getOperand(2).isImm())
330 Dest =
I->getOperand(2).getMBB();
331 else if ((
I->getOpcode() == PPC::BC ||
I->getOpcode() == PPC::BCn) &&
332 !
I->getOperand(1).isImm())
333 Dest =
I->getOperand(1).getMBB();
334 else if ((
I->getOpcode() == PPC::BDNZ8 ||
I->getOpcode() == PPC::BDNZ ||
335 I->getOpcode() == PPC::BDZ8 ||
I->getOpcode() == PPC::BDZ) &&
336 !
I->getOperand(0).isImm())
337 Dest =
I->getOperand(0).getMBB();
340 MBBStartOffset +=
TII->getInstSizeInBytes(*
I);
346 int BranchSize = computeBranchSize(Fn, &
MBB, Dest, MBBStartOffset);
349 if (isInt<16>(BranchSize)) {
358 if (
I->getOpcode() == PPC::BCC) {
364 Register CRReg =
I->getOperand(1).getReg();
369 }
else if (
I->getOpcode() == PPC::BC) {
370 Register CRBit =
I->getOperand(0).getReg();
372 }
else if (
I->getOpcode() == PPC::BCn) {
373 Register CRBit =
I->getOperand(0).getReg();
375 }
else if (
I->getOpcode() == PPC::BDNZ) {
377 }
else if (
I->getOpcode() == PPC::BDNZ8) {
379 }
else if (
I->getOpcode() == PPC::BDZ) {
381 }
else if (
I->getOpcode() == PPC::BDZ8) {
405 modifyAdjustment(Fn);
408 EverMadeChange |= MadeChange;
412 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.