blob: d4f4312058a3a267fef8ce2b5f33f6f2d0d83f2f [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
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000046 /// When PIC is used the GP must be saved on the stack
47 /// on the function prologue and must be reloaded from this
48 /// stack location after every call. A reference to its stack
49 /// location and frame index must be kept to be used on
50 /// emitPrologue and processFunctionBeforeFrameFinalized.
51 MipsFIHolder GPHolder;
52
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000053 // On LowerFORMAL_ARGUMENTS the stack size is unknown,
54 // so the Stack Pointer Offset calculation of "not in
55 // register arguments" must be postponed to emitPrologue.
56 SmallVector<MipsFIHolder, 16> FnLoadArgs;
57 bool HasLoadArgs;
58
59 // When VarArgs, we must write registers back to caller
60 // stack, preserving on register arguments. Since the
61 // stack size is unknown on LowerFORMAL_ARGUMENTS,
62 // the Stack Pointer Offset calculation must be
63 // postponed to emitPrologue.
64 SmallVector<MipsFIHolder, 4> FnStoreVarArgs;
65 bool HasStoreVarArgs;
66
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000067public:
68 MipsFunctionInfo(MachineFunction& MF)
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000069 : FPStackOffset(0), RAStackOffset(0), GPHolder(-1,-1),
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000070 HasLoadArgs(false), HasStoreVarArgs(false)
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000071 {}
72
73 int getFPStackOffset() const { return FPStackOffset; }
74 void setFPStackOffset(int Off) { FPStackOffset = Off; }
75
76 int getRAStackOffset() const { return RAStackOffset; }
77 void setRAStackOffset(int Off) { RAStackOffset = Off; }
78
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000079 int getGPStackOffset() const { return GPHolder.SPOffset; }
80 int getGPFI() const { return GPHolder.FI; }
81 void setGPStackOffset(int Off) { GPHolder.SPOffset = Off; }
82 void setGPFI(int FI) { GPHolder.FI = FI; }
Bruno Cardoso Lopes0a604002007-10-09 03:01:19 +000083
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +000084 int getTopSavedRegOffset() const {
85 return (RAStackOffset > FPStackOffset) ?
86 (RAStackOffset) : (FPStackOffset);
87 }
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +000088
89 bool hasLoadArgs() const { return HasLoadArgs; }
90 bool hasStoreVarArgs() const { return HasStoreVarArgs; }
91
92 void recordLoadArgsFI(int FI, int SPOffset) {
93 if (!HasLoadArgs) HasLoadArgs=true;
94 FnLoadArgs.push_back(MipsFIHolder(FI, SPOffset));
95 }
96 void recordStoreVarArgsFI(int FI, int SPOffset) {
97 if (!HasStoreVarArgs) HasStoreVarArgs=true;
98 FnStoreVarArgs.push_back(MipsFIHolder(FI, SPOffset));
99 }
100
101 void adjustLoadArgsFI(MachineFrameInfo *MFI) const {
102 if (!hasLoadArgs()) return;
103 for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i)
104 MFI->setObjectOffset( FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset );
105 }
106 void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const {
107 if (!hasStoreVarArgs()) return;
108 for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i)
109 MFI->setObjectOffset( FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset );
110 }
111
Bruno Cardoso Lopes4215a592007-07-11 22:44:21 +0000112};
113
114} // end of namespace llvm
115
Bruno Cardoso Lopes2d4575e2007-08-28 05:04:41 +0000116#endif // MIPS_MACHINE_FUNCTION_INFO_H