32053a186ff320082c8a2fe339e10f38e8f806c6
[oota-llvm.git] / lib / Target / PowerPC / PPCFrameLowering.h
1 //===-- PPCFrameLowering.h - Define frame lowering for PowerPC --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_LIB_TARGET_POWERPC_PPCFRAMELOWERING_H
14 #define LLVM_LIB_TARGET_POWERPC_PPCFRAMELOWERING_H
15
16 #include "PPC.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/Target/TargetFrameLowering.h"
19 #include "llvm/Target/TargetMachine.h"
20
21 namespace llvm {
22 class PPCSubtarget;
23
24 class PPCFrameLowering: public TargetFrameLowering {
25   const PPCSubtarget &Subtarget;
26   const unsigned ReturnSaveOffset;
27
28 public:
29   PPCFrameLowering(const PPCSubtarget &STI);
30
31   unsigned determineFrameLayout(MachineFunction &MF,
32                                 bool UpdateMF = true,
33                                 bool UseEstimate = false) const;
34
35   /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
36   /// the function.
37   void emitPrologue(MachineFunction &MF) const override;
38   void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
39
40   bool hasFP(const MachineFunction &MF) const override;
41   bool needsFP(const MachineFunction &MF) const;
42   void replaceFPWithRealFP(MachineFunction &MF) const;
43
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;
49
50   bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
51                                  MachineBasicBlock::iterator MI,
52                                  const std::vector<CalleeSavedInfo> &CSI,
53                                  const TargetRegisterInfo *TRI) const override;
54
55   void eliminateCallFramePseudoInstr(MachineFunction &MF,
56                                   MachineBasicBlock &MBB,
57                                   MachineBasicBlock::iterator I) const override;
58
59   bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
60                                   MachineBasicBlock::iterator MI,
61                                   const std::vector<CalleeSavedInfo> &CSI,
62                                   const TargetRegisterInfo *TRI) const override;
63
64   /// targetHandlesStackFrameRounding - Returns true if the target is
65   /// responsible for rounding up the stack frame (probably at emitPrologue
66   /// time).
67   bool targetHandlesStackFrameRounding() const override { return true; }
68
69   /// getReturnSaveOffset - Return the previous frame offset to save the
70   /// return address.
71   unsigned getReturnSaveOffset() const { return ReturnSaveOffset; }
72
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;
77   }
78
79   /// getFramePointerSaveOffset - Return the previous frame offset to save the
80   /// frame pointer.
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.
87     if (isDarwinABI)
88       return isPPC64 ? -8U : -4U;
89
90     // SVR4 ABI: First slot in the general register save area.
91     return isPPC64 ? -8U : -4U;
92   }
93
94   /// getBasePointerSaveOffset - Return the previous frame offset to save the
95   /// base pointer.
96   static unsigned getBasePointerSaveOffset(bool isPPC64,
97                                            bool isDarwinABI,
98                                            bool isPIC) {
99     if (isDarwinABI)
100       return isPPC64 ? -16U : -8U;
101
102     // SVR4 ABI: First slot in the general register save area.
103     return isPPC64 ? -16U : isPIC ? -12U : -8U;
104   }
105
106   /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
107   ///
108   static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI,
109                                  bool isELFv2ABI) {
110     if (isDarwinABI || isPPC64)
111       return (isELFv2ABI ? 4 : 6) * (isPPC64 ? 8 : 4);
112
113     // SVR4 ABI:
114     return 8;
115   }
116
117   const SpillSlot *
118   getCalleeSavedSpillSlots(unsigned &NumEntries) const override;
119 };
120 } // End llvm namespace
121
122 #endif