Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
SystemZFrameLowering.cpp
Go to the documentation of this file.
1//===-- SystemZFrameLowering.cpp - Frame lowering for SystemZ -------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "SystemZFrameLowering.h"
10#include "SystemZCallingConv.h"
11#include "SystemZInstrInfo.h"
12#include "SystemZMachineFunctionInfo.h"
13#include "SystemZRegisterInfo.h"
14#include "SystemZSubtarget.h"
15#include "llvm/CodeGen/LivePhysRegs.h"
16#include "llvm/CodeGen/MachineModuleInfo.h"
17#include "llvm/CodeGen/MachineRegisterInfo.h"
18#include "llvm/CodeGen/RegisterScavenging.h"
19#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
20#include "llvm/IR/Function.h"
21#include "llvm/Target/TargetMachine.h"
22
23using namespacellvm;
24
25namespace{
26// The ABI-defined register save slots, relative to the CFA (i.e.
27// incoming stack pointer + SystemZMC::ELFCallFrameSize).
28staticconstTargetFrameLowering::SpillSlot ELFSpillOffsetTable[] = {
29 { SystemZ::R2D, 0x10 },
30 { SystemZ::R3D, 0x18 },
31 { SystemZ::R4D, 0x20 },
32 { SystemZ::R5D, 0x28 },
33 { SystemZ::R6D, 0x30 },
34 { SystemZ::R7D, 0x38 },
35 { SystemZ::R8D, 0x40 },
36 { SystemZ::R9D, 0x48 },
37 { SystemZ::R10D, 0x50 },
38 { SystemZ::R11D, 0x58 },
39 { SystemZ::R12D, 0x60 },
40 { SystemZ::R13D, 0x68 },
41 { SystemZ::R14D, 0x70 },
42 { SystemZ::R15D, 0x78 },
43 { SystemZ::F0D, 0x80 },
44 { SystemZ::F2D, 0x88 },
45 { SystemZ::F4D, 0x90 },
46 { SystemZ::F6D, 0x98 }
47};
48
49staticconstTargetFrameLowering::SpillSlot XPLINKSpillOffsetTable[] = {
50 {SystemZ::R4D, 0x00}, {SystemZ::R5D, 0x08}, {SystemZ::R6D, 0x10},
51 {SystemZ::R7D, 0x18}, {SystemZ::R8D, 0x20}, {SystemZ::R9D, 0x28},
52 {SystemZ::R10D, 0x30}, {SystemZ::R11D, 0x38}, {SystemZ::R12D, 0x40},
53 {SystemZ::R13D, 0x48}, {SystemZ::R14D, 0x50}, {SystemZ::R15D, 0x58}};
54}// end anonymous namespace
55
56SystemZFrameLowering::SystemZFrameLowering(StackDirectionD,Align StackAl,
57int LAO,Align TransAl,
58bool StackReal,unsigned PointerSize)
59 :TargetFrameLowering(D, StackAl, LAO, TransAl, StackReal),
60 PointerSize(PointerSize) {}
61
62std::unique_ptr<SystemZFrameLowering>
63SystemZFrameLowering::create(constSystemZSubtarget &STI) {
64unsigned PtrSz =
65 STI.getTargetLowering()->getTargetMachine().getPointerSize(0);
66if (STI.isTargetXPLINK64())
67return std::make_unique<SystemZXPLINKFrameLowering>(PtrSz);
68return std::make_unique<SystemZELFFrameLowering>(PtrSz);
69}
70
71namespace{
72structSZFrameSortingObj {
73bool IsValid =false;// True if we care about this Object.
74uint32_t ObjectIndex = 0;// Index of Object into MFI list.
75uint64_t ObjectSize = 0;// Size of Object in bytes.
76uint32_t D12Count = 0;// 12-bit displacement only.
77uint32_t DPairCount = 0;// 12 or 20 bit displacement.
78};
79typedef std::vector<SZFrameSortingObj> SZFrameObjVec;
80}// namespace
81
82// TODO: Move to base class.
83voidSystemZELFFrameLowering::orderFrameObjects(
84constMachineFunction &MF,SmallVectorImpl<int> &ObjectsToAllocate) const{
85constMachineFrameInfo &MFI = MF.getFrameInfo();
86auto *TII = MF.getSubtarget<SystemZSubtarget>().getInstrInfo();
87
88// Make a vector of sorting objects to track all MFI objects and mark those
89// to be sorted as valid.
90if (ObjectsToAllocate.size() <= 1)
91return;
92 SZFrameObjVec SortingObjects(MFI.getObjectIndexEnd());
93for (auto &Obj : ObjectsToAllocate) {
94 SortingObjects[Obj].IsValid =true;
95 SortingObjects[Obj].ObjectIndex = Obj;
96 SortingObjects[Obj].ObjectSize = MFI.getObjectSize(Obj);
97 }
98
99// Examine uses for each object and record short (12-bit) and "pair"
100// displacement types.
101for (auto &MBB : MF)
102for (auto &MI :MBB) {
103if (MI.isDebugInstr())
104continue;
105for (unsignedI = 0, E =MI.getNumOperands();I != E; ++I) {
106constMachineOperand &MO =MI.getOperand(I);
107if (!MO.isFI())
108continue;
109int Index = MO.getIndex();
110if (Index >= 0 && Index < MFI.getObjectIndexEnd() &&
111 SortingObjects[Index].IsValid) {
112if (TII->hasDisplacementPairInsn(MI.getOpcode()))
113 SortingObjects[Index].DPairCount++;
114elseif (!(MI.getDesc().TSFlags &SystemZII::Has20BitOffset))
115 SortingObjects[Index].D12Count++;
116 }
117 }
118 }
119
120// Sort all objects for short/paired displacements, which should be
121// sufficient as it seems like all frame objects typically are within the
122// long displacement range. Sorting works by computing the "density" as
123// Count / ObjectSize. The comparisons of two such fractions are refactored
124// by multiplying both sides with A.ObjectSize * B.ObjectSize, in order to
125// eliminate the (fp) divisions. A higher density object needs to go after
126// in the list in order for it to end up lower on the stack.
127auto CmpD12 = [](const SZFrameSortingObj &A,const SZFrameSortingObj &B) {
128// Put all invalid and variable sized objects at the end.
129if (!A.IsValid || !B.IsValid)
130returnA.IsValid;
131if (!A.ObjectSize || !B.ObjectSize)
132returnA.ObjectSize > 0;
133uint64_t ADensityCmp =A.D12Count *B.ObjectSize;
134uint64_t BDensityCmp =B.D12Count *A.ObjectSize;
135if (ADensityCmp != BDensityCmp)
136return ADensityCmp < BDensityCmp;
137returnA.DPairCount *B.ObjectSize <B.DPairCount *A.ObjectSize;
138 };
139 std::stable_sort(SortingObjects.begin(), SortingObjects.end(), CmpD12);
140
141// Now modify the original list to represent the final order that
142// we want.
143unsignedIdx = 0;
144for (auto &Obj : SortingObjects) {
145// All invalid items are sorted at the end, so it's safe to stop.
146if (!Obj.IsValid)
147break;
148 ObjectsToAllocate[Idx++] = Obj.ObjectIndex;
149 }
150}
151
152boolSystemZFrameLowering::hasReservedCallFrame(
153constMachineFunction &MF) const{
154// The ELF ABI requires us to allocate 160 bytes of stack space for the
155// callee, with any outgoing stack arguments being placed above that. It
156// seems better to make that area a permanent feature of the frame even if
157// we're using a frame pointer. Similarly, 64-bit XPLINK requires 96 bytes
158// of stack space for the register save area.
159returntrue;
160}
161
162boolSystemZELFFrameLowering::assignCalleeSavedSpillSlots(
163MachineFunction &MF,constTargetRegisterInfo *TRI,
164 std::vector<CalleeSavedInfo> &CSI) const{
165SystemZMachineFunctionInfo *ZFI = MF.getInfo<SystemZMachineFunctionInfo>();
166MachineFrameInfo &MFFrame = MF.getFrameInfo();
167bool IsVarArg = MF.getFunction().isVarArg();
168if (CSI.empty())
169returntrue;// Early exit if no callee saved registers are modified!
170
171unsigned LowGPR = 0;
172unsigned HighGPR = SystemZ::R15D;
173int StartSPOffset =SystemZMC::ELFCallFrameSize;
174for (auto &CS : CSI) {
175Register Reg = CS.getReg();
176intOffset =getRegSpillOffset(MF, Reg);
177if (Offset) {
178if (SystemZ::GR64BitRegClass.contains(Reg) && StartSPOffset >Offset) {
179 LowGPR = Reg;
180 StartSPOffset =Offset;
181 }
182Offset -=SystemZMC::ELFCallFrameSize;
183int FrameIdx =
184 MFFrame.CreateFixedSpillStackObject(getPointerSize(),Offset);
185 CS.setFrameIdx(FrameIdx);
186 }else
187 CS.setFrameIdx(INT32_MAX);
188 }
189
190// Save the range of call-saved registers, for use by the
191// prologue/epilogue inserters.
192 ZFI->setRestoreGPRRegs(LowGPR, HighGPR, StartSPOffset);
193if (IsVarArg) {
194// Also save the GPR varargs, if any. R6D is call-saved, so would
195// already be included, but we also need to handle the call-clobbered
196// argument registers.
197Register FirstGPR = ZFI->getVarArgsFirstGPR();
198if (FirstGPR <SystemZ::ELFNumArgGPRs) {
199unsigned Reg =SystemZ::ELFArgGPRs[FirstGPR];
200intOffset =getRegSpillOffset(MF, Reg);
201if (StartSPOffset >Offset) {
202 LowGPR = Reg; StartSPOffset =Offset;
203 }
204 }
205 }
206 ZFI->setSpillGPRRegs(LowGPR, HighGPR, StartSPOffset);
207
208// Create fixed stack objects for the remaining registers.
209int CurrOffset = -SystemZMC::ELFCallFrameSize;
210if (usePackedStack(MF))
211 CurrOffset += StartSPOffset;
212
213for (auto &CS : CSI) {
214if (CS.getFrameIdx() != INT32_MAX)
215continue;
216Register Reg = CS.getReg();
217constTargetRegisterClass *RC =TRI->getMinimalPhysRegClass(Reg);
218unsignedSize =TRI->getSpillSize(*RC);
219 CurrOffset -=Size;
220assert(CurrOffset % 8 == 0 &&
221"8-byte alignment required for for all register save slots");
222int FrameIdx = MFFrame.CreateFixedSpillStackObject(Size, CurrOffset);
223 CS.setFrameIdx(FrameIdx);
224 }
225
226returntrue;
227}
228
229voidSystemZELFFrameLowering::determineCalleeSaves(MachineFunction &MF,
230BitVector &SavedRegs,
231RegScavenger *RS) const{
232TargetFrameLowering::determineCalleeSaves(MF, SavedRegs, RS);
233
234MachineFrameInfo &MFFrame = MF.getFrameInfo();
235constTargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
236bool HasFP =hasFP(MF);
237SystemZMachineFunctionInfo *MFI = MF.getInfo<SystemZMachineFunctionInfo>();
238bool IsVarArg = MF.getFunction().isVarArg();
239
240// va_start stores incoming FPR varargs in the normal way, but delegates
241// the saving of incoming GPR varargs to spillCalleeSavedRegisters().
242// Record these pending uses, which typically include the call-saved
243// argument register R6D.
244if (IsVarArg)
245for (unsignedI = MFI->getVarArgsFirstGPR();I <SystemZ::ELFNumArgGPRs; ++I)
246 SavedRegs.set(SystemZ::ELFArgGPRs[I]);
247
248// If there are any landing pads, entering them will modify r6/r7.
249if (!MF.getLandingPads().empty()) {
250 SavedRegs.set(SystemZ::R6D);
251 SavedRegs.set(SystemZ::R7D);
252 }
253
254// If the function requires a frame pointer, record that the hard
255// frame pointer will be clobbered.
256if (HasFP)
257 SavedRegs.set(SystemZ::R11D);
258
259// If the function calls other functions, record that the return
260// address register will be clobbered.
261if (MFFrame.hasCalls())
262 SavedRegs.set(SystemZ::R14D);
263
264// If we are saving GPRs other than the stack pointer, we might as well
265// save and restore the stack pointer at the same time, via STMG and LMG.
266// This allows the deallocation to be done by the LMG, rather than needing
267// a separate %r15 addition.
268constMCPhysReg *CSRegs =TRI->getCalleeSavedRegs(&MF);
269for (unsignedI = 0; CSRegs[I]; ++I) {
270unsigned Reg = CSRegs[I];
271if (SystemZ::GR64BitRegClass.contains(Reg) && SavedRegs.test(Reg)) {
272 SavedRegs.set(SystemZ::R15D);
273break;
274 }
275 }
276}
277
278SystemZELFFrameLowering::SystemZELFFrameLowering(unsigned PointerSize)
279 :SystemZFrameLowering(TargetFrameLowering::StackGrowsDown,Align(8), 0,
280Align(8),/* StackRealignable */false, PointerSize),
281 RegSpillOffsets(0) {
282
283// Due to the SystemZ ABI, the DWARF CFA (Canonical Frame Address) is not
284// equal to the incoming stack pointer, but to incoming stack pointer plus
285// 160. Instead of using a Local Area Offset, the Register save area will
286// be occupied by fixed frame objects, and all offsets are actually
287// relative to CFA.
288
289// Create a mapping from register number to save slot offset.
290// These offsets are relative to the start of the register save area.
291 RegSpillOffsets.grow(SystemZ::NUM_TARGET_REGS);
292for (constauto &Entry : ELFSpillOffsetTable)
293 RegSpillOffsets[Entry.Reg] = Entry.Offset;
294}
295
296// Add GPR64 to the save instruction being built by MIB, which is in basic
297// block MBB. IsImplicit says whether this is an explicit operand to the
298// instruction, or an implicit one that comes between the explicit start
299// and end registers.
300staticvoidaddSavedGPR(MachineBasicBlock &MBB,MachineInstrBuilder &MIB,
301unsigned GPR64,bool IsImplicit) {
302constTargetRegisterInfo *RI =
303MBB.getParent()->getSubtarget().getRegisterInfo();
304Register GPR32 = RI->getSubReg(GPR64, SystemZ::subreg_l32);
305bool IsLive =MBB.isLiveIn(GPR64) ||MBB.isLiveIn(GPR32);
306if (!IsLive || !IsImplicit) {
307 MIB.addReg(GPR64,getImplRegState(IsImplicit) |getKillRegState(!IsLive));
308if (!IsLive)
309MBB.addLiveIn(GPR64);
310 }
311}
312
313boolSystemZELFFrameLowering::spillCalleeSavedRegisters(
314MachineBasicBlock &MBB,MachineBasicBlock::iteratorMBBI,
315ArrayRef<CalleeSavedInfo> CSI,constTargetRegisterInfo *TRI) const{
316if (CSI.empty())
317returnfalse;
318
319MachineFunction &MF = *MBB.getParent();
320constTargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
321SystemZMachineFunctionInfo *ZFI = MF.getInfo<SystemZMachineFunctionInfo>();
322bool IsVarArg = MF.getFunction().isVarArg();
323DebugLocDL;
324
325// Save GPRs
326SystemZ::GPRRegs SpillGPRs = ZFI->getSpillGPRRegs();
327if (SpillGPRs.LowGPR) {
328assert(SpillGPRs.LowGPR != SpillGPRs.HighGPR &&
329"Should be saving %r15 and something else");
330
331// Build an STMG instruction.
332MachineInstrBuilder MIB =BuildMI(MBB,MBBI,DL,TII->get(SystemZ::STMG));
333
334// Add the explicit register operands.
335addSavedGPR(MBB, MIB, SpillGPRs.LowGPR,false);
336addSavedGPR(MBB, MIB, SpillGPRs.HighGPR,false);
337
338// Add the address.
339 MIB.addReg(SystemZ::R15D).addImm(SpillGPRs.GPROffset);
340
341// Make sure all call-saved GPRs are included as operands and are
342// marked as live on entry.
343for (constCalleeSavedInfo &I : CSI) {
344Register Reg =I.getReg();
345if (SystemZ::GR64BitRegClass.contains(Reg))
346addSavedGPR(MBB, MIB, Reg,true);
347 }
348
349// ...likewise GPR varargs.
350if (IsVarArg)
351for (unsignedI = ZFI->getVarArgsFirstGPR();I <SystemZ::ELFNumArgGPRs; ++I)
352addSavedGPR(MBB, MIB,SystemZ::ELFArgGPRs[I],true);
353 }
354
355// Save FPRs/VRs in the normal TargetInstrInfo way.
356for (constCalleeSavedInfo &I : CSI) {
357Register Reg =I.getReg();
358if (SystemZ::FP64BitRegClass.contains(Reg)) {
359MBB.addLiveIn(Reg);
360TII->storeRegToStackSlot(MBB,MBBI, Reg,true,I.getFrameIdx(),
361 &SystemZ::FP64BitRegClass,TRI,Register());
362 }
363if (SystemZ::VR128BitRegClass.contains(Reg)) {
364MBB.addLiveIn(Reg);
365TII->storeRegToStackSlot(MBB,MBBI, Reg,true,I.getFrameIdx(),
366 &SystemZ::VR128BitRegClass,TRI,Register());
367 }
368 }
369
370returntrue;
371}
372
373boolSystemZELFFrameLowering::restoreCalleeSavedRegisters(
374MachineBasicBlock &MBB,MachineBasicBlock::iteratorMBBI,
375MutableArrayRef<CalleeSavedInfo> CSI,constTargetRegisterInfo *TRI) const{
376if (CSI.empty())
377returnfalse;
378
379MachineFunction &MF = *MBB.getParent();
380constTargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
381SystemZMachineFunctionInfo *ZFI = MF.getInfo<SystemZMachineFunctionInfo>();
382bool HasFP =hasFP(MF);
383DebugLocDL =MBBI !=MBB.end() ?MBBI->getDebugLoc() :DebugLoc();
384
385// Restore FPRs/VRs in the normal TargetInstrInfo way.
386for (constCalleeSavedInfo &I : CSI) {
387Register Reg =I.getReg();
388if (SystemZ::FP64BitRegClass.contains(Reg))
389TII->loadRegFromStackSlot(MBB,MBBI, Reg,I.getFrameIdx(),
390 &SystemZ::FP64BitRegClass,TRI,Register());
391if (SystemZ::VR128BitRegClass.contains(Reg))
392TII->loadRegFromStackSlot(MBB,MBBI, Reg,I.getFrameIdx(),
393 &SystemZ::VR128BitRegClass,TRI,Register());
394 }
395
396// Restore call-saved GPRs (but not call-clobbered varargs, which at
397// this point might hold return values).
398SystemZ::GPRRegs RestoreGPRs = ZFI->getRestoreGPRRegs();
399if (RestoreGPRs.LowGPR) {
400// If we saved any of %r2-%r5 as varargs, we should also be saving
401// and restoring %r6. If we're saving %r6 or above, we should be
402// restoring it too.
403assert(RestoreGPRs.LowGPR != RestoreGPRs.HighGPR &&
404"Should be loading %r15 and something else");
405
406// Build an LMG instruction.
407MachineInstrBuilder MIB =BuildMI(MBB,MBBI,DL,TII->get(SystemZ::LMG));
408
409// Add the explicit register operands.
410 MIB.addReg(RestoreGPRs.LowGPR,RegState::Define);
411 MIB.addReg(RestoreGPRs.HighGPR,RegState::Define);
412
413// Add the address.
414 MIB.addReg(HasFP ? SystemZ::R11D : SystemZ::R15D);
415 MIB.addImm(RestoreGPRs.GPROffset);
416
417// Do a second scan adding regs as being defined by instruction
418for (constCalleeSavedInfo &I : CSI) {
419Register Reg =I.getReg();
420if (Reg != RestoreGPRs.LowGPR && Reg != RestoreGPRs.HighGPR &&
421 SystemZ::GR64BitRegClass.contains(Reg))
422 MIB.addReg(Reg,RegState::ImplicitDefine);
423 }
424 }
425
426returntrue;
427}
428
429voidSystemZELFFrameLowering::processFunctionBeforeFrameFinalized(
430MachineFunction &MF,RegScavenger *RS) const{
431MachineFrameInfo &MFFrame = MF.getFrameInfo();
432SystemZMachineFunctionInfo *ZFI = MF.getInfo<SystemZMachineFunctionInfo>();
433MachineRegisterInfo *MRI = &MF.getRegInfo();
434bool BackChain = MF.getSubtarget<SystemZSubtarget>().hasBackChain();
435
436if (!usePackedStack(MF) || BackChain)
437// Create the incoming register save area.
438getOrCreateFramePointerSaveIndex(MF);
439
440// Get the size of our stack frame to be allocated ...
441uint64_t StackSize = (MFFrame.estimateStackSize(MF) +
442SystemZMC::ELFCallFrameSize);
443// ... and the maximum offset we may need to reach into the
444// caller's frame to access the save area or stack arguments.
445 int64_t MaxArgOffset = 0;
446for (intI = MFFrame.getObjectIndexBegin();I != 0; ++I)
447if (MFFrame.getObjectOffset(I) >= 0) {
448 int64_t ArgOffset = MFFrame.getObjectOffset(I) +
449 MFFrame.getObjectSize(I);
450 MaxArgOffset = std::max(MaxArgOffset, ArgOffset);
451 }
452
453uint64_t MaxReach = StackSize + MaxArgOffset;
454if (!isUInt<12>(MaxReach)) {
455// We may need register scavenging slots if some parts of the frame
456// are outside the reach of an unsigned 12-bit displacement.
457// Create 2 for the case where both addresses in an MVC are
458// out of range.
459 RS->addScavengingFrameIndex(
460 MFFrame.CreateSpillStackObject(getPointerSize(),Align(8)));
461 RS->addScavengingFrameIndex(
462 MFFrame.CreateSpillStackObject(getPointerSize(),Align(8)));
463 }
464
465// If R6 is used as an argument register it is still callee saved. If it in
466// this case is not clobbered (and restored) it should never be marked as
467// killed.
468if (MF.front().isLiveIn(SystemZ::R6D) &&
469 ZFI->getRestoreGPRRegs().LowGPR != SystemZ::R6D)
470for (auto &MO :MRI->use_nodbg_operands(SystemZ::R6D))
471 MO.setIsKill(false);
472}
473
474// Emit instructions before MBBI (in MBB) to add NumBytes to Reg.
475staticvoidemitIncrement(MachineBasicBlock &MBB,
476MachineBasicBlock::iterator &MBBI,constDebugLoc &DL,
477Register Reg, int64_t NumBytes,
478constTargetInstrInfo *TII) {
479while (NumBytes) {
480unsigned Opcode;
481 int64_t ThisVal = NumBytes;
482if (isInt<16>(NumBytes))
483 Opcode = SystemZ::AGHI;
484else {
485 Opcode = SystemZ::AGFI;
486// Make sure we maintain 8-byte stack alignment.
487 int64_t MinVal = -uint64_t(1) << 31;
488 int64_t MaxVal = (int64_t(1) << 31) - 8;
489if (ThisVal < MinVal)
490 ThisVal = MinVal;
491elseif (ThisVal > MaxVal)
492 ThisVal = MaxVal;
493 }
494MachineInstr *MI =BuildMI(MBB,MBBI,DL,TII->get(Opcode), Reg)
495 .addReg(Reg).addImm(ThisVal);
496// The CC implicit def is dead.
497MI->getOperand(3).setIsDead();
498 NumBytes -= ThisVal;
499 }
500}
501
502// Add CFI for the new CFA offset.
503staticvoidbuildCFAOffs(MachineBasicBlock &MBB,
504MachineBasicBlock::iteratorMBBI,
505constDebugLoc &DL,intOffset,
506constSystemZInstrInfo *ZII) {
507unsigned CFIIndex =MBB.getParent()->addFrameInst(
508MCCFIInstruction::cfiDefCfaOffset(nullptr, -Offset));
509BuildMI(MBB,MBBI,DL, ZII->get(TargetOpcode::CFI_INSTRUCTION))
510 .addCFIIndex(CFIIndex);
511}
512
513// Add CFI for the new frame location.
514staticvoidbuildDefCFAReg(MachineBasicBlock &MBB,
515MachineBasicBlock::iteratorMBBI,
516constDebugLoc &DL,unsigned Reg,
517constSystemZInstrInfo *ZII) {
518MachineFunction &MF = *MBB.getParent();
519constMCRegisterInfo *MRI = MF.getContext().getRegisterInfo();
520unsigned RegNum =MRI->getDwarfRegNum(Reg,true);
521unsigned CFIIndex = MF.addFrameInst(
522MCCFIInstruction::createDefCfaRegister(nullptr, RegNum));
523BuildMI(MBB,MBBI,DL, ZII->get(TargetOpcode::CFI_INSTRUCTION))
524 .addCFIIndex(CFIIndex);
525}
526
527voidSystemZELFFrameLowering::emitPrologue(MachineFunction &MF,
528MachineBasicBlock &MBB) const{
529assert(&MF.front() == &MBB &&"Shrink-wrapping not yet supported");
530constSystemZSubtarget &STI = MF.getSubtarget<SystemZSubtarget>();
531constSystemZTargetLowering &TLI = *STI.getTargetLowering();
532MachineFrameInfo &MFFrame = MF.getFrameInfo();
533auto *ZII =static_cast<constSystemZInstrInfo *>(STI.getInstrInfo());
534SystemZMachineFunctionInfo *ZFI = MF.getInfo<SystemZMachineFunctionInfo>();
535MachineBasicBlock::iteratorMBBI =MBB.begin();
536constMCRegisterInfo *MRI = MF.getContext().getRegisterInfo();
537const std::vector<CalleeSavedInfo> &CSI = MFFrame.getCalleeSavedInfo();
538bool HasFP =hasFP(MF);
539
540// In GHC calling convention C stack space, including the ABI-defined
541// 160-byte base area, is (de)allocated by GHC itself. This stack space may
542// be used by LLVM as spill slots for the tail recursive GHC functions. Thus
543// do not allocate stack space here, too.
544if (MF.getFunction().getCallingConv() ==CallingConv::GHC) {
545if (MFFrame.getStackSize() > 2048 *sizeof(long)) {
546report_fatal_error(
547"Pre allocated stack space for GHC function is too small");
548 }
549if (HasFP) {
550report_fatal_error(
551"In GHC calling convention a frame pointer is not supported");
552 }
553 MFFrame.setStackSize(MFFrame.getStackSize() +SystemZMC::ELFCallFrameSize);
554return;
555 }
556
557// Debug location must be unknown since the first debug location is used
558// to determine the end of the prologue.
559DebugLocDL;
560
561// The current offset of the stack pointer from the CFA.
562 int64_t SPOffsetFromCFA = -SystemZMC::ELFCFAOffsetFromInitialSP;
563
564if (ZFI->getSpillGPRRegs().LowGPR) {
565// Skip over the GPR saves.
566if (MBBI !=MBB.end() &&MBBI->getOpcode() == SystemZ::STMG)
567 ++MBBI;
568else
569llvm_unreachable("Couldn't skip over GPR saves");
570
571// Add CFI for the GPR saves.
572for (auto &Save : CSI) {
573Register Reg = Save.getReg();
574if (SystemZ::GR64BitRegClass.contains(Reg)) {
575int FI = Save.getFrameIdx();
576 int64_tOffset = MFFrame.getObjectOffset(FI);
577unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::createOffset(
578nullptr,MRI->getDwarfRegNum(Reg,true),Offset));
579BuildMI(MBB,MBBI,DL, ZII->get(TargetOpcode::CFI_INSTRUCTION))
580 .addCFIIndex(CFIIndex);
581 }
582 }
583 }
584
585uint64_t StackSize = MFFrame.getStackSize();
586// We need to allocate the ABI-defined 160-byte base area whenever
587// we allocate stack space for our own use and whenever we call another
588// function.
589bool HasStackObject =false;
590for (unsigned i = 0, e = MFFrame.getObjectIndexEnd(); i != e; ++i)
591if (!MFFrame.isDeadObjectIndex(i)) {
592 HasStackObject =true;
593break;
594 }
595if (HasStackObject || MFFrame.hasCalls())
596 StackSize +=SystemZMC::ELFCallFrameSize;
597// Don't allocate the incoming reg save area.
598 StackSize = StackSize >SystemZMC::ELFCallFrameSize
599 ? StackSize -SystemZMC::ELFCallFrameSize
600 : 0;
601 MFFrame.setStackSize(StackSize);
602
603if (StackSize) {
604// Allocate StackSize bytes.
605 int64_t Delta = -int64_t(StackSize);
606constunsigned ProbeSize = TLI.getStackProbeSize(MF);
607bool FreeProbe = (ZFI->getSpillGPRRegs().GPROffset &&
608 (ZFI->getSpillGPRRegs().GPROffset + StackSize) < ProbeSize);
609if (!FreeProbe &&
610 MF.getSubtarget().getTargetLowering()->hasInlineStackProbe(MF)) {
611// Stack probing may involve looping, but splitting the prologue block
612// is not possible at this point since it would invalidate the
613// SaveBlocks / RestoreBlocks sets of PEI in the single block function
614// case. Build a pseudo to be handled later by inlineStackProbe().
615BuildMI(MBB,MBBI,DL, ZII->get(SystemZ::PROBED_STACKALLOC))
616 .addImm(StackSize);
617 }
618else {
619bool StoreBackchain = MF.getSubtarget<SystemZSubtarget>().hasBackChain();
620// If we need backchain, save current stack pointer. R1 is free at
621// this point.
622if (StoreBackchain)
623BuildMI(MBB,MBBI,DL, ZII->get(SystemZ::LGR))
624 .addReg(SystemZ::R1D,RegState::Define).addReg(SystemZ::R15D);
625emitIncrement(MBB,MBBI,DL, SystemZ::R15D, Delta, ZII);
626buildCFAOffs(MBB,MBBI,DL, SPOffsetFromCFA + Delta, ZII);
627if (StoreBackchain)
628BuildMI(MBB,MBBI,DL, ZII->get(SystemZ::STG))
629 .addReg(SystemZ::R1D,RegState::Kill).addReg(SystemZ::R15D)
630 .addImm(getBackchainOffset(MF)).addReg(0);
631 }
632 SPOffsetFromCFA += Delta;
633 }
634
635if (HasFP) {
636// Copy the base of the frame to R11.
637BuildMI(MBB,MBBI,DL, ZII->get(SystemZ::LGR), SystemZ::R11D)
638 .addReg(SystemZ::R15D);
639
640// Add CFI for the new frame location.
641buildDefCFAReg(MBB,MBBI,DL, SystemZ::R11D, ZII);
642
643// Mark the FramePtr as live at the beginning of every block except
644// the entry block. (We'll have marked R11 as live on entry when
645// saving the GPRs.)
646for (MachineBasicBlock &MBBJ :llvm::drop_begin(MF))
647 MBBJ.addLiveIn(SystemZ::R11D);
648 }
649
650// Skip over the FPR/VR saves.
651SmallVector<unsigned, 8> CFIIndexes;
652for (auto &Save : CSI) {
653Register Reg = Save.getReg();
654if (SystemZ::FP64BitRegClass.contains(Reg)) {
655if (MBBI !=MBB.end() &&
656 (MBBI->getOpcode() == SystemZ::STD ||
657MBBI->getOpcode() == SystemZ::STDY))
658 ++MBBI;
659else
660llvm_unreachable("Couldn't skip over FPR save");
661 }elseif (SystemZ::VR128BitRegClass.contains(Reg)) {
662if (MBBI !=MBB.end() &&
663MBBI->getOpcode() == SystemZ::VST)
664 ++MBBI;
665else
666llvm_unreachable("Couldn't skip over VR save");
667 }else
668continue;
669
670// Add CFI for the this save.
671unsigned DwarfReg =MRI->getDwarfRegNum(Reg,true);
672Register IgnoredFrameReg;
673 int64_tOffset =
674getFrameIndexReference(MF, Save.getFrameIdx(), IgnoredFrameReg)
675 .getFixed();
676
677unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::createOffset(
678nullptr, DwarfReg, SPOffsetFromCFA +Offset));
679 CFIIndexes.push_back(CFIIndex);
680 }
681// Complete the CFI for the FPR/VR saves, modelling them as taking effect
682// after the last save.
683for (auto CFIIndex : CFIIndexes) {
684BuildMI(MBB,MBBI,DL, ZII->get(TargetOpcode::CFI_INSTRUCTION))
685 .addCFIIndex(CFIIndex);
686 }
687}
688
689voidSystemZELFFrameLowering::emitEpilogue(MachineFunction &MF,
690MachineBasicBlock &MBB) const{
691MachineBasicBlock::iteratorMBBI =MBB.getLastNonDebugInstr();
692auto *ZII =
693static_cast<constSystemZInstrInfo *>(MF.getSubtarget().getInstrInfo());
694SystemZMachineFunctionInfo *ZFI = MF.getInfo<SystemZMachineFunctionInfo>();
695MachineFrameInfo &MFFrame = MF.getFrameInfo();
696
697// See SystemZELFFrameLowering::emitPrologue
698if (MF.getFunction().getCallingConv() ==CallingConv::GHC)
699return;
700
701// Skip the return instruction.
702assert(MBBI->isReturn() &&"Can only insert epilogue into returning blocks");
703
704uint64_t StackSize = MFFrame.getStackSize();
705if (ZFI->getRestoreGPRRegs().LowGPR) {
706 --MBBI;
707unsigned Opcode =MBBI->getOpcode();
708if (Opcode != SystemZ::LMG)
709llvm_unreachable("Expected to see callee-save register restore code");
710
711unsigned AddrOpNo = 2;
712DebugLocDL =MBBI->getDebugLoc();
713uint64_tOffset = StackSize +MBBI->getOperand(AddrOpNo + 1).getImm();
714unsigned NewOpcode = ZII->getOpcodeForOffset(Opcode,Offset);
715
716// If the offset is too large, use the largest stack-aligned offset
717// and add the rest to the base register (the stack or frame pointer).
718if (!NewOpcode) {
719uint64_t NumBytes =Offset - 0x7fff8;
720emitIncrement(MBB,MBBI,DL,MBBI->getOperand(AddrOpNo).getReg(),
721 NumBytes, ZII);
722Offset -= NumBytes;
723 NewOpcode = ZII->getOpcodeForOffset(Opcode,Offset);
724assert(NewOpcode &&"No restore instruction available");
725 }
726
727MBBI->setDesc(ZII->get(NewOpcode));
728MBBI->getOperand(AddrOpNo + 1).ChangeToImmediate(Offset);
729 }elseif (StackSize) {
730DebugLocDL =MBBI->getDebugLoc();
731emitIncrement(MBB,MBBI,DL, SystemZ::R15D, StackSize, ZII);
732 }
733}
734
735voidSystemZELFFrameLowering::inlineStackProbe(
736MachineFunction &MF,MachineBasicBlock &PrologMBB) const{
737auto *ZII =
738static_cast<constSystemZInstrInfo *>(MF.getSubtarget().getInstrInfo());
739constSystemZSubtarget &STI = MF.getSubtarget<SystemZSubtarget>();
740constSystemZTargetLowering &TLI = *STI.getTargetLowering();
741
742MachineInstr *StackAllocMI =nullptr;
743for (MachineInstr &MI : PrologMBB)
744if (MI.getOpcode() == SystemZ::PROBED_STACKALLOC) {
745 StackAllocMI = &MI;
746break;
747 }
748if (StackAllocMI ==nullptr)
749return;
750uint64_t StackSize = StackAllocMI->getOperand(0).getImm();
751constunsigned ProbeSize = TLI.getStackProbeSize(MF);
752uint64_t NumFullBlocks = StackSize / ProbeSize;
753uint64_t Residual = StackSize % ProbeSize;
754 int64_t SPOffsetFromCFA = -SystemZMC::ELFCFAOffsetFromInitialSP;
755MachineBasicBlock *MBB = &PrologMBB;
756MachineBasicBlock::iteratorMBBI = StackAllocMI;
757constDebugLocDL = StackAllocMI->getDebugLoc();
758
759// Allocate a block of Size bytes on the stack and probe it.
760auto allocateAndProbe = [&](MachineBasicBlock &InsMBB,
761MachineBasicBlock::iterator InsPt,unsignedSize,
762bool EmitCFI) ->void {
763emitIncrement(InsMBB, InsPt,DL, SystemZ::R15D, -int64_t(Size), ZII);
764if (EmitCFI) {
765 SPOffsetFromCFA -=Size;
766buildCFAOffs(InsMBB, InsPt,DL, SPOffsetFromCFA, ZII);
767 }
768// Probe by means of a volatile compare.
769MachineMemOperand *MMO = MF.getMachineMemOperand(MachinePointerInfo(),
770MachineMemOperand::MOVolatile |MachineMemOperand::MOLoad, 8,Align(1));
771BuildMI(InsMBB, InsPt,DL, ZII->get(SystemZ::CG))
772 .addReg(SystemZ::R0D,RegState::Undef)
773 .addReg(SystemZ::R15D).addImm(Size - 8).addReg(0)
774 .addMemOperand(MMO);
775 };
776
777bool StoreBackchain = MF.getSubtarget<SystemZSubtarget>().hasBackChain();
778if (StoreBackchain)
779BuildMI(*MBB,MBBI,DL, ZII->get(SystemZ::LGR))
780 .addReg(SystemZ::R1D,RegState::Define).addReg(SystemZ::R15D);
781
782MachineBasicBlock *DoneMBB =nullptr;
783MachineBasicBlock *LoopMBB =nullptr;
784if (NumFullBlocks < 3) {
785// Emit unrolled probe statements.
786for (unsignedint i = 0; i < NumFullBlocks; i++)
787 allocateAndProbe(*MBB,MBBI, ProbeSize,true/*EmitCFI*/);
788 }else {
789// Emit a loop probing the pages.
790uint64_t LoopAlloc = ProbeSize * NumFullBlocks;
791 SPOffsetFromCFA -= LoopAlloc;
792
793// Use R0D to hold the exit value.
794BuildMI(*MBB,MBBI,DL, ZII->get(SystemZ::LGR), SystemZ::R0D)
795 .addReg(SystemZ::R15D);
796buildDefCFAReg(*MBB,MBBI,DL, SystemZ::R0D, ZII);
797emitIncrement(*MBB,MBBI,DL, SystemZ::R0D, -int64_t(LoopAlloc), ZII);
798buildCFAOffs(*MBB,MBBI,DL, -int64_t(SystemZMC::ELFCallFrameSize + LoopAlloc),
799 ZII);
800
801 DoneMBB =SystemZ::splitBlockBefore(MBBI,MBB);
802 LoopMBB =SystemZ::emitBlockAfter(MBB);
803MBB->addSuccessor(LoopMBB);
804 LoopMBB->addSuccessor(LoopMBB);
805 LoopMBB->addSuccessor(DoneMBB);
806
807MBB = LoopMBB;
808 allocateAndProbe(*MBB,MBB->end(), ProbeSize,false/*EmitCFI*/);
809BuildMI(*MBB,MBB->end(),DL, ZII->get(SystemZ::CLGR))
810 .addReg(SystemZ::R15D).addReg(SystemZ::R0D);
811BuildMI(*MBB,MBB->end(),DL, ZII->get(SystemZ::BRC))
812 .addImm(SystemZ::CCMASK_ICMP).addImm(SystemZ::CCMASK_CMP_GT).addMBB(MBB);
813
814MBB = DoneMBB;
815MBBI = DoneMBB->begin();
816buildDefCFAReg(*MBB,MBBI,DL, SystemZ::R15D, ZII);
817 }
818
819if (Residual)
820 allocateAndProbe(*MBB,MBBI, Residual,true/*EmitCFI*/);
821
822if (StoreBackchain)
823BuildMI(*MBB,MBBI,DL, ZII->get(SystemZ::STG))
824 .addReg(SystemZ::R1D,RegState::Kill).addReg(SystemZ::R15D)
825 .addImm(getBackchainOffset(MF)).addReg(0);
826
827 StackAllocMI->eraseFromParent();
828if (DoneMBB !=nullptr) {
829// Compute the live-in lists for the new blocks.
830fullyRecomputeLiveIns({DoneMBB, LoopMBB});
831 }
832}
833
834boolSystemZELFFrameLowering::hasFPImpl(constMachineFunction &MF) const{
835return (MF.getTarget().Options.DisableFramePointerElim(MF) ||
836 MF.getFrameInfo().hasVarSizedObjects());
837}
838
839StackOffsetSystemZELFFrameLowering::getFrameIndexReference(
840constMachineFunction &MF,int FI,Register &FrameReg) const{
841// Our incoming SP is actually SystemZMC::ELFCallFrameSize below the CFA, so
842// add that difference here.
843StackOffsetOffset =
844TargetFrameLowering::getFrameIndexReference(MF, FI, FrameReg);
845returnOffset +StackOffset::getFixed(SystemZMC::ELFCallFrameSize);
846}
847
848unsignedSystemZELFFrameLowering::getRegSpillOffset(MachineFunction &MF,
849Register Reg) const{
850bool IsVarArg = MF.getFunction().isVarArg();
851constSystemZSubtarget &Subtarget = MF.getSubtarget<SystemZSubtarget>();
852bool BackChain = Subtarget.hasBackChain();
853bool SoftFloat = Subtarget.hasSoftFloat();
854unsignedOffset = RegSpillOffsets[Reg];
855if (usePackedStack(MF) && !(IsVarArg && !SoftFloat)) {
856if (SystemZ::GR64BitRegClass.contains(Reg))
857// Put all GPRs at the top of the Register save area with packed
858// stack. Make room for the backchain if needed.
859Offset += BackChain ? 24 : 32;
860else
861Offset = 0;
862 }
863returnOffset;
864}
865
866intSystemZELFFrameLowering::getOrCreateFramePointerSaveIndex(
867MachineFunction &MF) const{
868SystemZMachineFunctionInfo *ZFI = MF.getInfo<SystemZMachineFunctionInfo>();
869int FI = ZFI->getFramePointerSaveIndex();
870if (!FI) {
871MachineFrameInfo &MFFrame = MF.getFrameInfo();
872intOffset =getBackchainOffset(MF) -SystemZMC::ELFCallFrameSize;
873 FI = MFFrame.CreateFixedObject(getPointerSize(),Offset,false);
874 ZFI->setFramePointerSaveIndex(FI);
875 }
876return FI;
877}
878
879boolSystemZELFFrameLowering::usePackedStack(MachineFunction &MF) const{
880bool HasPackedStackAttr = MF.getFunction().hasFnAttribute("packed-stack");
881constSystemZSubtarget &Subtarget = MF.getSubtarget<SystemZSubtarget>();
882bool BackChain = Subtarget.hasBackChain();
883bool SoftFloat = Subtarget.hasSoftFloat();
884if (HasPackedStackAttr && BackChain && !SoftFloat)
885report_fatal_error("packed-stack + backchain + hard-float is unsupported.");
886bool CallConv = MF.getFunction().getCallingConv() !=CallingConv::GHC;
887return HasPackedStackAttr && CallConv;
888}
889
890SystemZXPLINKFrameLowering::SystemZXPLINKFrameLowering(unsigned PointerSize)
891 :SystemZFrameLowering(TargetFrameLowering::StackGrowsDown,Align(32), 0,
892Align(32),/* StackRealignable */false,
893 PointerSize),
894 RegSpillOffsets(-1) {
895
896// Create a mapping from register number to save slot offset.
897// These offsets are relative to the start of the local are area.
898 RegSpillOffsets.grow(SystemZ::NUM_TARGET_REGS);
899for (constauto &Entry : XPLINKSpillOffsetTable)
900 RegSpillOffsets[Entry.Reg] = Entry.Offset;
901}
902
903intSystemZXPLINKFrameLowering::getOrCreateFramePointerSaveIndex(
904MachineFunction &MF) const{
905SystemZMachineFunctionInfo *ZFI = MF.getInfo<SystemZMachineFunctionInfo>();
906int FI = ZFI->getFramePointerSaveIndex();
907if (!FI) {
908MachineFrameInfo &MFFrame = MF.getFrameInfo();
909 FI = MFFrame.CreateFixedObject(getPointerSize(), 0,false);
910 MFFrame.setStackID(FI,TargetStackID::NoAlloc);
911 ZFI->setFramePointerSaveIndex(FI);
912 }
913return FI;
914}
915
916// Checks if the function is a potential candidate for being a XPLeaf routine.
917staticboolisXPLeafCandidate(constMachineFunction &MF) {
918constMachineFrameInfo &MFFrame = MF.getFrameInfo();
919constMachineRegisterInfo &MRI = MF.getRegInfo();
920constSystemZSubtarget &Subtarget = MF.getSubtarget<SystemZSubtarget>();
921auto *Regs =
922static_cast<SystemZXPLINK64Registers *>(Subtarget.getSpecialRegisters());
923
924// If function calls other functions including alloca, then it is not a XPLeaf
925// routine.
926if (MFFrame.hasCalls())
927returnfalse;
928
929// If the function has var Sized Objects, then it is not a XPLeaf routine.
930if (MFFrame.hasVarSizedObjects())
931returnfalse;
932
933// If the function adjusts the stack, then it is not a XPLeaf routine.
934if (MFFrame.adjustsStack())
935returnfalse;
936
937// If function modifies the stack pointer register, then it is not a XPLeaf
938// routine.
939if (MRI.isPhysRegModified(Regs->getStackPointerRegister()))
940returnfalse;
941
942// If function modifies the ADA register, then it is not a XPLeaf routine.
943if (MRI.isPhysRegModified(Regs->getAddressOfCalleeRegister()))
944returnfalse;
945
946// If function modifies the return address register, then it is not a XPLeaf
947// routine.
948if (MRI.isPhysRegModified(Regs->getReturnFunctionAddressRegister()))
949returnfalse;
950
951// If the backchain pointer should be stored, then it is not a XPLeaf routine.
952if (MF.getSubtarget<SystemZSubtarget>().hasBackChain())
953returnfalse;
954
955// If function acquires its own stack frame, then it is not a XPLeaf routine.
956// At the time this function is called, only slots for local variables are
957// allocated, so this is a very rough estimate.
958if (MFFrame.estimateStackSize(MF) > 0)
959returnfalse;
960
961returntrue;
962}
963
964boolSystemZXPLINKFrameLowering::assignCalleeSavedSpillSlots(
965MachineFunction &MF,constTargetRegisterInfo *TRI,
966 std::vector<CalleeSavedInfo> &CSI) const{
967MachineFrameInfo &MFFrame = MF.getFrameInfo();
968SystemZMachineFunctionInfo *MFI = MF.getInfo<SystemZMachineFunctionInfo>();
969constSystemZSubtarget &Subtarget = MF.getSubtarget<SystemZSubtarget>();
970auto &Regs = Subtarget.getSpecialRegisters<SystemZXPLINK64Registers>();
971auto &GRRegClass = SystemZ::GR64BitRegClass;
972
973// At this point, the result of isXPLeafCandidate() is not accurate because
974// the size of the save area has not yet been determined. If
975// isXPLeafCandidate() indicates a potential leaf function, and there are no
976// callee-save registers, then it is indeed a leaf function, and we can early
977// exit.
978// TODO: It is possible for leaf functions to use callee-saved registers.
979// It can use the 0-2k range between R4 and the caller's stack frame without
980// acquiring its own stack frame.
981bool IsLeaf = CSI.empty() &&isXPLeafCandidate(MF);
982if (IsLeaf)
983returntrue;
984
985// For non-leaf functions:
986// - the address of callee (entry point) register R6 must be saved
987 CSI.push_back(CalleeSavedInfo(Regs.getAddressOfCalleeRegister()));
988 CSI.back().setRestored(false);
989
990// The return address register R7 must be saved and restored.
991 CSI.push_back(CalleeSavedInfo(Regs.getReturnFunctionAddressRegister()));
992
993// If the function needs a frame pointer, or if the backchain pointer should
994// be stored, then save the stack pointer register R4.
995if (hasFP(MF) || Subtarget.hasBackChain())
996 CSI.push_back(CalleeSavedInfo(Regs.getStackPointerRegister()));
997
998// If this function has an associated personality function then the
999// environment register R5 must be saved in the DSA.
1000if (!MF.getLandingPads().empty())
1001 CSI.push_back(CalleeSavedInfo(Regs.getADARegister()));
1002
1003// Scan the call-saved GPRs and find the bounds of the register spill area.
1004Register LowRestoreGPR = 0;
1005int LowRestoreOffset = INT32_MAX;
1006Register LowSpillGPR = 0;
1007int LowSpillOffset = INT32_MAX;
1008Register HighGPR = 0;
1009int HighOffset = -1;
1010
1011// Query index of the saved frame pointer.
1012int FPSI = MFI->getFramePointerSaveIndex();
1013
1014for (auto &CS : CSI) {
1015Register Reg = CS.getReg();
1016intOffset = RegSpillOffsets[Reg];
1017if (Offset >= 0) {
1018if (GRRegClass.contains(Reg)) {
1019if (LowSpillOffset >Offset) {
1020 LowSpillOffset =Offset;
1021 LowSpillGPR = Reg;
1022 }
1023if (CS.isRestored() && LowRestoreOffset >Offset) {
1024 LowRestoreOffset =Offset;
1025 LowRestoreGPR = Reg;
1026 }
1027
1028if (Offset > HighOffset) {
1029 HighOffset =Offset;
1030 HighGPR = Reg;
1031 }
1032// Non-volatile GPRs are saved in the dedicated register save area at
1033// the bottom of the stack and are not truly part of the "normal" stack
1034// frame. Mark the frame index as NoAlloc to indicate it as such.
1035unsignedRegSize =getPointerSize();
1036int FrameIdx =
1037 (FPSI &&Offset == 0)
1038 ? FPSI
1039 : MFFrame.CreateFixedSpillStackObject(RegSize,Offset);
1040 CS.setFrameIdx(FrameIdx);
1041 MFFrame.setStackID(FrameIdx,TargetStackID::NoAlloc);
1042 }
1043 }else {
1044Register Reg = CS.getReg();
1045constTargetRegisterClass *RC =TRI->getMinimalPhysRegClass(Reg);
1046Align Alignment =TRI->getSpillAlign(*RC);
1047unsignedSize =TRI->getSpillSize(*RC);
1048 Alignment = std::min(Alignment,getStackAlign());
1049int FrameIdx = MFFrame.CreateStackObject(Size, Alignment,true);
1050 CS.setFrameIdx(FrameIdx);
1051 }
1052 }
1053
1054// Save the range of call-saved registers, for use by the
1055// prologue/epilogue inserters.
1056if (LowRestoreGPR)
1057 MFI->setRestoreGPRRegs(LowRestoreGPR, HighGPR, LowRestoreOffset);
1058
1059// Save the range of call-saved registers, for use by the epilogue inserter.
1060assert(LowSpillGPR &&"Expected registers to spill");
1061 MFI->setSpillGPRRegs(LowSpillGPR, HighGPR, LowSpillOffset);
1062
1063returntrue;
1064}
1065
1066voidSystemZXPLINKFrameLowering::determineCalleeSaves(MachineFunction &MF,
1067BitVector &SavedRegs,
1068RegScavenger *RS) const{
1069TargetFrameLowering::determineCalleeSaves(MF, SavedRegs, RS);
1070
1071bool HasFP =hasFP(MF);
1072constSystemZSubtarget &Subtarget = MF.getSubtarget<SystemZSubtarget>();
1073auto &Regs = Subtarget.getSpecialRegisters<SystemZXPLINK64Registers>();
1074
1075// If the function requires a frame pointer, record that the hard
1076// frame pointer will be clobbered.
1077if (HasFP)
1078 SavedRegs.set(Regs.getFramePointerRegister());
1079}
1080
1081boolSystemZXPLINKFrameLowering::spillCalleeSavedRegisters(
1082MachineBasicBlock &MBB,MachineBasicBlock::iteratorMBBI,
1083ArrayRef<CalleeSavedInfo> CSI,constTargetRegisterInfo *TRI) const{
1084if (CSI.empty())
1085returntrue;
1086
1087MachineFunction &MF = *MBB.getParent();
1088SystemZMachineFunctionInfo *ZFI = MF.getInfo<SystemZMachineFunctionInfo>();
1089constSystemZSubtarget &Subtarget = MF.getSubtarget<SystemZSubtarget>();
1090constTargetInstrInfo *TII = Subtarget.getInstrInfo();
1091auto &Regs = Subtarget.getSpecialRegisters<SystemZXPLINK64Registers>();
1092SystemZ::GPRRegs SpillGPRs = ZFI->getSpillGPRRegs();
1093DebugLocDL;
1094
1095// Save GPRs
1096if (SpillGPRs.LowGPR) {
1097assert(SpillGPRs.LowGPR != SpillGPRs.HighGPR &&
1098"Should be saving multiple registers");
1099
1100// Build an STM/STMG instruction.
1101MachineInstrBuilder MIB =BuildMI(MBB,MBBI,DL,TII->get(SystemZ::STMG));
1102
1103// Add the explicit register operands.
1104addSavedGPR(MBB, MIB, SpillGPRs.LowGPR,false);
1105addSavedGPR(MBB, MIB, SpillGPRs.HighGPR,false);
1106
1107// Add the address r4
1108 MIB.addReg(Regs.getStackPointerRegister());
1109
1110// Add the partial offset
1111// We cannot add the actual offset as, at the stack is not finalized
1112 MIB.addImm(SpillGPRs.GPROffset);
1113
1114// Make sure all call-saved GPRs are included as operands and are
1115// marked as live on entry.
1116auto &GRRegClass = SystemZ::GR64BitRegClass;
1117for (constCalleeSavedInfo &I : CSI) {
1118Register Reg =I.getReg();
1119if (GRRegClass.contains(Reg))
1120addSavedGPR(MBB, MIB, Reg,true);
1121 }
1122 }
1123
1124// Spill FPRs to the stack in the normal TargetInstrInfo way
1125for (constCalleeSavedInfo &I : CSI) {
1126Register Reg =I.getReg();
1127if (SystemZ::FP64BitRegClass.contains(Reg)) {
1128MBB.addLiveIn(Reg);
1129TII->storeRegToStackSlot(MBB,MBBI, Reg,true,I.getFrameIdx(),
1130 &SystemZ::FP64BitRegClass,TRI,Register());
1131 }
1132if (SystemZ::VR128BitRegClass.contains(Reg)) {
1133MBB.addLiveIn(Reg);
1134TII->storeRegToStackSlot(MBB,MBBI, Reg,true,I.getFrameIdx(),
1135 &SystemZ::VR128BitRegClass,TRI,Register());
1136 }
1137 }
1138
1139returntrue;
1140}
1141
1142boolSystemZXPLINKFrameLowering::restoreCalleeSavedRegisters(
1143MachineBasicBlock &MBB,MachineBasicBlock::iteratorMBBI,
1144MutableArrayRef<CalleeSavedInfo> CSI,constTargetRegisterInfo *TRI) const{
1145
1146if (CSI.empty())
1147returnfalse;
1148
1149MachineFunction &MF = *MBB.getParent();
1150SystemZMachineFunctionInfo *ZFI = MF.getInfo<SystemZMachineFunctionInfo>();
1151constSystemZSubtarget &Subtarget = MF.getSubtarget<SystemZSubtarget>();
1152constTargetInstrInfo *TII = Subtarget.getInstrInfo();
1153auto &Regs = Subtarget.getSpecialRegisters<SystemZXPLINK64Registers>();
1154
1155DebugLocDL =MBBI !=MBB.end() ?MBBI->getDebugLoc() :DebugLoc();
1156
1157// Restore FPRs in the normal TargetInstrInfo way.
1158for (constCalleeSavedInfo &I : CSI) {
1159Register Reg =I.getReg();
1160if (SystemZ::FP64BitRegClass.contains(Reg))
1161TII->loadRegFromStackSlot(MBB,MBBI, Reg,I.getFrameIdx(),
1162 &SystemZ::FP64BitRegClass,TRI,Register());
1163if (SystemZ::VR128BitRegClass.contains(Reg))
1164TII->loadRegFromStackSlot(MBB,MBBI, Reg,I.getFrameIdx(),
1165 &SystemZ::VR128BitRegClass,TRI,Register());
1166 }
1167
1168// Restore call-saved GPRs (but not call-clobbered varargs, which at
1169// this point might hold return values).
1170SystemZ::GPRRegs RestoreGPRs = ZFI->getRestoreGPRRegs();
1171if (RestoreGPRs.LowGPR) {
1172assert(isInt<20>(Regs.getStackPointerBias() + RestoreGPRs.GPROffset));
1173if (RestoreGPRs.LowGPR == RestoreGPRs.HighGPR)
1174// Build an LG/L instruction.
1175BuildMI(MBB,MBBI,DL,TII->get(SystemZ::LG), RestoreGPRs.LowGPR)
1176 .addReg(Regs.getStackPointerRegister())
1177 .addImm(Regs.getStackPointerBias() + RestoreGPRs.GPROffset)
1178 .addReg(0);
1179else {
1180// Build an LMG/LM instruction.
1181MachineInstrBuilder MIB =BuildMI(MBB,MBBI,DL,TII->get(SystemZ::LMG));
1182
1183// Add the explicit register operands.
1184 MIB.addReg(RestoreGPRs.LowGPR,RegState::Define);
1185 MIB.addReg(RestoreGPRs.HighGPR,RegState::Define);
1186
1187// Add the address.
1188 MIB.addReg(Regs.getStackPointerRegister());
1189 MIB.addImm(Regs.getStackPointerBias() + RestoreGPRs.GPROffset);
1190
1191// Do a second scan adding regs as being defined by instruction
1192for (constCalleeSavedInfo &I : CSI) {
1193Register Reg =I.getReg();
1194if (Reg > RestoreGPRs.LowGPR && Reg < RestoreGPRs.HighGPR)
1195 MIB.addReg(Reg,RegState::ImplicitDefine);
1196 }
1197 }
1198 }
1199
1200returntrue;
1201}
1202
1203voidSystemZXPLINKFrameLowering::emitPrologue(MachineFunction &MF,
1204MachineBasicBlock &MBB) const{
1205assert(&MF.front() == &MBB &&"Shrink-wrapping not yet supported");
1206constSystemZSubtarget &Subtarget = MF.getSubtarget<SystemZSubtarget>();
1207SystemZMachineFunctionInfo *ZFI = MF.getInfo<SystemZMachineFunctionInfo>();
1208MachineBasicBlock::iteratorMBBI =MBB.begin();
1209auto *ZII =static_cast<constSystemZInstrInfo *>(Subtarget.getInstrInfo());
1210auto &Regs = Subtarget.getSpecialRegisters<SystemZXPLINK64Registers>();
1211MachineFrameInfo &MFFrame = MF.getFrameInfo();
1212MachineInstr *StoreInstr =nullptr;
1213
1214determineFrameLayout(MF);
1215
1216bool HasFP =hasFP(MF);
1217// Debug location must be unknown since the first debug location is used
1218// to determine the end of the prologue.
1219DebugLocDL;
1220uint64_tOffset = 0;
1221
1222constuint64_t StackSize = MFFrame.getStackSize();
1223
1224if (ZFI->getSpillGPRRegs().LowGPR) {
1225// Skip over the GPR saves.
1226if ((MBBI !=MBB.end()) && ((MBBI->getOpcode() == SystemZ::STMG))) {
1227constint Operand = 3;
1228// Now we can set the offset for the operation, since now the Stack
1229// has been finalized.
1230Offset = Regs.getStackPointerBias() +MBBI->getOperand(Operand).getImm();
1231// Maximum displacement for STMG instruction.
1232if (isInt<20>(Offset - StackSize))
1233Offset -= StackSize;
1234else
1235 StoreInstr = &*MBBI;
1236MBBI->getOperand(Operand).setImm(Offset);
1237 ++MBBI;
1238 }else
1239llvm_unreachable("Couldn't skip over GPR saves");
1240 }
1241
1242if (StackSize) {
1243MachineBasicBlock::iterator InsertPt = StoreInstr ? StoreInstr :MBBI;
1244// Allocate StackSize bytes.
1245 int64_t Delta = -int64_t(StackSize);
1246
1247// In case the STM(G) instruction also stores SP (R4), but the displacement
1248// is too large, the SP register is manipulated first before storing,
1249// resulting in the wrong value stored and retrieved later. In this case, we
1250// need to temporarily save the value of SP, and store it later to memory.
1251if (StoreInstr && HasFP) {
1252// Insert LR r0,r4 before STMG instruction.
1253BuildMI(MBB, InsertPt,DL, ZII->get(SystemZ::LGR))
1254 .addReg(SystemZ::R0D,RegState::Define)
1255 .addReg(SystemZ::R4D);
1256// Insert ST r0,xxx(,r4) after STMG instruction.
1257BuildMI(MBB,MBBI,DL, ZII->get(SystemZ::STG))
1258 .addReg(SystemZ::R0D,RegState::Kill)
1259 .addReg(SystemZ::R4D)
1260 .addImm(Offset)
1261 .addReg(0);
1262 }
1263
1264emitIncrement(MBB, InsertPt,DL, Regs.getStackPointerRegister(), Delta,
1265 ZII);
1266
1267// If the requested stack size is larger than the guard page, then we need
1268// to check if we need to call the stack extender. This requires adding a
1269// conditional branch, but splitting the prologue block is not possible at
1270// this point since it would invalidate the SaveBlocks / RestoreBlocks sets
1271// of PEI in the single block function case. Build a pseudo to be handled
1272// later by inlineStackProbe().
1273constuint64_t GuardPageSize = 1024 * 1024;
1274if (StackSize > GuardPageSize) {
1275assert(StoreInstr &&"Wrong insertion point");
1276BuildMI(MBB, InsertPt,DL, ZII->get(SystemZ::XPLINK_STACKALLOC));
1277 }
1278 }
1279
1280if (HasFP) {
1281// Copy the base of the frame to Frame Pointer Register.
1282BuildMI(MBB,MBBI,DL, ZII->get(SystemZ::LGR),
1283 Regs.getFramePointerRegister())
1284 .addReg(Regs.getStackPointerRegister());
1285
1286// Mark the FramePtr as live at the beginning of every block except
1287// the entry block. (We'll have marked R8 as live on entry when
1288// saving the GPRs.)
1289for (MachineBasicBlock &B :llvm::drop_begin(MF))
1290B.addLiveIn(Regs.getFramePointerRegister());
1291 }
1292
1293// Save GPRs used for varargs, if any.
1294constTargetInstrInfo *TII = Subtarget.getInstrInfo();
1295bool IsVarArg = MF.getFunction().isVarArg();
1296
1297if (IsVarArg) {
1298// FixedRegs is the number of used registers, accounting for shadow
1299// registers.
1300unsigned FixedRegs = ZFI->getVarArgsFirstGPR() + ZFI->getVarArgsFirstFPR();
1301auto &GPRs =SystemZ::XPLINK64ArgGPRs;
1302for (unsignedI = FixedRegs;I <SystemZ::XPLINK64NumArgGPRs;I++) {
1303uint64_t StartOffset = MFFrame.getOffsetAdjustment() +
1304 MFFrame.getStackSize() + Regs.getCallFrameSize() +
1305getOffsetOfLocalArea() +I *getPointerSize();
1306unsigned Reg = GPRs[I];
1307BuildMI(MBB,MBBI,DL,TII->get(SystemZ::STG))
1308 .addReg(Reg)
1309 .addReg(Regs.getStackPointerRegister())
1310 .addImm(StartOffset)
1311 .addReg(0);
1312if (!MBB.isLiveIn(Reg))
1313MBB.addLiveIn(Reg);
1314 }
1315 }
1316}
1317
1318voidSystemZXPLINKFrameLowering::emitEpilogue(MachineFunction &MF,
1319MachineBasicBlock &MBB) const{
1320constSystemZSubtarget &Subtarget = MF.getSubtarget<SystemZSubtarget>();
1321MachineBasicBlock::iteratorMBBI =MBB.getLastNonDebugInstr();
1322SystemZMachineFunctionInfo *ZFI = MF.getInfo<SystemZMachineFunctionInfo>();
1323MachineFrameInfo &MFFrame = MF.getFrameInfo();
1324auto *ZII =static_cast<constSystemZInstrInfo *>(Subtarget.getInstrInfo());
1325auto &Regs = Subtarget.getSpecialRegisters<SystemZXPLINK64Registers>();
1326
1327// Skip the return instruction.
1328assert(MBBI->isReturn() &&"Can only insert epilogue into returning blocks");
1329
1330uint64_t StackSize = MFFrame.getStackSize();
1331if (StackSize) {
1332unsignedSPReg = Regs.getStackPointerRegister();
1333if (ZFI->getRestoreGPRRegs().LowGPR !=SPReg) {
1334DebugLocDL =MBBI->getDebugLoc();
1335emitIncrement(MBB,MBBI,DL,SPReg, StackSize, ZII);
1336 }
1337 }
1338}
1339
1340// Emit a compare of the stack pointer against the stack floor, and a call to
1341// the LE stack extender if needed.
1342voidSystemZXPLINKFrameLowering::inlineStackProbe(
1343MachineFunction &MF,MachineBasicBlock &PrologMBB) const{
1344auto *ZII =
1345static_cast<constSystemZInstrInfo *>(MF.getSubtarget().getInstrInfo());
1346
1347MachineInstr *StackAllocMI =nullptr;
1348for (MachineInstr &MI : PrologMBB)
1349if (MI.getOpcode() == SystemZ::XPLINK_STACKALLOC) {
1350 StackAllocMI = &MI;
1351break;
1352 }
1353if (StackAllocMI ==nullptr)
1354return;
1355
1356bool NeedSaveSP =hasFP(MF);
1357bool NeedSaveArg = PrologMBB.isLiveIn(SystemZ::R3D);
1358const int64_t SaveSlotR3 = 2192;
1359
1360MachineBasicBlock &MBB = PrologMBB;
1361constDebugLocDL = StackAllocMI->getDebugLoc();
1362
1363// The 2nd half of block MBB after split.
1364MachineBasicBlock *NextMBB;
1365
1366// Add new basic block for the call to the stack overflow function.
1367MachineBasicBlock *StackExtMBB =
1368 MF.CreateMachineBasicBlock(MBB.getBasicBlock());
1369 MF.push_back(StackExtMBB);
1370
1371// LG r3,72(,r3)
1372BuildMI(StackExtMBB,DL, ZII->get(SystemZ::LG), SystemZ::R3D)
1373 .addReg(SystemZ::R3D)
1374 .addImm(72)
1375 .addReg(0);
1376// BASR r3,r3
1377BuildMI(StackExtMBB,DL, ZII->get(SystemZ::CallBASR_STACKEXT))
1378 .addReg(SystemZ::R3D);
1379if (NeedSaveArg) {
1380if (!NeedSaveSP) {
1381// LGR r0,r3
1382BuildMI(MBB, StackAllocMI,DL, ZII->get(SystemZ::LGR))
1383 .addReg(SystemZ::R0D,RegState::Define)
1384 .addReg(SystemZ::R3D);
1385 }else {
1386// In this case, the incoming value of r4 is saved in r0 so the
1387// latter register is unavailable. Store r3 in its corresponding
1388// slot in the parameter list instead. Do this at the start of
1389// the prolog before r4 is manipulated by anything else.
1390// STG r3, 2192(r4)
1391BuildMI(MBB,MBB.begin(),DL, ZII->get(SystemZ::STG))
1392 .addReg(SystemZ::R3D)
1393 .addReg(SystemZ::R4D)
1394 .addImm(SaveSlotR3)
1395 .addReg(0);
1396 }
1397 }
1398// LLGT r3,1208
1399BuildMI(MBB, StackAllocMI,DL, ZII->get(SystemZ::LLGT), SystemZ::R3D)
1400 .addReg(0)
1401 .addImm(1208)
1402 .addReg(0);
1403// CG r4,64(,r3)
1404BuildMI(MBB, StackAllocMI,DL, ZII->get(SystemZ::CG))
1405 .addReg(SystemZ::R4D)
1406 .addReg(SystemZ::R3D)
1407 .addImm(64)
1408 .addReg(0);
1409// JLL b'0100',F'37'
1410BuildMI(MBB, StackAllocMI,DL, ZII->get(SystemZ::BRC))
1411 .addImm(SystemZ::CCMASK_ICMP)
1412 .addImm(SystemZ::CCMASK_CMP_LT)
1413 .addMBB(StackExtMBB);
1414
1415 NextMBB =SystemZ::splitBlockBefore(StackAllocMI, &MBB);
1416MBB.addSuccessor(NextMBB);
1417MBB.addSuccessor(StackExtMBB);
1418if (NeedSaveArg) {
1419if (!NeedSaveSP) {
1420// LGR r3, r0
1421BuildMI(*NextMBB, StackAllocMI,DL, ZII->get(SystemZ::LGR))
1422 .addReg(SystemZ::R3D,RegState::Define)
1423 .addReg(SystemZ::R0D,RegState::Kill);
1424 }else {
1425// In this case, the incoming value of r4 is saved in r0 so the
1426// latter register is unavailable. We stored r3 in its corresponding
1427// slot in the parameter list instead and we now restore it from there.
1428// LGR r3, r0
1429BuildMI(*NextMBB, StackAllocMI,DL, ZII->get(SystemZ::LGR))
1430 .addReg(SystemZ::R3D,RegState::Define)
1431 .addReg(SystemZ::R0D);
1432// LG r3, 2192(r3)
1433BuildMI(*NextMBB, StackAllocMI,DL, ZII->get(SystemZ::LG))
1434 .addReg(SystemZ::R3D,RegState::Define)
1435 .addReg(SystemZ::R3D)
1436 .addImm(SaveSlotR3)
1437 .addReg(0);
1438 }
1439 }
1440
1441// Add jump back from stack extension BB.
1442BuildMI(StackExtMBB,DL, ZII->get(SystemZ::J)).addMBB(NextMBB);
1443 StackExtMBB->addSuccessor(NextMBB);
1444
1445 StackAllocMI->eraseFromParent();
1446
1447// Compute the live-in lists for the new blocks.
1448fullyRecomputeLiveIns({StackExtMBB, NextMBB});
1449}
1450
1451boolSystemZXPLINKFrameLowering::hasFPImpl(constMachineFunction &MF) const{
1452return (MF.getFrameInfo().hasVarSizedObjects());
1453}
1454
1455voidSystemZXPLINKFrameLowering::processFunctionBeforeFrameFinalized(
1456MachineFunction &MF,RegScavenger *RS) const{
1457MachineFrameInfo &MFFrame = MF.getFrameInfo();
1458constSystemZSubtarget &Subtarget = MF.getSubtarget<SystemZSubtarget>();
1459auto &Regs = Subtarget.getSpecialRegisters<SystemZXPLINK64Registers>();
1460
1461// Setup stack frame offset
1462 MFFrame.setOffsetAdjustment(Regs.getStackPointerBias());
1463
1464// Nothing to do for leaf functions.
1465uint64_t StackSize = MFFrame.estimateStackSize(MF);
1466if (StackSize == 0 && MFFrame.getCalleeSavedInfo().empty())
1467return;
1468
1469// Although the XPLINK specifications for AMODE64 state that minimum size
1470// of the param area is minimum 32 bytes and no rounding is otherwise
1471// specified, we round this area in 64 bytes increments to be compatible
1472// with existing compilers.
1473 MFFrame.setMaxCallFrameSize(
1474 std::max(64U, (unsigned)alignTo(MFFrame.getMaxCallFrameSize(), 64)));
1475
1476// Add frame values with positive object offsets. Since the displacement from
1477// the SP/FP is calculated by ObjectOffset + StackSize + Bias, object offsets
1478// with positive values are in the caller's stack frame. We need to include
1479// that since it is accessed by displacement to SP/FP.
1480 int64_t LargestArgOffset = 0;
1481for (intI = MFFrame.getObjectIndexBegin();I != 0; ++I) {
1482if (MFFrame.getObjectOffset(I) >= 0) {
1483 int64_t ObjOffset = MFFrame.getObjectOffset(I) + MFFrame.getObjectSize(I);
1484 LargestArgOffset = std::max(ObjOffset, LargestArgOffset);
1485 }
1486 }
1487
1488uint64_t MaxReach = (StackSize + Regs.getCallFrameSize() +
1489 Regs.getStackPointerBias() + LargestArgOffset);
1490
1491if (!isUInt<12>(MaxReach)) {
1492// We may need register scavenging slots if some parts of the frame
1493// are outside the reach of an unsigned 12-bit displacement.
1494 RS->addScavengingFrameIndex(MFFrame.CreateSpillStackObject(8,Align(8)));
1495 RS->addScavengingFrameIndex(MFFrame.CreateSpillStackObject(8,Align(8)));
1496 }
1497}
1498
1499// Determines the size of the frame, and creates the deferred spill objects.
1500voidSystemZXPLINKFrameLowering::determineFrameLayout(
1501MachineFunction &MF) const{
1502MachineFrameInfo &MFFrame = MF.getFrameInfo();
1503constSystemZSubtarget &Subtarget = MF.getSubtarget<SystemZSubtarget>();
1504auto *Regs =
1505static_cast<SystemZXPLINK64Registers *>(Subtarget.getSpecialRegisters());
1506
1507uint64_t StackSize = MFFrame.getStackSize();
1508if (StackSize == 0)
1509return;
1510
1511// Add the size of the register save area and the reserved area to the size.
1512 StackSize += Regs->getCallFrameSize();
1513 MFFrame.setStackSize(StackSize);
1514
1515// We now know the stack size. Update the stack objects for the register save
1516// area now. This has no impact on the stack frame layout, as this is already
1517// computed. However, it makes sure that all callee saved registers have a
1518// valid offset assigned.
1519for (int FrameIdx = MFFrame.getObjectIndexBegin(); FrameIdx != 0;
1520 ++FrameIdx) {
1521if (MFFrame.getStackID(FrameIdx) ==TargetStackID::NoAlloc) {
1522 int64_t SPOffset = MFFrame.getObjectOffset(FrameIdx);
1523 SPOffset -= StackSize;
1524 MFFrame.setObjectOffset(FrameIdx, SPOffset);
1525 }
1526 }
1527}
MRI
unsigned const MachineRegisterInfo * MRI
Definition:AArch64AdvSIMDScalarPass.cpp:105
RegSize
unsigned RegSize
Definition:AArch64MIPeepholeOpt.cpp:161
MBB
MachineBasicBlock & MBB
Definition:ARMSLSHardening.cpp:71
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition:ARMSLSHardening.cpp:73
MBBI
MachineBasicBlock MachineBasicBlock::iterator MBBI
Definition:ARMSLSHardening.cpp:72
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
A
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
Idx
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Definition:DeadArgumentElimination.cpp:353
Size
uint64_t Size
Definition:ELFObjHandler.cpp:81
TII
const HexagonInstrInfo * TII
Definition:HexagonCopyToCombine.cpp:125
MI
IRTranslator LLVM IR MI
Definition:IRTranslator.cpp:112
Function.h
LivePhysRegs.h
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
I
#define I(x, y, z)
Definition:MD5.cpp:58
MachineModuleInfo.h
MachineRegisterInfo.h
TRI
unsigned const TargetRegisterInfo * TRI
Definition:MachineSink.cpp:2029
SPReg
static constexpr Register SPReg
Definition:RISCVFrameLowering.cpp:108
RegisterScavenging.h
This file declares the machine register scavenger class.
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
contains
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition:Value.cpp:469
SystemZCallingConv.h
emitIncrement
static void emitIncrement(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, const DebugLoc &DL, Register Reg, int64_t NumBytes, const TargetInstrInfo *TII)
Definition:SystemZFrameLowering.cpp:475
buildDefCFAReg
static void buildDefCFAReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, unsigned Reg, const SystemZInstrInfo *ZII)
Definition:SystemZFrameLowering.cpp:514
buildCFAOffs
static void buildCFAOffs(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, int Offset, const SystemZInstrInfo *ZII)
Definition:SystemZFrameLowering.cpp:503
isXPLeafCandidate
static bool isXPLeafCandidate(const MachineFunction &MF)
Definition:SystemZFrameLowering.cpp:917
addSavedGPR
static void addSavedGPR(MachineBasicBlock &MBB, MachineInstrBuilder &MIB, unsigned GPR64, bool IsImplicit)
Definition:SystemZFrameLowering.cpp:300
SystemZFrameLowering.h
SystemZInstrInfo.h
SystemZMachineFunctionInfo.h
SystemZRegisterInfo.h
SystemZSubtarget.h
TargetLoweringObjectFileImpl.h
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition:ArrayRef.h:41
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition:ArrayRef.h:163
llvm::BitVector
Definition:BitVector.h:82
llvm::BitVector::test
bool test(unsigned Idx) const
Definition:BitVector.h:461
llvm::BitVector::set
BitVector & set()
Definition:BitVector.h:351
llvm::CalleeSavedInfo
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
Definition:MachineFrameInfo.h:34
llvm::DebugLoc
A debug info location.
Definition:DebugLoc.h:33
llvm::Function::getCallingConv
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition:Function.h:277
llvm::Function::isVarArg
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
Definition:Function.h:234
llvm::Function::hasFnAttribute
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition:Function.cpp:731
llvm::HexagonInstrInfo::storeRegToStackSlot
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, Register VReg, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
Store the specified register of the given register class to the specified stack frame index.
Definition:HexagonInstrInfo.cpp:962
llvm::HexagonInstrInfo::loadRegFromStackSlot
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register DestReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, Register VReg, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
Load the specified register of the given register class from the specified stack frame index.
Definition:HexagonInstrInfo.cpp:1011
llvm::IndexedMap::grow
void grow(IndexT n)
Definition:IndexedMap.h:69
llvm::MCCFIInstruction::createDefCfaRegister
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_def_cfa_register modifies a rule for computing CFA.
Definition:MCDwarf.h:582
llvm::MCCFIInstruction::createOffset
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.
Definition:MCDwarf.h:617
llvm::MCCFIInstruction::cfiDefCfaOffset
static MCCFIInstruction cfiDefCfaOffset(MCSymbol *L, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa_offset modifies a rule for computing CFA.
Definition:MCDwarf.h:590
llvm::MCContext::getRegisterInfo
const MCRegisterInfo * getRegisterInfo() const
Definition:MCContext.h:414
llvm::MCRegisterInfo
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Definition:MCRegisterInfo.h:149
llvm::MachineBasicBlock
Definition:MachineBasicBlock.h:125
llvm::MachineBasicBlock::getBasicBlock
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
Definition:MachineBasicBlock.h:256
llvm::MachineBasicBlock::addSuccessor
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
Definition:MachineBasicBlock.cpp:798
llvm::MachineBasicBlock::begin
iterator begin()
Definition:MachineBasicBlock.h:355
llvm::MachineBasicBlock::getLastNonDebugInstr
iterator getLastNonDebugInstr(bool SkipPseudoOp=true)
Returns an iterator to the last non-debug instruction in the basic block, or end().
Definition:MachineBasicBlock.cpp:273
llvm::MachineBasicBlock::end
iterator end()
Definition:MachineBasicBlock.h:357
llvm::MachineBasicBlock::addLiveIn
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
Definition:MachineBasicBlock.h:456
llvm::MachineBasicBlock::getParent
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
Definition:MachineBasicBlock.h:311
llvm::MachineBasicBlock::isLiveIn
bool isLiveIn(MCRegister Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
Definition:MachineBasicBlock.cpp:618
llvm::MachineFrameInfo
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Definition:MachineFrameInfo.h:106
llvm::MachineFrameInfo::setMaxCallFrameSize
void setMaxCallFrameSize(uint64_t S)
Definition:MachineFrameInfo.h:676
llvm::MachineFrameInfo::CreateFixedObject
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
Definition:MachineFrameInfo.cpp:83
llvm::MachineFrameInfo::hasVarSizedObjects
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
Definition:MachineFrameInfo.h:357
llvm::MachineFrameInfo::getStackSize
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
Definition:MachineFrameInfo.h:587
llvm::MachineFrameInfo::adjustsStack
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
Definition:MachineFrameInfo.h:617
llvm::MachineFrameInfo::CreateStackObject
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.
Definition:MachineFrameInfo.cpp:51
llvm::MachineFrameInfo::hasCalls
bool hasCalls() const
Return true if the current function has any function calls.
Definition:MachineFrameInfo.h:621
llvm::MachineFrameInfo::setObjectOffset
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
Definition:MachineFrameInfo.h:562
llvm::MachineFrameInfo::getMaxCallFrameSize
uint64_t getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call.
Definition:MachineFrameInfo.h:666
llvm::MachineFrameInfo::CreateSpillStackObject
int CreateSpillStackObject(uint64_t Size, Align Alignment)
Create a new statically sized stack object that represents a spill slot, returning a nonnegative iden...
Definition:MachineFrameInfo.cpp:66
llvm::MachineFrameInfo::estimateStackSize
uint64_t estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
Definition:MachineFrameInfo.cpp:137
llvm::MachineFrameInfo::setStackID
void setStackID(int ObjectIdx, uint8_t ID)
Definition:MachineFrameInfo.h:755
llvm::MachineFrameInfo::getObjectSize
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
Definition:MachineFrameInfo.h:472
llvm::MachineFrameInfo::getCalleeSavedInfo
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
Definition:MachineFrameInfo.h:806
llvm::MachineFrameInfo::getObjectIndexEnd
int getObjectIndexEnd() const
Return one past the maximum frame object index.
Definition:MachineFrameInfo.h:412
llvm::MachineFrameInfo::CreateFixedSpillStackObject
int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset, bool IsImmutable=false)
Create a spill slot at a fixed location on the stack.
Definition:MachineFrameInfo.cpp:102
llvm::MachineFrameInfo::getStackID
uint8_t getStackID(int ObjectIdx) const
Definition:MachineFrameInfo.h:750
llvm::MachineFrameInfo::getObjectOffset
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
Definition:MachineFrameInfo.h:528
llvm::MachineFrameInfo::setStackSize
void setStackSize(uint64_t Size)
Set the size of the stack.
Definition:MachineFrameInfo.h:590
llvm::MachineFrameInfo::getObjectIndexBegin
int getObjectIndexBegin() const
Return the minimum frame object index.
Definition:MachineFrameInfo.h:409
llvm::MachineFrameInfo::isDeadObjectIndex
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
Definition:MachineFrameInfo.h:764
llvm::MachineFrameInfo::setOffsetAdjustment
void setOffsetAdjustment(int64_t Adj)
Set the correction for frame offsets.
Definition:MachineFrameInfo.h:599
llvm::MachineFunction
Definition:MachineFunction.h:267
llvm::MachineFunction::addFrameInst
unsigned addFrameInst(const MCCFIInstruction &Inst)
Definition:MachineFunction.cpp:334
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition:MachineFunction.h:733
llvm::MachineFunction::getMachineMemOperand
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, LLT MemTy, Align base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
Definition:MachineFunction.cpp:536
llvm::MachineFunction::getFrameInfo
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Definition:MachineFunction.h:749
llvm::MachineFunction::push_back
void push_back(MachineBasicBlock *MBB)
Definition:MachineFunction.h:964
llvm::MachineFunction::getContext
MCContext & getContext() const
Definition:MachineFunction.h:690
llvm::MachineFunction::getRegInfo
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Definition:MachineFunction.h:743
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition:MachineFunction.h:704
llvm::MachineFunction::getLandingPads
const std::vector< LandingPadInfo > & getLandingPads() const
Return a reference to the landing pad info for the current function.
Definition:MachineFunction.h:1250
llvm::MachineFunction::getInfo
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Definition:MachineFunction.h:831
llvm::MachineFunction::front
const MachineBasicBlock & front() const
Definition:MachineFunction.h:959
llvm::MachineFunction::CreateMachineBasicBlock
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
Definition:MachineFunction.cpp:499
llvm::MachineFunction::getTarget
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Definition:MachineFunction.h:729
llvm::MachineInstrBuilder
Definition:MachineInstrBuilder.h:71
llvm::MachineInstrBuilder::addCFIIndex
const MachineInstrBuilder & addCFIIndex(unsigned CFIIndex) const
Definition:MachineInstrBuilder.h:249
llvm::MachineInstrBuilder::addImm
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Definition:MachineInstrBuilder.h:133
llvm::MachineInstrBuilder::addReg
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Definition:MachineInstrBuilder.h:99
llvm::MachineInstrBuilder::addMBB
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
Definition:MachineInstrBuilder.h:148
llvm::MachineInstrBuilder::addMemOperand
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
Definition:MachineInstrBuilder.h:204
llvm::MachineInstrBundleIterator< MachineInstr >
llvm::MachineInstr
Representation of each machine instruction.
Definition:MachineInstr.h:71
llvm::MachineInstr::getDebugLoc
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
Definition:MachineInstr.h:501
llvm::MachineInstr::eraseFromParent
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
Definition:MachineInstr.cpp:767
llvm::MachineInstr::getOperand
const MachineOperand & getOperand(unsigned i) const
Definition:MachineInstr.h:587
llvm::MachineMemOperand
A description of a memory reference used in the backend.
Definition:MachineMemOperand.h:129
llvm::MachineMemOperand::MOVolatile
@ MOVolatile
The memory access is volatile.
Definition:MachineMemOperand.h:140
llvm::MachineMemOperand::MOLoad
@ MOLoad
The memory access reads data.
Definition:MachineMemOperand.h:136
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition:MachineOperand.h:48
llvm::MachineOperand::getImm
int64_t getImm() const
Definition:MachineOperand.h:556
llvm::MachineOperand::getIndex
int getIndex() const
Definition:MachineOperand.h:576
llvm::MachineOperand::isFI
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
Definition:MachineOperand.h:339
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition:MachineRegisterInfo.h:51
llvm::MutableArrayRef
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition:ArrayRef.h:310
llvm::RegScavenger
Definition:RegisterScavenging.h:34
llvm::RegScavenger::addScavengingFrameIndex
void addScavengingFrameIndex(int FI)
Add a scavenging frame index.
Definition:RegisterScavenging.h:112
llvm::Register
Wrapper class representing virtual and physical registers.
Definition:Register.h:19
llvm::SmallVectorBase::size
size_t size() const
Definition:SmallVector.h:78
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition:SmallVector.h:573
llvm::SmallVectorTemplateBase::push_back
void push_back(const T &Elt)
Definition:SmallVector.h:413
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition:SmallVector.h:1196
llvm::StackOffset
StackOffset holds a fixed and a scalable offset in bytes.
Definition:TypeSize.h:33
llvm::StackOffset::getFixed
int64_t getFixed() const
Returns the fixed component of the stack.
Definition:TypeSize.h:49
llvm::StackOffset::getFixed
static StackOffset getFixed(int64_t Fixed)
Definition:TypeSize.h:42
llvm::SystemZELFFrameLowering::restoreCalleeSavedRegisters
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBII, MutableArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
Definition:SystemZFrameLowering.cpp:373
llvm::SystemZELFFrameLowering::getOrCreateFramePointerSaveIndex
int getOrCreateFramePointerSaveIndex(MachineFunction &MF) const override
Definition:SystemZFrameLowering.cpp:866
llvm::SystemZELFFrameLowering::orderFrameObjects
void orderFrameObjects(const MachineFunction &MF, SmallVectorImpl< int > &ObjectsToAllocate) const override
Order the symbols in the local stack frame.
Definition:SystemZFrameLowering.cpp:83
llvm::SystemZELFFrameLowering::assignCalleeSavedSpillSlots
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const override
Definition:SystemZFrameLowering.cpp:162
llvm::SystemZELFFrameLowering::getBackchainOffset
unsigned getBackchainOffset(MachineFunction &MF) const override
Definition:SystemZFrameLowering.h:103
llvm::SystemZELFFrameLowering::inlineStackProbe
void inlineStackProbe(MachineFunction &MF, MachineBasicBlock &PrologMBB) const override
Replace a StackProbe stub (if any) with the actual probe code inline.
Definition:SystemZFrameLowering.cpp:735
llvm::SystemZELFFrameLowering::hasFPImpl
bool hasFPImpl(const MachineFunction &MF) const override
Definition:SystemZFrameLowering.cpp:834
llvm::SystemZELFFrameLowering::emitPrologue
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
Definition:SystemZFrameLowering.cpp:527
llvm::SystemZELFFrameLowering::emitEpilogue
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
Definition:SystemZFrameLowering.cpp:689
llvm::SystemZELFFrameLowering::getFrameIndexReference
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...
Definition:SystemZFrameLowering.cpp:839
llvm::SystemZELFFrameLowering::usePackedStack
bool usePackedStack(MachineFunction &MF) const
Definition:SystemZFrameLowering.cpp:879
llvm::SystemZELFFrameLowering::determineCalleeSaves
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
Definition:SystemZFrameLowering.cpp:229
llvm::SystemZELFFrameLowering::spillCalleeSavedRegisters
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
Definition:SystemZFrameLowering.cpp:313
llvm::SystemZELFFrameLowering::SystemZELFFrameLowering
SystemZELFFrameLowering(unsigned PointerSize)
Definition:SystemZFrameLowering.cpp:278
llvm::SystemZELFFrameLowering::getRegSpillOffset
unsigned getRegSpillOffset(MachineFunction &MF, Register Reg) const
Definition:SystemZFrameLowering.cpp:848
llvm::SystemZELFFrameLowering::processFunctionBeforeFrameFinalized
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
Definition:SystemZFrameLowering.cpp:429
llvm::SystemZFrameLowering
Definition:SystemZFrameLowering.h:22
llvm::SystemZFrameLowering::hasReservedCallFrame
bool hasReservedCallFrame(const MachineFunction &MF) const override
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required,...
Definition:SystemZFrameLowering.cpp:152
llvm::SystemZFrameLowering::create
static std::unique_ptr< SystemZFrameLowering > create(const SystemZSubtarget &STI)
Definition:SystemZFrameLowering.cpp:63
llvm::SystemZFrameLowering::getPointerSize
unsigned getPointerSize() const
Definition:SystemZFrameLowering.h:55
llvm::SystemZFrameLowering::SystemZFrameLowering
SystemZFrameLowering(StackDirection D, Align StackAl, int LAO, Align TransAl, bool StackReal, unsigned PointerSize)
Definition:SystemZFrameLowering.cpp:56
llvm::SystemZInstrInfo
Definition:SystemZInstrInfo.h:185
llvm::SystemZMachineFunctionInfo
Definition:SystemZMachineFunctionInfo.h:27
llvm::SystemZMachineFunctionInfo::getVarArgsFirstGPR
Register getVarArgsFirstGPR() const
Definition:SystemZMachineFunctionInfo.h:82
llvm::SystemZMachineFunctionInfo::getFramePointerSaveIndex
int getFramePointerSaveIndex() const
Definition:SystemZMachineFunctionInfo.h:99
llvm::SystemZMachineFunctionInfo::getRestoreGPRRegs
SystemZ::GPRRegs getRestoreGPRRegs() const
Definition:SystemZMachineFunctionInfo.h:73
llvm::SystemZMachineFunctionInfo::setRestoreGPRRegs
void setRestoreGPRRegs(Register Low, Register High, unsigned Offs)
Definition:SystemZMachineFunctionInfo.h:74
llvm::SystemZMachineFunctionInfo::setFramePointerSaveIndex
void setFramePointerSaveIndex(int Idx)
Definition:SystemZMachineFunctionInfo.h:100
llvm::SystemZMachineFunctionInfo::getSpillGPRRegs
SystemZ::GPRRegs getSpillGPRRegs() const
Definition:SystemZMachineFunctionInfo.h:63
llvm::SystemZMachineFunctionInfo::setSpillGPRRegs
void setSpillGPRRegs(Register Low, Register High, unsigned Offs)
Definition:SystemZMachineFunctionInfo.h:64
llvm::SystemZSubtarget
Definition:SystemZSubtarget.h:33
llvm::SystemZSubtarget::getInstrInfo
const SystemZInstrInfo * getInstrInfo() const override
Definition:SystemZSubtarget.h:76
llvm::SystemZSubtarget::getTargetLowering
const SystemZTargetLowering * getTargetLowering() const override
Definition:SystemZSubtarget.h:80
llvm::SystemZSubtarget::isTargetXPLINK64
bool isTargetXPLINK64() const
Definition:SystemZSubtarget.h:123
llvm::SystemZSubtarget::getSpecialRegisters
SystemZCallingConventionRegisters * getSpecialRegisters() const
Definition:SystemZSubtarget.h:59
llvm::SystemZTargetLowering
Definition:SystemZISelLowering.h:412
llvm::SystemZXPLINK64Registers
XPLINK64 calling convention specific use registers Particular to z/OS when in 64 bit mode.
Definition:SystemZRegisterInfo.h:82
llvm::SystemZXPLINKFrameLowering::inlineStackProbe
void inlineStackProbe(MachineFunction &MF, MachineBasicBlock &PrologMBB) const override
Replace a StackProbe stub (if any) with the actual probe code inline.
Definition:SystemZFrameLowering.cpp:1342
llvm::SystemZXPLINKFrameLowering::restoreCalleeSavedRegisters
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBII, MutableArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
Definition:SystemZFrameLowering.cpp:1142
llvm::SystemZXPLINKFrameLowering::getOrCreateFramePointerSaveIndex
int getOrCreateFramePointerSaveIndex(MachineFunction &MF) const override
Definition:SystemZFrameLowering.cpp:903
llvm::SystemZXPLINKFrameLowering::emitEpilogue
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
Definition:SystemZFrameLowering.cpp:1318
llvm::SystemZXPLINKFrameLowering::emitPrologue
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
Definition:SystemZFrameLowering.cpp:1203
llvm::SystemZXPLINKFrameLowering::determineFrameLayout
void determineFrameLayout(MachineFunction &MF) const
Definition:SystemZFrameLowering.cpp:1500
llvm::SystemZXPLINKFrameLowering::SystemZXPLINKFrameLowering
SystemZXPLINKFrameLowering(unsigned PointerSize)
Definition:SystemZFrameLowering.cpp:890
llvm::SystemZXPLINKFrameLowering::hasFPImpl
bool hasFPImpl(const MachineFunction &MF) const override
Definition:SystemZFrameLowering.cpp:1451
llvm::SystemZXPLINKFrameLowering::spillCalleeSavedRegisters
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
Definition:SystemZFrameLowering.cpp:1081
llvm::SystemZXPLINKFrameLowering::processFunctionBeforeFrameFinalized
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
Definition:SystemZFrameLowering.cpp:1455
llvm::SystemZXPLINKFrameLowering::determineCalleeSaves
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
Definition:SystemZFrameLowering.cpp:1066
llvm::SystemZXPLINKFrameLowering::assignCalleeSavedSpillSlots
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const override
Definition:SystemZFrameLowering.cpp:964
llvm::TargetFrameLowering
Information about stack frame layout on the target.
Definition:TargetFrameLowering.h:45
llvm::TargetFrameLowering::hasFP
bool hasFP(const MachineFunction &MF) const
hasFP - Return true if the specified function should have a dedicated frame pointer register.
Definition:TargetFrameLowering.h:285
llvm::TargetFrameLowering::determineCalleeSaves
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
Definition:TargetFrameLoweringImpl.cpp:95
llvm::TargetFrameLowering::StackDirection
StackDirection
Definition:TargetFrameLowering.h:47
llvm::TargetFrameLowering::getOffsetOfLocalArea
int getOffsetOfLocalArea() const
getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on ent...
Definition:TargetFrameLowering.h:144
llvm::TargetFrameLowering::getStackAlign
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
Definition:TargetFrameLowering.h:105
llvm::TargetFrameLowering::getFrameIndexReference
virtual StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const
getFrameIndexReference - This method should return the base register and offset used to reference a f...
Definition:TargetFrameLoweringImpl.cpp:48
llvm::TargetInstrInfo
TargetInstrInfo - Interface to description of machine instruction set.
Definition:TargetInstrInfo.h:112
llvm::TargetLoweringBase::getTargetMachine
const TargetMachine & getTargetMachine() const
Definition:TargetLowering.h:364
llvm::TargetLoweringBase::hasInlineStackProbe
virtual bool hasInlineStackProbe(const MachineFunction &MF) const
Definition:TargetLowering.h:2099
llvm::TargetMachine::getPointerSize
unsigned getPointerSize(unsigned AS) const
Get the pointer size for this target.
Definition:TargetMachine.h:190
llvm::TargetMachine::Options
TargetOptions Options
Definition:TargetMachine.h:118
llvm::TargetOptions::DisableFramePointerElim
bool DisableFramePointerElim(const MachineFunction &MF) const
DisableFramePointerElim - This returns true if frame pointer elimination optimization should be disab...
Definition:TargetOptionsImpl.cpp:24
llvm::TargetRegisterClass
Definition:TargetRegisterInfo.h:44
llvm::TargetRegisterInfo
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Definition:TargetRegisterInfo.h:235
llvm::TargetRegisterInfo::getSubReg
MCRegister getSubReg(MCRegister Reg, unsigned Idx) const
Returns the physical register number of sub-register "Index" for physical register RegNo.
Definition:TargetRegisterInfo.h:1217
llvm::TargetSubtargetInfo::getRegisterInfo
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
Definition:TargetSubtargetInfo.h:129
llvm::TargetSubtargetInfo::getInstrInfo
virtual const TargetInstrInfo * getInstrInfo() const
Definition:TargetSubtargetInfo.h:97
llvm::TargetSubtargetInfo::getTargetLowering
virtual const TargetLowering * getTargetLowering() const
Definition:TargetSubtargetInfo.h:101
uint16_t
uint32_t
uint64_t
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition:ErrorHandling.h:143
TargetMachine.h
false
Definition:StackSlotColoring.cpp:193
llvm::CallingConv::GHC
@ GHC
Used by the Glasgow Haskell Compiler (GHC).
Definition:CallingConv.h:50
llvm::RegState::Define
@ Define
Register definition.
Definition:MachineInstrBuilder.h:46
llvm::RegState::ImplicitDefine
@ ImplicitDefine
Definition:MachineInstrBuilder.h:65
llvm::RegState::Kill
@ Kill
The last use of a register.
Definition:MachineInstrBuilder.h:50
llvm::RegState::Undef
@ Undef
Value of the register doesn't matter.
Definition:MachineInstrBuilder.h:54
llvm::SystemZII::Has20BitOffset
@ Has20BitOffset
Definition:SystemZInstrInfo.h:38
llvm::SystemZMC::ELFCallFrameSize
const int64_t ELFCallFrameSize
Definition:SystemZMCTargetDesc.h:31
llvm::SystemZMC::ELFCFAOffsetFromInitialSP
const int64_t ELFCFAOffsetFromInitialSP
Definition:SystemZMCTargetDesc.h:34
llvm::SystemZ::splitBlockBefore
MachineBasicBlock * splitBlockBefore(MachineBasicBlock::iterator MI, MachineBasicBlock *MBB)
Definition:SystemZInstrInfo.cpp:2185
llvm::SystemZ::CCMASK_CMP_GT
const unsigned CCMASK_CMP_GT
Definition:SystemZ.h:37
llvm::SystemZ::emitBlockAfter
MachineBasicBlock * emitBlockAfter(MachineBasicBlock *MBB)
Definition:SystemZInstrInfo.cpp:2169
llvm::SystemZ::CCMASK_ICMP
const unsigned CCMASK_ICMP
Definition:SystemZ.h:47
llvm::SystemZ::XPLINK64NumArgGPRs
const unsigned XPLINK64NumArgGPRs
Definition:SystemZCallingConv.h:25
llvm::SystemZ::ELFArgGPRs
const MCPhysReg ELFArgGPRs[ELFNumArgGPRs]
Definition:SystemZCallingConv.cpp:13
llvm::SystemZ::CCMASK_CMP_LT
const unsigned CCMASK_CMP_LT
Definition:SystemZ.h:36
llvm::SystemZ::ELFNumArgGPRs
const unsigned ELFNumArgGPRs
Definition:SystemZCallingConv.h:19
llvm::SystemZ::XPLINK64ArgGPRs
const MCPhysReg XPLINK64ArgGPRs[XPLINK64NumArgGPRs]
Definition:SystemZCallingConv.cpp:22
llvm::TargetStackID::NoAlloc
@ NoAlloc
Definition:TargetFrameLowering.h:34
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::drop_begin
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
Definition:STLExtras.h:329
llvm::Offset
@ Offset
Definition:DWP.cpp:480
llvm::BuildMI
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
Definition:MachineInstrBuilder.h:373
llvm::getImplRegState
unsigned getImplRegState(bool B)
Definition:MachineInstrBuilder.h:552
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition:Error.cpp:167
llvm::getKillRegState
unsigned getKillRegState(bool B)
Definition:MachineInstrBuilder.h:555
llvm::alignTo
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition:Alignment.h:155
llvm::fullyRecomputeLiveIns
void fullyRecomputeLiveIns(ArrayRef< MachineBasicBlock * > MBBs)
Convenience function for recomputing live-in's for a set of MBBs until the computation converges.
Definition:LivePhysRegs.h:215
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition:Alignment.h:39
llvm::MachinePointerInfo
This class contains a discriminated union of information about pointers in memory operands,...
Definition:MachineMemOperand.h:41
llvm::SystemZ::GPRRegs
Definition:SystemZMachineFunctionInfo.h:19
llvm::SystemZ::GPRRegs::LowGPR
unsigned LowGPR
Definition:SystemZMachineFunctionInfo.h:20
llvm::SystemZ::GPRRegs::HighGPR
unsigned HighGPR
Definition:SystemZMachineFunctionInfo.h:21
llvm::SystemZ::GPRRegs::GPROffset
unsigned GPROffset
Definition:SystemZMachineFunctionInfo.h:22
llvm::TargetFrameLowering::SpillSlot
Definition:TargetFrameLowering.h:53

Generated on Fri Jul 18 2025 14:36:18 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp