MipsMachineFunction.h revision 225ca9cdd70de3d12641b0aba7daf6cb568a7ebd
1//===-- MipsMachineFunctionInfo.h - Private data used for Mips ----*- 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// This file declares the Mips specific subclass of MachineFunctionInfo.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef MIPS_MACHINE_FUNCTION_INFO_H
15#define MIPS_MACHINE_FUNCTION_INFO_H
16
17#include "llvm/ADT/VectorExtras.h"
18#include "llvm/CodeGen/MachineFunction.h"
19#include "llvm/CodeGen/MachineFrameInfo.h"
20
21namespace llvm {
22
23/// MipsFunctionInfo - This class is derived from MachineFunction private
24/// Mips target-specific information for each MachineFunction.
25class MipsFunctionInfo : public MachineFunctionInfo {
26
27private:
28  /// Holds for each function where on the stack the Frame Pointer must be
29  /// saved.
30  int FPStackOffset;
31
32  /// Holds for each function where on the stack the Return Address must be
33  /// saved.
34  int RAStackOffset;
35
36  /// MipsFIHolder - Holds a FrameIndex and it's Stack Pointer Offset
37  struct MipsFIHolder {
38
39    int FI;
40    int SPOffset;
41
42    MipsFIHolder(int FrameIndex, int StackPointerOffset)
43      : FI(FrameIndex), SPOffset(StackPointerOffset) {}
44  };
45
46  /// When PIC is used the GP must be saved on the stack on the function
47  /// prologue and must be reloaded from this stack location after every
48  /// call. A reference to its stack location and frame index must be kept
49  /// to be used on emitPrologue and processFunctionBeforeFrameFinalized.
50  MipsFIHolder GPHolder;
51
52  // On LowerFORMAL_ARGUMENTS the stack size is unknown, so the Stack
53  // Pointer Offset calculation of "not in register arguments" must be
54  // postponed to emitPrologue.
55  SmallVector<MipsFIHolder, 16> FnLoadArgs;
56  bool HasLoadArgs;
57
58  // When VarArgs, we must write registers back to caller stack, preserving
59  // on register arguments. Since the stack size is unknown on
60  // LowerFORMAL_ARGUMENTS, the Stack Pointer Offset calculation must be
61  // postponed to emitPrologue.
62  SmallVector<MipsFIHolder, 4> FnStoreVarArgs;
63  bool HasStoreVarArgs;
64
65  /// SRetReturnReg - Some subtargets require that sret lowering includes
66  /// returning the value of the returned struct in a register. This field
67  /// holds the virtual register into which the sret argument is passed.
68  unsigned SRetReturnReg;
69
70public:
71  MipsFunctionInfo(MachineFunction& MF)
72  : FPStackOffset(0), RAStackOffset(0), GPHolder(-1,-1), HasLoadArgs(false),
73    HasStoreVarArgs(false), SRetReturnReg(0)
74  {}
75
76  int getFPStackOffset() const { return FPStackOffset; }
77  void setFPStackOffset(int Off) { FPStackOffset = Off; }
78
79  int getRAStackOffset() const { return RAStackOffset; }
80  void setRAStackOffset(int Off) { RAStackOffset = Off; }
81
82  int getGPStackOffset() const { return GPHolder.SPOffset; }
83  int getGPFI() const { return GPHolder.FI; }
84  void setGPStackOffset(int Off) { GPHolder.SPOffset = Off; }
85  void setGPFI(int FI) { GPHolder.FI = FI; }
86
87  int getTopSavedRegOffset() const {
88    return (RAStackOffset > FPStackOffset) ?
89           (RAStackOffset) : (FPStackOffset);
90  }
91
92  bool hasLoadArgs() const { return HasLoadArgs; }
93  bool hasStoreVarArgs() const { return HasStoreVarArgs; }
94
95  void recordLoadArgsFI(int FI, int SPOffset) {
96    if (!HasLoadArgs) HasLoadArgs=true;
97    FnLoadArgs.push_back(MipsFIHolder(FI, SPOffset));
98  }
99  void recordStoreVarArgsFI(int FI, int SPOffset) {
100    if (!HasStoreVarArgs) HasStoreVarArgs=true;
101    FnStoreVarArgs.push_back(MipsFIHolder(FI, SPOffset));
102  }
103
104  void adjustLoadArgsFI(MachineFrameInfo *MFI) const {
105    if (!hasLoadArgs()) return;
106    for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i)
107      MFI->setObjectOffset( FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset );
108  }
109  void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const {
110    if (!hasStoreVarArgs()) return;
111    for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i)
112      MFI->setObjectOffset( FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset );
113  }
114
115  unsigned getSRetReturnReg() const { return SRetReturnReg; }
116  void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
117};
118
119} // end of namespace llvm
120
121#endif // MIPS_MACHINE_FUNCTION_INFO_H
122