blob: c4d2cfe7be347f523c38bc6ede57df4cb791baac [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.
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000087public:
Che-Liang Chiouacf1d482010-09-28 10:06:53 +000088 MipsFunctionInfo(MachineFunction& MF)
Akira Hatanaka17a1e872011-05-20 18:39:33 +000089 : CPUTopSavedRegOff(0),
Che-Liang Chiouacf1d482010-09-28 10:06:53 +000090 FPUTopSavedRegOff(0), GPHolder(-1,-1), HasLoadArgs(false),
Dan Gohman1e93df62010-04-17 14:41:14 +000091 HasStoreVarArgs(false), SRetReturnReg(0), GlobalBaseReg(0),
Akira Hatanakada0a3572011-05-20 01:17:58 +000092 VarArgsFrameIndex(0), InArgFIRange(std::make_pair(-1, 0)),
93 OutArgFIRange(std::make_pair(-1, 0)), GPFI(0), HasCall(false)
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000094 {}
95
Bruno Cardoso Lopesbbe51362008-08-06 06:14:43 +000096 int getCPUTopSavedRegOff() const { return CPUTopSavedRegOff; }
97 void setCPUTopSavedRegOff(int Off) { CPUTopSavedRegOff = Off; }
98
99 int getFPUTopSavedRegOff() const { return FPUTopSavedRegOff; }
100 void setFPUTopSavedRegOff(int Off) { FPUTopSavedRegOff = Off; }
101
Akira Hatanakada0a3572011-05-20 01:17:58 +0000102 bool isInArgFI(int FI) const {
103 return FI <= InArgFIRange.first && FI >= InArgFIRange.second;
104 }
105 void setLastInArgFI(int FI) { InArgFIRange.second = FI; }
106
107 bool isOutArgFI(int FI) const {
108 return FI <= OutArgFIRange.first && FI >= OutArgFIRange.second;
109 }
110 void extendOutArgFIRange(int FirstFI, int LastFI) {
111 if (!OutArgFIRange.second)
112 // this must be the first time this function was called.
113 OutArgFIRange.first = FirstFI;
114 OutArgFIRange.second = LastFI;
115 }
116
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000117 int getGPStackOffset() const { return GPHolder.SPOffset; }
118 int getGPFI() const { return GPHolder.FI; }
119 void setGPStackOffset(int Off) { GPHolder.SPOffset = Off; }
120 void setGPFI(int FI) { GPHolder.FI = FI; }
Bruno Cardoso Lopesb8e0ebf2009-11-09 14:27:49 +0000121 bool needGPSaveRestore() const { return GPHolder.SPOffset != -1; }
Akira Hatanakada0a3572011-05-20 01:17:58 +0000122 bool isGPFI(int FI) const { return GPFI && GPFI == FI; }
Bruno Cardoso Lopes0a604002007-10-09 03:01:19 +0000123
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000124 bool hasLoadArgs() const { return HasLoadArgs; }
Che-Liang Chiouacf1d482010-09-28 10:06:53 +0000125 bool hasStoreVarArgs() const { return HasStoreVarArgs; }
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000126
127 void recordLoadArgsFI(int FI, int SPOffset) {
128 if (!HasLoadArgs) HasLoadArgs=true;
129 FnLoadArgs.push_back(MipsFIHolder(FI, SPOffset));
130 }
131 void recordStoreVarArgsFI(int FI, int SPOffset) {
132 if (!HasStoreVarArgs) HasStoreVarArgs=true;
133 FnStoreVarArgs.push_back(MipsFIHolder(FI, SPOffset));
134 }
135
136 void adjustLoadArgsFI(MachineFrameInfo *MFI) const {
137 if (!hasLoadArgs()) return;
Che-Liang Chiouacf1d482010-09-28 10:06:53 +0000138 for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i)
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000139 MFI->setObjectOffset( FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset );
140 }
141 void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const {
Che-Liang Chiouacf1d482010-09-28 10:06:53 +0000142 if (!hasStoreVarArgs()) return;
143 for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i)
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000144 MFI->setObjectOffset( FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset );
145 }
146
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000147 unsigned getSRetReturnReg() const { return SRetReturnReg; }
148 void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
Dan Gohman99114052009-06-03 20:30:14 +0000149
150 unsigned getGlobalBaseReg() const { return GlobalBaseReg; }
151 void setGlobalBaseReg(unsigned Reg) { GlobalBaseReg = Reg; }
Dan Gohman1e93df62010-04-17 14:41:14 +0000152
153 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
154 void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
Akira Hatanakada0a3572011-05-20 01:17:58 +0000155
Benjamin Kramer6e35e4c2011-05-20 09:20:25 +0000156 bool hasCall() const { return HasCall; }
Akira Hatanakada0a3572011-05-20 01:17:58 +0000157 void setHasCall() { HasCall = true; }
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +0000158};
159
160} // end of namespace llvm
161
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000162#endif // MIPS_MACHINE_FUNCTION_INFO_H