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;
28 const unsigned FramePointerSaveOffset;
31 PPCFrameLowering(const PPCSubtarget &STI);
33 unsigned determineFrameLayout(MachineFunction &MF,
35 bool UseEstimate = false) const;
37 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
39 void emitPrologue(MachineFunction &MF) const override;
40 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
42 bool hasFP(const MachineFunction &MF) const override;
43 bool needsFP(const MachineFunction &MF) const;
44 void replaceFPWithRealFP(MachineFunction &MF) const;
46 void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
47 RegScavenger *RS = nullptr) const override;
48 void processFunctionBeforeFrameFinalized(MachineFunction &MF,
49 RegScavenger *RS = nullptr) const override;
50 void addScavengingSpillSlot(MachineFunction &MF, RegScavenger *RS) const;
52 bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
53 MachineBasicBlock::iterator MI,
54 const std::vector<CalleeSavedInfo> &CSI,
55 const TargetRegisterInfo *TRI) const override;
57 void eliminateCallFramePseudoInstr(MachineFunction &MF,
58 MachineBasicBlock &MBB,
59 MachineBasicBlock::iterator I) const override;
61 bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
62 MachineBasicBlock::iterator MI,
63 const std::vector<CalleeSavedInfo> &CSI,
64 const TargetRegisterInfo *TRI) const override;
66 /// targetHandlesStackFrameRounding - Returns true if the target is
67 /// responsible for rounding up the stack frame (probably at emitPrologue
69 bool targetHandlesStackFrameRounding() const override { return true; }
71 /// getReturnSaveOffset - Return the previous frame offset to save the
73 unsigned getReturnSaveOffset() const { return ReturnSaveOffset; }
75 /// getTOCSaveOffset - Return the previous frame offset to save the
76 /// TOC register -- 64-bit SVR4 ABI only.
77 unsigned getTOCSaveOffset() const { return TOCSaveOffset; }
79 /// getFramePointerSaveOffset - Return the previous frame offset to save the
81 unsigned getFramePointerSaveOffset() const { return FramePointerSaveOffset; }
83 /// getBasePointerSaveOffset - Return the previous frame offset to save the
85 static unsigned getBasePointerSaveOffset(bool isPPC64,
89 return isPPC64 ? -16U : -8U;
91 // SVR4 ABI: First slot in the general register save area.
92 return isPPC64 ? -16U : isPIC ? -12U : -8U;
95 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
97 static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI,
99 if (isDarwinABI || isPPC64)
100 return (isELFv2ABI ? 4 : 6) * (isPPC64 ? 8 : 4);
107 getCalleeSavedSpillSlots(unsigned &NumEntries) const override;
109 } // End llvm namespace