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;
26 const unsigned ReturnSaveOffset;
27 const unsigned TOCSaveOffset;
30 PPCFrameLowering(const PPCSubtarget &STI);
32 unsigned determineFrameLayout(MachineFunction &MF,
34 bool UseEstimate = false) const;
36 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
38 void emitPrologue(MachineFunction &MF) const override;
39 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
41 bool hasFP(const MachineFunction &MF) const override;
42 bool needsFP(const MachineFunction &MF) const;
43 void replaceFPWithRealFP(MachineFunction &MF) const;
45 void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
46 RegScavenger *RS = nullptr) const override;
47 void processFunctionBeforeFrameFinalized(MachineFunction &MF,
48 RegScavenger *RS = nullptr) const override;
49 void addScavengingSpillSlot(MachineFunction &MF, RegScavenger *RS) const;
51 bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
52 MachineBasicBlock::iterator MI,
53 const std::vector<CalleeSavedInfo> &CSI,
54 const TargetRegisterInfo *TRI) const override;
56 void eliminateCallFramePseudoInstr(MachineFunction &MF,
57 MachineBasicBlock &MBB,
58 MachineBasicBlock::iterator I) const override;
60 bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
61 MachineBasicBlock::iterator MI,
62 const std::vector<CalleeSavedInfo> &CSI,
63 const TargetRegisterInfo *TRI) const override;
65 /// targetHandlesStackFrameRounding - Returns true if the target is
66 /// responsible for rounding up the stack frame (probably at emitPrologue
68 bool targetHandlesStackFrameRounding() const override { return true; }
70 /// getReturnSaveOffset - Return the previous frame offset to save the
72 unsigned getReturnSaveOffset() const { return ReturnSaveOffset; }
74 /// getTOCSaveOffset - Return the previous frame offset to save the
75 /// TOC register -- 64-bit SVR4 ABI only.
76 unsigned getTOCSaveOffset() const { return TOCSaveOffset; }
78 /// getFramePointerSaveOffset - Return the previous frame offset to save the
80 static unsigned getFramePointerSaveOffset(bool isPPC64, bool isDarwinABI) {
81 // For the Darwin ABI:
82 // We cannot use the TOC save slot (offset +20) in the PowerPC linkage area
83 // for saving the frame pointer (if needed.) While the published ABI has
84 // not used this slot since at least MacOSX 10.2, there is older code
85 // around that does use it, and that needs to continue to work.
87 return isPPC64 ? -8U : -4U;
89 // SVR4 ABI: First slot in the general register save area.
90 return isPPC64 ? -8U : -4U;
93 /// getBasePointerSaveOffset - Return the previous frame offset to save the
95 static unsigned getBasePointerSaveOffset(bool isPPC64,
99 return isPPC64 ? -16U : -8U;
101 // SVR4 ABI: First slot in the general register save area.
102 return isPPC64 ? -16U : isPIC ? -12U : -8U;
105 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
107 static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI,
109 if (isDarwinABI || isPPC64)
110 return (isELFv2ABI ? 4 : 6) * (isPPC64 ? 8 : 4);
117 getCalleeSavedSpillSlots(unsigned &NumEntries) const override;
119 } // End llvm namespace