The TOC save offset can be computed at compile time, do so and
[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   const unsigned TOCSaveOffset;
28
29 public:
30   PPCFrameLowering(const PPCSubtarget &STI);
31
32   unsigned determineFrameLayout(MachineFunction &MF,
33                                 bool UpdateMF = true,
34                                 bool UseEstimate = false) const;
35
36   /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
37   /// the function.
38   void emitPrologue(MachineFunction &MF) const override;
39   void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
40
41   bool hasFP(const MachineFunction &MF) const override;
42   bool needsFP(const MachineFunction &MF) const;
43   void replaceFPWithRealFP(MachineFunction &MF) const;
44
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;
50
51   bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
52                                  MachineBasicBlock::iterator MI,
53                                  const std::vector<CalleeSavedInfo> &CSI,
54                                  const TargetRegisterInfo *TRI) const override;
55
56   void eliminateCallFramePseudoInstr(MachineFunction &MF,
57                                   MachineBasicBlock &MBB,
58                                   MachineBasicBlock::iterator I) const override;
59
60   bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
61                                   MachineBasicBlock::iterator MI,
62                                   const std::vector<CalleeSavedInfo> &CSI,
63                                   const TargetRegisterInfo *TRI) const override;
64
65   /// targetHandlesStackFrameRounding - Returns true if the target is
66   /// responsible for rounding up the stack frame (probably at emitPrologue
67   /// time).
68   bool targetHandlesStackFrameRounding() const override { return true; }
69
70   /// getReturnSaveOffset - Return the previous frame offset to save the
71   /// return address.
72   unsigned getReturnSaveOffset() const { return ReturnSaveOffset; }
73
74   /// getTOCSaveOffset - Return the previous frame offset to save the
75   /// TOC register -- 64-bit SVR4 ABI only.
76   unsigned getTOCSaveOffset() const { return TOCSaveOffset; }
77
78   /// getFramePointerSaveOffset - Return the previous frame offset to save the
79   /// frame pointer.
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.
86     if (isDarwinABI)
87       return isPPC64 ? -8U : -4U;
88
89     // SVR4 ABI: First slot in the general register save area.
90     return isPPC64 ? -8U : -4U;
91   }
92
93   /// getBasePointerSaveOffset - Return the previous frame offset to save the
94   /// base pointer.
95   static unsigned getBasePointerSaveOffset(bool isPPC64,
96                                            bool isDarwinABI,
97                                            bool isPIC) {
98     if (isDarwinABI)
99       return isPPC64 ? -16U : -8U;
100
101     // SVR4 ABI: First slot in the general register save area.
102     return isPPC64 ? -16U : isPIC ? -12U : -8U;
103   }
104
105   /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
106   ///
107   static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI,
108                                  bool isELFv2ABI) {
109     if (isDarwinABI || isPPC64)
110       return (isELFv2ABI ? 4 : 6) * (isPPC64 ? 8 : 4);
111
112     // SVR4 ABI:
113     return 8;
114   }
115
116   const SpillSlot *
117   getCalleeSavedSpillSlots(unsigned &NumEntries) const override;
118 };
119 } // End llvm namespace
120
121 #endif