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