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