blob: d1468db45bef1d18f86cd47776cfd21785bf00fa [file] [log] [blame]
Wesley Pecka70f28c2010-02-23 19:15:24 +00001//===-- MBlazeMachineFunctionInfo.h - Private data ----------------*- C++ -*-=//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file declares the MBlaze specific subclass of MachineFunctionInfo.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef MBLAZE_MACHINE_FUNCTION_INFO_H
15#define MBLAZE_MACHINE_FUNCTION_INFO_H
16
17#include "llvm/ADT/SmallVector.h"
18#include "llvm/ADT/VectorExtras.h"
19#include "llvm/CodeGen/MachineFunction.h"
20#include "llvm/CodeGen/MachineFrameInfo.h"
21
22namespace llvm {
23
24/// MBlazeFunctionInfo - This class is derived from MachineFunction private
25/// MBlaze target-specific information for each MachineFunction.
26class MBlazeFunctionInfo : public MachineFunctionInfo {
27
28private:
Wesley Peck0a67d922010-11-08 19:40:01 +000029 /// Holds for each function where on the stack the Frame Pointer must be
Wesley Pecka70f28c2010-02-23 19:15:24 +000030 /// saved. This is used on Prologue and Epilogue to emit FP save/restore
31 int FPStackOffset;
32
Wesley Peck0a67d922010-11-08 19:40:01 +000033 /// Holds for each function where on the stack the Return Address must be
Wesley Pecka70f28c2010-02-23 19:15:24 +000034 /// saved. This is used on Prologue and Epilogue to emit RA save/restore
35 int RAStackOffset;
36
Wesley Peckeb133822010-12-12 20:52:31 +000037 /// Holds the stack adjustment necessary for each function.
38 int StackAdjust;
39
Wesley Pecka70f28c2010-02-23 19:15:24 +000040 /// MBlazeFIHolder - Holds a FrameIndex and it's Stack Pointer Offset
41 struct MBlazeFIHolder {
42
43 int FI;
44 int SPOffset;
45
46 MBlazeFIHolder(int FrameIndex, int StackPointerOffset)
47 : FI(FrameIndex), SPOffset(StackPointerOffset) {}
48 };
49
Wesley Peck0a67d922010-11-08 19:40:01 +000050 /// When PIC is used the GP must be saved on the stack on the function
51 /// prologue and must be reloaded from this stack location after every
52 /// call. A reference to its stack location and frame index must be kept
Wesley Pecka70f28c2010-02-23 19:15:24 +000053 /// to be used on emitPrologue and processFunctionBeforeFrameFinalized.
54 MBlazeFIHolder GPHolder;
55
56 /// On LowerFormalArguments the stack size is unknown, so the Stack
Wesley Peck0a67d922010-11-08 19:40:01 +000057 /// Pointer Offset calculation of "not in register arguments" must be
58 /// postponed to emitPrologue.
Wesley Pecka70f28c2010-02-23 19:15:24 +000059 SmallVector<MBlazeFIHolder, 16> FnLoadArgs;
60 bool HasLoadArgs;
61
Wesley Peck0a67d922010-11-08 19:40:01 +000062 // When VarArgs, we must write registers back to caller stack, preserving
63 // on register arguments. Since the stack size is unknown on
Wesley Pecka70f28c2010-02-23 19:15:24 +000064 // LowerFormalArguments, the Stack Pointer Offset calculation must be
Wesley Peck0a67d922010-11-08 19:40:01 +000065 // postponed to emitPrologue.
Wesley Pecka70f28c2010-02-23 19:15:24 +000066 SmallVector<MBlazeFIHolder, 4> FnStoreVarArgs;
67 bool HasStoreVarArgs;
68
69 /// SRetReturnReg - Some subtargets require that sret lowering includes
70 /// returning the value of the returned struct in a register. This field
71 /// holds the virtual register into which the sret argument is passed.
72 unsigned SRetReturnReg;
73
74 /// GlobalBaseReg - keeps track of the virtual register initialized for
75 /// use as the global base register. This is used for PIC in some PIC
76 /// relocation models.
77 unsigned GlobalBaseReg;
78
Dan Gohman1e93df62010-04-17 14:41:14 +000079 // VarArgsFrameIndex - FrameIndex for start of varargs area.
80 int VarArgsFrameIndex;
81
Wesley Peckeb133822010-12-12 20:52:31 +000082 /// LiveInFI - keeps track of the frame indexes in a callers stack
83 /// frame that are live into a function.
84 SmallVector<int, 16> LiveInFI;
85
Wesley Pecka70f28c2010-02-23 19:15:24 +000086public:
Wesley Peck0a67d922010-11-08 19:40:01 +000087 MBlazeFunctionInfo(MachineFunction& MF)
Wesley Peckeb133822010-12-12 20:52:31 +000088 : FPStackOffset(0), RAStackOffset(0), StackAdjust(0), GPHolder(-1,-1),
Wesley Peck8397be02010-12-09 03:42:04 +000089 HasLoadArgs(false), HasStoreVarArgs(false), SRetReturnReg(0),
Wesley Peckeb133822010-12-12 20:52:31 +000090 GlobalBaseReg(0), VarArgsFrameIndex(0), LiveInFI()
Wesley Pecka70f28c2010-02-23 19:15:24 +000091 {}
92
93 int getFPStackOffset() const { return FPStackOffset; }
94 void setFPStackOffset(int Off) { FPStackOffset = Off; }
95
96 int getRAStackOffset() const { return RAStackOffset; }
97 void setRAStackOffset(int Off) { RAStackOffset = Off; }
98
Wesley Peckeb133822010-12-12 20:52:31 +000099 int getStackAdjust() const { return StackAdjust; }
100 void setStackAdjust(int Adj) { StackAdjust = Adj; }
101
Wesley Pecka70f28c2010-02-23 19:15:24 +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; }
106 bool needGPSaveRestore() const { return GPHolder.SPOffset != -1; }
107
108 bool hasLoadArgs() const { return HasLoadArgs; }
Wesley Peck0a67d922010-11-08 19:40:01 +0000109 bool hasStoreVarArgs() const { return HasStoreVarArgs; }
Wesley Pecka70f28c2010-02-23 19:15:24 +0000110
Wesley Peckeb133822010-12-12 20:52:31 +0000111 void recordLiveIn(int FI) {
112 LiveInFI.push_back(FI);
113 }
114
115 bool isLiveIn(int FI) {
116 for (unsigned i = 0, e = LiveInFI.size(); i < e; ++i)
117 if (FI == LiveInFI[i]) return true;
118
119 return false;
120 }
121
122 const SmallVector<int, 16>& getLiveIn() const { return LiveInFI; }
123
Wesley Pecka70f28c2010-02-23 19:15:24 +0000124 void recordLoadArgsFI(int FI, int SPOffset) {
125 if (!HasLoadArgs) HasLoadArgs=true;
126 FnLoadArgs.push_back(MBlazeFIHolder(FI, SPOffset));
127 }
128 void recordStoreVarArgsFI(int FI, int SPOffset) {
129 if (!HasStoreVarArgs) HasStoreVarArgs=true;
130 FnStoreVarArgs.push_back(MBlazeFIHolder(FI, SPOffset));
131 }
132
133 void adjustLoadArgsFI(MachineFrameInfo *MFI) const {
134 if (!hasLoadArgs()) return;
Wesley Peck0a67d922010-11-08 19:40:01 +0000135 for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i)
136 MFI->setObjectOffset(FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset);
Wesley Pecka70f28c2010-02-23 19:15:24 +0000137 }
138 void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const {
Wesley Peck0a67d922010-11-08 19:40:01 +0000139 if (!hasStoreVarArgs()) return;
140 for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i)
141 MFI->setObjectOffset(FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset);
Wesley Pecka70f28c2010-02-23 19:15:24 +0000142 }
143
144 unsigned getSRetReturnReg() const { return SRetReturnReg; }
145 void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
146
147 unsigned getGlobalBaseReg() const { return GlobalBaseReg; }
148 void setGlobalBaseReg(unsigned Reg) { GlobalBaseReg = Reg; }
Dan Gohman1e93df62010-04-17 14:41:14 +0000149
150 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
151 void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
Wesley Pecka70f28c2010-02-23 19:15:24 +0000152};
153
154} // end of namespace llvm
155
156#endif // MBLAZE_MACHINE_FUNCTION_INFO_H