1 //===-- MipsMachineFunctionInfo.h - Private data used for Mips ----*- C++ -*-=//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Bruno Cardoso Lopes and is distributed under
6 // the University of Illinois Open Source 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 /// When PIC is used the GP must be saved on the stack
37 /// on the function prologue, so a reference to its stack
38 /// location must be kept.
41 /// MipsFIHolder - Holds a FrameIndex and it's Stack Pointer Offset
47 MipsFIHolder(int FrameIndex, int StackPointerOffset)
48 : FI(FrameIndex), SPOffset(StackPointerOffset) {}
51 // On LowerFORMAL_ARGUMENTS the stack size is unknown,
52 // so the Stack Pointer Offset calculation of "not in
53 // register arguments" must be postponed to emitPrologue.
54 SmallVector<MipsFIHolder, 16> FnLoadArgs;
57 // When VarArgs, we must write registers back to caller
58 // stack, preserving on register arguments. Since the
59 // stack size is unknown on LowerFORMAL_ARGUMENTS,
60 // the Stack Pointer Offset calculation must be
61 // postponed to emitPrologue.
62 SmallVector<MipsFIHolder, 4> FnStoreVarArgs;
66 MipsFunctionInfo(MachineFunction& MF)
67 : FPStackOffset(0), RAStackOffset(0),
68 HasLoadArgs(false), HasStoreVarArgs(false)
71 int getFPStackOffset() const { return FPStackOffset; }
72 void setFPStackOffset(int Off) { FPStackOffset = Off; }
74 int getRAStackOffset() const { return RAStackOffset; }
75 void setRAStackOffset(int Off) { RAStackOffset = Off; }
77 int getGPStackOffset() const { return GPStackOffset; }
78 void setGPStackOffset(int Off) { GPStackOffset = Off; }
80 int getTopSavedRegOffset() const {
81 return (RAStackOffset > FPStackOffset) ?
82 (RAStackOffset) : (FPStackOffset);
85 bool hasLoadArgs() const { return HasLoadArgs; }
86 bool hasStoreVarArgs() const { return HasStoreVarArgs; }
88 void recordLoadArgsFI(int FI, int SPOffset) {
89 if (!HasLoadArgs) HasLoadArgs=true;
90 FnLoadArgs.push_back(MipsFIHolder(FI, SPOffset));
92 void recordStoreVarArgsFI(int FI, int SPOffset) {
93 if (!HasStoreVarArgs) HasStoreVarArgs=true;
94 FnStoreVarArgs.push_back(MipsFIHolder(FI, SPOffset));
97 void adjustLoadArgsFI(MachineFrameInfo *MFI) const {
98 if (!hasLoadArgs()) return;
99 for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i)
100 MFI->setObjectOffset( FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset );
102 void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const {
103 if (!hasStoreVarArgs()) return;
104 for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i)
105 MFI->setObjectOffset( FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset );
110 } // end of namespace llvm
112 #endif // MIPS_MACHINE_FUNCTION_INFO_H