[mips] Fold FeatureSEInReg into FeatureMips32r2
[oota-llvm.git] / lib / Target / Mips / MipsSubtarget.h
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 "llvm/MC/MCInstrItineraries.h"
18 #include "llvm/Support/ErrorHandling.h"
19 #include "llvm/Target/TargetSubtargetInfo.h"
20 #include <string>
21
22 #define GET_SUBTARGETINFO_HEADER
23 #include "MipsGenSubtargetInfo.inc"
24
25 namespace llvm {
26 class StringRef;
27
28 class MipsTargetMachine;
29
30 class MipsSubtarget : public MipsGenSubtargetInfo {
31   virtual void anchor();
32
33 public:
34   // NOTE: O64 will not be supported.
35   enum MipsABIEnum {
36     UnknownABI, O32, N32, N64, EABI
37   };
38
39 protected:
40   enum MipsArchEnum {
41     Mips1, Mips2, Mips32, Mips32r2, Mips32r6, Mips3, Mips4, Mips5, Mips64,
42     Mips64r2, Mips64r6
43   };
44
45   // Mips architecture version
46   MipsArchEnum MipsArchVersion;
47
48   // Mips supported ABIs
49   MipsABIEnum MipsABI;
50
51   // IsLittle - The target is Little Endian
52   bool IsLittle;
53
54   // IsSingleFloat - The target only supports single precision float
55   // point operations. This enable the target to use all 32 32-bit
56   // floating point registers instead of only using even ones.
57   bool IsSingleFloat;
58
59   // IsFP64bit - The target processor has 64-bit floating point registers.
60   bool IsFP64bit;
61
62   // IsNan2008 - IEEE 754-2008 NaN encoding.
63   bool IsNaN2008bit;
64
65   // IsFP64bit - General-purpose registers are 64 bits wide
66   bool IsGP64bit;
67
68   // HasVFPU - Processor has a vector floating point unit.
69   bool HasVFPU;
70
71   // CPU supports cnMIPS (Cavium Networks Octeon CPU).
72   bool HasCnMips;
73
74   // isLinux - Target system is Linux. Is false we consider ELFOS for now.
75   bool IsLinux;
76
77   // UseSmallSection - Small section is used.
78   bool UseSmallSection;
79
80   /// Features related to the presence of specific instructions.
81
82   // HasMips3_32 - The subset of MIPS-III instructions added to MIPS32
83   bool HasMips3_32;
84
85   // HasMips4_32 - Has the subset of MIPS-IV present in MIPS32
86   bool HasMips4_32;
87
88   // HasMips4_32r2 - Has the subset of MIPS-IV present in MIPS32r2
89   bool HasMips4_32r2;
90
91   // HasBitCount - Count leading '1' and '0' bits.
92   bool HasBitCount;
93
94   // InMips16 -- can process Mips16 instructions
95   bool InMips16Mode;
96
97   // Mips16 hard float
98   bool InMips16HardFloat;
99
100   // PreviousInMips16 -- the function we just processed was in Mips 16 Mode
101   bool PreviousInMips16Mode;
102
103   // InMicroMips -- can process MicroMips instructions
104   bool InMicroMipsMode;
105
106   // HasDSP, HasDSPR2 -- supports DSP ASE.
107   bool HasDSP, HasDSPR2;
108
109   // Allow mixed Mips16 and Mips32 in one source file
110   bool AllowMixed16_32;
111
112   // Optimize for space by compiling all functions as Mips 16 unless
113   // it needs floating point. Functions needing floating point are
114   // compiled as Mips32
115   bool Os16;
116
117   // HasMSA -- supports MSA ASE.
118   bool HasMSA;
119
120   InstrItineraryData InstrItins;
121
122   // Relocation Model
123   Reloc::Model RM;
124
125   // We can override the determination of whether we are in mips16 mode
126   // as from the command line
127   enum {NoOverride, Mips16Override, NoMips16Override} OverrideMode;
128
129   MipsTargetMachine *TM;
130
131   Triple TargetTriple;
132 public:
133   bool enablePostRAScheduler(CodeGenOpt::Level OptLevel,
134                              AntiDepBreakMode& Mode,
135                              RegClassVector& CriticalPathRCs) const override;
136
137   /// Only O32 and EABI supported right now.
138   bool isABI_EABI() const { return MipsABI == EABI; }
139   bool isABI_N64() const { return MipsABI == N64; }
140   bool isABI_N32() const { return MipsABI == N32; }
141   bool isABI_O32() const { return MipsABI == O32; }
142   unsigned getTargetABI() const { return MipsABI; }
143
144   /// This constructor initializes the data members to match that
145   /// of the specified triple.
146   MipsSubtarget(const std::string &TT, const std::string &CPU,
147                 const std::string &FS, bool little, Reloc::Model RM,
148                 MipsTargetMachine *TM);
149
150   /// ParseSubtargetFeatures - Parses features string setting specified
151   /// subtarget options.  Definition of function is auto generated by tblgen.
152   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
153
154   bool hasMips2() const { return MipsArchVersion >= Mips2; }
155   bool hasMips3() const { return MipsArchVersion >= Mips3; }
156   bool hasMips4_32() const { return HasMips4_32; }
157   bool hasMips4_32r2() const { return HasMips4_32r2; }
158   bool hasMips32() const { return MipsArchVersion >= Mips32; }
159   bool hasMips32r2() const { return MipsArchVersion == Mips32r2 ||
160                                    MipsArchVersion == Mips64r2; }
161   bool hasMips32r6() const { return MipsArchVersion == Mips32r6 ||
162                                    MipsArchVersion == Mips64r6; }
163   bool hasMips64() const { return MipsArchVersion >= Mips64; }
164   bool hasMips64r2() const { return MipsArchVersion == Mips64r2; }
165   bool hasMips64r6() const { return MipsArchVersion == Mips64r6; }
166
167   bool hasCnMips() const { return HasCnMips; }
168
169   bool isLittle() const { return IsLittle; }
170   bool isFP64bit() const { return IsFP64bit; }
171   bool isNaN2008() const { return IsNaN2008bit; }
172   bool isNotFP64bit() const { return !IsFP64bit; }
173   bool isGP64bit() const { return IsGP64bit; }
174   bool isGP32bit() const { return !IsGP64bit; }
175   bool isSingleFloat() const { return IsSingleFloat; }
176   bool isNotSingleFloat() const { return !IsSingleFloat; }
177   bool hasVFPU() const { return HasVFPU; }
178   bool inMips16Mode() const {
179     switch (OverrideMode) {
180     case NoOverride:
181       return InMips16Mode;
182     case Mips16Override:
183       return true;
184     case NoMips16Override:
185       return false;
186     }
187     llvm_unreachable("Unexpected mode");
188   }
189   bool inMips16ModeDefault() const {
190     return InMips16Mode;
191   }
192   bool inMips16HardFloat() const {
193     return inMips16Mode() && InMips16HardFloat;
194   }
195   bool inMicroMipsMode() const { return InMicroMipsMode; }
196   bool hasDSP() const { return HasDSP; }
197   bool hasDSPR2() const { return HasDSPR2; }
198   bool hasMSA() const { return HasMSA; }
199   bool isLinux() const { return IsLinux; }
200   bool useSmallSection() const { return UseSmallSection; }
201
202   bool hasStandardEncoding() const { return !inMips16Mode(); }
203
204   bool mipsSEUsesSoftFloat() const;
205
206   bool enableLongBranchPass() const {
207     return hasStandardEncoding() || allowMixed16_32();
208   }
209
210   /// Features related to the presence of specific instructions.
211   bool hasBitCount()  const { return HasBitCount; }
212   bool hasExtractInsert() const { return !inMips16Mode() && hasMips32r2(); }
213
214   const InstrItineraryData &getInstrItineraryData() const { return InstrItins; }
215   bool allowMixed16_32() const { return inMips16ModeDefault() |
216                                         AllowMixed16_32;}
217
218   bool os16() const { return Os16;};
219
220   bool isTargetNaCl() const { return TargetTriple.isOSNaCl(); }
221   bool isNotTargetNaCl() const { return !TargetTriple.isOSNaCl(); }
222
223   // for now constant islands are on for the whole compilation unit but we only
224   // really use them if in addition we are in mips16 mode
225   static bool useConstantIslands();
226
227   unsigned stackAlignment() const { return hasMips64() ? 16 : 8; }
228
229   // Grab relocation model
230   Reloc::Model getRelocationModel() const {return RM;}
231
232   /// \brief Reset the subtarget for the Mips target.
233   void resetSubtarget(MachineFunction *MF);
234
235
236 };
237 } // End llvm namespace
238
239 #endif