blob: fd5658c721adacea9bd2592c8c72ab9d0196794c [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
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000017#include "llvm/ADT/VectorExtras.h"
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000018#include "llvm/CodeGen/MachineFunction.h"
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000019#include "llvm/CodeGen/MachineFrameInfo.h"
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000020
21namespace llvm {
22
23/// MipsFunctionInfo - This class is derived from MachineFunction private
24/// Mips target-specific information for each MachineFunction.
25class MipsFunctionInfo : public MachineFunctionInfo {
26
27private:
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000028 /// Holds for each function where on the stack the Frame Pointer must be
Bruno Cardoso Lopesbbe51362008-08-06 06:14:43 +000029 /// saved. This is used on Prologue and Epilogue to emit FP save/restore
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000030 int FPStackOffset;
31
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000032 /// Holds for each function where on the stack the Return Address must be
Bruno Cardoso Lopesbbe51362008-08-06 06:14:43 +000033 /// saved. This is used on Prologue and Epilogue to emit RA save/restore
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000034 int RAStackOffset;
35
Bruno Cardoso Lopesbbe51362008-08-06 06:14:43 +000036 /// At each function entry, two special bitmask directives must be emitted
37 /// to help debugging, for CPU and FPU callee saved registers. Both need
38 /// the negative offset from the final stack size and its higher registers
39 /// location on the stack.
40 int CPUTopSavedRegOff;
41 int FPUTopSavedRegOff;
42
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000043 /// MipsFIHolder - Holds a FrameIndex and it's Stack Pointer Offset
44 struct MipsFIHolder {
45
46 int FI;
47 int SPOffset;
48
49 MipsFIHolder(int FrameIndex, int StackPointerOffset)
50 : FI(FrameIndex), SPOffset(StackPointerOffset) {}
51 };
52
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000053 /// When PIC is used the GP must be saved on the stack on the function
54 /// prologue and must be reloaded from this stack location after every
55 /// call. A reference to its stack location and frame index must be kept
56 /// to be used on emitPrologue and processFunctionBeforeFrameFinalized.
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000057 MipsFIHolder GPHolder;
58
Bruno Cardoso Lopesbbe51362008-08-06 06:14:43 +000059 /// On LowerFORMAL_ARGUMENTS the stack size is unknown, so the Stack
60 /// Pointer Offset calculation of "not in register arguments" must be
61 /// postponed to emitPrologue.
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000062 SmallVector<MipsFIHolder, 16> FnLoadArgs;
63 bool HasLoadArgs;
64
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000065 // When VarArgs, we must write registers back to caller stack, preserving
66 // on register arguments. Since the stack size is unknown on
67 // LowerFORMAL_ARGUMENTS, the Stack Pointer Offset calculation must be
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000068 // postponed to emitPrologue.
69 SmallVector<MipsFIHolder, 4> FnStoreVarArgs;
70 bool HasStoreVarArgs;
71
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000072 /// SRetReturnReg - Some subtargets require that sret lowering includes
73 /// returning the value of the returned struct in a register. This field
74 /// holds the virtual register into which the sret argument is passed.
75 unsigned SRetReturnReg;
76
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000077public:
78 MipsFunctionInfo(MachineFunction& MF)
Bruno Cardoso Lopesbbe51362008-08-06 06:14:43 +000079 : FPStackOffset(0), RAStackOffset(0), CPUTopSavedRegOff(0),
80 FPUTopSavedRegOff(0), GPHolder(-1,-1), HasLoadArgs(false),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000081 HasStoreVarArgs(false), SRetReturnReg(0)
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000082 {}
83
84 int getFPStackOffset() const { return FPStackOffset; }
85 void setFPStackOffset(int Off) { FPStackOffset = Off; }
86
87 int getRAStackOffset() const { return RAStackOffset; }
88 void setRAStackOffset(int Off) { RAStackOffset = Off; }
89
Bruno Cardoso Lopesbbe51362008-08-06 06:14:43 +000090 int getCPUTopSavedRegOff() const { return CPUTopSavedRegOff; }
91 void setCPUTopSavedRegOff(int Off) { CPUTopSavedRegOff = Off; }
92
93 int getFPUTopSavedRegOff() const { return FPUTopSavedRegOff; }
94 void setFPUTopSavedRegOff(int Off) { FPUTopSavedRegOff = Off; }
95
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000096 int getGPStackOffset() const { return GPHolder.SPOffset; }
97 int getGPFI() const { return GPHolder.FI; }
98 void setGPStackOffset(int Off) { GPHolder.SPOffset = Off; }
99 void setGPFI(int FI) { GPHolder.FI = FI; }
Bruno Cardoso Lopes0a604002007-10-09 03:01:19 +0000100
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000101 bool hasLoadArgs() const { return HasLoadArgs; }
102 bool hasStoreVarArgs() const { return HasStoreVarArgs; }
103
104 void recordLoadArgsFI(int FI, int SPOffset) {
105 if (!HasLoadArgs) HasLoadArgs=true;
106 FnLoadArgs.push_back(MipsFIHolder(FI, SPOffset));
107 }
108 void recordStoreVarArgsFI(int FI, int SPOffset) {
109 if (!HasStoreVarArgs) HasStoreVarArgs=true;
110 FnStoreVarArgs.push_back(MipsFIHolder(FI, SPOffset));
111 }
112
113 void adjustLoadArgsFI(MachineFrameInfo *MFI) const {
114 if (!hasLoadArgs()) return;
115 for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i)
116 MFI->setObjectOffset( FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset );
117 }
118 void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const {
119 if (!hasStoreVarArgs()) return;
120 for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i)
121 MFI->setObjectOffset( FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset );
122 }
123
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000124 unsigned getSRetReturnReg() const { return SRetReturnReg; }
125 void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +0000126};
127
128} // end of namespace llvm
129
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000130#endif // MIPS_MACHINE_FUNCTION_INFO_H