Remove attribution from file headers, per discussion on llvmdev.
[oota-llvm.git] / lib / Target / Mips / MipsMachineFunction.h
1 //===-- MipsMachineFunctionInfo.h - Private data used for Mips ----*- C++ -*-=//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the Mips specific subclass of MachineFunctionInfo.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef MIPS_MACHINE_FUNCTION_INFO_H
15 #define MIPS_MACHINE_FUNCTION_INFO_H
16
17 #include "llvm/ADT/VectorExtras.h"
18 #include "llvm/CodeGen/MachineFunction.h"
19 #include "llvm/CodeGen/MachineFrameInfo.h"
20
21 namespace llvm {
22
23 /// MipsFunctionInfo - This class is derived from MachineFunction private
24 /// Mips target-specific information for each MachineFunction.
25 class MipsFunctionInfo : public MachineFunctionInfo {
26
27 private:
28   /// Holds for each function where on the stack 
29   /// the Frame Pointer must be saved
30   int FPStackOffset;
31
32   /// Holds for each function where on the stack 
33   /// the Return Address must be saved
34   int RAStackOffset;
35
36   /// MipsFIHolder - Holds a FrameIndex and it's Stack Pointer Offset
37   struct MipsFIHolder {
38
39     int FI;
40     int SPOffset;
41
42     MipsFIHolder(int FrameIndex, int StackPointerOffset)
43       : FI(FrameIndex), SPOffset(StackPointerOffset) {}
44   };
45
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;
52
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;
57   bool HasLoadArgs;
58
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;
65   bool HasStoreVarArgs;
66
67 public:
68   MipsFunctionInfo(MachineFunction& MF) 
69   : FPStackOffset(0), RAStackOffset(0), GPHolder(-1,-1),
70     HasLoadArgs(false), HasStoreVarArgs(false)
71   {}
72
73   int getFPStackOffset() const { return FPStackOffset; }
74   void setFPStackOffset(int Off) { FPStackOffset = Off; }
75
76   int getRAStackOffset() const { return RAStackOffset; }
77   void setRAStackOffset(int Off) { RAStackOffset = Off; }
78
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; }
83
84   int getTopSavedRegOffset() const { 
85     return (RAStackOffset > FPStackOffset) ? 
86            (RAStackOffset) : (FPStackOffset);
87   }
88
89   bool hasLoadArgs() const { return HasLoadArgs; }
90   bool hasStoreVarArgs() const { return HasStoreVarArgs; } 
91
92   void recordLoadArgsFI(int FI, int SPOffset) {
93     if (!HasLoadArgs) HasLoadArgs=true;
94     FnLoadArgs.push_back(MipsFIHolder(FI, SPOffset));
95   }
96   void recordStoreVarArgsFI(int FI, int SPOffset) {
97     if (!HasStoreVarArgs) HasStoreVarArgs=true;
98     FnStoreVarArgs.push_back(MipsFIHolder(FI, SPOffset));
99   }
100
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 );
105   }
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 );
110   }
111
112 };
113
114 } // end of namespace llvm
115
116 #endif // MIPS_MACHINE_FUNCTION_INFO_H