1 //===-- MipsMachineFunctionInfo.h - Private data used for Mips ----*- C++ -*-=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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/VectorExtras.h"
18 #include "llvm/CodeGen/MachineFunction.h"
19 #include "llvm/CodeGen/MachineFrameInfo.h"
23 /// MipsFunctionInfo - This class is derived from MachineFunction private
24 /// Mips target-specific information for each MachineFunction.
25 class MipsFunctionInfo : public MachineFunctionInfo {
28 /// Holds for each function where on the stack the Frame Pointer must be
29 /// saved. This is used on Prologue and Epilogue to emit FP save/restore
32 /// Holds for each function where on the stack the Return Address must be
33 /// saved. This is used on Prologue and Epilogue to emit RA save/restore
36 /// At each function entry, two special bitmask directives must be emitted
37 /// to help debugging, for CPU and FPU callee saved registers. Both need
38 /// the negative offset from the final stack size and its higher registers
39 /// location on the stack.
40 int CPUTopSavedRegOff;
41 int FPUTopSavedRegOff;
43 /// MipsFIHolder - Holds a FrameIndex and it's Stack Pointer Offset
49 MipsFIHolder(int FrameIndex, int StackPointerOffset)
50 : FI(FrameIndex), SPOffset(StackPointerOffset) {}
53 /// When PIC is used the GP must be saved on the stack on the function
54 /// prologue and must be reloaded from this stack location after every
55 /// call. A reference to its stack location and frame index must be kept
56 /// to be used on emitPrologue and processFunctionBeforeFrameFinalized.
57 MipsFIHolder GPHolder;
59 /// On LowerFORMAL_ARGUMENTS the stack size is unknown, so the Stack
60 /// Pointer Offset calculation of "not in register arguments" must be
61 /// postponed to emitPrologue.
62 SmallVector<MipsFIHolder, 16> FnLoadArgs;
65 // When VarArgs, we must write registers back to caller stack, preserving
66 // on register arguments. Since the stack size is unknown on
67 // LowerFORMAL_ARGUMENTS, the Stack Pointer Offset calculation must be
68 // postponed to emitPrologue.
69 SmallVector<MipsFIHolder, 4> FnStoreVarArgs;
72 /// SRetReturnReg - Some subtargets require that sret lowering includes
73 /// returning the value of the returned struct in a register. This field
74 /// holds the virtual register into which the sret argument is passed.
75 unsigned SRetReturnReg;
78 MipsFunctionInfo(MachineFunction& MF)
79 : FPStackOffset(0), RAStackOffset(0), CPUTopSavedRegOff(0),
80 FPUTopSavedRegOff(0), GPHolder(-1,-1), HasLoadArgs(false),
81 HasStoreVarArgs(false), SRetReturnReg(0)
84 int getFPStackOffset() const { return FPStackOffset; }
85 void setFPStackOffset(int Off) { FPStackOffset = Off; }
87 int getRAStackOffset() const { return RAStackOffset; }
88 void setRAStackOffset(int Off) { RAStackOffset = Off; }
90 int getCPUTopSavedRegOff() const { return CPUTopSavedRegOff; }
91 void setCPUTopSavedRegOff(int Off) { CPUTopSavedRegOff = Off; }
93 int getFPUTopSavedRegOff() const { return FPUTopSavedRegOff; }
94 void setFPUTopSavedRegOff(int Off) { FPUTopSavedRegOff = Off; }
96 int getGPStackOffset() const { return GPHolder.SPOffset; }
97 int getGPFI() const { return GPHolder.FI; }
98 void setGPStackOffset(int Off) { GPHolder.SPOffset = Off; }
99 void setGPFI(int FI) { GPHolder.FI = FI; }
101 bool hasLoadArgs() const { return HasLoadArgs; }
102 bool hasStoreVarArgs() const { return HasStoreVarArgs; }
104 void recordLoadArgsFI(int FI, int SPOffset) {
105 if (!HasLoadArgs) HasLoadArgs=true;
106 FnLoadArgs.push_back(MipsFIHolder(FI, SPOffset));
108 void recordStoreVarArgsFI(int FI, int SPOffset) {
109 if (!HasStoreVarArgs) HasStoreVarArgs=true;
110 FnStoreVarArgs.push_back(MipsFIHolder(FI, SPOffset));
113 void adjustLoadArgsFI(MachineFrameInfo *MFI) const {
114 if (!hasLoadArgs()) return;
115 for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i)
116 MFI->setObjectOffset( FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset );
118 void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const {
119 if (!hasStoreVarArgs()) return;
120 for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i)
121 MFI->setObjectOffset( FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset );
124 unsigned getSRetReturnReg() const { return SRetReturnReg; }
125 void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
128 } // end of namespace llvm
130 #endif // MIPS_MACHINE_FUNCTION_INFO_H