LLVM API Documentation

MipsABIFlagsSection.h
Go to the documentation of this file.
00001 //===-- MipsABIFlagsSection.h - Mips ELF ABI Flags Section -----*- 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 #ifndef LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSABIFLAGSSECTION_H
00011 #define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSABIFLAGSSECTION_H
00012 
00013 #include "llvm/MC/MCStreamer.h"
00014 
00015 namespace llvm {
00016 
00017 class MCStreamer;
00018 
00019 struct MipsABIFlagsSection {
00020   // Values for the xxx_size bytes of an ABI flags structure.
00021   enum AFL_REG {
00022     AFL_REG_NONE = 0x00, // No registers.
00023     AFL_REG_32 = 0x01,   // 32-bit registers.
00024     AFL_REG_64 = 0x02,   // 64-bit registers.
00025     AFL_REG_128 = 0x03   // 128-bit registers.
00026   };
00027 
00028   // Masks for the ases word of an ABI flags structure.
00029   enum AFL_ASE {
00030     AFL_ASE_DSP = 0x00000001,       // DSP ASE.
00031     AFL_ASE_DSPR2 = 0x00000002,     // DSP R2 ASE.
00032     AFL_ASE_EVA = 0x00000004,       // Enhanced VA Scheme.
00033     AFL_ASE_MCU = 0x00000008,       // MCU (MicroController) ASE.
00034     AFL_ASE_MDMX = 0x00000010,      // MDMX ASE.
00035     AFL_ASE_MIPS3D = 0x00000020,    // MIPS-3D ASE.
00036     AFL_ASE_MT = 0x00000040,        // MT ASE.
00037     AFL_ASE_SMARTMIPS = 0x00000080, // SmartMIPS ASE.
00038     AFL_ASE_VIRT = 0x00000100,      // VZ ASE.
00039     AFL_ASE_MSA = 0x00000200,       // MSA ASE.
00040     AFL_ASE_MIPS16 = 0x00000400,    // MIPS16 ASE.
00041     AFL_ASE_MICROMIPS = 0x00000800, // MICROMIPS ASE.
00042     AFL_ASE_XPA = 0x00001000        // XPA ASE.
00043   };
00044 
00045   // Values for the isa_ext word of an ABI flags structure.
00046   enum AFL_EXT {
00047     AFL_EXT_XLR = 1,          // RMI Xlr instruction.
00048     AFL_EXT_OCTEON2 = 2,      // Cavium Networks Octeon2.
00049     AFL_EXT_OCTEONP = 3,      // Cavium Networks OcteonP.
00050     AFL_EXT_LOONGSON_3A = 4,  // Loongson 3A.
00051     AFL_EXT_OCTEON = 5,       // Cavium Networks Octeon.
00052     AFL_EXT_5900 = 6,         // MIPS R5900 instruction.
00053     AFL_EXT_4650 = 7,         // MIPS R4650 instruction.
00054     AFL_EXT_4010 = 8,         // LSI R4010 instruction.
00055     AFL_EXT_4100 = 9,         // NEC VR4100 instruction.
00056     AFL_EXT_3900 = 10,        // Toshiba R3900 instruction.
00057     AFL_EXT_10000 = 11,       // MIPS R10000 instruction.
00058     AFL_EXT_SB1 = 12,         // Broadcom SB-1 instruction.
00059     AFL_EXT_4111 = 13,        // NEC VR4111/VR4181 instruction.
00060     AFL_EXT_4120 = 14,        // NEC VR4120 instruction.
00061     AFL_EXT_5400 = 15,        // NEC VR5400 instruction.
00062     AFL_EXT_5500 = 16,        // NEC VR5500 instruction.
00063     AFL_EXT_LOONGSON_2E = 17, // ST Microelectronics Loongson 2E.
00064     AFL_EXT_LOONGSON_2F = 18  // ST Microelectronics Loongson 2F.
00065   };
00066 
00067   // Values for the fp_abi word of an ABI flags structure.
00068   enum Val_GNU_MIPS_ABI {
00069     Val_GNU_MIPS_ABI_FP_ANY = 0,
00070     Val_GNU_MIPS_ABI_FP_DOUBLE = 1,
00071     Val_GNU_MIPS_ABI_FP_XX = 5,
00072     Val_GNU_MIPS_ABI_FP_64 = 6,
00073     Val_GNU_MIPS_ABI_FP_64A = 7
00074   };
00075 
00076   enum AFL_FLAGS1 {
00077     AFL_FLAGS1_ODDSPREG = 1
00078   };
00079 
00080   // Internal representation of the values used in .module fp=value
00081   enum class FpABIKind { ANY, XX, S32, S64 };
00082 
00083   // Version of flags structure.
00084   uint16_t Version;
00085   // The level of the ISA: 1-5, 32, 64.
00086   uint8_t ISALevel;
00087   // The revision of ISA: 0 for MIPS V and below, 1-n otherwise.
00088   uint8_t ISARevision;
00089   // The size of general purpose registers.
00090   AFL_REG GPRSize;
00091   // The size of co-processor 1 registers.
00092   AFL_REG CPR1Size;
00093   // The size of co-processor 2 registers.
00094   AFL_REG CPR2Size;
00095   // Processor-specific extension.
00096   uint32_t ISAExtensionSet;
00097   // Mask of ASEs used.
00098   uint32_t ASESet;
00099 
00100   bool OddSPReg;
00101 
00102   bool Is32BitABI;
00103 
00104 protected:
00105   // The floating-point ABI.
00106   FpABIKind FpABI;
00107 
00108 public:
00109   MipsABIFlagsSection()
00110       : Version(0), ISALevel(0), ISARevision(0), GPRSize(AFL_REG_NONE),
00111         CPR1Size(AFL_REG_NONE), CPR2Size(AFL_REG_NONE), ISAExtensionSet(0),
00112         ASESet(0), OddSPReg(false), Is32BitABI(false), FpABI(FpABIKind::ANY) {}
00113 
00114   uint16_t getVersionValue() { return (uint16_t)Version; }
00115   uint8_t getISALevelValue() { return (uint8_t)ISALevel; }
00116   uint8_t getISARevisionValue() { return (uint8_t)ISARevision; }
00117   uint8_t getGPRSizeValue() { return (uint8_t)GPRSize; }
00118   uint8_t getCPR1SizeValue();
00119   uint8_t getCPR2SizeValue() { return (uint8_t)CPR2Size; }
00120   uint8_t getFpABIValue();
00121   uint32_t getISAExtensionSetValue() { return (uint32_t)ISAExtensionSet; }
00122   uint32_t getASESetValue() { return (uint32_t)ASESet; }
00123 
00124   uint32_t getFlags1Value() {
00125     uint32_t Value = 0;
00126 
00127     if (OddSPReg)
00128       Value |= (uint32_t)AFL_FLAGS1_ODDSPREG;
00129 
00130     return Value;
00131   }
00132 
00133   uint32_t getFlags2Value() { return 0; }
00134 
00135   FpABIKind getFpABI() { return FpABI; }
00136   void setFpABI(FpABIKind Value, bool IsABI32Bit) {
00137     FpABI = Value;
00138     Is32BitABI = IsABI32Bit;
00139   }
00140   StringRef getFpABIString(FpABIKind Value);
00141 
00142   template <class PredicateLibrary>
00143   void setISALevelAndRevisionFromPredicates(const PredicateLibrary &P) {
00144     if (P.hasMips64()) {
00145       ISALevel = 64;
00146       if (P.hasMips64r6())
00147         ISARevision = 6;
00148       else if (P.hasMips64r2())
00149         ISARevision = 2;
00150       else
00151         ISARevision = 1;
00152     } else if (P.hasMips32()) {
00153       ISALevel = 32;
00154       if (P.hasMips32r6())
00155         ISARevision = 6;
00156       else if (P.hasMips32r2())
00157         ISARevision = 2;
00158       else
00159         ISARevision = 1;
00160     } else {
00161       ISARevision = 0;
00162       if (P.hasMips5())
00163         ISALevel = 5;
00164       else if (P.hasMips4())
00165         ISALevel = 4;
00166       else if (P.hasMips3())
00167         ISALevel = 3;
00168       else if (P.hasMips2())
00169         ISALevel = 2;
00170       else if (P.hasMips1())
00171         ISALevel = 1;
00172       else
00173         llvm_unreachable("Unknown ISA level!");
00174     }
00175   }
00176 
00177   template <class PredicateLibrary>
00178   void setGPRSizeFromPredicates(const PredicateLibrary &P) {
00179     GPRSize = P.isGP64bit() ? AFL_REG_64 : AFL_REG_32;
00180   }
00181 
00182   template <class PredicateLibrary>
00183   void setCPR1SizeFromPredicates(const PredicateLibrary &P) {
00184     if (P.abiUsesSoftFloat())
00185       CPR1Size = AFL_REG_NONE;
00186     else if (P.hasMSA())
00187       CPR1Size = AFL_REG_128;
00188     else
00189       CPR1Size = P.isFP64bit() ? AFL_REG_64 : AFL_REG_32;
00190   }
00191 
00192   template <class PredicateLibrary>
00193   void setASESetFromPredicates(const PredicateLibrary &P) {
00194     ASESet = 0;
00195     if (P.hasDSP())
00196       ASESet |= AFL_ASE_DSP;
00197     if (P.hasDSPR2())
00198       ASESet |= AFL_ASE_DSPR2;
00199     if (P.hasMSA())
00200       ASESet |= AFL_ASE_MSA;
00201     if (P.inMicroMipsMode())
00202       ASESet |= AFL_ASE_MICROMIPS;
00203     if (P.inMips16Mode())
00204       ASESet |= AFL_ASE_MIPS16;
00205   }
00206 
00207   template <class PredicateLibrary>
00208   void setFpAbiFromPredicates(const PredicateLibrary &P) {
00209     Is32BitABI = P.isABI_O32();
00210 
00211     FpABI = FpABIKind::ANY;
00212     if (P.isABI_N32() || P.isABI_N64())
00213       FpABI = FpABIKind::S64;
00214     else if (P.isABI_O32()) {
00215       if (P.isABI_FPXX())
00216         FpABI = FpABIKind::XX;
00217       else if (P.isFP64bit())
00218         FpABI = FpABIKind::S64;
00219       else
00220         FpABI = FpABIKind::S32;
00221     }
00222   }
00223 
00224   template <class PredicateLibrary>
00225   void setAllFromPredicates(const PredicateLibrary &P) {
00226     setISALevelAndRevisionFromPredicates(P);
00227     setGPRSizeFromPredicates(P);
00228     setCPR1SizeFromPredicates(P);
00229     setASESetFromPredicates(P);
00230     setFpAbiFromPredicates(P);
00231     OddSPReg = P.useOddSPReg();
00232   }
00233 };
00234 
00235 MCStreamer &operator<<(MCStreamer &OS, MipsABIFlagsSection &ABIFlagsSection);
00236 }
00237 
00238 #endif