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