blob: 3f6b67030fa2167b26652874c17141e0a0a17c3e [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:
Bruno Cardoso Lopesbbe51362008-08-06 06:14:43 +000030 /// At each function entry, two special bitmask directives must be emitted
31 /// to help debugging, for CPU and FPU callee saved registers. Both need
32 /// the negative offset from the final stack size and its higher registers
33 /// location on the stack.
34 int CPUTopSavedRegOff;
35 int FPUTopSavedRegOff;
36
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000037 /// MipsFIHolder - Holds a FrameIndex and it's Stack Pointer Offset
38 struct MipsFIHolder {
39
40 int FI;
41 int SPOffset;
42
43 MipsFIHolder(int FrameIndex, int StackPointerOffset)
44 : FI(FrameIndex), SPOffset(StackPointerOffset) {}
45 };
46
Che-Liang Chiouacf1d482010-09-28 10:06:53 +000047 /// When PIC is used the GP must be saved on the stack on the function
48 /// prologue and must be reloaded from this stack location after every
49 /// call. A reference to its stack location and frame index must be kept
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000050 /// to be used on emitPrologue and processFunctionBeforeFrameFinalized.
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000051 MipsFIHolder GPHolder;
52
Dan Gohman98ca4f22009-08-05 01:29:28 +000053 /// On LowerFormalArguments the stack size is unknown, so the Stack
Che-Liang Chiouacf1d482010-09-28 10:06:53 +000054 /// Pointer Offset calculation of "not in register arguments" must be
55 /// postponed to emitPrologue.
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000056 SmallVector<MipsFIHolder, 16> FnLoadArgs;
57 bool HasLoadArgs;
58
Che-Liang Chiouacf1d482010-09-28 10:06:53 +000059 // When VarArgs, we must write registers back to caller stack, preserving
60 // on register arguments. Since the stack size is unknown on
Dan Gohman98ca4f22009-08-05 01:29:28 +000061 // LowerFormalArguments, the Stack Pointer Offset calculation must be
Che-Liang Chiouacf1d482010-09-28 10:06:53 +000062 // postponed to emitPrologue.
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000063 SmallVector<MipsFIHolder, 4> FnStoreVarArgs;
64 bool HasStoreVarArgs;
65
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000066 /// SRetReturnReg - Some subtargets require that sret lowering includes
67 /// returning the value of the returned struct in a register. This field
68 /// holds the virtual register into which the sret argument is passed.
69 unsigned SRetReturnReg;
70
Dan Gohman99114052009-06-03 20:30:14 +000071 /// GlobalBaseReg - keeps track of the virtual register initialized for
72 /// use as the global base register. This is used for PIC in some PIC
73 /// relocation models.
74 unsigned GlobalBaseReg;
75
Dan Gohman1e93df62010-04-17 14:41:14 +000076 /// VarArgsFrameIndex - FrameIndex for start of varargs area.
77 int VarArgsFrameIndex;
78
Akira Hatanakada0a3572011-05-20 01:17:58 +000079 // Range of frame object indices.
80 // InArgFIRange: Range of indices of all frame objects created during call to
81 // LowerFormalArguments.
82 // OutArgFIRange: Range of indices of all frame objects created during call to
83 // LowerCall except for the frame object for restoring $gp.
84 std::pair<int, int> InArgFIRange, OutArgFIRange;
85 int GPFI; // Index of the frame object for restoring $gp
86 bool HasCall; // True if function has a function call.
Akira Hatanaka6ffbf822011-05-20 20:11:17 +000087 int MaxCallFrameSize;
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000088public:
Che-Liang Chiouacf1d482010-09-28 10:06:53 +000089 MipsFunctionInfo(MachineFunction& MF)
Akira Hatanaka17a1e872011-05-20 18:39:33 +000090 : CPUTopSavedRegOff(0),
Che-Liang Chiouacf1d482010-09-28 10:06:53 +000091 FPUTopSavedRegOff(0), GPHolder(-1,-1), HasLoadArgs(false),
Dan Gohman1e93df62010-04-17 14:41:14 +000092 HasStoreVarArgs(false), SRetReturnReg(0), GlobalBaseReg(0),
Akira Hatanakada0a3572011-05-20 01:17:58 +000093 VarArgsFrameIndex(0), InArgFIRange(std::make_pair(-1, 0)),
Akira Hatanaka6ffbf822011-05-20 20:11:17 +000094 OutArgFIRange(std::make_pair(-1, 0)), GPFI(0), HasCall(false),
95 MaxCallFrameSize(-1)
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000096 {}
97
Bruno Cardoso Lopesbbe51362008-08-06 06:14:43 +000098 int getCPUTopSavedRegOff() const { return CPUTopSavedRegOff; }
99 void setCPUTopSavedRegOff(int Off) { CPUTopSavedRegOff = Off; }
100
101 int getFPUTopSavedRegOff() const { return FPUTopSavedRegOff; }
102 void setFPUTopSavedRegOff(int Off) { FPUTopSavedRegOff = Off; }
103
Akira Hatanakada0a3572011-05-20 01:17:58 +0000104 bool isInArgFI(int FI) const {
105 return FI <= InArgFIRange.first && FI >= InArgFIRange.second;
106 }
107 void setLastInArgFI(int FI) { InArgFIRange.second = FI; }
108
109 bool isOutArgFI(int FI) const {
110 return FI <= OutArgFIRange.first && FI >= OutArgFIRange.second;
111 }
112 void extendOutArgFIRange(int FirstFI, int LastFI) {
113 if (!OutArgFIRange.second)
114 // this must be the first time this function was called.
115 OutArgFIRange.first = FirstFI;
116 OutArgFIRange.second = LastFI;
117 }
118
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000119 int getGPStackOffset() const { return GPHolder.SPOffset; }
120 int getGPFI() const { return GPHolder.FI; }
121 void setGPStackOffset(int Off) { GPHolder.SPOffset = Off; }
122 void setGPFI(int FI) { GPHolder.FI = FI; }
Bruno Cardoso Lopesb8e0ebf2009-11-09 14:27:49 +0000123 bool needGPSaveRestore() const { return GPHolder.SPOffset != -1; }
Akira Hatanakada0a3572011-05-20 01:17:58 +0000124 bool isGPFI(int FI) const { return GPFI && GPFI == FI; }
Bruno Cardoso Lopes0a604002007-10-09 03:01:19 +0000125
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000126 bool hasLoadArgs() const { return HasLoadArgs; }
Che-Liang Chiouacf1d482010-09-28 10:06:53 +0000127 bool hasStoreVarArgs() const { return HasStoreVarArgs; }
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000128
129 void recordLoadArgsFI(int FI, int SPOffset) {
130 if (!HasLoadArgs) HasLoadArgs=true;
131 FnLoadArgs.push_back(MipsFIHolder(FI, SPOffset));
132 }
133 void recordStoreVarArgsFI(int FI, int SPOffset) {
134 if (!HasStoreVarArgs) HasStoreVarArgs=true;
135 FnStoreVarArgs.push_back(MipsFIHolder(FI, SPOffset));
136 }
137
138 void adjustLoadArgsFI(MachineFrameInfo *MFI) const {
139 if (!hasLoadArgs()) return;
Che-Liang Chiouacf1d482010-09-28 10:06:53 +0000140 for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i)
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000141 MFI->setObjectOffset( FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset );
142 }
143 void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const {
Che-Liang Chiouacf1d482010-09-28 10:06:53 +0000144 if (!hasStoreVarArgs()) return;
145 for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i)
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000146 MFI->setObjectOffset( FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset );
147 }
148
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000149 unsigned getSRetReturnReg() const { return SRetReturnReg; }
150 void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
Dan Gohman99114052009-06-03 20:30:14 +0000151
152 unsigned getGlobalBaseReg() const { return GlobalBaseReg; }
153 void setGlobalBaseReg(unsigned Reg) { GlobalBaseReg = Reg; }
Dan Gohman1e93df62010-04-17 14:41:14 +0000154
155 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
156 void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
Akira Hatanakada0a3572011-05-20 01:17:58 +0000157
Benjamin Kramer6e35e4c2011-05-20 09:20:25 +0000158 bool hasCall() const { return HasCall; }
Akira Hatanakada0a3572011-05-20 01:17:58 +0000159 void setHasCall() { HasCall = true; }
Akira Hatanaka6ffbf822011-05-20 20:11:17 +0000160
161 int getMaxCallFrameSize() const { return MaxCallFrameSize; }
162 void setMaxCallFrameSize(int S) { MaxCallFrameSize = S; }
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +0000163};
164
165} // end of namespace llvm
166
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000167#endif // MIPS_MACHINE_FUNCTION_INFO_H