1 //===-- X86Subtarget.h - Define Subtarget for the X86 ----------*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the X86 specific subclass of TargetSubtargetInfo.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_X86_X86SUBTARGET_H
15 #define LLVM_LIB_TARGET_X86_X86SUBTARGET_H
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"
27 #define GET_SUBTARGETINFO_HEADER
28 #include "X86GenSubtargetInfo.inc"
35 /// PICStyles - The X86 backend supports a number of different styles of PIC.
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).
47 class X86Subtarget final : public X86GenSubtargetInfo {
51 NoMMXSSE, MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42, AVX, AVX2, AVX512F
55 NoThreeDNow, ThreeDNow, ThreeDNowA
58 enum X86ProcFamilyEnum {
59 Others, IntelAtom, IntelSLM
62 /// X86ProcFamily - X86 processor family: Intel Atom, and others
63 X86ProcFamilyEnum X86ProcFamily;
65 /// PICStyle - Which PIC style to use
67 PICStyles::Style PICStyle;
69 /// X86SSELevel - MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42, or
71 X86SSEEnum X86SSELevel;
73 /// X863DNowLevel - 3DNow or 3DNow Athlon, or none supported.
75 X863DNowEnum X863DNowLevel;
77 /// HasCMov - True if this processor has conditional move instructions
78 /// (generally pentium pro+).
81 /// HasX86_64 - True if the processor supports X86-64 instructions.
85 /// HasPOPCNT - True if the processor supports POPCNT.
88 /// HasSSE4A - True if the processor supports SSE4A instructions.
91 /// HasAES - Target has AES instructions
94 /// HasPCLMUL - Target has carry-less multiplication
97 /// HasFMA - Target has 3-operand fused multiply-add
100 /// HasFMA4 - Target has 4-operand fused multiply-add
103 /// HasXOP - Target has XOP instructions
106 /// HasTBM - Target has TBM instructions.
109 /// HasMOVBE - True if the processor has the MOVBE instruction.
112 /// HasRDRAND - True if the processor has the RDRAND instruction.
115 /// HasF16C - Processor has 16-bit floating point conversion instructions.
118 /// HasFSGSBase - Processor has FS/GS base insturctions.
121 /// HasLZCNT - Processor has LZCNT instruction.
124 /// HasBMI - Processor has BMI1 instructions.
127 /// HasBMI2 - Processor has BMI2 instructions.
130 /// HasRTM - Processor has RTM instructions.
133 /// HasHLE - Processor has HLE.
136 /// HasADX - Processor has ADX instructions.
139 /// HasSHA - Processor has SHA instructions.
142 /// HasSGX - Processor has SGX instructions.
145 /// HasPRFCHW - Processor has PRFCHW instructions.
148 /// HasRDSEED - Processor has RDSEED instructions.
151 /// HasSMAP - Processor has SMAP instructions.
154 /// IsBTMemSlow - True if BT (bit test) of memory instructions are slow.
157 /// IsSHLDSlow - True if SHLD instructions are slow.
160 /// IsUAMemFast - True if unaligned memory access is fast.
163 /// HasVectorUAMem - True if SIMD operations can have unaligned memory
164 /// operands. This may require setting a feature bit in the processor.
167 /// HasCmpxchg16b - True if this processor has the CMPXCHG16B instruction;
168 /// this is true for most x86-64 chips, but not the first AMD chips.
171 /// UseLeaForSP - True if the LEA instruction should be used for adjusting
172 /// the stack pointer. This is an optimization for Intel Atom processors.
175 /// HasSlowDivide - True if smaller divides are significantly faster than
176 /// full divides and should be used when possible.
179 /// PadShortFunctions - True if the short functions should be padded to prevent
180 /// a stall when returning too early.
181 bool PadShortFunctions;
183 /// CallRegIndirect - True if the Calls with memory reference should be converted
184 /// to a register-based indirect call.
185 bool CallRegIndirect;
186 /// LEAUsesAG - True if the LEA instruction inputs have to be ready at
187 /// address generation (AG) time.
190 /// SlowLEA - True if the LEA instruction with certain arguments is slow
193 /// SlowIncDec - True if INC and DEC instructions are slow when writing to flags
196 /// Processor has AVX-512 PreFetch Instructions
199 /// Processor has AVX-512 Exponential and Reciprocal Instructions
202 /// Processor has AVX-512 Conflict Detection Instructions
205 /// Processor has AVX-512 Doubleword and Quadword instructions
208 /// Processor has AVX-512 Byte and Word instructions
211 /// Processor has AVX-512 Vector Length eXtenstions
214 /// stackAlignment - The minimum alignment known to hold of the stack frame on
215 /// entry to the function and which must be maintained by every function.
216 unsigned stackAlignment;
218 /// Max. memset / memcpy size that is turned into rep/movs, rep/stos ops.
220 unsigned MaxInlineSizeThreshold;
222 /// TargetTriple - What processor and OS we're targeting.
225 /// Instruction itineraries for scheduling
226 InstrItineraryData InstrItins;
229 // Calculates type size & alignment
232 /// StackAlignOverride - Override the stack alignment.
233 unsigned StackAlignOverride;
235 /// In64BitMode - True if compiling for 64-bit, false for 16-bit or 32-bit.
238 /// In32BitMode - True if compiling for 32-bit, false for 16-bit or 64-bit.
241 /// In16BitMode - True if compiling for 16-bit, false for 32-bit or 64-bit.
244 X86SelectionDAGInfo TSInfo;
245 // Ordering here is important. X86InstrInfo initializes X86RegisterInfo which
246 // X86TargetLowering needs.
247 X86InstrInfo InstrInfo;
248 X86TargetLowering TLInfo;
249 X86FrameLowering FrameLowering;
253 /// This constructor initializes the data members to match that
254 /// of the specified triple.
256 X86Subtarget(const std::string &TT, const std::string &CPU,
257 const std::string &FS, X86TargetMachine &TM,
258 unsigned StackAlignOverride);
260 const X86TargetLowering *getTargetLowering() const override {
263 const X86InstrInfo *getInstrInfo() const override { return &InstrInfo; }
264 const DataLayout *getDataLayout() const override { return &DL; }
265 const X86FrameLowering *getFrameLowering() const override {
266 return &FrameLowering;
268 const X86SelectionDAGInfo *getSelectionDAGInfo() const override {
271 const X86RegisterInfo *getRegisterInfo() const override {
272 return &getInstrInfo()->getRegisterInfo();
274 X86JITInfo *getJITInfo() override { return &JITInfo; }
276 /// getStackAlignment - 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; }
281 /// getMaxInlineSizeThreshold - Returns the maximum memset / memcpy size
282 /// that still makes it profitable to inline the call.
283 unsigned getMaxInlineSizeThreshold() const { return MaxInlineSizeThreshold; }
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);
289 /// \brief Reset the features for the X86 target.
290 void resetSubtargetFeatures(const MachineFunction *MF) override;
292 /// \brief Initialize the full set of dependencies so we can use an initializer
293 /// list for X86Subtarget.
294 X86Subtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
295 void initializeEnvironment();
296 void resetSubtargetFeatures(StringRef CPU, StringRef FS);
298 /// Is this x86_64? (disregarding specific ABI / programming model)
299 bool is64Bit() const {
303 bool is32Bit() const {
307 bool is16Bit() const {
311 /// Is this x86_64 with the ILP32 programming model (x32 ABI)?
312 bool isTarget64BitILP32() const {
313 return In64BitMode && (TargetTriple.getEnvironment() == Triple::GNUX32 ||
314 TargetTriple.getOS() == Triple::NaCl);
317 /// Is this x86_64 with the LP64 programming model (standard AMD64, no x32)?
318 bool isTarget64BitLP64() const {
319 return In64BitMode && (TargetTriple.getEnvironment() != Triple::GNUX32 &&
320 TargetTriple.getOS() != Triple::NaCl);
323 PICStyles::Style getPICStyle() const { return PICStyle; }
324 void setPICStyle(PICStyles::Style Style) { PICStyle = Style; }
326 bool hasCMov() const { return HasCMov; }
327 bool hasMMX() const { return X86SSELevel >= MMX; }
328 bool hasSSE1() const { return X86SSELevel >= SSE1; }
329 bool hasSSE2() const { return X86SSELevel >= SSE2; }
330 bool hasSSE3() const { return X86SSELevel >= SSE3; }
331 bool hasSSSE3() const { return X86SSELevel >= SSSE3; }
332 bool hasSSE41() const { return X86SSELevel >= SSE41; }
333 bool hasSSE42() const { return X86SSELevel >= SSE42; }
334 bool hasAVX() const { return X86SSELevel >= AVX; }
335 bool hasAVX2() const { return X86SSELevel >= AVX2; }
336 bool hasAVX512() const { return X86SSELevel >= AVX512F; }
337 bool hasFp256() const { return hasAVX(); }
338 bool hasInt256() const { return hasAVX2(); }
339 bool hasSSE4A() const { return HasSSE4A; }
340 bool has3DNow() const { return X863DNowLevel >= ThreeDNow; }
341 bool has3DNowA() const { return X863DNowLevel >= ThreeDNowA; }
342 bool hasPOPCNT() const { return HasPOPCNT; }
343 bool hasAES() const { return HasAES; }
344 bool hasPCLMUL() const { return HasPCLMUL; }
345 bool hasFMA() const { return HasFMA; }
346 // FIXME: Favor FMA when both are enabled. Is this the right thing to do?
347 bool hasFMA4() const { return HasFMA4 && !HasFMA; }
348 bool hasXOP() const { return HasXOP; }
349 bool hasTBM() const { return HasTBM; }
350 bool hasMOVBE() const { return HasMOVBE; }
351 bool hasRDRAND() const { return HasRDRAND; }
352 bool hasF16C() const { return HasF16C; }
353 bool hasFSGSBase() const { return HasFSGSBase; }
354 bool hasLZCNT() const { return HasLZCNT; }
355 bool hasBMI() const { return HasBMI; }
356 bool hasBMI2() const { return HasBMI2; }
357 bool hasRTM() const { return HasRTM; }
358 bool hasHLE() const { return HasHLE; }
359 bool hasADX() const { return HasADX; }
360 bool hasSHA() const { return HasSHA; }
361 bool hasSGX() const { return HasSGX; }
362 bool hasPRFCHW() const { return HasPRFCHW; }
363 bool hasRDSEED() const { return HasRDSEED; }
364 bool hasSMAP() const { return HasSMAP; }
365 bool isBTMemSlow() const { return IsBTMemSlow; }
366 bool isSHLDSlow() const { return IsSHLDSlow; }
367 bool isUnalignedMemAccessFast() const { return IsUAMemFast; }
368 bool hasVectorUAMem() const { return HasVectorUAMem; }
369 bool hasCmpxchg16b() const { return HasCmpxchg16b; }
370 bool useLeaForSP() const { return UseLeaForSP; }
371 bool hasSlowDivide() const { return HasSlowDivide; }
372 bool padShortFunctions() const { return PadShortFunctions; }
373 bool callRegIndirect() const { return CallRegIndirect; }
374 bool LEAusesAG() const { return LEAUsesAG; }
375 bool slowLEA() const { return SlowLEA; }
376 bool slowIncDec() const { return SlowIncDec; }
377 bool hasCDI() const { return HasCDI; }
378 bool hasPFI() const { return HasPFI; }
379 bool hasERI() const { return HasERI; }
380 bool hasDQI() const { return HasDQI; }
381 bool hasBWI() const { return HasBWI; }
382 bool hasVLX() const { return HasVLX; }
384 bool isAtom() const { return X86ProcFamily == IntelAtom; }
385 bool isSLM() const { return X86ProcFamily == IntelSLM; }
387 const Triple &getTargetTriple() const { return TargetTriple; }
389 bool isTargetDarwin() const { return TargetTriple.isOSDarwin(); }
390 bool isTargetFreeBSD() const {
391 return TargetTriple.getOS() == Triple::FreeBSD;
393 bool isTargetSolaris() const {
394 return TargetTriple.getOS() == Triple::Solaris;
397 bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
398 bool isTargetCOFF() const { return TargetTriple.isOSBinFormatCOFF(); }
399 bool isTargetMacho() const { return TargetTriple.isOSBinFormatMachO(); }
401 bool isTargetLinux() const { return TargetTriple.isOSLinux(); }
402 bool isTargetNaCl() const { return TargetTriple.isOSNaCl(); }
403 bool isTargetNaCl32() const { return isTargetNaCl() && !is64Bit(); }
404 bool isTargetNaCl64() const { return isTargetNaCl() && is64Bit(); }
406 bool isTargetWindowsMSVC() const {
407 return TargetTriple.isWindowsMSVCEnvironment();
410 bool isTargetKnownWindowsMSVC() const {
411 return TargetTriple.isKnownWindowsMSVCEnvironment();
414 bool isTargetWindowsCygwin() const {
415 return TargetTriple.isWindowsCygwinEnvironment();
418 bool isTargetWindowsGNU() const {
419 return TargetTriple.isWindowsGNUEnvironment();
422 bool isTargetCygMing() const { return TargetTriple.isOSCygMing(); }
424 bool isOSWindows() const { return TargetTriple.isOSWindows(); }
426 bool isTargetWin64() const {
427 return In64BitMode && TargetTriple.isOSWindows();
430 bool isTargetWin32() const {
431 return !In64BitMode && (isTargetCygMing() || isTargetKnownWindowsMSVC());
434 bool isPICStyleSet() const { return PICStyle != PICStyles::None; }
435 bool isPICStyleGOT() const { return PICStyle == PICStyles::GOT; }
436 bool isPICStyleRIPRel() const { return PICStyle == PICStyles::RIPRel; }
438 bool isPICStyleStubPIC() const {
439 return PICStyle == PICStyles::StubPIC;
442 bool isPICStyleStubNoDynamic() const {
443 return PICStyle == PICStyles::StubDynamicNoPIC;
445 bool isPICStyleStubAny() const {
446 return PICStyle == PICStyles::StubDynamicNoPIC ||
447 PICStyle == PICStyles::StubPIC;
450 bool isCallingConvWin64(CallingConv::ID CC) const {
451 return (isTargetWin64() && CC != CallingConv::X86_64_SysV) ||
452 CC == CallingConv::X86_64_Win64;
455 /// ClassifyGlobalReference - Classify a global variable reference for the
456 /// current subtarget according to how we should reference it in a non-pcrel
458 unsigned char ClassifyGlobalReference(const GlobalValue *GV,
459 const TargetMachine &TM)const;
461 /// ClassifyBlockAddressReference - Classify a blockaddress reference for the
462 /// current subtarget according to how we should reference it in a non-pcrel
464 unsigned char ClassifyBlockAddressReference() const;
466 /// IsLegalToCallImmediateAddr - Return true if the subtarget allows calls
467 /// to immediate address.
468 bool IsLegalToCallImmediateAddr(const TargetMachine &TM) const;
470 /// This function returns the name of a function which has an interface
471 /// like the non-standard bzero function, if such a function exists on
472 /// the current subtarget and it is considered prefereable over
473 /// memset with zero passed as the second argument. Otherwise it
475 const char *getBZeroEntry() const;
477 /// This function returns true if the target has sincos() routine in its
478 /// compiler runtime or math libraries.
479 bool hasSinCos() const;
481 /// Enable the MachineScheduler pass for all X86 subtargets.
482 bool enableMachineScheduler() const override { return true; }
484 bool enableEarlyIfConversion() const override;
486 /// getInstrItins = Return the instruction itineraries based on the
487 /// subtarget selection.
488 const InstrItineraryData *getInstrItineraryData() const override {
492 AntiDepBreakMode getAntiDepBreakMode() const override {
493 return TargetSubtargetInfo::ANTIDEP_CRITICAL;
497 } // End llvm namespace