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 "X86SelectionDAGInfo.h"
21 #include "llvm/ADT/Triple.h"
22 #include "llvm/IR/CallingConv.h"
23 #include "llvm/Target/TargetSubtargetInfo.h"
26 #define GET_SUBTARGETINFO_HEADER
27 #include "X86GenSubtargetInfo.inc"
34 /// The X86 backend supports a number of different styles of PIC.
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).
46 class X86Subtarget final : public X86GenSubtargetInfo {
50 NoMMXSSE, MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42, AVX, AVX2, AVX512F
54 NoThreeDNow, ThreeDNow, ThreeDNowA
57 enum X86ProcFamilyEnum {
58 Others, IntelAtom, IntelSLM
61 /// X86 processor family: Intel Atom, and others
62 X86ProcFamilyEnum X86ProcFamily;
64 /// Which PIC style to use
65 PICStyles::Style PICStyle;
67 /// MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42, or none supported.
68 X86SSEEnum X86SSELevel;
70 /// 3DNow, 3DNow Athlon, or none supported.
71 X863DNowEnum X863DNowLevel;
73 /// True if this processor has conditional move instructions
74 /// (generally pentium pro+).
77 /// True if the processor supports X86-64 instructions.
80 /// True if the processor supports POPCNT.
83 /// True if the processor supports SSE4A instructions.
86 /// Target has AES instructions
89 /// Target has carry-less multiplication
92 /// Target has 3-operand fused multiply-add
95 /// Target has 4-operand fused multiply-add
98 /// Target has XOP instructions
101 /// Target has TBM instructions.
104 /// True if the processor has the MOVBE instruction.
107 /// True if the processor has the RDRAND instruction.
110 /// Processor has 16-bit floating point conversion instructions.
113 /// Processor has FS/GS base insturctions.
116 /// Processor has LZCNT instruction.
119 /// Processor has BMI1 instructions.
122 /// Processor has BMI2 instructions.
125 /// Processor has RTM instructions.
128 /// Processor has HLE.
131 /// Processor has ADX instructions.
134 /// Processor has SHA instructions.
137 /// Processor has PRFCHW instructions.
140 /// Processor has RDSEED instructions.
143 /// True if BT (bit test) of memory instructions are slow.
146 /// True if SHLD instructions are slow.
149 /// True if unaligned memory access is fast.
152 /// True if unaligned 32-byte memory accesses are slow.
155 /// True if SSE operations can have unaligned memory operands.
156 /// This may require setting a configuration bit in the processor.
157 bool HasSSEUnalignedMem;
159 /// True if this processor has the CMPXCHG16B instruction;
160 /// this is true for most x86-64 chips, but not the first AMD chips.
163 /// True if the LEA instruction should be used for adjusting
164 /// the stack pointer. This is an optimization for Intel Atom processors.
167 /// True if 8-bit divisions are significantly faster than
168 /// 32-bit divisions and should be used when possible.
169 bool HasSlowDivide32;
171 /// True if 16-bit divides are significantly faster than
172 /// 64-bit divisions and should be used when possible.
173 bool HasSlowDivide64;
175 /// True if the short functions should be padded to prevent
176 /// a stall when returning too early.
177 bool PadShortFunctions;
179 /// True if the Calls with memory reference should be converted
180 /// to a register-based indirect call.
181 bool CallRegIndirect;
183 /// True if the LEA instruction inputs have to be ready at address generation
187 /// True if the LEA instruction with certain arguments is slow
190 /// True if INC and DEC instructions are slow when writing to flags
193 /// Use the RSQRT* instructions to optimize square root calculations.
194 /// For this to be profitable, the cost of FSQRT and FDIV must be
195 /// substantially higher than normal FP ops like FADD and FMUL.
198 /// Use the RCP* instructions to optimize FP division calculations.
199 /// For this to be profitable, the cost of FDIV must be
200 /// substantially higher than normal FP ops like FADD and FMUL.
201 bool UseReciprocalEst;
203 /// Processor has AVX-512 PreFetch Instructions
206 /// Processor has AVX-512 Exponential and Reciprocal Instructions
209 /// Processor has AVX-512 Conflict Detection Instructions
212 /// Processor has AVX-512 Doubleword and Quadword instructions
215 /// Processor has AVX-512 Byte and Word instructions
218 /// Processor has AVX-512 Vector Length eXtenstions
221 /// Use software floating point for code generation.
224 /// The minimum alignment known to hold of the stack frame on
225 /// entry to the function and which must be maintained by every function.
226 unsigned stackAlignment;
228 /// Max. memset / memcpy size that is turned into rep/movs, rep/stos ops.
230 unsigned MaxInlineSizeThreshold;
232 /// What processor and OS we're targeting.
235 /// Instruction itineraries for scheduling
236 InstrItineraryData InstrItins;
240 /// Override the stack alignment.
241 unsigned StackAlignOverride;
243 /// True if compiling for 64-bit, false for 16-bit or 32-bit.
246 /// True if compiling for 32-bit, false for 16-bit or 64-bit.
249 /// True if compiling for 16-bit, false for 32-bit or 64-bit.
252 X86SelectionDAGInfo TSInfo;
253 // Ordering here is important. X86InstrInfo initializes X86RegisterInfo which
254 // X86TargetLowering needs.
255 X86InstrInfo InstrInfo;
256 X86TargetLowering TLInfo;
257 X86FrameLowering FrameLowering;
260 /// This constructor initializes the data members to match that
261 /// of the specified triple.
263 X86Subtarget(const std::string &TT, const std::string &CPU,
264 const std::string &FS, const X86TargetMachine &TM,
265 unsigned StackAlignOverride);
267 const X86TargetLowering *getTargetLowering() const override {
270 const X86InstrInfo *getInstrInfo() const override { return &InstrInfo; }
271 const X86FrameLowering *getFrameLowering() const override {
272 return &FrameLowering;
274 const X86SelectionDAGInfo *getSelectionDAGInfo() const override {
277 const X86RegisterInfo *getRegisterInfo() const override {
278 return &getInstrInfo()->getRegisterInfo();
281 /// Returns the minimum alignment known to hold of the
282 /// stack frame on entry to the function and which must be maintained by every
283 /// function for this subtarget.
284 unsigned getStackAlignment() const { return stackAlignment; }
286 /// Returns the maximum memset / memcpy size
287 /// that still makes it profitable to inline the call.
288 unsigned getMaxInlineSizeThreshold() const { return MaxInlineSizeThreshold; }
290 /// ParseSubtargetFeatures - Parses features string setting specified
291 /// subtarget options. Definition of function is auto generated by tblgen.
292 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
295 /// Initialize the full set of dependencies so we can use an initializer
296 /// list for X86Subtarget.
297 X86Subtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
298 void initializeEnvironment();
299 void initSubtargetFeatures(StringRef CPU, StringRef FS);
301 /// Is this x86_64? (disregarding specific ABI / programming model)
302 bool is64Bit() const {
306 bool is32Bit() const {
310 bool is16Bit() const {
314 /// Is this x86_64 with the ILP32 programming model (x32 ABI)?
315 bool isTarget64BitILP32() const {
316 return In64BitMode && (TargetTriple.getEnvironment() == Triple::GNUX32 ||
317 TargetTriple.isOSNaCl());
320 /// Is this x86_64 with the LP64 programming model (standard AMD64, no x32)?
321 bool isTarget64BitLP64() const {
322 return In64BitMode && (TargetTriple.getEnvironment() != Triple::GNUX32 &&
323 !TargetTriple.isOSNaCl());
326 PICStyles::Style getPICStyle() const { return PICStyle; }
327 void setPICStyle(PICStyles::Style Style) { PICStyle = Style; }
329 bool hasCMov() const { return HasCMov; }
330 bool hasMMX() const { return X86SSELevel >= MMX; }
331 bool hasSSE1() const { return X86SSELevel >= SSE1; }
332 bool hasSSE2() const { return X86SSELevel >= SSE2; }
333 bool hasSSE3() const { return X86SSELevel >= SSE3; }
334 bool hasSSSE3() const { return X86SSELevel >= SSSE3; }
335 bool hasSSE41() const { return X86SSELevel >= SSE41; }
336 bool hasSSE42() const { return X86SSELevel >= SSE42; }
337 bool hasAVX() const { return X86SSELevel >= AVX; }
338 bool hasAVX2() const { return X86SSELevel >= AVX2; }
339 bool hasAVX512() const { return X86SSELevel >= AVX512F; }
340 bool hasFp256() const { return hasAVX(); }
341 bool hasInt256() const { return hasAVX2(); }
342 bool hasSSE4A() const { return HasSSE4A; }
343 bool has3DNow() const { return X863DNowLevel >= ThreeDNow; }
344 bool has3DNowA() const { return X863DNowLevel >= ThreeDNowA; }
345 bool hasPOPCNT() const { return HasPOPCNT; }
346 bool hasAES() const { return HasAES; }
347 bool hasPCLMUL() const { return HasPCLMUL; }
348 bool hasFMA() const { return HasFMA; }
349 // FIXME: Favor FMA when both are enabled. Is this the right thing to do?
350 bool hasFMA4() const { return HasFMA4 && !HasFMA; }
351 bool hasXOP() const { return HasXOP; }
352 bool hasTBM() const { return HasTBM; }
353 bool hasMOVBE() const { return HasMOVBE; }
354 bool hasRDRAND() const { return HasRDRAND; }
355 bool hasF16C() const { return HasF16C; }
356 bool hasFSGSBase() const { return HasFSGSBase; }
357 bool hasLZCNT() const { return HasLZCNT; }
358 bool hasBMI() const { return HasBMI; }
359 bool hasBMI2() const { return HasBMI2; }
360 bool hasRTM() const { return HasRTM; }
361 bool hasHLE() const { return HasHLE; }
362 bool hasADX() const { return HasADX; }
363 bool hasSHA() const { return HasSHA; }
364 bool hasPRFCHW() const { return HasPRFCHW; }
365 bool hasRDSEED() const { return HasRDSEED; }
366 bool isBTMemSlow() const { return IsBTMemSlow; }
367 bool isSHLDSlow() const { return IsSHLDSlow; }
368 bool isUnalignedMemAccessFast() const { return IsUAMemFast; }
369 bool isUnalignedMem32Slow() const { return IsUAMem32Slow; }
370 bool hasSSEUnalignedMem() const { return HasSSEUnalignedMem; }
371 bool hasCmpxchg16b() const { return HasCmpxchg16b; }
372 bool useLeaForSP() const { return UseLeaForSP; }
373 bool hasSlowDivide32() const { return HasSlowDivide32; }
374 bool hasSlowDivide64() const { return HasSlowDivide64; }
375 bool padShortFunctions() const { return PadShortFunctions; }
376 bool callRegIndirect() const { return CallRegIndirect; }
377 bool LEAusesAG() const { return LEAUsesAG; }
378 bool slowLEA() const { return SlowLEA; }
379 bool slowIncDec() const { return SlowIncDec; }
380 bool useSqrtEst() const { return UseSqrtEst; }
381 bool useReciprocalEst() const { return UseReciprocalEst; }
382 bool hasCDI() const { return HasCDI; }
383 bool hasPFI() const { return HasPFI; }
384 bool hasERI() const { return HasERI; }
385 bool hasDQI() const { return HasDQI; }
386 bool hasBWI() const { return HasBWI; }
387 bool hasVLX() const { return HasVLX; }
389 bool isAtom() const { return X86ProcFamily == IntelAtom; }
390 bool isSLM() const { return X86ProcFamily == IntelSLM; }
391 bool useSoftFloat() const { return UseSoftFloat; }
393 const Triple &getTargetTriple() const { return TargetTriple; }
395 bool isTargetDarwin() const { return TargetTriple.isOSDarwin(); }
396 bool isTargetFreeBSD() const { return TargetTriple.isOSFreeBSD(); }
397 bool isTargetDragonFly() const { return TargetTriple.isOSDragonFly(); }
398 bool isTargetSolaris() const { return TargetTriple.isOSSolaris(); }
399 bool isTargetPS4() const { return TargetTriple.isPS4(); }
401 bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
402 bool isTargetCOFF() const { return TargetTriple.isOSBinFormatCOFF(); }
403 bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); }
405 bool isTargetLinux() const { return TargetTriple.isOSLinux(); }
406 bool isTargetNaCl() const { return TargetTriple.isOSNaCl(); }
407 bool isTargetNaCl32() const { return isTargetNaCl() && !is64Bit(); }
408 bool isTargetNaCl64() const { return isTargetNaCl() && is64Bit(); }
410 bool isTargetWindowsMSVC() const {
411 return TargetTriple.isWindowsMSVCEnvironment();
414 bool isTargetKnownWindowsMSVC() const {
415 return TargetTriple.isKnownWindowsMSVCEnvironment();
418 bool isTargetWindowsCygwin() const {
419 return TargetTriple.isWindowsCygwinEnvironment();
422 bool isTargetWindowsGNU() const {
423 return TargetTriple.isWindowsGNUEnvironment();
426 bool isTargetWindowsItanium() const {
427 return TargetTriple.isWindowsItaniumEnvironment();
430 bool isTargetCygMing() const { return TargetTriple.isOSCygMing(); }
432 bool isOSWindows() const { return TargetTriple.isOSWindows(); }
434 bool isTargetWin64() const {
435 return In64BitMode && TargetTriple.isOSWindows();
438 bool isTargetWin32() const {
439 return !In64BitMode && (isTargetCygMing() || isTargetKnownWindowsMSVC());
442 bool isPICStyleSet() const { return PICStyle != PICStyles::None; }
443 bool isPICStyleGOT() const { return PICStyle == PICStyles::GOT; }
444 bool isPICStyleRIPRel() const { return PICStyle == PICStyles::RIPRel; }
446 bool isPICStyleStubPIC() const {
447 return PICStyle == PICStyles::StubPIC;
450 bool isPICStyleStubNoDynamic() const {
451 return PICStyle == PICStyles::StubDynamicNoPIC;
453 bool isPICStyleStubAny() const {
454 return PICStyle == PICStyles::StubDynamicNoPIC ||
455 PICStyle == PICStyles::StubPIC;
458 bool isCallingConvWin64(CallingConv::ID CC) const {
459 return (isTargetWin64() && CC != CallingConv::X86_64_SysV) ||
460 CC == CallingConv::X86_64_Win64;
463 /// ClassifyGlobalReference - Classify a global variable reference for the
464 /// current subtarget according to how we should reference it in a non-pcrel
466 unsigned char ClassifyGlobalReference(const GlobalValue *GV,
467 const TargetMachine &TM)const;
469 /// Classify a blockaddress reference for the current subtarget according to
470 /// how we should reference it in a non-pcrel context.
471 unsigned char ClassifyBlockAddressReference() const;
473 /// Return true if the subtarget allows calls to immediate address.
474 bool IsLegalToCallImmediateAddr(const TargetMachine &TM) const;
476 /// This function returns the name of a function which has an interface
477 /// like the non-standard bzero function, if such a function exists on
478 /// the current subtarget and it is considered prefereable over
479 /// memset with zero passed as the second argument. Otherwise it
481 const char *getBZeroEntry() const;
483 /// This function returns true if the target has sincos() routine in its
484 /// compiler runtime or math libraries.
485 bool hasSinCos() const;
487 /// Enable the MachineScheduler pass for all X86 subtargets.
488 bool enableMachineScheduler() const override { return true; }
490 bool enableEarlyIfConversion() const override;
492 /// Return the instruction itineraries based on the subtarget selection.
493 const InstrItineraryData *getInstrItineraryData() const override {
497 AntiDepBreakMode getAntiDepBreakMode() const override {
498 return TargetSubtargetInfo::ANTIDEP_CRITICAL;
502 } // End llvm namespace