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