66 #define DEBUG_TYPE "hexagon-pei" 150 using namespace llvm;
173 cl::desc(
"Enable stack frame shrink wrapping"));
177 cl::desc(
"Max count of stack frame shrink-wraps"));
225 bool HexagonCallFrameInformation::runOnMachineFunction(
MachineFunction &MF) {
232 HFI.insertCFIInstructions(MF);
237 "Hexagon call frame information",
false,
false)
240 return new HexagonCallFrameInformation();
248 if (Reg < Hexagon::D0 || Reg > Hexagon::D15)
254 if (*SubRegs > RegNo)
257 if (!RegNo || *SubRegs < RegNo)
267 static_assert(Hexagon::R1 > 0,
268 "Assume physical registers are encoded as positive integers");
273 for (
unsigned I = 1,
E = CSI.size();
I <
E; ++
I) {
285 for (
auto &
I : MBB) {
291 case Hexagon::PS_alloca:
292 case Hexagon::PS_aligna:
307 unsigned R = MO.getReg();
317 if (MO.isRegMask()) {
322 const uint32_t *BM = MO.getRegMask();
326 if (!(BM[R/32] & (1u << (R%32))))
341 unsigned RetOpc = I->getOpcode();
342 return RetOpc == Hexagon::PS_tailcall_i || RetOpc == Hexagon::PS_tailcall_r;
364 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4:
365 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4_PIC:
366 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4_EXT:
367 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4_EXT_PIC:
368 case Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT:
369 case Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT_PIC:
370 case Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4:
371 case Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_PIC:
397 static unsigned ShrinkCounter = 0;
418 for (RPOTType::rpo_iterator
I = RPOT.begin(),
E = RPOT.end();
I !=
E; ++
I)
419 RPO[(*I)->getNumber()] = RPON++;
425 unsigned BN = RPO[
I.getNumber()];
426 for (
auto SI =
I.succ_begin(), SE =
I.succ_end();
SI != SE; ++
SI) {
428 if (RPO[(*SI)->getNumber()] <= BN)
437 for (
const MCPhysReg *
P = HRI.getCalleeSavedRegs(&MF); *
P; ++
P)
446 dbgs() <<
"Blocks needing SF: {";
447 for (
auto &
B : SFBlocks)
452 if (SFBlocks.
empty())
457 for (
unsigned i = 1, n = SFBlocks.
size(); i < n; ++i) {
463 for (
unsigned i = 1, n = SFBlocks.
size(); i < n; ++i) {
469 dbgs() <<
"Computed dom block: ";
474 dbgs() <<
", computed pdom block: ";
490 LLVM_DEBUG(
dbgs() <<
"PDom block does not post-dominate dom block\n");
513 findShrunkPrologEpilog(MF, PrologB, EpilogB);
515 bool PrologueStubs =
false;
516 insertCSRSpillsInBlock(*PrologB, CSI, HRI, PrologueStubs);
517 insertPrologueInBlock(*PrologB, PrologueStubs);
518 updateEntryPaths(MF, *PrologB);
521 insertCSRRestoresInBlock(*EpilogB, CSI, HRI);
522 insertEpilogueInBlock(*EpilogB);
525 if (
B.isReturnBlock())
526 insertCSRRestoresInBlock(
B, CSI, HRI);
529 if (
B.isReturnBlock())
530 insertEpilogueInBlock(
B);
548 BitVector DoneT(MaxBN+1), DoneF(MaxBN+1), Path(MaxBN+1);
549 updateExitPaths(*EpilogB, *EpilogB, DoneT, DoneF, Path);
554 bool PrologueStubs)
const {
559 auto &HRI = *HST.getRegisterInfo();
570 FrameSize = MaxCFA +
alignTo(FrameSize, MaxAlign);
573 bool AlignStack = (MaxAlign > getStackAlignment());
577 unsigned SP = HRI.getStackRegister();
584 if (
MI.getOpcode() == Hexagon::PS_alloca)
587 for (
auto MI : AdjustRegs) {
588 assert((
MI->getOpcode() == Hexagon::PS_alloca) &&
"Expected alloca");
589 expandAlloca(
MI, HII, SP, MaxCF);
590 MI->eraseFromParent();
593 DebugLoc dl = MBB.findDebugLoc(InsertPt);
596 insertAllocframe(MBB, InsertPt, NumBytes);
598 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::A2_andir), SP)
600 .
addImm(-int64_t(MaxAlign));
606 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::PS_call_stk))
607 .addExternalSymbol(
"__runtime_stack_check");
608 }
else if (NumBytes > 0) {
610 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::A2_addi), SP)
620 auto &HRI = *HST.getRegisterInfo();
621 unsigned SP = HRI.getStackRegister();
629 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::A2_addi), SP)
637 unsigned RetOpc = RetI ? RetI->
getOpcode() : 0;
640 if (RetOpc == Hexagon::EH_RETURN_JMPR) {
641 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::L2_deallocframe))
642 .addDef(Hexagon::D15)
644 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::A2_add), SP)
652 if (RetOpc == Hexagon::RESTORE_DEALLOC_RET_JMP_V4 ||
653 RetOpc == Hexagon::RESTORE_DEALLOC_RET_JMP_V4_PIC ||
654 RetOpc == Hexagon::RESTORE_DEALLOC_RET_JMP_V4_EXT ||
655 RetOpc == Hexagon::RESTORE_DEALLOC_RET_JMP_V4_EXT_PIC) {
659 while (It != MBB.
end()) {
671 bool NeedsDeallocframe =
true;
672 if (!MBB.
empty() && InsertPt != MBB.
begin()) {
674 unsigned COpc = PrevIt->getOpcode();
675 if (COpc == Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4 ||
676 COpc == Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_PIC ||
677 COpc == Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT ||
678 COpc == Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT_PIC ||
679 COpc == Hexagon::PS_call_nr || COpc == Hexagon::PS_callr_nr)
680 NeedsDeallocframe =
false;
683 if (!NeedsDeallocframe)
689 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::L2_deallocframe))
690 .addDef(Hexagon::D15)
694 unsigned NewOpc = Hexagon::L4_return;
696 .addDef(Hexagon::D15)
708 auto &HRI = *HST.getRegisterInfo();
712 const unsigned int ALLOCFRAME_MAX = 16384;
720 unsigned SP = HRI.getStackRegister();
722 if (NumBytes >= ALLOCFRAME_MAX) {
724 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::S2_allocframe))
731 unsigned SP = HRI.getStackRegister();
732 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::A2_addi), SP)
736 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::S2_allocframe))
754 for (
unsigned i = 0; i < Worklist.
size(); ++i) {
755 unsigned BN = Worklist[i];
762 Worklist.
insert(SB->getNumber());
771 if (Path[BN] || DoneF[BN])
779 bool ReachedExit =
false;
781 ReachedExit |= updateExitPaths(*SB, RestoreB, DoneT, DoneF, Path);
797 if (ReachedExit && &MBB != &RestoreB) {
822 if (
I.getOpcode() == Hexagon::S2_allocframe)
823 return std::next(It);
827 bool HasCall =
false, HasAllocFrame =
false;
829 while (++
T != End &&
T->isBundled()) {
830 if (
T->getOpcode() == Hexagon::S2_allocframe)
831 HasAllocFrame =
true;
832 else if (
T->isCall())
836 return HasCall ? It : std::next(It);
845 insertCFIInstructionsAt(
B, At.getValue());
856 auto &HRI = *HST.getRegisterInfo();
862 const MCInstrDesc &CFID = HII.get(TargetOpcode::CFI_INSTRUCTION);
865 bool HasFP = hasFP(MF);
868 unsigned DwFPReg = HRI.getDwarfRegNum(HRI.getFrameRegister(),
true);
869 unsigned DwRAReg = HRI.getDwarfRegNum(HRI.getRARegister(),
true);
895 static unsigned int RegsToMove[] = {
896 Hexagon::R1, Hexagon::R0, Hexagon::R3,
Hexagon::R2,
897 Hexagon::R17, Hexagon::R16, Hexagon::R19, Hexagon::R18,
898 Hexagon::R21, Hexagon::R20, Hexagon::R23, Hexagon::R22,
899 Hexagon::R25, Hexagon::R24, Hexagon::R27, Hexagon::R26,
900 Hexagon::D0, Hexagon::D1, Hexagon::D8, Hexagon::D9,
901 Hexagon::D10, Hexagon::D11, Hexagon::D12, Hexagon::D13,
907 for (
unsigned i = 0; RegsToMove[i] != Hexagon::NoRegister; ++i) {
908 unsigned Reg = RegsToMove[i];
910 return C.getReg() ==
Reg;
928 Offset = getFrameIndexReference(MF,
F->getFrameIdx(), FrameReg);
933 if (Reg < Hexagon::D0 || Reg > Hexagon::D15) {
934 unsigned DwarfReg = HRI.getDwarfRegNum(Reg,
true);
946 unsigned HiReg = HRI.getSubReg(Reg, Hexagon::isub_hi);
947 unsigned LoReg = HRI.getSubReg(Reg, Hexagon::isub_lo);
948 unsigned HiDwarfReg = HRI.getDwarfRegNum(HiReg,
true);
949 unsigned LoDwarfReg = HRI.getDwarfRegNum(LoReg,
true);
968 bool HasExtraAlign = HRI.needsStackRealignment(MF);
969 bool HasAlloca = MFI.hasVarSizedObjects();
984 if (HasAlloca || HasExtraAlign)
987 if (MFI.getStackSize() > 0) {
997 if (MFI.hasCalls() || HMFI.hasClobberLR())
1010 bool Stkchk =
false) {
1011 const char * V4SpillToMemoryFunctions[] = {
1012 "__save_r16_through_r17",
1013 "__save_r16_through_r19",
1014 "__save_r16_through_r21",
1015 "__save_r16_through_r23",
1016 "__save_r16_through_r25",
1017 "__save_r16_through_r27" };
1019 const char * V4SpillToMemoryStkchkFunctions[] = {
1020 "__save_r16_through_r17_stkchk",
1021 "__save_r16_through_r19_stkchk",
1022 "__save_r16_through_r21_stkchk",
1023 "__save_r16_through_r23_stkchk",
1024 "__save_r16_through_r25_stkchk",
1025 "__save_r16_through_r27_stkchk" };
1027 const char * V4SpillFromMemoryFunctions[] = {
1028 "__restore_r16_through_r17_and_deallocframe",
1029 "__restore_r16_through_r19_and_deallocframe",
1030 "__restore_r16_through_r21_and_deallocframe",
1031 "__restore_r16_through_r23_and_deallocframe",
1032 "__restore_r16_through_r25_and_deallocframe",
1033 "__restore_r16_through_r27_and_deallocframe" };
1035 const char * V4SpillFromMemoryTailcallFunctions[] = {
1036 "__restore_r16_through_r17_and_deallocframe_before_tailcall",
1037 "__restore_r16_through_r19_and_deallocframe_before_tailcall",
1038 "__restore_r16_through_r21_and_deallocframe_before_tailcall",
1039 "__restore_r16_through_r23_and_deallocframe_before_tailcall",
1040 "__restore_r16_through_r25_and_deallocframe_before_tailcall",
1041 "__restore_r16_through_r27_and_deallocframe_before_tailcall" 1044 const char **SpillFunc =
nullptr;
1048 SpillFunc = Stkchk ? V4SpillToMemoryStkchkFunctions
1049 : V4SpillToMemoryFunctions;
1052 SpillFunc = V4SpillFromMemoryFunctions;
1055 SpillFunc = V4SpillFromMemoryTailcallFunctions;
1058 assert(SpillFunc &&
"Unknown spill kind");
1063 return SpillFunc[0];
1065 return SpillFunc[1];
1067 return SpillFunc[2];
1069 return SpillFunc[3];
1071 return SpillFunc[4];
1073 return SpillFunc[5];
1081 int FI,
unsigned &FrameReg)
const {
1085 int Offset = MFI.getObjectOffset(FI);
1086 bool HasAlloca = MFI.hasVarSizedObjects();
1087 bool HasExtraAlign = HRI.needsStackRealignment(MF);
1091 unsigned FrameSize = MFI.getStackSize();
1092 unsigned SP = HRI.getStackRegister();
1093 unsigned FP = HRI.getFrameRegister();
1094 unsigned AP = HMFI.getStackAlignBasePhysReg();
1112 bool UseFP =
false, UseAP =
false;
1117 if (NoOpt && !HasExtraAlign)
1119 if (MFI.isFixedObjectIndex(FI) || MFI.isObjectPreAllocated(FI)) {
1122 UseFP |= (HasAlloca || HasExtraAlign);
1133 bool HasFP = hasFP(MF);
1134 assert((HasFP || !UseFP) &&
"This function must have frame pointer");
1160 if (Offset > 0 && !HasFP)
1175 if (!UseFP && !UseAP)
1176 RealOffset = FrameSize+
Offset;
1182 bool &PrologueStubs)
const {
1187 PrologueStubs =
false;
1192 if (useSpillFunction(MF, CSI)) {
1193 PrologueStubs =
true;
1205 if (StkOvrFlowEnabled) {
1207 SpillOpc = IsPIC ? Hexagon::SAVE_REGISTERS_CALL_V4STK_EXT_PIC
1208 : Hexagon::SAVE_REGISTERS_CALL_V4STK_EXT;
1210 SpillOpc = IsPIC ? Hexagon::SAVE_REGISTERS_CALL_V4STK_PIC
1211 : Hexagon::SAVE_REGISTERS_CALL_V4STK;
1214 SpillOpc = IsPIC ? Hexagon::SAVE_REGISTERS_CALL_V4_EXT_PIC
1215 : Hexagon::SAVE_REGISTERS_CALL_V4_EXT;
1217 SpillOpc = IsPIC ? Hexagon::SAVE_REGISTERS_CALL_V4_PIC
1218 : Hexagon::SAVE_REGISTERS_CALL_V4;
1222 BuildMI(MBB, MI, DL, HII.get(SpillOpc))
1223 .addExternalSymbol(SpillFun);
1226 addCalleeSaveRegistersAsImpOperand(SaveRegsCall, CSI,
false,
true);
1228 for (
unsigned I = 0;
I < CSI.size(); ++
I)
1233 for (
unsigned i = 0, n = CSI.size(); i < n; ++i) {
1234 unsigned Reg = CSI[i].getReg();
1239 int FI = CSI[i].getFrameIdx();
1241 HII.storeRegToStackSlot(MBB, MI, Reg, IsKill, FI, RC, &HRI);
1258 if (useRestoreFunction(MF, CSI)) {
1275 RetOpc = IsPIC ? Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT_PIC
1276 : Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT;
1278 RetOpc = IsPIC ? Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_PIC
1279 : Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4;
1280 DeallocCall =
BuildMI(MBB, MI, DL, HII.get(RetOpc))
1281 .addExternalSymbol(RestoreFn);
1285 assert(It->isReturn() && std::next(It) == MBB.
end());
1288 RetOpc = IsPIC ? Hexagon::RESTORE_DEALLOC_RET_JMP_V4_EXT_PIC
1289 : Hexagon::RESTORE_DEALLOC_RET_JMP_V4_EXT;
1291 RetOpc = IsPIC ? Hexagon::RESTORE_DEALLOC_RET_JMP_V4_PIC
1292 : Hexagon::RESTORE_DEALLOC_RET_JMP_V4;
1293 DeallocCall =
BuildMI(MBB, It, DL, HII.get(RetOpc))
1294 .addExternalSymbol(RestoreFn);
1298 addCalleeSaveRegistersAsImpOperand(DeallocCall, CSI,
true,
false);
1302 for (
unsigned i = 0; i < CSI.size(); ++i) {
1303 unsigned Reg = CSI[i].getReg();
1305 int FI = CSI[i].getFrameIdx();
1306 HII.loadRegFromStackSlot(MBB, MI, Reg, FI, RC, &HRI);
1318 assert((Opc == Hexagon::ADJCALLSTACKDOWN || Opc == Hexagon::ADJCALLSTACKUP) &&
1319 "Cannot handle this call frame pseudo instruction");
1320 return MBB.
erase(I);
1333 if (!HasAlloca || !NeedsAlign)
1351 assert(A <= 8 &&
"Unexpected local frame alignment");
1359 AP = AI->getOperand(0).getReg();
1369 auto IsUsed = [&HRI,&
MRI] (
unsigned Reg) ->
bool {
1401 BitVector SRegs(Hexagon::NUM_TARGET_REGS);
1410 for (
unsigned i = 0, n = CSI.size(); i < n; ++i) {
1411 unsigned R = CSI[i].getReg();
1423 for (
int x = Reserved.find_first(); x >= 0; x = Reserved.find_next(x)) {
1437 BitVector TmpSup(Hexagon::NUM_TARGET_REGS);
1443 for (
int x = TmpSup.find_first(); x >= 0; x = TmpSup.find_next(x)) {
1482 const SpillSlot *FixedSlots = getCalleeSavedSpillSlots(NumFixed);
1483 for (
const SpillSlot *S = FixedSlots; S != FixedSlots+NumFixed; ++S) {
1487 int FI = MFI.CreateFixedSpillStackObject(TRI->
getSpillSize(*RC), S->Offset);
1488 MinOffset = std::min(MinOffset, S->Offset);
1490 SRegs[S->Reg] =
false;
1500 int Off = MinOffset -
Size;
1504 int FI = MFI.CreateFixedSpillStackObject(Size, Off);
1505 MinOffset = std::min(MinOffset, Off);
1511 dbgs() <<
"CS information: {";
1512 for (
unsigned i = 0, n = CSI.size(); i < n; ++i) {
1513 int FI = CSI[i].getFrameIdx();
1514 int Off = MFI.getObjectOffset(FI);
1525 bool MissedReg =
false;
1545 if (!Hexagon::ModRegsRegClass.
contains(DstR) ||
1546 !Hexagon::ModRegsRegClass.
contains(SrcR))
1551 BuildMI(B, It, DL, HII.get(TargetOpcode::COPY), DstR)
1575 unsigned TfrOpc = (Opc == Hexagon::STriw_pred) ? Hexagon::C2_tfrpr
1576 : Hexagon::A2_tfrcrr;
1577 BuildMI(B, It, DL, HII.get(TfrOpc), TmpR)
1581 BuildMI(B, It, DL, HII.get(Hexagon::S2_storeri_io))
1606 BuildMI(B, It, DL, HII.get(Hexagon::L2_loadri_io), TmpR)
1613 unsigned TfrOpc = (Opc == Hexagon::LDriw_pred) ? Hexagon::C2_tfrrp
1614 : Hexagon::A2_tfrrcr;
1615 BuildMI(B, It, DL, HII.get(TfrOpc), DstR)
1634 auto *RC = &Hexagon::HvxVRRegClass;
1643 BuildMI(B, It, DL, HII.get(Hexagon::A2_tfrsi), TmpR0)
1644 .addImm(0x01010101);
1646 BuildMI(B, It, DL, HII.get(Hexagon::V6_vandqrt), TmpR1)
1652 expandStoreVec(B, std::prev(It), MRI, HII, NewRegs);
1670 auto *RC = &Hexagon::HvxVRRegClass;
1678 BuildMI(B, It, DL, HII.get(Hexagon::A2_tfrsi), TmpR0)
1679 .addImm(0x01010101);
1683 expandLoadVec(B, std::prev(It), MRI, HII, NewRegs);
1685 BuildMI(B, It, DL, HII.get(Hexagon::V6_vandvrt), DstR)
1712 for (
auto R = B.
begin(); R != It; ++R) {
1719 unsigned SrcLo = HRI.getSubReg(SrcR, Hexagon::vsub_lo);
1720 unsigned SrcHi = HRI.getSubReg(SrcR, Hexagon::vsub_hi);
1724 unsigned Size = HRI.getSpillSize(Hexagon::HvxVRRegClass);
1725 unsigned NeedAlign = HRI.getSpillAlignment(Hexagon::HvxVRRegClass);
1726 unsigned HasAlign = MFI.getObjectAlignment(FI);
1731 StoreOpc = NeedAlign <= HasAlign ? Hexagon::V6_vS32b_ai
1732 : Hexagon::V6_vS32Ub_ai;
1733 BuildMI(B, It, DL, HII.get(StoreOpc))
1742 StoreOpc = NeedAlign <=
MinAlign(HasAlign, Size) ? Hexagon::V6_vS32b_ai
1743 : Hexagon::V6_vS32Ub_ai;
1744 BuildMI(B, It, DL, HII.get(StoreOpc))
1767 unsigned DstHi = HRI.getSubReg(DstR, Hexagon::vsub_hi);
1768 unsigned DstLo = HRI.getSubReg(DstR, Hexagon::vsub_lo);
1771 unsigned Size = HRI.getSpillSize(Hexagon::HvxVRRegClass);
1772 unsigned NeedAlign = HRI.getSpillAlignment(Hexagon::HvxVRRegClass);
1773 unsigned HasAlign = MFI.getObjectAlignment(FI);
1777 LoadOpc = NeedAlign <= HasAlign ? Hexagon::V6_vL32b_ai
1778 : Hexagon::V6_vL32Ub_ai;
1779 BuildMI(B, It, DL, HII.get(LoadOpc), DstLo)
1785 LoadOpc = NeedAlign <=
MinAlign(HasAlign, Size) ? Hexagon::V6_vL32b_ai
1786 : Hexagon::V6_vL32Ub_ai;
1787 BuildMI(B, It, DL, HII.get(LoadOpc), DstHi)
1811 unsigned NeedAlign = HRI.getSpillAlignment(Hexagon::HvxVRRegClass);
1812 unsigned HasAlign = MFI.getObjectAlignment(FI);
1813 unsigned StoreOpc = NeedAlign <= HasAlign ? Hexagon::V6_vS32b_ai
1814 : Hexagon::V6_vS32Ub_ai;
1815 BuildMI(B, It, DL, HII.get(StoreOpc))
1839 unsigned NeedAlign = HRI.getSpillAlignment(Hexagon::HvxVRRegClass);
1840 unsigned HasAlign = MFI.getObjectAlignment(FI);
1841 unsigned LoadOpc = NeedAlign <= HasAlign ? Hexagon::V6_vL32b_ai
1842 : Hexagon::V6_vL32Ub_ai;
1843 BuildMI(B, It, DL, HII.get(LoadOpc), DstR)
1856 bool Changed =
false;
1858 for (
auto &B : MF) {
1863 NextI = std::next(
I);
1867 case TargetOpcode::COPY:
1868 Changed |= expandCopy(B,
I, MRI, HII, NewRegs);
1870 case Hexagon::STriw_pred:
1871 case Hexagon::STriw_ctr:
1872 Changed |= expandStoreInt(B,
I, MRI, HII, NewRegs);
1874 case Hexagon::LDriw_pred:
1875 case Hexagon::LDriw_ctr:
1876 Changed |= expandLoadInt(B,
I, MRI, HII, NewRegs);
1878 case Hexagon::PS_vstorerq_ai:
1879 Changed |= expandStoreVecPred(B,
I, MRI, HII, NewRegs);
1881 case Hexagon::PS_vloadrq_ai:
1882 Changed |= expandLoadVecPred(B,
I, MRI, HII, NewRegs);
1884 case Hexagon::PS_vloadrw_ai:
1885 case Hexagon::PS_vloadrwu_ai:
1886 Changed |= expandLoadVec2(B,
I, MRI, HII, NewRegs);
1888 case Hexagon::PS_vstorerw_ai:
1889 case Hexagon::PS_vstorerwu_ai:
1890 Changed |= expandStoreVec2(B,
I, MRI, HII, NewRegs);
1904 SavedRegs.
resize(HRI.getNumRegs());
1914 expandSpillMacros(MF, NewRegs);
1916 optimizeSpillSlots(MF, NewRegs);
1920 if (!NewRegs.
empty() || mayOverflowFrameOffset(MF)) {
1926 SpillRCs.
insert(&Hexagon::IntRegsRegClass);
1928 for (
unsigned VR : NewRegs)
1931 for (
auto *RC : SpillRCs) {
1935 unsigned S = HRI.getSpillSize(*RC), A = HRI.getSpillAlignment(*RC);
1936 for (
unsigned i = 0; i < Num; i++) {
1954 auto isDead = [&FIR,&DeadMap] (
unsigned Reg) ->
bool {
1955 auto F = DeadMap.find({
Reg,0});
1956 if (
F == DeadMap.end())
1958 for (
auto &DR :
F->second)
1959 if (DR.contains(FIR))
1981 auto &HII = *HST.getInstrInfo();
1982 auto &HRI = *HST.getRegisterInfo();
1986 using BlockIndexMap =
1987 std::map<MachineBasicBlock *, HexagonBlockRanges::InstrIndexMap>;
1988 using BlockRangeMap =
1989 std::map<MachineBasicBlock *, HexagonBlockRanges::RangeList>;
1997 SlotInfo() =
default;
2000 BlockIndexMap BlockIndexes;
2002 std::map<int,SlotInfo> FIRangeMap;
2011 if (HaveRC ==
nullptr || HaveRC == NewRC)
2016 if (NewRC->hasSubClassEq(HaveRC))
2023 for (
auto &B : MF) {
2024 std::map<int,IndexType> LastStore, LastLoad;
2027 auto P = BlockIndexes.insert(
2029 auto &IndexMap =
P.first->second;
2031 << IndexMap <<
'\n');
2033 for (
auto &
In : B) {
2035 bool Load = HII.isLoadFromStackSlot(
In, LFI) && !HII.isPredicated(
In);
2036 bool Store = HII.isStoreToStackSlot(
In, SFI) && !HII.isPredicated(
In);
2037 if (Load && Store) {
2049 if (Load || Store) {
2050 int TFI = Load ? LFI : SFI;
2051 unsigned AM = HII.getAddrMode(
In);
2052 SlotInfo &
SI = FIRangeMap[TFI];
2056 unsigned OpNum = Load ? 0 : 2;
2057 auto *RC = HII.getRegClass(
In.getDesc(), OpNum, &HRI, MF);
2058 RC = getCommonRC(SI.RC, RC);
2066 unsigned S = HII.getMemAccessSize(
In);
2067 if (SI.Size != 0 && SI.Size != S)
2073 for (
auto *Mo :
In.memoperands()) {
2074 if (!Mo->isVolatile())
2085 for (
unsigned i = 0, n =
In.getNumOperands(); i < n; ++i) {
2092 if (i+1 >= n || !
In.getOperand(i+1).isImm() ||
2093 In.getOperand(i+1).getImm() != 0)
2095 if (BadFIs.
count(FI))
2101 LastStore[FI] = IndexType::Entry;
2102 LastLoad[FI] =
Index;
2106 RL.
add(LastStore[FI], LastLoad[FI],
false,
false);
2108 RL.
add(IndexType::Entry, LastLoad[FI],
false,
false);
2110 LastStore[FI] =
Index;
2117 for (
auto &
I : LastLoad) {
2118 IndexType LL =
I.second;
2121 auto &RL = FIRangeMap[
I.first].Map[&
B];
2122 IndexType &
LS = LastStore[
I.first];
2124 RL.add(LS, LL,
false,
false);
2126 RL.add(IndexType::Entry, LL,
false,
false);
2129 for (
auto &
I : LastStore) {
2130 IndexType
LS =
I.second;
2133 auto &RL = FIRangeMap[
I.first].Map[&
B];
2139 for (
auto &
P : FIRangeMap) {
2140 dbgs() <<
"fi#" <<
P.first;
2141 if (BadFIs.
count(
P.first))
2144 if (
P.second.RC !=
nullptr)
2145 dbgs() << HRI.getRegClassName(
P.second.RC) <<
'\n';
2147 dbgs() <<
"<null>\n";
2148 for (
auto &R :
P.second.Map)
2159 std::map<MachineBasicBlock*,std::vector<int>> BlockFIMap;
2161 for (
auto &
P : FIRangeMap) {
2163 if (BadFIs.
count(
P.first))
2165 for (
auto &B : MF) {
2166 auto F =
P.second.Map.find(&B);
2168 if (
F ==
P.second.Map.end() ||
F->second.empty())
2171 if (IR.
start() == IndexType::Entry)
2172 LoxFIs.insert(
P.first);
2173 BlockFIMap[&
B].push_back(
P.first);
2178 dbgs() <<
"Block-to-FI map (* -- live-on-exit):\n";
2179 for (
auto &
P : BlockFIMap) {
2180 auto &FIs =
P.second;
2184 for (
auto I : FIs) {
2185 dbgs() <<
" fi#" <<
I;
2186 if (LoxFIs.count(
I))
2198 for (
auto &B : MF) {
2199 auto F = BlockIndexes.find(&B);
2200 assert(
F != BlockIndexes.end());
2207 for (
auto FI : BlockFIMap[&B]) {
2208 if (BadFIs.
count(FI))
2212 for (
auto &Range : RL) {
2214 if (!IndexType::isInstr(Range.start()) ||
2215 !IndexType::isInstr(Range.end()))
2224 SrcOp.getSubReg() };
2225 auto *RC = HII.getRegClass(SI.
getDesc(), 2, &HRI, MF);
2227 unsigned FoundR = this->findPhysReg(MF, Range, IM, DM, RC);
2243 if (SrcRR.
Reg != FoundR || SrcRR.
Sub != 0) {
2245 CopyIn =
BuildMI(B, StartIt, DL, HII.get(TargetOpcode::COPY), FoundR)
2251 if (LoxFIs.count(FI) && (&Range == &RL.back())) {
2253 if (
unsigned SR = SrcOp.getSubReg())
2254 SrcOp.setReg(HRI.getSubReg(FoundR, SR));
2256 SrcOp.setReg(FoundR);
2259 SrcOp.setIsKill(
false);
2262 IM.replaceInstr(&SI, CopyIn);
2266 for (
auto It = StartIt; It != EndIt; It = NextIt) {
2268 NextIt = std::next(It);
2270 if (!HII.isLoadFromStackSlot(MI, TFI) || TFI != FI)
2275 if (DstR != FoundR) {
2277 unsigned MemSize = HII.getMemAccessSize(MI);
2279 unsigned CopyOpc = TargetOpcode::COPY;
2280 if (HII.isSignExtendingLoad(MI))
2281 CopyOpc = (MemSize == 1) ? Hexagon::A2_sxtb : Hexagon::A2_sxth;
2282 else if (HII.isZeroExtendingLoad(MI))
2283 CopyOpc = (MemSize == 1) ? Hexagon::A2_zxtb : Hexagon::A2_zxth;
2284 CopyOut =
BuildMI(B, It, DL, HII.get(CopyOpc), DstR)
2287 IM.replaceInstr(&MI, CopyOut);
2294 DM[RR].subtract(Range);
2300 void HexagonFrameLowering::expandAlloca(
MachineInstr *AI,
2326 BuildMI(MB, AI, DL, HII.get(Hexagon::A2_sub), Rd)
2331 BuildMI(MB, AI, DL, HII.get(Hexagon::A2_sub), SP)
2337 BuildMI(MB, AI, DL, HII.get(Hexagon::A2_andir), Rd)
2341 BuildMI(MB, AI, DL, HII.get(Hexagon::A2_andir), SP)
2347 BuildMI(MB, AI, DL, HII.get(TargetOpcode::COPY), SP)
2352 BuildMI(MB, AI, DL, HII.get(Hexagon::A2_addi), Rd)
2363 if (MaxA <= getStackAlignment())
2372 if (
I.getOpcode() == Hexagon::PS_aligna)
2379 void HexagonFrameLowering::addCalleeSaveRegistersAsImpOperand(
MachineInstr *
MI,
2380 const CSIVect &CSI,
bool IsDef,
bool IsKill)
const {
2391 const CSIVect &CSI)
const {
2403 for (
unsigned i = 0, n = CSI.size(); i < n; ++i) {
2404 unsigned R = CSI[i].getReg();
2405 if (!Hexagon::DoubleRegsRegClass.
contains(R))
2410 if (F != Hexagon::D8)
2414 if (N >= 0 && N != F+1)
2422 bool HexagonFrameLowering::useSpillFunction(
const MachineFunction &MF,
2423 const CSIVect &CSI)
const {
2424 if (shouldInlineCSR(MF, CSI))
2426 unsigned NumCSI = CSI.size();
2432 return Threshold < NumCSI;
2435 bool HexagonFrameLowering::useRestoreFunction(
const MachineFunction &MF,
2436 const CSIVect &CSI)
const {
2437 if (shouldInlineCSR(MF, CSI))
2447 unsigned NumCSI = CSI.size();
2453 return Threshold < NumCSI;
2456 bool HexagonFrameLowering::mayOverflowFrameOffset(
MachineFunction &MF)
const {
2461 if (HST.useHVXOps() && StackSize > 256)
2468 bool HasImmStack =
false;
2469 unsigned MinLS = ~0u;
2475 case Hexagon::S4_storeirit_io:
2476 case Hexagon::S4_storeirif_io:
2477 case Hexagon::S4_storeiri_io:
2480 case Hexagon::S4_storeirht_io:
2481 case Hexagon::S4_storeirhf_io:
2482 case Hexagon::S4_storeirh_io:
2485 case Hexagon::S4_storeirbt_io:
2486 case Hexagon::S4_storeirbf_io:
2487 case Hexagon::S4_storeirb_io:
2490 MinLS = std::min(MinLS, LS);
2497 return !isUInt<6>(StackSize >> MinLS);
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
void push_back(const T &Elt)
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
bool isCall(QueryType Type=AnyInBundle) const
instr_iterator instr_end()
bool hasDebugInfo() const
Returns true if valid debug info is present.
void mapLocalFrameObject(int ObjectIndex, int64_t Offset)
Map a frame index into the local object block.
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
void stepForward(const MachineInstr &MI, SmallVectorImpl< std::pair< unsigned, const MachineOperand *>> &Clobbers)
Simulates liveness when stepping forward over an instruction(bundle).
static cl::opt< int > SpillFuncThresholdOs("spill-func-threshold-Os", cl::Hidden, cl::desc("Specify Os spill func threshold"), cl::init(1), cl::ZeroOrMore)
Compute iterated dominance frontiers using a linear time algorithm.
size_type size() const
Determine the number of elements in the SetVector.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
INITIALIZE_PASS(HexagonCallFrameInformation, "hexagon-cfi", "Hexagon call frame information", false, false) FunctionPass *llvm
const MachineInstrBuilder & addCFIIndex(unsigned CFIIndex) const
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
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...
ArrayRef< MCPhysReg > getRawAllocationOrder(const MachineFunction &MF) const
Returns the preferred order for allocating registers from this register class in MF.
MachineBasicBlock * findNearestCommonDominator(MachineBasicBlock *A, MachineBasicBlock *B)
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
static Optional< MachineBasicBlock::iterator > findCFILocation(MachineBasicBlock &B)
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.
unsigned getReg() const
getReg - Returns the register number.
int64_t getLocalFrameSize() const
Get the size of the local object blob.
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)
unsigned getSubReg() const
static RegisterSet expandToSubRegs(RegisterRef R, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI)
static const MCPhysReg VRegs[32]
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Hexagon target-specific information for each MachineFunction.
unsigned const TargetRegisterInfo * TRI
MachineModuleInfo & getMMI() const
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()))
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 setStackAlignBasePhysReg(unsigned R)
return AArch64::GPR64RegClass contains(Reg)
iterator_range< succ_iterator > successors()
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, bool isRenamable=false)
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
std::map< RegisterRef, RangeList > RegToRangeMap
bool isEHReturnCalleeSaveReg(unsigned Reg) const
unsigned getSpillAlignment(const TargetRegisterClass &RC) const
Return the minimum required alignment in bytes for a spill slot for a register of this class...
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.
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 contains(unsigned Reg) const
Returns true if register Reg is contained in the set.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
Printable printReg(unsigned Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
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...
int find_first() const
find_first - Returns the index of the first set bit, -1 if none of the bits are set.
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
static cl::opt< bool > EnableStackOVFSanitizer("enable-stackovf-sanitizer", cl::Hidden, cl::desc("Enable runtime checks for stack overflow."), cl::init(false), cl::ZeroOrMore)
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
int find_next(unsigned Prev) const
find_next - Returns the index of the next set bit following the "Prev" bit.
static cl::opt< bool > EnableShrinkWrapping("hexagon-shrink-frame", cl::init(true), cl::Hidden, cl::ZeroOrMore, cl::desc("Enable stack frame shrink wrapping"))
This file contains the simple types necessary to represent the attributes associated with functions a...
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
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.
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 MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
const MachineInstr * getAlignaInstr(const MachineFunction &MF) 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.
static bool isMinSize(const MachineFunction &MF)
bool DisableFramePointerElim(const MachineFunction &MF) const
DisableFramePointerElim - This returns true if frame pointer elimination optimization should be disab...
const MCContext & getContext() const
instr_iterator getInstrIterator() const
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...
int getObjectIndexEnd() const
Return one past the maximum frame object index.
iterator getLastNonDebugInstr()
Returns an iterator to the last non-debug instruction in the basic block, or end().
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
MachineBasicBlock * findNearestCommonDominator(MachineBasicBlock *A, MachineBasicBlock *B)
findNearestCommonDominator - Find nearest common dominator basic block for basic block A and B...
const MCPhysReg * getCallerSavedRegs(const MachineFunction *MF, const TargetRegisterClass *RC) const
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:
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
unsigned getKillRegState(bool B)
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
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 isReturn(QueryType Type=AnyInBundle) const
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.
unsigned getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
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)
void addLiveIn(MCPhysReg PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
This file declares the machine register scavenger class.
MachineBasicBlock * getBlockNumbered(unsigned N) const
getBlockNumbered - MachineBasicBlocks are automatically numbered when they are inserted into the mach...
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
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"))
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void setStackSize(uint64_t Size)
Set the size of the stack.
void addLiveIns(const MachineBasicBlock &MBB)
Adds all live-in registers of basic block MBB.
DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any DBG_VALUE and DBG_LABEL instructions...
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
bool dominates(const MachineDomTreeNode *A, const MachineDomTreeNode *B) const
MCRegAliasIterator enumerates all registers aliasing Reg.
unsigned getMaxAlignment() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
bool optForSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
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.
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
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...
const MachineBasicBlock & front() const
MCSubRegIterator enumerates all sub-registers of Reg.
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
IndexType getIndex(MachineInstr *MI) const
bool hasSubClassEq(const TargetRegisterClass *RC) const
Returns true if RC is a sub-class of or equal to this class.
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.
The memory access writes data.
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.
unsigned getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call...
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.
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...
bool dominates(const MachineDomTreeNode *A, const MachineDomTreeNode *B) const
unsigned estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) 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.
const Function & getFunction() const
Return the LLVM function that this machine code represents.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool needsUnwindTableEntry() const
True if this function needs an unwind table.
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
bool isLiveIn(MCPhysReg Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
bool isPhysRegUsed(unsigned PhysReg) const
Return true if the specified register is modified or read in this function.
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...
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
FunctionPass * createHexagonCallFrameInformation()
bool runOnMachineFunction(MachineFunction &F) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const MachineBasicBlock * getParent() const
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.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
RegToRangeMap computeLiveMap(InstrIndexMap &IndexMap)
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
static bool isRestoreCall(unsigned Opc)
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...
LLVM_NODISCARD bool empty() const
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
bool isPositionIndependent() const
static cl::opt< bool > OptimizeSpillSlots("hexagon-opt-spill", cl::Hidden, cl::init(true), cl::desc("Optimize spill slots"))
void setMaxCallFrameSize(unsigned S)
void insertCFIInstructions(MachineFunction &MF) const
unsigned getLocalFrameMaxAlign() const
Return the required alignment of the local object blob.
bool optForMinSize() const
Optimize this function for minimum size (-Oz).
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
RegToRangeMap computeDeadMap(InstrIndexMap &IndexMap, RegToRangeMap &LiveMap)
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
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...
static int const Threshold
TODO: Write a new FunctionPass AliasAnalysis so that it can keep a cache.
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
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.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
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...
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
static MachinePointerInfo getStack(MachineFunction &MF, int64_t Offset, uint8_t ID=0)
Stack pointer relative access.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
void initializeHexagonCallFrameInformationPass(PassRegistry &)
const MachineInstrBuilder & setMemRefs(MachineInstr::mmo_iterator b, MachineInstr::mmo_iterator e) const
const MachineOperand & getOperand(unsigned i) const
void setObjectAlignment(int ObjectIdx, unsigned Align)
setObjectAlignment - Change the alignment of the specified stack object.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects...
bool needsAligna(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
const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const override
Code Generation virtual methods...
unsigned createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
bool isSpillSlotObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a spill slot.
Properties which a MachineFunction may have at a given point in time.
This class contains meta information specific to a module.
mmo_iterator memoperands_end() const
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.