69#define DEBUG_TYPE "hexagon-pei"
79 return containsHLXObject(HST, EltTy);
177 if (!HST.getFrameLowering()->hasFP(MF))
188 Register SCSPReg = HST.getSCSPReg();
189 const auto &HRI = *HST.getRegisterInfo();
190 if (!HST.isRegisterReservedByUser(SCSPReg))
195 " to use shadow call stack on Hexagon");
197 const auto &HII = *HST.getInstrInfo();
211 MBB.addLiveIn(SCSPReg);
218 unsigned DwarfSCSReg = HRI.getDwarfRegNum(SCSPReg,
true);
221 assert(DwarfSCSReg < 32 &&
"SCS register should be < 32");
222 const char CFIInst[] = {
223 (
char)dwarf::DW_CFA_val_expression,
226 (
char)(
unsigned)(dwarf::DW_OP_breg0 + DwarfSCSReg),
246 Register SCSPReg = HST.getSCSPReg();
247 const auto &HII = *HST.getInstrInfo();
250 BuildMI(
MBB,
MI,
DL, HII.get(Hexagon::L2_loadri_io), Hexagon::R31)
283 char HexagonCallFrameInformation::ID = 0;
287bool HexagonCallFrameInformation::runOnMachineFunction(
MachineFunction &MF) {
288 auto &HFI = *MF.
getSubtarget<HexagonSubtarget>().getFrameLowering();
293 HFI.insertCFIInstructions(MF);
298 "Hexagon call frame information",
false,
false)
301 return new HexagonCallFrameInformation();
318 if (!RegNo || SubReg < RegNo)
328 static_assert(Hexagon::R1 > 0,
329 "Assume physical registers are encoded as positive integers");
334 for (
unsigned I = 1,
E = CSI.
size();
I <
E; ++
I) {
355 unsigned Opc =
MI.getOpcode();
357 case Hexagon::PS_alloca:
380 for (
MCPhysReg S : HRI.subregs_inclusive(R))
385 if (MO.isRegMask()) {
390 const uint32_t *BM = MO.getRegMask();
394 if (!(BM[R / 32] & (1u << (R % 32))))
409 unsigned RetOpc =
I->getOpcode();
410 return RetOpc == Hexagon::PS_tailcall_i || RetOpc == Hexagon::PS_tailcall_r;
432 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4:
433 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4_PIC:
434 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4_EXT:
435 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4_EXT_PIC:
436 case Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT:
437 case Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT_PIC:
438 case Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4:
439 case Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_PIC:
452 return F.hasOptSize() && !
F.hasMinSize();
464 MachineBasicBlock *&PrologB, MachineBasicBlock *&EpilogB)
const {
465 static unsigned ShrinkCounter = 0;
467 if (MF.
getSubtarget<HexagonSubtarget>().isEnvironmentMusl() &&
475 if (CLOpts.shrink_frame_limit) {
476 if (ShrinkCounter >= *CLOpts.shrink_frame_limit)
481 auto &HRI = *MF.
getSubtarget<HexagonSubtarget>().getRegisterInfo();
483 MachineDominatorTree MDT;
485 MachinePostDominatorTree MPT;
488 using UnsignedMap = DenseMap<unsigned, unsigned>;
489 using RPOTType = ReversePostOrderTraversal<const MachineFunction *>;
495 RPO[
I->getNumber()] = RPON++;
501 unsigned BN = RPO[
I.getNumber()];
502 for (MachineBasicBlock *Succ :
I.successors())
504 if (RPO[Succ->getNumber()] <= BN)
511 BitVector CSR(Hexagon::NUM_TARGET_REGS);
512 for (
const MCPhysReg *
P = HRI.getCalleeSavedRegs(&MF); *
P; ++
P)
521 dbgs() <<
"Blocks needing SF: {";
522 for (
auto &
B : SFBlocks)
527 if (SFBlocks.
empty())
531 MachineBasicBlock *DomB = SFBlocks[0];
532 for (
unsigned i = 1, n = SFBlocks.
size(); i < n; ++i) {
537 MachineBasicBlock *PDomB = SFBlocks[0];
538 for (
unsigned i = 1, n = SFBlocks.
size(); i < n; ++i) {
544 dbgs() <<
"Computed dom block: ";
549 dbgs() <<
", computed pdom block: ";
565 LLVM_DEBUG(
dbgs() <<
"PDom block does not post-dominate dom block\n");
588 findShrunkPrologEpilog(MF, PrologB, EpilogB);
590 bool PrologueStubs =
false;
592 insertCSRSpillsInBlock(*PrologB, CSI, HRI, PrologueStubs);
598 insertAlignaInBlock(*PrologB, AfterCSR);
599 insertPrologueInBlock(*PrologB, PrologueStubs);
607 while (AfterProlog != PrologB->
end() &&
613 updateEntryPaths(MF, *PrologB);
616 insertCSRRestoresInBlock(*EpilogB, CSI, HRI);
617 insertEpilogueInBlock(*EpilogB);
620 if (
B.isReturnBlock())
621 insertCSRRestoresInBlock(
B, CSI, HRI);
624 if (
B.isReturnBlock())
625 insertEpilogueInBlock(
B);
643 BitVector DoneT(MaxBN+1), DoneF(MaxBN+1), Path(MaxBN+1);
644 updateExitPaths(*EpilogB, *EpilogB, DoneT, DoneF, Path);
653 assert(
F.hasFnAttribute(Attribute::NoReturn) &&
654 F.getFunction().hasFnAttribute(Attribute::NoUnwind) &&
655 !
F.getFunction().hasFnAttribute(Attribute::UWTable));
671 assert(!MFI.hasVarSizedObjects() &&
672 !HST.getRegisterInfo()->hasStackRealignment(MF));
673 return F.hasFnAttribute(Attribute::NoReturn) &&
674 F.hasFnAttribute(Attribute::NoUnwind) &&
675 !
F.hasFnAttribute(Attribute::UWTable) && HST.noreturnStackElim() &&
676 MFI.getStackSize() == 0;
679void HexagonFrameLowering::insertPrologueInBlock(MachineBasicBlock &
MBB,
680 bool PrologueStubs)
const {
686 auto &HMFI = *MF.
getInfo<HexagonMachineFunctionInfo>();
689 uint64_t VTCMFrameSize = HMFI.getVTCMFrameInfo().getStackSize();
698 FrameSize = MaxCFA +
alignTo(FrameSize, MaxAlign);
709 SmallVector<MachineInstr *, 4> AdjustRegs;
712 if (
MI.getOpcode() == Hexagon::PS_alloca)
715 for (
auto *
MI : AdjustRegs) {
716 assert((
MI->getOpcode() == Hexagon::PS_alloca) &&
"Expected alloca");
717 expandAlloca(
MI, MF, HII, SP, MaxCF);
718 MI->eraseFromParent();
723 if (MF.getFunction().isVarArg() &&
724 MF.getSubtarget<HexagonSubtarget>().isEnvironmentMusl()) {
726 int NumVarArgRegs = 6 - FirstVarArgSavedReg;
727 int RegisterSavedAreaSizePlusPadding = (NumVarArgRegs % 2 == 0)
729 : NumVarArgRegs * 4 + 4;
730 if (RegisterSavedAreaSizePlusPadding > 0) {
735 .
addImm(-RegisterSavedAreaSizePlusPadding)
740 auto &HMFI = *MF.getInfo<HexagonMachineFunctionInfo>();
741 for (
int i = HMFI.getFirstNamedArgFrameIndex(),
742 e = HMFI.getLastNamedArgFrameIndex(); i >= e; --i) {
750 unsigned LDOpc, STOpc;
754 if (ObjAlign > ObjSize) {
757 else if (ObjSize <= 2)
759 else if (ObjSize <= 4)
761 else if (ObjSize > 4)
765 switch (OpcodeChecker) {
767 LDOpc = Hexagon::L2_loadrb_io;
768 STOpc = Hexagon::S2_storerb_io;
771 LDOpc = Hexagon::L2_loadrh_io;
772 STOpc = Hexagon::S2_storerh_io;
775 LDOpc = Hexagon::L2_loadri_io;
776 STOpc = Hexagon::S2_storeri_io;
780 LDOpc = Hexagon::L2_loadrd_io;
781 STOpc = Hexagon::S2_storerd_io;
785 Register RegUsed = LDOpc == Hexagon::L2_loadrd_io ? Hexagon::D3
787 int LoadStoreCount = ObjSize / OpcodeChecker;
789 if (ObjSize % OpcodeChecker)
797 NumBytes =
alignTo(NumBytes, ObjAlign);
800 while (
Count < LoadStoreCount) {
804 .
addImm(RegisterSavedAreaSizePlusPadding +
821 NumBytes =
alignTo(NumBytes, 8);
826 NumBytes = (NumVarArgRegs % 2 == 0) ? NumBytes : NumBytes + 4;
828 for (
int j = FirstVarArgSavedReg, i = 0;
j < 6; ++
j, ++i) {
843 .
addImm(-int64_t(MaxAlign.value()));
848 if (HST.getCLOpts().stackovf_sanitizer && !PrologueStubs)
851 }
else if (NumBytes > 0) {
853 auto *
TLI = HST.getTargetLowering();
855 unsigned ProbeSize = 0;
858 ProbeSize =
TLI->getStackProbeSize(MF, StackAlign);
860 if (NeedsProbing && NumBytes > ProbeSize) {
879 if (
int VSPFI = HMFI.getVSPFrameIndex(); VSPFI >= 0) {
886 HII.storeRegToStackSlot(
MBB,
InsertPt, Hexagon::R7,
true, VSPFI,
887 &Hexagon::IntRegsRegClass,
Register());
891 .
addImm(VTCMFrameSize / 2048)
895void HexagonFrameLowering::insertEpilogueInBlock(MachineBasicBlock &
MBB)
const {
905 const auto &HMFI = *MF.
getInfo<HexagonMachineFunctionInfo>();
906 uint64_t VTCMFrameSize = HMFI.getVTCMFrameInfo().getStackSize();
909 .
addImm(VTCMFrameSize / 2048);
915 MF.
getSubtarget<HexagonSubtarget>().isEnvironmentMusl()) {
917 int NumVarArgRegs = 6 - FirstVarArgSavedReg;
918 int RegisterSavedAreaSizePlusPadding = (NumVarArgRegs % 2 == 0) ?
919 (NumVarArgRegs * 4) : (NumVarArgRegs * 4 + 4);
920 NumBytes += RegisterSavedAreaSizePlusPadding;
931 unsigned RetOpc = RetI ? RetI->
getOpcode() : 0;
934 if (RetOpc == Hexagon::EH_RETURN_JMPR) {
951 if (RetOpc == Hexagon::RESTORE_DEALLOC_RET_JMP_V4 ||
952 RetOpc == Hexagon::RESTORE_DEALLOC_RET_JMP_V4_PIC ||
953 RetOpc == Hexagon::RESTORE_DEALLOC_RET_JMP_V4_EXT ||
954 RetOpc == Hexagon::RESTORE_DEALLOC_RET_JMP_V4_EXT_PIC) {
971 bool NeedsDeallocframe =
true;
972 unsigned PrevOpc = 0;
975 PrevOpc = PrevIt->getOpcode();
976 if (PrevOpc == Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4 ||
977 PrevOpc == Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_PIC ||
978 PrevOpc == Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT ||
979 PrevOpc == Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT_PIC ||
980 PrevOpc == Hexagon::PS_call_nr || PrevOpc == Hexagon::PS_callr_nr)
981 NeedsDeallocframe =
false;
984 if (!MF.
getSubtarget<HexagonSubtarget>().isEnvironmentMusl() ||
986 if (!NeedsDeallocframe) {
991 if (NeedsSCS && PrevOpc != Hexagon::PS_call_nr &&
992 PrevOpc != Hexagon::PS_callr_nr)
994 "useRestoreFunction() should have prevented this");
1000 if (RetOpc != Hexagon::PS_jmpret || !HST.getCLOpts().dealloc_ret ||
1011 unsigned NewOpc = Hexagon::L4_return;
1012 MachineInstrBuilder NewI =
BuildMI(
MBB, RetI, dl, HII.get(NewOpc))
1022 int NumVarArgRegs = 6 - FirstVarArgSavedReg;
1023 int RegisterSavedAreaSizePlusPadding = (NumVarArgRegs % 2 == 0) ?
1024 (NumVarArgRegs * 4) : (NumVarArgRegs * 4 + 4);
1029 bool HasRestoreStub =
1031 (
I->getOpcode() == Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT ||
1033 Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT_PIC ||
1034 I->getOpcode() == Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4 ||
1035 I->getOpcode() == Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_PIC);
1036 if (!HasRestoreStub)
1040 if (RegisterSavedAreaSizePlusPadding != 0)
1043 .
addImm(RegisterSavedAreaSizePlusPadding);
1047 if (NeedsSCS && !HasRestoreStub)
1052void HexagonFrameLowering::insertAllocframe(MachineBasicBlock &
MBB,
1061 const unsigned int ALLOCFRAME_MAX = 16384;
1071 auto *
TLI = HST.getTargetLowering();
1073 unsigned ProbeSize = 0;
1076 ProbeSize =
TLI->getStackProbeSize(MF, StackAlign);
1079 if (NeedsProbing && NumBytes > ProbeSize) {
1098 }
else if (NumBytes >= ALLOCFRAME_MAX) {
1129 if (
MI.getOpcode() == Hexagon::PS_probed_stackalloc)
1134 auto *
TLI = HST.getTargetLowering();
1136 unsigned ProbeSize =
TLI->getStackProbeSize(MF, StackAlign);
1142 Register TargetReg =
MI->getOperand(0).getReg();
1173 BuildMI(*LoopMBB, LoopMBB->
end(),
DL, HII.get(Hexagon::A2_addi),
1179 BuildMI(*LoopMBB, LoopMBB->
end(),
DL, HII.get(Hexagon::S4_storeiri_io))
1185 BuildMI(*LoopMBB, LoopMBB->
end(),
DL, HII.get(Hexagon::C2_cmpgtu),
1191 BuildMI(*LoopMBB, LoopMBB->
end(),
DL, HII.get(Hexagon::J2_jumpt))
1197 BuildMI(*ExitMBB, ExitMBB->
begin(),
DL, HII.get(Hexagon::A2_tfr),
1203 MBB->addSuccessor(LoopMBB);
1208 MI->eraseFromParent();
1215void HexagonFrameLowering::insertAlignaInBlock(
1223 assert(needsAligna(MF) &&
"Unexpected stack align base register");
1242 for (
unsigned i = 0; i < Worklist.
size(); ++i) {
1243 unsigned BN = Worklist[i];
1246 if (!
MBB.isLiveIn(R.getReg()))
1247 MBB.addLiveIn(R.getReg());
1249 for (
auto &SB :
MBB.successors())
1250 Worklist.
insert(SB->getNumber());
1254bool HexagonFrameLowering::updateExitPaths(MachineBasicBlock &
MBB,
1255 MachineBasicBlock &RestoreB, BitVector &DoneT, BitVector &DoneF,
1256 BitVector &Path)
const {
1259 if (Path[BN] || DoneF[BN])
1267 bool ReachedExit =
false;
1269 ReachedExit |= updateExitPaths(*SB, RestoreB, DoneT, DoneF, Path);
1275 MachineInstr &RetI =
MBB.
back();
1285 if (ReachedExit && &
MBB != &RestoreB) {
1298static std::optional<MachineBasicBlock::iterator>
1305 auto End =
B.instr_end();
1309 if (!
I.isBundle()) {
1310 if (
I.getOpcode() == Hexagon::S2_allocframe)
1311 return std::next(It);
1315 bool HasCall =
false, HasAllocFrame =
false;
1317 while (++
T !=
End &&
T->isBundled()) {
1318 if (
T->getOpcode() == Hexagon::S2_allocframe)
1319 HasAllocFrame =
true;
1320 else if (
T->isCall())
1324 return HasCall ? It : std::next(It);
1326 return std::nullopt;
1332 insertCFIInstructionsAt(
B, *At);
1347 const MCInstrDesc &CFID = HII.get(TargetOpcode::CFI_INSTRUCTION);
1350 bool HasFP = hasFP(MF);
1353 unsigned DwFPReg = HRI.getDwarfRegNum(HRI.getFrameRegister(),
true);
1354 unsigned DwRAReg = HRI.getDwarfRegNum(HRI.getRARegister(),
true);
1381 Hexagon::R1, Hexagon::R0, Hexagon::R3, Hexagon::R2,
1382 Hexagon::R17, Hexagon::R16, Hexagon::R19, Hexagon::R18,
1383 Hexagon::R21, Hexagon::R20, Hexagon::R23, Hexagon::R22,
1384 Hexagon::R25, Hexagon::R24, Hexagon::R27, Hexagon::R26,
1385 Hexagon::D0, Hexagon::D1, Hexagon::D8, Hexagon::D9,
1386 Hexagon::D10, Hexagon::D11, Hexagon::D12, Hexagon::D13
1392 auto IfR = [
Reg] (
const CalleeSavedInfo &
C) ->
bool {
1393 return C.getReg() ==
Reg;
1412 getFrameIndexReference(MF,
F->getFrameIdx(), FrameReg).getFixed();
1418 unsigned DwarfReg = HRI.getDwarfRegNum(
Reg,
true);
1430 Register HiReg = HRI.getSubReg(
Reg, Hexagon::isub_hi);
1431 Register LoReg = HRI.getSubReg(
Reg, Hexagon::isub_lo);
1432 unsigned HiDwarfReg = HRI.getDwarfRegNum(HiReg,
true);
1433 unsigned LoDwarfReg = HRI.getDwarfRegNum(LoReg,
true);
1451 auto &HMFI = *MF.
getInfo<HexagonMachineFunctionInfo>();
1452 unsigned DwVSPReg = HRI.getDwarfRegNum(Hexagon::VSP,
true);
1453 int64_t VTCMFrameSize = HMFI.getVTCMFrameInfo().getStackSize();
1454 for (
const MCPhysReg *R = HRI.getCalleeSavedRegs(&MF); *R; ++R) {
1455 if (!Hexagon::HlxLRRegClass.
contains(*R))
1457 unsigned DwarfReg = HRI.getDwarfRegNum(*R,
true);
1459 CSI, [R](
const CalleeSavedInfo &
C) {
return C.getReg() == *
R; });
1460 if (
F == CSI.end()) {
1465 assert(HMFI.isVTCMStackIndex(
F->getFrameIdx()) &&
1466 "HLX register not spilled to the VTCM stack");
1468 VTCMFrameSize + HMFI.getMappedVTCMObjectOffset(
F->getFrameIdx());
1470 SmallString<16> Expr, Vals;
1474 Vals.
push_back(dwarf::DW_CFA_expression);
1479 (Twine(HRI.getRegAsmName(*R)) +
" at vsp + " + Twine(
Offset)).str();
1486 if (
int VSPFI = HMFI.getVSPFrameIndex(); VSPFI >= 0) {
1487 assert(HasFP &&
"A VTCM frame requires a frame pointer");
1498 bool HasExtraAlign = HRI.hasStackRealignment(MF);
1514 if (HasAlloca || HasExtraAlign)
1525 if (CLOpts.stackovf_sanitizer)
1530 if (HMFI.getVTCMFrameInfo().getStackSize())
1545 bool Stkchk =
false) {
1546 const char * V4SpillToMemoryFunctions[] = {
1547 "__save_r16_through_r17",
1548 "__save_r16_through_r19",
1549 "__save_r16_through_r21",
1550 "__save_r16_through_r23",
1551 "__save_r16_through_r25",
1552 "__save_r16_through_r27" };
1554 const char * V4SpillToMemoryStkchkFunctions[] = {
1555 "__save_r16_through_r17_stkchk",
1556 "__save_r16_through_r19_stkchk",
1557 "__save_r16_through_r21_stkchk",
1558 "__save_r16_through_r23_stkchk",
1559 "__save_r16_through_r25_stkchk",
1560 "__save_r16_through_r27_stkchk" };
1562 const char * V4SpillFromMemoryFunctions[] = {
1563 "__restore_r16_through_r17_and_deallocframe",
1564 "__restore_r16_through_r19_and_deallocframe",
1565 "__restore_r16_through_r21_and_deallocframe",
1566 "__restore_r16_through_r23_and_deallocframe",
1567 "__restore_r16_through_r25_and_deallocframe",
1568 "__restore_r16_through_r27_and_deallocframe" };
1570 const char * V4SpillFromMemoryTailcallFunctions[] = {
1571 "__restore_r16_through_r17_and_deallocframe_before_tailcall",
1572 "__restore_r16_through_r19_and_deallocframe_before_tailcall",
1573 "__restore_r16_through_r21_and_deallocframe_before_tailcall",
1574 "__restore_r16_through_r23_and_deallocframe_before_tailcall",
1575 "__restore_r16_through_r25_and_deallocframe_before_tailcall",
1576 "__restore_r16_through_r27_and_deallocframe_before_tailcall"
1579 const char **SpillFunc =
nullptr;
1583 SpillFunc = Stkchk ? V4SpillToMemoryStkchkFunctions
1584 : V4SpillToMemoryFunctions;
1587 SpillFunc = V4SpillFromMemoryFunctions;
1590 SpillFunc = V4SpillFromMemoryTailcallFunctions;
1593 assert(SpillFunc &&
"Unknown spill kind");
1598 return SpillFunc[0];
1600 return SpillFunc[1];
1602 return SpillFunc[2];
1604 return SpillFunc[3];
1606 return SpillFunc[4];
1608 return SpillFunc[5];
1622 if (HMFI.isVTCMStackIndex(FI)) {
1624 FrameReg = HRI.getVTCMStackRegister();
1626 HMFI.getMappedVTCMObjectOffset(FI));
1631 bool HasExtraAlign = HRI.hasStackRealignment(MF);
1635 Register SP = HRI.getStackRegister();
1637 Register AP = HMFI.getStackAlignBaseReg();
1652 bool UseFP =
false, UseAP =
false;
1657 if (NoOpt && !HasExtraAlign)
1662 UseFP |= (HasAlloca || HasExtraAlign);
1673 bool HasFP =
hasFP(MF);
1674 assert((HasFP || !UseFP) &&
"This function must have frame pointer");
1700 if (
Offset > 0 && !HasFP)
1715 if (!UseFP && !UseAP)
1716 RealOffset = FrameSize+
Offset;
1722 bool &PrologueStubs)
const {
1727 PrologueStubs =
false;
1732 if (useSpillFunction(MF, CSI)) {
1733 PrologueStubs =
true;
1735 bool StkOvrFlowEnabled = HST.getCLOpts().stackovf_sanitizer;
1740 bool LongCalls = HST.useLongCalls() || HST.getCLOpts().save_restore_long;
1745 if (StkOvrFlowEnabled) {
1747 SpillOpc = IsPIC ? Hexagon::SAVE_REGISTERS_CALL_V4STK_EXT_PIC
1748 : Hexagon::SAVE_REGISTERS_CALL_V4STK_EXT;
1750 SpillOpc = IsPIC ? Hexagon::SAVE_REGISTERS_CALL_V4STK_PIC
1751 : Hexagon::SAVE_REGISTERS_CALL_V4STK;
1754 SpillOpc = IsPIC ? Hexagon::SAVE_REGISTERS_CALL_V4_EXT_PIC
1755 : Hexagon::SAVE_REGISTERS_CALL_V4_EXT;
1757 SpillOpc = IsPIC ? Hexagon::SAVE_REGISTERS_CALL_V4_PIC
1758 : Hexagon::SAVE_REGISTERS_CALL_V4;
1761 MachineInstr *SaveRegsCall =
1766 addCalleeSaveRegistersAsImpOperand(SaveRegsCall, CSI,
false,
true);
1768 for (
const CalleeSavedInfo &
I : CSI)
1771 for (
const CalleeSavedInfo &
I : CSI) {
1772 MCRegister
Reg =
I.getReg();
1777 int FI =
I.getFrameIdx();
1788bool HexagonFrameLowering::insertCSRRestoresInBlock(MachineBasicBlock &
MBB,
1789 const CSIVect &CSI,
const HexagonRegisterInfo &HRI)
const {
1798 if (useRestoreFunction(MF, CSI)) {
1803 auto &HTM =
static_cast<const HexagonTargetMachine&
>(MF.
getTarget());
1804 bool IsPIC = HTM.isPositionIndependent();
1805 bool LongCalls = HST.useLongCalls() || HST.getCLOpts().save_restore_long;
1810 MachineInstr *DeallocCall =
nullptr;
1815 RetOpc = IsPIC ? Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT_PIC
1816 : Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_EXT;
1818 RetOpc = IsPIC ? Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4_PIC
1819 : Hexagon::RESTORE_DEALLOC_BEFORE_TAILCALL_V4;
1828 RetOpc = IsPIC ? Hexagon::RESTORE_DEALLOC_RET_JMP_V4_EXT_PIC
1829 : Hexagon::RESTORE_DEALLOC_RET_JMP_V4_EXT;
1831 RetOpc = IsPIC ? Hexagon::RESTORE_DEALLOC_RET_JMP_V4_PIC
1832 : Hexagon::RESTORE_DEALLOC_RET_JMP_V4;
1833 MachineInstrBuilder MIB =
1837 for (
const MachineOperand &MO :
drop_begin(It->implicit_operands()))
1841 addCalleeSaveRegistersAsImpOperand(DeallocCall, CSI,
true,
false);
1845 for (
const CalleeSavedInfo &
I : CSI) {
1846 MCRegister
Reg =
I.getReg();
1848 int FI =
I.getFrameIdx();
1859 unsigned Opc =
MI.getOpcode();
1861 assert((
Opc == Hexagon::ADJCALLSTACKDOWN ||
Opc == Hexagon::ADJCALLSTACKUP) &&
1862 "Cannot handle this call frame pseudo instruction");
1863 return MBB.erase(
I);
1866void HexagonFrameLowering::computeVTCMStackOffsets(
MachineFunction &MF)
const {
1869 const auto &HRI = *HST.getRegisterInfo();
1872 const int64_t HlxLRSize = HRI.getSpillSize(Hexagon::HlxLRRegClass);
1873 const int64_t HlxLLRSize = HRI.getSpillSize(Hexagon::HlxLLRRegClass);
1880 HMFI.moveToVTCMStack(
I, VTCMFrameInfo.CreateFixedObject(
1901 IsHlxSpill ? VTCMFrameInfo.CreateSpillStackObject(
Size, Alignment)
1902 : VTCMFrameInfo.CreateStackObject(
1905 VTCMFrameInfo.setObjectOffset(VTCMIndex, -
Offset);
1906 HMFI.moveToVTCMStack(
I, VTCMIndex);
1912 VTCMFrameInfo.setStackSize(StackSize);
1916 uint64_t Limit =
F.getFnAttributeAsParsedInteger(
1917 "hlx-vector-stack-limit",
1918 MF.
getSubtarget<HexagonSubtarget>().getCLOpts().hlx_vector_stack_limit);
1919 if (StackSize > Limit)
1920 F.getContext().diagnose(DiagnosticInfoResourceLimit(
1921 F,
"HLX vector stack size", StackSize, Limit,
DS_Error));
1927 if (!HST.hasV85OpsOnly() || !HST.useHLXOps())
1929 computeVTCMStackOffsets(MF);
1931 if (HST.getCLOpts().save_parent_vsp && HMFI.getVTCMFrameInfo().getStackSize())
1939 if (!HST.hasV85OpsOnly() || !HST.useHLXOps())
1949 Align MaxAlign = std::max(HMFI.getOutgoingArgAlign(),
1967 if (
MRI.isPhysRegUsed(*AI))
1997 BitVector SRegs(Hexagon::NUM_TARGET_REGS);
2024 "AP must be assigned before register allocation");
2029 bool HasResSub =
false;
2056 BitVector TmpSup(Hexagon::NUM_TARGET_REGS);
2059 if (Hexagon::HlxLRRegClass.
contains(R))
2064 for (
int x = TmpSup.find_first(); x >= 0; x = TmpSup.find_next(x)) {
2102 int64_t MinOffset = 0;
2104 for (
const SpillSlot *S = FixedSlots; S != FixedSlots+NumFixed; ++S) {
2109 MinOffset = std::min(MinOffset, S->Offset);
2111 SRegs[S->Reg] =
false;
2120 unsigned Size =
TRI->getSpillSize(*RC);
2122 if (Hexagon::HlxLRRegClass.
contains(R)) {
2128 int64_t
Off = MinOffset -
Size;
2130 Off &= -Alignment.value();
2132 MinOffset = std::min(MinOffset,
Off);
2138 dbgs() <<
"CS information: {";
2140 int FI =
I.getFrameIdx();
2152 bool MissedReg =
false;
2172 if (!Hexagon::ModRegsRegClass.
contains(DstR) ||
2173 !Hexagon::ModRegsRegClass.
contains(SrcR))
2176 Register TmpR =
MRI.createVirtualRegister(&Hexagon::IntRegsRegClass);
2177 BuildMI(
B, It,
DL, HII.get(TargetOpcode::COPY), TmpR).
add(
MI->getOperand(1));
2178 BuildMI(
B, It,
DL, HII.get(TargetOpcode::COPY), DstR)
2190 if (!
MI->getOperand(0).isFI())
2194 unsigned Opc =
MI->getOpcode();
2196 bool IsKill =
MI->getOperand(2).isKill();
2197 int FI =
MI->getOperand(0).getIndex();
2201 Register TmpR =
MRI.createVirtualRegister(&Hexagon::IntRegsRegClass);
2202 unsigned TfrOpc = (
Opc == Hexagon::STriw_pred) ? Hexagon::C2_tfrpr
2208 BuildMI(
B, It,
DL, HII.get(Hexagon::S2_storeri_io))
2219bool HexagonFrameLowering::expandStoreCirc(
2221 MachineRegisterInfo &
MRI,
const HexagonInstrInfo &HII,
2222 SmallVectorImpl<Register> &NewRegs)
const {
2224 const auto &HRI = *MF.
getSubtarget<HexagonSubtarget>().getRegisterInfo();
2225 MachineInstr *
MI = &*It;
2226 if (!
MI->getOperand(0).isFI())
2231 bool IsKill =
MI->getOperand(1).isKill();
2232 int FI =
MI->getOperand(0).getIndex();
2235 for (
auto SubReg : {Hexagon::isub_lo, Hexagon::isub_hi}) {
2236 Register SrcSubReg = HRI.getSubReg(SrcR, SubReg);
2240 BuildMI(
B, It,
DL, HII.get(Hexagon::A2_tfrcrr), TmpR)
2245 BuildMI(
B, It,
DL, HII.get(Hexagon::S2_storeri_io))
2248 .
addReg(TmpR, RegState::Kill)
2251 Offset += HRI.getSpillSize(Hexagon::IntRegsRegClass);
2258bool HexagonFrameLowering::expandLoadCirc(
2260 MachineRegisterInfo &
MRI,
const HexagonInstrInfo &HII,
2261 SmallVectorImpl<Register> &NewRegs)
const {
2263 const auto &HRI = *MF.
getSubtarget<HexagonSubtarget>().getRegisterInfo();
2264 MachineInstr *
MI = &*It;
2265 if (!
MI->getOperand(1).isFI())
2270 int FI =
MI->getOperand(1).getIndex();
2273 for (
auto SubReg : {Hexagon::isub_lo, Hexagon::isub_hi}) {
2274 Register DstSubReg = HRI.getSubReg(DstR, SubReg);
2278 BuildMI(
B, It,
DL, HII.get(Hexagon::L2_loadri_io), TmpR)
2284 BuildMI(
B, It,
DL, HII.get(Hexagon::A2_tfrrcr), DstSubReg)
2285 .
addReg(TmpR, RegState::Kill)
2289 Offset += HRI.getSpillSize(Hexagon::IntRegsRegClass);
2296bool HexagonFrameLowering::expandLoadInt(
2298 MachineRegisterInfo &
MRI,
const HexagonInstrInfo &HII,
2299 SmallVectorImpl<Register> &NewRegs)
const {
2300 MachineInstr *
MI = &*It;
2301 if (!
MI->getOperand(1).isFI())
2305 unsigned Opc =
MI->getOpcode();
2307 int FI =
MI->getOperand(1).getIndex();
2311 BuildMI(
B, It,
DL, HII.get(Hexagon::L2_loadri_io), TmpR)
2318 unsigned TfrOpc = (
Opc == Hexagon::LDriw_pred) ? Hexagon::C2_tfrrp
2319 : Hexagon::A2_tfrrcr;
2321 .
addReg(TmpR, RegState::Kill);
2328bool HexagonFrameLowering::expandStoreVecPred(MachineBasicBlock &
B,
2330 const HexagonInstrInfo &HII, SmallVectorImpl<Register> &NewRegs)
const {
2331 MachineInstr *
MI = &*It;
2332 if (!
MI->getOperand(0).isFI())
2337 bool IsKill =
MI->getOperand(2).isKill();
2338 int FI =
MI->getOperand(0).getIndex();
2339 auto *RC = &Hexagon::HvxVRRegClass;
2348 BuildMI(
B, It,
DL, HII.get(Hexagon::A2_tfrsi), TmpR0)
2351 BuildMI(
B, It,
DL, HII.get(Hexagon::V6_vandqrt), TmpR1)
2353 .
addReg(TmpR0, RegState::Kill);
2356 expandStoreVec(
B, std::prev(It),
MRI, HII, NewRegs);
2364bool HexagonFrameLowering::expandLoadVecPred(MachineBasicBlock &
B,
2366 const HexagonInstrInfo &HII, SmallVectorImpl<Register> &NewRegs)
const {
2367 MachineInstr *
MI = &*It;
2368 if (!
MI->getOperand(1).isFI())
2373 int FI =
MI->getOperand(1).getIndex();
2374 auto *RC = &Hexagon::HvxVRRegClass;
2382 BuildMI(
B, It,
DL, HII.get(Hexagon::A2_tfrsi), TmpR0)
2385 expandLoadVec(
B, std::prev(It),
MRI, HII, NewRegs);
2387 BuildMI(
B, It,
DL, HII.get(Hexagon::V6_vandvrt), DstR)
2388 .
addReg(TmpR1, RegState::Kill)
2389 .
addReg(TmpR0, RegState::Kill);
2397bool HexagonFrameLowering::expandStoreVec2(MachineBasicBlock &
B,
2399 MachineRegisterInfo &
MRI,
2400 const HexagonInstrInfo &HII,
2401 SmallVectorImpl<Register> &NewRegs,
2405 auto &HRI = *MF.
getSubtarget<HexagonSubtarget>().getRegisterInfo();
2406 MachineInstr *
MI = &*It;
2407 if (!
MI->getOperand(0).isFI())
2414 LivePhysRegs LPR(HRI);
2417 for (
auto R =
B.begin(); R != It; ++R) {
2419 LPR.stepForward(*R, Clobbers);
2424 Register SrcLo = HRI.getSubReg(SrcR, Hexagon::vsub_lo);
2425 Register SrcHi = HRI.getSubReg(SrcR, Hexagon::vsub_hi);
2426 bool IsKill =
MI->getOperand(2).isKill();
2427 int FI =
MI->getOperand(0).getIndex();
2430 const MachineOperand &SrcOp =
MI->getOperand(2);
2431 unsigned Size = HRI.getSpillSize(Hexagon::HlxLRRegClass);
2432 assert(
MI->hasOneMemOperand() &&
"HLX pair spill must have one MMO");
2433 const MachineMemOperand *PairMMO = *
MI->memoperands_begin();
2437 if (LPR.contains(SrcLo)) {
2438 BuildMI(
B, It,
DL, HII.get(Hexagon::LX_S16b_pseudo))
2441 .
addReg(Hexagon::VSP, RegState::Implicit)
2445 if (LPR.contains(SrcHi)) {
2447 BuildMI(
B, It,
DL, HII.get(Hexagon::A2_addi), StackReg)
2450 BuildMI(
B, It,
DL, HII.get(Hexagon::LX_S16b_pseudo))
2451 .
addReg(StackReg, RegState::Kill)
2453 .
addReg(Hexagon::VSP, RegState::Implicit)
2461 unsigned Size = HRI.getSpillSize(Hexagon::HvxVRRegClass);
2462 Align NeedAlign = HRI.getSpillAlign(Hexagon::HvxVRRegClass);
2467 if (LPR.contains(SrcLo)) {
2468 StoreOpc = NeedAlign <= HasAlign ? Hexagon::V6_vS32b_ai
2469 : Hexagon::V6_vS32Ub_ai;
2478 if (LPR.contains(SrcHi)) {
2479 StoreOpc = NeedAlign <= HasAlign ? Hexagon::V6_vS32b_ai
2480 : Hexagon::V6_vS32Ub_ai;
2492bool HexagonFrameLowering::expandLoadVec2(MachineBasicBlock &
B,
2494 MachineRegisterInfo &
MRI,
2495 const HexagonInstrInfo &HII,
2496 SmallVectorImpl<Register> &NewRegs,
2500 auto &HRI = *MF.
getSubtarget<HexagonSubtarget>().getRegisterInfo();
2501 MachineInstr *
MI = &*It;
2502 if (!
MI->getOperand(1).isFI())
2507 Register DstHi = HRI.getSubReg(DstR, Hexagon::vsub_hi);
2508 Register DstLo = HRI.getSubReg(DstR, Hexagon::vsub_lo);
2509 int FI =
MI->getOperand(1).getIndex();
2512 const MachineOperand &DstOp =
MI->getOperand(0);
2513 unsigned Size = HRI.getSpillSize(Hexagon::HlxLRRegClass);
2514 assert(
MI->hasOneMemOperand() &&
"HLX pair reload must have one MMO");
2515 const MachineMemOperand *PairMMO = *
MI->memoperands_begin();
2519 BuildMI(
B, It,
DL, HII.get(Hexagon::LX_L16b_pseudo))
2522 .
addReg(Hexagon::VSP, RegState::Implicit)
2526 BuildMI(
B, It,
DL, HII.get(Hexagon::A2_addi), StackReg)
2529 BuildMI(
B, It,
DL, HII.get(Hexagon::LX_L16b_pseudo))
2531 .
addReg(StackReg, RegState::Kill)
2532 .
addReg(Hexagon::VSP, RegState::Implicit)
2539 unsigned Size = HRI.getSpillSize(Hexagon::HvxVRRegClass);
2540 Align NeedAlign = HRI.getSpillAlign(Hexagon::HvxVRRegClass);
2545 LoadOpc = NeedAlign <= HasAlign ? Hexagon::V6_vL32b_ai
2546 : Hexagon::V6_vL32Ub_ai;
2553 LoadOpc = NeedAlign <= HasAlign ? Hexagon::V6_vL32b_ai
2554 : Hexagon::V6_vL32Ub_ai;
2564bool HexagonFrameLowering::expandStoreVec(MachineBasicBlock &
B,
2566 const HexagonInstrInfo &HII, SmallVectorImpl<Register> &NewRegs)
const {
2569 MachineInstr *
MI = &*It;
2570 if (!
MI->getOperand(0).isFI())
2573 auto &HRI = *MF.
getSubtarget<HexagonSubtarget>().getRegisterInfo();
2576 bool IsKill =
MI->getOperand(2).isKill();
2577 int FI =
MI->getOperand(0).getIndex();
2579 Align NeedAlign = HRI.getSpillAlign(Hexagon::HvxVRRegClass);
2581 unsigned StoreOpc = NeedAlign <= HasAlign ? Hexagon::V6_vS32b_ai
2582 : Hexagon::V6_vS32Ub_ai;
2593bool HexagonFrameLowering::expandLoadVec(MachineBasicBlock &
B,
2595 const HexagonInstrInfo &HII, SmallVectorImpl<Register> &NewRegs)
const {
2598 MachineInstr *
MI = &*It;
2599 if (!
MI->getOperand(1).isFI())
2602 auto &HRI = *MF.
getSubtarget<HexagonSubtarget>().getRegisterInfo();
2605 int FI =
MI->getOperand(1).getIndex();
2607 Align NeedAlign = HRI.getSpillAlign(Hexagon::HvxVRRegClass);
2609 unsigned LoadOpc = NeedAlign <= HasAlign ? Hexagon::V6_vL32b_ai
2610 : Hexagon::V6_vL32Ub_ai;
2621 SmallVectorImpl<Register> &NewRegs)
const {
2622 auto &HII = *MF.
getSubtarget<HexagonSubtarget>().getInstrInfo();
2626 for (
auto &
B : MF) {
2629 for (
auto I =
B.begin(),
E =
B.end();
I !=
E;
I = NextI) {
2630 MachineInstr *
MI = &*
I;
2631 NextI = std::next(
I);
2632 unsigned Opc =
MI->getOpcode();
2635 case TargetOpcode::COPY:
2638 case Hexagon::STriw_pred:
2639 case Hexagon::STriw_ctr:
2642 case Hexagon::STriw_circ:
2645 case Hexagon::LDriw_pred:
2646 case Hexagon::LDriw_ctr:
2649 case Hexagon::LDriw_circ:
2652 case Hexagon::PS_vstorerq_ai:
2653 Changed |= expandStoreVecPred(
B,
I,
MRI, HII, NewRegs);
2655 case Hexagon::PS_vloadrq_ai:
2658 case Hexagon::PS_vloadrw_ai:
2661 case Hexagon::PS_vstorerw_ai:
2664 case Hexagon::PS_loadrll:
2665 Changed |= expandLoadVec2(
B,
I,
MRI, HII, NewRegs,
true);
2667 case Hexagon::PS_storerll:
2668 Changed |= expandStoreVec2(
B,
I,
MRI, HII, NewRegs,
true);
2683 SavedRegs.
resize(HRI.getNumRegs());
2688 for (
const MCPhysReg *R = HRI.getCalleeSavedRegs(&MF); *R; ++R)
2697 assert(AP.
isValid() &&
"AP must be assigned before register allocation");
2703 expandSpillMacros(MF, NewRegs);
2705 optimizeSpillSlots(MF, NewRegs);
2709 if (!NewRegs.
empty() || mayOverflowFrameOffset(MF)) {
2715 SpillRCs.
insert(&Hexagon::IntRegsRegClass);
2720 for (
const auto *RC : SpillRCs) {
2724 switch (RC->
getID()) {
2725 case Hexagon::IntRegsRegClassID:
2726 Num = CLOpts.number_scavenger_slots;
2728 case Hexagon::HvxQRRegClassID:
2732 unsigned S = HRI.getSpillSize(*RC);
2733 Align A = HRI.getSpillAlign(*RC);
2734 for (
unsigned i = 0; i < Num; i++) {
2736 RS->addScavengingFrameIndex(NewFI);
2753 auto F = DeadMap.find({Reg,0});
2754 if (
F == DeadMap.end())
2756 for (
auto &DR :
F->second)
2757 if (DR.contains(FIR))
2762 for (
Register Reg : HRI.getRawAllocationOrder(*RC, MF)) {
2777 SmallVectorImpl<Register> &VRegs)
const {
2779 auto &HII = *HST.getInstrInfo();
2782 HexagonBlockRanges HBR(MF);
2784 using BlockIndexMap =
2785 std::map<MachineBasicBlock *, HexagonBlockRanges::InstrIndexMap>;
2786 using BlockRangeMap =
2787 std::map<MachineBasicBlock *, HexagonBlockRanges::RangeList>;
2788 using IndexType = HexagonBlockRanges::IndexType;
2795 SlotInfo() =
default;
2798 BlockIndexMap BlockIndexes;
2799 SmallSet<int,4> BadFIs;
2800 std::map<int,SlotInfo> FIRangeMap;
2809 if (HaveRC ==
nullptr || HaveRC == NewRC)
2814 if (NewRC->hasSubClassEq(HaveRC))
2821 for (
auto &
B : MF) {
2822 std::map<int,IndexType> LastStore, LastLoad;
2823 auto P = BlockIndexes.emplace(&
B, HexagonBlockRanges::InstrIndexMap(
B));
2824 auto &IndexMap =
P.first->second;
2826 << IndexMap <<
'\n');
2828 for (
auto &In :
B) {
2832 if (
In.isDebugInstr())
2835 bool Load = HII.isLoadFromStackSlot(In, LFI) && !HII.isPredicated(In);
2836 bool Store = HII.isStoreToStackSlot(In, SFI) && !HII.isPredicated(In);
2850 int TFI =
Load ? LFI : SFI;
2851 unsigned AM = HII.getAddrMode(In);
2852 SlotInfo &
SI = FIRangeMap[TFI];
2856 unsigned OpNum =
Load ? 0 : 2;
2857 auto *RC = HII.getRegClass(
In.getDesc(), OpNum);
2858 RC = getCommonRC(
SI.RC, RC);
2866 unsigned S = HII.getMemAccessSize(In);
2867 if (
SI.Size != 0 &&
SI.Size != S)
2873 for (
auto *Mo :
In.memoperands()) {
2874 if (!Mo->isVolatile() && !Mo->isAtomic())
2885 for (
unsigned i = 0, n =
In.getNumOperands(); i < n; ++i) {
2886 const MachineOperand &
Op =
In.getOperand(i);
2889 int FI =
Op.getIndex();
2892 if (i+1 >= n || !
In.getOperand(i+1).isImm() ||
2893 In.getOperand(i+1).getImm() != 0)
2895 if (BadFIs.
count(FI))
2899 auto &
LS = LastStore[FI];
2900 auto &LL = LastLoad[FI];
2902 if (LS == IndexType::None)
2903 LS = IndexType::Entry;
2906 HexagonBlockRanges::RangeList &RL = FIRangeMap[FI].Map[&
B];
2907 if (LS != IndexType::None)
2908 RL.
add(LS, LL,
false,
false);
2909 else if (LL != IndexType::None)
2910 RL.
add(IndexType::Entry, LL,
false,
false);
2911 LL = IndexType::None;
2919 for (
auto &
I : LastLoad) {
2920 IndexType LL =
I.second;
2921 if (LL == IndexType::None)
2923 auto &RL = FIRangeMap[
I.first].Map[&
B];
2924 IndexType &
LS = LastStore[
I.first];
2925 if (LS != IndexType::None)
2926 RL.
add(LS, LL,
false,
false);
2928 RL.
add(IndexType::Entry, LL,
false,
false);
2929 LS = IndexType::None;
2931 for (
auto &
I : LastStore) {
2932 IndexType
LS =
I.second;
2933 if (LS == IndexType::None)
2935 auto &RL = FIRangeMap[
I.first].Map[&
B];
2936 RL.
add(LS, IndexType::None,
false,
false);
2941 for (
auto &
P : FIRangeMap) {
2942 dbgs() <<
"fi#" <<
P.first;
2943 if (BadFIs.
count(
P.first))
2946 if (
P.second.RC !=
nullptr)
2947 dbgs() << HRI.getRegClassName(
P.second.RC) <<
'\n';
2949 dbgs() <<
"<null>\n";
2950 for (
auto &R :
P.second.Map)
2959 SmallSet<int,4> LoxFIs;
2961 std::map<MachineBasicBlock*,std::vector<int>> BlockFIMap;
2963 for (
auto &
P : FIRangeMap) {
2965 if (BadFIs.
count(
P.first))
2967 for (
auto &
B : MF) {
2968 auto F =
P.second.Map.find(&
B);
2970 if (
F ==
P.second.Map.end() ||
F->second.empty())
2972 HexagonBlockRanges::IndexRange &
IR =
F->second.front();
2973 if (
IR.start() == IndexType::Entry)
2974 LoxFIs.insert(
P.first);
2975 BlockFIMap[&
B].push_back(
P.first);
2980 dbgs() <<
"Block-to-FI map (* -- live-on-exit):\n";
2981 for (
auto &
P : BlockFIMap) {
2982 auto &FIs =
P.second;
2986 for (
auto I : FIs) {
2987 dbgs() <<
" fi#" <<
I;
2988 if (LoxFIs.count(
I))
2996 bool HasOptLimit = HST.getCLOpts().spill_opt_max.has_value();
3000 for (
auto &
B : MF) {
3001 auto F = BlockIndexes.find(&
B);
3002 assert(
F != BlockIndexes.end());
3003 HexagonBlockRanges::InstrIndexMap &IM =
F->second;
3007 << HexagonBlockRanges::PrintRangeMap(
DM, HRI));
3009 for (
auto FI : BlockFIMap[&
B]) {
3010 if (BadFIs.
count(FI))
3013 HexagonBlockRanges::RangeList &RL = FIRangeMap[FI].Map[&
B];
3014 for (
auto &
Range : RL) {
3016 if (!IndexType::isInstr(
Range.start()) ||
3017 !IndexType::isInstr(
Range.end()))
3021 assert(
SI.mayStore() &&
"Unexpected start instruction");
3023 MachineOperand &SrcOp =
SI.getOperand(2);
3025 HexagonBlockRanges::RegisterRef SrcRR = { SrcOp.
getReg(),
3027 auto *RC = HII.getRegClass(
SI.getDesc(), 2);
3044 MachineInstr *CopyIn =
nullptr;
3045 if (SrcRR.
Reg != FoundR || SrcRR.
Sub != 0) {
3047 CopyIn =
BuildMI(
B, StartIt,
DL, HII.get(TargetOpcode::COPY), FoundR)
3053 if (LoxFIs.count(FI) && (&
Range == &RL.back())) {
3056 SrcOp.
setReg(HRI.getSubReg(FoundR, SR));
3068 for (
auto It = StartIt; It != EndIt; It = NextIt) {
3069 MachineInstr &
MI = *It;
3070 NextIt = std::next(It);
3072 if (!HII.isLoadFromStackSlot(
MI, TFI) || TFI != FI)
3075 assert(
MI.getOperand(0).getSubReg() == 0);
3076 MachineInstr *CopyOut =
nullptr;
3077 if (DstR != FoundR) {
3079 unsigned MemSize = HII.getMemAccessSize(
MI);
3081 unsigned CopyOpc = TargetOpcode::COPY;
3082 if (HII.isSignExtendingLoad(
MI))
3083 CopyOpc = (MemSize == 1) ? Hexagon::A2_sxtb : Hexagon::A2_sxth;
3084 else if (HII.isZeroExtendingLoad(
MI))
3085 CopyOpc = (MemSize == 1) ? Hexagon::A2_zxtb : Hexagon::A2_zxth;
3086 CopyOut =
BuildMI(
B, It,
DL, HII.get(CopyOpc), DstR)
3094 HexagonBlockRanges::RegisterRef FoundRR = { FoundR, 0 };
3102void HexagonFrameLowering::expandAlloca(MachineInstr *AI,
MachineFunction &MF,
3103 const HexagonInstrInfo &HII,
3105 MachineBasicBlock &MB = *AI->
getParent();
3114 auto *
TLI = HST.getTargetLowering();
3117 if (!NeedsProbing) {
3141 BuildMI(MB, AI,
DL, HII.get(Hexagon::A2_andir), Rd)
3145 BuildMI(MB, AI,
DL, HII.get(Hexagon::A2_andir), SP)
3183 unsigned ProbeSize =
TLI->getStackProbeSize(MF, StackAlign);
3188 BuildMI(MB, AI,
DL, HII.get(Hexagon::A2_sub), Rd)
3194 BuildMI(MB, AI,
DL, HII.get(Hexagon::A2_andir), Rd)
3216 BuildMI(*LoopMBB, LoopMBB->
end(),
DL, HII.get(Hexagon::A2_addi), Hexagon::R29)
3221 BuildMI(*LoopMBB, LoopMBB->
end(),
DL, HII.get(Hexagon::S4_storeiri_io))
3227 BuildMI(*LoopMBB, LoopMBB->
end(),
DL, HII.get(Hexagon::C2_cmpgtu),
3233 BuildMI(*LoopMBB, LoopMBB->
end(),
DL, HII.get(Hexagon::J2_jumpt))
3242 BuildMI(*ExitMBB, ExitIt,
DL, HII.get(Hexagon::A2_tfr), Hexagon::R29)
3246 BuildMI(*ExitMBB, ExitIt,
DL, HII.get(Hexagon::A2_addi), Rd)
3274void HexagonFrameLowering::addCalleeSaveRegistersAsImpOperand(
MachineInstr *
MI,
3275 const CSIVect &CSI,
bool IsDef,
bool IsKill)
const {
3286 const CSIVect &CSI)
const {
3299 BitVector Regs(Hexagon::NUM_TARGET_REGS);
3302 if (!Hexagon::DoubleRegsRegClass.
contains(R))
3306 int F = Regs.find_first();
3307 if (
F != Hexagon::D8)
3310 int N = Regs.find_next(
F);
3311 if (
N >= 0 &&
N !=
F+1)
3320 const CSIVect &CSI)
const {
3321 if (shouldInlineCSR(MF, CSI))
3323 unsigned NumCSI = CSI.size();
3342 if (HST.getSCSPReg().id() <= MaxReg.id())
3347 unsigned Threshold =
isOptSize(MF) ? CLOpts.spill_func_threshold_os
3348 : CLOpts.spill_func_threshold;
3349 return Threshold < NumCSI;
3352bool HexagonFrameLowering::useRestoreFunction(
const MachineFunction &MF,
3353 const CSIVect &CSI)
const {
3354 if (shouldInlineCSR(MF, CSI))
3367 unsigned NumCSI = CSI.size();
3372 unsigned Threshold =
isOptSize(MF) ? CLOpts.spill_func_threshold_os - 1
3373 : CLOpts.spill_func_threshold;
3374 return Threshold < NumCSI;
3377bool HexagonFrameLowering::mayOverflowFrameOffset(
MachineFunction &MF)
const {
3382 if (HST.useHVXOps() && StackSize > 256)
3389 bool HasImmStack =
false;
3390 unsigned MinLS = ~0
u;
3392 for (
const MachineBasicBlock &
B : MF) {
3393 for (
const MachineInstr &
MI :
B) {
3395 switch (
MI.getOpcode()) {
3396 case Hexagon::S4_storeirit_io:
3397 case Hexagon::S4_storeirif_io:
3398 case Hexagon::S4_storeiri_io:
3401 case Hexagon::S4_storeirht_io:
3402 case Hexagon::S4_storeirhf_io:
3403 case Hexagon::S4_storeirh_io:
3406 case Hexagon::S4_storeirbt_io:
3407 case Hexagon::S4_storeirbf_io:
3408 case Hexagon::S4_storeirb_io:
3409 if (
MI.getOperand(0).isFI())
3411 MinLS = std::min(MinLS, LS);
3425struct HexagonFrameSortingObject {
3426 bool IsValid =
false;
3432struct HexagonFrameSortingComparator {
3433 inline bool operator()(
const HexagonFrameSortingObject &
A,
3434 const HexagonFrameSortingObject &
B)
const {
3435 return std::make_tuple(!
A.IsValid,
A.ObjectAlignment,
A.Size) <
3436 std::make_tuple(!
B.IsValid,
B.ObjectAlignment,
B.Size);
3446 if (ObjectsToAllocate.
empty())
3450 int NObjects = ObjectsToAllocate.
size();
3458 if (i != ObjectsToAllocate[j])
3469 SortingObjects[i].IsValid =
true;
3470 SortingObjects[i].Index = i;
3480 for (
auto &Obj : SortingObjects) {
3483 ObjectsToAllocate[--i] = Obj.Index;
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const AArch64InstrInfo MachineBasicBlock::iterator InsertPt
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
This file contains the simple types necessary to represent the attributes associated with functions a...
This file implements the BitVector class.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static RegisterPass< DebugifyModulePass > DM("debugify", "Attach debug info to everything")
This file defines the DenseMap class.
This file contains constants used for implementing Dwarf debug support.
static MachineInstr * getReturn(MachineBasicBlock &MBB)
Returns the "return" instruction from this block, or nullptr if there isn't any.
static bool isOptNone(const MachineFunction &MF)
static std::optional< MachineBasicBlock::iterator > findCFILocation(MachineBasicBlock &B)
static bool enableAllocFrameElim(const MachineFunction &MF)
static const char * getSpillFunctionFor(Register MaxReg, SpillKind SpillType, bool Stkchk=false)
static bool hasReturn(const MachineBasicBlock &MBB)
Returns true if MBB contains an instruction that returns.
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)
static Register getMax32BitSubRegister(Register Reg, const TargetRegisterInfo &TRI, bool hireg=true)
Map a register pair Reg to the subregister that has the greater "number", i.e.
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.
static bool hasTailCall(const MachineBasicBlock &MBB)
Returns true if MBB has a machine instructions that indicates a tail call in the block.
static Register getMaxCalleeSavedReg(ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo &TRI)
Returns the callee saved register with the largest id in the vector.
static bool isMinSize(const MachineFunction &MF)
static bool containsHLXObject(const llvm::HexagonSubtarget &HST, llvm::Type *Ty)
static unsigned SpillOptCount
static void dump_registers(BitVector &Regs, const TargetRegisterInfo &TRI)
static void emitSCSPrologue(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const DebugLoc &DL)
static bool isRestoreCall(unsigned Opc)
static void emitSCSEpilogue(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const DebugLoc &DL)
Legalize the Machine IR a function s Machine IR
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
Register const TargetRegisterInfo * TRI
Promote Memory to Register
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
MachineRegisterInfo & MRI
This file declares the machine register scavenger class.
bool isDead(const MachineInstr &MI, const MachineRegisterInfo &MRI)
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallSet class.
This file defines the SmallVector class.
an instruction to allocate memory on the stack
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
bool empty() const
Check if the array is empty.
int find_first() const
Returns the index of the first set bit, -1 if none of the bits are set.
void resize(unsigned N, bool t=false)
Grow or shrink the bitvector.
BitVector & set()
Set all bits in the bitvector.
int find_next(unsigned Prev) const
Returns the index of the next set bit following the "Prev" bit.
Helper class for creating CFI instructions and inserting them into MIR.
void buildEscape(StringRef Bytes, StringRef Comment="") const
void buildRestore(MCRegister Reg) const
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
NodeT * findNearestCommonDominator(NodeT *A, NodeT *B) const
Find nearest common dominator basic block for basic block A and B.
bool dominates(const DomTreeNodeBase< NodeT > *A, const DomTreeNodeBase< NodeT > *B) const
dominates - Returns true iff A dominates B.
void recalculate(ParentType &Func)
recalculate - compute a dominator tree for the given function
FunctionPass class - This class is used to implement most global optimizations.
MaybeAlign getFnStackAlign() const
Return the stack alignment for the function.
bool hasMinSize() const
Optimize this function for minimum size (-Oz).
bool hasOptNone() const
Do not optimize this function (-O0).
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
void replaceInstr(MachineInstr *OldMI, MachineInstr *NewMI)
IndexType getIndex(MachineInstr *MI) const
MachineInstr * getInstr(IndexType Idx) const
void add(IndexType Start, IndexType End, bool Fixed, bool TiedEnd)
void insertCFIInstructions(MachineFunction &MF) const
bool hasFPImpl(const MachineFunction &MF) const override
bool enableCalleeSaveSkip(const MachineFunction &MF) const override
Returns true if the target can safely skip saving callee-saved registers for noreturn nounwind functi...
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...
StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const override
getFrameIndexReference - This method should return the base register and offset used to reference a f...
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
Perform most of the PEI work here:
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
void orderFrameObjects(const MachineFunction &MF, SmallVectorImpl< int > &ObjectsToAllocate) const override
Order the symbols in the local stack frame.
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS=nullptr) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
void inlineStackProbe(MachineFunction &MF, MachineBasicBlock &PrologueMBB) const override
Replace a StackProbe stub (if any) with the actual probe code inline.
const SpillSlot * getCalleeSavedSpillSlots(unsigned &NumEntries) const override
getCalleeSavedSpillSlots - This method returns a pointer to an array of pairs, that contains an entry...
bool needsAligna(const MachineFunction &MF) const
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const override
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, Register VReg, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
Store the specified register of the given register class to the specified stack frame index.
const HexagonRegisterInfo & getRegisterInfo() const
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register DestReg, int FrameIndex, const TargetRegisterClass *RC, Register VReg, unsigned SubReg=0, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
Load the specified register of the given register class from the specified stack frame index.
Hexagon target-specific information for each MachineFunction.
void setVSPFrameIndex(int FI)
Register getStackAlignBaseReg() const
bool isEHReturnCalleeSaveReg(Register Reg) const
const MCPhysReg * getCallerSavedRegs(const MachineFunction *MF, const TargetRegisterClass *RC) const
bool isTypeForHLX(Type *VecTy) const
const HexagonInstrInfo * getInstrInfo() const override
const HexagonFrameLowering * getFrameLowering() const override
const HexagonRegisterInfo * getRegisterInfo() const override
bool isEnvironmentMusl() const
const HexagonOptions & getCLOpts() const
static MCCFIInstruction cfiDefCfa(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa defines a rule for computing CFA as: take address from Register and add Offset to it.
static MCCFIInstruction createOffset(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_offset Previous value of Register is saved at offset Offset from CFA.
static MCCFIInstruction createEscape(MCSymbol *L, StringRef Vals, SMLoc Loc={}, StringRef Comment="")
.cfi_escape Allows the user to add arbitrary bytes to the unwind info.
static MCCFIInstruction createSameValue(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_same_value Current value of Register is the same as in the previous frame.
LLVM_ABI MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Describe properties that are true of each instruction in the target description file.
MCRegAliasIterator enumerates all registers aliasing Reg.
unsigned getID() const
getID() - Return the register class ID number.
bool hasSubClassEq(const MCRegisterClass *RC) const
Returns true if RC is a sub-class of or equal to this class.
Wrapper class representing physical registers and target specific virtual registers.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
LLVM_ABI void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
MachineInstrBundleIterator< const MachineInstr > const_iterator
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
LLVM_ABI iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
LLVM_ABI void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
LLVM_ABI DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any debug instructions.
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
LLVM_ABI instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
iterator_range< succ_iterator > successors()
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineInstrBundleIterator< MachineInstr > iterator
LLVM_ABI bool isLiveIn(MCRegister Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
bool dominates(const MachineInstr *A, const MachineInstr *B) const
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
void setMaxCallFrameSize(uint64_t S)
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
bool isObjectPreAllocated(int ObjectIdx) const
Return true if the object was pre-allocated into the local block.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
const AllocaInst * getObjectAllocation(int ObjectIdx) const
Return the underlying Alloca of the specified stack object if it exists.
bool hasCalls() const
Return true if the current function has any function calls.
Align getMaxAlign() const
Return alignment of this function's frame.
uint64_t getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call.
LLVM_ABI uint64_t estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
bool isSpillSlotObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a spill slot.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
LLVM_ABI int CreateSpillStackObject(uint64_t Size, Align Alignment, TargetStackID::Value StackID=TargetStackID::Default)
Create a new statically sized stack object that represents a spill slot, returning a nonnegative iden...
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
void RemoveStackObject(int ObjectIdx)
Remove or mark dead a statically sized stack object.
bool isVariableSizedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a variable sized object.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
LLVM_ABI int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset, bool IsImmutable=false)
Create a spill slot at a fixed location on the stack.
uint8_t getStackID(int ObjectIdx) const
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
void setStackSize(uint64_t Size)
Set the size of the stack.
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
int getObjectIndexBegin() const
Return the minimum frame object index.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Properties which a MachineFunction may have at a given point in time.
unsigned addFrameInst(const MCCFIInstruction &Inst)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
bool needsFrameMoves() const
True if this function needs frame moves for debug or exceptions.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MCContext & getContext() const
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
MachineBasicBlock * getBlockNumbered(unsigned N) const
getBlockNumbered - MachineBasicBlocks are automatically numbered when they are inserted into the mach...
Function & getFunction()
Return the LLVM function that this machine code represents.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
BasicBlockListType::iterator iterator
bool disableFramePointerElim() const
Returns true if frame pointer elimination should be disabled for this function.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineBasicBlock & front() const
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags F, LLT MemTy, Align BaseAlignment, const MMOMetadata &Metadata=MMOMetadata(), SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineInstr - Allocate a new MachineInstr.
void insert(iterator MBBI, MachineBasicBlock *MBB)
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned TargetFlags=0) const
const MachineInstrBuilder & addCFIIndex(unsigned CFIIndex) const
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addFrameIndex(int Idx) const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & addDef(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register definition operand.
const MachineInstrBuilder & cloneMemRefs(const MachineInstr &OtherMI) const
const MachineInstrBuilder & setMIFlags(unsigned Flags) const
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
instr_iterator getInstrIterator() const
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bool isReturn(QueryType Type=AnyInBundle) const
const MachineBasicBlock * getParent() const
LLVM_ABI void addOperand(MachineFunction &MF, const MachineOperand &Op)
Add the specified operand to the instruction.
mop_range implicit_operands()
LLVM_ABI void copyImplicitOps(MachineFunction &MF, const MachineInstr &MI)
Copy implicit register operands from specified instruction to this instruction.
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
@ MOStore
The memory access writes data.
MachineOperand class - Representation of each machine instruction operand.
void setSubReg(unsigned subReg)
unsigned getSubReg() const
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
void setIsKill(bool Val=true)
Register getReg() const
getReg - Returns the register number.
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)
LLVM_ABI MachineBasicBlock * findNearestCommonDominator(ArrayRef< MachineBasicBlock * > Blocks) const
Returns the nearest common dominator of the given blocks.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
Wrapper class representing virtual and physical registers.
constexpr bool isValid() const
A vector that has set insertion semantics.
size_type size() const
Determine the number of elements in the SetVector.
bool insert(const value_type &X)
Insert a new element into the SetVector.
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
void append(StringRef RHS)
Append from a StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
int64_t getFixed() const
Returns the fixed component of the stack.
Represent a constant reference to a string, i.e.
LLVM_ABI std::string lower() const
bool hasFP(const MachineFunction &MF) const
hasFP - Return true if the specified function should have a dedicated frame pointer register.
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
const TargetRegisterInfo & getRegisterInfo() const
virtual bool hasInlineStackProbe(const MachineFunction &MF) const
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
bool isPositionIndependent() const
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetInstrInfo * getInstrInfo() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const AArch64MCOptions & getCLOpts(const MCTargetOptions &Options)
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
void stable_sort(R &&Range)
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
@ Kill
The last use of a register.
constexpr RegState getKillRegState(bool B)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
@ Load
The value being inserted comes from a load (InsertElement only).
@ Store
The extracted value is stored (ExtractElement only).
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
@ Off
Use window algorithm after SMS algorithm fails.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
FunctionPass * createHexagonCallFrameInformation()
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
RegState getRegState(const MachineOperand &RegOp)
Get all register state flags from machine operand RegOp.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
DWARFExpression::Operation Op
unsigned encodeSLEB128(int64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a SLEB128 value to an output stream.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
MaybeAlign getStackAlign(const Function &F, unsigned Index)
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
@ End
Run the machine verifier once, at the end of the pipeline.
void fullyRecomputeLiveIns(ArrayRef< MachineBasicBlock * > MBBs)
Convenience function for recomputing live-in's for a set of MBBs until the computation converges.
LLVM_ABI 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.
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
MCRegisterClass TargetRegisterClass
This struct is a compact representation of a valid (non-zero power of two) alignment.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
static RegisterSet expandToSubRegs(RegisterRef R, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI)
std::map< RegisterRef, RangeList > RegToRangeMap
static LLVM_ABI MachinePointerInfo getStack(MachineFunction &MF, int64_t Offset, uint8_t ID=0)
Stack pointer relative access.
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.