blob: 2515aa0438a6d0231daa6274908f15f9d12f57af [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//
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
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:
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
Bruno Cardoso Lopes0a604002007-10-09 03:01:19 +000036 /// 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
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000041 /// 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
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000065public:
66 MipsFunctionInfo(MachineFunction& MF)
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000067 : FPStackOffset(0), RAStackOffset(0),
68 HasLoadArgs(false), HasStoreVarArgs(false)
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000069 {}
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
Bruno Cardoso Lopes0a604002007-10-09 03:01:19 +000077 int getGPStackOffset() const { return GPStackOffset; }
78 void setGPStackOffset(int Off) { GPStackOffset = Off; }
79
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000080 int getTopSavedRegOffset() const {
81 return (RAStackOffset > FPStackOffset) ?
82 (RAStackOffset) : (FPStackOffset);
83 }
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000084
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
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +0000108};
109
110} // end of namespace llvm
111
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000112#endif // MIPS_MACHINE_FUNCTION_INFO_H