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 /// At each function entry a special bitmask directive must be emitted
38 /// to help in debugging CPU callee saved registers. It needs a negative
39 /// offset from the final stack size and its higher register location on
41 int CPUTopSavedRegOff;
43 /// MBlazeFIHolder - Holds a FrameIndex and it's Stack Pointer Offset
44 struct MBlazeFIHolder {
49 MBlazeFIHolder(int FrameIndex, int StackPointerOffset)
50 : FI(FrameIndex), SPOffset(StackPointerOffset) {}
53 /// 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.
57 MBlazeFIHolder GPHolder;
59 /// On LowerFormalArguments the stack size is unknown, so the Stack
60 /// Pointer Offset calculation of "not in register arguments" must be
61 /// postponed to emitPrologue.
62 SmallVector<MBlazeFIHolder, 16> FnLoadArgs;
65 // When VarArgs, we must write registers back to caller stack, preserving
66 // on register arguments. Since the stack size is unknown on
67 // LowerFormalArguments, the Stack Pointer Offset calculation must be
68 // postponed to emitPrologue.
69 SmallVector<MBlazeFIHolder, 4> FnStoreVarArgs;
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;
83 MBlazeFunctionInfo(MachineFunction& MF)
84 : FPStackOffset(0), RAStackOffset(0), CPUTopSavedRegOff(0),
85 GPHolder(-1,-1), HasLoadArgs(false), HasStoreVarArgs(false),
86 SRetReturnReg(0), GlobalBaseReg(0)
89 int getFPStackOffset() const { return FPStackOffset; }
90 void setFPStackOffset(int Off) { FPStackOffset = Off; }
92 int getRAStackOffset() const { return RAStackOffset; }
93 void setRAStackOffset(int Off) { RAStackOffset = Off; }
95 int getCPUTopSavedRegOff() const { return CPUTopSavedRegOff; }
96 void setCPUTopSavedRegOff(int Off) { CPUTopSavedRegOff = Off; }
98 int getGPStackOffset() const { return GPHolder.SPOffset; }
99 int getGPFI() const { return GPHolder.FI; }
100 void setGPStackOffset(int Off) { GPHolder.SPOffset = Off; }
101 void setGPFI(int FI) { GPHolder.FI = FI; }
102 bool needGPSaveRestore() const { return GPHolder.SPOffset != -1; }
104 bool hasLoadArgs() const { return HasLoadArgs; }
105 bool hasStoreVarArgs() const { return HasStoreVarArgs; }
107 void recordLoadArgsFI(int FI, int SPOffset) {
108 if (!HasLoadArgs) HasLoadArgs=true;
109 FnLoadArgs.push_back(MBlazeFIHolder(FI, SPOffset));
111 void recordStoreVarArgsFI(int FI, int SPOffset) {
112 if (!HasStoreVarArgs) HasStoreVarArgs=true;
113 FnStoreVarArgs.push_back(MBlazeFIHolder(FI, SPOffset));
116 void adjustLoadArgsFI(MachineFrameInfo *MFI) const {
117 if (!hasLoadArgs()) return;
118 for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i)
119 MFI->setObjectOffset( FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset );
121 void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const {
122 if (!hasStoreVarArgs()) return;
123 for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i)
124 MFI->setObjectOffset( FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset );
127 unsigned getSRetReturnReg() const { return SRetReturnReg; }
128 void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
130 unsigned getGlobalBaseReg() const { return GlobalBaseReg; }
131 void setGlobalBaseReg(unsigned Reg) { GlobalBaseReg = Reg; }
134 } // end of namespace llvm
136 #endif // MBLAZE_MACHINE_FUNCTION_INFO_H