1 //===-- MipsMachineFunctionInfo.h - Private data used for Mips ----*- 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 Mips specific subclass of MachineFunctionInfo.
12 //===----------------------------------------------------------------------===//
14 #ifndef MIPS_MACHINE_FUNCTION_INFO_H
15 #define MIPS_MACHINE_FUNCTION_INFO_H
17 #include "llvm/ADT/VectorExtras.h"
18 #include "llvm/CodeGen/MachineFunction.h"
19 #include "llvm/CodeGen/MachineFrameInfo.h"
23 /// MipsFunctionInfo - This class is derived from MachineFunction private
24 /// Mips target-specific information for each MachineFunction.
25 class MipsFunctionInfo : public MachineFunctionInfo {
28 /// Holds for each function where on the stack
29 /// the Frame Pointer must be saved
32 /// Holds for each function where on the stack
33 /// the Return Address must be saved
36 /// MipsFIHolder - Holds a FrameIndex and it's Stack Pointer Offset
42 MipsFIHolder(int FrameIndex, int StackPointerOffset)
43 : FI(FrameIndex), SPOffset(StackPointerOffset) {}
46 /// When PIC is used the GP must be saved on the stack
47 /// on the function prologue and must be reloaded from this
48 /// stack location after every call. A reference to its stack
49 /// location and frame index must be kept to be used on
50 /// emitPrologue and processFunctionBeforeFrameFinalized.
51 MipsFIHolder GPHolder;
53 // On LowerFORMAL_ARGUMENTS the stack size is unknown,
54 // so the Stack Pointer Offset calculation of "not in
55 // register arguments" must be postponed to emitPrologue.
56 SmallVector<MipsFIHolder, 16> FnLoadArgs;
59 // When VarArgs, we must write registers back to caller
60 // stack, preserving on register arguments. Since the
61 // stack size is unknown on LowerFORMAL_ARGUMENTS,
62 // the Stack Pointer Offset calculation must be
63 // postponed to emitPrologue.
64 SmallVector<MipsFIHolder, 4> FnStoreVarArgs;
68 MipsFunctionInfo(MachineFunction& MF)
69 : FPStackOffset(0), RAStackOffset(0), GPHolder(-1,-1),
70 HasLoadArgs(false), HasStoreVarArgs(false)
73 int getFPStackOffset() const { return FPStackOffset; }
74 void setFPStackOffset(int Off) { FPStackOffset = Off; }
76 int getRAStackOffset() const { return RAStackOffset; }
77 void setRAStackOffset(int Off) { RAStackOffset = Off; }
79 int getGPStackOffset() const { return GPHolder.SPOffset; }
80 int getGPFI() const { return GPHolder.FI; }
81 void setGPStackOffset(int Off) { GPHolder.SPOffset = Off; }
82 void setGPFI(int FI) { GPHolder.FI = FI; }
84 int getTopSavedRegOffset() const {
85 return (RAStackOffset > FPStackOffset) ?
86 (RAStackOffset) : (FPStackOffset);
89 bool hasLoadArgs() const { return HasLoadArgs; }
90 bool hasStoreVarArgs() const { return HasStoreVarArgs; }
92 void recordLoadArgsFI(int FI, int SPOffset) {
93 if (!HasLoadArgs) HasLoadArgs=true;
94 FnLoadArgs.push_back(MipsFIHolder(FI, SPOffset));
96 void recordStoreVarArgsFI(int FI, int SPOffset) {
97 if (!HasStoreVarArgs) HasStoreVarArgs=true;
98 FnStoreVarArgs.push_back(MipsFIHolder(FI, SPOffset));
101 void adjustLoadArgsFI(MachineFrameInfo *MFI) const {
102 if (!hasLoadArgs()) return;
103 for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i)
104 MFI->setObjectOffset( FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset );
106 void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const {
107 if (!hasStoreVarArgs()) return;
108 for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i)
109 MFI->setObjectOffset( FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset );
114 } // end of namespace llvm
116 #endif // MIPS_MACHINE_FUNCTION_INFO_H