Move the MMX subtarget feature out of the SSE set of features and into
[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 LLVM_LIB_TARGET_X86_X86SUBTARGET_H
15 #define LLVM_LIB_TARGET_X86_X86SUBTARGET_H
16
17 #include "X86FrameLowering.h"
18 #include "X86ISelLowering.h"
19 #include "X86InstrInfo.h"
20 #include "X86SelectionDAGInfo.h"
21 #include "llvm/ADT/Triple.h"
22 #include "llvm/IR/CallingConv.h"
23 #include "llvm/Target/TargetSubtargetInfo.h"
24 #include <string>
25
26 #define GET_SUBTARGETINFO_HEADER
27 #include "X86GenSubtargetInfo.inc"
28
29 namespace llvm {
30 class GlobalValue;
31 class StringRef;
32 class TargetMachine;
33
34 /// The X86 backend supports a number of different styles of PIC.
35 ///
36 namespace PICStyles {
37 enum Style {
38   StubPIC,          // Used on i386-darwin in -fPIC mode.
39   StubDynamicNoPIC, // Used on i386-darwin in -mdynamic-no-pic mode.
40   GOT,              // Used on many 32-bit unices in -fPIC mode.
41   RIPRel,           // Used on X86-64 when not in -static mode.
42   None              // Set when in -static mode (not PIC or DynamicNoPIC mode).
43 };
44 }
45
46 class X86Subtarget final : public X86GenSubtargetInfo {
47
48 protected:
49   enum X86SSEEnum {
50     NoSSE, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42, AVX, AVX2, AVX512F
51   };
52
53   enum X863DNowEnum {
54     NoThreeDNow, ThreeDNow, ThreeDNowA
55   };
56
57   enum X86ProcFamilyEnum {
58     Others, IntelAtom, IntelSLM
59   };
60
61   /// X86 processor family: Intel Atom, and others
62   X86ProcFamilyEnum X86ProcFamily;
63
64   /// Which PIC style to use
65   PICStyles::Style PICStyle;
66
67   /// SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42, or none supported.
68   X86SSEEnum X86SSELevel;
69
70   /// 3DNow, 3DNow Athlon, or none supported.
71   X863DNowEnum X863DNowLevel;
72
73   /// True if this processor has conditional move instructions
74   /// (generally pentium pro+).
75   bool HasCMov;
76
77   /// True if this processor supports MMX instructions.
78   bool HasMMX;
79
80   /// True if the processor supports X86-64 instructions.
81   bool HasX86_64;
82
83   /// True if the processor supports POPCNT.
84   bool HasPOPCNT;
85
86   /// True if the processor supports SSE4A instructions.
87   bool HasSSE4A;
88
89   /// Target has AES instructions
90   bool HasAES;
91
92   /// Target has carry-less multiplication
93   bool HasPCLMUL;
94
95   /// Target has 3-operand fused multiply-add
96   bool HasFMA;
97
98   /// Target has 4-operand fused multiply-add
99   bool HasFMA4;
100
101   /// Target has XOP instructions
102   bool HasXOP;
103
104   /// Target has TBM instructions.
105   bool HasTBM;
106
107   /// True if the processor has the MOVBE instruction.
108   bool HasMOVBE;
109
110   /// True if the processor has the RDRAND instruction.
111   bool HasRDRAND;
112
113   /// Processor has 16-bit floating point conversion instructions.
114   bool HasF16C;
115
116   /// Processor has FS/GS base insturctions.
117   bool HasFSGSBase;
118
119   /// Processor has LZCNT instruction.
120   bool HasLZCNT;
121
122   /// Processor has BMI1 instructions.
123   bool HasBMI;
124
125   /// Processor has BMI2 instructions.
126   bool HasBMI2;
127
128   /// Processor has RTM instructions.
129   bool HasRTM;
130
131   /// Processor has HLE.
132   bool HasHLE;
133
134   /// Processor has ADX instructions.
135   bool HasADX;
136
137   /// Processor has SHA instructions.
138   bool HasSHA;
139
140   /// Processor has PRFCHW instructions.
141   bool HasPRFCHW;
142
143   /// Processor has RDSEED instructions.
144   bool HasRDSEED;
145
146   /// True if BT (bit test) of memory instructions are slow.
147   bool IsBTMemSlow;
148
149   /// True if SHLD instructions are slow.
150   bool IsSHLDSlow;
151
152   /// True if unaligned memory accesses of 16-bytes are slow.
153   bool IsUAMem16Slow;
154
155   /// True if unaligned memory accesses of 32-bytes are slow.
156   bool IsUAMem32Slow;
157
158   /// True if SSE operations can have unaligned memory operands.
159   /// This may require setting a configuration bit in the processor.
160   bool HasSSEUnalignedMem;
161
162   /// True if this processor has the CMPXCHG16B instruction;
163   /// this is true for most x86-64 chips, but not the first AMD chips.
164   bool HasCmpxchg16b;
165
166   /// True if the LEA instruction should be used for adjusting
167   /// the stack pointer. This is an optimization for Intel Atom processors.
168   bool UseLeaForSP;
169
170   /// True if 8-bit divisions are significantly faster than
171   /// 32-bit divisions and should be used when possible.
172   bool HasSlowDivide32;
173
174   /// True if 16-bit divides are significantly faster than
175   /// 64-bit divisions and should be used when possible.
176   bool HasSlowDivide64;
177
178   /// True if the short functions should be padded to prevent
179   /// a stall when returning too early.
180   bool PadShortFunctions;
181
182   /// True if the Calls with memory reference should be converted
183   /// to a register-based indirect call.
184   bool CallRegIndirect;
185
186   /// True if the LEA instruction inputs have to be ready at address generation
187   /// (AG) time.
188   bool LEAUsesAG;
189
190   /// True if the LEA instruction with certain arguments is slow
191   bool SlowLEA;
192
193   /// True if INC and DEC instructions are slow when writing to flags
194   bool SlowIncDec;
195
196   /// Processor has AVX-512 PreFetch Instructions
197   bool HasPFI;
198
199   /// Processor has AVX-512 Exponential and Reciprocal Instructions
200   bool HasERI;
201
202   /// Processor has AVX-512 Conflict Detection Instructions
203   bool HasCDI;
204
205   /// Processor has AVX-512 Doubleword and Quadword instructions
206   bool HasDQI;
207
208   /// Processor has AVX-512 Byte and Word instructions
209   bool HasBWI;
210
211   /// Processor has AVX-512 Vector Length eXtenstions
212   bool HasVLX;
213
214   /// Processot supports MPX - Memory Protection Extensions
215   bool HasMPX;
216
217   /// Use software floating point for code generation.
218   bool UseSoftFloat;
219
220   /// The minimum alignment known to hold of the stack frame on
221   /// entry to the function and which must be maintained by every function.
222   unsigned stackAlignment;
223
224   /// Max. memset / memcpy size that is turned into rep/movs, rep/stos ops.
225   ///
226   unsigned MaxInlineSizeThreshold;
227
228   /// What processor and OS we're targeting.
229   Triple TargetTriple;
230
231   /// Instruction itineraries for scheduling
232   InstrItineraryData InstrItins;
233
234 private:
235
236   /// Override the stack alignment.
237   unsigned StackAlignOverride;
238
239   /// True if compiling for 64-bit, false for 16-bit or 32-bit.
240   bool In64BitMode;
241
242   /// True if compiling for 32-bit, false for 16-bit or 64-bit.
243   bool In32BitMode;
244
245   /// True if compiling for 16-bit, false for 32-bit or 64-bit.
246   bool In16BitMode;
247
248   X86SelectionDAGInfo TSInfo;
249   // Ordering here is important. X86InstrInfo initializes X86RegisterInfo which
250   // X86TargetLowering needs.
251   X86InstrInfo InstrInfo;
252   X86TargetLowering TLInfo;
253   X86FrameLowering FrameLowering;
254
255 public:
256   /// This constructor initializes the data members to match that
257   /// of the specified triple.
258   ///
259   X86Subtarget(const Triple &TT, const std::string &CPU, const std::string &FS,
260                const X86TargetMachine &TM, unsigned StackAlignOverride);
261
262   const X86TargetLowering *getTargetLowering() const override {
263     return &TLInfo;
264   }
265   const X86InstrInfo *getInstrInfo() const override { return &InstrInfo; }
266   const X86FrameLowering *getFrameLowering() const override {
267     return &FrameLowering;
268   }
269   const X86SelectionDAGInfo *getSelectionDAGInfo() const override {
270     return &TSInfo;
271   }
272   const X86RegisterInfo *getRegisterInfo() const override {
273     return &getInstrInfo()->getRegisterInfo();
274   }
275
276   /// Returns the minimum alignment known to hold of the
277   /// stack frame on entry to the function and which must be maintained by every
278   /// function for this subtarget.
279   unsigned getStackAlignment() const { return stackAlignment; }
280
281   /// Returns the maximum memset / memcpy size
282   /// that still makes it profitable to inline the call.
283   unsigned getMaxInlineSizeThreshold() const { return MaxInlineSizeThreshold; }
284
285   /// ParseSubtargetFeatures - Parses features string setting specified
286   /// subtarget options.  Definition of function is auto generated by tblgen.
287   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
288
289 private:
290   /// Initialize the full set of dependencies so we can use an initializer
291   /// list for X86Subtarget.
292   X86Subtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
293   void initializeEnvironment();
294   void initSubtargetFeatures(StringRef CPU, StringRef FS);
295 public:
296   /// Is this x86_64? (disregarding specific ABI / programming model)
297   bool is64Bit() const {
298     return In64BitMode;
299   }
300
301   bool is32Bit() const {
302     return In32BitMode;
303   }
304
305   bool is16Bit() const {
306     return In16BitMode;
307   }
308
309   /// Is this x86_64 with the ILP32 programming model (x32 ABI)?
310   bool isTarget64BitILP32() const {
311     return In64BitMode && (TargetTriple.getEnvironment() == Triple::GNUX32 ||
312                            TargetTriple.isOSNaCl());
313   }
314
315   /// Is this x86_64 with the LP64 programming model (standard AMD64, no x32)?
316   bool isTarget64BitLP64() const {
317     return In64BitMode && (TargetTriple.getEnvironment() != Triple::GNUX32 &&
318                            !TargetTriple.isOSNaCl());
319   }
320
321   PICStyles::Style getPICStyle() const { return PICStyle; }
322   void setPICStyle(PICStyles::Style Style)  { PICStyle = Style; }
323
324   bool hasCMov() const { return HasCMov; }
325   bool hasMMX() const { return HasMMX; }
326   bool hasSSE1() const { return X86SSELevel >= SSE1; }
327   bool hasSSE2() const { return X86SSELevel >= SSE2; }
328   bool hasSSE3() const { return X86SSELevel >= SSE3; }
329   bool hasSSSE3() const { return X86SSELevel >= SSSE3; }
330   bool hasSSE41() const { return X86SSELevel >= SSE41; }
331   bool hasSSE42() const { return X86SSELevel >= SSE42; }
332   bool hasAVX() const { return X86SSELevel >= AVX; }
333   bool hasAVX2() const { return X86SSELevel >= AVX2; }
334   bool hasAVX512() const { return X86SSELevel >= AVX512F; }
335   bool hasFp256() const { return hasAVX(); }
336   bool hasInt256() const { return hasAVX2(); }
337   bool hasSSE4A() const { return HasSSE4A; }
338   bool has3DNow() const { return X863DNowLevel >= ThreeDNow; }
339   bool has3DNowA() const { return X863DNowLevel >= ThreeDNowA; }
340   bool hasPOPCNT() const { return HasPOPCNT; }
341   bool hasAES() const { return HasAES; }
342   bool hasPCLMUL() const { return HasPCLMUL; }
343   bool hasFMA() const { return HasFMA; }
344   // FIXME: Favor FMA when both are enabled. Is this the right thing to do?
345   bool hasFMA4() const { return HasFMA4 && !HasFMA; }
346   bool hasXOP() const { return HasXOP; }
347   bool hasTBM() const { return HasTBM; }
348   bool hasMOVBE() const { return HasMOVBE; }
349   bool hasRDRAND() const { return HasRDRAND; }
350   bool hasF16C() const { return HasF16C; }
351   bool hasFSGSBase() const { return HasFSGSBase; }
352   bool hasLZCNT() const { return HasLZCNT; }
353   bool hasBMI() const { return HasBMI; }
354   bool hasBMI2() const { return HasBMI2; }
355   bool hasRTM() const { return HasRTM; }
356   bool hasHLE() const { return HasHLE; }
357   bool hasADX() const { return HasADX; }
358   bool hasSHA() const { return HasSHA; }
359   bool hasPRFCHW() const { return HasPRFCHW; }
360   bool hasRDSEED() const { return HasRDSEED; }
361   bool isBTMemSlow() const { return IsBTMemSlow; }
362   bool isSHLDSlow() const { return IsSHLDSlow; }
363   bool isUnalignedMem16Slow() const { return IsUAMem16Slow; }
364   bool isUnalignedMem32Slow() const { return IsUAMem32Slow; }
365   bool hasSSEUnalignedMem() const { return HasSSEUnalignedMem; }
366   bool hasCmpxchg16b() const { return HasCmpxchg16b; }
367   bool useLeaForSP() const { return UseLeaForSP; }
368   bool hasSlowDivide32() const { return HasSlowDivide32; }
369   bool hasSlowDivide64() const { return HasSlowDivide64; }
370   bool padShortFunctions() const { return PadShortFunctions; }
371   bool callRegIndirect() const { return CallRegIndirect; }
372   bool LEAusesAG() const { return LEAUsesAG; }
373   bool slowLEA() const { return SlowLEA; }
374   bool slowIncDec() const { return SlowIncDec; }
375   bool hasCDI() const { return HasCDI; }
376   bool hasPFI() const { return HasPFI; }
377   bool hasERI() const { return HasERI; }
378   bool hasDQI() const { return HasDQI; }
379   bool hasBWI() const { return HasBWI; }
380   bool hasVLX() const { return HasVLX; }
381   bool hasMPX() const { return HasMPX; }
382
383   bool isAtom() const { return X86ProcFamily == IntelAtom; }
384   bool isSLM() const { return X86ProcFamily == IntelSLM; }
385   bool useSoftFloat() const { return UseSoftFloat; }
386
387   const Triple &getTargetTriple() const { return TargetTriple; }
388
389   bool isTargetDarwin() const { return TargetTriple.isOSDarwin(); }
390   bool isTargetFreeBSD() const { return TargetTriple.isOSFreeBSD(); }
391   bool isTargetDragonFly() const { return TargetTriple.isOSDragonFly(); }
392   bool isTargetSolaris() const { return TargetTriple.isOSSolaris(); }
393   bool isTargetPS4() const { return TargetTriple.isPS4(); }
394
395   bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
396   bool isTargetCOFF() const { return TargetTriple.isOSBinFormatCOFF(); }
397   bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); }
398
399   bool isTargetLinux() const { return TargetTriple.isOSLinux(); }
400   bool isTargetAndroid() const {
401     return TargetTriple.getEnvironment() == Triple::Android;
402   }
403   bool isTargetNaCl() const { return TargetTriple.isOSNaCl(); }
404   bool isTargetNaCl32() const { return isTargetNaCl() && !is64Bit(); }
405   bool isTargetNaCl64() const { return isTargetNaCl() && is64Bit(); }
406
407   bool isTargetWindowsMSVC() const {
408     return TargetTriple.isWindowsMSVCEnvironment();
409   }
410
411   bool isTargetKnownWindowsMSVC() const {
412     return TargetTriple.isKnownWindowsMSVCEnvironment();
413   }
414
415   bool isTargetWindowsCoreCLR() const {
416     return TargetTriple.isWindowsCoreCLREnvironment();
417   }
418
419   bool isTargetWindowsCygwin() const {
420     return TargetTriple.isWindowsCygwinEnvironment();
421   }
422
423   bool isTargetWindowsGNU() const {
424     return TargetTriple.isWindowsGNUEnvironment();
425   }
426
427   bool isTargetWindowsItanium() const {
428     return TargetTriple.isWindowsItaniumEnvironment();
429   }
430
431   bool isTargetCygMing() const { return TargetTriple.isOSCygMing(); }
432
433   bool isOSWindows() const { return TargetTriple.isOSWindows(); }
434
435   bool isTargetWin64() const {
436     return In64BitMode && TargetTriple.isOSWindows();
437   }
438
439   bool isTargetWin32() const {
440     return !In64BitMode && (isTargetCygMing() || isTargetKnownWindowsMSVC());
441   }
442
443   bool isPICStyleSet() const { return PICStyle != PICStyles::None; }
444   bool isPICStyleGOT() const { return PICStyle == PICStyles::GOT; }
445   bool isPICStyleRIPRel() const { return PICStyle == PICStyles::RIPRel; }
446
447   bool isPICStyleStubPIC() const {
448     return PICStyle == PICStyles::StubPIC;
449   }
450
451   bool isPICStyleStubNoDynamic() const {
452     return PICStyle == PICStyles::StubDynamicNoPIC;
453   }
454   bool isPICStyleStubAny() const {
455     return PICStyle == PICStyles::StubDynamicNoPIC ||
456            PICStyle == PICStyles::StubPIC;
457   }
458
459   bool isCallingConvWin64(CallingConv::ID CC) const {
460     switch (CC) {
461     // On Win64, all these conventions just use the default convention.
462     case CallingConv::C:
463     case CallingConv::Fast:
464     case CallingConv::X86_FastCall:
465     case CallingConv::X86_StdCall:
466     case CallingConv::X86_ThisCall:
467     case CallingConv::X86_VectorCall:
468     case CallingConv::Intel_OCL_BI:
469       return isTargetWin64();
470     // This convention allows using the Win64 convention on other targets.
471     case CallingConv::X86_64_Win64:
472       return true;
473     // This convention allows using the SysV convention on Windows targets.
474     case CallingConv::X86_64_SysV:
475       return false;
476     // Otherwise, who knows what this is.
477     default:
478       return false;
479     }
480   }
481
482   /// ClassifyGlobalReference - Classify a global variable reference for the
483   /// current subtarget according to how we should reference it in a non-pcrel
484   /// context.
485   unsigned char ClassifyGlobalReference(const GlobalValue *GV,
486                                         const TargetMachine &TM)const;
487
488   /// Classify a blockaddress reference for the current subtarget according to
489   /// how we should reference it in a non-pcrel context.
490   unsigned char ClassifyBlockAddressReference() const;
491
492   /// Return true if the subtarget allows calls to immediate address.
493   bool IsLegalToCallImmediateAddr(const TargetMachine &TM) const;
494
495   /// This function returns the name of a function which has an interface
496   /// like the non-standard bzero function, if such a function exists on
497   /// the current subtarget and it is considered prefereable over
498   /// memset with zero passed as the second argument. Otherwise it
499   /// returns null.
500   const char *getBZeroEntry() const;
501
502   /// This function returns true if the target has sincos() routine in its
503   /// compiler runtime or math libraries.
504   bool hasSinCos() const;
505
506   /// Enable the MachineScheduler pass for all X86 subtargets.
507   bool enableMachineScheduler() const override { return true; }
508
509   bool enableEarlyIfConversion() const override;
510
511   /// Return the instruction itineraries based on the subtarget selection.
512   const InstrItineraryData *getInstrItineraryData() const override {
513     return &InstrItins;
514   }
515
516   AntiDepBreakMode getAntiDepBreakMode() const override {
517     return TargetSubtargetInfo::ANTIDEP_CRITICAL;
518   }
519 };
520
521 } // End llvm namespace
522
523 #endif