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 LLVM_LIB_TARGET_POWERPC_PPCFRAMELOWERING_H
14 #define LLVM_LIB_TARGET_POWERPC_PPCFRAMELOWERING_H
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/Target/TargetFrameLowering.h"
19 #include "llvm/Target/TargetMachine.h"
24 class PPCFrameLowering: public TargetFrameLowering {
25 const PPCSubtarget &Subtarget;
28 PPCFrameLowering(const PPCSubtarget &STI);
30 unsigned determineFrameLayout(MachineFunction &MF,
32 bool UseEstimate = false) const;
34 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
36 void emitPrologue(MachineFunction &MF) const override;
37 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
39 bool hasFP(const MachineFunction &MF) const override;
40 bool needsFP(const MachineFunction &MF) const;
41 void replaceFPWithRealFP(MachineFunction &MF) const;
43 void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
44 RegScavenger *RS = nullptr) const override;
45 void processFunctionBeforeFrameFinalized(MachineFunction &MF,
46 RegScavenger *RS = nullptr) const override;
47 void addScavengingSpillSlot(MachineFunction &MF, RegScavenger *RS) const;
49 bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
50 MachineBasicBlock::iterator MI,
51 const std::vector<CalleeSavedInfo> &CSI,
52 const TargetRegisterInfo *TRI) const override;
54 void eliminateCallFramePseudoInstr(MachineFunction &MF,
55 MachineBasicBlock &MBB,
56 MachineBasicBlock::iterator I) const override;
58 bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
59 MachineBasicBlock::iterator MI,
60 const std::vector<CalleeSavedInfo> &CSI,
61 const TargetRegisterInfo *TRI) const override;
63 /// targetHandlesStackFrameRounding - Returns true if the target is
64 /// responsible for rounding up the stack frame (probably at emitPrologue
66 bool targetHandlesStackFrameRounding() const override { 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 /// getTOCSaveOffset - Return the previous frame offset to save the
78 /// TOC register -- 64-bit SVR4 ABI only.
79 static unsigned getTOCSaveOffset(bool isELFv2ABI) {
80 return isELFv2ABI ? 24 : 40;
83 /// getFramePointerSaveOffset - Return the previous frame offset to save the
85 static unsigned getFramePointerSaveOffset(bool isPPC64, bool isDarwinABI) {
86 // For the Darwin ABI:
87 // We cannot use the TOC save slot (offset +20) in the PowerPC linkage area
88 // for saving the frame pointer (if needed.) While the published ABI has
89 // not used this slot since at least MacOSX 10.2, there is older code
90 // around that does use it, and that needs to continue to work.
92 return isPPC64 ? -8U : -4U;
94 // SVR4 ABI: First slot in the general register save area.
95 return isPPC64 ? -8U : -4U;
98 /// getBasePointerSaveOffset - Return the previous frame offset to save the
100 static unsigned getBasePointerSaveOffset(bool isPPC64,
104 return isPPC64 ? -16U : -8U;
106 // SVR4 ABI: First slot in the general register save area.
107 return isPPC64 ? -16U : isPIC ? -12U : -8U;
110 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
112 static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI,
114 if (isDarwinABI || isPPC64)
115 return (isELFv2ABI ? 4 : 6) * (isPPC64 ? 8 : 4);
122 getCalleeSavedSpillSlots(unsigned &NumEntries) const override;
124 } // End llvm namespace