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