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/SmallVector.h"
18 #include "llvm/ADT/VectorExtras.h"
19 #include "llvm/CodeGen/MachineFunction.h"
20 #include "llvm/CodeGen/MachineFrameInfo.h"
24 /// MBlazeFunctionInfo - This class is derived from MachineFunction private
25 /// MBlaze target-specific information for each MachineFunction.
26 class MBlazeFunctionInfo : public MachineFunctionInfo {
29 /// Holds for each function where on the stack the Frame Pointer must be
30 /// saved. This is used on Prologue and Epilogue to emit FP save/restore
33 /// Holds for each function where on the stack the Return Address must be
34 /// saved. This is used on Prologue and Epilogue to emit RA save/restore
37 /// Holds the stack adjustment necessary for each function.
40 /// MBlazeFIHolder - Holds a FrameIndex and it's Stack Pointer Offset
41 struct MBlazeFIHolder {
46 MBlazeFIHolder(int FrameIndex, int StackPointerOffset)
47 : FI(FrameIndex), SPOffset(StackPointerOffset) {}
50 /// 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
53 /// to be used on emitPrologue and processFunctionBeforeFrameFinalized.
54 MBlazeFIHolder GPHolder;
56 /// On LowerFormalArguments the stack size is unknown, so the Stack
57 /// Pointer Offset calculation of "not in register arguments" must be
58 /// postponed to emitPrologue.
59 SmallVector<MBlazeFIHolder, 16> FnLoadArgs;
62 // When VarArgs, we must write registers back to caller stack, preserving
63 // on register arguments. Since the stack size is unknown on
64 // LowerFormalArguments, the Stack Pointer Offset calculation must be
65 // postponed to emitPrologue.
66 SmallVector<MBlazeFIHolder, 4> FnStoreVarArgs;
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;
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;
79 // VarArgsFrameIndex - FrameIndex for start of varargs area.
80 int VarArgsFrameIndex;
82 /// LiveInFI - keeps track of the frame indexes in a callers stack
83 /// frame that are live into a function.
84 SmallVector<int, 16> LiveInFI;
87 MBlazeFunctionInfo(MachineFunction& MF)
88 : FPStackOffset(0), RAStackOffset(0), StackAdjust(0), GPHolder(-1,-1),
89 HasLoadArgs(false), HasStoreVarArgs(false), SRetReturnReg(0),
90 GlobalBaseReg(0), VarArgsFrameIndex(0), LiveInFI()
93 int getFPStackOffset() const { return FPStackOffset; }
94 void setFPStackOffset(int Off) { FPStackOffset = Off; }
96 int getRAStackOffset() const { return RAStackOffset; }
97 void setRAStackOffset(int Off) { RAStackOffset = Off; }
99 int getStackAdjust() const { return StackAdjust; }
100 void setStackAdjust(int Adj) { StackAdjust = Adj; }
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 recordLoadArgsFI(int FI, int SPOffset) {
125 if (!HasLoadArgs) HasLoadArgs=true;
126 FnLoadArgs.push_back(MBlazeFIHolder(FI, SPOffset));
128 void recordStoreVarArgsFI(int FI, int SPOffset) {
129 if (!HasStoreVarArgs) HasStoreVarArgs=true;
130 FnStoreVarArgs.push_back(MBlazeFIHolder(FI, SPOffset));
133 void adjustLoadArgsFI(MachineFrameInfo *MFI) const {
134 if (!hasLoadArgs()) return;
135 for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i)
136 MFI->setObjectOffset(FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset);
138 void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const {
139 if (!hasStoreVarArgs()) return;
140 for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i)
141 MFI->setObjectOffset(FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset);
144 unsigned getSRetReturnReg() const { return SRetReturnReg; }
145 void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
147 unsigned getGlobalBaseReg() const { return GlobalBaseReg; }
148 void setGlobalBaseReg(unsigned Reg) { GlobalBaseReg = Reg; }
150 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
151 void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
154 } // end of namespace llvm
156 #endif // MBLAZE_MACHINE_FUNCTION_INFO_H