PPCFrameLowering.h revision cd81d94322a39503e4a3e87b6ee03d4fcb3465fb
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 POWERPC_FRAMEINFO_H
14#define POWERPC_FRAMEINFO_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
21namespace llvm {
22class PPCSubtarget;
23
24class PPCFrameLowering: public TargetFrameLowering {
25  const PPCSubtarget &Subtarget;
26
27public:
28  PPCFrameLowering(const PPCSubtarget &STI);
29
30  unsigned determineFrameLayout(MachineFunction &MF,
31                                bool UpdateMF = true,
32                                bool UseEstimate = false) const;
33
34  /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
35  /// the function.
36  void emitPrologue(MachineFunction &MF) const override;
37  void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
38
39  bool hasFP(const MachineFunction &MF) const override;
40  bool needsFP(const MachineFunction &MF) const;
41  void replaceFPWithRealFP(MachineFunction &MF) const;
42
43  void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
44                                     RegScavenger *RS = nullptr) const override;
45  void processFunctionBeforeFrameFinalized(MachineFunction &MF,
46                                     RegScavenger *RS = nullptr) const override;
47  void addScavengingSpillSlot(MachineFunction &MF, RegScavenger *RS) const;
48
49  bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
50                                 MachineBasicBlock::iterator MI,
51                                 const std::vector<CalleeSavedInfo> &CSI,
52                                 const TargetRegisterInfo *TRI) const override;
53
54  void eliminateCallFramePseudoInstr(MachineFunction &MF,
55                                  MachineBasicBlock &MBB,
56                                  MachineBasicBlock::iterator I) const override;
57
58  bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
59                                  MachineBasicBlock::iterator MI,
60                                  const std::vector<CalleeSavedInfo> &CSI,
61                                  const TargetRegisterInfo *TRI) const override;
62
63  /// targetHandlesStackFrameRounding - Returns true if the target is
64  /// responsible for rounding up the stack frame (probably at emitPrologue
65  /// time).
66  bool targetHandlesStackFrameRounding() const override { return true; }
67
68  /// getReturnSaveOffset - Return the previous frame offset to save the
69  /// return address.
70  static unsigned getReturnSaveOffset(bool isPPC64, bool isDarwinABI) {
71    if (isDarwinABI)
72      return isPPC64 ? 16 : 8;
73    // SVR4 ABI:
74    return isPPC64 ? 16 : 4;
75  }
76
77  /// getTOCSaveOffset - Return the previous frame offset to save the
78  /// TOC register -- 64-bit SVR4 ABI only.
79  static unsigned getTOCSaveOffset(void) {
80    return 40;
81  }
82
83  /// getFramePointerSaveOffset - Return the previous frame offset to save the
84  /// frame pointer.
85  static unsigned getFramePointerSaveOffset(bool isPPC64, bool isDarwinABI) {
86    // For the Darwin ABI:
87    // We cannot use the TOC save slot (offset +20) in the PowerPC linkage area
88    // for saving the frame pointer (if needed.)  While the published ABI has
89    // not used this slot since at least MacOSX 10.2, there is older code
90    // around that does use it, and that needs to continue to work.
91    if (isDarwinABI)
92      return isPPC64 ? -8U : -4U;
93
94    // SVR4 ABI: First slot in the general register save area.
95    return isPPC64 ? -8U : -4U;
96  }
97
98  /// getBasePointerSaveOffset - Return the previous frame offset to save the
99  /// base pointer.
100  static unsigned getBasePointerSaveOffset(bool isPPC64, bool isDarwinABI) {
101    if (isDarwinABI)
102      return isPPC64 ? -16U : -8U;
103
104    // SVR4 ABI: First slot in the general register save area.
105    return isPPC64 ? -16U : -8U;
106  }
107
108  /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
109  ///
110  static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI) {
111    if (isDarwinABI || isPPC64)
112      return 6 * (isPPC64 ? 8 : 4);
113
114    // SVR4 ABI:
115    return 8;
116  }
117
118  const SpillSlot *
119  getCalleeSavedSpillSlots(unsigned &NumEntries) const override;
120};
121} // End llvm namespace
122
123#endif
124