blob: a300f49ff5d475cc2047a88d0f9ff577deaa3f3d [file] [log] [blame]
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +00001//===-- MipsMachineFunctionInfo.h - Private data used for Mips ----*- C++ -*-=//
2//
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//
8//===----------------------------------------------------------------------===//
9//
10// This file declares the Mips specific subclass of MachineFunctionInfo.
11//
12//===----------------------------------------------------------------------===//
13
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:
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +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
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +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
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +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
57 /// 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
Bruno Cardoso Lopesbbe51362008-08-06 06:14:43 +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
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +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
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000069 // postponed to emitPrologue.
70 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
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000083public:
84 MipsFunctionInfo(MachineFunction& MF)
Bruno Cardoso Lopesbbe51362008-08-06 06:14:43 +000085 : FPStackOffset(0), RAStackOffset(0), CPUTopSavedRegOff(0),
86 FPUTopSavedRegOff(0), GPHolder(-1,-1), HasLoadArgs(false),
Dan Gohman99114052009-06-03 20:30:14 +000087 HasStoreVarArgs(false), SRetReturnReg(0), GlobalBaseReg(0)
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000088 {}
89
90 int getFPStackOffset() const { return FPStackOffset; }
91 void setFPStackOffset(int Off) { FPStackOffset = Off; }
92
93 int getRAStackOffset() const { return RAStackOffset; }
94 void setRAStackOffset(int Off) { RAStackOffset = Off; }
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
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000102 int getGPStackOffset() const { return GPHolder.SPOffset; }
103 int getGPFI() const { return GPHolder.FI; }
104 void setGPStackOffset(int Off) { GPHolder.SPOffset = Off; }
105 void setGPFI(int FI) { GPHolder.FI = FI; }
Bruno Cardoso Lopesb8e0ebf2009-11-09 14:27:49 +0000106 bool needGPSaveRestore() const { return GPHolder.SPOffset != -1; }
Bruno Cardoso Lopes0a604002007-10-09 03:01:19 +0000107
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000108 bool hasLoadArgs() const { return HasLoadArgs; }
109 bool hasStoreVarArgs() const { return HasStoreVarArgs; }
110
111 void recordLoadArgsFI(int FI, int SPOffset) {
112 if (!HasLoadArgs) HasLoadArgs=true;
113 FnLoadArgs.push_back(MipsFIHolder(FI, SPOffset));
114 }
115 void recordStoreVarArgsFI(int FI, int SPOffset) {
116 if (!HasStoreVarArgs) HasStoreVarArgs=true;
117 FnStoreVarArgs.push_back(MipsFIHolder(FI, SPOffset));
118 }
119
120 void adjustLoadArgsFI(MachineFrameInfo *MFI) const {
121 if (!hasLoadArgs()) return;
122 for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i)
123 MFI->setObjectOffset( FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset );
124 }
125 void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const {
126 if (!hasStoreVarArgs()) return;
127 for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i)
128 MFI->setObjectOffset( FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset );
129 }
130
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000131 unsigned getSRetReturnReg() const { return SRetReturnReg; }
132 void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
Dan Gohman99114052009-06-03 20:30:14 +0000133
134 unsigned getGlobalBaseReg() const { return GlobalBaseReg; }
135 void setGlobalBaseReg(unsigned Reg) { GlobalBaseReg = Reg; }
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +0000136};
137
138} // end of namespace llvm
139
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000140#endif // MIPS_MACHINE_FUNCTION_INFO_H