1 //===-- PPCFrameLowering.h - Define frame lowering for PowerPC --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
13 #ifndef POWERPC_FRAMEINFO_H
14 #define POWERPC_FRAMEINFO_H
17 #include "PPCSubtarget.h"
18 #include "llvm/ADT/STLExtras.h"
19 #include "llvm/Target/TargetFrameLowering.h"
20 #include "llvm/Target/TargetMachine.h"
25 class PPCFrameLowering: public TargetFrameLowering {
26 const PPCSubtarget &Subtarget;
29 PPCFrameLowering(const PPCSubtarget &sti)
30 : TargetFrameLowering(TargetFrameLowering::StackGrowsDown,
31 (sti.hasQPX() || sti.isBGQ()) ? 32 : 16, 0),
35 void determineFrameLayout(MachineFunction &MF) const;
37 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
39 void emitPrologue(MachineFunction &MF) const;
40 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
42 bool hasFP(const MachineFunction &MF) const;
43 bool needsFP(const MachineFunction &MF) const;
45 void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
46 RegScavenger *RS = NULL) const;
47 void processFunctionBeforeFrameFinalized(MachineFunction &MF) const;
49 bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
50 MachineBasicBlock::iterator MI,
51 const std::vector<CalleeSavedInfo> &CSI,
52 const TargetRegisterInfo *TRI) const;
54 void eliminateCallFramePseudoInstr(MachineFunction &MF,
55 MachineBasicBlock &MBB,
56 MachineBasicBlock::iterator I) const;
58 bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
59 MachineBasicBlock::iterator MI,
60 const std::vector<CalleeSavedInfo> &CSI,
61 const TargetRegisterInfo *TRI) const;
63 /// targetHandlesStackFrameRounding - Returns true if the target is
64 /// responsible for rounding up the stack frame (probably at emitPrologue
66 bool targetHandlesStackFrameRounding() const { return true; }
68 /// getReturnSaveOffset - Return the previous frame offset to save the
70 static unsigned getReturnSaveOffset(bool isPPC64, bool isDarwinABI) {
72 return isPPC64 ? 16 : 8;
74 return isPPC64 ? 16 : 4;
77 /// getFramePointerSaveOffset - Return the previous frame offset to save the
79 static unsigned getFramePointerSaveOffset(bool isPPC64, bool isDarwinABI) {
80 // For the Darwin ABI:
81 // We cannot use the TOC save slot (offset +20) in the PowerPC linkage area
82 // for saving the frame pointer (if needed.) While the published ABI has
83 // not used this slot since at least MacOSX 10.2, there is older code
84 // around that does use it, and that needs to continue to work.
86 return isPPC64 ? -8U : -4U;
88 // SVR4 ABI: First slot in the general register save area.
89 return isPPC64 ? -8U : -4U;
92 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
94 static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI) {
95 if (isDarwinABI || isPPC64)
96 return 6 * (isPPC64 ? 8 : 4);
102 /// getMinCallArgumentsSize - Return the size of the minium PowerPC ABI
104 static unsigned getMinCallArgumentsSize(bool isPPC64, bool isDarwinABI) {
105 // For the Darwin ABI / 64-bit SVR4 ABI:
106 // The prolog code of the callee may store up to 8 GPR argument registers to
107 // the stack, allowing va_start to index over them in memory if its varargs.
108 // Because we cannot tell if this is needed on the caller side, we have to
109 // conservatively assume that it is needed. As such, make sure we have at
110 // least enough stack space for the caller to store the 8 GPRs.
111 if (isDarwinABI || isPPC64)
112 return 8 * (isPPC64 ? 8 : 4);
115 // There is no default stack allocated for the 8 first GPR arguments.
119 /// getMinCallFrameSize - Return the minimum size a call frame can be using
121 static unsigned getMinCallFrameSize(bool isPPC64, bool isDarwinABI) {
122 // The call frame needs to be at least big enough for linkage and 8 args.
123 return getLinkageSize(isPPC64, isDarwinABI) +
124 getMinCallArgumentsSize(isPPC64, isDarwinABI);
127 // With the SVR4 ABI, callee-saved registers have fixed offsets on the stack.
129 getCalleeSavedSpillSlots(unsigned &NumEntries) const {
130 if (Subtarget.isDarwinABI()) {
132 if (Subtarget.isPPC64()) {
133 static const SpillSlot darwin64Offsets = {PPC::X31, -8};
134 return &darwin64Offsets;
136 static const SpillSlot darwinOffsets = {PPC::R31, -4};
137 return &darwinOffsets;
141 // Early exit if not using the SVR4 ABI.
142 if (!Subtarget.isSVR4ABI()) {
147 // Note that the offsets here overlap, but this is fixed up in
148 // processFunctionBeforeFrameFinalized.
150 static const SpillSlot Offsets[] = {
151 // Floating-point register save area offsets.
171 // General register save area offsets.
191 // CR save area offset. We map each of the nonvolatile CR fields
192 // to the slot for CR2, which is the first of the nonvolatile CR
193 // fields to be assigned, so that we only allocate one save slot.
194 // See PPCRegisterInfo::hasReservedSpillSlot() for more information.
197 // VRSAVE save area offset.
200 // Vector register save area
215 static const SpillSlot Offsets64[] = {
216 // Floating-point register save area offsets.
236 // General register save area offsets.
256 // VRSAVE save area offset.
259 // Vector register save area
274 if (Subtarget.isPPC64()) {
275 NumEntries = array_lengthof(Offsets64);
279 NumEntries = array_lengthof(Offsets);
286 } // End llvm namespace