Position Independent Code (PIC) support [2]
[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 was developed by Bruno Cardoso Lopes and is distributed under
6 // the University of Illinois Open Source 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   /// 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.
39   int GPStackOffset;
40
41   /// MipsFIHolder - Holds a FrameIndex and it's Stack Pointer Offset
42   struct MipsFIHolder {
43
44     int FI;
45     int SPOffset;
46
47     MipsFIHolder(int FrameIndex, int StackPointerOffset)
48       : FI(FrameIndex), SPOffset(StackPointerOffset) {}
49   };
50
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;
55   bool HasLoadArgs;
56
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;
63   bool HasStoreVarArgs;
64
65 public:
66   MipsFunctionInfo(MachineFunction& MF) 
67   : FPStackOffset(0), RAStackOffset(0), 
68     HasLoadArgs(false), HasStoreVarArgs(false)
69   {}
70
71   int getFPStackOffset() const { return FPStackOffset; }
72   void setFPStackOffset(int Off) { FPStackOffset = Off; }
73
74   int getRAStackOffset() const { return RAStackOffset; }
75   void setRAStackOffset(int Off) { RAStackOffset = Off; }
76
77   int getGPStackOffset() const { return GPStackOffset; }
78   void setGPStackOffset(int Off) { GPStackOffset = Off; }
79
80   int getTopSavedRegOffset() const { 
81     return (RAStackOffset > FPStackOffset) ? 
82            (RAStackOffset) : (FPStackOffset);
83   }
84
85   bool hasLoadArgs() const { return HasLoadArgs; }
86   bool hasStoreVarArgs() const { return HasStoreVarArgs; } 
87
88   void recordLoadArgsFI(int FI, int SPOffset) {
89     if (!HasLoadArgs) HasLoadArgs=true;
90     FnLoadArgs.push_back(MipsFIHolder(FI, SPOffset));
91   }
92   void recordStoreVarArgsFI(int FI, int SPOffset) {
93     if (!HasStoreVarArgs) HasStoreVarArgs=true;
94     FnStoreVarArgs.push_back(MipsFIHolder(FI, SPOffset));
95   }
96
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 );
101   }
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 );
106   }
107
108 };
109
110 } // end of namespace llvm
111
112 #endif // MIPS_MACHINE_FUNCTION_INFO_H