4967e7b8a2e038b72cd85087c5d1a1834a697c39
[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 LLVM_LIB_TARGET_MIPS_MIPSSUBTARGET_H
15 #define LLVM_LIB_TARGET_MIPS_MIPSSUBTARGET_H
16
17 #include "MipsFrameLowering.h"
18 #include "MipsISelLowering.h"
19 #include "MipsInstrInfo.h"
20 #include "MipsSelectionDAGInfo.h"
21 #include "llvm/IR/DataLayout.h"
22 #include "llvm/MC/MCInstrItineraries.h"
23 #include "llvm/Support/ErrorHandling.h"
24 #include "llvm/Target/TargetSubtargetInfo.h"
25 #include <string>
26
27 #define GET_SUBTARGETINFO_HEADER
28 #include "MipsGenSubtargetInfo.inc"
29
30 namespace llvm {
31 class StringRef;
32
33 class MipsTargetMachine;
34
35 class MipsSubtarget : public MipsGenSubtargetInfo {
36   virtual void anchor();
37
38 public:
39   // NOTE: O64 will not be supported.
40   enum MipsABIEnum {
41     UnknownABI, O32, N32, N64, EABI
42   };
43
44 protected:
45   enum MipsArchEnum {
46     Mips1, Mips2, Mips32, Mips32r2, Mips32r6, Mips3, Mips4, Mips5, Mips64,
47     Mips64r2, Mips64r6
48   };
49
50   // Mips architecture version
51   MipsArchEnum MipsArchVersion;
52
53   // Mips supported ABIs
54   MipsABIEnum MipsABI;
55
56   // IsLittle - The target is Little Endian
57   bool IsLittle;
58
59   // IsSingleFloat - The target only supports single precision float
60   // point operations. This enable the target to use all 32 32-bit
61   // floating point registers instead of only using even ones.
62   bool IsSingleFloat;
63
64   // IsFPXX - MIPS O32 modeless ABI.
65   bool IsFPXX;
66
67   // NoABICalls - Disable SVR4-style position-independent code.
68   bool NoABICalls;
69
70   // IsFP64bit - The target processor has 64-bit floating point registers.
71   bool IsFP64bit;
72
73   /// Are odd single-precision registers permitted?
74   /// This corresponds to -modd-spreg and -mno-odd-spreg
75   bool UseOddSPReg;
76
77   // IsNan2008 - IEEE 754-2008 NaN encoding.
78   bool IsNaN2008bit;
79
80   // IsFP64bit - General-purpose registers are 64 bits wide
81   bool IsGP64bit;
82
83   // HasVFPU - Processor has a vector floating point unit.
84   bool HasVFPU;
85
86   // CPU supports cnMIPS (Cavium Networks Octeon CPU).
87   bool HasCnMips;
88
89   // isLinux - Target system is Linux. Is false we consider ELFOS for now.
90   bool IsLinux;
91
92   // UseSmallSection - Small section is used.
93   bool UseSmallSection;
94
95   /// Features related to the presence of specific instructions.
96
97   // HasMips3_32 - The subset of MIPS-III instructions added to MIPS32
98   bool HasMips3_32;
99
100   // HasMips3_32r2 - The subset of MIPS-III instructions added to MIPS32r2
101   bool HasMips3_32r2;
102
103   // HasMips4_32 - Has the subset of MIPS-IV present in MIPS32
104   bool HasMips4_32;
105
106   // HasMips4_32r2 - Has the subset of MIPS-IV present in MIPS32r2
107   bool HasMips4_32r2;
108
109   // HasMips5_32r2 - Has the subset of MIPS-V present in MIPS32r2
110   bool HasMips5_32r2;
111
112   // InMips16 -- can process Mips16 instructions
113   bool InMips16Mode;
114
115   // Mips16 hard float
116   bool InMips16HardFloat;
117
118   // PreviousInMips16 -- the function we just processed was in Mips 16 Mode
119   bool PreviousInMips16Mode;
120
121   // InMicroMips -- can process MicroMips instructions
122   bool InMicroMipsMode;
123
124   // HasDSP, HasDSPR2 -- supports DSP ASE.
125   bool HasDSP, HasDSPR2;
126
127   // Allow mixed Mips16 and Mips32 in one source file
128   bool AllowMixed16_32;
129
130   // Optimize for space by compiling all functions as Mips 16 unless
131   // it needs floating point. Functions needing floating point are
132   // compiled as Mips32
133   bool Os16;
134
135   // HasMSA -- supports MSA ASE.
136   bool HasMSA;
137
138   InstrItineraryData InstrItins;
139
140   // We can override the determination of whether we are in mips16 mode
141   // as from the command line
142   enum {NoOverride, Mips16Override, NoMips16Override} OverrideMode;
143
144   MipsTargetMachine *TM;
145
146   Triple TargetTriple;
147
148   const DataLayout DL; // Calculates type size & alignment
149   const MipsSelectionDAGInfo TSInfo;
150   std::unique_ptr<const MipsInstrInfo> InstrInfo;
151   std::unique_ptr<const MipsFrameLowering> FrameLowering;
152   std::unique_ptr<const MipsTargetLowering> TLInfo;
153
154 public:
155   /// This overrides the PostRAScheduler bit in the SchedModel for each CPU.
156   bool enablePostMachineScheduler() const override;
157   void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const override;
158   CodeGenOpt::Level getOptLevelToEnablePostRAScheduler() 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 isABI_O32() && IsFPXX; }
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, MipsTargetMachine *TM);
172
173   /// ParseSubtargetFeatures - Parses features string setting specified
174   /// subtarget options.  Definition of function is auto generated by tblgen.
175   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
176
177   bool hasMips1() const { return MipsArchVersion >= Mips1; }
178   bool hasMips2() const { return MipsArchVersion >= Mips2; }
179   bool hasMips3() const { return MipsArchVersion >= Mips3; }
180   bool hasMips4() const { return MipsArchVersion >= Mips4; }
181   bool hasMips5() const { return MipsArchVersion >= Mips5; }
182   bool hasMips4_32() const { return HasMips4_32; }
183   bool hasMips4_32r2() const { return HasMips4_32r2; }
184   bool hasMips32() const {
185     return MipsArchVersion >= Mips32 && MipsArchVersion != Mips3 &&
186            MipsArchVersion != Mips4 && MipsArchVersion != Mips5;
187   }
188   bool hasMips32r2() const {
189     return MipsArchVersion == Mips32r2 || MipsArchVersion == Mips32r6 ||
190            MipsArchVersion == Mips64r2 || MipsArchVersion == Mips64r6;
191   }
192   bool hasMips32r6() const {
193     return MipsArchVersion == Mips32r6 || MipsArchVersion == Mips64r6;
194   }
195   bool hasMips64() const { return MipsArchVersion >= Mips64; }
196   bool hasMips64r2() const {
197     return MipsArchVersion == Mips64r2 || MipsArchVersion == Mips64r6;
198   }
199   bool hasMips64r6() const { return MipsArchVersion == Mips64r6; }
200
201   bool hasCnMips() const { return HasCnMips; }
202
203   bool isLittle() const { return IsLittle; }
204   bool isABICalls() const { return !NoABICalls; }
205   bool isFPXX() const { return IsFPXX; }
206   bool isFP64bit() const { return IsFP64bit; }
207   bool useOddSPReg() const { return UseOddSPReg; }
208   bool noOddSPReg() const { return !UseOddSPReg; }
209   bool isNaN2008() const { return IsNaN2008bit; }
210   bool isGP64bit() const { return IsGP64bit; }
211   bool isGP32bit() const { return !IsGP64bit; }
212   unsigned getGPRSizeInBytes() const { return isGP64bit() ? 8 : 4; }
213   bool isSingleFloat() const { return IsSingleFloat; }
214   bool hasVFPU() const { return HasVFPU; }
215   bool inMips16Mode() const { return InMips16Mode; }
216   bool inMips16ModeDefault() const {
217     return InMips16Mode;
218   }
219   // Hard float for mips16 means essentially to compile as soft float
220   // but to use a runtime library for soft float that is written with
221   // native mips32 floating point instructions (those runtime routines
222   // run in mips32 hard float mode).
223   bool inMips16HardFloat() const {
224     return inMips16Mode() && InMips16HardFloat;
225   }
226   bool inMicroMipsMode() const { return InMicroMipsMode; }
227   bool hasDSP() const { return HasDSP; }
228   bool hasDSPR2() const { return HasDSPR2; }
229   bool hasMSA() const { return HasMSA; }
230   bool isLinux() const { return IsLinux; }
231   bool useSmallSection() const { return UseSmallSection; }
232
233   bool hasStandardEncoding() const { return !inMips16Mode(); }
234
235   bool abiUsesSoftFloat() const;
236
237   bool enableLongBranchPass() const {
238     return hasStandardEncoding() || allowMixed16_32();
239   }
240
241   /// Features related to the presence of specific instructions.
242   bool hasExtractInsert() const { return !inMips16Mode() && hasMips32r2(); }
243   bool hasMTHC1() const { return hasMips32r2(); }
244
245   bool allowMixed16_32() const { return inMips16ModeDefault() |
246                                         AllowMixed16_32;}
247
248   bool os16() const { return Os16;};
249
250   bool isTargetNaCl() 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   const MipsSelectionDAGInfo *getSelectionDAGInfo() const override {
276     return &TSInfo;
277   }
278   const DataLayout *getDataLayout() const override { return &DL; }
279   const MipsInstrInfo *getInstrInfo() const override { return InstrInfo.get(); }
280   const TargetFrameLowering *getFrameLowering() const override {
281     return FrameLowering.get();
282   }
283   const MipsRegisterInfo *getRegisterInfo() const override {
284     return &InstrInfo->getRegisterInfo();
285   }
286   const MipsTargetLowering *getTargetLowering() const override {
287     return TLInfo.get();
288   }
289   const InstrItineraryData *getInstrItineraryData() const override {
290     return &InstrItins;
291   }
292 };
293 } // End llvm namespace
294
295 #endif