64 #define DEBUG_TYPE "hexagon-pei"
148 using namespace llvm;
171 cl::desc(
"Enable stack frame shrink wrapping"));
175 cl::desc(
"Max count of stack frame shrink-wraps"));
223 bool HexagonCallFrameInformation::runOnMachineFunction(
MachineFunction &MF) {
230 HFI.insertCFIInstructions(MF);
235 "Hexagon call frame information",
false,
false)
238 return new HexagonCallFrameInformation();
246 if (Reg < Hexagon::D0 || Reg > Hexagon::D15)
252 if (*SubRegs > RegNo)
255 if (!RegNo || *SubRegs < RegNo)
265 static_assert(Hexagon::R1 > 0,
266 "Assume physical registers are encoded as positive integers");
271 for (
unsigned I = 1,
E = CSI.size();
I <
E; ++
I) {
283 for (
auto &
I : MBB) {
289 case Hexagon::PS_alloca:
290 case Hexagon::PS_aligna:
305 unsigned R = MO.getReg();
315 if (MO.isRegMask()) {
320 const uint32_t *BM = MO.getRegMask();
324 if (!(BM[R/32] & (1u << (R%32))))
337 unsigned RetOpc = I->getOpcode();
338 return RetOpc == Hexagon::PS_tailcall_i || RetOpc == Hexagon::PS_tailcall_r;
360 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4:
361 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4_PIC:
362 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4_EXT:
363 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4_EXT_PIC:
364 case Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT:
365 case Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT_PIC:
366 case Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4:
367 case Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_PIC:
393 static unsigned ShrinkCounter = 0;
414 for (RPOTType::rpo_iterator
I = RPOT.begin(),
E = RPOT.end();
I !=
E; ++
I)
415 RPO[(*I)->getNumber()] = RPON++;
421 unsigned BN = RPO[
I.getNumber()];
422 for (
auto SI =
I.succ_begin(), SE =
I.succ_end();
SI != SE; ++
SI) {
424 if (RPO[(*SI)->getNumber()] <= BN)
433 for (
const MCPhysReg *
P = HRI.getCalleeSavedRegs(&MF); *
P; ++
P)
442 dbgs() <<
"Blocks needing SF: {";
443 for (
auto &
B : SFBlocks)
444 dbgs() <<
" BB#" <<
B->getNumber();
448 if (SFBlocks.empty())
453 for (
unsigned i = 1, n = SFBlocks.size(); i < n; ++i) {
459 for (
unsigned i = 1, n = SFBlocks.size(); i < n; ++i) {
465 dbgs() <<
"Computed dom block: BB#";
467 else dbgs() <<
"<null>";
468 dbgs() <<
", computed pdom block: BB#";
470 else dbgs() <<
"<null>";
478 DEBUG(
dbgs() <<
"Dom block does not dominate pdom block\n");
482 DEBUG(
dbgs() <<
"PDom block does not post-dominate dom block\n");
506 findShrunkPrologEpilog(MF, PrologB, EpilogB);
508 bool PrologueStubs =
false;
509 insertCSRSpillsInBlock(*PrologB, CSI, HRI, PrologueStubs);
510 insertPrologueInBlock(*PrologB, PrologueStubs);
511 updateEntryPaths(MF, *PrologB);
514 insertCSRRestoresInBlock(*EpilogB, CSI, HRI);
515 insertEpilogueInBlock(*EpilogB);
518 if (
B.isReturnBlock())
519 insertCSRRestoresInBlock(
B, CSI, HRI);
522 if (
B.isReturnBlock())
523 insertEpilogueInBlock(
B);
541 BitVector DoneT(MaxBN+1), DoneF(MaxBN+1), Path(MaxBN+1);
542 updateExitPaths(*EpilogB, *EpilogB, DoneT, DoneF, Path);
547 bool PrologueStubs)
const {
563 FrameSize = MaxCFA +
alignTo(FrameSize, MaxAlign);
570 unsigned SP = HRI.getStackRegister();
577 if (
MI.getOpcode() == Hexagon::PS_alloca)
580 for (
auto MI : AdjustRegs) {
581 assert((
MI->getOpcode() == Hexagon::PS_alloca) &&
"Expected alloca");
582 expandAlloca(
MI, HII, SP, MaxCF);
583 MI->eraseFromParent();
586 DebugLoc dl = MBB.findDebugLoc(InsertPt);
589 insertAllocframe(MBB, InsertPt, NumBytes);
591 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::A2_andir), SP)
593 .
addImm(-int64_t(MaxAlign));
599 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::PS_call_stk))
600 .addExternalSymbol(
"__runtime_stack_check");
601 }
else if (NumBytes > 0) {
603 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::A2_addi), SP)
614 unsigned SP = HRI.getStackRegister();
622 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::A2_addi), SP)
630 unsigned RetOpc = RetI ? RetI->
getOpcode() : 0;
633 if (RetOpc == Hexagon::EH_RETURN_JMPR) {
634 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::L2_deallocframe));
635 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::A2_add), SP)
643 if (RetOpc == Hexagon::RESTORE_DEALLOC_RET_JMP_V4 ||
644 RetOpc == Hexagon::RESTORE_DEALLOC_RET_JMP_V4_PIC ||
645 RetOpc == Hexagon::RESTORE_DEALLOC_RET_JMP_V4_EXT ||
646 RetOpc == Hexagon::RESTORE_DEALLOC_RET_JMP_V4_EXT_PIC) {
650 while (It != MBB.
end()) {
662 bool NeedsDeallocframe =
true;
663 if (!MBB.
empty() && InsertPt != MBB.
begin()) {
665 unsigned COpc = PrevIt->getOpcode();
666 if (COpc == Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4 ||
667 COpc == Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_PIC ||
668 COpc == Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT ||
669 COpc == Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT_PIC ||
670 COpc == Hexagon::PS_call_nr || COpc == Hexagon::PS_callr_nr)
671 NeedsDeallocframe =
false;
674 if (!NeedsDeallocframe)
680 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::L2_deallocframe));
683 unsigned NewOpc = Hexagon::L4_return;
699 const unsigned int ALLOCFRAME_MAX = 16384;
708 if (NumBytes >= ALLOCFRAME_MAX) {
710 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::S2_allocframe))
715 unsigned SP = HRI.getStackRegister();
716 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::A2_addi), SP)
720 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::S2_allocframe))
736 for (
unsigned i = 0; i < Worklist.
size(); ++i) {
737 unsigned BN = Worklist[i];
753 if (Path[BN] || DoneF[BN])
761 bool ReachedExit =
false;
763 ReachedExit |= updateExitPaths(*
SB, RestoreB, DoneT, DoneF, Path);
779 if (ReachedExit && &MBB != &RestoreB) {
804 if (
I.getOpcode() == Hexagon::S2_allocframe)
805 return std::next(It);
809 bool HasCall =
false, HasAllocFrame =
false;
811 while (++
T !=
End &&
T->isBundled()) {
812 if (
T->getOpcode() == Hexagon::S2_allocframe)
813 HasAllocFrame =
true;
814 else if (
T->isCall())
818 return HasCall ? It : std::next(It);
827 insertCFIInstructionsAt(
B, At.getValue());
844 const MCInstrDesc &CFID = HII.get(TargetOpcode::CFI_INSTRUCTION);
847 bool HasFP =
hasFP(MF);
850 unsigned DwFPReg = HRI.getDwarfRegNum(HRI.getFrameRegister(),
true);
851 unsigned DwRAReg = HRI.getDwarfRegNum(HRI.getRARegister(),
true);
877 static unsigned int RegsToMove[] = {
878 Hexagon::R1, Hexagon::R0, Hexagon::R3,
Hexagon::R2,
879 Hexagon::R17, Hexagon::R16, Hexagon::R19, Hexagon::R18,
880 Hexagon::R21, Hexagon::R20, Hexagon::R23, Hexagon::R22,
881 Hexagon::R25, Hexagon::R24, Hexagon::R27, Hexagon::R26,
882 Hexagon::D0, Hexagon::D1, Hexagon::D8, Hexagon::D9,
883 Hexagon::D10, Hexagon::D11, Hexagon::D12, Hexagon::D13,
889 for (
unsigned i = 0; RegsToMove[i] != Hexagon::NoRegister; ++i) {
890 unsigned Reg = RegsToMove[i];
892 return C.getReg() ==
Reg;
915 if (Reg < Hexagon::D0 || Reg > Hexagon::D15) {
916 unsigned DwarfReg = HRI.getDwarfRegNum(Reg,
true);
928 unsigned HiReg = HRI.getSubReg(Reg, Hexagon::isub_hi);
929 unsigned LoReg = HRI.getSubReg(Reg, Hexagon::isub_lo);
930 unsigned HiDwarfReg = HRI.getDwarfRegNum(HiReg,
true);
931 unsigned LoDwarfReg = HRI.getDwarfRegNum(LoReg,
true);
950 bool HasExtraAlign = HRI.needsStackRealignment(MF);
966 if (HasAlloca || HasExtraAlign)
979 if (MFI.
hasCalls() || HMFI.hasClobberLR())
992 bool Stkchk =
false) {
993 const char * V4SpillToMemoryFunctions[] = {
994 "__save_r16_through_r17",
995 "__save_r16_through_r19",
996 "__save_r16_through_r21",
997 "__save_r16_through_r23",
998 "__save_r16_through_r25",
999 "__save_r16_through_r27" };
1001 const char * V4SpillToMemoryStkchkFunctions[] = {
1002 "__save_r16_through_r17_stkchk",
1003 "__save_r16_through_r19_stkchk",
1004 "__save_r16_through_r21_stkchk",
1005 "__save_r16_through_r23_stkchk",
1006 "__save_r16_through_r25_stkchk",
1007 "__save_r16_through_r27_stkchk" };
1009 const char * V4SpillFromMemoryFunctions[] = {
1010 "__restore_r16_through_r17_and_deallocframe",
1011 "__restore_r16_through_r19_and_deallocframe",
1012 "__restore_r16_through_r21_and_deallocframe",
1013 "__restore_r16_through_r23_and_deallocframe",
1014 "__restore_r16_through_r25_and_deallocframe",
1015 "__restore_r16_through_r27_and_deallocframe" };
1017 const char * V4SpillFromMemoryTailcallFunctions[] = {
1018 "__restore_r16_through_r17_and_deallocframe_before_tailcall",
1019 "__restore_r16_through_r19_and_deallocframe_before_tailcall",
1020 "__restore_r16_through_r21_and_deallocframe_before_tailcall",
1021 "__restore_r16_through_r23_and_deallocframe_before_tailcall",
1022 "__restore_r16_through_r25_and_deallocframe_before_tailcall",
1023 "__restore_r16_through_r27_and_deallocframe_before_tailcall"
1026 const char **SpillFunc =
nullptr;
1030 SpillFunc = Stkchk ? V4SpillToMemoryStkchkFunctions
1031 : V4SpillToMemoryFunctions;
1034 SpillFunc = V4SpillFromMemoryFunctions;
1037 SpillFunc = V4SpillFromMemoryTailcallFunctions;
1040 assert(SpillFunc &&
"Unknown spill kind");
1045 return SpillFunc[0];
1047 return SpillFunc[1];
1049 return SpillFunc[2];
1051 return SpillFunc[3];
1053 return SpillFunc[4];
1055 return SpillFunc[5];
1063 int FI,
unsigned &FrameReg)
const {
1069 bool HasExtraAlign = HRI.needsStackRealignment(MF);
1074 unsigned SP = HRI.getStackRegister();
1075 unsigned FP = HRI.getFrameRegister();
1076 unsigned AP = HMFI.getStackAlignBasePhysReg();
1094 bool UseFP =
false, UseAP =
false;
1099 if (NoOpt && !HasExtraAlign)
1104 UseFP |= (HasAlloca || HasExtraAlign);
1115 bool HasFP =
hasFP(MF);
1116 assert((HasFP || !UseFP) &&
"This function must have frame pointer");
1142 if (Offset > 0 && !HasFP)
1157 if (!UseFP && !UseAP)
1158 RealOffset = FrameSize+
Offset;
1164 bool &PrologueStubs)
const {
1169 PrologueStubs =
false;
1174 if (useSpillFunction(MF, CSI)) {
1175 PrologueStubs =
true;
1187 if (StkOvrFlowEnabled) {
1189 SpillOpc = IsPIC ? Hexagon::SAVE_REGISTERS_CALL_V4STK_EXT_PIC
1190 : Hexagon::SAVE_REGISTERS_CALL_V4STK_EXT;
1192 SpillOpc = IsPIC ? Hexagon::SAVE_REGISTERS_CALL_V4STK_PIC
1193 : Hexagon::SAVE_REGISTERS_CALL_V4STK;
1196 SpillOpc = IsPIC ? Hexagon::SAVE_REGISTERS_CALL_V4_EXT_PIC
1197 : Hexagon::SAVE_REGISTERS_CALL_V4_EXT;
1199 SpillOpc = IsPIC ? Hexagon::SAVE_REGISTERS_CALL_V4_PIC
1200 : Hexagon::SAVE_REGISTERS_CALL_V4;
1204 BuildMI(MBB, MI, DL, HII.get(SpillOpc))
1205 .addExternalSymbol(SpillFun);
1208 addCalleeSaveRegistersAsImpOperand(SaveRegsCall, CSI,
false,
true);
1210 for (
unsigned I = 0;
I < CSI.size(); ++
I)
1215 for (
unsigned i = 0, n = CSI.size(); i < n; ++i) {
1216 unsigned Reg = CSI[i].getReg();
1221 int FI = CSI[i].getFrameIdx();
1223 HII.storeRegToStackSlot(MBB, MI, Reg, IsKill, FI, RC, &HRI);
1240 if (useRestoreFunction(MF, CSI)) {
1246 bool IsPIC = HTM.isPositionIndependent();
1257 RetOpc = IsPIC ? Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT_PIC
1258 : Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT;
1260 RetOpc = IsPIC ? Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_PIC
1261 : Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4;
1262 DeallocCall =
BuildMI(MBB, MI, DL, HII.get(RetOpc))
1263 .addExternalSymbol(RestoreFn);
1267 assert(It->isReturn() && std::next(It) == MBB.
end());
1270 RetOpc = IsPIC ? Hexagon::RESTORE_DEALLOC_RET_JMP_V4_EXT_PIC
1271 : Hexagon::RESTORE_DEALLOC_RET_JMP_V4_EXT;
1273 RetOpc = IsPIC ? Hexagon::RESTORE_DEALLOC_RET_JMP_V4_PIC
1274 : Hexagon::RESTORE_DEALLOC_RET_JMP_V4;
1275 DeallocCall =
BuildMI(MBB, It, DL, HII.get(RetOpc))
1276 .addExternalSymbol(RestoreFn);
1280 addCalleeSaveRegistersAsImpOperand(DeallocCall, CSI,
true,
false);
1284 for (
unsigned i = 0; i < CSI.size(); ++i) {
1285 unsigned Reg = CSI[i].getReg();
1287 int FI = CSI[i].getFrameIdx();
1288 HII.loadRegFromStackSlot(MBB, MI, Reg, FI, RC, &HRI);
1300 assert((Opc == Hexagon::ADJCALLSTACKDOWN || Opc == Hexagon::ADJCALLSTACKUP) &&
1301 "Cannot handle this call frame pseudo instruction");
1302 return MBB.
erase(I);
1315 if (!HasAlloca || !NeedsAlign)
1333 assert(A <= 8 &&
"Unexpected local frame alignment");
1341 AP = AI->getOperand(0).getReg();
1351 auto IsUsed = [&HRI,&
MRI] (
unsigned Reg) ->
bool {
1384 BitVector SRegs(Hexagon::NUM_TARGET_REGS);
1392 DEBUG(
dbgs() <<
"Initial CS registers: {");
1393 for (
unsigned i = 0, n = CSI.size(); i < n; ++i) {
1394 unsigned R = CSI[i].getReg();
1405 for (
int x = Reserved.find_first(); x >= 0; x = Reserved.find_next(x)) {
1417 BitVector TmpSup(Hexagon::NUM_TARGET_REGS);
1423 for (
int x = TmpSup.find_first(); x >= 0; x = TmpSup.find_next(x)) {
1459 for (
const SpillSlot *S = FixedSlots; S != FixedSlots+NumFixed; ++S) {
1463 int FI = MFI.CreateFixedSpillStackObject(TRI->
getSpillSize(*RC), S->Offset);
1464 MinOffset =
std::min(MinOffset, S->Offset);
1466 SRegs[S->Reg] =
false;
1476 int Off = MinOffset -
Size;
1480 int FI = MFI.CreateFixedSpillStackObject(Size, Off);
1481 MinOffset =
std::min(MinOffset, Off);
1487 dbgs() <<
"CS information: {";
1488 for (
unsigned i = 0, n = CSI.size(); i < n; ++i) {
1489 int FI = CSI[i].getFrameIdx();
1490 int Off = MFI.getObjectOffset(FI);
1501 bool MissedReg =
false;
1521 if (!Hexagon::ModRegsRegClass.
contains(DstR) ||
1522 !Hexagon::ModRegsRegClass.
contains(SrcR))
1527 BuildMI(B, It, DL, HII.get(TargetOpcode::COPY), DstR)
1551 unsigned TfrOpc = (Opc == Hexagon::STriw_pred) ? Hexagon::C2_tfrpr
1552 : Hexagon::A2_tfrcrr;
1553 BuildMI(B, It, DL, HII.get(TfrOpc), TmpR)
1557 BuildMI(B, It, DL, HII.get(Hexagon::S2_storeri_io))
1582 BuildMI(B, It, DL, HII.get(Hexagon::L2_loadri_io), TmpR)
1589 unsigned TfrOpc = (Opc == Hexagon::LDriw_pred) ? Hexagon::C2_tfrrp
1590 : Hexagon::A2_tfrrcr;
1591 BuildMI(B, It, DL, HII.get(TfrOpc), DstR)
1604 if (!MI->getOperand(0).isFI())
1608 unsigned SrcR = MI->getOperand(2).getReg();
1609 bool IsKill = MI->getOperand(2).isKill();
1610 int FI = MI->getOperand(0).getIndex();
1612 bool Is128B = HST.useHVXDblOps();
1613 auto *RC = !Is128B ? &Hexagon::VectorRegsRegClass
1614 : &Hexagon::VectorRegs128BRegClass;
1623 BuildMI(B, It, DL, HII.get(Hexagon::A2_tfrsi), TmpR0)
1624 .addImm(0x01010101);
1626 unsigned VandOpc = !Is128B ? Hexagon::V6_vandqrt : Hexagon::V6_vandqrt_128B;
1627 BuildMI(B, It, DL, HII.get(VandOpc), TmpR1)
1633 expandStoreVec(B, std::prev(It), MRI, HII, NewRegs);
1646 if (!MI->getOperand(1).isFI())
1650 unsigned DstR = MI->getOperand(0).getReg();
1651 int FI = MI->getOperand(1).getIndex();
1653 bool Is128B = HST.useHVXDblOps();
1654 auto *RC = !Is128B ? &Hexagon::VectorRegsRegClass
1655 : &Hexagon::VectorRegs128BRegClass;
1663 BuildMI(B, It, DL, HII.get(Hexagon::A2_tfrsi), TmpR0)
1664 .addImm(0x01010101);
1667 expandLoadVec(B, std::prev(It), MRI, HII, NewRegs);
1669 unsigned VandOpc = !Is128B ? Hexagon::V6_vandvrt : Hexagon::V6_vandvrt_128B;
1670 BuildMI(B, It, DL, HII.get(VandOpc), DstR)
1698 for (
auto R = B.
begin(); R != It; ++R) {
1700 LPR.stepForward(*R, Clobbers);
1703 for (
auto &
C : Clobbers)
1704 if (
C.second->isReg() &&
C.second->isDead())
1705 LPR.removeReg(
C.first);
1710 unsigned SrcLo = HRI.getSubReg(SrcR, Hexagon::vsub_lo);
1711 unsigned SrcHi = HRI.getSubReg(SrcR, Hexagon::vsub_hi);
1715 bool Is128B = HST.useHVXDblOps();
1716 const auto &RC = !Is128B ? Hexagon::VectorRegsRegClass
1717 : Hexagon::VectorRegs128BRegClass;
1718 unsigned Size = HRI.getSpillSize(RC);
1719 unsigned NeedAlign = HRI.getSpillAlignment(RC);
1720 unsigned HasAlign = MFI.getObjectAlignment(FI);
1724 if (LPR.contains(SrcLo)) {
1725 if (NeedAlign <= HasAlign)
1726 StoreOpc = !Is128B ? Hexagon::V6_vS32b_ai : Hexagon::V6_vS32b_ai_128B;
1728 StoreOpc = !Is128B ? Hexagon::V6_vS32Ub_ai : Hexagon::V6_vS32Ub_ai_128B;
1730 BuildMI(B, It, DL, HII.get(StoreOpc))
1738 if (LPR.contains(SrcHi)) {
1739 if (NeedAlign <=
MinAlign(HasAlign, Size))
1740 StoreOpc = !Is128B ? Hexagon::V6_vS32b_ai : Hexagon::V6_vS32b_ai_128B;
1742 StoreOpc = !Is128B ? Hexagon::V6_vS32Ub_ai : Hexagon::V6_vS32Ub_ai_128B;
1744 BuildMI(B, It, DL, HII.get(StoreOpc))
1768 unsigned DstHi = HRI.getSubReg(DstR, Hexagon::vsub_hi);
1769 unsigned DstLo = HRI.getSubReg(DstR, Hexagon::vsub_lo);
1772 bool Is128B = HST.useHVXDblOps();
1773 const auto &RC = !Is128B ? Hexagon::VectorRegsRegClass
1774 : Hexagon::VectorRegs128BRegClass;
1775 unsigned Size = HRI.getSpillSize(RC);
1776 unsigned NeedAlign = HRI.getSpillAlignment(RC);
1777 unsigned HasAlign = MFI.getObjectAlignment(FI);
1781 if (NeedAlign <= HasAlign)
1782 LoadOpc = !Is128B ? Hexagon::V6_vL32b_ai : Hexagon::V6_vL32b_ai_128B;
1784 LoadOpc = !Is128B ? Hexagon::V6_vL32Ub_ai : Hexagon::V6_vL32Ub_ai_128B;
1786 BuildMI(B, It, DL, HII.get(LoadOpc), DstLo)
1792 if (NeedAlign <=
MinAlign(HasAlign, Size))
1793 LoadOpc = !Is128B ? Hexagon::V6_vL32b_ai : Hexagon::V6_vL32b_ai_128B;
1795 LoadOpc = !Is128B ? Hexagon::V6_vL32Ub_ai : Hexagon::V6_vL32Ub_ai_128B;
1797 BuildMI(B, It, DL, HII.get(LoadOpc), DstHi)
1816 auto &HRI = *HST.getRegisterInfo();
1822 bool Is128B = HST.useHVXDblOps();
1823 const auto &RC = !Is128B ? Hexagon::VectorRegsRegClass
1824 : Hexagon::VectorRegs128BRegClass;
1825 unsigned NeedAlign = HRI.getSpillAlignment(RC);
1826 unsigned HasAlign = MFI.getObjectAlignment(FI);
1829 if (NeedAlign <= HasAlign)
1830 StoreOpc = !Is128B ? Hexagon::V6_vS32b_ai : Hexagon::V6_vS32b_ai_128B;
1832 StoreOpc = !Is128B ? Hexagon::V6_vS32Ub_ai : Hexagon::V6_vS32Ub_ai_128B;
1834 BuildMI(B, It, DL, HII.get(StoreOpc))
1854 auto &HRI = *HST.getRegisterInfo();
1859 bool Is128B = HST.useHVXDblOps();
1860 const auto &RC = !Is128B ? Hexagon::VectorRegsRegClass
1861 : Hexagon::VectorRegs128BRegClass;
1862 unsigned NeedAlign = HRI.getSpillAlignment(RC);
1863 unsigned HasAlign = MFI.getObjectAlignment(FI);
1866 if (NeedAlign <= HasAlign)
1867 LoadOpc = !Is128B ? Hexagon::V6_vL32b_ai : Hexagon::V6_vL32b_ai_128B;
1869 LoadOpc = !Is128B ? Hexagon::V6_vL32Ub_ai : Hexagon::V6_vL32Ub_ai_128B;
1871 BuildMI(B, It, DL, HII.get(LoadOpc), DstR)
1883 auto &HII = *HST.getInstrInfo();
1885 bool Changed =
false;
1887 for (
auto &B : MF) {
1892 NextI = std::next(
I);
1896 case TargetOpcode::COPY:
1897 Changed |= expandCopy(B,
I, MRI, HII, NewRegs);
1899 case Hexagon::STriw_pred:
1900 case Hexagon::STriw_mod:
1901 Changed |= expandStoreInt(B,
I, MRI, HII, NewRegs);
1903 case Hexagon::LDriw_pred:
1904 case Hexagon::LDriw_mod:
1905 Changed |= expandLoadInt(B,
I, MRI, HII, NewRegs);
1907 case Hexagon::PS_vstorerq_ai:
1908 case Hexagon::PS_vstorerq_ai_128B:
1909 Changed |= expandStoreVecPred(B,
I, MRI, HII, NewRegs);
1911 case Hexagon::PS_vloadrq_ai:
1912 case Hexagon::PS_vloadrq_ai_128B:
1913 Changed |= expandLoadVecPred(B,
I, MRI, HII, NewRegs);
1915 case Hexagon::PS_vloadrw_ai:
1916 case Hexagon::PS_vloadrwu_ai:
1917 case Hexagon::PS_vloadrw_ai_128B:
1918 case Hexagon::PS_vloadrwu_ai_128B:
1919 Changed |= expandLoadVec2(B,
I, MRI, HII, NewRegs);
1921 case Hexagon::PS_vstorerw_ai:
1922 case Hexagon::PS_vstorerwu_ai:
1923 case Hexagon::PS_vstorerw_ai_128B:
1924 case Hexagon::PS_vstorerwu_ai_128B:
1925 Changed |= expandStoreVec2(B,
I, MRI, HII, NewRegs);
1938 auto &HRI = *HST.getRegisterInfo();
1940 SavedRegs.
resize(HRI.getNumRegs());
1945 for (
const MCPhysReg *R = HRI.getCalleeSavedRegs(&MF); *R; ++R)
1950 expandSpillMacros(MF, NewRegs);
1952 optimizeSpillSlots(MF, NewRegs);
1956 if (!NewRegs.
empty() || mayOverflowFrameOffset(MF)) {
1962 SpillRCs.
insert(&Hexagon::IntRegsRegClass);
1964 for (
unsigned VR : NewRegs)
1967 for (
auto *RC : SpillRCs) {
1971 unsigned S = HRI.getSpillSize(*RC),
A = HRI.getSpillAlignment(*RC);
1972 for (
unsigned i = 0; i < Num; i++) {
1990 auto isDead = [&FIR,&DeadMap] (
unsigned Reg) ->
bool {
1991 auto F = DeadMap.find({
Reg,0});
1992 if (
F == DeadMap.end())
1994 for (
auto &DR :
F->second)
1995 if (DR.contains(FIR))
2018 auto &HRI = *HST.getRegisterInfo();
2022 typedef std::map<MachineBasicBlock*,HexagonBlockRanges::InstrIndexMap>
2024 typedef std::map<MachineBasicBlock*,HexagonBlockRanges::RangeList>
2033 SlotInfo() =
default;
2036 BlockIndexMap BlockIndexes;
2038 std::map<int,SlotInfo> FIRangeMap;
2047 if (HaveRC ==
nullptr || HaveRC == NewRC)
2052 if (NewRC->hasSubClassEq(HaveRC))
2059 for (
auto &B : MF) {
2060 std::map<int,IndexType> LastStore, LastLoad;
2063 auto P = BlockIndexes.insert(
2065 auto &IndexMap =
P.first->second;
2067 << IndexMap <<
'\n');
2069 for (
auto &
In : B) {
2071 bool Load = HII.isLoadFromStackSlot(
In, LFI) && !HII.isPredicated(
In);
2072 bool Store = HII.isStoreToStackSlot(
In, SFI) && !HII.isPredicated(
In);
2073 if (Load && Store) {
2085 if (Load || Store) {
2086 int TFI = Load ? LFI : SFI;
2087 unsigned AM = HII.getAddrMode(
In);
2088 SlotInfo &
SI = FIRangeMap[TFI];
2092 unsigned OpNum = Load ? 0 : 2;
2093 auto *RC = HII.getRegClass(
In.getDesc(), OpNum, &HRI, MF);
2094 RC = getCommonRC(SI.RC, RC);
2102 unsigned S = (1U << (HII.getMemAccessSize(
In) - 1));
2103 if (SI.Size != 0 && SI.Size != S)
2109 for (
auto *Mo :
In.memoperands()) {
2110 if (!Mo->isVolatile())
2121 for (
unsigned i = 0, n =
In.getNumOperands(); i < n; ++i) {
2128 if (i+1 >= n || !
In.getOperand(i+1).isImm() ||
2129 In.getOperand(i+1).getImm() != 0)
2131 if (BadFIs.
count(FI))
2137 LastStore[FI] = IndexType::Entry;
2138 LastLoad[FI] = Index;
2142 RL.
add(LastStore[FI], LastLoad[FI],
false,
false);
2144 RL.
add(IndexType::Entry, LastLoad[FI],
false,
false);
2146 LastStore[FI] = Index;
2153 for (
auto &
I : LastLoad) {
2154 IndexType LL =
I.second;
2157 auto &RL = FIRangeMap[
I.first].Map[&
B];
2158 IndexType &
LS = LastStore[
I.first];
2160 RL.
add(LS, LL,
false,
false);
2162 RL.
add(IndexType::Entry, LL,
false,
false);
2165 for (
auto &
I : LastStore) {
2166 IndexType LS =
I.second;
2169 auto &RL = FIRangeMap[
I.first].Map[&
B];
2175 for (
auto &
P : FIRangeMap) {
2176 dbgs() <<
"fi#" <<
P.first;
2177 if (BadFIs.
count(
P.first))
2180 if (
P.second.RC !=
nullptr)
2181 dbgs() << HRI.getRegClassName(
P.second.RC) <<
'\n';
2183 dbgs() <<
"<null>\n";
2184 for (
auto &R :
P.second.Map)
2185 dbgs() <<
" BB#" << R.first->getNumber() <<
" { " << R.second <<
"}\n";
2194 std::map<MachineBasicBlock*,std::vector<int>> BlockFIMap;
2196 for (
auto &
P : FIRangeMap) {
2198 if (BadFIs.
count(
P.first))
2200 for (
auto &B : MF) {
2201 auto F =
P.second.Map.find(&B);
2203 if (
F ==
P.second.Map.end() ||
F->second.empty())
2206 if (IR.
start() == IndexType::Entry)
2207 LoxFIs.insert(
P.first);
2208 BlockFIMap[&
B].push_back(
P.first);
2213 dbgs() <<
"Block-to-FI map (* -- live-on-exit):\n";
2214 for (
auto &
P : BlockFIMap) {
2215 auto &FIs =
P.second;
2218 dbgs() <<
" BB#" <<
P.first->getNumber() <<
": {";
2219 for (
auto I : FIs) {
2220 dbgs() <<
" fi#" <<
I;
2221 if (LoxFIs.count(
I))
2233 for (
auto &B : MF) {
2234 auto F = BlockIndexes.find(&B);
2235 assert(
F != BlockIndexes.end());
2239 DEBUG(
dbgs() <<
"BB#" << B.getNumber() <<
" dead map\n"
2242 for (
auto FI : BlockFIMap[&B]) {
2243 if (BadFIs.
count(FI))
2245 DEBUG(
dbgs() <<
"Working on fi#" << FI <<
'\n');
2247 for (
auto &Range : RL) {
2248 DEBUG(
dbgs() <<
"--Examining range:" << RL <<
'\n');
2249 if (!IndexType::isInstr(Range.start()) ||
2250 !IndexType::isInstr(Range.end()))
2259 SrcOp.getSubReg() };
2260 auto *RC = HII.getRegClass(SI.
getDesc(), 2, &HRI, MF);
2262 unsigned FoundR = this->findPhysReg(MF, Range, IM, DM, RC);
2277 if (SrcRR.
Reg != FoundR || SrcRR.
Sub != 0) {
2279 CopyIn =
BuildMI(B, StartIt, DL, HII.get(TargetOpcode::COPY), FoundR)
2285 if (LoxFIs.count(FI) && (&Range == &RL.back())) {
2287 if (
unsigned SR = SrcOp.getSubReg())
2288 SrcOp.setReg(HRI.getSubReg(FoundR, SR));
2290 SrcOp.setReg(FoundR);
2293 SrcOp.setIsKill(
false);
2296 IM.replaceInstr(&SI, CopyIn);
2300 for (
auto It = StartIt; It != EndIt; It = NextIt) {
2302 NextIt = std::next(It);
2304 if (!HII.isLoadFromStackSlot(MI, TFI) || TFI != FI)
2309 if (DstR != FoundR) {
2311 unsigned MemSize = (1U << (HII.getMemAccessSize(MI) - 1));
2313 unsigned CopyOpc = TargetOpcode::COPY;
2314 if (HII.isSignExtendingLoad(MI))
2315 CopyOpc = (MemSize == 1) ? Hexagon::A2_sxtb : Hexagon::A2_sxth;
2316 else if (HII.isZeroExtendingLoad(MI))
2317 CopyOpc = (MemSize == 1) ? Hexagon::A2_zxtb : Hexagon::A2_zxth;
2318 CopyOut =
BuildMI(B, It, DL, HII.get(CopyOpc), DstR)
2321 IM.replaceInstr(&MI, CopyOut);
2328 DM[RR].subtract(Range);
2334 void HexagonFrameLowering::expandAlloca(
MachineInstr *AI,
2360 BuildMI(MB, AI, DL, HII.get(Hexagon::A2_sub), Rd)
2365 BuildMI(MB, AI, DL, HII.get(Hexagon::A2_sub), SP)
2371 BuildMI(MB, AI, DL, HII.get(Hexagon::A2_andir), Rd)
2375 BuildMI(MB, AI, DL, HII.get(Hexagon::A2_andir), SP)
2381 BuildMI(MB, AI, DL, HII.get(TargetOpcode::COPY), SP)
2386 BuildMI(MB, AI, DL, HII.get(Hexagon::A2_addi), Rd)
2406 if (
I.getOpcode() == Hexagon::PS_aligna)
2413 void HexagonFrameLowering::addCalleeSaveRegistersAsImpOperand(
MachineInstr *MI,
2414 const CSIVect &CSI,
bool IsDef,
bool IsKill)
const {
2425 const CSIVect &CSI)
const {
2437 for (
unsigned i = 0, n = CSI.size(); i < n; ++i) {
2438 unsigned R = CSI[i].getReg();
2439 if (!Hexagon::DoubleRegsRegClass.
contains(R))
2443 int F =
Regs.find_first();
2444 if (F != Hexagon::D8)
2447 int N =
Regs.find_next(F);
2448 if (N >= 0 && N != F+1)
2456 bool HexagonFrameLowering::useSpillFunction(
const MachineFunction &MF,
2457 const CSIVect &CSI)
const {
2458 if (shouldInlineCSR(MF, CSI))
2460 unsigned NumCSI = CSI.size();
2466 return Threshold < NumCSI;
2469 bool HexagonFrameLowering::useRestoreFunction(
const MachineFunction &MF,
2470 const CSIVect &CSI)
const {
2471 if (shouldInlineCSR(MF, CSI))
2481 unsigned NumCSI = CSI.size();
2487 return Threshold < NumCSI;
2490 bool HexagonFrameLowering::mayOverflowFrameOffset(
MachineFunction &MF)
const {
2495 if (HST.useHVXOps() && StackSize > 256)
2502 bool HasImmStack =
false;
2503 unsigned MinLS = ~0u;
2509 case Hexagon::S4_storeirit_io:
2510 case Hexagon::S4_storeirif_io:
2511 case Hexagon::S4_storeiri_io:
2514 case Hexagon::S4_storeirht_io:
2515 case Hexagon::S4_storeirhf_io:
2516 case Hexagon::S4_storeirh_io:
2519 case Hexagon::S4_storeirbt_io:
2520 case Hexagon::S4_storeirbf_io:
2521 case Hexagon::S4_storeirb_io:
2531 return !isUInt<6>(StackSize >> MinLS);
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
void push_back(const T &Elt)
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const MCPhysReg * getCallerSavedRegs(const MachineFunction *MF, const TargetRegisterClass *RC) const
int find_first() const
find_first - Returns the index of the first set bit, -1 if none of the bits are set.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
instr_iterator instr_end()
void mapLocalFrameObject(int ObjectIndex, int64_t Offset)
Map a frame index into the local object block.
static cl::opt< int > SpillFuncThresholdOs("spill-func-threshold-Os", cl::Hidden, cl::desc("Specify Os spill func threshold"), cl::init(1), cl::ZeroOrMore)
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const override
Store the specified register of the given register class to the specified stack frame index...
unsigned createVirtualRegister(const TargetRegisterClass *RegClass)
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
MachineBasicBlock * findNearestCommonDominator(MachineBasicBlock *A, MachineBasicBlock *B)
bool hasSubClassEq(const TargetRegisterClass *RC) const
Returns true if RC is a sub-class of or equal to this class.
int find_next(unsigned Prev) const
find_next - Returns the index of the next set bit following the "Prev" bit.
static Optional< MachineBasicBlock::iterator > findCFILocation(MachineBasicBlock &B)
unsigned getSpillAlignment(const TargetRegisterClass &RC) const
Return the minimum required alignment for a spill slot for a register of this class.
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
Describe properties that are true of each instruction in the target description file.
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
static MCCFIInstruction createOffset(MCSymbol *L, unsigned Register, int Offset)
.cfi_offset Previous value of Register is saved at offset Offset from CFA.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
static void dump_registers(BitVector &Regs, const TargetRegisterInfo &TRI)
static RegisterSet expandToSubRegs(RegisterRef R, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI)
static const MCPhysReg VRegs[32]
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
Hexagon target-specific information for each MachineFunction.
const SpillSlot * getCalleeSavedSpillSlots(unsigned &NumEntries) const override
getCalleeSavedSpillSlots - This method returns a pointer to an array of pairs, that contains an entry...
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
static const char * getSpillFunctionFor(unsigned MaxReg, SpillKind SpillType, bool Stkchk=false)
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
static unsigned SpillOptCount
static cl::opt< int > SpillFuncThreshold("spill-func-threshold", cl::Hidden, cl::desc("Specify O2(not Os) spill func threshold"), cl::init(6), cl::ZeroOrMore)
iterator_range< mop_iterator > operands()
static cl::opt< unsigned > SpillOptMax("spill-opt-max", cl::Hidden, cl::init(std::numeric_limits< unsigned >::max()))
size_type size() const
Determine the number of elements in the SetVector.
const MachineInstrBuilder & addCFIIndex(unsigned CFIIndex) const
bool optForSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
bool isObjectPreAllocated(int ObjectIdx) const
Return true if the object was pre-allocated into the local block.
void setStackAlignBasePhysReg(unsigned R)
bool optForMinSize() const
Optimize this function for minimum size (-Oz).
return AArch64::GPR64RegClass contains(Reg)
iterator_range< succ_iterator > successors()
StringRef getName() const
Return a constant reference to the value's name.
INITIALIZE_PASS(HexagonCallFrameInformation,"hexagon-cfi","Hexagon call frame information", false, false) FunctionPass *llvm
unsigned getMaxAlignment() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects...
int64_t getLocalFrameSize() const
Get the size of the local object blob.
void add(IndexType Start, IndexType End, bool Fixed, bool TiedEnd)
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned DestReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const override
Load the specified register of the given register class from the specified stack frame index...
void setLocalFrameSize(int64_t sz)
Set the size of the local object blob.
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.
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
void setUseLocalStackAllocationBlock(bool v)
setUseLocalStackAllocationBlock - Set whether the local allocation blob should be allocated together ...
MCSuperRegIterator enumerates all super-registers of Reg.
bool isPhysRegUsed(unsigned PhysReg) const
Return true if the specified register is modified or read in this function.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
static MachineOperand CreateReg(unsigned Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false)
MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const override
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const HexagonRegisterInfo * getRegisterInfo() const override
bool DisableFramePointerElim(const MachineFunction &MF) const
DisableFramePointerElim - This returns true if frame pointer elimination optimization should be disab...
ArrayRef< MCPhysReg > getRawAllocationOrder(const MachineFunction &MF) const
Returns the preferred order for allocating registers from this register class in MF.
static cl::opt< bool > EnableStackOVFSanitizer("enable-stackovf-sanitizer", cl::Hidden, cl::desc("Enable runtime checks for stack overflow."), cl::init(false), cl::ZeroOrMore)
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
Reg
All possible values of the reg field in the ModR/M byte.
static cl::opt< bool > EnableShrinkWrapping("hexagon-shrink-frame", cl::init(true), cl::Hidden, cl::ZeroOrMore, cl::desc("Enable stack frame shrink wrapping"))
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
static unsigned getMax32BitSubRegister(unsigned Reg, const TargetRegisterInfo &TRI, bool hireg=true)
Map a register pair Reg to the subregister that has the greater "number", i.e.
bool hasDebugInfo() const
Returns true if valid debug info is present.
LLVM_NODISCARD unsigned addFrameInst(const MCCFIInstruction &Inst)
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, unsigned base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
LLVM_NODISCARD bool empty() const
const MachineBasicBlock & front() const
void copyImplicitOps(MachineFunction &MF, const MachineInstr &MI)
Copy implicit register operands from specified instruction to this instruction.
bool insert(const value_type &X)
Insert a new element into the SetVector.
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
static bool isMinSize(const MachineFunction &MF)
unsigned getLocalFrameMaxAlign() const
Return the required alignment of the local object blob.
static bool hasTailCall(const MachineBasicBlock &MBB)
Returns true if MBB has a machine instructions that indicates a tail call in the block.
void setLocalFrameMaxAlign(unsigned Align)
Required alignment of the local object blob, which is the strictest alignment of any object in it...
iterator getLastNonDebugInstr()
Returns an iterator to the last non-debug instruction in the basic block, or end().
bool needsAligna(const MachineFunction &MF) const
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
MachineBasicBlock * findNearestCommonDominator(MachineBasicBlock *A, MachineBasicBlock *B)
findNearestCommonDominator - Find nearest common dominator basic block for basic block A and B...
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
static bool needsStackFrame(const MachineBasicBlock &MBB, const BitVector &CSR, const HexagonRegisterInfo &HRI)
Checks if the basic block contains any instruction that needs a stack frame to be already in place...
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
Perform most of the PEI work here:
Printable PrintReg(unsigned Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubRegIdx=0)
Prints virtual and physical registers with or without a TRI instance.
static MachinePointerInfo getStack(MachineFunction &MF, int64_t Offset)
Stack pointer relative access.
unsigned getKillRegState(bool B)
unsigned estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
static cl::opt< bool > EliminateFramePointer("hexagon-fp-elim", cl::init(true), cl::Hidden, cl::desc("Refrain from using FP whenever possible"))
bool isSpillSlotObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a spill slot.
const MachineBasicBlock * getParent() const
mmo_iterator memoperands_end() const
INITIALIZE_PASS(HexagonEarlyIfConversion,"hexagon-eif","Hexagon early if conversion", false, false) bool HexagonEarlyIfConversion MachineBasicBlock * SB
constexpr uint64_t MinAlign(uint64_t A, uint64_t B)
A and B are either alignments or offsets.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
static bool needToReserveScavengingSpillSlots(MachineFunction &MF, const HexagonRegisterInfo &HRI, const TargetRegisterClass *RC)
Returns true if there are no caller-saved registers available in class RC.
static bool isOptSize(const MachineFunction &MF)
initializer< Ty > init(const Ty &Val)
static cl::opt< unsigned > NumberScavengerSlots("number-scavenger-slots", cl::Hidden, cl::desc("Set the number of scavenger slots"), cl::init(2), cl::ZeroOrMore)
bool isReturn(QueryType Type=AnyInBundle) const
const MachineInstrBuilder & setMemRefs(MachineInstr::mmo_iterator b, MachineInstr::mmo_iterator e) const
void addLiveIn(MCPhysReg PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
This file declares the machine register scavenger class.
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
unsigned const MachineRegisterInfo * MRI
static MCCFIInstruction createDefCfa(MCSymbol *L, unsigned Register, int Offset)
.cfi_def_cfa defines a rule for computing CFA as: take address from Register and add Offset to it...
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
static cl::opt< bool > DisableDeallocRet("disable-hexagon-dealloc-ret", cl::Hidden, cl::desc("Disable Dealloc Return for Hexagon target"))
bool isEHReturnCalleeSaveReg(unsigned Reg) const
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
void setStackSize(uint64_t Size)
Set the size of the stack.
DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any DBG_VALUE instructions.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
const MachineOperand & getOperand(unsigned i) const
void insertCFIInstructions(MachineFunction &MF) const
MCRegAliasIterator enumerates all registers aliasing Reg.
bool isPositionIndependent() const
static const unsigned End
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS=nullptr) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
FunctionPass class - This class is used to implement most global optimizations.
self_iterator getIterator()
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
unsigned getSubReg() const
int CreateSpillStackObject(uint64_t Size, unsigned Alignment)
Create a new statically sized stack object that represents a spill slot, returning a nonnegative iden...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
MCSubRegIterator enumerates all sub-registers of Reg.
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
bool dominates(const MachineDomTreeNode *A, const MachineDomTreeNode *B) const
static MachineInstr * getReturn(MachineBasicBlock &MBB)
Returns the "return" instruction from this block, or nullptr if there isn't any.
static bool hasReturn(const MachineBasicBlock &MBB)
Returns true if MBB contains an instruction that returns.
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
The memory access writes data.
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
bool hasCalls() const
Return true if the current function has any function calls.
static cl::opt< unsigned > ShrinkLimit("shrink-frame-limit", cl::init(std::numeric_limits< unsigned >::max()), cl::Hidden, cl::ZeroOrMore, cl::desc("Max count of stack frame shrink-wraps"))
void addOperand(MachineFunction &MF, const MachineOperand &Op)
Add the specified operand to the instruction.
const MCContext & getContext() const
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
void addScavengingFrameIndex(int FI)
Add a scavenging frame index.
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 getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
unsigned getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call...
MachineBasicBlock * getBlockNumbered(unsigned N) const
getBlockNumbered - MachineBasicBlocks are automatically numbered when they are inserted into the mach...
bool needsUnwindTableEntry() const
True if this function needs an unwind table.
instr_iterator getInstrIterator() const
int getFrameIndexReference(const MachineFunction &MF, int FI, unsigned &FrameReg) const override
getFrameIndexReference - This method should return the base register and offset used to reference a f...
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const override
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
static cl::opt< bool > EnableSaveRestoreLong("enable-save-restore-long", cl::Hidden, cl::desc("Enable long calls for save-restore stubs."), cl::init(false), cl::ZeroOrMore)
virtual BitVector getReservedRegs(const MachineFunction &MF) const =0
Returns a bitset indexed by physical register number indicating if a register is a special register t...
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
const TargetRegisterClass * getMinimalPhysRegClass(unsigned Reg, MVT VT=MVT::Other) const
Returns the Register Class of a physical register of the given type, picking the most sub register cl...
FunctionPass * createHexagonCallFrameInformation()
bool runOnMachineFunction(MachineFunction &F) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
llvm_unreachable("Unknown RegBank!")
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
MachineFunctionProperties & set(Property P)
Representation of each machine instruction.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
static bool isRestoreCall(unsigned Opc)
std::map< RegisterRef, RangeList > RegToRangeMap
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
A set of physical registers with utility functions to track liveness when walking backward/forward th...
IndexType getIndex(MachineInstr *MI) const
static cl::opt< bool > OptimizeSpillSlots("hexagon-opt-spill", cl::Hidden, cl::init(true), cl::desc("Optimize spill slots"))
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
void setMaxCallFrameSize(unsigned S)
bool isCall(QueryType Type=AnyInBundle) const
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
bool isLiveIn(MCPhysReg Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
static int const Threshold
TODO: Write a new FunctionPass AliasAnalysis so that it can keep a cache.
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const HexagonInstrInfo * getInstrInfo() const override
rpo Deduce function attributes in RPO
A vector that has set insertion semantics.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
static bool isOptNone(const MachineFunction &MF)
Primary interface to the complete machine description for the target machine.
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register...
MachineModuleInfo & getMMI() const
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
int getObjectIndexEnd() const
Return one past the maximum frame object index.
unsigned getSpillSize(const TargetRegisterClass &RC) const
Return the size in bytes of the stack slot allocated to hold a spilled copy of a register from class ...
void initializeHexagonCallFrameInformationPass(PassRegistry &)
auto find_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
bool dominates(const MachineDomTreeNode *A, const MachineDomTreeNode *B) const
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
void setObjectAlignment(int ObjectIdx, unsigned Align)
setObjectAlignment - Change the alignment of the specified stack object.
const MachineInstr * getAlignaInstr(const MachineFunction &MF) const
static unsigned getMaxCalleeSavedReg(const std::vector< CalleeSavedInfo > &CSI, const TargetRegisterInfo &TRI)
Returns the callee saved register with the largest id in the vector.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
Statically lint checks LLVM IR
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
Properties which a MachineFunction may have at a given point in time.
This class contains meta information specific to a module.
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.