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