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