blob: c5ff1baac444837ba9707567a24a444f5bf14cb2 [file] [log] [blame]
Akira Hatanaka0bf3dfb2011-04-15 21:00:26 +00001//===-- MipsMachineFunctionInfo.h - Private data used for Mips ---*- C++ -*-=//
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +00007//
Akira Hatanaka0bf3dfb2011-04-15 21:00:26 +00008//===---------------------------------------------------------------------===//
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +00009//
10// This file declares the Mips specific subclass of MachineFunctionInfo.
11//
Akira Hatanaka0bf3dfb2011-04-15 21:00:26 +000012//===---------------------------------------------------------------------===//
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000013
14#ifndef MIPS_MACHINE_FUNCTION_INFO_H
15#define MIPS_MACHINE_FUNCTION_INFO_H
16
Dan Gohmand68a0762009-01-05 17:59:02 +000017#include "llvm/ADT/SmallVector.h"
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000018#include "llvm/ADT/VectorExtras.h"
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000019#include "llvm/CodeGen/MachineFunction.h"
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000020#include "llvm/CodeGen/MachineFrameInfo.h"
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000021
22namespace llvm {
23
24/// MipsFunctionInfo - This class is derived from MachineFunction private
25/// Mips target-specific information for each MachineFunction.
26class MipsFunctionInfo : public MachineFunctionInfo {
27
28private:
Che-Liang Chiouacf1d482010-09-28 10:06:53 +000029 /// Holds for each function where on the stack the Frame Pointer must be
Bruno Cardoso Lopesbbe51362008-08-06 06:14:43 +000030 /// saved. This is used on Prologue and Epilogue to emit FP save/restore
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000031 int FPStackOffset;
32
Che-Liang Chiouacf1d482010-09-28 10:06:53 +000033 /// Holds for each function where on the stack the Return Address must be
Bruno Cardoso Lopesbbe51362008-08-06 06:14:43 +000034 /// saved. This is used on Prologue and Epilogue to emit RA save/restore
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000035 int RAStackOffset;
36
Bruno Cardoso Lopesbbe51362008-08-06 06:14:43 +000037 /// 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;
43
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000044 /// MipsFIHolder - Holds a FrameIndex and it's Stack Pointer Offset
45 struct MipsFIHolder {
46
47 int FI;
48 int SPOffset;
49
50 MipsFIHolder(int FrameIndex, int StackPointerOffset)
51 : FI(FrameIndex), SPOffset(StackPointerOffset) {}
52 };
53
Che-Liang Chiouacf1d482010-09-28 10:06:53 +000054 /// 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
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000057 /// to be used on emitPrologue and processFunctionBeforeFrameFinalized.
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000058 MipsFIHolder GPHolder;
59
Dan Gohman98ca4f22009-08-05 01:29:28 +000060 /// On LowerFormalArguments the stack size is unknown, so the Stack
Che-Liang Chiouacf1d482010-09-28 10:06:53 +000061 /// Pointer Offset calculation of "not in register arguments" must be
62 /// postponed to emitPrologue.
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000063 SmallVector<MipsFIHolder, 16> FnLoadArgs;
64 bool HasLoadArgs;
65
Che-Liang Chiouacf1d482010-09-28 10:06:53 +000066 // When VarArgs, we must write registers back to caller stack, preserving
67 // on register arguments. Since the stack size is unknown on
Dan Gohman98ca4f22009-08-05 01:29:28 +000068 // LowerFormalArguments, the Stack Pointer Offset calculation must be
Che-Liang Chiouacf1d482010-09-28 10:06:53 +000069 // postponed to emitPrologue.
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000070 SmallVector<MipsFIHolder, 4> FnStoreVarArgs;
71 bool HasStoreVarArgs;
72
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000073 /// 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;
77
Dan Gohman99114052009-06-03 20:30:14 +000078 /// GlobalBaseReg - keeps track of the virtual register initialized for
79 /// use as the global base register. This is used for PIC in some PIC
80 /// relocation models.
81 unsigned GlobalBaseReg;
82
Dan Gohman1e93df62010-04-17 14:41:14 +000083 /// VarArgsFrameIndex - FrameIndex for start of varargs area.
84 int VarArgsFrameIndex;
85
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000086public:
Che-Liang Chiouacf1d482010-09-28 10:06:53 +000087 MipsFunctionInfo(MachineFunction& MF)
88 : FPStackOffset(0), RAStackOffset(0), CPUTopSavedRegOff(0),
89 FPUTopSavedRegOff(0), GPHolder(-1,-1), HasLoadArgs(false),
Dan Gohman1e93df62010-04-17 14:41:14 +000090 HasStoreVarArgs(false), SRetReturnReg(0), GlobalBaseReg(0),
91 VarArgsFrameIndex(0)
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000092 {}
93
94 int getFPStackOffset() const { return FPStackOffset; }
95 void setFPStackOffset(int Off) { FPStackOffset = Off; }
96
97 int getRAStackOffset() const { return RAStackOffset; }
98 void setRAStackOffset(int Off) { RAStackOffset = Off; }
99
Bruno Cardoso Lopesbbe51362008-08-06 06:14:43 +0000100 int getCPUTopSavedRegOff() const { return CPUTopSavedRegOff; }
101 void setCPUTopSavedRegOff(int Off) { CPUTopSavedRegOff = Off; }
102
103 int getFPUTopSavedRegOff() const { return FPUTopSavedRegOff; }
104 void setFPUTopSavedRegOff(int Off) { FPUTopSavedRegOff = Off; }
105
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000106 int getGPStackOffset() const { return GPHolder.SPOffset; }
107 int getGPFI() const { return GPHolder.FI; }
108 void setGPStackOffset(int Off) { GPHolder.SPOffset = Off; }
109 void setGPFI(int FI) { GPHolder.FI = FI; }
Bruno Cardoso Lopesb8e0ebf2009-11-09 14:27:49 +0000110 bool needGPSaveRestore() const { return GPHolder.SPOffset != -1; }
Bruno Cardoso Lopes0a604002007-10-09 03:01:19 +0000111
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000112 bool hasLoadArgs() const { return HasLoadArgs; }
Che-Liang Chiouacf1d482010-09-28 10:06:53 +0000113 bool hasStoreVarArgs() const { return HasStoreVarArgs; }
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000114
115 void recordLoadArgsFI(int FI, int SPOffset) {
116 if (!HasLoadArgs) HasLoadArgs=true;
117 FnLoadArgs.push_back(MipsFIHolder(FI, SPOffset));
118 }
119 void recordStoreVarArgsFI(int FI, int SPOffset) {
120 if (!HasStoreVarArgs) HasStoreVarArgs=true;
121 FnStoreVarArgs.push_back(MipsFIHolder(FI, SPOffset));
122 }
123
124 void adjustLoadArgsFI(MachineFrameInfo *MFI) const {
125 if (!hasLoadArgs()) return;
Che-Liang Chiouacf1d482010-09-28 10:06:53 +0000126 for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i)
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000127 MFI->setObjectOffset( FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset );
128 }
129 void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const {
Che-Liang Chiouacf1d482010-09-28 10:06:53 +0000130 if (!hasStoreVarArgs()) return;
131 for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i)
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000132 MFI->setObjectOffset( FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset );
133 }
134
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000135 unsigned getSRetReturnReg() const { return SRetReturnReg; }
136 void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
Dan Gohman99114052009-06-03 20:30:14 +0000137
138 unsigned getGlobalBaseReg() const { return GlobalBaseReg; }
139 void setGlobalBaseReg(unsigned Reg) { GlobalBaseReg = Reg; }
Dan Gohman1e93df62010-04-17 14:41:14 +0000140
141 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
142 void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +0000143};
144
145} // end of namespace llvm
146
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000147#endif // MIPS_MACHINE_FUNCTION_INFO_H