27 { SystemZ::R2D, 0x10 },
28 { SystemZ::R3D, 0x18 },
29 { SystemZ::R4D, 0x20 },
30 { SystemZ::R5D, 0x28 },
31 { SystemZ::R6D, 0x30 },
32 { SystemZ::R7D, 0x38 },
33 { SystemZ::R8D, 0x40 },
34 { SystemZ::R9D, 0x48 },
35 { SystemZ::R10D, 0x50 },
36 { SystemZ::R11D, 0x58 },
37 { SystemZ::R12D, 0x60 },
38 { SystemZ::R13D, 0x68 },
39 { SystemZ::R14D, 0x70 },
40 { SystemZ::R15D, 0x78 },
41 { SystemZ::F0D, 0x80 },
42 { SystemZ::F2D, 0x88 },
43 { SystemZ::F4D, 0x90 },
44 { SystemZ::F6D, 0x98 }
60 RegSpillOffsets.
grow(SystemZ::NUM_TARGET_REGS);
62 RegSpillOffsets[SpillOffsetTable[
I].
Reg] = SpillOffsetTable[
I].
Offset;
71 if (HasPackedStackAttr && BackChain)
73 return HasPackedStackAttr && !IsVarArg && CallConv && !BackChain &&
80 std::vector<CalleeSavedInfo> &CSI)
const {
88 unsigned HighGPR = SystemZ::R15D;
92 for (
auto &CS : CSI) {
93 unsigned Reg = CS.getReg();
96 if (SystemZ::GR64BitRegClass.
contains(Reg) && StartSPOffset > Offset) {
101 int FrameIdx = MFFrame.CreateFixedSpillStackObject(8, Offset);
102 CS.setFrameIdx(FrameIdx);
104 CS.setFrameIdx(INT32_MAX);
118 if (StartSPOffset > Offset) {
129 for (
auto &CS : CSI) {
130 unsigned Reg = CS.getReg();
131 if (SystemZ::GR64BitRegClass.
contains(Reg)) {
133 int Offset = -8 * (15 - GR64Num + 1);
134 if (LowGR64Num > GR64Num) {
135 LowGR64Num = GR64Num;
138 int FrameIdx = MFFrame.CreateFixedSpillStackObject(8, Offset);
139 CS.setFrameIdx(FrameIdx);
141 CS.setFrameIdx(INT32_MAX);
143 if (LowGR64Num < UINT32_MAX)
155 for (
auto &CS : CSI) {
156 if (CS.getFrameIdx() != INT32_MAX)
158 unsigned Reg = CS.getReg();
162 assert(CurrOffset % 8 == 0 &&
163 "8-byte alignment required for for all register save slots");
164 int FrameIdx = MFFrame.CreateFixedSpillStackObject(Size, CurrOffset);
165 CS.setFrameIdx(FrameIdx);
178 bool HasFP =
hasFP(MF);
192 SavedRegs.
set(SystemZ::R6D);
193 SavedRegs.
set(SystemZ::R7D);
199 SavedRegs.
set(SystemZ::R11D);
204 SavedRegs.
set(SystemZ::R14D);
211 for (
unsigned I = 0; CSRegs[
I]; ++
I) {
212 unsigned Reg = CSRegs[
I];
213 if (SystemZ::GR64BitRegClass.
contains(Reg) && SavedRegs.
test(Reg)) {
214 SavedRegs.
set(SystemZ::R15D);
225 unsigned GPR64,
bool IsImplicit) {
230 if (!IsLive || !IsImplicit) {
240 const std::vector<CalleeSavedInfo> &CSI,
255 "Should be saving %r15 and something else");
269 for (
unsigned I = 0,
E = CSI.size();
I !=
E; ++
I) {
270 unsigned Reg = CSI[
I].getReg();
271 if (SystemZ::GR64BitRegClass.
contains(Reg))
282 for (
unsigned I = 0,
E = CSI.size();
I !=
E; ++
I) {
283 unsigned Reg = CSI[
I].getReg();
284 if (SystemZ::FP64BitRegClass.
contains(Reg)) {
287 &SystemZ::FP64BitRegClass, TRI);
289 if (SystemZ::VR128BitRegClass.
contains(Reg)) {
292 &SystemZ::VR128BitRegClass, TRI);
302 std::vector<CalleeSavedInfo> &CSI,
310 bool HasFP =
hasFP(MF);
314 for (
unsigned I = 0,
E = CSI.size();
I !=
E; ++
I) {
315 unsigned Reg = CSI[
I].getReg();
316 if (SystemZ::FP64BitRegClass.
contains(Reg))
318 &SystemZ::FP64BitRegClass, TRI);
319 if (SystemZ::VR128BitRegClass.
contains(Reg))
321 &SystemZ::VR128BitRegClass, TRI);
332 "Should be loading %r15 and something else");
342 MIB.
addReg(HasFP ? SystemZ::R11D : SystemZ::R15D);
346 for (
unsigned I = 0,
E = CSI.size();
I !=
E; ++
I) {
347 unsigned Reg = CSI[
I].getReg();
348 if (Reg != RestoreGPRs.
LowGPR && Reg != RestoreGPRs.
HighGPR &&
349 SystemZ::GR64BitRegClass.contains(Reg))
371 int64_t MaxArgOffset = 0;
376 MaxArgOffset =
std::max(MaxArgOffset, ArgOffset);
379 uint64_t MaxReach = StackSize + MaxArgOffset;
380 if (!isUInt<12>(MaxReach)) {
394 unsigned Reg, int64_t NumBytes,
398 int64_t ThisVal = NumBytes;
400 Opcode = SystemZ::AGHI;
402 Opcode = SystemZ::AGFI;
404 int64_t MinVal = -uint64_t(1) << 31;
405 int64_t MaxVal = (int64_t(1) << 31) - 8;
406 if (ThisVal < MinVal)
408 else if (ThisVal > MaxVal)
412 .addReg(Reg).
addImm(ThisVal);
421 assert(&MF.
front() == &MBB &&
"Shrink-wrapping not yet supported");
429 const std::vector<CalleeSavedInfo> &CSI = MFFrame.getCalleeSavedInfo();
430 bool HasFP =
hasFP(MF);
437 if (MFFrame.getStackSize() > 2048 *
sizeof(long)) {
439 "Pre allocated stack space for GHC function is too small");
443 "In GHC calling convention a frame pointer is not supported");
458 if (MBBI != MBB.
end() && MBBI->getOpcode() == SystemZ::STMG)
464 for (
auto &Save : CSI) {
465 unsigned Reg = Save.getReg();
466 if (SystemZ::GR64BitRegClass.
contains(Reg)) {
467 int FI = Save.getFrameIdx();
468 int64_t
Offset = MFFrame.getObjectOffset(FI);
471 BuildMI(MBB, MBBI, DL, ZII->
get(TargetOpcode::CFI_INSTRUCTION))
472 .addCFIIndex(CFIIndex);
477 uint64_t StackSize = MFFrame.getStackSize();
481 bool HasStackObject =
false;
482 for (
unsigned i = 0,
e = MFFrame.getObjectIndexEnd(); i !=
e; ++i)
483 if (!MFFrame.isDeadObjectIndex(i)) {
484 HasStackObject =
true;
487 if (HasStackObject || MFFrame.hasCalls())
493 MFFrame.setStackSize(StackSize);
502 BuildMI(MBB, MBBI, DL, ZII->
get(SystemZ::LGR))
506 int64_t Delta = -int64_t(StackSize);
512 BuildMI(MBB, MBBI, DL, ZII->
get(TargetOpcode::CFI_INSTRUCTION))
513 .addCFIIndex(CFIIndex);
514 SPOffsetFromCFA += Delta;
524 BuildMI(MBB, MBBI, DL, ZII->
get(SystemZ::LGR), SystemZ::R11D)
525 .addReg(SystemZ::R15D);
531 BuildMI(MBB, MBBI, DL, ZII->
get(TargetOpcode::CFI_INSTRUCTION))
532 .addCFIIndex(CFIIndex);
537 for (
auto I = std::next(MF.
begin()),
E = MF.
end();
I !=
E; ++
I)
538 I->addLiveIn(SystemZ::R11D);
543 for (
auto &Save : CSI) {
544 unsigned Reg = Save.getReg();
545 if (SystemZ::FP64BitRegClass.
contains(Reg)) {
546 if (MBBI != MBB.
end() &&
547 (MBBI->getOpcode() == SystemZ::STD ||
548 MBBI->getOpcode() == SystemZ::STDY))
552 }
else if (SystemZ::VR128BitRegClass.
contains(Reg)) {
553 if (MBBI != MBB.
end() &&
554 MBBI->getOpcode() == SystemZ::VST)
563 unsigned IgnoredFrameReg;
568 nullptr, DwarfReg, SPOffsetFromCFA + Offset));
573 for (
auto CFIIndex : CFIIndexes) {
574 BuildMI(MBB, MBBI, DL, ZII->
get(TargetOpcode::CFI_INSTRUCTION))
575 .addCFIIndex(CFIIndex);
592 assert(MBBI->isReturn() &&
"Can only insert epilogue into returning blocks");
594 uint64_t StackSize = MFFrame.getStackSize();
597 unsigned Opcode = MBBI->getOpcode();
598 if (Opcode != SystemZ::LMG)
601 unsigned AddrOpNo = 2;
603 uint64_t
Offset = StackSize + MBBI->getOperand(AddrOpNo + 1).getImm();
604 unsigned NewOpcode = ZII->getOpcodeForOffset(Opcode, Offset);
609 uint64_t NumBytes = Offset - 0x7fff8;
610 emitIncrement(MBB, MBBI, DL, MBBI->getOperand(AddrOpNo).getReg(),
613 NewOpcode = ZII->getOpcodeForOffset(Opcode, Offset);
614 assert(NewOpcode &&
"No restore instruction available");
617 MBBI->setDesc(ZII->get(NewOpcode));
618 MBBI->getOperand(AddrOpNo + 1).ChangeToImmediate(Offset);
619 }
else if (StackSize) {
642 unsigned &FrameReg)
const {
654 switch (MI->getOpcode()) {
655 case SystemZ::ADJCALLSTACKDOWN:
656 case SystemZ::ADJCALLSTACKUP:
658 "ADJSTACKDOWN and ADJSTACKUP should be no-ops");
659 return MBB.
erase(MI);
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register...
const int64_t CallFrameSize
unsigned getFirstReg(unsigned Reg)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
virtual int getFrameIndexReference(const MachineFunction &MF, int FI, unsigned &FrameReg) const
getFrameIndexReference - This method should return the base register and offset used to reference a f...
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
static void emitIncrement(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, const DebugLoc &DL, unsigned Reg, int64_t NumBytes, const TargetInstrInfo *TII)
void push_back(const T &Elt)
LLVM_NODISCARD unsigned addFrameInst(const MCCFIInstruction &Inst)
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
static MCCFIInstruction createOffset(MCSymbol *L, unsigned Register, int Offset)
.cfi_offset Previous value of Register is saved at offset Offset from CFA.
bool test(unsigned Idx) const
bool hasReservedCallFrame(const MachineFunction &MF) const override
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required, we reserve argument space for call sites in the function immediately on entry to the current function.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
constexpr bool isInt< 16 >(int64_t x)
unsigned const TargetRegisterInfo * TRI
void setIsDead(bool Val=true)
const unsigned NumArgGPRs
MachineModuleInfo & getMMI() const
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBII, std::vector< CalleeSavedInfo > &CSI, const TargetRegisterInfo *TRI) const override
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
static MCCFIInstruction createDefCfaOffset(MCSymbol *L, int Offset)
.cfi_def_cfa_offset modifies a rule for computing CFA.
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 ...
int getFramePointerSaveIndex() const
return AArch64::GPR64RegClass contains(Reg)
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
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...
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
const HexagonInstrInfo * TII
MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const override
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
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 ...
int getDwarfRegNum(MCRegister RegNum, bool isEH) const
Map a target register to an equivalent dwarf register number.
SystemZ::GPRRegs getRestoreGPRRegs() const
bool DisableFramePointerElim(const MachineFunction &MF) const
DisableFramePointerElim - This returns true if frame pointer elimination optimization should be disab...
const MCContext & getContext() const
Register getSubReg(MCRegister Reg, unsigned Idx) const
Returns the physical register number of sub-register "Index" for physical register RegNo...
int getObjectIndexBegin() const
Return the minimum frame object index.
iterator getLastNonDebugInstr()
Returns an iterator to the last non-debug instruction in the basic block, or end().
virtual const TargetInstrInfo * getInstrInfo() const
virtual const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const =0
Return a null-terminated list of all of the callee-saved registers on this target.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
unsigned getKillRegState(bool B)
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
TargetInstrInfo - Interface to description of machine instruction set.
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
This file declares the machine register scavenger class.
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
unsigned const MachineRegisterInfo * MRI
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register)
.cfi_def_cfa_register modifies a rule for computing CFA.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const int64_t CFAOffsetFromInitialSP
void setSpillGPRRegs(unsigned Low, unsigned High, unsigned Offs)
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
int getOrCreateFramePointerSaveIndex(MachineFunction &MF) const
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
const MachineBasicBlock & front() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This struct is a compact representation of a valid (non-zero power of two) alignment.
const std::vector< LandingPadInfo > & getLandingPads() const
Return a reference to the landing pad info for the current function.
static void addSavedGPR(MachineBasicBlock &MBB, MachineInstrBuilder &MIB, unsigned GPR64, bool IsImplicit)
Align max(MaybeAlign Lhs, Align Rhs)
unsigned getVarArgsFirstGPR() const
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
void addScavengingFrameIndex(int FI)
Add a scavenging frame index.
constexpr size_t array_lengthof(T(&)[N])
Find the length of an array.
Information about stack frame layout on the target.
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
const unsigned GR64Regs[16]
const Function & getFunction() const
Return the LLVM function that this machine code represents.
bool isLiveIn(MCPhysReg Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
virtual void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, unsigned SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const
Store the specified register of the given register class to the specified stack frame index...
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
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.
void setRestoreGPRRegs(unsigned Low, unsigned High, unsigned Offs)
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
unsigned getImplRegState(bool B)
void setFramePointerSaveIndex(int Idx)
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...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SystemZ::GPRRegs getSpillGPRRegs() const
int CreateStackObject(uint64_t Size, Align Alignment, bool isSpillSlot, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
Create a new statically sized stack object, returning a nonnegative identifier to represent it...
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const override
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
const MCRegisterInfo * getRegisterInfo() const
const MCPhysReg ArgGPRs[NumArgGPRs]
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const std::vector< CalleeSavedInfo > &CSI, const TargetRegisterInfo *TRI) const override
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
static bool usePackedStack(MachineFunction &MF)
const MachineOperand & getOperand(unsigned i) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
virtual void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, unsigned DestReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const
Load the specified register of the given register class from the specified stack frame index...
Wrapper class representing virtual and physical registers.
This class contains meta information specific to a module.
bool hasCalls() const
Return true if the current function has any function calls.