blob: bbb14a54e19bef4248831b7861ced97a84612430 [file] [log] [blame]
Akira Hatanaka4552c9a2011-04-15 21:51:11 +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 Hatanaka4552c9a2011-04-15 21:51:11 +00008//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +00009//
10// This file declares the Mips specific subclass of MachineFunctionInfo.
11//
Akira Hatanaka4552c9a2011-04-15 21:51:11 +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
Akira Hatanakada0a3572011-05-20 01:17:58 +000017#include <utility>
Dan Gohmand68a0762009-01-05 17:59:02 +000018#include "llvm/ADT/SmallVector.h"
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000019#include "llvm/ADT/VectorExtras.h"
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000020#include "llvm/CodeGen/MachineFunction.h"
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000021#include "llvm/CodeGen/MachineFrameInfo.h"
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000022
23namespace llvm {
24
25/// MipsFunctionInfo - This class is derived from MachineFunction private
26/// Mips target-specific information for each MachineFunction.
27class MipsFunctionInfo : public MachineFunctionInfo {
28
29private:
Che-Liang Chiouacf1d482010-09-28 10:06:53 +000030 /// Holds for each function where on the stack the Frame Pointer must be
Bruno Cardoso Lopesbbe51362008-08-06 06:14:43 +000031 /// saved. This is used on Prologue and Epilogue to emit FP save/restore
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000032 int FPStackOffset;
33
Che-Liang Chiouacf1d482010-09-28 10:06:53 +000034 /// Holds for each function where on the stack the Return Address must be
Bruno Cardoso Lopesbbe51362008-08-06 06:14:43 +000035 /// saved. This is used on Prologue and Epilogue to emit RA save/restore
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000036 int RAStackOffset;
37
Bruno Cardoso Lopesbbe51362008-08-06 06:14:43 +000038 /// At each function entry, two special bitmask directives must be emitted
39 /// to help debugging, for CPU and FPU callee saved registers. Both need
40 /// the negative offset from the final stack size and its higher registers
41 /// location on the stack.
42 int CPUTopSavedRegOff;
43 int FPUTopSavedRegOff;
44
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000045 /// MipsFIHolder - Holds a FrameIndex and it's Stack Pointer Offset
46 struct MipsFIHolder {
47
48 int FI;
49 int SPOffset;
50
51 MipsFIHolder(int FrameIndex, int StackPointerOffset)
52 : FI(FrameIndex), SPOffset(StackPointerOffset) {}
53 };
54
Che-Liang Chiouacf1d482010-09-28 10:06:53 +000055 /// When PIC is used the GP must be saved on the stack on the function
56 /// prologue and must be reloaded from this stack location after every
57 /// call. A reference to its stack location and frame index must be kept
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000058 /// to be used on emitPrologue and processFunctionBeforeFrameFinalized.
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000059 MipsFIHolder GPHolder;
60
Dan Gohman98ca4f22009-08-05 01:29:28 +000061 /// On LowerFormalArguments the stack size is unknown, so the Stack
Che-Liang Chiouacf1d482010-09-28 10:06:53 +000062 /// Pointer Offset calculation of "not in register arguments" must be
63 /// postponed to emitPrologue.
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000064 SmallVector<MipsFIHolder, 16> FnLoadArgs;
65 bool HasLoadArgs;
66
Che-Liang Chiouacf1d482010-09-28 10:06:53 +000067 // When VarArgs, we must write registers back to caller stack, preserving
68 // on register arguments. Since the stack size is unknown on
Dan Gohman98ca4f22009-08-05 01:29:28 +000069 // LowerFormalArguments, the Stack Pointer Offset calculation must be
Che-Liang Chiouacf1d482010-09-28 10:06:53 +000070 // postponed to emitPrologue.
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000071 SmallVector<MipsFIHolder, 4> FnStoreVarArgs;
72 bool HasStoreVarArgs;
73
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000074 /// SRetReturnReg - Some subtargets require that sret lowering includes
75 /// returning the value of the returned struct in a register. This field
76 /// holds the virtual register into which the sret argument is passed.
77 unsigned SRetReturnReg;
78
Dan Gohman99114052009-06-03 20:30:14 +000079 /// GlobalBaseReg - keeps track of the virtual register initialized for
80 /// use as the global base register. This is used for PIC in some PIC
81 /// relocation models.
82 unsigned GlobalBaseReg;
83
Dan Gohman1e93df62010-04-17 14:41:14 +000084 /// VarArgsFrameIndex - FrameIndex for start of varargs area.
85 int VarArgsFrameIndex;
86
Akira Hatanakada0a3572011-05-20 01:17:58 +000087 // Range of frame object indices.
88 // InArgFIRange: Range of indices of all frame objects created during call to
89 // LowerFormalArguments.
90 // OutArgFIRange: Range of indices of all frame objects created during call to
91 // LowerCall except for the frame object for restoring $gp.
92 std::pair<int, int> InArgFIRange, OutArgFIRange;
93 int GPFI; // Index of the frame object for restoring $gp
94 bool HasCall; // True if function has a function call.
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000095public:
Che-Liang Chiouacf1d482010-09-28 10:06:53 +000096 MipsFunctionInfo(MachineFunction& MF)
97 : FPStackOffset(0), RAStackOffset(0), CPUTopSavedRegOff(0),
98 FPUTopSavedRegOff(0), GPHolder(-1,-1), HasLoadArgs(false),
Dan Gohman1e93df62010-04-17 14:41:14 +000099 HasStoreVarArgs(false), SRetReturnReg(0), GlobalBaseReg(0),
Akira Hatanakada0a3572011-05-20 01:17:58 +0000100 VarArgsFrameIndex(0), InArgFIRange(std::make_pair(-1, 0)),
101 OutArgFIRange(std::make_pair(-1, 0)), GPFI(0), HasCall(false)
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +0000102 {}
103
104 int getFPStackOffset() const { return FPStackOffset; }
105 void setFPStackOffset(int Off) { FPStackOffset = Off; }
106
107 int getRAStackOffset() const { return RAStackOffset; }
108 void setRAStackOffset(int Off) { RAStackOffset = Off; }
109
Bruno Cardoso Lopesbbe51362008-08-06 06:14:43 +0000110 int getCPUTopSavedRegOff() const { return CPUTopSavedRegOff; }
111 void setCPUTopSavedRegOff(int Off) { CPUTopSavedRegOff = Off; }
112
113 int getFPUTopSavedRegOff() const { return FPUTopSavedRegOff; }
114 void setFPUTopSavedRegOff(int Off) { FPUTopSavedRegOff = Off; }
115
Akira Hatanakada0a3572011-05-20 01:17:58 +0000116 bool isInArgFI(int FI) const {
117 return FI <= InArgFIRange.first && FI >= InArgFIRange.second;
118 }
119 void setLastInArgFI(int FI) { InArgFIRange.second = FI; }
120
121 bool isOutArgFI(int FI) const {
122 return FI <= OutArgFIRange.first && FI >= OutArgFIRange.second;
123 }
124 void extendOutArgFIRange(int FirstFI, int LastFI) {
125 if (!OutArgFIRange.second)
126 // this must be the first time this function was called.
127 OutArgFIRange.first = FirstFI;
128 OutArgFIRange.second = LastFI;
129 }
130
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000131 int getGPStackOffset() const { return GPHolder.SPOffset; }
132 int getGPFI() const { return GPHolder.FI; }
133 void setGPStackOffset(int Off) { GPHolder.SPOffset = Off; }
134 void setGPFI(int FI) { GPHolder.FI = FI; }
Bruno Cardoso Lopesb8e0ebf2009-11-09 14:27:49 +0000135 bool needGPSaveRestore() const { return GPHolder.SPOffset != -1; }
Akira Hatanakada0a3572011-05-20 01:17:58 +0000136 bool isGPFI(int FI) const { return GPFI && GPFI == FI; }
Bruno Cardoso Lopes0a604002007-10-09 03:01:19 +0000137
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000138 bool hasLoadArgs() const { return HasLoadArgs; }
Che-Liang Chiouacf1d482010-09-28 10:06:53 +0000139 bool hasStoreVarArgs() const { return HasStoreVarArgs; }
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000140
141 void recordLoadArgsFI(int FI, int SPOffset) {
142 if (!HasLoadArgs) HasLoadArgs=true;
143 FnLoadArgs.push_back(MipsFIHolder(FI, SPOffset));
144 }
145 void recordStoreVarArgsFI(int FI, int SPOffset) {
146 if (!HasStoreVarArgs) HasStoreVarArgs=true;
147 FnStoreVarArgs.push_back(MipsFIHolder(FI, SPOffset));
148 }
149
150 void adjustLoadArgsFI(MachineFrameInfo *MFI) const {
151 if (!hasLoadArgs()) return;
Che-Liang Chiouacf1d482010-09-28 10:06:53 +0000152 for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i)
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000153 MFI->setObjectOffset( FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset );
154 }
155 void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const {
Che-Liang Chiouacf1d482010-09-28 10:06:53 +0000156 if (!hasStoreVarArgs()) return;
157 for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i)
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000158 MFI->setObjectOffset( FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset );
159 }
160
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000161 unsigned getSRetReturnReg() const { return SRetReturnReg; }
162 void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
Dan Gohman99114052009-06-03 20:30:14 +0000163
164 unsigned getGlobalBaseReg() const { return GlobalBaseReg; }
165 void setGlobalBaseReg(unsigned Reg) { GlobalBaseReg = Reg; }
Dan Gohman1e93df62010-04-17 14:41:14 +0000166
167 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
168 void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
Akira Hatanakada0a3572011-05-20 01:17:58 +0000169
170 bool hasCall() const { return HasCall; };
171 void setHasCall() { HasCall = true; }
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +0000172};
173
174} // end of namespace llvm
175
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000176#endif // MIPS_MACHINE_FUNCTION_INFO_H