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