Go to the documentation of this file.
31 #define DEBUG_TYPE "ppc-branch-select"
33 STATISTIC(NumExpanded,
"Number of branches expanded to long format");
34 STATISTIC(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;
68 StringRef getPassName()
const override {
return "PowerPC Branch Selector"; }
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);
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();
377 }
else if (
I->getOpcode() == PPC::BDNZ8) {
381 }
else if (
I->getOpcode() == PPC::BDZ8) {
405 modifyAdjustment(Fn);
408 EverMadeChange |= MadeChange;
412 return EverMadeChange;
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
This is an optimization pass for GlobalISel generic memory operations.
static const int BlockSize
@ BDNZ
CHAIN = BDNZ CHAIN, DESTBB - These are used to create counter-based loops.
virtual const TargetInstrInfo * getInstrInfo() const
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
Properties which a MachineFunction may have at a given point in time.
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...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const HexagonInstrInfo * TII
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
MachineFunctionProperties & set(Property P)
STATISTIC(NumFunctions, "Total number of functions")
void initializePPCBSelPass(PassRegistry &)
This struct is a compact representation of a valid (non-zero power of two) alignment.
bool use_empty(Register RegNo) const
use_empty - Return true if there are no instructions using the specified register.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
Representation of each machine instruction.
Align getAlignment() const
Return alignment of the basic block.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
FunctionPass * createPPCBranchSelectionPass()
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
StringRef - Represent a constant reference to a string, i.e.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Predicate InvertPredicate(Predicate Opcode)
Invert the specified predicate. != -> ==, < -> >=.
Wrapper class representing virtual and physical registers.
constexpr bool isInt< 16 >(int64_t x)
MachineBasicBlock * getBlockNumbered(unsigned N) const
getBlockNumbered - MachineBasicBlocks are automatically numbered when they are inserted into the mach...
Iterator for intrusive lists based on ilist_node.
uint64_t value() const
This is a hole in the type system and should not be abused.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
Align max(MaybeAlign Lhs, Align Rhs)
FunctionPass class - This class is used to implement most global optimizations.
INITIALIZE_PASS(PPCBSel, "ppc-branch-select", "PowerPC Branch Selector", false, false) FunctionPass *llvm
createPPCBranchSelectionPass - returns an instance of the Branch Selection Pass
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
Align getAlignment() const
getAlignment - Return the alignment of the function.
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 RenumberBlocks(MachineBasicBlock *MBBFrom=nullptr)
RenumberBlocks - This discards all of the MachineBasicBlock numbers and recomputes them.