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