Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 1 | //===-- 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 Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/VectorExtras.h" |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineFunction.h" |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 20 | |
| 21 | namespace llvm { |
| 22 | |
| 23 | /// MipsFunctionInfo - This class is derived from MachineFunction private |
| 24 | /// Mips target-specific information for each MachineFunction. |
| 25 | class MipsFunctionInfo : public MachineFunctionInfo { |
| 26 | |
| 27 | private: |
| 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 Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 36 | /// 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 Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame^] | 46 | /// 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 Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 53 | // 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 Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 67 | public: |
| 68 | MipsFunctionInfo(MachineFunction& MF) |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame^] | 69 | : FPStackOffset(0), RAStackOffset(0), GPHolder(-1,-1), |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 70 | HasLoadArgs(false), HasStoreVarArgs(false) |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 71 | {} |
| 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 Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame^] | 79 | 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 Lopes | 0a60400 | 2007-10-09 03:01:19 +0000 | [diff] [blame] | 83 | |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 84 | int getTopSavedRegOffset() const { |
| 85 | return (RAStackOffset > FPStackOffset) ? |
| 86 | (RAStackOffset) : (FPStackOffset); |
| 87 | } |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 88 | |
| 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 Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | } // end of namespace llvm |
| 115 | |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 116 | #endif // MIPS_MACHINE_FUNCTION_INFO_H |