Fix bug in lowering of DYNAMIC_STACKALLOC nodes. The correct offset of the
[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 <utility>
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/VectorExtras.h"
20 #include "llvm/CodeGen/MachineFunction.h"
21 #include "llvm/CodeGen/MachineFrameInfo.h"
22
23 namespace llvm {
24
25 /// MipsFunctionInfo - This class is derived from MachineFunction private
26 /// Mips target-specific information for each MachineFunction.
27 class MipsFunctionInfo : public MachineFunctionInfo {
28
29 private:
30   MachineFunction& MF;
31   /// SRetReturnReg - Some subtargets require that sret lowering includes
32   /// returning the value of the returned struct in a register. This field
33   /// holds the virtual register into which the sret argument is passed.
34   unsigned SRetReturnReg;
35
36   /// GlobalBaseReg - keeps track of the virtual register initialized for
37   /// use as the global base register. This is used for PIC in some PIC
38   /// relocation models.
39   unsigned GlobalBaseReg;
40
41   /// VarArgsFrameIndex - FrameIndex for start of varargs area.
42   int VarArgsFrameIndex;
43
44   // Range of frame object indices.
45   // InArgFIRange: Range of indices of all frame objects created during call to
46   //               LowerFormalArguments.
47   // OutArgFIRange: Range of indices of all frame objects created during call to
48   //                LowerCall except for the frame object for restoring $gp. 
49   std::pair<int, int> InArgFIRange, OutArgFIRange;
50   int GPFI; // Index of the frame object for restoring $gp 
51   mutable int DynAllocFI; // Frame index of dynamically allocated stack area.   
52   unsigned MaxCallFrameSize;
53
54   /// AtomicFrameIndex - To implement atomic.swap and atomic.cmp.swap
55   /// intrinsics, it is necessary to use a temporary stack location.
56   /// This field holds the frame index of this location.
57   int AtomicFrameIndex;
58 public:
59   MipsFunctionInfo(MachineFunction& MF)
60   : MF(MF), SRetReturnReg(0), GlobalBaseReg(0),
61     VarArgsFrameIndex(0), InArgFIRange(std::make_pair(-1, 0)),
62     OutArgFIRange(std::make_pair(-1, 0)), GPFI(0), DynAllocFI(0),
63     MaxCallFrameSize(0), AtomicFrameIndex(-1)
64   {}
65
66   bool isInArgFI(int FI) const {
67     return FI <= InArgFIRange.first && FI >= InArgFIRange.second;
68   }
69   void setLastInArgFI(int FI) { InArgFIRange.second = FI; }
70
71   bool isOutArgFI(int FI) const { 
72     return FI <= OutArgFIRange.first && FI >= OutArgFIRange.second;
73   }
74   void extendOutArgFIRange(int FirstFI, int LastFI) {
75     if (!OutArgFIRange.second)
76       // this must be the first time this function was called.
77       OutArgFIRange.first = FirstFI;
78     OutArgFIRange.second = LastFI;
79   }
80
81   int getGPFI() const { return GPFI; }
82   void setGPFI(int FI) { GPFI = FI; }
83   bool needGPSaveRestore() const { return getGPFI(); }
84   bool isGPFI(int FI) const { return GPFI && GPFI == FI; }
85
86   // The first call to this function creates a frame object for dynamically
87   // allocated stack area.
88   int getDynAllocFI() const {
89     if (!DynAllocFI)
90       DynAllocFI = MF.getFrameInfo()->CreateFixedObject(4, 0, true);
91
92     return DynAllocFI;
93   }
94   bool isDynAllocFI(int FI) const { return DynAllocFI && DynAllocFI == FI; }
95
96   unsigned getSRetReturnReg() const { return SRetReturnReg; }
97   void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
98
99   unsigned getGlobalBaseReg() const { return GlobalBaseReg; }
100   void setGlobalBaseReg(unsigned Reg) { GlobalBaseReg = Reg; }
101
102   int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
103   void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
104
105   unsigned getMaxCallFrameSize() const { return MaxCallFrameSize; }
106   void setMaxCallFrameSize(unsigned S) { MaxCallFrameSize = S; }
107
108   int getAtomicFrameIndex() const { return AtomicFrameIndex; }
109   void setAtomicFrameIndex(int Index) { AtomicFrameIndex = Index; }
110 };
111
112 } // end of namespace llvm
113
114 #endif // MIPS_MACHINE_FUNCTION_INFO_H