blob: 0f9a1e0e6a31932452505f4cc9966061f2698182 [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 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
46 // On LowerFORMAL_ARGUMENTS the stack size is unknown,
47 // so the Stack Pointer Offset calculation of "not in
48 // register arguments" must be postponed to emitPrologue.
49 SmallVector<MipsFIHolder, 16> FnLoadArgs;
50 bool HasLoadArgs;
51
52 // When VarArgs, we must write registers back to caller
53 // stack, preserving on register arguments. Since the
54 // stack size is unknown on LowerFORMAL_ARGUMENTS,
55 // the Stack Pointer Offset calculation must be
56 // postponed to emitPrologue.
57 SmallVector<MipsFIHolder, 4> FnStoreVarArgs;
58 bool HasStoreVarArgs;
59
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000060public:
61 MipsFunctionInfo(MachineFunction& MF)
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000062 : FPStackOffset(0), RAStackOffset(0),
63 HasLoadArgs(false), HasStoreVarArgs(false)
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000064 {}
65
66 int getFPStackOffset() const { return FPStackOffset; }
67 void setFPStackOffset(int Off) { FPStackOffset = Off; }
68
69 int getRAStackOffset() const { return RAStackOffset; }
70 void setRAStackOffset(int Off) { RAStackOffset = Off; }
71
72 int getTopSavedRegOffset() const {
73 return (RAStackOffset > FPStackOffset) ?
74 (RAStackOffset) : (FPStackOffset);
75 }
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000076
77 bool hasLoadArgs() const { return HasLoadArgs; }
78 bool hasStoreVarArgs() const { return HasStoreVarArgs; }
79
80 void recordLoadArgsFI(int FI, int SPOffset) {
81 if (!HasLoadArgs) HasLoadArgs=true;
82 FnLoadArgs.push_back(MipsFIHolder(FI, SPOffset));
83 }
84 void recordStoreVarArgsFI(int FI, int SPOffset) {
85 if (!HasStoreVarArgs) HasStoreVarArgs=true;
86 FnStoreVarArgs.push_back(MipsFIHolder(FI, SPOffset));
87 }
88
89 void adjustLoadArgsFI(MachineFrameInfo *MFI) const {
90 if (!hasLoadArgs()) return;
91 for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i)
92 MFI->setObjectOffset( FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset );
93 }
94 void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const {
95 if (!hasStoreVarArgs()) return;
96 for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i)
97 MFI->setObjectOffset( FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset );
98 }
99
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +0000100};
101
102} // end of namespace llvm
103
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000104#endif // MIPS_MACHINE_FUNCTION_INFO_H