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;
29 PPCFrameLowering(const PPCSubtarget &STI);
31 unsigned determineFrameLayout(MachineFunction &MF,
33 bool UseEstimate = false) const;
35 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
37 void emitPrologue(MachineFunction &MF) const override;
38 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
40 bool hasFP(const MachineFunction &MF) const override;
41 bool needsFP(const MachineFunction &MF) const;
42 void replaceFPWithRealFP(MachineFunction &MF) const;
44 void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
45 RegScavenger *RS = nullptr) const override;
46 void processFunctionBeforeFrameFinalized(MachineFunction &MF,
47 RegScavenger *RS = nullptr) const override;
48 void addScavengingSpillSlot(MachineFunction &MF, RegScavenger *RS) const;
50 bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
51 MachineBasicBlock::iterator MI,
52 const std::vector<CalleeSavedInfo> &CSI,
53 const TargetRegisterInfo *TRI) const override;
55 void eliminateCallFramePseudoInstr(MachineFunction &MF,
56 MachineBasicBlock &MBB,
57 MachineBasicBlock::iterator I) const override;
59 bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
60 MachineBasicBlock::iterator MI,
61 const std::vector<CalleeSavedInfo> &CSI,
62 const TargetRegisterInfo *TRI) const override;
64 /// targetHandlesStackFrameRounding - Returns true if the target is
65 /// responsible for rounding up the stack frame (probably at emitPrologue
67 bool targetHandlesStackFrameRounding() const override { return true; }
69 /// getReturnSaveOffset - Return the previous frame offset to save the
71 unsigned getReturnSaveOffset() const { return ReturnSaveOffset; }
73 /// getTOCSaveOffset - Return the previous frame offset to save the
74 /// TOC register -- 64-bit SVR4 ABI only.
75 static unsigned getTOCSaveOffset(bool isELFv2ABI) {
76 return isELFv2ABI ? 24 : 40;
79 /// getFramePointerSaveOffset - Return the previous frame offset to save the
81 static unsigned getFramePointerSaveOffset(bool isPPC64, bool isDarwinABI) {
82 // For the Darwin ABI:
83 // We cannot use the TOC save slot (offset +20) in the PowerPC linkage area
84 // for saving the frame pointer (if needed.) While the published ABI has
85 // not used this slot since at least MacOSX 10.2, there is older code
86 // around that does use it, and that needs to continue to work.
88 return isPPC64 ? -8U : -4U;
90 // SVR4 ABI: First slot in the general register save area.
91 return isPPC64 ? -8U : -4U;
94 /// getBasePointerSaveOffset - Return the previous frame offset to save the
96 static unsigned getBasePointerSaveOffset(bool isPPC64,
100 return isPPC64 ? -16U : -8U;
102 // SVR4 ABI: First slot in the general register save area.
103 return isPPC64 ? -16U : isPIC ? -12U : -8U;
106 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
108 static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI,
110 if (isDarwinABI || isPPC64)
111 return (isELFv2ABI ? 4 : 6) * (isPPC64 ? 8 : 4);
118 getCalleeSavedSpillSlots(unsigned &NumEntries) const override;
120 } // End llvm namespace