LLVM API Documentation

MipsSubtarget.h
Go to the documentation of this file.
00001 //===-- MipsSubtarget.h - Define Subtarget for the 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 TargetSubtargetInfo.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef MIPSSUBTARGET_H
00015 #define MIPSSUBTARGET_H
00016 
00017 #include "MCTargetDesc/MipsReginfo.h"
00018 #include "llvm/MC/MCInstrItineraries.h"
00019 #include "llvm/Support/ErrorHandling.h"
00020 #include "llvm/Target/TargetSubtargetInfo.h"
00021 
00022 #include <string>
00023 
00024 #define GET_SUBTARGETINFO_HEADER
00025 #include "MipsGenSubtargetInfo.inc"
00026 
00027 namespace llvm {
00028 class StringRef;
00029 
00030 class MipsTargetMachine;
00031 
00032 class MipsSubtarget : public MipsGenSubtargetInfo {
00033   virtual void anchor();
00034 
00035 public:
00036   // NOTE: O64 will not be supported.
00037   enum MipsABIEnum {
00038     UnknownABI, O32, N32, N64, EABI
00039   };
00040 
00041 protected:
00042 
00043   enum MipsArchEnum {
00044     Mips32, Mips32r2, Mips64, Mips64r2
00045   };
00046 
00047   // Mips architecture version
00048   MipsArchEnum MipsArchVersion;
00049 
00050   // Mips supported ABIs
00051   MipsABIEnum MipsABI;
00052 
00053   // IsLittle - The target is Little Endian
00054   bool IsLittle;
00055 
00056   // IsSingleFloat - The target only supports single precision float
00057   // point operations. This enable the target to use all 32 32-bit
00058   // floating point registers instead of only using even ones.
00059   bool IsSingleFloat;
00060 
00061   // IsFP64bit - The target processor has 64-bit floating point registers.
00062   bool IsFP64bit;
00063 
00064   // IsFP64bit - General-purpose registers are 64 bits wide
00065   bool IsGP64bit;
00066 
00067   // HasVFPU - Processor has a vector floating point unit.
00068   bool HasVFPU;
00069 
00070   // isLinux - Target system is Linux. Is false we consider ELFOS for now.
00071   bool IsLinux;
00072 
00073   // UseSmallSection - Small section is used.
00074   bool UseSmallSection;
00075 
00076   /// Features related to the presence of specific instructions.
00077 
00078   // HasSEInReg - SEB and SEH (signext in register) instructions.
00079   bool HasSEInReg;
00080 
00081   // HasCondMov - Conditional mov (MOVZ, MOVN) instructions.
00082   bool HasCondMov;
00083 
00084   // HasSwap - Byte and half swap instructions.
00085   bool HasSwap;
00086 
00087   // HasBitCount - Count leading '1' and '0' bits.
00088   bool HasBitCount;
00089 
00090   // HasFPIdx -- Floating point indexed load/store instructions.
00091   bool HasFPIdx;
00092 
00093   // InMips16 -- can process Mips16 instructions
00094   bool InMips16Mode;
00095 
00096   // Mips16 hard float
00097   bool InMips16HardFloat;
00098 
00099   // PreviousInMips16 -- the function we just processed was in Mips 16 Mode
00100   bool PreviousInMips16Mode;
00101 
00102   // InMicroMips -- can process MicroMips instructions
00103   bool InMicroMipsMode;
00104 
00105   // HasDSP, HasDSPR2 -- supports DSP ASE.
00106   bool HasDSP, HasDSPR2;
00107 
00108   // Allow mixed Mips16 and Mips32 in one source file
00109   bool AllowMixed16_32;
00110 
00111   // Optimize for space by compiling all functions as Mips 16 unless
00112   // it needs floating point. Functions needing floating point are
00113   // compiled as Mips32
00114   bool Os16;
00115 
00116   InstrItineraryData InstrItins;
00117 
00118   // The instance to the register info section object
00119   MipsReginfo MRI;
00120 
00121   // Relocation Model
00122   Reloc::Model RM;
00123 
00124   // We can override the determination of whether we are in mips16 mode
00125   // as from the command line
00126   enum {NoOverride, Mips16Override, NoMips16Override} OverrideMode;
00127 
00128   MipsTargetMachine *TM;
00129 
00130 public:
00131   virtual bool enablePostRAScheduler(CodeGenOpt::Level OptLevel,
00132                                      AntiDepBreakMode& Mode,
00133                                      RegClassVector& CriticalPathRCs) const;
00134 
00135   /// Only O32 and EABI supported right now.
00136   bool isABI_EABI() const { return MipsABI == EABI; }
00137   bool isABI_N64() const { return MipsABI == N64; }
00138   bool isABI_N32() const { return MipsABI == N32; }
00139   bool isABI_O32() const { return MipsABI == O32; }
00140   unsigned getTargetABI() const { return MipsABI; }
00141 
00142   /// This constructor initializes the data members to match that
00143   /// of the specified triple.
00144   MipsSubtarget(const std::string &TT, const std::string &CPU,
00145                 const std::string &FS, bool little, Reloc::Model RM,
00146                 MipsTargetMachine *TM);
00147 
00148   /// ParseSubtargetFeatures - Parses features string setting specified
00149   /// subtarget options.  Definition of function is auto generated by tblgen.
00150   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
00151 
00152   bool hasMips32() const { return MipsArchVersion >= Mips32; }
00153   bool hasMips32r2() const { return MipsArchVersion == Mips32r2 ||
00154                                    MipsArchVersion == Mips64r2; }
00155   bool hasMips64() const { return MipsArchVersion >= Mips64; }
00156   bool hasMips64r2() const { return MipsArchVersion == Mips64r2; }
00157 
00158   bool isLittle() const { return IsLittle; }
00159   bool isFP64bit() const { return IsFP64bit; }
00160   bool isGP64bit() const { return IsGP64bit; }
00161   bool isGP32bit() const { return !IsGP64bit; }
00162   bool isSingleFloat() const { return IsSingleFloat; }
00163   bool isNotSingleFloat() const { return !IsSingleFloat; }
00164   bool hasVFPU() const { return HasVFPU; }
00165   bool inMips16Mode() const {
00166     switch (OverrideMode) {
00167     case NoOverride:
00168       return InMips16Mode;
00169     case Mips16Override:
00170       return true;
00171     case NoMips16Override:
00172       return false;
00173     }
00174     llvm_unreachable("Unexpected mode");
00175   }
00176   bool inMips16ModeDefault() const {
00177     return InMips16Mode;
00178   }
00179   bool inMips16HardFloat() const {
00180     return inMips16Mode() && InMips16HardFloat;
00181   }
00182   bool inMicroMipsMode() const { return InMicroMipsMode; }
00183   bool hasDSP() const { return HasDSP; }
00184   bool hasDSPR2() const { return HasDSPR2; }
00185   bool isLinux() const { return IsLinux; }
00186   bool useSmallSection() const { return UseSmallSection; }
00187 
00188   bool hasStandardEncoding() const { return !inMips16Mode(); }
00189 
00190   /// Features related to the presence of specific instructions.
00191   bool hasSEInReg()   const { return HasSEInReg; }
00192   bool hasCondMov()   const { return HasCondMov; }
00193   bool hasSwap()      const { return HasSwap; }
00194   bool hasBitCount()  const { return HasBitCount; }
00195   bool hasFPIdx()     const { return HasFPIdx; }
00196 
00197   bool allowMixed16_32() const { return inMips16ModeDefault() |
00198                                         AllowMixed16_32;}
00199 
00200   bool os16() const { return Os16;};
00201 
00202   // Grab MipsRegInfo object
00203   const MipsReginfo &getMReginfo() const { return MRI; }
00204 
00205   // Grab relocation model
00206   Reloc::Model getRelocationModel() const {return RM;}
00207 
00208   /// \brief Reset the subtarget for the Mips target.
00209   void resetSubtarget(MachineFunction *MF);
00210 
00211 
00212 };
00213 } // End llvm namespace
00214 
00215 #endif