blob: 4c53fcb609a7c51a4a40e18835c9a5cec70a71dd [file] [log] [blame]
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +00001//===-- MipsMachineFunctionInfo.h - Private data used for Mips ----*- C++ -*-=//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +00007//
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
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000017#include "llvm/ADT/VectorExtras.h"
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000018#include "llvm/CodeGen/MachineFunction.h"
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000019#include "llvm/CodeGen/MachineFrameInfo.h"
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000020
21namespace llvm {
22
23/// MipsFunctionInfo - This class is derived from MachineFunction private
24/// Mips target-specific information for each MachineFunction.
25class MipsFunctionInfo : public MachineFunctionInfo {
26
27private:
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000028 /// Holds for each function where on the stack the Frame Pointer must be
29 /// saved.
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000030 int FPStackOffset;
31
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000032 /// Holds for each function where on the stack the Return Address must be
33 /// saved.
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000034 int RAStackOffset;
35
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000036 /// 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
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000046 /// When PIC is used the GP must be saved on the stack on the function
47 /// prologue and must be reloaded from this stack location after every
48 /// call. A reference to its stack location and frame index must be kept
49 /// to be used on emitPrologue and processFunctionBeforeFrameFinalized.
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000050 MipsFIHolder GPHolder;
51
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000052 // On LowerFORMAL_ARGUMENTS the stack size is unknown, so the Stack
53 // Pointer Offset calculation of "not in register arguments" must be
54 // postponed to emitPrologue.
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000055 SmallVector<MipsFIHolder, 16> FnLoadArgs;
56 bool HasLoadArgs;
57
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000058 // When VarArgs, we must write registers back to caller stack, preserving
59 // on register arguments. Since the stack size is unknown on
60 // LowerFORMAL_ARGUMENTS, the Stack Pointer Offset calculation must be
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000061 // postponed to emitPrologue.
62 SmallVector<MipsFIHolder, 4> FnStoreVarArgs;
63 bool HasStoreVarArgs;
64
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000065 /// SRetReturnReg - Some subtargets require that sret lowering includes
66 /// returning the value of the returned struct in a register. This field
67 /// holds the virtual register into which the sret argument is passed.
68 unsigned SRetReturnReg;
69
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000070public:
71 MipsFunctionInfo(MachineFunction& MF)
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000072 : FPStackOffset(0), RAStackOffset(0), GPHolder(-1,-1), HasLoadArgs(false),
73 HasStoreVarArgs(false), SRetReturnReg(0)
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000074 {}
75
76 int getFPStackOffset() const { return FPStackOffset; }
77 void setFPStackOffset(int Off) { FPStackOffset = Off; }
78
79 int getRAStackOffset() const { return RAStackOffset; }
80 void setRAStackOffset(int Off) { RAStackOffset = Off; }
81
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000082 int getGPStackOffset() const { return GPHolder.SPOffset; }
83 int getGPFI() const { return GPHolder.FI; }
84 void setGPStackOffset(int Off) { GPHolder.SPOffset = Off; }
85 void setGPFI(int FI) { GPHolder.FI = FI; }
Bruno Cardoso Lopes0a604002007-10-09 03:01:19 +000086
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000087 int getTopSavedRegOffset() const {
88 return (RAStackOffset > FPStackOffset) ?
89 (RAStackOffset) : (FPStackOffset);
90 }
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000091
92 bool hasLoadArgs() const { return HasLoadArgs; }
93 bool hasStoreVarArgs() const { return HasStoreVarArgs; }
94
95 void recordLoadArgsFI(int FI, int SPOffset) {
96 if (!HasLoadArgs) HasLoadArgs=true;
97 FnLoadArgs.push_back(MipsFIHolder(FI, SPOffset));
98 }
99 void recordStoreVarArgsFI(int FI, int SPOffset) {
100 if (!HasStoreVarArgs) HasStoreVarArgs=true;
101 FnStoreVarArgs.push_back(MipsFIHolder(FI, SPOffset));
102 }
103
104 void adjustLoadArgsFI(MachineFrameInfo *MFI) const {
105 if (!hasLoadArgs()) return;
106 for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i)
107 MFI->setObjectOffset( FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset );
108 }
109 void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const {
110 if (!hasStoreVarArgs()) return;
111 for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i)
112 MFI->setObjectOffset( FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset );
113 }
114
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000115 unsigned getSRetReturnReg() const { return SRetReturnReg; }
116 void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +0000117};
118
119} // end of namespace llvm
120
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000121#endif // MIPS_MACHINE_FUNCTION_INFO_H