Update comments.
[llvm/msp430.git] / lib / Target / Mips / MipsMachineFunction.h
blobb95394ec81cea41d4bcf77a982c0057b6e8fa69a
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.
12 //===----------------------------------------------------------------------===//
14 #ifndef MIPS_MACHINE_FUNCTION_INFO_H
15 #define MIPS_MACHINE_FUNCTION_INFO_H
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/ADT/VectorExtras.h"
19 #include "llvm/CodeGen/MachineFunction.h"
20 #include "llvm/CodeGen/MachineFrameInfo.h"
22 namespace llvm {
24 /// MipsFunctionInfo - This class is derived from MachineFunction private
25 /// Mips target-specific information for each MachineFunction.
26 class MipsFunctionInfo : public MachineFunctionInfo {
28 private:
29 /// Holds for each function where on the stack the Frame Pointer must be
30 /// saved. This is used on Prologue and Epilogue to emit FP save/restore
31 int FPStackOffset;
33 /// Holds for each function where on the stack the Return Address must be
34 /// saved. This is used on Prologue and Epilogue to emit RA save/restore
35 int RAStackOffset;
37 /// At each function entry, two special bitmask directives must be emitted
38 /// to help debugging, for CPU and FPU callee saved registers. Both need
39 /// the negative offset from the final stack size and its higher registers
40 /// location on the stack.
41 int CPUTopSavedRegOff;
42 int FPUTopSavedRegOff;
44 /// MipsFIHolder - Holds a FrameIndex and it's Stack Pointer Offset
45 struct MipsFIHolder {
47 int FI;
48 int SPOffset;
50 MipsFIHolder(int FrameIndex, int StackPointerOffset)
51 : FI(FrameIndex), SPOffset(StackPointerOffset) {}
54 /// When PIC is used the GP must be saved on the stack on the function
55 /// prologue and must be reloaded from this stack location after every
56 /// call. A reference to its stack location and frame index must be kept
57 /// to be used on emitPrologue and processFunctionBeforeFrameFinalized.
58 MipsFIHolder GPHolder;
60 /// On LowerFORMAL_ARGUMENTS the stack size is unknown, so the Stack
61 /// Pointer Offset calculation of "not in register arguments" must be
62 /// postponed to emitPrologue.
63 SmallVector<MipsFIHolder, 16> FnLoadArgs;
64 bool HasLoadArgs;
66 // When VarArgs, we must write registers back to caller stack, preserving
67 // on register arguments. Since the stack size is unknown on
68 // LowerFORMAL_ARGUMENTS, the Stack Pointer Offset calculation must be
69 // postponed to emitPrologue.
70 SmallVector<MipsFIHolder, 4> FnStoreVarArgs;
71 bool HasStoreVarArgs;
73 /// SRetReturnReg - Some subtargets require that sret lowering includes
74 /// returning the value of the returned struct in a register. This field
75 /// holds the virtual register into which the sret argument is passed.
76 unsigned SRetReturnReg;
78 public:
79 MipsFunctionInfo(MachineFunction& MF)
80 : FPStackOffset(0), RAStackOffset(0), CPUTopSavedRegOff(0),
81 FPUTopSavedRegOff(0), GPHolder(-1,-1), HasLoadArgs(false),
82 HasStoreVarArgs(false), SRetReturnReg(0)
85 int getFPStackOffset() const { return FPStackOffset; }
86 void setFPStackOffset(int Off) { FPStackOffset = Off; }
88 int getRAStackOffset() const { return RAStackOffset; }
89 void setRAStackOffset(int Off) { RAStackOffset = Off; }
91 int getCPUTopSavedRegOff() const { return CPUTopSavedRegOff; }
92 void setCPUTopSavedRegOff(int Off) { CPUTopSavedRegOff = Off; }
94 int getFPUTopSavedRegOff() const { return FPUTopSavedRegOff; }
95 void setFPUTopSavedRegOff(int Off) { FPUTopSavedRegOff = Off; }
97 int getGPStackOffset() const { return GPHolder.SPOffset; }
98 int getGPFI() const { return GPHolder.FI; }
99 void setGPStackOffset(int Off) { GPHolder.SPOffset = Off; }
100 void setGPFI(int FI) { GPHolder.FI = FI; }
102 bool hasLoadArgs() const { return HasLoadArgs; }
103 bool hasStoreVarArgs() const { return HasStoreVarArgs; }
105 void recordLoadArgsFI(int FI, int SPOffset) {
106 if (!HasLoadArgs) HasLoadArgs=true;
107 FnLoadArgs.push_back(MipsFIHolder(FI, SPOffset));
109 void recordStoreVarArgsFI(int FI, int SPOffset) {
110 if (!HasStoreVarArgs) HasStoreVarArgs=true;
111 FnStoreVarArgs.push_back(MipsFIHolder(FI, SPOffset));
114 void adjustLoadArgsFI(MachineFrameInfo *MFI) const {
115 if (!hasLoadArgs()) return;
116 for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i)
117 MFI->setObjectOffset( FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset );
119 void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const {
120 if (!hasStoreVarArgs()) return;
121 for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i)
122 MFI->setObjectOffset( FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset );
125 unsigned getSRetReturnReg() const { return SRetReturnReg; }
126 void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
129 } // end of namespace llvm
131 #endif // MIPS_MACHINE_FUNCTION_INFO_H