1 //===-- MipsSubtarget.h - Define Subtarget for the Mips ---------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file declares the Mips specific subclass of TargetSubtargetInfo. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef MIPSSUBTARGET_H 15 #define MIPSSUBTARGET_H 16 17 #include "MipsFrameLowering.h" 18 #include "MipsISelLowering.h" 19 #include "MipsInstrInfo.h" 20 #include "MipsJITInfo.h" 21 #include "MipsSelectionDAGInfo.h" 22 #include "llvm/IR/DataLayout.h" 23 #include "llvm/MC/MCInstrItineraries.h" 24 #include "llvm/Support/ErrorHandling.h" 25 #include "llvm/Target/TargetSubtargetInfo.h" 26 #include <string> 27 28 #define GET_SUBTARGETINFO_HEADER 29 #include "MipsGenSubtargetInfo.inc" 30 31 namespace llvm { 32 class StringRef; 33 34 class MipsTargetMachine; 35 36 class MipsSubtarget : public MipsGenSubtargetInfo { 37 virtual void anchor(); 38 39 public: 40 // NOTE: O64 will not be supported. 41 enum MipsABIEnum { 42 UnknownABI, O32, N32, N64, EABI 43 }; 44 45 protected: 46 enum MipsArchEnum { 47 Mips1, Mips2, Mips32, Mips32r2, Mips32r6, Mips3, Mips4, Mips5, Mips64, 48 Mips64r2, Mips64r6 49 }; 50 51 // Mips architecture version 52 MipsArchEnum MipsArchVersion; 53 54 // Mips supported ABIs 55 MipsABIEnum MipsABI; 56 57 // IsLittle - The target is Little Endian 58 bool IsLittle; 59 60 // IsSingleFloat - The target only supports single precision float 61 // point operations. This enable the target to use all 32 32-bit 62 // floating point registers instead of only using even ones. 63 bool IsSingleFloat; 64 65 // IsFPXX - MIPS O32 modeless ABI. 66 bool IsFPXX; 67 68 // IsFP64bit - The target processor has 64-bit floating point registers. 69 bool IsFP64bit; 70 71 /// Are odd single-precision registers permitted? 72 /// This corresponds to -modd-spreg and -mno-odd-spreg 73 bool UseOddSPReg; 74 75 // IsNan2008 - IEEE 754-2008 NaN encoding. 76 bool IsNaN2008bit; 77 78 // IsFP64bit - General-purpose registers are 64 bits wide 79 bool IsGP64bit; 80 81 // HasVFPU - Processor has a vector floating point unit. 82 bool HasVFPU; 83 84 // CPU supports cnMIPS (Cavium Networks Octeon CPU). 85 bool HasCnMips; 86 87 // isLinux - Target system is Linux. Is false we consider ELFOS for now. 88 bool IsLinux; 89 90 // UseSmallSection - Small section is used. 91 bool UseSmallSection; 92 93 /// Features related to the presence of specific instructions. 94 95 // HasMips3_32 - The subset of MIPS-III instructions added to MIPS32 96 bool HasMips3_32; 97 98 // HasMips3_32r2 - The subset of MIPS-III instructions added to MIPS32r2 99 bool HasMips3_32r2; 100 101 // HasMips4_32 - Has the subset of MIPS-IV present in MIPS32 102 bool HasMips4_32; 103 104 // HasMips4_32r2 - Has the subset of MIPS-IV present in MIPS32r2 105 bool HasMips4_32r2; 106 107 // HasMips5_32r2 - Has the subset of MIPS-V present in MIPS32r2 108 bool HasMips5_32r2; 109 110 // InMips16 -- can process Mips16 instructions 111 bool InMips16Mode; 112 113 // Mips16 hard float 114 bool InMips16HardFloat; 115 116 // PreviousInMips16 -- the function we just processed was in Mips 16 Mode 117 bool PreviousInMips16Mode; 118 119 // InMicroMips -- can process MicroMips instructions 120 bool InMicroMipsMode; 121 122 // HasDSP, HasDSPR2 -- supports DSP ASE. 123 bool HasDSP, HasDSPR2; 124 125 // Allow mixed Mips16 and Mips32 in one source file 126 bool AllowMixed16_32; 127 128 // Optimize for space by compiling all functions as Mips 16 unless 129 // it needs floating point. Functions needing floating point are 130 // compiled as Mips32 131 bool Os16; 132 133 // HasMSA -- supports MSA ASE. 134 bool HasMSA; 135 136 InstrItineraryData InstrItins; 137 138 // We can override the determination of whether we are in mips16 mode 139 // as from the command line 140 enum {NoOverride, Mips16Override, NoMips16Override} OverrideMode; 141 142 MipsTargetMachine *TM; 143 144 Triple TargetTriple; 145 146 const DataLayout DL; // Calculates type size & alignment 147 const MipsSelectionDAGInfo TSInfo; 148 MipsJITInfo JITInfo; 149 std::unique_ptr<const MipsInstrInfo> InstrInfo; 150 std::unique_ptr<const MipsFrameLowering> FrameLowering; 151 std::unique_ptr<const MipsTargetLowering> TLInfo; 152 153 public: 154 /// This overrides the PostRAScheduler bit in the SchedModel for each CPU. 155 bool enablePostMachineScheduler() const override; 156 void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const override; 157 CodeGenOpt::Level getOptLevelToEnablePostRAScheduler() const override; 158 159 /// Only O32 and EABI supported right now. 160 bool isABI_EABI() const { return MipsABI == EABI; } 161 bool isABI_N64() const { return MipsABI == N64; } 162 bool isABI_N32() const { return MipsABI == N32; } 163 bool isABI_O32() const { return MipsABI == O32; } 164 bool isABI_FPXX() const { return isABI_O32() && IsFPXX; } 165 unsigned getTargetABI() const { return MipsABI; } 166 167 /// This constructor initializes the data members to match that 168 /// of the specified triple. 169 MipsSubtarget(const std::string &TT, const std::string &CPU, 170 const std::string &FS, bool little, MipsTargetMachine *TM); 171 172 /// ParseSubtargetFeatures - Parses features string setting specified 173 /// subtarget options. Definition of function is auto generated by tblgen. 174 void ParseSubtargetFeatures(StringRef CPU, StringRef FS); 175 176 bool hasMips1() const { return MipsArchVersion >= Mips1; } 177 bool hasMips2() const { return MipsArchVersion >= Mips2; } 178 bool hasMips3() const { return MipsArchVersion >= Mips3; } 179 bool hasMips4() const { return MipsArchVersion >= Mips4; } 180 bool hasMips5() const { return MipsArchVersion >= Mips5; } 181 bool hasMips4_32() const { return HasMips4_32; } 182 bool hasMips4_32r2() const { return HasMips4_32r2; } 183 bool hasMips32() const { 184 return MipsArchVersion >= Mips32 && MipsArchVersion != Mips3 && 185 MipsArchVersion != Mips4 && MipsArchVersion != Mips5; 186 } 187 bool hasMips32r2() const { 188 return MipsArchVersion == Mips32r2 || MipsArchVersion == Mips32r6 || 189 MipsArchVersion == Mips64r2 || MipsArchVersion == Mips64r6; 190 } 191 bool hasMips32r6() const { 192 return MipsArchVersion == Mips32r6 || MipsArchVersion == Mips64r6; 193 } 194 bool hasMips64() const { return MipsArchVersion >= Mips64; } 195 bool hasMips64r2() const { 196 return MipsArchVersion == Mips64r2 || MipsArchVersion == Mips64r6; 197 } 198 bool hasMips64r6() const { return MipsArchVersion == Mips64r6; } 199 200 bool hasCnMips() const { return HasCnMips; } 201 202 bool isLittle() const { return IsLittle; } 203 bool isFPXX() const { return IsFPXX; } 204 bool isFP64bit() const { return IsFP64bit; } 205 bool useOddSPReg() const { return UseOddSPReg; } 206 bool isNaN2008() const { return IsNaN2008bit; } 207 bool isNotFP64bit() const { return !IsFP64bit; } 208 bool isGP64bit() const { return IsGP64bit; } 209 bool isGP32bit() const { return !IsGP64bit; } 210 bool isSingleFloat() const { return IsSingleFloat; } 211 bool isNotSingleFloat() const { return !IsSingleFloat; } 212 bool hasVFPU() const { return HasVFPU; } 213 bool inMips16Mode() const { return InMips16Mode; } 214 bool inMips16ModeDefault() const { 215 return InMips16Mode; 216 } 217 // Hard float for mips16 means essentially to compile as soft float 218 // but to use a runtime library for soft float that is written with 219 // native mips32 floating point instructions (those runtime routines 220 // run in mips32 hard float mode). 221 bool inMips16HardFloat() const { 222 return inMips16Mode() && InMips16HardFloat; 223 } 224 bool inMicroMipsMode() const { return InMicroMipsMode; } 225 bool hasDSP() const { return HasDSP; } 226 bool hasDSPR2() const { return HasDSPR2; } 227 bool hasMSA() const { return HasMSA; } 228 bool isLinux() const { return IsLinux; } 229 bool useSmallSection() const { return UseSmallSection; } 230 231 bool hasStandardEncoding() const { return !inMips16Mode(); } 232 233 bool abiUsesSoftFloat() const; 234 235 bool enableLongBranchPass() const { 236 return hasStandardEncoding() || allowMixed16_32(); 237 } 238 239 /// Features related to the presence of specific instructions. 240 bool hasExtractInsert() const { return !inMips16Mode() && hasMips32r2(); } 241 bool hasMTHC1() const { return hasMips32r2(); } 242 243 const InstrItineraryData &getInstrItineraryData() const { return InstrItins; } 244 bool allowMixed16_32() const { return inMips16ModeDefault() | 245 AllowMixed16_32;} 246 247 bool os16() const { return Os16;}; 248 249 bool isTargetNaCl() const { return TargetTriple.isOSNaCl(); } 250 bool isNotTargetNaCl() const { return !TargetTriple.isOSNaCl(); } 251 252 // for now constant islands are on for the whole compilation unit but we only 253 // really use them if in addition we are in mips16 mode 254 static bool useConstantIslands(); 255 256 unsigned stackAlignment() const { return hasMips64() ? 16 : 8; } 257 258 // Grab relocation model 259 Reloc::Model getRelocationModel() const; 260 261 MipsSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS, 262 const TargetMachine *TM); 263 264 /// Does the system support unaligned memory access. 265 /// 266 /// MIPS32r6/MIPS64r6 require full unaligned access support but does not 267 /// specify which component of the system provides it. Hardware, software, and 268 /// hybrid implementations are all valid. 269 bool systemSupportsUnalignedAccess() const { return hasMips32r6(); } 270 271 // Set helper classes 272 void setHelperClassesMips16(); 273 void setHelperClassesMipsSE(); 274 275 MipsJITInfo *getJITInfo() { return &JITInfo; } 276 const MipsSelectionDAGInfo *getSelectionDAGInfo() const { return &TSInfo; } 277 const DataLayout *getDataLayout() const { return &DL; } 278 const MipsInstrInfo *getInstrInfo() const { return InstrInfo.get(); } 279 const TargetFrameLowering *getFrameLowering() const { 280 return FrameLowering.get(); 281 } 282 const MipsRegisterInfo *getRegisterInfo() const { 283 return &InstrInfo->getRegisterInfo(); 284 } 285 const MipsTargetLowering *getTargetLowering() const { return TLInfo.get(); } 286 }; 287 } // End llvm namespace 288 289 #endif 290