LLVM API Documentation

MipsMachineFunction.h

Go to the documentation of this file.
00001 //===-- MipsMachineFunctionInfo.h - Private data used for Mips ----*- C++ -*-=//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file declares the Mips specific subclass of MachineFunctionInfo.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef MIPS_MACHINE_FUNCTION_INFO_H
00015 #define MIPS_MACHINE_FUNCTION_INFO_H
00016 
00017 #include "llvm/ADT/SmallVector.h"
00018 #include "llvm/ADT/VectorExtras.h"
00019 #include "llvm/CodeGen/MachineFunction.h"
00020 #include "llvm/CodeGen/MachineFrameInfo.h"
00021 
00022 namespace llvm {
00023 
00024 /// MipsFunctionInfo - This class is derived from MachineFunction private
00025 /// Mips target-specific information for each MachineFunction.
00026 class MipsFunctionInfo : public MachineFunctionInfo {
00027 
00028 private:
00029   /// Holds for each function where on the stack the Frame Pointer must be 
00030   /// saved. This is used on Prologue and Epilogue to emit FP save/restore
00031   int FPStackOffset;
00032 
00033   /// Holds for each function where on the stack the Return Address must be 
00034   /// saved. This is used on Prologue and Epilogue to emit RA save/restore
00035   int RAStackOffset;
00036 
00037   /// At each function entry, two special bitmask directives must be emitted
00038   /// to help debugging, for CPU and FPU callee saved registers. Both need
00039   /// the negative offset from the final stack size and its higher registers
00040   /// location on the stack.
00041   int CPUTopSavedRegOff;
00042   int FPUTopSavedRegOff;
00043 
00044   /// MipsFIHolder - Holds a FrameIndex and it's Stack Pointer Offset
00045   struct MipsFIHolder {
00046 
00047     int FI;
00048     int SPOffset;
00049 
00050     MipsFIHolder(int FrameIndex, int StackPointerOffset)
00051       : FI(FrameIndex), SPOffset(StackPointerOffset) {}
00052   };
00053 
00054   /// When PIC is used the GP must be saved on the stack on the function 
00055   /// prologue and must be reloaded from this stack location after every 
00056   /// call. A reference to its stack location and frame index must be kept 
00057   /// to be used on emitPrologue and processFunctionBeforeFrameFinalized.
00058   MipsFIHolder GPHolder;
00059 
00060   /// On LowerFORMAL_ARGUMENTS the stack size is unknown, so the Stack 
00061   /// Pointer Offset calculation of "not in register arguments" must be 
00062   /// postponed to emitPrologue. 
00063   SmallVector<MipsFIHolder, 16> FnLoadArgs;
00064   bool HasLoadArgs;
00065 
00066   // When VarArgs, we must write registers back to caller stack, preserving 
00067   // on register arguments. Since the stack size is unknown on 
00068   // LowerFORMAL_ARGUMENTS, the Stack Pointer Offset calculation must be
00069   // postponed to emitPrologue. 
00070   SmallVector<MipsFIHolder, 4> FnStoreVarArgs;
00071   bool HasStoreVarArgs;
00072 
00073   /// SRetReturnReg - Some subtargets require that sret lowering includes
00074   /// returning the value of the returned struct in a register. This field
00075   /// holds the virtual register into which the sret argument is passed.
00076   unsigned SRetReturnReg;
00077 
00078 public:
00079   MipsFunctionInfo(MachineFunction& MF) 
00080   : FPStackOffset(0), RAStackOffset(0), CPUTopSavedRegOff(0), 
00081     FPUTopSavedRegOff(0), GPHolder(-1,-1), HasLoadArgs(false), 
00082     HasStoreVarArgs(false), SRetReturnReg(0)
00083   {}
00084 
00085   int getFPStackOffset() const { return FPStackOffset; }
00086   void setFPStackOffset(int Off) { FPStackOffset = Off; }
00087 
00088   int getRAStackOffset() const { return RAStackOffset; }
00089   void setRAStackOffset(int Off) { RAStackOffset = Off; }
00090 
00091   int getCPUTopSavedRegOff() const { return CPUTopSavedRegOff; }
00092   void setCPUTopSavedRegOff(int Off) { CPUTopSavedRegOff = Off; }
00093 
00094   int getFPUTopSavedRegOff() const { return FPUTopSavedRegOff; }
00095   void setFPUTopSavedRegOff(int Off) { FPUTopSavedRegOff = Off; }
00096 
00097   int getGPStackOffset() const { return GPHolder.SPOffset; }
00098   int getGPFI() const { return GPHolder.FI; }
00099   void setGPStackOffset(int Off) { GPHolder.SPOffset = Off; }
00100   void setGPFI(int FI) { GPHolder.FI = FI; }
00101 
00102   bool hasLoadArgs() const { return HasLoadArgs; }
00103   bool hasStoreVarArgs() const { return HasStoreVarArgs; } 
00104 
00105   void recordLoadArgsFI(int FI, int SPOffset) {
00106     if (!HasLoadArgs) HasLoadArgs=true;
00107     FnLoadArgs.push_back(MipsFIHolder(FI, SPOffset));
00108   }
00109   void recordStoreVarArgsFI(int FI, int SPOffset) {
00110     if (!HasStoreVarArgs) HasStoreVarArgs=true;
00111     FnStoreVarArgs.push_back(MipsFIHolder(FI, SPOffset));
00112   }
00113 
00114   void adjustLoadArgsFI(MachineFrameInfo *MFI) const {
00115     if (!hasLoadArgs()) return;
00116     for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i) 
00117       MFI->setObjectOffset( FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset );
00118   }
00119   void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const {
00120     if (!hasStoreVarArgs()) return; 
00121     for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i) 
00122       MFI->setObjectOffset( FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset );
00123   }
00124 
00125   unsigned getSRetReturnReg() const { return SRetReturnReg; }
00126   void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
00127 };
00128 
00129 } // end of namespace llvm
00130 
00131 #endif // MIPS_MACHINE_FUNCTION_INFO_H



This web site is hosted by the Computer Science Department at the University of Illinois at Urbana-Champaign.