Add a non-const subtarget returning function to the target machine
[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   /// HasSGX - Processor has SGX instructions.
143   bool HasSGX;
144
145   /// HasPRFCHW - Processor has PRFCHW instructions.
146   bool HasPRFCHW;
147
148   /// HasRDSEED - Processor has RDSEED instructions.
149   bool HasRDSEED;
150
151   /// IsBTMemSlow - True if BT (bit test) of memory instructions are slow.
152   bool IsBTMemSlow;
153
154   /// IsSHLDSlow - True if SHLD instructions are slow.
155   bool IsSHLDSlow;
156
157   /// IsUAMemFast - True if unaligned memory access is fast.
158   bool IsUAMemFast;
159
160   /// HasVectorUAMem - True if SIMD operations can have unaligned memory
161   /// operands. This may require setting a feature bit in the processor.
162   bool HasVectorUAMem;
163
164   /// HasCmpxchg16b - True if this processor has the CMPXCHG16B instruction;
165   /// this is true for most x86-64 chips, but not the first AMD chips.
166   bool HasCmpxchg16b;
167
168   /// UseLeaForSP - True if the LEA instruction should be used for adjusting
169   /// the stack pointer. This is an optimization for Intel Atom processors.
170   bool UseLeaForSP;
171
172   /// HasSlowDivide - True if smaller divides are significantly faster than
173   /// full divides and should be used when possible.
174   bool HasSlowDivide;
175
176   /// PadShortFunctions - True if the short functions should be padded to prevent
177   /// a stall when returning too early.
178   bool PadShortFunctions;
179
180   /// CallRegIndirect - True if the Calls with memory reference should be converted
181   /// to a register-based indirect call.
182   bool CallRegIndirect;
183   /// LEAUsesAG - True if the LEA instruction inputs have to be ready at
184   ///             address generation (AG) time.
185   bool LEAUsesAG;
186
187   /// SlowLEA - True if the LEA instruction with certain arguments is slow
188   bool SlowLEA;
189
190   /// SlowIncDec - True if INC and DEC instructions are slow when writing to flags
191   bool SlowIncDec;
192
193   /// Processor has AVX-512 PreFetch Instructions
194   bool HasPFI;
195
196   /// Processor has AVX-512 Exponential and Reciprocal Instructions
197   bool HasERI;
198
199   /// Processor has AVX-512 Conflict Detection Instructions
200   bool HasCDI;
201
202   /// Processor has AVX-512 Doubleword and Quadword instructions
203   bool HasDQI;
204
205   /// Processor has AVX-512 Byte and Word instructions
206   bool HasBWI;
207
208   /// Processor has AVX-512 Vector Length eXtenstions
209   bool HasVLX;
210
211   /// stackAlignment - The minimum alignment known to hold of the stack frame on
212   /// entry to the function and which must be maintained by every function.
213   unsigned stackAlignment;
214
215   /// Max. memset / memcpy size that is turned into rep/movs, rep/stos ops.
216   ///
217   unsigned MaxInlineSizeThreshold;
218
219   /// TargetTriple - What processor and OS we're targeting.
220   Triple TargetTriple;
221
222   /// Instruction itineraries for scheduling
223   InstrItineraryData InstrItins;
224
225 private:
226   /// StackAlignOverride - Override the stack alignment.
227   unsigned StackAlignOverride;
228
229   /// In64BitMode - True if compiling for 64-bit, false for 16-bit or 32-bit.
230   bool In64BitMode;
231
232   /// In32BitMode - True if compiling for 32-bit, false for 16-bit or 64-bit.
233   bool In32BitMode;
234
235   /// In16BitMode - True if compiling for 16-bit, false for 32-bit or 64-bit.
236   bool In16BitMode;
237
238   // Calculates type size & alignment
239   const DataLayout DL;
240   X86SelectionDAGInfo TSInfo;
241   // Ordering here is important. X86InstrInfo initializes X86RegisterInfo which
242   // X86TargetLowering needs.
243   X86InstrInfo InstrInfo;
244   X86TargetLowering TLInfo;
245   X86FrameLowering FrameLowering;
246   X86JITInfo JITInfo;
247
248 public:
249   /// This constructor initializes the data members to match that
250   /// of the specified triple.
251   ///
252   X86Subtarget(const std::string &TT, const std::string &CPU,
253                const std::string &FS, X86TargetMachine &TM,
254                unsigned StackAlignOverride);
255
256   const X86TargetLowering *getTargetLowering() const { return &TLInfo; }
257   const X86InstrInfo *getInstrInfo() const { return &InstrInfo; }
258   const DataLayout *getDataLayout() const { return &DL; }
259   const X86FrameLowering *getFrameLowering() const { return &FrameLowering; }
260   const X86SelectionDAGInfo *getSelectionDAGInfo() const { return &TSInfo; }
261   X86JITInfo *getJITInfo() { return &JITInfo; }
262
263   /// getStackAlignment - Returns the minimum alignment known to hold of the
264   /// stack frame on entry to the function and which must be maintained by every
265   /// function for this subtarget.
266   unsigned getStackAlignment() const { return stackAlignment; }
267
268   /// getMaxInlineSizeThreshold - Returns the maximum memset / memcpy size
269   /// that still makes it profitable to inline the call.
270   unsigned getMaxInlineSizeThreshold() const { return MaxInlineSizeThreshold; }
271
272   /// ParseSubtargetFeatures - Parses features string setting specified
273   /// subtarget options.  Definition of function is auto generated by tblgen.
274   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
275
276   /// \brief Reset the features for the X86 target.
277   void resetSubtargetFeatures(const MachineFunction *MF) override;
278 private:
279   /// \brief Initialize the full set of dependencies so we can use an initializer
280   /// list for X86Subtarget.
281   X86Subtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
282   void initializeEnvironment();
283   void resetSubtargetFeatures(StringRef CPU, StringRef FS);
284 public:
285   /// Is this x86_64? (disregarding specific ABI / programming model)
286   bool is64Bit() const {
287     return In64BitMode;
288   }
289
290   bool is32Bit() const {
291     return In32BitMode;
292   }
293
294   bool is16Bit() const {
295     return In16BitMode;
296   }
297
298   /// Is this x86_64 with the ILP32 programming model (x32 ABI)?
299   bool isTarget64BitILP32() const {
300     return In64BitMode && (TargetTriple.getEnvironment() == Triple::GNUX32 ||
301                            TargetTriple.getOS() == Triple::NaCl);
302   }
303
304   /// Is this x86_64 with the LP64 programming model (standard AMD64, no x32)?
305   bool isTarget64BitLP64() const {
306     return In64BitMode && (TargetTriple.getEnvironment() != Triple::GNUX32);
307   }
308
309   PICStyles::Style getPICStyle() const { return PICStyle; }
310   void setPICStyle(PICStyles::Style Style)  { PICStyle = Style; }
311
312   bool hasCMov() const { return HasCMov; }
313   bool hasMMX() const { return X86SSELevel >= MMX; }
314   bool hasSSE1() const { return X86SSELevel >= SSE1; }
315   bool hasSSE2() const { return X86SSELevel >= SSE2; }
316   bool hasSSE3() const { return X86SSELevel >= SSE3; }
317   bool hasSSSE3() const { return X86SSELevel >= SSSE3; }
318   bool hasSSE41() const { return X86SSELevel >= SSE41; }
319   bool hasSSE42() const { return X86SSELevel >= SSE42; }
320   bool hasAVX() const { return X86SSELevel >= AVX; }
321   bool hasAVX2() const { return X86SSELevel >= AVX2; }
322   bool hasAVX512() const { return X86SSELevel >= AVX512F; }
323   bool hasFp256() const { return hasAVX(); }
324   bool hasInt256() const { return hasAVX2(); }
325   bool hasSSE4A() const { return HasSSE4A; }
326   bool has3DNow() const { return X863DNowLevel >= ThreeDNow; }
327   bool has3DNowA() const { return X863DNowLevel >= ThreeDNowA; }
328   bool hasPOPCNT() const { return HasPOPCNT; }
329   bool hasAES() const { return HasAES; }
330   bool hasPCLMUL() const { return HasPCLMUL; }
331   bool hasFMA() const { return HasFMA; }
332   // FIXME: Favor FMA when both are enabled. Is this the right thing to do?
333   bool hasFMA4() const { return HasFMA4 && !HasFMA; }
334   bool hasXOP() const { return HasXOP; }
335   bool hasTBM() const { return HasTBM; }
336   bool hasMOVBE() const { return HasMOVBE; }
337   bool hasRDRAND() const { return HasRDRAND; }
338   bool hasF16C() const { return HasF16C; }
339   bool hasFSGSBase() const { return HasFSGSBase; }
340   bool hasLZCNT() const { return HasLZCNT; }
341   bool hasBMI() const { return HasBMI; }
342   bool hasBMI2() const { return HasBMI2; }
343   bool hasRTM() const { return HasRTM; }
344   bool hasHLE() const { return HasHLE; }
345   bool hasADX() const { return HasADX; }
346   bool hasSHA() const { return HasSHA; }
347   bool hasSGX() const { return HasSGX; }
348   bool hasPRFCHW() const { return HasPRFCHW; }
349   bool hasRDSEED() const { return HasRDSEED; }
350   bool isBTMemSlow() const { return IsBTMemSlow; }
351   bool isSHLDSlow() const { return IsSHLDSlow; }
352   bool isUnalignedMemAccessFast() const { return IsUAMemFast; }
353   bool hasVectorUAMem() const { return HasVectorUAMem; }
354   bool hasCmpxchg16b() const { return HasCmpxchg16b; }
355   bool useLeaForSP() const { return UseLeaForSP; }
356   bool hasSlowDivide() const { return HasSlowDivide; }
357   bool padShortFunctions() const { return PadShortFunctions; }
358   bool callRegIndirect() const { return CallRegIndirect; }
359   bool LEAusesAG() const { return LEAUsesAG; }
360   bool slowLEA() const { return SlowLEA; }
361   bool slowIncDec() const { return SlowIncDec; }
362   bool hasCDI() const { return HasCDI; }
363   bool hasPFI() const { return HasPFI; }
364   bool hasERI() const { return HasERI; }
365   bool hasDQI() const { return HasDQI; }
366   bool hasBWI() const { return HasBWI; }
367   bool hasVLX() const { return HasVLX; }
368
369   bool isAtom() const { return X86ProcFamily == IntelAtom; }
370   bool isSLM() const { return X86ProcFamily == IntelSLM; }
371
372   const Triple &getTargetTriple() const { return TargetTriple; }
373
374   bool isTargetDarwin() const { return TargetTriple.isOSDarwin(); }
375   bool isTargetFreeBSD() const {
376     return TargetTriple.getOS() == Triple::FreeBSD;
377   }
378   bool isTargetSolaris() const {
379     return TargetTriple.getOS() == Triple::Solaris;
380   }
381
382   bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
383   bool isTargetCOFF() const { return TargetTriple.isOSBinFormatCOFF(); }
384   bool isTargetMacho() const { return TargetTriple.isOSBinFormatMachO(); }
385
386   bool isTargetLinux() const { return TargetTriple.isOSLinux(); }
387   bool isTargetNaCl() const { return TargetTriple.isOSNaCl(); }
388   bool isTargetNaCl32() const { return isTargetNaCl() && !is64Bit(); }
389   bool isTargetNaCl64() const { return isTargetNaCl() && is64Bit(); }
390
391   bool isTargetWindowsMSVC() const {
392     return TargetTriple.isWindowsMSVCEnvironment();
393   }
394
395   bool isTargetKnownWindowsMSVC() const {
396     return TargetTriple.isKnownWindowsMSVCEnvironment();
397   }
398
399   bool isTargetWindowsCygwin() const {
400     return TargetTriple.isWindowsCygwinEnvironment();
401   }
402
403   bool isTargetWindowsGNU() const {
404     return TargetTriple.isWindowsGNUEnvironment();
405   }
406
407   bool isTargetCygMing() const { return TargetTriple.isOSCygMing(); }
408
409   bool isOSWindows() const { return TargetTriple.isOSWindows(); }
410
411   bool isTargetWin64() const {
412     return In64BitMode && TargetTriple.isOSWindows();
413   }
414
415   bool isTargetWin32() const {
416     return !In64BitMode && (isTargetCygMing() || isTargetKnownWindowsMSVC());
417   }
418
419   bool isPICStyleSet() const { return PICStyle != PICStyles::None; }
420   bool isPICStyleGOT() const { return PICStyle == PICStyles::GOT; }
421   bool isPICStyleRIPRel() const { return PICStyle == PICStyles::RIPRel; }
422
423   bool isPICStyleStubPIC() const {
424     return PICStyle == PICStyles::StubPIC;
425   }
426
427   bool isPICStyleStubNoDynamic() const {
428     return PICStyle == PICStyles::StubDynamicNoPIC;
429   }
430   bool isPICStyleStubAny() const {
431     return PICStyle == PICStyles::StubDynamicNoPIC ||
432            PICStyle == PICStyles::StubPIC;
433   }
434
435   bool isCallingConvWin64(CallingConv::ID CC) const {
436     return (isTargetWin64() && CC != CallingConv::X86_64_SysV) ||
437            CC == CallingConv::X86_64_Win64;
438   }
439
440   /// ClassifyGlobalReference - Classify a global variable reference for the
441   /// current subtarget according to how we should reference it in a non-pcrel
442   /// context.
443   unsigned char ClassifyGlobalReference(const GlobalValue *GV,
444                                         const TargetMachine &TM)const;
445
446   /// ClassifyBlockAddressReference - Classify a blockaddress reference for the
447   /// current subtarget according to how we should reference it in a non-pcrel
448   /// context.
449   unsigned char ClassifyBlockAddressReference() const;
450
451   /// IsLegalToCallImmediateAddr - Return true if the subtarget allows calls
452   /// to immediate address.
453   bool IsLegalToCallImmediateAddr(const TargetMachine &TM) const;
454
455   /// This function returns the name of a function which has an interface
456   /// like the non-standard bzero function, if such a function exists on
457   /// the current subtarget and it is considered prefereable over
458   /// memset with zero passed as the second argument. Otherwise it
459   /// returns null.
460   const char *getBZeroEntry() const;
461
462   /// This function returns true if the target has sincos() routine in its
463   /// compiler runtime or math libraries.
464   bool hasSinCos() const;
465
466   /// Enable the MachineScheduler pass for all X86 subtargets.
467   bool enableMachineScheduler() const override { return true; }
468
469   bool enableEarlyIfConversion() const override;
470
471   /// getInstrItins = Return the instruction itineraries based on the
472   /// subtarget selection.
473   const InstrItineraryData &getInstrItineraryData() const { return InstrItins; }
474
475   AntiDepBreakMode getAntiDepBreakMode() const override {
476     return TargetSubtargetInfo::ANTIDEP_CRITICAL;
477   }
478 };
479
480 } // End llvm namespace
481
482 #endif