1d94bbaafb773d90261e2d9bff7cb079eb725013
[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 "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   // IsFP64bit - The target processor has 64-bit floating point registers.
66   bool IsFP64bit;
67
68   // IsNan2008 - IEEE 754-2008 NaN encoding.
69   bool IsNaN2008bit;
70
71   // IsFP64bit - General-purpose registers are 64 bits wide
72   bool IsGP64bit;
73
74   // HasVFPU - Processor has a vector floating point unit.
75   bool HasVFPU;
76
77   // CPU supports cnMIPS (Cavium Networks Octeon CPU).
78   bool HasCnMips;
79
80   // isLinux - Target system is Linux. Is false we consider ELFOS for now.
81   bool IsLinux;
82
83   // UseSmallSection - Small section is used.
84   bool UseSmallSection;
85
86   /// Features related to the presence of specific instructions.
87
88   // HasMips3_32 - The subset of MIPS-III instructions added to MIPS32
89   bool HasMips3_32;
90
91   // HasMips3_32r2 - The subset of MIPS-III instructions added to MIPS32r2
92   bool HasMips3_32r2;
93
94   // HasMips4_32 - Has the subset of MIPS-IV present in MIPS32
95   bool HasMips4_32;
96
97   // HasMips4_32r2 - Has the subset of MIPS-IV present in MIPS32r2
98   bool HasMips4_32r2;
99
100   // HasMips5_32r2 - Has the subset of MIPS-V present in MIPS32r2
101   bool HasMips5_32r2;
102
103   // InMips16 -- can process Mips16 instructions
104   bool InMips16Mode;
105
106   // Mips16 hard float
107   bool InMips16HardFloat;
108
109   // PreviousInMips16 -- the function we just processed was in Mips 16 Mode
110   bool PreviousInMips16Mode;
111
112   // InMicroMips -- can process MicroMips instructions
113   bool InMicroMipsMode;
114
115   // HasDSP, HasDSPR2 -- supports DSP ASE.
116   bool HasDSP, HasDSPR2;
117
118   // Allow mixed Mips16 and Mips32 in one source file
119   bool AllowMixed16_32;
120
121   // Optimize for space by compiling all functions as Mips 16 unless
122   // it needs floating point. Functions needing floating point are
123   // compiled as Mips32
124   bool Os16;
125
126   // HasMSA -- supports MSA ASE.
127   bool HasMSA;
128
129   InstrItineraryData InstrItins;
130
131   // Relocation Model
132   Reloc::Model RM;
133
134   // We can override the determination of whether we are in mips16 mode
135   // as from the command line
136   enum {NoOverride, Mips16Override, NoMips16Override} OverrideMode;
137
138   MipsTargetMachine *TM;
139
140   Triple TargetTriple;
141
142   const DataLayout DL; // Calculates type size & alignment
143   const MipsSelectionDAGInfo TSInfo;
144   MipsJITInfo JITInfo;
145   std::unique_ptr<const MipsInstrInfo> InstrInfo;
146   std::unique_ptr<const MipsFrameLowering> FrameLowering;
147   std::unique_ptr<const MipsTargetLowering> TLInfo;
148   std::unique_ptr<const MipsInstrInfo> InstrInfo16;
149   std::unique_ptr<const MipsFrameLowering> FrameLowering16;
150   std::unique_ptr<const MipsTargetLowering> TLInfo16;
151   std::unique_ptr<const MipsInstrInfo> InstrInfoSE;
152   std::unique_ptr<const MipsFrameLowering> FrameLoweringSE;
153   std::unique_ptr<const MipsTargetLowering> TLInfoSE;
154
155 public:
156   bool enablePostRAScheduler(CodeGenOpt::Level OptLevel,
157                              AntiDepBreakMode& Mode,
158                              RegClassVector& CriticalPathRCs) const override;
159
160   /// Only O32 and EABI supported right now.
161   bool isABI_EABI() const { return MipsABI == EABI; }
162   bool isABI_N64() const { return MipsABI == N64; }
163   bool isABI_N32() const { return MipsABI == N32; }
164   bool isABI_O32() const { return MipsABI == O32; }
165   bool isABI_FPXX() const { return false; } // TODO: add check for FPXX
166   unsigned getTargetABI() const { return MipsABI; }
167
168   /// This constructor initializes the data members to match that
169   /// of the specified triple.
170   MipsSubtarget(const std::string &TT, const std::string &CPU,
171                 const std::string &FS, bool little, Reloc::Model RM,
172                 MipsTargetMachine *TM);
173
174   /// ParseSubtargetFeatures - Parses features string setting specified
175   /// subtarget options.  Definition of function is auto generated by tblgen.
176   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
177
178   bool hasMips1() const { return MipsArchVersion >= Mips1; }
179   bool hasMips2() const { return MipsArchVersion >= Mips2; }
180   bool hasMips3() const { return MipsArchVersion >= Mips3; }
181   bool hasMips4() const { return MipsArchVersion >= Mips4; }
182   bool hasMips5() const { return MipsArchVersion >= Mips5; }
183   bool hasMips4_32() const { return HasMips4_32; }
184   bool hasMips4_32r2() const { return HasMips4_32r2; }
185   bool hasMips32() const {
186     return MipsArchVersion >= Mips32 && MipsArchVersion != Mips3 &&
187            MipsArchVersion != Mips4 && MipsArchVersion != Mips5;
188   }
189   bool hasMips32r2() const {
190     return MipsArchVersion == Mips32r2 || MipsArchVersion == Mips32r6 ||
191            MipsArchVersion == Mips64r2 || MipsArchVersion == Mips64r6;
192   }
193   bool hasMips32r6() const {
194     return MipsArchVersion == Mips32r6 || MipsArchVersion == Mips64r6;
195   }
196   bool hasMips64() const { return MipsArchVersion >= Mips64; }
197   bool hasMips64r2() const {
198     return MipsArchVersion == Mips64r2 || MipsArchVersion == Mips64r6;
199   }
200   bool hasMips64r6() const { return MipsArchVersion == Mips64r6; }
201
202   bool hasCnMips() const { return HasCnMips; }
203
204   bool isLittle() const { return IsLittle; }
205   bool isFP64bit() const { return IsFP64bit; }
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 {
214     switch (OverrideMode) {
215     case NoOverride:
216       return InMips16Mode;
217     case Mips16Override:
218       return true;
219     case NoMips16Override:
220       return false;
221     }
222     llvm_unreachable("Unexpected mode");
223   }
224   bool inMips16ModeDefault() const {
225     return InMips16Mode;
226   }
227   bool inMips16HardFloat() const {
228     return inMips16Mode() && InMips16HardFloat;
229   }
230   bool inMicroMipsMode() const { return InMicroMipsMode; }
231   bool hasDSP() const { return HasDSP; }
232   bool hasDSPR2() const { return HasDSPR2; }
233   bool hasMSA() const { return HasMSA; }
234   bool isLinux() const { return IsLinux; }
235   bool useSmallSection() const { return UseSmallSection; }
236
237   bool hasStandardEncoding() const { return !inMips16Mode(); }
238
239   bool mipsSEUsesSoftFloat() const;
240
241   bool enableLongBranchPass() const {
242     return hasStandardEncoding() || allowMixed16_32();
243   }
244
245   /// Features related to the presence of specific instructions.
246   bool hasExtractInsert() const { return !inMips16Mode() && hasMips32r2(); }
247
248   const InstrItineraryData &getInstrItineraryData() const { return InstrItins; }
249   bool allowMixed16_32() const { return inMips16ModeDefault() |
250                                         AllowMixed16_32;}
251
252   bool os16() const { return Os16;};
253
254   bool isTargetNaCl() const { return TargetTriple.isOSNaCl(); }
255   bool isNotTargetNaCl() const { return !TargetTriple.isOSNaCl(); }
256
257   // for now constant islands are on for the whole compilation unit but we only
258   // really use them if in addition we are in mips16 mode
259   static bool useConstantIslands();
260
261   unsigned stackAlignment() const { return hasMips64() ? 16 : 8; }
262
263   // Grab relocation model
264   Reloc::Model getRelocationModel() const {return RM;}
265
266   /// \brief Reset the subtarget for the Mips target.
267   void resetSubtarget(MachineFunction *MF);
268
269   MipsSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS,
270                                                  const TargetMachine *TM);
271
272   /// Does the system support unaligned memory access.
273   ///
274   /// MIPS32r6/MIPS64r6 require full unaligned access support but does not
275   /// specify which component of the system provides it. Hardware, software, and
276   /// hybrid implementations are all valid.
277   bool systemSupportsUnalignedAccess() const { return hasMips32r6(); }
278
279   // Set helper classes
280   void setHelperClassesMips16();
281   void setHelperClassesMipsSE();
282
283   MipsJITInfo *getJITInfo() { return &JITInfo; }
284   const MipsSelectionDAGInfo *getSelectionDAGInfo() const { return &TSInfo; }
285   const DataLayout *getDataLayout() const { return &DL; }
286   const MipsInstrInfo *getInstrInfo() const { return InstrInfo.get(); }
287   const TargetFrameLowering *getFrameLowering() const {
288     return FrameLowering.get();
289   }
290   const MipsRegisterInfo *getRegisterInfo() const {
291     return &InstrInfo->getRegisterInfo();
292   }
293   const MipsTargetLowering *getTargetLowering() const { return TLInfo.get(); }
294 };
295 } // End llvm namespace
296
297 #endif