Partial support for Intel SHA Extensions (sha1rnds4)
[oota-llvm.git] / lib / Target / X86 / X86Subtarget.h
1 //===-- X86Subtarget.h - Define Subtarget for the X86 ----------*- 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 X86 specific subclass of TargetSubtargetInfo.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef X86SUBTARGET_H
15 #define X86SUBTARGET_H
16
17 #include "llvm/ADT/Triple.h"
18 #include "llvm/IR/CallingConv.h"
19 #include "llvm/Target/TargetSubtargetInfo.h"
20 #include <string>
21
22 #define GET_SUBTARGETINFO_HEADER
23 #include "X86GenSubtargetInfo.inc"
24
25 namespace llvm {
26 class GlobalValue;
27 class StringRef;
28 class TargetMachine;
29
30 /// PICStyles - The X86 backend supports a number of different styles of PIC.
31 ///
32 namespace PICStyles {
33 enum Style {
34   StubPIC,          // Used on i386-darwin in -fPIC mode.
35   StubDynamicNoPIC, // Used on i386-darwin in -mdynamic-no-pic mode.
36   GOT,              // Used on many 32-bit unices in -fPIC mode.
37   RIPRel,           // Used on X86-64 when not in -static mode.
38   None              // Set when in -static mode (not PIC or DynamicNoPIC mode).
39 };
40 }
41
42 class X86Subtarget : public X86GenSubtargetInfo {
43 protected:
44   enum X86SSEEnum {
45     NoMMXSSE, MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42, AVX, AVX2, AVX512F
46   };
47
48   enum X863DNowEnum {
49     NoThreeDNow, ThreeDNow, ThreeDNowA
50   };
51
52   enum X86ProcFamilyEnum {
53     Others, IntelAtom
54   };
55
56   /// X86ProcFamily - X86 processor family: Intel Atom, and others
57   X86ProcFamilyEnum X86ProcFamily;
58
59   /// PICStyle - Which PIC style to use
60   ///
61   PICStyles::Style PICStyle;
62
63   /// X86SSELevel - MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42, or
64   /// none supported.
65   X86SSEEnum X86SSELevel;
66
67   /// X863DNowLevel - 3DNow or 3DNow Athlon, or none supported.
68   ///
69   X863DNowEnum X863DNowLevel;
70
71   /// HasCMov - True if this processor has conditional move instructions
72   /// (generally pentium pro+).
73   bool HasCMov;
74
75   /// HasX86_64 - True if the processor supports X86-64 instructions.
76   ///
77   bool HasX86_64;
78
79   /// HasPOPCNT - True if the processor supports POPCNT.
80   bool HasPOPCNT;
81
82   /// HasSSE4A - True if the processor supports SSE4A instructions.
83   bool HasSSE4A;
84
85   /// HasAES - Target has AES instructions
86   bool HasAES;
87
88   /// HasPCLMUL - Target has carry-less multiplication
89   bool HasPCLMUL;
90
91   /// HasFMA - Target has 3-operand fused multiply-add
92   bool HasFMA;
93
94   /// HasFMA4 - Target has 4-operand fused multiply-add
95   bool HasFMA4;
96
97   /// HasXOP - Target has XOP instructions
98   bool HasXOP;
99
100   /// HasMOVBE - True if the processor has the MOVBE instruction.
101   bool HasMOVBE;
102
103   /// HasRDRAND - True if the processor has the RDRAND instruction.
104   bool HasRDRAND;
105
106   /// HasF16C - Processor has 16-bit floating point conversion instructions.
107   bool HasF16C;
108
109   /// HasFSGSBase - Processor has FS/GS base insturctions.
110   bool HasFSGSBase;
111
112   /// HasLZCNT - Processor has LZCNT instruction.
113   bool HasLZCNT;
114
115   /// HasBMI - Processor has BMI1 instructions.
116   bool HasBMI;
117
118   /// HasBMI2 - Processor has BMI2 instructions.
119   bool HasBMI2;
120
121   /// HasRTM - Processor has RTM instructions.
122   bool HasRTM;
123
124   /// HasHLE - Processor has HLE.
125   bool HasHLE;
126
127   /// HasADX - Processor has ADX instructions.
128   bool HasADX;
129
130   /// HasSHA - Processor has SHA instructions.
131   bool HasSHA;
132
133   /// HasPRFCHW - Processor has PRFCHW instructions.
134   bool HasPRFCHW;
135
136   /// HasRDSEED - Processor has RDSEED instructions.
137   bool HasRDSEED;
138
139   /// IsBTMemSlow - True if BT (bit test) of memory instructions are slow.
140   bool IsBTMemSlow;
141
142   /// IsUAMemFast - True if unaligned memory access is fast.
143   bool IsUAMemFast;
144
145   /// HasVectorUAMem - True if SIMD operations can have unaligned memory
146   /// operands. This may require setting a feature bit in the processor.
147   bool HasVectorUAMem;
148
149   /// HasCmpxchg16b - True if this processor has the CMPXCHG16B instruction;
150   /// this is true for most x86-64 chips, but not the first AMD chips.
151   bool HasCmpxchg16b;
152
153   /// UseLeaForSP - True if the LEA instruction should be used for adjusting
154   /// the stack pointer. This is an optimization for Intel Atom processors.
155   bool UseLeaForSP;
156
157   /// HasSlowDivide - True if smaller divides are significantly faster than
158   /// full divides and should be used when possible.
159   bool HasSlowDivide;
160
161   /// PostRAScheduler - True if using post-register-allocation scheduler.
162   bool PostRAScheduler;
163
164   /// PadShortFunctions - True if the short functions should be padded to prevent
165   /// a stall when returning too early.
166   bool PadShortFunctions;
167
168   /// CallRegIndirect - True if the Calls with memory reference should be converted
169   /// to a register-based indirect call.
170   bool CallRegIndirect;
171   /// LEAUsesAG - True if the LEA instruction inputs have to be ready at
172   ///             address generation (AG) time.
173   bool LEAUsesAG;
174
175   /// Processor has AVX-512 PreFetch Instructions
176   bool HasPFI;
177   
178   /// Processor has AVX-512 Exponential and Reciprocal Instructions
179   bool HasERI;
180   
181   /// Processor has AVX-512 Conflict Detection Instructions
182   bool HasCDI;
183   
184   /// stackAlignment - The minimum alignment known to hold of the stack frame on
185   /// entry to the function and which must be maintained by every function.
186   unsigned stackAlignment;
187
188   /// Max. memset / memcpy size that is turned into rep/movs, rep/stos ops.
189   ///
190   unsigned MaxInlineSizeThreshold;
191
192   /// TargetTriple - What processor and OS we're targeting.
193   Triple TargetTriple;
194
195   /// Instruction itineraries for scheduling
196   InstrItineraryData InstrItins;
197
198 private:
199   /// StackAlignOverride - Override the stack alignment.
200   unsigned StackAlignOverride;
201
202   /// In64BitMode - True if compiling for 64-bit, false for 32-bit.
203   bool In64BitMode;
204
205 public:
206   /// This constructor initializes the data members to match that
207   /// of the specified triple.
208   ///
209   X86Subtarget(const std::string &TT, const std::string &CPU,
210                const std::string &FS,
211                unsigned StackAlignOverride, bool is64Bit);
212
213   /// getStackAlignment - Returns the minimum alignment known to hold of the
214   /// stack frame on entry to the function and which must be maintained by every
215   /// function for this subtarget.
216   unsigned getStackAlignment() const { return stackAlignment; }
217
218   /// getMaxInlineSizeThreshold - Returns the maximum memset / memcpy size
219   /// that still makes it profitable to inline the call.
220   unsigned getMaxInlineSizeThreshold() const { return MaxInlineSizeThreshold; }
221
222   /// ParseSubtargetFeatures - Parses features string setting specified
223   /// subtarget options.  Definition of function is auto generated by tblgen.
224   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
225
226   /// AutoDetectSubtargetFeatures - Auto-detect CPU features using CPUID
227   /// instruction.
228   void AutoDetectSubtargetFeatures();
229
230   /// \brief Reset the features for the X86 target.
231   virtual void resetSubtargetFeatures(const MachineFunction *MF);
232 private:
233   void initializeEnvironment();
234   void resetSubtargetFeatures(StringRef CPU, StringRef FS);
235 public:
236   /// Is this x86_64? (disregarding specific ABI / programming model)
237   bool is64Bit() const {
238     return In64BitMode;
239   }
240
241   /// Is this x86_64 with the ILP32 programming model (x32 ABI)?
242   bool isTarget64BitILP32() const {
243     return In64BitMode && (TargetTriple.getEnvironment() == Triple::GNUX32);
244   }
245
246   /// Is this x86_64 with the LP64 programming model (standard AMD64, no x32)?
247   bool isTarget64BitLP64() const {
248     return In64BitMode && (TargetTriple.getEnvironment() != Triple::GNUX32);
249   }
250
251   PICStyles::Style getPICStyle() const { return PICStyle; }
252   void setPICStyle(PICStyles::Style Style)  { PICStyle = Style; }
253
254   bool hasCMov() const { return HasCMov; }
255   bool hasMMX() const { return X86SSELevel >= MMX; }
256   bool hasSSE1() const { return X86SSELevel >= SSE1; }
257   bool hasSSE2() const { return X86SSELevel >= SSE2; }
258   bool hasSSE3() const { return X86SSELevel >= SSE3; }
259   bool hasSSSE3() const { return X86SSELevel >= SSSE3; }
260   bool hasSSE41() const { return X86SSELevel >= SSE41; }
261   bool hasSSE42() const { return X86SSELevel >= SSE42; }
262   bool hasAVX() const { return X86SSELevel >= AVX; }
263   bool hasAVX2() const { return X86SSELevel >= AVX2; }
264   bool hasAVX512() const { return X86SSELevel >= AVX512F; }
265   bool hasFp256() const { return hasAVX(); }
266   bool hasInt256() const { return hasAVX2(); }
267   bool hasSSE4A() const { return HasSSE4A; }
268   bool has3DNow() const { return X863DNowLevel >= ThreeDNow; }
269   bool has3DNowA() const { return X863DNowLevel >= ThreeDNowA; }
270   bool hasPOPCNT() const { return HasPOPCNT; }
271   bool hasAES() const { return HasAES; }
272   bool hasPCLMUL() const { return HasPCLMUL; }
273   bool hasFMA() const { return HasFMA; }
274   // FIXME: Favor FMA when both are enabled. Is this the right thing to do?
275   bool hasFMA4() const { return HasFMA4 && !HasFMA; }
276   bool hasXOP() const { return HasXOP; }
277   bool hasMOVBE() const { return HasMOVBE; }
278   bool hasRDRAND() const { return HasRDRAND; }
279   bool hasF16C() const { return HasF16C; }
280   bool hasFSGSBase() const { return HasFSGSBase; }
281   bool hasLZCNT() const { return HasLZCNT; }
282   bool hasBMI() const { return HasBMI; }
283   bool hasBMI2() const { return HasBMI2; }
284   bool hasRTM() const { return HasRTM; }
285   bool hasHLE() const { return HasHLE; }
286   bool hasADX() const { return HasADX; }
287   bool hasSHA() const { return HasSHA; }
288   bool hasPRFCHW() const { return HasPRFCHW; }
289   bool hasRDSEED() const { return HasRDSEED; }
290   bool isBTMemSlow() const { return IsBTMemSlow; }
291   bool isUnalignedMemAccessFast() const { return IsUAMemFast; }
292   bool hasVectorUAMem() const { return HasVectorUAMem; }
293   bool hasCmpxchg16b() const { return HasCmpxchg16b; }
294   bool useLeaForSP() const { return UseLeaForSP; }
295   bool hasSlowDivide() const { return HasSlowDivide; }
296   bool padShortFunctions() const { return PadShortFunctions; }
297   bool callRegIndirect() const { return CallRegIndirect; }
298   bool LEAusesAG() const { return LEAUsesAG; }
299   bool hasCDI() const { return HasCDI; }
300   bool hasPFI() const { return HasPFI; }
301   bool hasERI() const { return HasERI; }
302
303   bool isAtom() const { return X86ProcFamily == IntelAtom; }
304
305   const Triple &getTargetTriple() const { return TargetTriple; }
306
307   bool isTargetDarwin() const { return TargetTriple.isOSDarwin(); }
308   bool isTargetFreeBSD() const {
309     return TargetTriple.getOS() == Triple::FreeBSD;
310   }
311   bool isTargetSolaris() const {
312     return TargetTriple.getOS() == Triple::Solaris;
313   }
314   bool isTargetELF() const {
315     return (TargetTriple.getEnvironment() == Triple::ELF ||
316             TargetTriple.isOSBinFormatELF());
317   }
318   bool isTargetLinux() const { return TargetTriple.isOSLinux(); }
319   bool isTargetNaCl() const { return TargetTriple.isOSNaCl(); }
320   bool isTargetNaCl32() const { return isTargetNaCl() && !is64Bit(); }
321   bool isTargetNaCl64() const { return isTargetNaCl() && is64Bit(); }
322   bool isTargetWindows() const { return TargetTriple.getOS() == Triple::Win32; }
323   bool isTargetMingw() const { return TargetTriple.getOS() == Triple::MinGW32; }
324   bool isTargetCygwin() const { return TargetTriple.getOS() == Triple::Cygwin; }
325   bool isTargetCygMing() const { return TargetTriple.isOSCygMing(); }
326   bool isTargetCOFF() const {
327     return (TargetTriple.getEnvironment() != Triple::ELF &&
328             TargetTriple.isOSBinFormatCOFF());
329   }
330   bool isTargetEnvMacho() const { return TargetTriple.isEnvironmentMachO(); }
331
332   bool isTargetWin64() const {
333     return In64BitMode && TargetTriple.isOSWindows();
334   }
335
336   bool isTargetWin32() const {
337     return !In64BitMode && (isTargetCygMing() || isTargetWindows());
338   }
339
340   bool isPICStyleSet() const { return PICStyle != PICStyles::None; }
341   bool isPICStyleGOT() const { return PICStyle == PICStyles::GOT; }
342   bool isPICStyleRIPRel() const { return PICStyle == PICStyles::RIPRel; }
343
344   bool isPICStyleStubPIC() const {
345     return PICStyle == PICStyles::StubPIC;
346   }
347
348   bool isPICStyleStubNoDynamic() const {
349     return PICStyle == PICStyles::StubDynamicNoPIC;
350   }
351   bool isPICStyleStubAny() const {
352     return PICStyle == PICStyles::StubDynamicNoPIC ||
353            PICStyle == PICStyles::StubPIC;
354   }
355
356   bool isCallingConvWin64(CallingConv::ID CC) const {
357     return (isTargetWin64() && CC != CallingConv::X86_64_SysV) ||
358            CC == CallingConv::X86_64_Win64;
359   }
360
361   /// ClassifyGlobalReference - Classify a global variable reference for the
362   /// current subtarget according to how we should reference it in a non-pcrel
363   /// context.
364   unsigned char ClassifyGlobalReference(const GlobalValue *GV,
365                                         const TargetMachine &TM)const;
366
367   /// ClassifyBlockAddressReference - Classify a blockaddress reference for the
368   /// current subtarget according to how we should reference it in a non-pcrel
369   /// context.
370   unsigned char ClassifyBlockAddressReference() const;
371
372   /// IsLegalToCallImmediateAddr - Return true if the subtarget allows calls
373   /// to immediate address.
374   bool IsLegalToCallImmediateAddr(const TargetMachine &TM) const;
375
376   /// This function returns the name of a function which has an interface
377   /// like the non-standard bzero function, if such a function exists on
378   /// the current subtarget and it is considered prefereable over
379   /// memset with zero passed as the second argument. Otherwise it
380   /// returns null.
381   const char *getBZeroEntry() const;
382   
383   /// This function returns true if the target has sincos() routine in its
384   /// compiler runtime or math libraries.
385   bool hasSinCos() const;
386
387   /// enablePostRAScheduler - run for Atom optimization.
388   bool enablePostRAScheduler(CodeGenOpt::Level OptLevel,
389                              TargetSubtargetInfo::AntiDepBreakMode& Mode,
390                              RegClassVector& CriticalPathRCs) const;
391
392   bool postRAScheduler() const { return PostRAScheduler; }
393
394   /// getInstrItins = Return the instruction itineraries based on the
395   /// subtarget selection.
396   const InstrItineraryData &getInstrItineraryData() const { return InstrItins; }
397 };
398
399 } // End llvm namespace
400
401 #endif