28 #define DEBUG_TYPE "msp430-branch-select"
30 STATISTIC(NumExpanded,
"Number of branches expanded to long format");
38 std::vector<unsigned> BlockSizes;
42 const char *getPassName()
const override {
43 return "MSP430 Branch Selector";
53 return new MSP430BSel();
64 unsigned FuncSize = 0;
69 unsigned BlockSize = 0;
75 FuncSize += BlockSize;
81 if (FuncSize < (1 << 9)) {
95 bool MadeChange =
true;
96 bool EverMadeChange =
false;
104 unsigned MBBStartOffset = 0;
107 if ((
I->getOpcode() != MSP430::JCC ||
I->getOperand(0).isImm()) &&
108 I->getOpcode() != MSP430::JMP) {
122 BranchSize = MBBStartOffset;
125 BranchSize += BlockSizes[i];
129 BranchSize = -MBBStartOffset;
132 BranchSize += BlockSizes[i];
136 if (isInt<10>(BranchSize)) {
146 if (
I->getOpcode() == MSP430::JMP) {
157 BuildMI(MBB,
I, dl, TII->get(MSP430::JCC))
163 I =
BuildMI(MBB,
I, dl, TII->get(MSP430::Bi)).addMBB(Dest);
170 BlockSizes[MBB.
getNumber()] += NewSize-2;
171 MBBStartOffset += NewSize;
177 EverMadeChange |= MadeChange;
void push_back(const T &Elt)
bool ReverseBranchCondition(SmallVectorImpl< MachineOperand > &Cond) const override
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 eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
bundle_iterator< MachineInstr, instr_iterator > iterator
unsigned GetInstSizeInBytes(const MachineInstr *MI) const
GetInstSize - Return the number of bytes of code the specified instruction may be.
FunctionPass * createMSP430BranchSelectionPass()
createMSP430BranchSelectionPass - 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.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
Representation of each machine instruction.
virtual const TargetInstrInfo * getInstrInfo() const
const MachineInstrBuilder & addOperand(const MachineOperand &MO) const
BasicBlockListType::iterator iterator