Lines Matching +full:stm +full:- +full:base
1 //===-- SystemZFrameLowering.cpp - Frame lowering for SystemZ -------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
27 // The ABI-defined register save slots, relative to the CFA (i.e.
66 STI.getTargetLowering()->getTargetMachine().getPointerSize(0); in create()
77 uint32_t D12Count = 0; // 12-bit displacement only.
83 // TODO: Move to base class.
100 // Examine uses for each object and record short (12-bit) and "pair" in orderFrameObjects()
113 if (TII->hasDisplacementPairInsn(MI.getOpcode())) in orderFrameObjects()
158 // we're using a frame pointer. Similarly, 64-bit XPLINK requires 96 bytes in hasReservedCallFrame()
183 Offset -= SystemZMC::ELFCallFrameSize; in assignCalleeSavedSpillSlots()
191 // Save the range of call-saved registers, for use by the in assignCalleeSavedSpillSlots()
193 ZFI->setRestoreGPRRegs(LowGPR, HighGPR, StartSPOffset); in assignCalleeSavedSpillSlots()
195 // Also save the GPR varargs, if any. R6D is call-saved, so would in assignCalleeSavedSpillSlots()
196 // already be included, but we also need to handle the call-clobbered in assignCalleeSavedSpillSlots()
198 Register FirstGPR = ZFI->getVarArgsFirstGPR(); in assignCalleeSavedSpillSlots()
207 ZFI->setSpillGPRRegs(LowGPR, HighGPR, StartSPOffset); in assignCalleeSavedSpillSlots()
210 int CurrOffset = -SystemZMC::ELFCallFrameSize; in assignCalleeSavedSpillSlots()
218 const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(Reg); in assignCalleeSavedSpillSlots()
219 unsigned Size = TRI->getSpillSize(*RC); in assignCalleeSavedSpillSlots()
220 CurrOffset -= Size; in assignCalleeSavedSpillSlots()
222 "8-byte alignment required for for all register save slots"); in assignCalleeSavedSpillSlots()
243 // Record these pending uses, which typically include the call-saved in determineCalleeSaves()
246 for (unsigned I = MFI->getVarArgsFirstGPR(); I < SystemZ::ELFNumArgGPRs; ++I) in determineCalleeSaves()
269 const MCPhysReg *CSRegs = TRI->getCalleeSavedRegs(&MF); in determineCalleeSaves()
304 MBB.getParent()->getSubtarget().getRegisterInfo(); in addSavedGPR()
305 Register GPR32 = RI->getSubReg(GPR64, SystemZ::subreg_l32); in addSavedGPR()
327 SystemZ::GPRRegs SpillGPRs = ZFI->getSpillGPRRegs(); in spillCalleeSavedRegisters()
333 MachineInstrBuilder MIB = BuildMI(MBB, MBBI, DL, TII->get(SystemZ::STMG)); in spillCalleeSavedRegisters()
342 // Make sure all call-saved GPRs are included as operands and are in spillCalleeSavedRegisters()
352 for (unsigned I = ZFI->getVarArgsFirstGPR(); I < SystemZ::ELFNumArgGPRs; ++I) in spillCalleeSavedRegisters()
361 TII->storeRegToStackSlot(MBB, MBBI, Reg, true, I.getFrameIdx(), in spillCalleeSavedRegisters()
366 TII->storeRegToStackSlot(MBB, MBBI, Reg, true, I.getFrameIdx(), in spillCalleeSavedRegisters()
384 DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc(); in restoreCalleeSavedRegisters()
390 TII->loadRegFromStackSlot(MBB, MBBI, Reg, I.getFrameIdx(), in restoreCalleeSavedRegisters()
393 TII->loadRegFromStackSlot(MBB, MBBI, Reg, I.getFrameIdx(), in restoreCalleeSavedRegisters()
397 // Restore call-saved GPRs (but not call-clobbered varargs, which at in restoreCalleeSavedRegisters()
399 SystemZ::GPRRegs RestoreGPRs = ZFI->getRestoreGPRRegs(); in restoreCalleeSavedRegisters()
401 // If we saved any of %r2-%r5 as varargs, we should also be saving in restoreCalleeSavedRegisters()
408 MachineInstrBuilder MIB = BuildMI(MBB, MBBI, DL, TII->get(SystemZ::LMG)); in restoreCalleeSavedRegisters()
457 // are outside the reach of an unsigned 12-bit displacement. in processFunctionBeforeFrameFinalized()
460 RS->addScavengingFrameIndex( in processFunctionBeforeFrameFinalized()
462 RS->addScavengingFrameIndex( in processFunctionBeforeFrameFinalized()
470 ZFI->getRestoreGPRRegs().LowGPR != SystemZ::R6D) in processFunctionBeforeFrameFinalized()
471 for (auto &MO : MRI->use_nodbg_operands(SystemZ::R6D)) in processFunctionBeforeFrameFinalized()
487 // Make sure we maintain 8-byte stack alignment. in emitIncrement()
488 int64_t MinVal = -uint64_t(1) << 31; in emitIncrement()
489 int64_t MaxVal = (int64_t(1) << 31) - 8; in emitIncrement()
495 MachineInstr *MI = BuildMI(MBB, MBBI, DL, TII->get(Opcode), Reg) in emitIncrement()
498 MI->getOperand(3).setIsDead(); in emitIncrement()
499 NumBytes -= ThisVal; in emitIncrement()
508 unsigned CFIIndex = MBB.getParent()->addFrameInst( in buildCFAOffs()
509 MCCFIInstruction::cfiDefCfaOffset(nullptr, -Offset)); in buildCFAOffs()
510 BuildMI(MBB, MBBI, DL, ZII->get(TargetOpcode::CFI_INSTRUCTION)) in buildCFAOffs()
521 unsigned RegNum = MRI->getDwarfRegNum(Reg, true); in buildDefCFAReg()
524 BuildMI(MBB, MBBI, DL, ZII->get(TargetOpcode::CFI_INSTRUCTION)) in buildDefCFAReg()
530 assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported"); in emitPrologue()
541 // In GHC calling convention C stack space, including the ABI-defined in emitPrologue()
542 // 160-byte base area, is (de)allocated by GHC itself. This stack space may in emitPrologue()
563 int64_t SPOffsetFromCFA = -SystemZMC::ELFCFAOffsetFromInitialSP; in emitPrologue()
565 if (ZFI->getSpillGPRRegs().LowGPR) { in emitPrologue()
567 if (MBBI != MBB.end() && MBBI->getOpcode() == SystemZ::STMG) in emitPrologue()
579 nullptr, MRI->getDwarfRegNum(Reg, true), Offset)); in emitPrologue()
580 BuildMI(MBB, MBBI, DL, ZII->get(TargetOpcode::CFI_INSTRUCTION)) in emitPrologue()
587 // We need to allocate the ABI-defined 160-byte base area whenever in emitPrologue()
600 ? StackSize - SystemZMC::ELFCallFrameSize in emitPrologue()
606 int64_t Delta = -int64_t(StackSize); in emitPrologue()
608 bool FreeProbe = (ZFI->getSpillGPRRegs().GPROffset && in emitPrologue()
609 (ZFI->getSpillGPRRegs().GPROffset + StackSize) < ProbeSize); in emitPrologue()
611 MF.getSubtarget().getTargetLowering()->hasInlineStackProbe(MF)) { in emitPrologue()
616 BuildMI(MBB, MBBI, DL, ZII->get(SystemZ::PROBED_STACKALLOC)) in emitPrologue()
624 BuildMI(MBB, MBBI, DL, ZII->get(SystemZ::LGR)) in emitPrologue()
629 BuildMI(MBB, MBBI, DL, ZII->get(SystemZ::STG)) in emitPrologue()
637 // Copy the base of the frame to R11. in emitPrologue()
638 BuildMI(MBB, MBBI, DL, ZII->get(SystemZ::LGR), SystemZ::R11D) in emitPrologue()
657 (MBBI->getOpcode() == SystemZ::STD || in emitPrologue()
658 MBBI->getOpcode() == SystemZ::STDY)) in emitPrologue()
664 MBBI->getOpcode() == SystemZ::VST) in emitPrologue()
672 unsigned DwarfReg = MRI->getDwarfRegNum(Reg, true); in emitPrologue()
685 BuildMI(MBB, MBBI, DL, ZII->get(TargetOpcode::CFI_INSTRUCTION)) in emitPrologue()
703 assert(MBBI->isReturn() && "Can only insert epilogue into returning blocks"); in emitEpilogue()
706 if (ZFI->getRestoreGPRRegs().LowGPR) { in emitEpilogue()
707 --MBBI; in emitEpilogue()
708 unsigned Opcode = MBBI->getOpcode(); in emitEpilogue()
710 llvm_unreachable("Expected to see callee-save register restore code"); in emitEpilogue()
713 DebugLoc DL = MBBI->getDebugLoc(); in emitEpilogue()
714 uint64_t Offset = StackSize + MBBI->getOperand(AddrOpNo + 1).getImm(); in emitEpilogue()
715 unsigned NewOpcode = ZII->getOpcodeForOffset(Opcode, Offset); in emitEpilogue()
717 // If the offset is too large, use the largest stack-aligned offset in emitEpilogue()
718 // and add the rest to the base register (the stack or frame pointer). in emitEpilogue()
720 uint64_t NumBytes = Offset - 0x7fff8; in emitEpilogue()
721 emitIncrement(MBB, MBBI, DL, MBBI->getOperand(AddrOpNo).getReg(), in emitEpilogue()
723 Offset -= NumBytes; in emitEpilogue()
724 NewOpcode = ZII->getOpcodeForOffset(Opcode, Offset); in emitEpilogue()
728 MBBI->setDesc(ZII->get(NewOpcode)); in emitEpilogue()
729 MBBI->getOperand(AddrOpNo + 1).ChangeToImmediate(Offset); in emitEpilogue()
731 DebugLoc DL = MBBI->getDebugLoc(); in emitEpilogue()
751 uint64_t StackSize = StackAllocMI->getOperand(0).getImm(); in inlineStackProbe()
755 int64_t SPOffsetFromCFA = -SystemZMC::ELFCFAOffsetFromInitialSP; in inlineStackProbe()
758 const DebugLoc DL = StackAllocMI->getDebugLoc(); in inlineStackProbe()
763 bool EmitCFI) -> void { in inlineStackProbe()
764 emitIncrement(InsMBB, InsPt, DL, SystemZ::R15D, -int64_t(Size), ZII); in inlineStackProbe()
766 SPOffsetFromCFA -= Size; in inlineStackProbe()
772 BuildMI(InsMBB, InsPt, DL, ZII->get(SystemZ::CG)) in inlineStackProbe()
774 .addReg(SystemZ::R15D).addImm(Size - 8).addReg(0) in inlineStackProbe()
780 BuildMI(*MBB, MBBI, DL, ZII->get(SystemZ::LGR)) in inlineStackProbe()
792 SPOffsetFromCFA -= LoopAlloc; in inlineStackProbe()
795 BuildMI(*MBB, MBBI, DL, ZII->get(SystemZ::LGR), SystemZ::R0D) in inlineStackProbe()
798 emitIncrement(*MBB, MBBI, DL, SystemZ::R0D, -int64_t(LoopAlloc), ZII); in inlineStackProbe()
799 buildCFAOffs(*MBB, MBBI, DL, -int64_t(SystemZMC::ELFCallFrameSize + LoopAlloc), in inlineStackProbe()
804 MBB->addSuccessor(LoopMBB); in inlineStackProbe()
805 LoopMBB->addSuccessor(LoopMBB); in inlineStackProbe()
806 LoopMBB->addSuccessor(DoneMBB); in inlineStackProbe()
809 allocateAndProbe(*MBB, MBB->end(), ProbeSize, false/*EmitCFI*/); in inlineStackProbe()
810 BuildMI(*MBB, MBB->end(), DL, ZII->get(SystemZ::CLGR)) in inlineStackProbe()
812 BuildMI(*MBB, MBB->end(), DL, ZII->get(SystemZ::BRC)) in inlineStackProbe()
816 MBBI = DoneMBB->begin(); in inlineStackProbe()
824 BuildMI(*MBB, MBBI, DL, ZII->get(SystemZ::STG)) in inlineStackProbe()
828 StackAllocMI->eraseFromParent(); in inlineStackProbe()
830 // Compute the live-in lists for the new blocks. in inlineStackProbe()
870 int FI = ZFI->getFramePointerSaveIndex(); in getOrCreateFramePointerSaveIndex()
873 int Offset = getBackchainOffset(MF) - SystemZMC::ELFCallFrameSize; in getOrCreateFramePointerSaveIndex()
875 ZFI->setFramePointerSaveIndex(FI); in getOrCreateFramePointerSaveIndex()
881 bool HasPackedStackAttr = MF.getFunction().hasFnAttribute("packed-stack"); in usePackedStack()
886 report_fatal_error("packed-stack + backchain + hard-float is unsupported."); in usePackedStack()
895 RegSpillOffsets(-1) { in SystemZXPLINKFrameLowering()
907 int FI = ZFI->getFramePointerSaveIndex(); in getOrCreateFramePointerSaveIndex()
912 ZFI->setFramePointerSaveIndex(FI); in getOrCreateFramePointerSaveIndex()
940 if (MRI.isPhysRegModified(Regs->getStackPointerRegister())) in isXPLeafCandidate()
944 if (MRI.isPhysRegModified(Regs->getAddressOfCalleeRegister())) in isXPLeafCandidate()
949 if (MRI.isPhysRegModified(Regs->getReturnFunctionAddressRegister())) in isXPLeafCandidate()
977 // callee-save registers, then it is indeed a leaf function, and we can early in assignCalleeSavedSpillSlots()
979 // TODO: It is possible for leaf functions to use callee-saved registers. in assignCalleeSavedSpillSlots()
980 // It can use the 0-2k range between R4 and the caller's stack frame without in assignCalleeSavedSpillSlots()
986 // For non-leaf functions: in assignCalleeSavedSpillSlots()
987 // - the address of callee (entry point) register R6 must be saved in assignCalleeSavedSpillSlots()
1004 // Scan the call-saved GPRs and find the bounds of the register spill area. in assignCalleeSavedSpillSlots()
1010 int HighOffset = -1; in assignCalleeSavedSpillSlots()
1013 int FPSI = MFI->getFramePointerSaveIndex(); in assignCalleeSavedSpillSlots()
1033 // Non-volatile GPRs are saved in the dedicated register save area at in assignCalleeSavedSpillSlots()
1046 const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(Reg); in assignCalleeSavedSpillSlots()
1047 Align Alignment = TRI->getSpillAlign(*RC); in assignCalleeSavedSpillSlots()
1048 unsigned Size = TRI->getSpillSize(*RC); in assignCalleeSavedSpillSlots()
1055 // Save the range of call-saved registers, for use by the in assignCalleeSavedSpillSlots()
1058 MFI->setRestoreGPRRegs(LowRestoreGPR, HighGPR, LowRestoreOffset); in assignCalleeSavedSpillSlots()
1060 // Save the range of call-saved registers, for use by the epilogue inserter. in assignCalleeSavedSpillSlots()
1062 MFI->setSpillGPRRegs(LowSpillGPR, HighGPR, LowSpillOffset); in assignCalleeSavedSpillSlots()
1093 SystemZ::GPRRegs SpillGPRs = ZFI->getSpillGPRRegs(); in spillCalleeSavedRegisters()
1101 // Build an STM/STMG instruction. in spillCalleeSavedRegisters()
1102 MachineInstrBuilder MIB = BuildMI(MBB, MBBI, DL, TII->get(SystemZ::STMG)); in spillCalleeSavedRegisters()
1115 // Make sure all call-saved GPRs are included as operands and are in spillCalleeSavedRegisters()
1130 TII->storeRegToStackSlot(MBB, MBBI, Reg, true, I.getFrameIdx(), in spillCalleeSavedRegisters()
1135 TII->storeRegToStackSlot(MBB, MBBI, Reg, true, I.getFrameIdx(), in spillCalleeSavedRegisters()
1156 DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc(); in restoreCalleeSavedRegisters()
1162 TII->loadRegFromStackSlot(MBB, MBBI, Reg, I.getFrameIdx(), in restoreCalleeSavedRegisters()
1165 TII->loadRegFromStackSlot(MBB, MBBI, Reg, I.getFrameIdx(), in restoreCalleeSavedRegisters()
1169 // Restore call-saved GPRs (but not call-clobbered varargs, which at in restoreCalleeSavedRegisters()
1171 SystemZ::GPRRegs RestoreGPRs = ZFI->getRestoreGPRRegs(); in restoreCalleeSavedRegisters()
1176 BuildMI(MBB, MBBI, DL, TII->get(SystemZ::LG), RestoreGPRs.LowGPR) in restoreCalleeSavedRegisters()
1182 MachineInstrBuilder MIB = BuildMI(MBB, MBBI, DL, TII->get(SystemZ::LMG)); in restoreCalleeSavedRegisters()
1206 assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported"); in emitPrologue()
1225 if (ZFI->getSpillGPRRegs().LowGPR) { in emitPrologue()
1227 if ((MBBI != MBB.end()) && ((MBBI->getOpcode() == SystemZ::STMG))) { in emitPrologue()
1231 Offset = Regs.getStackPointerBias() + MBBI->getOperand(Operand).getImm(); in emitPrologue()
1233 if (isInt<20>(Offset - StackSize)) in emitPrologue()
1234 Offset -= StackSize; in emitPrologue()
1237 MBBI->getOperand(Operand).setImm(Offset); in emitPrologue()
1246 int64_t Delta = -int64_t(StackSize); in emitPrologue()
1248 // In case the STM(G) instruction also stores SP (R4), but the displacement in emitPrologue()
1254 BuildMI(MBB, InsertPt, DL, ZII->get(SystemZ::LGR)) in emitPrologue()
1258 BuildMI(MBB, MBBI, DL, ZII->get(SystemZ::STG)) in emitPrologue()
1277 BuildMI(MBB, InsertPt, DL, ZII->get(SystemZ::XPLINK_STACKALLOC)); in emitPrologue()
1282 // Copy the base of the frame to Frame Pointer Register. in emitPrologue()
1283 BuildMI(MBB, MBBI, DL, ZII->get(SystemZ::LGR), in emitPrologue()
1301 unsigned FixedRegs = ZFI->getVarArgsFirstGPR() + ZFI->getVarArgsFirstFPR(); in emitPrologue()
1308 BuildMI(MBB, MBBI, DL, TII->get(SystemZ::STG)) in emitPrologue()
1329 assert(MBBI->isReturn() && "Can only insert epilogue into returning blocks"); in emitEpilogue()
1334 if (ZFI->getRestoreGPRRegs().LowGPR != SPReg) { in emitEpilogue()
1335 DebugLoc DL = MBBI->getDebugLoc(); in emitEpilogue()
1362 const DebugLoc DL = StackAllocMI->getDebugLoc(); in inlineStackProbe()
1373 BuildMI(StackExtMBB, DL, ZII->get(SystemZ::LG), SystemZ::R3D) in inlineStackProbe()
1378 BuildMI(StackExtMBB, DL, ZII->get(SystemZ::CallBASR_STACKEXT)) in inlineStackProbe()
1383 BuildMI(MBB, StackAllocMI, DL, ZII->get(SystemZ::LGR)) in inlineStackProbe()
1392 BuildMI(MBB, MBB.begin(), DL, ZII->get(SystemZ::STG)) in inlineStackProbe()
1400 BuildMI(MBB, StackAllocMI, DL, ZII->get(SystemZ::LLGT), SystemZ::R3D) in inlineStackProbe()
1405 BuildMI(MBB, StackAllocMI, DL, ZII->get(SystemZ::CG)) in inlineStackProbe()
1411 BuildMI(MBB, StackAllocMI, DL, ZII->get(SystemZ::BRC)) in inlineStackProbe()
1422 BuildMI(*NextMBB, StackAllocMI, DL, ZII->get(SystemZ::LGR)) in inlineStackProbe()
1430 BuildMI(*NextMBB, StackAllocMI, DL, ZII->get(SystemZ::LGR)) in inlineStackProbe()
1434 BuildMI(*NextMBB, StackAllocMI, DL, ZII->get(SystemZ::LG)) in inlineStackProbe()
1443 BuildMI(StackExtMBB, DL, ZII->get(SystemZ::J)).addMBB(NextMBB); in inlineStackProbe()
1444 StackExtMBB->addSuccessor(NextMBB); in inlineStackProbe()
1446 StackAllocMI->eraseFromParent(); in inlineStackProbe()
1448 // Compute the live-in lists for the new blocks. in inlineStackProbe()
1494 // are outside the reach of an unsigned 12-bit displacement. in processFunctionBeforeFrameFinalized()
1495 RS->addScavengingFrameIndex(MFFrame.CreateStackObject(8, Align(8), false)); in processFunctionBeforeFrameFinalized()
1496 RS->addScavengingFrameIndex(MFFrame.CreateStackObject(8, Align(8), false)); in processFunctionBeforeFrameFinalized()
1513 StackSize += Regs->getCallFrameSize(); in determineFrameLayout()
1524 SPOffset -= StackSize; in determineFrameLayout()