1 //===-- MBlazeMachineFunctionInfo.h - Private data ----------------*- C++ -*-=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the MBlaze specific subclass of MachineFunctionInfo.
12 //===----------------------------------------------------------------------===//
14 #ifndef MBLAZE_MACHINE_FUNCTION_INFO_H
15 #define MBLAZE_MACHINE_FUNCTION_INFO_H
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/VectorExtras.h"
20 #include "llvm/CodeGen/MachineFunction.h"
21 #include "llvm/CodeGen/MachineFrameInfo.h"
25 /// MBlazeFunctionInfo - This class is derived from MachineFunction private
26 /// MBlaze target-specific information for each MachineFunction.
27 class MBlazeFunctionInfo
: public MachineFunctionInfo
{
30 /// Holds for each function where on the stack the Frame Pointer must be
31 /// saved. This is used on Prologue and Epilogue to emit FP save/restore
34 /// Holds for each function where on the stack the Return Address must be
35 /// saved. This is used on Prologue and Epilogue to emit RA save/restore
38 /// MBlazeFIHolder - Holds a FrameIndex and it's Stack Pointer Offset
39 struct MBlazeFIHolder
{
44 MBlazeFIHolder(int FrameIndex
, int StackPointerOffset
)
45 : FI(FrameIndex
), SPOffset(StackPointerOffset
) {}
48 /// When PIC is used the GP must be saved on the stack on the function
49 /// prologue and must be reloaded from this stack location after every
50 /// call. A reference to its stack location and frame index must be kept
51 /// to be used on emitPrologue and processFunctionBeforeFrameFinalized.
52 MBlazeFIHolder GPHolder
;
54 /// On LowerFormalArguments the stack size is unknown, so the Stack
55 /// Pointer Offset calculation of "not in register arguments" must be
56 /// postponed to emitPrologue.
57 SmallVector
<MBlazeFIHolder
, 16> FnLoadArgs
;
60 // When VarArgs, we must write registers back to caller stack, preserving
61 // on register arguments. Since the stack size is unknown on
62 // LowerFormalArguments, the Stack Pointer Offset calculation must be
63 // postponed to emitPrologue.
64 SmallVector
<MBlazeFIHolder
, 4> FnStoreVarArgs
;
67 // When determining the final stack layout some of the frame indexes may
68 // be replaced by new frame indexes that reside in the caller's stack
69 // frame. The replacements are recorded in this structure.
70 DenseMap
<int,int> FIReplacements
;
72 /// 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
;
77 /// GlobalBaseReg - keeps track of the virtual register initialized for
78 /// use as the global base register. This is used for PIC in some PIC
79 /// relocation models.
80 unsigned GlobalBaseReg
;
82 // VarArgsFrameIndex - FrameIndex for start of varargs area.
83 int VarArgsFrameIndex
;
85 /// LiveInFI - keeps track of the frame indexes in a callers stack
86 /// frame that are live into a function.
87 SmallVector
<int, 16> LiveInFI
;
90 MBlazeFunctionInfo(MachineFunction
& MF
)
91 : FPStackOffset(0), RAStackOffset(0), GPHolder(-1,-1), HasLoadArgs(false),
92 HasStoreVarArgs(false), SRetReturnReg(0), GlobalBaseReg(0),
93 VarArgsFrameIndex(0), LiveInFI()
96 int getFPStackOffset() const { return FPStackOffset
; }
97 void setFPStackOffset(int Off
) { FPStackOffset
= Off
; }
99 int getRAStackOffset() const { return RAStackOffset
; }
100 void setRAStackOffset(int Off
) { RAStackOffset
= Off
; }
102 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; }
108 bool hasLoadArgs() const { return HasLoadArgs
; }
109 bool hasStoreVarArgs() const { return HasStoreVarArgs
; }
111 void recordLiveIn(int FI
) {
112 LiveInFI
.push_back(FI
);
115 bool isLiveIn(int FI
) {
116 for (unsigned i
= 0, e
= LiveInFI
.size(); i
< e
; ++i
)
117 if (FI
== LiveInFI
[i
]) return true;
122 const SmallVector
<int, 16>& getLiveIn() const { return LiveInFI
; }
124 void recordReplacement(int OFI
, int NFI
) {
125 FIReplacements
.insert(std::make_pair(OFI
,NFI
));
128 bool hasReplacement(int OFI
) const {
129 return FIReplacements
.find(OFI
) != FIReplacements
.end();
132 int getReplacement(int OFI
) const {
133 return FIReplacements
.lookup(OFI
);
136 void recordLoadArgsFI(int FI
, int SPOffset
) {
137 if (!HasLoadArgs
) HasLoadArgs
=true;
138 FnLoadArgs
.push_back(MBlazeFIHolder(FI
, SPOffset
));
141 void recordStoreVarArgsFI(int FI
, int SPOffset
) {
142 if (!HasStoreVarArgs
) HasStoreVarArgs
=true;
143 FnStoreVarArgs
.push_back(MBlazeFIHolder(FI
, SPOffset
));
146 void adjustLoadArgsFI(MachineFrameInfo
*MFI
) const {
147 if (!hasLoadArgs()) return;
148 for (unsigned i
= 0, e
= FnLoadArgs
.size(); i
!= e
; ++i
)
149 MFI
->setObjectOffset(FnLoadArgs
[i
].FI
, FnLoadArgs
[i
].SPOffset
);
152 void adjustStoreVarArgsFI(MachineFrameInfo
*MFI
) const {
153 if (!hasStoreVarArgs()) return;
154 for (unsigned i
= 0, e
= FnStoreVarArgs
.size(); i
!= e
; ++i
)
155 MFI
->setObjectOffset(FnStoreVarArgs
[i
].FI
, FnStoreVarArgs
[i
].SPOffset
);
158 unsigned getSRetReturnReg() const { return SRetReturnReg
; }
159 void setSRetReturnReg(unsigned Reg
) { SRetReturnReg
= Reg
; }
161 unsigned getGlobalBaseReg() const { return GlobalBaseReg
; }
162 void setGlobalBaseReg(unsigned Reg
) { GlobalBaseReg
= Reg
; }
164 int getVarArgsFrameIndex() const { return VarArgsFrameIndex
; }
165 void setVarArgsFrameIndex(int Index
) { VarArgsFrameIndex
= Index
; }
168 } // end of namespace llvm
170 #endif // MBLAZE_MACHINE_FUNCTION_INFO_H