31 #define DEBUG_TYPE "ppc-branch-select" 33 STATISTIC(NumExpanded,
"Number of branches expanded to long format");
49 std::vector<std::pair<unsigned, unsigned>> BlockSizes;
58 StringRef getPassName()
const override {
return "PowerPC Branch Selector"; }
80 auto GetAlignmentAdjustment =
86 unsigned AlignAmt = 1 <<
Align;
89 if (Align <= ParentAlign)
103 unsigned InitialOffset = 0;
109 unsigned FuncSize = InitialOffset;
117 unsigned AlignExtra = GetAlignmentAdjustment(*MBB, FuncSize);
119 auto &BS = BlockSizes[MBB->
getNumber()-1];
120 BS.first += AlignExtra;
121 BS.second = AlignExtra;
123 FuncSize += AlignExtra;
130 BlockSizes[MBB->getNumber()].first =
BlockSize;
137 if (FuncSize < (1 << 15)) {
151 bool MadeChange =
true;
152 bool EverMadeChange =
false;
160 unsigned MBBStartOffset = 0;
164 if (
I->getOpcode() == PPC::BCC && !
I->getOperand(2).isImm())
165 Dest =
I->getOperand(2).getMBB();
166 else if ((
I->getOpcode() == PPC::BC ||
I->getOpcode() == PPC::BCn) &&
167 !
I->getOperand(1).isImm())
168 Dest =
I->getOperand(1).getMBB();
169 else if ((
I->getOpcode() == PPC::BDNZ8 ||
I->getOpcode() ==
PPC::BDNZ ||
170 I->getOpcode() == PPC::BDZ8 ||
I->getOpcode() ==
PPC::BDZ) &&
171 !
I->getOperand(0).isImm())
172 Dest =
I->getOperand(0).getMBB();
186 BranchSize = MBBStartOffset;
189 BranchSize += BlockSizes[i].
first;
193 BranchSize = -MBBStartOffset;
196 BranchSize += BlockSizes[i].
first;
209 if (
I->getOpcode() == PPC::BCC) {
215 unsigned CRReg =
I->getOperand(1).getReg();
218 BuildMI(MBB,
I, dl, TII->get(PPC::BCC))
220 }
else if (
I->getOpcode() == PPC::BC) {
221 unsigned CRBit =
I->getOperand(0).getReg();
223 }
else if (
I->getOpcode() == PPC::BCn) {
224 unsigned CRBit =
I->getOperand(0).getReg();
228 }
else if (
I->getOpcode() == PPC::BDNZ8) {
229 BuildMI(MBB,
I, dl, TII->get(PPC::BDZ8)).addImm(2);
232 }
else if (
I->getOpcode() == PPC::BDZ8) {
233 BuildMI(MBB,
I, dl, TII->get(PPC::BDNZ8)).addImm(2);
256 unsigned Offset = InitialOffset;
262 auto &BS = BlockSizes[MBB->
getNumber()-1];
263 BS.first -= BS.second;
266 unsigned AlignExtra = GetAlignmentAdjustment(*MBB, Offset);
268 BS.first += AlignExtra;
269 BS.second = AlignExtra;
271 Offset += AlignExtra;
274 Offset += BlockSizes[MBB->
getNumber()].first;
278 EverMadeChange |= MadeChange;
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
void RenumberBlocks(MachineBasicBlock *MBBFrom=nullptr)
RenumberBlocks - This discards all of the MachineBasicBlock numbers and recomputes them...
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
constexpr bool isInt< 16 >(int64_t x)
STATISTIC(NumFunctions, "Total number of functions")
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
void initializePPCBSelPass(PassRegistry &)
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
unsigned getAlignment() const
getAlignment - Return the alignment (log2, not bytes) of the function.
CHAIN = BDNZ CHAIN, DESTBB - These are used to create counter-based loops.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
virtual const TargetInstrInfo * getInstrInfo() const
FunctionPass * createPPCBranchSelectionPass()
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")
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
unsigned getAlignment() const
Return alignment of the basic block.
FunctionPass class - This class is used to implement most global optimizations.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static const int BlockSize
Iterator for intrusive lists based on ilist_node.
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
bool use_empty(unsigned RegNo) const
use_empty - Return true if there are no instructions using the specified register.
MachineFunctionProperties & set(Property P)
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
Predicate InvertPredicate(Predicate Opcode)
Invert the specified predicate. != -> ==, < -> >=.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
unsigned getInstSizeInBytes(const MachineInstr &MI) const override
GetInstSize - Return the number of bytes of code the specified instruction may be.
INITIALIZE_PASS(PPCBSel, "ppc-branch-select", "PowerPC Branch Selector", false, false) FunctionPass *llvm
createPPCBranchSelectionPass - returns an instance of the Branch Selection Pass
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...
StringRef - Represent a constant reference to a string, i.e.
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.