61 #define DEBUG_TYPE "mips-constant-islands"
63 STATISTIC(NumCPEs,
"Number of constpool entries");
64 STATISTIC(NumSplit,
"Number of uncond branches inserted");
65 STATISTIC(NumCBrFixed,
"Number of cond branches fixed");
66 STATISTIC(NumUBrFixed,
"Number of uncond branches fixed");
71 cl::desc(
"Align constant islands in code"));
77 "mips-constant-islands-small-offset",
79 cl::desc(
"Make small offsets be this amount for testing purposes"),
87 "mips-constant-islands-no-load-relaxation",
89 cl::desc(
"Don't relax loads to long loads - for testing purposes"),
102 case Mips::BeqzRxImm16:
103 case Mips::BeqzRxImmX16:
104 case Mips::BnezRxImm16:
105 case Mips::BnezRxImmX16:
115 return Mips::BimmX16;
118 return Mips::BteqzX16;
121 return Mips::BtnezX16;
124 case Mips::BeqzRxImm16:
125 case Mips::BeqzRxImmX16:
126 return Mips::BeqzRxImmX16;
127 case Mips::BnezRxImm16:
128 case Mips::BnezRxImmX16:
129 return Mips::BnezRxImmX16;
141 unsigned Bits, Scale;
151 case Mips::BeqzRxImm16:
155 case Mips::BeqzRxImmX16:
159 case Mips::BnezRxImm16:
163 case Mips::BnezRxImmX16:
186 unsigned MaxOffs = ((1 << (Bits-1))-1) * Scale;
233 unsigned postOffset(
unsigned LogAlign = 0)
const {
239 std::vector<BasicBlockInfo> BBInfo;
244 std::vector<MachineBasicBlock*> WaterList;
250 typedef std::vector<MachineBasicBlock*>::iterator water_iterator;
271 unsigned LongFormMaxDisp;
273 unsigned LongFormOpcode;
280 unsigned longformmaxdisp,
unsigned longformopcode)
281 :
MI(mi), CPEMI(cpemi), MaxDisp(maxdisp),
282 LongFormMaxDisp(longformmaxdisp), LongFormOpcode(longformopcode),
284 HighWaterMark = CPEMI->getParent();
288 unsigned getMaxDisp()
const {
294 void setMaxDisp(
unsigned val) {
298 unsigned getLongFormMaxDisp()
const {
299 return LongFormMaxDisp;
302 unsigned getLongFormOpcode()
const {
303 return LongFormOpcode;
309 std::vector<CPUser> CPUsers;
320 : CPEMI(cpemi), CPI(cpi), RefCount(
rc) {}
328 std::vector<std::vector<CPEntry>> CPEntries;
336 unsigned MaxDisp : 31;
340 ImmBranch(
MachineInstr *mi,
unsigned maxdisp,
bool cond,
int ubr)
341 :
MI(mi), MaxDisp(maxdisp), isCond(cond), UncondBr(ubr) {}
346 std::vector<ImmBranch> ImmBranches;
358 unsigned PICLabelUId;
359 bool PrescannedForConstants =
false;
361 void initPICLabelUId(
unsigned UId) {
365 unsigned createPICLabelUId() {
366 return PICLabelUId++;
374 StringRef getPassName()
const override {
return "Mips Constant Islands"; }
383 void doInitialPlacement(std::vector<MachineInstr*> &CPEMIs);
384 CPEntry *findConstPoolEntry(
unsigned CPI,
const MachineInstr *CPEMI);
386 void initializeFunctionInfo(
const std::vector<MachineInstr*> &CPEMIs);
388 unsigned getUserOffset(CPUser&)
const;
391 bool isOffsetInRange(
unsigned UserOffset,
unsigned TrialOffset,
392 unsigned Disp,
bool NegativeOK);
393 bool isOffsetInRange(
unsigned UserOffset,
unsigned TrialOffset,
400 bool decrementCPEReferenceCount(
unsigned CPI,
MachineInstr* CPEMI);
401 int findInRangeCPEntry(CPUser& U,
unsigned UserOffset);
402 int findLongFormInRangeCPEntry(CPUser& U,
unsigned UserOffset);
403 bool findAvailableWater(CPUser&U,
unsigned UserOffset,
404 water_iterator &WaterIter);
405 void createNewWater(
unsigned CPUserIndex,
unsigned UserOffset,
407 bool handleConstantPoolUser(
unsigned CPUserIndex);
409 bool removeUnusedCPEntries();
412 bool DoDump =
false);
414 CPUser &U,
unsigned &Growth);
416 bool fixupImmediateBr(ImmBranch &Br);
417 bool fixupConditionalBr(ImmBranch &Br);
418 bool fixupUnconditionalBr(ImmBranch &Br);
420 void prescanForConstants();
427 bool MipsConstantIslands::isOffsetInRange
428 (
unsigned UserOffset,
unsigned TrialOffset,
430 return isOffsetInRange(UserOffset, TrialOffset,
431 U.getMaxDisp(), U.NegOk);
434 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
437 for (
unsigned J = 0,
E = BBInfo.size(); J !=
E; ++J) {
451 DEBUG(
dbgs() <<
"constant island machine function " <<
"\n");
457 DEBUG(
dbgs() <<
"constant island processing " <<
"\n");
462 if (!PrescannedForConstants) prescanForConstants();
466 MF->getRegInfo().invalidateLiveness();
470 MF->RenumberBlocks();
472 bool MadeChange =
false;
476 std::vector<MachineInstr*> CPEMIs;
478 doInitialPlacement(CPEMIs);
481 initPICLabelUId(CPEMIs.size());
486 initializeFunctionInfo(CPEMIs);
491 MadeChange |= removeUnusedCPEntries();
495 unsigned NoCPIters = 0, NoBRIters = 0;
498 DEBUG(
dbgs() <<
"Beginning CP iteration #" << NoCPIters <<
'\n');
499 bool CPChange =
false;
500 for (
unsigned i = 0, e = CPUsers.size(); i != e; ++i)
501 CPChange |= handleConstantPoolUser(i);
502 if (CPChange && ++NoCPIters > 30)
508 NewWaterList.clear();
510 DEBUG(
dbgs() <<
"Beginning BR iteration #" << NoBRIters <<
'\n');
511 bool BRChange =
false;
512 for (
unsigned i = 0, e = ImmBranches.size(); i != e; ++i)
513 BRChange |= fixupImmediateBr(ImmBranches[i]);
514 if (BRChange && ++NoBRIters > 30)
517 if (!CPChange && !BRChange)
535 MipsConstantIslands::doInitialPlacement(std::vector<MachineInstr*> &CPEMIs) {
541 unsigned MaxAlign =
Log2_32(MCP->getConstantPoolAlignment());
559 const std::vector<MachineConstantPoolEntry> &CPs = MCP->getConstants();
562 for (
unsigned i = 0, e = CPs.
size(); i != e; ++i) {
564 assert(Size >= 4 &&
"Too small constant pool entry");
565 unsigned Align = CPs[i].getAlignment();
569 assert((Size % Align) == 0 &&
"CP Entry not multiple of 4 bytes!");
572 unsigned LogAlign =
Log2_32(Align);
579 CPEMIs.push_back(CPEMI);
583 for (
unsigned a = LogAlign + 1; a <= MaxAlign; ++a)
584 if (InsPoint[a] == InsAt)
587 CPEntries.emplace_back(1, CPEntry(CPEMI, i));
589 DEBUG(
dbgs() <<
"Moved CPI#" << i <<
" to end of function, size = "
590 << Size <<
", align = " << Align <<
'\n');
615 MipsConstantIslands::CPEntry
616 *MipsConstantIslands::findConstPoolEntry(
unsigned CPI,
618 std::vector<CPEntry> &CPEs = CPEntries[CPI];
621 for (
unsigned i = 0, e = CPEs.size(); i != e; ++i) {
622 if (CPEs[i].CPEMI == CPEMI)
630 unsigned MipsConstantIslands::getCPELogAlign(
const MachineInstr &CPEMI) {
638 assert(CPI < MCP->getConstants().size() &&
"Invalid constant pool index.");
639 unsigned Align = MCP->getConstants()[CPI].getAlignment();
647 void MipsConstantIslands::
648 initializeFunctionInfo(
const std::vector<MachineInstr*> &CPEMIs) {
650 BBInfo.resize(MF->getNumBlockIDs());
660 adjustBBOffsetsAfter(&MF->front());
667 WaterList.push_back(&MBB);
669 if (
MI.isDebugValue())
672 int Opc =
MI.getOpcode();
691 case Mips::BeqzRxImm16:
697 case Mips::BeqzRxImmX16:
703 case Mips::BnezRxImm16:
709 case Mips::BnezRxImmX16:
741 unsigned MaxOffs = ((1 << (Bits-1))-1) * Scale;
742 ImmBranches.push_back(ImmBranch(&
MI, MaxOffs, isCond, UOpc));
745 if (Opc == Mips::CONSTPOOL_ENTRY)
749 for (
unsigned op = 0, e =
MI.getNumOperands();
op != e; ++
op)
750 if (
MI.getOperand(
op).isCPI()) {
759 unsigned LongFormBits = 0;
760 unsigned LongFormScale = 0;
761 unsigned LongFormOpcode = 0;
765 case Mips::LwRxPcTcp16:
768 LongFormOpcode = Mips::LwRxPcTcpX16;
772 case Mips::LwRxPcTcpX16:
779 unsigned CPI =
MI.getOperand(
op).getIndex();
781 unsigned MaxOffs = ((1 <<
Bits)-1) * Scale;
782 unsigned LongFormMaxOffs = ((1 << LongFormBits)-1) * LongFormScale;
783 CPUsers.push_back(CPUser(&
MI, CPEMI, MaxOffs, NegOk, LongFormMaxOffs,
787 CPEntry *CPE = findConstPoolEntry(CPI, CPEMI);
788 assert(CPE &&
"Cannot find a corresponding CPEntry!");
812 unsigned MipsConstantIslands::getOffsetOf(
MachineInstr *
MI)
const {
822 assert(
I != MBB->
end() &&
"Didn't find MI in its own basic block?");
823 Offset +=
TII->getInstSizeInBytes(*
I);
838 void MipsConstantIslands::updateForInsertedWaterBlock
850 std::lower_bound(WaterList.begin(), WaterList.end(), NewBB,
852 WaterList.insert(IP, NewBB);
855 unsigned MipsConstantIslands::getUserOffset(CPUser &U)
const {
856 return getOffsetOf(U.MI);
863 MipsConstantIslands::splitBlockBeforeInstr(
MachineInstr &MI) {
870 MF->insert(MBBI, NewBB);
891 MF->RenumberBlocks(NewBB);
902 std::lower_bound(WaterList.begin(), WaterList.end(), OrigBB,
905 if (WaterBB == OrigBB)
906 WaterList.
insert(std::next(IP), NewBB);
908 WaterList.insert(IP, OrigBB);
909 NewWaterList.insert(OrigBB);
923 adjustBBOffsetsAfter(OrigBB);
931 bool MipsConstantIslands::isOffsetInRange(
unsigned UserOffset,
932 unsigned TrialOffset,
unsigned MaxDisp,
934 if (UserOffset <= TrialOffset) {
936 if (TrialOffset - UserOffset <= MaxDisp)
938 }
else if (NegativeOK) {
939 if (UserOffset - TrialOffset <= MaxDisp)
949 bool MipsConstantIslands::isWaterInRange(
unsigned UserOffset,
952 unsigned CPELogAlign = getCPELogAlign(*U.CPEMI);
953 unsigned CPEOffset = BBInfo[Water->
getNumber()].postOffset(CPELogAlign);
954 unsigned NextBlockOffset, NextBlockAlignment;
956 if (NextBlock == MF->end()) {
957 NextBlockOffset = BBInfo[Water->
getNumber()].postOffset();
958 NextBlockAlignment = 0;
960 NextBlockOffset = BBInfo[NextBlock->getNumber()].Offset;
961 NextBlockAlignment = NextBlock->getAlignment();
963 unsigned Size = U.CPEMI->getOperand(2).getImm();
964 unsigned CPEEnd = CPEOffset +
Size;
969 if (CPEEnd > NextBlockOffset) {
970 Growth = CPEEnd - NextBlockOffset;
978 if (CPEOffset < UserOffset)
979 UserOffset += Growth;
984 return isOffsetInRange(UserOffset, CPEOffset, U);
989 bool MipsConstantIslands::isCPEntryInRange
992 bool NegOk,
bool DoDump) {
993 unsigned CPEOffset = getOffsetOf(CPEMI);
1000 <<
" max delta=" << MaxDisp
1001 <<
format(
" insn address=%#x", UserOffset)
1002 <<
" in BB#" << Block <<
": "
1004 <<
format(
"CPE address=%#x offset=%+d: ", CPEOffset,
1005 int(CPEOffset-UserOffset));
1009 return isOffsetInRange(UserOffset, CPEOffset, MaxDisp, NegOk);
1021 if (PredMI->
getOpcode() == Mips::Bimm16)
1029 for(
unsigned i = BBNum + 1, e = MF->getNumBlockIDs(); i < e; ++i) {
1032 unsigned Offset = BBInfo[i - 1].Offset + BBInfo[i - 1].Size;
1033 BBInfo[i].Offset =
Offset;
1042 bool MipsConstantIslands::decrementCPEReferenceCount(
unsigned CPI,
1045 CPEntry *CPE = findConstPoolEntry(CPI, CPEMI);
1046 assert(CPE &&
"Unexpected!");
1047 if (--CPE->RefCount == 0) {
1048 removeDeadCPEMI(CPEMI);
1049 CPE->CPEMI =
nullptr;
1062 int MipsConstantIslands::findInRangeCPEntry(CPUser& U,
unsigned UserOffset)
1068 if (isCPEntryInRange(UserMI, UserOffset, CPEMI, U.getMaxDisp(), U.NegOk,
1076 std::vector<CPEntry> &CPEs = CPEntries[CPI];
1077 for (
unsigned i = 0, e = CPEs.size(); i != e; ++i) {
1079 if (CPEs[i].CPEMI == CPEMI)
1082 if (CPEs[i].CPEMI ==
nullptr)
1084 if (isCPEntryInRange(UserMI, UserOffset, CPEs[i].CPEMI, U.getMaxDisp(),
1086 DEBUG(
dbgs() <<
"Replacing CPE#" << CPI <<
" with CPE#"
1087 << CPEs[i].CPI <<
"\n");
1089 U.CPEMI = CPEs[i].CPEMI;
1100 return decrementCPEReferenceCount(CPI, CPEMI) ? 2 : 1;
1114 int MipsConstantIslands::findLongFormInRangeCPEntry
1115 (CPUser& U,
unsigned UserOffset)
1121 if (isCPEntryInRange(UserMI, UserOffset, CPEMI,
1122 U.getLongFormMaxDisp(), U.NegOk,
1125 UserMI->
setDesc(
TII->get(U.getLongFormOpcode()));
1126 U.setMaxDisp(U.getLongFormMaxDisp());
1132 std::vector<CPEntry> &CPEs = CPEntries[CPI];
1133 for (
unsigned i = 0, e = CPEs.size(); i != e; ++i) {
1135 if (CPEs[i].CPEMI == CPEMI)
1138 if (CPEs[i].CPEMI ==
nullptr)
1140 if (isCPEntryInRange(UserMI, UserOffset, CPEs[i].CPEMI,
1141 U.getLongFormMaxDisp(), U.NegOk)) {
1142 DEBUG(
dbgs() <<
"Replacing CPE#" << CPI <<
" with CPE#"
1143 << CPEs[i].CPI <<
"\n");
1145 U.CPEMI = CPEs[i].CPEMI;
1156 return decrementCPEReferenceCount(CPI, CPEMI) ? 2 : 1;
1167 return ((1<<10)-1)*2;
1169 return ((1<<16)-1)*2;
1173 return ((1<<16)-1)*2;
1184 bool MipsConstantIslands::findAvailableWater(CPUser &U,
unsigned UserOffset,
1185 water_iterator &WaterIter) {
1186 if (WaterList.empty())
1189 unsigned BestGrowth = ~0u;
1190 for (water_iterator IP = std::prev(WaterList.end()),
B = WaterList.begin();;
1202 if (isWaterInRange(UserOffset, WaterBB, U, Growth) &&
1203 (WaterBB->
getNumber() < U.HighWaterMark->getNumber() ||
1204 NewWaterList.count(WaterBB)) && Growth < BestGrowth) {
1206 BestGrowth = Growth;
1209 <<
" Growth=" << Growth <<
'\n');
1212 if (BestGrowth == 0)
1218 return BestGrowth != ~0u;
1228 void MipsConstantIslands::createNewWater(
unsigned CPUserIndex,
1229 unsigned UserOffset,
1231 CPUser &U = CPUsers[CPUserIndex];
1234 unsigned CPELogAlign = getCPELogAlign(*CPEMI);
1244 unsigned CPEOffset = UserBBI.
postOffset(CPELogAlign) + Delta;
1246 if (isOffsetInRange(UserOffset, CPEOffset, U)) {
1248 <<
format(
", expected CPE offset %#x\n", CPEOffset));
1255 int UncondBr = Mips::Bimm16;
1258 ImmBranches.push_back(ImmBranch(&UserMBB->
back(),
1259 MaxDisp,
false, UncondBr));
1260 BBInfo[UserMBB->
getNumber()].Size += Delta;
1261 adjustBBOffsetsAfter(UserMBB);
1271 unsigned LogAlign = MF->getAlignment();
1272 assert(LogAlign >= CPELogAlign &&
"Over-aligned constant pool entry");
1273 unsigned BaseInsertOffset = UserOffset + U.getMaxDisp();
1280 BaseInsertOffset -= 4;
1283 <<
" la=" << LogAlign <<
'\n');
1289 if (BaseInsertOffset + 8 >= UserBBI.
postOffset()) {
1291 DEBUG(
dbgs() <<
format(
"Move inside block: %#x\n", BaseInsertOffset));
1293 unsigned EndInsertOffset = BaseInsertOffset + 4 +
1297 unsigned CPUIndex = CPUserIndex+1;
1298 unsigned NumCPUsers = CPUsers.size();
1300 for (
unsigned Offset = UserOffset +
TII->getInstSizeInBytes(*UserMI);
1301 Offset < BaseInsertOffset;
1302 Offset +=
TII->getInstSizeInBytes(*MI), MI = std::next(MI)) {
1303 assert(MI != UserMBB->
end() &&
"Fell off end of block");
1304 if (CPUIndex < NumCPUsers && CPUsers[CPUIndex].MI == MI) {
1305 CPUser &U = CPUsers[CPUIndex];
1306 if (!isOffsetInRange(Offset, EndInsertOffset, U)) {
1308 BaseInsertOffset -= 1u << LogAlign;
1309 EndInsertOffset -= 1u << LogAlign;
1315 EndInsertOffset += U.CPEMI->getOperand(2).getImm();
1320 NewMBB = splitBlockBeforeInstr(*--MI);
1327 bool MipsConstantIslands::handleConstantPoolUser(
unsigned CPUserIndex) {
1328 CPUser &U = CPUsers[CPUserIndex];
1334 unsigned UserOffset = getUserOffset(U);
1338 int result = findInRangeCPEntry(U, UserOffset);
1339 if (result==1)
return false;
1340 else if (result==2)
return true;
1346 if (findAvailableWater(U, UserOffset, IP)) {
1347 DEBUG(
dbgs() <<
"Found water in range\n");
1353 if (NewWaterList.erase(WaterBB))
1354 NewWaterList.
insert(NewIsland);
1363 result = findLongFormInRangeCPEntry(U, UserOffset);
1364 if (result != 0)
return true;
1367 createNewWater(CPUserIndex, UserOffset, NewMBB);
1376 if (IP != WaterList.end())
1377 NewWaterList.erase(WaterBB);
1380 NewWaterList.insert(NewIsland);
1387 if (IP != WaterList.end())
1388 WaterList.erase(IP);
1394 updateForInsertedWaterBlock(NewIsland);
1397 decrementCPEReferenceCount(CPI, CPEMI);
1401 unsigned ID = createPICLabelUId();
1405 U.HighWaterMark = NewIsland;
1408 CPEntries[CPI].push_back(CPEntry(U.CPEMI, ID, 1));
1416 adjustBBOffsetsAfter(&*--NewIsland->
getIterator());
1425 DEBUG(
dbgs() <<
" Moved CPE to #" << ID <<
" CPI=" << CPI
1433 void MipsConstantIslands::removeDeadCPEMI(
MachineInstr *CPEMI) {
1439 if (CPEBB->
empty()) {
1448 adjustBBOffsetsAfter(CPEBB);
1458 bool MipsConstantIslands::removeUnusedCPEntries() {
1459 unsigned MadeChange =
false;
1460 for (
unsigned i = 0, e = CPEntries.size(); i != e; ++i) {
1461 std::vector<CPEntry> &CPEs = CPEntries[i];
1462 for (
unsigned j = 0, ee = CPEs.size(); j != ee; ++j) {
1463 if (CPEs[j].RefCount == 0 && CPEs[j].CPEMI) {
1464 removeDeadCPEMI(CPEs[j].CPEMI);
1465 CPEs[j].CPEMI =
nullptr;
1475 bool MipsConstantIslands::isBBInRange
1478 unsigned BrOffset = getOffsetOf(MI) + PCAdj;
1479 unsigned DestOffset = BBInfo[DestBB->
getNumber()].Offset;
1483 <<
" max delta=" << MaxDisp
1484 <<
" from " << getOffsetOf(MI) <<
" to " << DestOffset
1485 <<
" offset " << int(DestOffset-BrOffset) <<
"\t" << *
MI);
1487 if (BrOffset <= DestOffset) {
1489 if (DestOffset-BrOffset <= MaxDisp)
1492 if (BrOffset-DestOffset <= MaxDisp)
1500 bool MipsConstantIslands::fixupImmediateBr(ImmBranch &Br) {
1506 if (isBBInRange(MI, DestBB, Br.MaxDisp))
1510 return fixupUnconditionalBr(Br);
1511 return fixupConditionalBr(Br);
1519 MipsConstantIslands::fixupUnconditionalBr(ImmBranch &Br) {
1524 unsigned BimmX16MaxDisp = ((1 << 16)-1) * 2;
1525 if (isBBInRange(MI, DestBB, BimmX16MaxDisp)) {
1526 Br.MaxDisp = BimmX16MaxDisp;
1542 Br.MaxDisp = ((1<<24)-1) * 2;
1546 adjustBBOffsetsAfter(MBB);
1550 DEBUG(
dbgs() <<
" Changed B to long jump " << *MI);
1559 MipsConstantIslands::fixupConditionalBr(ImmBranch &Br) {
1568 if (isBBInRange(MI, DestBB, LongFormMaxOff)) {
1569 Br.MaxDisp = LongFormMaxOff;
1588 unsigned OppositeBranchOpcode =
TII->getOppositeBranchOpc(Opcode);
1604 if (isBBInRange(MI, NewDest, Br.MaxDisp)) {
1605 DEBUG(
dbgs() <<
" Invert Bcc condition and swap its destination with "
1616 splitBlockBeforeInstr(*MI);
1619 int delta =
TII->getInstSizeInBytes(MBB->
back());
1627 <<
" also invert condition and change dest. to BB#"
1640 Br.MI = &MBB->
back();
1645 ImmBranches.push_back(ImmBranch(&MBB->
back(), MaxDisp,
false, Br.UncondBr));
1650 adjustBBOffsetsAfter(MBB);
1654 void MipsConstantIslands::prescanForConstants() {
1658 MF->begin(),
E = MF->end();
B !=
E; ++
B) {
1660 B->instr_begin(), EB =
B->instr_end();
I != EB; ++
I) {
1661 switch(
I->getDesc().getOpcode()) {
1662 case Mips::LwConstant32: {
1663 PrescannedForConstants =
true;
1664 DEBUG(
dbgs() <<
"constant island constant " << *
I <<
"\n");
1665 J =
I->getNumOperands();
1666 DEBUG(
dbgs() <<
"num operands " << J <<
"\n");
1668 if (Literal.
isImm()) {
1669 int64_t V = Literal.
getImm();
1670 DEBUG(
dbgs() <<
"literal " << V <<
"\n");
1674 unsigned index = MCP->getConstantPoolIndex(C, 4);
1675 I->getOperand(2).ChangeToImmediate(index);
1676 DEBUG(
dbgs() <<
"constant island constant " << *
I <<
"\n");
1677 I->setDesc(
TII->get(Mips::LwRxPcTcp16));
1678 I->RemoveOperand(1);
1679 I->RemoveOperand(1);
1694 return new MipsConstantIslands();
unsigned succ_size() const
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
A parsed version of the target data layout string in and methods for querying it. ...
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
static unsigned int branchTargetOperand(MachineInstr *MI)
static bool CompareMBBNumbers(const MachineBasicBlock *LHS, const MachineBasicBlock *RHS)
CompareMBBNumbers - Little predicate function to sort the WaterList by MBB ID.
STATISTIC(NumFunctions,"Total number of functions")
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
void RenumberBlocks(MachineBasicBlock *MBBFrom=nullptr)
RenumberBlocks - This discards all of the MachineBasicBlock numbers and recomputes them...
MachineBasicBlock * getMBB() const
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
void transferSuccessors(MachineBasicBlock *FromMBB)
Transfers all the successors from MBB to this machine basic block (i.e., copies all the successors Fr...
unsigned Offset
Offset - Distance from the beginning of the function to the beginning of this basic block...
static unsigned int branchMaxOffsets(unsigned int Opcode)
void computeBlockSize(MachineFunction *MF, MachineBasicBlock *MBB, BasicBlockInfo &BBI)
void setAlignment(unsigned Align)
Set alignment of the basic block.
BasicBlockInfo - Information about the offset and size of a single basic block.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
static cl::opt< bool > AlignConstantIslands("mips-align-constant-islands", cl::Hidden, cl::init(true), cl::desc("Align constant islands in code"))
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
unsigned getNumOperands() const
Access to explicit operands of the instruction.
bool isCPI() const
isCPI - Tests if this is a MO_ConstantPoolIndex operand.
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
static cl::opt< int > ConstantIslandsSmallOffset("mips-constant-islands-small-offset", cl::init(0), cl::desc("Make small offsets be this amount for testing purposes"), cl::Hidden)
static cl::opt< bool > NoLoadRelaxation("mips-constant-islands-no-load-relaxation", cl::init(false), cl::desc("Don't relax loads to long loads - for testing purposes"), cl::Hidden)
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
initializer< Ty > init(const Ty &Val)
static unsigned int longformBranchOpcode(unsigned int Opcode)
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
static MachineOperand CreateCPI(unsigned Idx, int Offset, unsigned char TargetFlags=0)
The instances of the Type class are immutable: once they are created, they are never changed...
static bool BBIsJumpedOver(MachineBasicBlock *MBB)
BBIsJumpedOver - Return true of the specified basic block's only predecessor unconditionally branches...
This is an important base class in LLVM.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const MachineOperand & getOperand(unsigned i) const
void setMBB(MachineBasicBlock *MBB)
unsigned getNumExplicitOperands() const
Returns the number of non-implicit operands.
FunctionPass class - This class is used to implement most global optimizations.
FunctionPass * createMipsConstantIslandPass()
Returns a pass that converts branches to long branches.
self_iterator getIterator()
MachineConstantPool * getConstantPool()
getConstantPool - Return the constant pool object for the current function.
succ_iterator succ_begin()
pred_iterator pred_begin()
static wasm::ValType getType(const TargetRegisterClass *RC)
static unsigned getUnconditionalBrDisp(int Opc)
getUnconditionalBrDisp - Returns the maximum displacement that can fit in the specific unconditional ...
static bool useConstantIslands()
Iterator for intrusive lists based on ilist_node.
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
void setDesc(const MCInstrDesc &tid)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one...
auto find(R &&Range, const T &Val) -> decltype(std::begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
unsigned Size
Size - Size of the basic block in bytes.
APFloat neg(APFloat X)
Returns the negated value of the argument.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
llvm_unreachable("Unknown RegBank!")
MachineFunctionProperties & set(Property P)
Representation of each machine instruction.
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
static IntegerType * getInt32Ty(LLVMContext &C)
static bool BBHasFallthrough(MachineBasicBlock *MBB)
BBHasFallthrough - Return true if the specified basic block can fallthrough into the block immediatel...
const MachineInstrBuilder & addConstantPoolIndex(unsigned Idx, int Offset=0, unsigned char TargetFlags=0) const
static MachineOperand CreateImm(int64_t Val)
void push_back(MachineInstr *MI)
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
MipsFunctionInfo - This class is derived from MachineFunction private Mips target-specific informatio...
Instructions::iterator instr_iterator
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
unsigned pred_size() const
std::vector< MachineBasicBlock * >::iterator succ_iterator
Properties which a MachineFunction may have at a given point in time.
bool isUnconditionalBranch(QueryType Type=AnyInBundle) const
Return true if this is a branch which always transfers control flow to some other block...
unsigned postOffset(unsigned LogAlign=0) const
Compute the offset immediately following this block.
unsigned getAlignment() const
Return alignment of the basic block.