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) {
231 HFI.insertCFIInstructions(MF);
236 "Hexagon call frame information",
false,
false)
239 return new HexagonCallFrameInformation();
247 if (Reg < Hexagon::D0 || Reg > Hexagon::D15)
253 if (*SubRegs > RegNo)
256 if (!RegNo || *SubRegs < RegNo)
266 static_assert(Hexagon::R1 > 0,
267 "Assume physical registers are encoded as positive integers");
272 for (
unsigned I = 1,
E = CSI.size();
I <
E; ++
I) {
284 for (
auto &
I : MBB) {
290 case Hexagon::PS_alloca:
291 case Hexagon::PS_aligna:
316 if (MO.isRegMask()) {
321 const uint32_t *BM = MO.getRegMask();
325 if (!(BM[R/32] & (1u << (R%32))))
340 unsigned RetOpc = I->getOpcode();
341 return RetOpc == Hexagon::PS_tailcall_i || RetOpc == Hexagon::PS_tailcall_r;
363 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4:
364 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4_PIC:
365 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4_EXT:
366 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4_EXT_PIC:
367 case Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT:
368 case Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT_PIC:
369 case Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4:
370 case Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_PIC:
396 static unsigned ShrinkCounter = 0;
417 for (RPOTType::rpo_iterator
I = RPOT.begin(),
E = RPOT.end();
I !=
E; ++
I)
418 RPO[(*I)->getNumber()] = RPON++;
424 unsigned BN = RPO[
I.getNumber()];
425 for (
auto SI =
I.succ_begin(), SE =
I.succ_end();
SI != SE; ++
SI) {
427 if (RPO[(*SI)->getNumber()] <= BN)
436 for (
const MCPhysReg *
P = HRI.getCalleeSavedRegs(&MF); *
P; ++
P)
445 dbgs() <<
"Blocks needing SF: {";
446 for (
auto &
B : SFBlocks)
451 if (SFBlocks.
empty())
456 for (
unsigned i = 1, n = SFBlocks.
size(); i < n; ++i) {
462 for (
unsigned i = 1, n = SFBlocks.
size(); i < n; ++i) {
468 dbgs() <<
"Computed dom block: ";
473 dbgs() <<
", computed pdom block: ";
489 LLVM_DEBUG(
dbgs() <<
"PDom block does not post-dominate dom block\n");
512 findShrunkPrologEpilog(MF, PrologB, EpilogB);
514 bool PrologueStubs =
false;
515 insertCSRSpillsInBlock(*PrologB, CSI, HRI, PrologueStubs);
516 insertPrologueInBlock(*PrologB, PrologueStubs);
517 updateEntryPaths(MF, *PrologB);
520 insertCSRRestoresInBlock(*EpilogB, CSI, HRI);
521 insertEpilogueInBlock(*EpilogB);
524 if (
B.isReturnBlock())
525 insertCSRRestoresInBlock(
B, CSI, HRI);
528 if (
B.isReturnBlock())
529 insertEpilogueInBlock(
B);
547 BitVector DoneT(MaxBN+1), DoneF(MaxBN+1), Path(MaxBN+1);
548 updateExitPaths(*EpilogB, *EpilogB, DoneT, DoneF, Path);
557 assert(
F.hasFnAttribute(Attribute::NoReturn) &&
558 F.getFunction().hasFnAttribute(Attribute::NoUnwind) &&
559 !
F.getFunction().hasFnAttribute(Attribute::UWTable));
575 assert(!MFI.hasVarSizedObjects() &&
576 !HST.getRegisterInfo()->needsStackRealignment(MF));
577 return F.hasFnAttribute(Attribute::NoReturn) &&
578 F.hasFnAttribute(Attribute::NoUnwind) &&
579 !
F.hasFnAttribute(Attribute::UWTable) && HST.noreturnStackElim() &&
580 MFI.getStackSize() == 0;
584 bool PrologueStubs)
const {
589 auto &HRI = *HST.getRegisterInfo();
600 FrameSize = MaxCFA +
alignTo(FrameSize, MaxAlign);
603 bool AlignStack = (MaxAlign > getStackAlignment());
607 unsigned SP = HRI.getStackRegister();
614 if (
MI.getOpcode() == Hexagon::PS_alloca)
617 for (
auto MI : AdjustRegs) {
618 assert((
MI->getOpcode() == Hexagon::PS_alloca) &&
"Expected alloca");
619 expandAlloca(
MI, HII, SP, MaxCF);
620 MI->eraseFromParent();
623 DebugLoc dl = MBB.findDebugLoc(InsertPt);
626 insertAllocframe(MBB, InsertPt, NumBytes);
628 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::A2_andir), SP)
630 .
addImm(-int64_t(MaxAlign));
636 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::PS_call_stk))
637 .addExternalSymbol(
"__runtime_stack_check");
638 }
else if (NumBytes > 0) {
640 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::A2_addi), SP)
650 auto &HRI = *HST.getRegisterInfo();
651 unsigned SP = HRI.getStackRegister();
659 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::A2_addi), SP)
667 unsigned RetOpc = RetI ? RetI->
getOpcode() : 0;
670 if (RetOpc == Hexagon::EH_RETURN_JMPR) {
671 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::L2_deallocframe))
672 .addDef(Hexagon::D15)
674 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::A2_add), SP)
682 if (RetOpc == Hexagon::RESTORE_DEALLOC_RET_JMP_V4 ||
683 RetOpc == Hexagon::RESTORE_DEALLOC_RET_JMP_V4_PIC ||
684 RetOpc == Hexagon::RESTORE_DEALLOC_RET_JMP_V4_EXT ||
685 RetOpc == Hexagon::RESTORE_DEALLOC_RET_JMP_V4_EXT_PIC) {
689 while (It != MBB.
end()) {
701 bool NeedsDeallocframe =
true;
702 if (!MBB.
empty() && InsertPt != MBB.
begin()) {
704 unsigned COpc = PrevIt->getOpcode();
705 if (COpc == Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4 ||
706 COpc == Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_PIC ||
707 COpc == Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT ||
708 COpc == Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT_PIC ||
709 COpc == Hexagon::PS_call_nr || COpc == Hexagon::PS_callr_nr)
710 NeedsDeallocframe =
false;
713 if (!NeedsDeallocframe)
719 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::L2_deallocframe))
720 .addDef(Hexagon::D15)
724 unsigned NewOpc = Hexagon::L4_return;
726 .addDef(Hexagon::D15)
738 auto &HRI = *HST.getRegisterInfo();
742 const unsigned int ALLOCFRAME_MAX = 16384;
750 unsigned SP = HRI.getStackRegister();
752 if (NumBytes >= ALLOCFRAME_MAX) {
754 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::S2_allocframe))
761 unsigned SP = HRI.getStackRegister();
762 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::A2_addi), SP)
766 BuildMI(MBB, InsertPt, dl, HII.get(Hexagon::S2_allocframe))
784 for (
unsigned i = 0; i < Worklist.
size(); ++i) {
785 unsigned BN = Worklist[i];
792 Worklist.
insert(SB->getNumber());
801 if (Path[BN] || DoneF[BN])
809 bool ReachedExit =
false;
811 ReachedExit |= updateExitPaths(*SB, RestoreB, DoneT, DoneF, Path);
827 if (ReachedExit && &MBB != &RestoreB) {
852 if (
I.getOpcode() == Hexagon::S2_allocframe)
853 return std::next(It);
857 bool HasCall =
false, HasAllocFrame =
false;
859 while (++
T != End &&
T->isBundled()) {
860 if (
T->getOpcode() == Hexagon::S2_allocframe)
861 HasAllocFrame =
true;
862 else if (
T->isCall())
866 return HasCall ? It : std::next(It);
875 insertCFIInstructionsAt(
B, At.getValue());
886 auto &HRI = *HST.getRegisterInfo();
892 const MCInstrDesc &CFID = HII.get(TargetOpcode::CFI_INSTRUCTION);
895 bool HasFP = hasFP(MF);
898 unsigned DwFPReg = HRI.getDwarfRegNum(HRI.getFrameRegister(),
true);
899 unsigned DwRAReg = HRI.getDwarfRegNum(HRI.getRARegister(),
true);
925 static unsigned int RegsToMove[] = {
926 Hexagon::R1, Hexagon::R0, Hexagon::R3,
Hexagon::R2,
927 Hexagon::R17, Hexagon::R16, Hexagon::R19, Hexagon::R18,
928 Hexagon::R21, Hexagon::R20, Hexagon::R23, Hexagon::R22,
929 Hexagon::R25, Hexagon::R24, Hexagon::R27, Hexagon::R26,
930 Hexagon::D0, Hexagon::D1, Hexagon::D8, Hexagon::D9,
931 Hexagon::D10, Hexagon::D11, Hexagon::D12, Hexagon::D13,
937 for (
unsigned i = 0; RegsToMove[i] != Hexagon::NoRegister; ++i) {
938 unsigned Reg = RegsToMove[i];
940 return C.getReg() ==
Reg;
958 Offset = getFrameIndexReference(MF,
F->getFrameIdx(), FrameReg);
963 if (Reg < Hexagon::D0 || Reg > Hexagon::D15) {
964 unsigned DwarfReg = HRI.getDwarfRegNum(Reg,
true);
976 Register HiReg = HRI.getSubReg(Reg, Hexagon::isub_hi);
977 Register LoReg = HRI.getSubReg(Reg, Hexagon::isub_lo);
978 unsigned HiDwarfReg = HRI.getDwarfRegNum(HiReg,
true);
979 unsigned LoDwarfReg = HRI.getDwarfRegNum(LoReg,
true);
998 bool HasExtraAlign = HRI.needsStackRealignment(MF);
999 bool HasAlloca = MFI.hasVarSizedObjects();
1014 if (HasAlloca || HasExtraAlign)
1017 if (MFI.getStackSize() > 0) {
1040 bool Stkchk =
false) {
1041 const char * V4SpillToMemoryFunctions[] = {
1042 "__save_r16_through_r17",
1043 "__save_r16_through_r19",
1044 "__save_r16_through_r21",
1045 "__save_r16_through_r23",
1046 "__save_r16_through_r25",
1047 "__save_r16_through_r27" };
1049 const char * V4SpillToMemoryStkchkFunctions[] = {
1050 "__save_r16_through_r17_stkchk",
1051 "__save_r16_through_r19_stkchk",
1052 "__save_r16_through_r21_stkchk",
1053 "__save_r16_through_r23_stkchk",
1054 "__save_r16_through_r25_stkchk",
1055 "__save_r16_through_r27_stkchk" };
1057 const char * V4SpillFromMemoryFunctions[] = {
1058 "__restore_r16_through_r17_and_deallocframe",
1059 "__restore_r16_through_r19_and_deallocframe",
1060 "__restore_r16_through_r21_and_deallocframe",
1061 "__restore_r16_through_r23_and_deallocframe",
1062 "__restore_r16_through_r25_and_deallocframe",
1063 "__restore_r16_through_r27_and_deallocframe" };
1065 const char * V4SpillFromMemoryTailcallFunctions[] = {
1066 "__restore_r16_through_r17_and_deallocframe_before_tailcall",
1067 "__restore_r16_through_r19_and_deallocframe_before_tailcall",
1068 "__restore_r16_through_r21_and_deallocframe_before_tailcall",
1069 "__restore_r16_through_r23_and_deallocframe_before_tailcall",
1070 "__restore_r16_through_r25_and_deallocframe_before_tailcall",
1071 "__restore_r16_through_r27_and_deallocframe_before_tailcall" 1074 const char **SpillFunc =
nullptr;
1078 SpillFunc = Stkchk ? V4SpillToMemoryStkchkFunctions
1079 : V4SpillToMemoryFunctions;
1082 SpillFunc = V4SpillFromMemoryFunctions;
1085 SpillFunc = V4SpillFromMemoryTailcallFunctions;
1088 assert(SpillFunc &&
"Unknown spill kind");
1093 return SpillFunc[0];
1095 return SpillFunc[1];
1097 return SpillFunc[2];
1099 return SpillFunc[3];
1101 return SpillFunc[4];
1103 return SpillFunc[5];
1111 int FI,
unsigned &FrameReg)
const {
1115 int Offset = MFI.getObjectOffset(FI);
1116 bool HasAlloca = MFI.hasVarSizedObjects();
1117 bool HasExtraAlign = HRI.needsStackRealignment(MF);
1121 unsigned FrameSize = MFI.getStackSize();
1122 unsigned SP = HRI.getStackRegister();
1123 unsigned FP = HRI.getFrameRegister();
1124 unsigned AP = HMFI.getStackAlignBasePhysReg();
1142 bool UseFP =
false, UseAP =
false;
1147 if (NoOpt && !HasExtraAlign)
1149 if (MFI.isFixedObjectIndex(FI) || MFI.isObjectPreAllocated(FI)) {
1152 UseFP |= (HasAlloca || HasExtraAlign);
1163 bool HasFP = hasFP(MF);
1164 assert((HasFP || !UseFP) &&
"This function must have frame pointer");
1190 if (Offset > 0 && !HasFP)
1205 if (!UseFP && !UseAP)
1206 RealOffset = FrameSize+
Offset;
1212 bool &PrologueStubs)
const {
1217 PrologueStubs =
false;
1222 if (useSpillFunction(MF, CSI)) {
1223 PrologueStubs =
true;
1235 if (StkOvrFlowEnabled) {
1237 SpillOpc = IsPIC ? Hexagon::SAVE_REGISTERS_CALL_V4STK_EXT_PIC
1238 : Hexagon::SAVE_REGISTERS_CALL_V4STK_EXT;
1240 SpillOpc = IsPIC ? Hexagon::SAVE_REGISTERS_CALL_V4STK_PIC
1241 : Hexagon::SAVE_REGISTERS_CALL_V4STK;
1244 SpillOpc = IsPIC ? Hexagon::SAVE_REGISTERS_CALL_V4_EXT_PIC
1245 : Hexagon::SAVE_REGISTERS_CALL_V4_EXT;
1247 SpillOpc = IsPIC ? Hexagon::SAVE_REGISTERS_CALL_V4_PIC
1248 : Hexagon::SAVE_REGISTERS_CALL_V4;
1252 BuildMI(MBB, MI, DL, HII.get(SpillOpc))
1253 .addExternalSymbol(SpillFun);
1256 addCalleeSaveRegistersAsImpOperand(SaveRegsCall, CSI,
false,
true);
1258 for (
unsigned I = 0;
I < CSI.size(); ++
I)
1263 for (
unsigned i = 0, n = CSI.size(); i < n; ++i) {
1264 unsigned Reg = CSI[i].getReg();
1269 int FI = CSI[i].getFrameIdx();
1271 HII.storeRegToStackSlot(MBB, MI, Reg, IsKill, FI, RC, &HRI);
1288 if (useRestoreFunction(MF, CSI)) {
1305 RetOpc = IsPIC ? Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT_PIC
1306 : Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT;
1308 RetOpc = IsPIC ? Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_PIC
1309 : Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4;
1310 DeallocCall =
BuildMI(MBB, MI, DL, HII.get(RetOpc))
1311 .addExternalSymbol(RestoreFn);
1315 assert(It->isReturn() && std::next(It) == MBB.
end());
1318 RetOpc = IsPIC ? Hexagon::RESTORE_DEALLOC_RET_JMP_V4_EXT_PIC
1319 : Hexagon::RESTORE_DEALLOC_RET_JMP_V4_EXT;
1321 RetOpc = IsPIC ? Hexagon::RESTORE_DEALLOC_RET_JMP_V4_PIC
1322 : Hexagon::RESTORE_DEALLOC_RET_JMP_V4;
1323 DeallocCall =
BuildMI(MBB, It, DL, HII.get(RetOpc))
1324 .addExternalSymbol(RestoreFn);
1328 addCalleeSaveRegistersAsImpOperand(DeallocCall, CSI,
true,
false);
1332 for (
unsigned i = 0; i < CSI.size(); ++i) {
1333 unsigned Reg = CSI[i].getReg();
1335 int FI = CSI[i].getFrameIdx();
1336 HII.loadRegFromStackSlot(MBB, MI, Reg, FI, RC, &HRI);
1348 assert((Opc == Hexagon::ADJCALLSTACKDOWN || Opc == Hexagon::ADJCALLSTACKUP) &&
1349 "Cannot handle this call frame pseudo instruction");
1350 return MBB.
erase(I);
1363 if (!HasAlloca || !NeedsAlign)
1383 assert(A <= 8 &&
"Unexpected local frame alignment");
1390 if (!DealignSlots.
empty()) {
1393 bool KeepOld =
true;
1397 auto *PV = MMO->getPseudoValue();
1398 if (
auto *
FS = dyn_cast_or_null<FixedStackPseudoSourceValue>(PV)) {
1399 int FI =
FS->getFrameIndex();
1400 if (DealignSlots.
count(FI)) {
1402 auto *NewMMO = MF.getMachineMemOperand(MMO->getPointerInfo(),
1403 MMO->getFlags(), MMO->getSize(), A,
1404 MMO->getAAInfo(), MMO->getRanges(),
1405 MMO->getSyncScopeID(), MMO->getOrdering(),
1406 MMO->getFailureOrdering());
1415 MI.setMemRefs(MF, new_memops);
1423 AP = AI->getOperand(0).getReg();
1433 auto IsUsed = [&HRI,&
MRI] (
unsigned Reg) ->
bool {
1465 BitVector SRegs(Hexagon::NUM_TARGET_REGS);
1474 for (
unsigned i = 0, n = CSI.size(); i < n; ++i) {
1475 unsigned R = CSI[i].getReg();
1487 for (
int x = Reserved.find_first(); x >= 0; x = Reserved.find_next(x)) {
1501 BitVector TmpSup(Hexagon::NUM_TARGET_REGS);
1507 for (
int x = TmpSup.find_first(); x >= 0; x = TmpSup.find_next(x)) {
1546 const SpillSlot *FixedSlots = getCalleeSavedSpillSlots(NumFixed);
1547 for (
const SpillSlot *S = FixedSlots; S != FixedSlots+NumFixed; ++S) {
1551 int FI = MFI.CreateFixedSpillStackObject(TRI->
getSpillSize(*RC), S->Offset);
1552 MinOffset = std::min(MinOffset, S->Offset);
1554 SRegs[S->Reg] =
false;
1564 int Off = MinOffset -
Size;
1568 int FI = MFI.CreateFixedSpillStackObject(Size, Off);
1569 MinOffset = std::min(MinOffset, Off);
1575 dbgs() <<
"CS information: {";
1576 for (
unsigned i = 0, n = CSI.size(); i < n; ++i) {
1577 int FI = CSI[i].getFrameIdx();
1578 int Off = MFI.getObjectOffset(FI);
1589 bool MissedReg =
false;
1609 if (!Hexagon::ModRegsRegClass.
contains(DstR) ||
1610 !Hexagon::ModRegsRegClass.
contains(SrcR))
1615 BuildMI(B, It, DL, HII.get(TargetOpcode::COPY), DstR)
1639 unsigned TfrOpc = (Opc == Hexagon::STriw_pred) ? Hexagon::C2_tfrpr
1640 : Hexagon::A2_tfrcrr;
1641 BuildMI(B, It, DL, HII.get(TfrOpc), TmpR)
1645 BuildMI(B, It, DL, HII.get(Hexagon::S2_storeri_io))
1670 BuildMI(B, It, DL, HII.get(Hexagon::L2_loadri_io), TmpR)
1677 unsigned TfrOpc = (Opc == Hexagon::LDriw_pred) ? Hexagon::C2_tfrrp
1678 : Hexagon::A2_tfrrcr;
1679 BuildMI(B, It, DL, HII.get(TfrOpc), DstR)
1698 auto *RC = &Hexagon::HvxVRRegClass;
1707 BuildMI(B, It, DL, HII.get(Hexagon::A2_tfrsi), TmpR0)
1708 .addImm(0x01010101);
1710 BuildMI(B, It, DL, HII.get(Hexagon::V6_vandqrt), TmpR1)
1716 expandStoreVec(B, std::prev(It), MRI, HII, NewRegs);
1734 auto *RC = &Hexagon::HvxVRRegClass;
1742 BuildMI(B, It, DL, HII.get(Hexagon::A2_tfrsi), TmpR0)
1743 .addImm(0x01010101);
1747 expandLoadVec(B, std::prev(It), MRI, HII, NewRegs);
1749 BuildMI(B, It, DL, HII.get(Hexagon::V6_vandvrt), DstR)
1776 for (
auto R = B.
begin(); R != It; ++R) {
1783 Register SrcLo = HRI.getSubReg(SrcR, Hexagon::vsub_lo);
1784 Register SrcHi = HRI.getSubReg(SrcR, Hexagon::vsub_hi);
1787 bool NeedsAligna = needsAligna(MF);
1789 unsigned Size = HRI.getSpillSize(Hexagon::HvxVRRegClass);
1790 unsigned NeedAlign = HRI.getSpillAlignment(Hexagon::HvxVRRegClass);
1791 unsigned HasAlign = MFI.getObjectAlignment(FI);
1794 auto UseAligned = [&] (
unsigned NeedAlign,
unsigned HasAlign) {
1795 return !NeedsAligna && (NeedAlign <= HasAlign);
1800 StoreOpc = UseAligned(NeedAlign, HasAlign) ? Hexagon::V6_vS32b_ai
1801 : Hexagon::V6_vS32Ub_ai;
1802 BuildMI(B, It, DL, HII.get(StoreOpc))
1811 StoreOpc = UseAligned(NeedAlign, HasAlign) ? Hexagon::V6_vS32b_ai
1812 : Hexagon::V6_vS32Ub_ai;
1813 BuildMI(B, It, DL, HII.get(StoreOpc))
1836 Register DstHi = HRI.getSubReg(DstR, Hexagon::vsub_hi);
1837 Register DstLo = HRI.getSubReg(DstR, Hexagon::vsub_lo);
1839 bool NeedsAligna = needsAligna(MF);
1841 unsigned Size = HRI.getSpillSize(Hexagon::HvxVRRegClass);
1842 unsigned NeedAlign = HRI.getSpillAlignment(Hexagon::HvxVRRegClass);
1843 unsigned HasAlign = MFI.getObjectAlignment(FI);
1846 auto UseAligned = [&] (
unsigned NeedAlign,
unsigned HasAlign) {
1847 return !NeedsAligna && (NeedAlign <= HasAlign);
1851 LoadOpc = UseAligned(NeedAlign, HasAlign) ? Hexagon::V6_vL32b_ai
1852 : Hexagon::V6_vL32Ub_ai;
1853 BuildMI(B, It, DL, HII.get(LoadOpc), DstLo)
1859 LoadOpc = UseAligned(NeedAlign, HasAlign) ? Hexagon::V6_vL32b_ai
1860 : Hexagon::V6_vL32Ub_ai;
1861 BuildMI(B, It, DL, HII.get(LoadOpc), DstHi)
1879 bool NeedsAligna = needsAligna(MF);
1886 unsigned NeedAlign = HRI.getSpillAlignment(Hexagon::HvxVRRegClass);
1887 unsigned HasAlign = MFI.getObjectAlignment(FI);
1888 bool UseAligned = !NeedsAligna && (NeedAlign <= HasAlign);
1889 unsigned StoreOpc = UseAligned ? Hexagon::V6_vS32b_ai
1890 : Hexagon::V6_vS32Ub_ai;
1891 BuildMI(B, It, DL, HII.get(StoreOpc))
1910 bool NeedsAligna = needsAligna(MF);
1916 unsigned NeedAlign = HRI.getSpillAlignment(Hexagon::HvxVRRegClass);
1917 unsigned HasAlign = MFI.getObjectAlignment(FI);
1918 bool UseAligned = !NeedsAligna && (NeedAlign <= HasAlign);
1919 unsigned LoadOpc = UseAligned ? Hexagon::V6_vL32b_ai
1920 : Hexagon::V6_vL32Ub_ai;
1921 BuildMI(B, It, DL, HII.get(LoadOpc), DstR)
1934 bool Changed =
false;
1936 for (
auto &B : MF) {
1941 NextI = std::next(
I);
1945 case TargetOpcode::COPY:
1946 Changed |= expandCopy(B,
I, MRI, HII, NewRegs);
1948 case Hexagon::STriw_pred:
1949 case Hexagon::STriw_ctr:
1950 Changed |= expandStoreInt(B,
I, MRI, HII, NewRegs);
1952 case Hexagon::LDriw_pred:
1953 case Hexagon::LDriw_ctr:
1954 Changed |= expandLoadInt(B,
I, MRI, HII, NewRegs);
1956 case Hexagon::PS_vstorerq_ai:
1957 Changed |= expandStoreVecPred(B,
I, MRI, HII, NewRegs);
1959 case Hexagon::PS_vloadrq_ai:
1960 Changed |= expandLoadVecPred(B,
I, MRI, HII, NewRegs);
1962 case Hexagon::PS_vloadrw_ai:
1963 Changed |= expandLoadVec2(B,
I, MRI, HII, NewRegs);
1965 case Hexagon::PS_vstorerw_ai:
1966 Changed |= expandStoreVec2(B,
I, MRI, HII, NewRegs);
1980 SavedRegs.
resize(HRI.getNumRegs());
1990 expandSpillMacros(MF, NewRegs);
1992 optimizeSpillSlots(MF, NewRegs);
1996 if (!NewRegs.
empty() || mayOverflowFrameOffset(MF)) {
2002 SpillRCs.
insert(&Hexagon::IntRegsRegClass);
2004 for (
unsigned VR : NewRegs)
2007 for (
auto *RC : SpillRCs) {
2011 switch (RC->getID()) {
2012 case Hexagon::IntRegsRegClassID:
2015 case Hexagon::HvxQRRegClassID:
2019 unsigned S = HRI.getSpillSize(*RC), A = HRI.getSpillAlignment(*RC);
2020 for (
unsigned i = 0; i < Num; i++) {
2038 auto isDead = [&FIR,&DeadMap] (
unsigned Reg) ->
bool {
2039 auto F = DeadMap.find({
Reg,0});
2040 if (
F == DeadMap.end())
2042 for (
auto &DR :
F->second)
2043 if (DR.contains(FIR))
2065 auto &HII = *HST.getInstrInfo();
2066 auto &HRI = *HST.getRegisterInfo();
2070 using BlockIndexMap =
2071 std::map<MachineBasicBlock *, HexagonBlockRanges::InstrIndexMap>;
2072 using BlockRangeMap =
2073 std::map<MachineBasicBlock *, HexagonBlockRanges::RangeList>;
2081 SlotInfo() =
default;
2084 BlockIndexMap BlockIndexes;
2086 std::map<int,SlotInfo> FIRangeMap;
2095 if (HaveRC ==
nullptr || HaveRC == NewRC)
2100 if (NewRC->hasSubClassEq(HaveRC))
2107 for (
auto &B : MF) {
2108 std::map<int,IndexType> LastStore, LastLoad;
2111 auto P = BlockIndexes.insert(
2113 auto &IndexMap =
P.first->second;
2115 << IndexMap <<
'\n');
2117 for (
auto &
In : B) {
2119 bool Load = HII.isLoadFromStackSlot(
In, LFI) && !HII.isPredicated(
In);
2120 bool Store = HII.isStoreToStackSlot(
In, SFI) && !HII.isPredicated(
In);
2121 if (Load && Store) {
2133 if (Load || Store) {
2134 int TFI = Load ? LFI : SFI;
2135 unsigned AM = HII.getAddrMode(
In);
2136 SlotInfo &
SI = FIRangeMap[TFI];
2140 unsigned OpNum = Load ? 0 : 2;
2141 auto *RC = HII.getRegClass(
In.getDesc(), OpNum, &HRI, MF);
2142 RC = getCommonRC(SI.RC, RC);
2150 unsigned S = HII.getMemAccessSize(
In);
2151 if (SI.Size != 0 && SI.Size != S)
2157 for (
auto *Mo :
In.memoperands()) {
2158 if (!Mo->isVolatile() && !Mo->isAtomic())
2169 for (
unsigned i = 0, n =
In.getNumOperands(); i < n; ++i) {
2176 if (i+1 >= n || !
In.getOperand(i+1).isImm() ||
2177 In.getOperand(i+1).getImm() != 0)
2179 if (BadFIs.
count(FI))
2185 LastStore[FI] = IndexType::Entry;
2186 LastLoad[FI] =
Index;
2190 RL.
add(LastStore[FI], LastLoad[FI],
false,
false);
2192 RL.
add(IndexType::Entry, LastLoad[FI],
false,
false);
2194 LastStore[FI] =
Index;
2201 for (
auto &
I : LastLoad) {
2202 IndexType LL =
I.second;
2205 auto &RL = FIRangeMap[
I.first].Map[&
B];
2206 IndexType &
LS = LastStore[
I.first];
2208 RL.add(LS, LL,
false,
false);
2210 RL.add(IndexType::Entry, LL,
false,
false);
2213 for (
auto &
I : LastStore) {
2214 IndexType
LS =
I.second;
2217 auto &RL = FIRangeMap[
I.first].Map[&
B];
2223 for (
auto &
P : FIRangeMap) {
2224 dbgs() <<
"fi#" <<
P.first;
2225 if (BadFIs.
count(
P.first))
2228 if (
P.second.RC !=
nullptr)
2229 dbgs() << HRI.getRegClassName(
P.second.RC) <<
'\n';
2231 dbgs() <<
"<null>\n";
2232 for (
auto &R :
P.second.Map)
2243 std::map<MachineBasicBlock*,std::vector<int>> BlockFIMap;
2245 for (
auto &
P : FIRangeMap) {
2247 if (BadFIs.
count(
P.first))
2249 for (
auto &B : MF) {
2250 auto F =
P.second.Map.find(&B);
2252 if (
F ==
P.second.Map.end() ||
F->second.empty())
2255 if (IR.
start() == IndexType::Entry)
2256 LoxFIs.insert(
P.first);
2257 BlockFIMap[&
B].push_back(
P.first);
2262 dbgs() <<
"Block-to-FI map (* -- live-on-exit):\n";
2263 for (
auto &
P : BlockFIMap) {
2264 auto &FIs =
P.second;
2268 for (
auto I : FIs) {
2269 dbgs() <<
" fi#" <<
I;
2270 if (LoxFIs.count(
I))
2282 for (
auto &B : MF) {
2283 auto F = BlockIndexes.find(&B);
2284 assert(
F != BlockIndexes.end());
2291 for (
auto FI : BlockFIMap[&B]) {
2292 if (BadFIs.
count(FI))
2296 for (
auto &Range : RL) {
2298 if (!IndexType::isInstr(Range.start()) ||
2299 !IndexType::isInstr(Range.end()))
2308 SrcOp.getSubReg() };
2309 auto *RC = HII.getRegClass(SI.
getDesc(), 2, &HRI, MF);
2311 unsigned FoundR = this->findPhysReg(MF, Range, IM, DM, RC);
2327 if (SrcRR.
Reg != FoundR || SrcRR.
Sub != 0) {
2329 CopyIn =
BuildMI(B, StartIt, DL, HII.get(TargetOpcode::COPY), FoundR)
2335 if (LoxFIs.count(FI) && (&Range == &RL.back())) {
2337 if (
unsigned SR = SrcOp.getSubReg())
2338 SrcOp.setReg(HRI.getSubReg(FoundR, SR));
2340 SrcOp.setReg(FoundR);
2343 SrcOp.setIsKill(
false);
2346 IM.replaceInstr(&SI, CopyIn);
2350 for (
auto It = StartIt; It != EndIt; It = NextIt) {
2352 NextIt = std::next(It);
2354 if (!HII.isLoadFromStackSlot(MI, TFI) || TFI != FI)
2359 if (DstR != FoundR) {
2361 unsigned MemSize = HII.getMemAccessSize(MI);
2363 unsigned CopyOpc = TargetOpcode::COPY;
2364 if (HII.isSignExtendingLoad(MI))
2365 CopyOpc = (MemSize == 1) ? Hexagon::A2_sxtb : Hexagon::A2_sxth;
2366 else if (HII.isZeroExtendingLoad(MI))
2367 CopyOpc = (MemSize == 1) ? Hexagon::A2_zxtb : Hexagon::A2_zxth;
2368 CopyOut =
BuildMI(B, It, DL, HII.get(CopyOpc), DstR)
2371 IM.replaceInstr(&MI, CopyOut);
2378 DM[RR].subtract(Range);
2384 void HexagonFrameLowering::expandAlloca(
MachineInstr *AI,
2410 BuildMI(MB, AI, DL, HII.get(Hexagon::A2_sub), Rd)
2415 BuildMI(MB, AI, DL, HII.get(Hexagon::A2_sub), SP)
2421 BuildMI(MB, AI, DL, HII.get(Hexagon::A2_andir), Rd)
2425 BuildMI(MB, AI, DL, HII.get(Hexagon::A2_andir), SP)
2431 BuildMI(MB, AI, DL, HII.get(TargetOpcode::COPY), SP)
2436 BuildMI(MB, AI, DL, HII.get(Hexagon::A2_addi), Rd)
2456 if (
I.getOpcode() == Hexagon::PS_aligna)
2463 void HexagonFrameLowering::addCalleeSaveRegistersAsImpOperand(
MachineInstr *
MI,
2464 const CSIVect &CSI,
bool IsDef,
bool IsKill)
const {
2475 const CSIVect &CSI)
const {
2486 BitVector Regs(Hexagon::NUM_TARGET_REGS);
2487 for (
unsigned i = 0, n = CSI.size(); i < n; ++i) {
2488 unsigned R = CSI[i].getReg();
2489 if (!Hexagon::DoubleRegsRegClass.
contains(R))
2494 if (F != Hexagon::D8)
2498 if (N >= 0 && N != F+1)
2506 bool HexagonFrameLowering::useSpillFunction(
const MachineFunction &MF,
2507 const CSIVect &CSI)
const {
2508 if (shouldInlineCSR(MF, CSI))
2510 unsigned NumCSI = CSI.size();
2516 return Threshold < NumCSI;
2519 bool HexagonFrameLowering::useRestoreFunction(
const MachineFunction &MF,
2520 const CSIVect &CSI)
const {
2521 if (shouldInlineCSR(MF, CSI))
2531 unsigned NumCSI = CSI.size();
2537 return Threshold < NumCSI;
2540 bool HexagonFrameLowering::mayOverflowFrameOffset(
MachineFunction &MF)
const {
2545 if (HST.useHVXOps() && StackSize > 256)
2552 bool HasImmStack =
false;
2553 unsigned MinLS = ~0u;
2559 case Hexagon::S4_storeirit_io:
2560 case Hexagon::S4_storeirif_io:
2561 case Hexagon::S4_storeiri_io:
2564 case Hexagon::S4_storeirht_io:
2565 case Hexagon::S4_storeirhf_io:
2566 case Hexagon::S4_storeirh_io:
2569 case Hexagon::S4_storeirbt_io:
2570 case Hexagon::S4_storeirbf_io:
2571 case Hexagon::S4_storeirb_io:
2574 MinLS = std::min(MinLS, LS);
2581 return !isUInt<6>(StackSize >> MinLS);
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
bool dominates(const MachineDomTreeNode *A, const MachineDomTreeNode *B) const
bool isCall(QueryType Type=AnyInBundle) const
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)
This class represents lattice values for constants.
bool hasOptNone() const
Do not optimize this function (-O0).
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 ...
bool hasOptSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
INITIALIZE_PASS(HexagonCallFrameInformation, "hexagon-cfi", "Hexagon call frame information", false, false) FunctionPass *llvm
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
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.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
void push_back(const T &Elt)
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
static Optional< MachineBasicBlock::iterator > findCFILocation(MachineBasicBlock &B)
LLVM_NODISCARD unsigned addFrameInst(const MCCFIInstruction &Inst)
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.
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 void dump_registers(BitVector &Regs, const TargetRegisterInfo &TRI)
unsigned getSubReg() const
static RegisterSet expandToSubRegs(RegisterRef R, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI)
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Hexagon target-specific information for each MachineFunction.
static RegisterPass< DebugifyModulePass > DM("debugify", "Attach debug info to everything")
unsigned const TargetRegisterInfo * TRI
MachineModuleInfo & getMMI() const
static const char * getSpillFunctionFor(unsigned MaxReg, SpillKind SpillType, bool Stkchk=false)
bool contains(MCPhysReg Reg) const
Returns true if register Reg is contained in the set.
Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
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)
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
iterator_range< succ_iterator > successors()
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)
A description of a memory reference used in the backend.
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...
LLVM_NODISCARD bool empty() const
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.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
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.
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.
void setLocalFrameMaxAlign(Align Alignment)
Required alignment of the local object blob, which is the strictest alignment of any object in it...
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.
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.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
MachineBasicBlock * findNearestCommonDominator(MachineBasicBlock *A, MachineBasicBlock *B) const
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
int CreateSpillStackObject(uint64_t Size, Align Alignment)
Create a new statically sized stack object that represents a spill slot, returning a nonnegative iden...
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"))
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
bool isReturn(QueryType Type=AnyInBundle) const
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)
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...
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...
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...
static MachineOperand CreateReg(Register 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)
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
This struct is a compact representation of a valid (non-zero power of two) alignment.
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.
Align max(MaybeAlign Lhs, Align Rhs)
unsigned getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call...
static uint64_t add(uint64_t LeftOp, uint64_t RightOp)
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
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.
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()
static cl::opt< unsigned > Threshold("loop-unswitch-threshold", cl::desc("Max loop size to unswitch"), cl::init(100), cl::Hidden)
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)
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
RegToRangeMap computeLiveMap(InstrIndexMap &IndexMap)
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
uint64_t estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
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...
static bool enableAllocFrameElim(const MachineFunction &MF)
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
const MachineInstrBuilder & cloneMemRefs(const MachineInstr &OtherMI) const
bool hasMinSize() 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 LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
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...
Align getLocalFrameMaxAlign() const
Return the required alignment of the local object blob.
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool enableCalleeSaveSkip(const MachineFunction &MF) const override
Returns true if the target can safely skip saving callee-saved registers for noreturn nounwind functi...
MachinePostDominatorTree - an analysis pass wrapper for DominatorTree used to compute the post-domina...
const HexagonInstrInfo * getInstrInfo() const override
rpo Deduce function attributes in RPO
A vector that has set insertion semantics.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
#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...
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...
Register getReg() const
getReg - Returns the register number.
void stepForward(const MachineInstr &MI, SmallVectorImpl< std::pair< MCPhysReg, const MachineOperand *>> &Clobbers)
Simulates liveness when stepping forward over an instruction(bundle).
void initializeHexagonCallFrameInformationPass(PassRegistry &)
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 needsFrameMoves() const
True if this function needs frame moves for debug or exceptions.
bool needsAligna(const MachineFunction &MF) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
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...
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.
Wrapper class representing virtual and physical registers.
This class contains meta information specific to a module.
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.