xref: /freebsd/contrib/llvm-project/llvm/lib/Target/X86/X86Subtarget.h (revision d5e3895ea4fe4ef9db8823774e07b4368180a23e)
1 //===-- X86Subtarget.h - Define Subtarget for the X86 ----------*- C++ -*--===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares the X86 specific subclass of TargetSubtargetInfo.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_TARGET_X86_X86SUBTARGET_H
14 #define LLVM_LIB_TARGET_X86_X86SUBTARGET_H
15 
16 #include "X86FrameLowering.h"
17 #include "X86ISelLowering.h"
18 #include "X86InstrInfo.h"
19 #include "X86SelectionDAGInfo.h"
20 #include "llvm/ADT/Triple.h"
21 #include "llvm/CodeGen/TargetSubtargetInfo.h"
22 #include "llvm/IR/CallingConv.h"
23 #include <climits>
24 #include <memory>
25 
26 #define GET_SUBTARGETINFO_HEADER
27 #include "X86GenSubtargetInfo.inc"
28 
29 namespace llvm {
30 
31 class CallLowering;
32 class GlobalValue;
33 class InstructionSelector;
34 class LegalizerInfo;
35 class RegisterBankInfo;
36 class StringRef;
37 class TargetMachine;
38 
39 /// The X86 backend supports a number of different styles of PIC.
40 ///
41 namespace PICStyles {
42 
43 enum class Style {
44   StubPIC,          // Used on i386-darwin in pic mode.
45   GOT,              // Used on 32 bit elf on when in pic mode.
46   RIPRel,           // Used on X86-64 when in pic mode.
47   None              // Set when not in pic mode.
48 };
49 
50 } // end namespace PICStyles
51 
52 class X86Subtarget final : public X86GenSubtargetInfo {
53 public:
54   // NOTE: Do not add anything new to this list. Coarse, CPU name based flags
55   // are not a good idea. We should be migrating away from these.
56   enum X86ProcFamilyEnum {
57     Others,
58     IntelAtom,
59     IntelSLM
60   };
61 
62 protected:
63   enum X86SSEEnum {
64     NoSSE, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42, AVX, AVX2, AVX512F
65   };
66 
67   enum X863DNowEnum {
68     NoThreeDNow, MMX, ThreeDNow, ThreeDNowA
69   };
70 
71   /// X86 processor family: Intel Atom, and others
72   X86ProcFamilyEnum X86ProcFamily = Others;
73 
74   /// Which PIC style to use
75   PICStyles::Style PICStyle;
76 
77   const TargetMachine &TM;
78 
79   /// SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42, or none supported.
80   X86SSEEnum X86SSELevel = NoSSE;
81 
82   /// MMX, 3DNow, 3DNow Athlon, or none supported.
83   X863DNowEnum X863DNowLevel = NoThreeDNow;
84 
85   /// True if the processor supports X87 instructions.
86   bool HasX87 = false;
87 
88   /// True if the processor supports CMPXCHG8B.
89   bool HasCmpxchg8b = false;
90 
91   /// True if this processor has NOPL instruction
92   /// (generally pentium pro+).
93   bool HasNOPL = false;
94 
95   /// True if this processor has conditional move instructions
96   /// (generally pentium pro+).
97   bool HasCMov = false;
98 
99   /// True if the processor supports X86-64 instructions.
100   bool HasX86_64 = false;
101 
102   /// True if the processor supports POPCNT.
103   bool HasPOPCNT = false;
104 
105   /// True if the processor supports SSE4A instructions.
106   bool HasSSE4A = false;
107 
108   /// Target has AES instructions
109   bool HasAES = false;
110   bool HasVAES = false;
111 
112   /// Target has FXSAVE/FXRESTOR instructions
113   bool HasFXSR = false;
114 
115   /// Target has XSAVE instructions
116   bool HasXSAVE = false;
117 
118   /// Target has XSAVEOPT instructions
119   bool HasXSAVEOPT = false;
120 
121   /// Target has XSAVEC instructions
122   bool HasXSAVEC = false;
123 
124   /// Target has XSAVES instructions
125   bool HasXSAVES = false;
126 
127   /// Target has carry-less multiplication
128   bool HasPCLMUL = false;
129   bool HasVPCLMULQDQ = false;
130 
131   /// Target has Galois Field Arithmetic instructions
132   bool HasGFNI = false;
133 
134   /// Target has 3-operand fused multiply-add
135   bool HasFMA = false;
136 
137   /// Target has 4-operand fused multiply-add
138   bool HasFMA4 = false;
139 
140   /// Target has XOP instructions
141   bool HasXOP = false;
142 
143   /// Target has TBM instructions.
144   bool HasTBM = false;
145 
146   /// Target has LWP instructions
147   bool HasLWP = false;
148 
149   /// True if the processor has the MOVBE instruction.
150   bool HasMOVBE = false;
151 
152   /// True if the processor has the RDRAND instruction.
153   bool HasRDRAND = false;
154 
155   /// Processor has 16-bit floating point conversion instructions.
156   bool HasF16C = false;
157 
158   /// Processor has FS/GS base insturctions.
159   bool HasFSGSBase = false;
160 
161   /// Processor has LZCNT instruction.
162   bool HasLZCNT = false;
163 
164   /// Processor has BMI1 instructions.
165   bool HasBMI = false;
166 
167   /// Processor has BMI2 instructions.
168   bool HasBMI2 = false;
169 
170   /// Processor has VBMI instructions.
171   bool HasVBMI = false;
172 
173   /// Processor has VBMI2 instructions.
174   bool HasVBMI2 = false;
175 
176   /// Processor has Integer Fused Multiply Add
177   bool HasIFMA = false;
178 
179   /// Processor has RTM instructions.
180   bool HasRTM = false;
181 
182   /// Processor has ADX instructions.
183   bool HasADX = false;
184 
185   /// Processor has SHA instructions.
186   bool HasSHA = false;
187 
188   /// Processor has PRFCHW instructions.
189   bool HasPRFCHW = false;
190 
191   /// Processor has RDSEED instructions.
192   bool HasRDSEED = false;
193 
194   /// Processor has LAHF/SAHF instructions.
195   bool HasLAHFSAHF = false;
196 
197   /// Processor has MONITORX/MWAITX instructions.
198   bool HasMWAITX = false;
199 
200   /// Processor has Cache Line Zero instruction
201   bool HasCLZERO = false;
202 
203   /// Processor has Cache Line Demote instruction
204   bool HasCLDEMOTE = false;
205 
206   /// Processor has MOVDIRI instruction (direct store integer).
207   bool HasMOVDIRI = false;
208 
209   /// Processor has MOVDIR64B instruction (direct store 64 bytes).
210   bool HasMOVDIR64B = false;
211 
212   /// Processor has ptwrite instruction.
213   bool HasPTWRITE = false;
214 
215   /// Processor has Prefetch with intent to Write instruction
216   bool HasPREFETCHWT1 = false;
217 
218   /// True if SHLD instructions are slow.
219   bool IsSHLDSlow = false;
220 
221   /// True if the PMULLD instruction is slow compared to PMULLW/PMULHW and
222   //  PMULUDQ.
223   bool IsPMULLDSlow = false;
224 
225   /// True if the PMADDWD instruction is slow compared to PMULLD.
226   bool IsPMADDWDSlow = false;
227 
228   /// True if unaligned memory accesses of 16-bytes are slow.
229   bool IsUAMem16Slow = false;
230 
231   /// True if unaligned memory accesses of 32-bytes are slow.
232   bool IsUAMem32Slow = false;
233 
234   /// True if SSE operations can have unaligned memory operands.
235   /// This may require setting a configuration bit in the processor.
236   bool HasSSEUnalignedMem = false;
237 
238   /// True if this processor has the CMPXCHG16B instruction;
239   /// this is true for most x86-64 chips, but not the first AMD chips.
240   bool HasCmpxchg16b = false;
241 
242   /// True if the LEA instruction should be used for adjusting
243   /// the stack pointer. This is an optimization for Intel Atom processors.
244   bool UseLeaForSP = false;
245 
246   /// True if POPCNT instruction has a false dependency on the destination register.
247   bool HasPOPCNTFalseDeps = false;
248 
249   /// True if LZCNT/TZCNT instructions have a false dependency on the destination register.
250   bool HasLZCNTFalseDeps = false;
251 
252   /// True if its preferable to combine to a single shuffle using a variable
253   /// mask over multiple fixed shuffles.
254   bool HasFastVariableShuffle = false;
255 
256   /// True if vzeroupper instructions should be inserted after code that uses
257   /// ymm or zmm registers.
258   bool InsertVZEROUPPER = false;
259 
260   /// True if there is no performance penalty for writing NOPs with up to
261   /// 7 bytes.
262   bool HasFast7ByteNOP = false;
263 
264   /// True if there is no performance penalty for writing NOPs with up to
265   /// 11 bytes.
266   bool HasFast11ByteNOP = false;
267 
268   /// True if there is no performance penalty for writing NOPs with up to
269   /// 15 bytes.
270   bool HasFast15ByteNOP = false;
271 
272   /// True if gather is reasonably fast. This is true for Skylake client and
273   /// all AVX-512 CPUs.
274   bool HasFastGather = false;
275 
276   /// True if hardware SQRTSS instruction is at least as fast (latency) as
277   /// RSQRTSS followed by a Newton-Raphson iteration.
278   bool HasFastScalarFSQRT = false;
279 
280   /// True if hardware SQRTPS/VSQRTPS instructions are at least as fast
281   /// (throughput) as RSQRTPS/VRSQRTPS followed by a Newton-Raphson iteration.
282   bool HasFastVectorFSQRT = false;
283 
284   /// True if 8-bit divisions are significantly faster than
285   /// 32-bit divisions and should be used when possible.
286   bool HasSlowDivide32 = false;
287 
288   /// True if 32-bit divides are significantly faster than
289   /// 64-bit divisions and should be used when possible.
290   bool HasSlowDivide64 = false;
291 
292   /// True if LZCNT instruction is fast.
293   bool HasFastLZCNT = false;
294 
295   /// True if SHLD based rotate is fast.
296   bool HasFastSHLDRotate = false;
297 
298   /// True if the processor supports macrofusion.
299   bool HasMacroFusion = false;
300 
301   /// True if the processor supports branch fusion.
302   bool HasBranchFusion = false;
303 
304   /// True if the processor has enhanced REP MOVSB/STOSB.
305   bool HasERMSB = false;
306 
307   /// True if the short functions should be padded to prevent
308   /// a stall when returning too early.
309   bool PadShortFunctions = false;
310 
311   /// True if two memory operand instructions should use a temporary register
312   /// instead.
313   bool SlowTwoMemOps = false;
314 
315   /// True if the LEA instruction inputs have to be ready at address generation
316   /// (AG) time.
317   bool LEAUsesAG = false;
318 
319   /// True if the LEA instruction with certain arguments is slow
320   bool SlowLEA = false;
321 
322   /// True if the LEA instruction has all three source operands: base, index,
323   /// and offset or if the LEA instruction uses base and index registers where
324   /// the base is EBP, RBP,or R13
325   bool Slow3OpsLEA = false;
326 
327   /// True if INC and DEC instructions are slow when writing to flags
328   bool SlowIncDec = false;
329 
330   /// Processor has AVX-512 PreFetch Instructions
331   bool HasPFI = false;
332 
333   /// Processor has AVX-512 Exponential and Reciprocal Instructions
334   bool HasERI = false;
335 
336   /// Processor has AVX-512 Conflict Detection Instructions
337   bool HasCDI = false;
338 
339   /// Processor has AVX-512 population count Instructions
340   bool HasVPOPCNTDQ = false;
341 
342   /// Processor has AVX-512 Doubleword and Quadword instructions
343   bool HasDQI = false;
344 
345   /// Processor has AVX-512 Byte and Word instructions
346   bool HasBWI = false;
347 
348   /// Processor has AVX-512 Vector Length eXtenstions
349   bool HasVLX = false;
350 
351   /// Processor has PKU extenstions
352   bool HasPKU = false;
353 
354   /// Processor has AVX-512 Vector Neural Network Instructions
355   bool HasVNNI = false;
356 
357   /// Processor has AVX-512 bfloat16 floating-point extensions
358   bool HasBF16 = false;
359 
360   /// Processor supports ENQCMD instructions
361   bool HasENQCMD = false;
362 
363   /// Processor has AVX-512 Bit Algorithms instructions
364   bool HasBITALG = false;
365 
366   /// Processor has AVX-512 vp2intersect instructions
367   bool HasVP2INTERSECT = false;
368 
369   /// Deprecated flag for MPX instructions.
370   bool DeprecatedHasMPX = false;
371 
372   /// Processor supports CET SHSTK - Control-Flow Enforcement Technology
373   /// using Shadow Stack
374   bool HasSHSTK = false;
375 
376   /// Processor supports Invalidate Process-Context Identifier
377   bool HasINVPCID = false;
378 
379   /// Processor has Software Guard Extensions
380   bool HasSGX = false;
381 
382   /// Processor supports Flush Cache Line instruction
383   bool HasCLFLUSHOPT = false;
384 
385   /// Processor supports Cache Line Write Back instruction
386   bool HasCLWB = false;
387 
388   /// Processor supports Write Back No Invalidate instruction
389   bool HasWBNOINVD = false;
390 
391   /// Processor support RDPID instruction
392   bool HasRDPID = false;
393 
394   /// Processor supports WaitPKG instructions
395   bool HasWAITPKG = false;
396 
397   /// Processor supports PCONFIG instruction
398   bool HasPCONFIG = false;
399 
400   /// Processor supports SERIALIZE instruction
401   bool HasSERIALIZE = false;
402 
403   /// Processor supports TSXLDTRK instruction
404   bool HasTSXLDTRK = false;
405 
406   /// Processor has AMX support
407   bool HasAMXTILE = false;
408   bool HasAMXBF16 = false;
409   bool HasAMXINT8 = false;
410 
411   /// Processor has a single uop BEXTR implementation.
412   bool HasFastBEXTR = false;
413 
414   /// Try harder to combine to horizontal vector ops if they are fast.
415   bool HasFastHorizontalOps = false;
416 
417   /// Prefer a left/right scalar logical shifts pair over a shift+and pair.
418   bool HasFastScalarShiftMasks = false;
419 
420   /// Prefer a left/right vector logical shifts pair over a shift+and pair.
421   bool HasFastVectorShiftMasks = false;
422 
423   /// Use a retpoline thunk rather than indirect calls to block speculative
424   /// execution.
425   bool UseRetpolineIndirectCalls = false;
426 
427   /// Use a retpoline thunk or remove any indirect branch to block speculative
428   /// execution.
429   bool UseRetpolineIndirectBranches = false;
430 
431   /// Deprecated flag, query `UseRetpolineIndirectCalls` and
432   /// `UseRetpolineIndirectBranches` instead.
433   bool DeprecatedUseRetpoline = false;
434 
435   /// When using a retpoline thunk, call an externally provided thunk rather
436   /// than emitting one inside the compiler.
437   bool UseRetpolineExternalThunk = false;
438 
439   /// Prevent generation of indirect call/branch instructions from memory,
440   /// and force all indirect call/branch instructions from a register to be
441   /// preceded by an LFENCE. Also decompose RET instructions into a
442   /// POP+LFENCE+JMP sequence.
443   bool UseLVIControlFlowIntegrity = false;
444 
445   /// Enable Speculative Execution Side Effect Suppression
446   bool UseSpeculativeExecutionSideEffectSuppression = false;
447 
448   /// Insert LFENCE instructions to prevent data speculatively injected into
449   /// loads from being used maliciously.
450   bool UseLVILoadHardening = false;
451 
452   /// Use software floating point for code generation.
453   bool UseSoftFloat = false;
454 
455   /// Use alias analysis during code generation.
456   bool UseAA = false;
457 
458   /// The minimum alignment known to hold of the stack frame on
459   /// entry to the function and which must be maintained by every function.
460   Align stackAlignment = Align(4);
461 
462   /// Max. memset / memcpy size that is turned into rep/movs, rep/stos ops.
463   ///
464   // FIXME: this is a known good value for Yonah. How about others?
465   unsigned MaxInlineSizeThreshold = 128;
466 
467   /// Indicates target prefers 128 bit instructions.
468   bool Prefer128Bit = false;
469 
470   /// Indicates target prefers 256 bit instructions.
471   bool Prefer256Bit = false;
472 
473   /// Indicates target prefers AVX512 mask registers.
474   bool PreferMaskRegisters = false;
475 
476   /// Threeway branch is profitable in this subtarget.
477   bool ThreewayBranchProfitable = false;
478 
479   /// Use Goldmont specific floating point div/sqrt costs.
480   bool UseGLMDivSqrtCosts = false;
481 
482   /// What processor and OS we're targeting.
483   Triple TargetTriple;
484 
485   /// GlobalISel related APIs.
486   std::unique_ptr<CallLowering> CallLoweringInfo;
487   std::unique_ptr<LegalizerInfo> Legalizer;
488   std::unique_ptr<RegisterBankInfo> RegBankInfo;
489   std::unique_ptr<InstructionSelector> InstSelector;
490 
491 private:
492   /// Override the stack alignment.
493   MaybeAlign StackAlignOverride;
494 
495   /// Preferred vector width from function attribute.
496   unsigned PreferVectorWidthOverride;
497 
498   /// Resolved preferred vector width from function attribute and subtarget
499   /// features.
500   unsigned PreferVectorWidth = UINT32_MAX;
501 
502   /// Required vector width from function attribute.
503   unsigned RequiredVectorWidth;
504 
505   /// True if compiling for 64-bit, false for 16-bit or 32-bit.
506   bool In64BitMode;
507 
508   /// True if compiling for 32-bit, false for 16-bit or 64-bit.
509   bool In32BitMode;
510 
511   /// True if compiling for 16-bit, false for 32-bit or 64-bit.
512   bool In16BitMode;
513 
514   /// Contains the Overhead of gather\scatter instructions
515   int GatherOverhead = 1024;
516   int ScatterOverhead = 1024;
517 
518   X86SelectionDAGInfo TSInfo;
519   // Ordering here is important. X86InstrInfo initializes X86RegisterInfo which
520   // X86TargetLowering needs.
521   X86InstrInfo InstrInfo;
522   X86TargetLowering TLInfo;
523   X86FrameLowering FrameLowering;
524 
525 public:
526   /// This constructor initializes the data members to match that
527   /// of the specified triple.
528   ///
529   X86Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
530                const X86TargetMachine &TM, MaybeAlign StackAlignOverride,
531                unsigned PreferVectorWidthOverride,
532                unsigned RequiredVectorWidth);
533 
534   const X86TargetLowering *getTargetLowering() const override {
535     return &TLInfo;
536   }
537 
538   const X86InstrInfo *getInstrInfo() const override { return &InstrInfo; }
539 
540   const X86FrameLowering *getFrameLowering() const override {
541     return &FrameLowering;
542   }
543 
544   const X86SelectionDAGInfo *getSelectionDAGInfo() const override {
545     return &TSInfo;
546   }
547 
548   const X86RegisterInfo *getRegisterInfo() const override {
549     return &getInstrInfo()->getRegisterInfo();
550   }
551 
552   /// Returns the minimum alignment known to hold of the
553   /// stack frame on entry to the function and which must be maintained by every
554   /// function for this subtarget.
555   Align getStackAlignment() const { return stackAlignment; }
556 
557   /// Returns the maximum memset / memcpy size
558   /// that still makes it profitable to inline the call.
559   unsigned getMaxInlineSizeThreshold() const { return MaxInlineSizeThreshold; }
560 
561   /// ParseSubtargetFeatures - Parses features string setting specified
562   /// subtarget options.  Definition of function is auto generated by tblgen.
563   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
564 
565   /// Methods used by Global ISel
566   const CallLowering *getCallLowering() const override;
567   InstructionSelector *getInstructionSelector() const override;
568   const LegalizerInfo *getLegalizerInfo() const override;
569   const RegisterBankInfo *getRegBankInfo() const override;
570 
571 private:
572   /// Initialize the full set of dependencies so we can use an initializer
573   /// list for X86Subtarget.
574   X86Subtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
575   void initSubtargetFeatures(StringRef CPU, StringRef FS);
576 
577 public:
578   /// Is this x86_64? (disregarding specific ABI / programming model)
579   bool is64Bit() const {
580     return In64BitMode;
581   }
582 
583   bool is32Bit() const {
584     return In32BitMode;
585   }
586 
587   bool is16Bit() const {
588     return In16BitMode;
589   }
590 
591   /// Is this x86_64 with the ILP32 programming model (x32 ABI)?
592   bool isTarget64BitILP32() const {
593     return In64BitMode && (TargetTriple.getEnvironment() == Triple::GNUX32 ||
594                            TargetTriple.isOSNaCl());
595   }
596 
597   /// Is this x86_64 with the LP64 programming model (standard AMD64, no x32)?
598   bool isTarget64BitLP64() const {
599     return In64BitMode && (TargetTriple.getEnvironment() != Triple::GNUX32 &&
600                            !TargetTriple.isOSNaCl());
601   }
602 
603   PICStyles::Style getPICStyle() const { return PICStyle; }
604   void setPICStyle(PICStyles::Style Style)  { PICStyle = Style; }
605 
606   bool hasX87() const { return HasX87; }
607   bool hasCmpxchg8b() const { return HasCmpxchg8b; }
608   bool hasNOPL() const { return HasNOPL; }
609   // SSE codegen depends on cmovs, and all SSE1+ processors support them.
610   // All 64-bit processors support cmov.
611   bool hasCMov() const { return HasCMov || X86SSELevel >= SSE1 || is64Bit(); }
612   bool hasSSE1() const { return X86SSELevel >= SSE1; }
613   bool hasSSE2() const { return X86SSELevel >= SSE2; }
614   bool hasSSE3() const { return X86SSELevel >= SSE3; }
615   bool hasSSSE3() const { return X86SSELevel >= SSSE3; }
616   bool hasSSE41() const { return X86SSELevel >= SSE41; }
617   bool hasSSE42() const { return X86SSELevel >= SSE42; }
618   bool hasAVX() const { return X86SSELevel >= AVX; }
619   bool hasAVX2() const { return X86SSELevel >= AVX2; }
620   bool hasAVX512() const { return X86SSELevel >= AVX512F; }
621   bool hasInt256() const { return hasAVX2(); }
622   bool hasSSE4A() const { return HasSSE4A; }
623   bool hasMMX() const { return X863DNowLevel >= MMX; }
624   bool has3DNow() const { return X863DNowLevel >= ThreeDNow; }
625   bool has3DNowA() const { return X863DNowLevel >= ThreeDNowA; }
626   bool hasPOPCNT() const { return HasPOPCNT; }
627   bool hasAES() const { return HasAES; }
628   bool hasVAES() const { return HasVAES; }
629   bool hasFXSR() const { return HasFXSR; }
630   bool hasXSAVE() const { return HasXSAVE; }
631   bool hasXSAVEOPT() const { return HasXSAVEOPT; }
632   bool hasXSAVEC() const { return HasXSAVEC; }
633   bool hasXSAVES() const { return HasXSAVES; }
634   bool hasPCLMUL() const { return HasPCLMUL; }
635   bool hasVPCLMULQDQ() const { return HasVPCLMULQDQ; }
636   bool hasGFNI() const { return HasGFNI; }
637   // Prefer FMA4 to FMA - its better for commutation/memory folding and
638   // has equal or better performance on all supported targets.
639   bool hasFMA() const { return HasFMA; }
640   bool hasFMA4() const { return HasFMA4; }
641   bool hasAnyFMA() const { return hasFMA() || hasFMA4(); }
642   bool hasXOP() const { return HasXOP; }
643   bool hasTBM() const { return HasTBM; }
644   bool hasLWP() const { return HasLWP; }
645   bool hasMOVBE() const { return HasMOVBE; }
646   bool hasRDRAND() const { return HasRDRAND; }
647   bool hasF16C() const { return HasF16C; }
648   bool hasFSGSBase() const { return HasFSGSBase; }
649   bool hasLZCNT() const { return HasLZCNT; }
650   bool hasBMI() const { return HasBMI; }
651   bool hasBMI2() const { return HasBMI2; }
652   bool hasVBMI() const { return HasVBMI; }
653   bool hasVBMI2() const { return HasVBMI2; }
654   bool hasIFMA() const { return HasIFMA; }
655   bool hasRTM() const { return HasRTM; }
656   bool hasADX() const { return HasADX; }
657   bool hasSHA() const { return HasSHA; }
658   bool hasPRFCHW() const { return HasPRFCHW; }
659   bool hasPREFETCHWT1() const { return HasPREFETCHWT1; }
660   bool hasPrefetchW() const {
661     // The PREFETCHW instruction was added with 3DNow but later CPUs gave it
662     // its own CPUID bit as part of deprecating 3DNow. Intel eventually added
663     // it and KNL has another that prefetches to L2 cache. We assume the
664     // L1 version exists if the L2 version does.
665     return has3DNow() || hasPRFCHW() || hasPREFETCHWT1();
666   }
667   bool hasSSEPrefetch() const {
668     // We implicitly enable these when we have a write prefix supporting cache
669     // level OR if we have prfchw, but don't already have a read prefetch from
670     // 3dnow.
671     return hasSSE1() || (hasPRFCHW() && !has3DNow()) || hasPREFETCHWT1();
672   }
673   bool hasRDSEED() const { return HasRDSEED; }
674   bool hasLAHFSAHF() const { return HasLAHFSAHF; }
675   bool hasMWAITX() const { return HasMWAITX; }
676   bool hasCLZERO() const { return HasCLZERO; }
677   bool hasCLDEMOTE() const { return HasCLDEMOTE; }
678   bool hasMOVDIRI() const { return HasMOVDIRI; }
679   bool hasMOVDIR64B() const { return HasMOVDIR64B; }
680   bool hasPTWRITE() const { return HasPTWRITE; }
681   bool isSHLDSlow() const { return IsSHLDSlow; }
682   bool isPMULLDSlow() const { return IsPMULLDSlow; }
683   bool isPMADDWDSlow() const { return IsPMADDWDSlow; }
684   bool isUnalignedMem16Slow() const { return IsUAMem16Slow; }
685   bool isUnalignedMem32Slow() const { return IsUAMem32Slow; }
686   int getGatherOverhead() const { return GatherOverhead; }
687   int getScatterOverhead() const { return ScatterOverhead; }
688   bool hasSSEUnalignedMem() const { return HasSSEUnalignedMem; }
689   bool hasCmpxchg16b() const { return HasCmpxchg16b && is64Bit(); }
690   bool useLeaForSP() const { return UseLeaForSP; }
691   bool hasPOPCNTFalseDeps() const { return HasPOPCNTFalseDeps; }
692   bool hasLZCNTFalseDeps() const { return HasLZCNTFalseDeps; }
693   bool hasFastVariableShuffle() const {
694     return HasFastVariableShuffle;
695   }
696   bool insertVZEROUPPER() const { return InsertVZEROUPPER; }
697   bool hasFastGather() const { return HasFastGather; }
698   bool hasFastScalarFSQRT() const { return HasFastScalarFSQRT; }
699   bool hasFastVectorFSQRT() const { return HasFastVectorFSQRT; }
700   bool hasFastLZCNT() const { return HasFastLZCNT; }
701   bool hasFastSHLDRotate() const { return HasFastSHLDRotate; }
702   bool hasFastBEXTR() const { return HasFastBEXTR; }
703   bool hasFastHorizontalOps() const { return HasFastHorizontalOps; }
704   bool hasFastScalarShiftMasks() const { return HasFastScalarShiftMasks; }
705   bool hasFastVectorShiftMasks() const { return HasFastVectorShiftMasks; }
706   bool hasMacroFusion() const { return HasMacroFusion; }
707   bool hasBranchFusion() const { return HasBranchFusion; }
708   bool hasERMSB() const { return HasERMSB; }
709   bool hasSlowDivide32() const { return HasSlowDivide32; }
710   bool hasSlowDivide64() const { return HasSlowDivide64; }
711   bool padShortFunctions() const { return PadShortFunctions; }
712   bool slowTwoMemOps() const { return SlowTwoMemOps; }
713   bool LEAusesAG() const { return LEAUsesAG; }
714   bool slowLEA() const { return SlowLEA; }
715   bool slow3OpsLEA() const { return Slow3OpsLEA; }
716   bool slowIncDec() const { return SlowIncDec; }
717   bool hasCDI() const { return HasCDI; }
718   bool hasVPOPCNTDQ() const { return HasVPOPCNTDQ; }
719   bool hasPFI() const { return HasPFI; }
720   bool hasERI() const { return HasERI; }
721   bool hasDQI() const { return HasDQI; }
722   bool hasBWI() const { return HasBWI; }
723   bool hasVLX() const { return HasVLX; }
724   bool hasPKU() const { return HasPKU; }
725   bool hasVNNI() const { return HasVNNI; }
726   bool hasBF16() const { return HasBF16; }
727   bool hasVP2INTERSECT() const { return HasVP2INTERSECT; }
728   bool hasBITALG() const { return HasBITALG; }
729   bool hasSHSTK() const { return HasSHSTK; }
730   bool hasCLFLUSHOPT() const { return HasCLFLUSHOPT; }
731   bool hasCLWB() const { return HasCLWB; }
732   bool hasWBNOINVD() const { return HasWBNOINVD; }
733   bool hasRDPID() const { return HasRDPID; }
734   bool hasWAITPKG() const { return HasWAITPKG; }
735   bool hasPCONFIG() const { return HasPCONFIG; }
736   bool hasSGX() const { return HasSGX; }
737   bool threewayBranchProfitable() const { return ThreewayBranchProfitable; }
738   bool hasINVPCID() const { return HasINVPCID; }
739   bool hasENQCMD() const { return HasENQCMD; }
740   bool hasSERIALIZE() const { return HasSERIALIZE; }
741   bool hasTSXLDTRK() const { return HasTSXLDTRK; }
742   bool useRetpolineIndirectCalls() const { return UseRetpolineIndirectCalls; }
743   bool useRetpolineIndirectBranches() const {
744     return UseRetpolineIndirectBranches;
745   }
746   bool hasAMXTILE() const { return HasAMXTILE; }
747   bool hasAMXBF16() const { return HasAMXBF16; }
748   bool hasAMXINT8() const { return HasAMXINT8; }
749   bool useRetpolineExternalThunk() const { return UseRetpolineExternalThunk; }
750 
751   // These are generic getters that OR together all of the thunk types
752   // supported by the subtarget. Therefore useIndirectThunk*() will return true
753   // if any respective thunk feature is enabled.
754   bool useIndirectThunkCalls() const {
755     return useRetpolineIndirectCalls() || useLVIControlFlowIntegrity();
756   }
757   bool useIndirectThunkBranches() const {
758     return useRetpolineIndirectBranches() || useLVIControlFlowIntegrity();
759   }
760 
761   bool preferMaskRegisters() const { return PreferMaskRegisters; }
762   bool useGLMDivSqrtCosts() const { return UseGLMDivSqrtCosts; }
763   bool useLVIControlFlowIntegrity() const { return UseLVIControlFlowIntegrity; }
764   bool useLVILoadHardening() const { return UseLVILoadHardening; }
765   bool useSpeculativeExecutionSideEffectSuppression() const {
766     return UseSpeculativeExecutionSideEffectSuppression;
767   }
768 
769   unsigned getPreferVectorWidth() const { return PreferVectorWidth; }
770   unsigned getRequiredVectorWidth() const { return RequiredVectorWidth; }
771 
772   // Helper functions to determine when we should allow widening to 512-bit
773   // during codegen.
774   // TODO: Currently we're always allowing widening on CPUs without VLX,
775   // because for many cases we don't have a better option.
776   bool canExtendTo512DQ() const {
777     return hasAVX512() && (!hasVLX() || getPreferVectorWidth() >= 512);
778   }
779   bool canExtendTo512BW() const  {
780     return hasBWI() && canExtendTo512DQ();
781   }
782 
783   // If there are no 512-bit vectors and we prefer not to use 512-bit registers,
784   // disable them in the legalizer.
785   bool useAVX512Regs() const {
786     return hasAVX512() && (canExtendTo512DQ() || RequiredVectorWidth > 256);
787   }
788 
789   bool useBWIRegs() const {
790     return hasBWI() && useAVX512Regs();
791   }
792 
793   bool isXRaySupported() const override { return is64Bit(); }
794 
795   X86ProcFamilyEnum getProcFamily() const { return X86ProcFamily; }
796 
797   /// TODO: to be removed later and replaced with suitable properties
798   bool isAtom() const { return X86ProcFamily == IntelAtom; }
799   bool isSLM() const { return X86ProcFamily == IntelSLM; }
800   bool useSoftFloat() const { return UseSoftFloat; }
801   bool useAA() const override { return UseAA; }
802 
803   /// Use mfence if we have SSE2 or we're on x86-64 (even if we asked for
804   /// no-sse2). There isn't any reason to disable it if the target processor
805   /// supports it.
806   bool hasMFence() const { return hasSSE2() || is64Bit(); }
807 
808   const Triple &getTargetTriple() const { return TargetTriple; }
809 
810   bool isTargetDarwin() const { return TargetTriple.isOSDarwin(); }
811   bool isTargetFreeBSD() const { return TargetTriple.isOSFreeBSD(); }
812   bool isTargetDragonFly() const { return TargetTriple.isOSDragonFly(); }
813   bool isTargetSolaris() const { return TargetTriple.isOSSolaris(); }
814   bool isTargetPS4() const { return TargetTriple.isPS4CPU(); }
815 
816   bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
817   bool isTargetCOFF() const { return TargetTriple.isOSBinFormatCOFF(); }
818   bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); }
819 
820   bool isTargetLinux() const { return TargetTriple.isOSLinux(); }
821   bool isTargetKFreeBSD() const { return TargetTriple.isOSKFreeBSD(); }
822   bool isTargetGlibc() const { return TargetTriple.isOSGlibc(); }
823   bool isTargetAndroid() const { return TargetTriple.isAndroid(); }
824   bool isTargetNaCl() const { return TargetTriple.isOSNaCl(); }
825   bool isTargetNaCl32() const { return isTargetNaCl() && !is64Bit(); }
826   bool isTargetNaCl64() const { return isTargetNaCl() && is64Bit(); }
827   bool isTargetMCU() const { return TargetTriple.isOSIAMCU(); }
828   bool isTargetFuchsia() const { return TargetTriple.isOSFuchsia(); }
829 
830   bool isTargetWindowsMSVC() const {
831     return TargetTriple.isWindowsMSVCEnvironment();
832   }
833 
834   bool isTargetWindowsCoreCLR() const {
835     return TargetTriple.isWindowsCoreCLREnvironment();
836   }
837 
838   bool isTargetWindowsCygwin() const {
839     return TargetTriple.isWindowsCygwinEnvironment();
840   }
841 
842   bool isTargetWindowsGNU() const {
843     return TargetTriple.isWindowsGNUEnvironment();
844   }
845 
846   bool isTargetWindowsItanium() const {
847     return TargetTriple.isWindowsItaniumEnvironment();
848   }
849 
850   bool isTargetCygMing() const { return TargetTriple.isOSCygMing(); }
851 
852   bool isOSWindows() const { return TargetTriple.isOSWindows(); }
853 
854   bool isTargetWin64() const { return In64BitMode && isOSWindows(); }
855 
856   bool isTargetWin32() const { return !In64BitMode && isOSWindows(); }
857 
858   bool isPICStyleGOT() const { return PICStyle == PICStyles::Style::GOT; }
859   bool isPICStyleRIPRel() const { return PICStyle == PICStyles::Style::RIPRel; }
860 
861   bool isPICStyleStubPIC() const {
862     return PICStyle == PICStyles::Style::StubPIC;
863   }
864 
865   bool isPositionIndependent() const;
866 
867   bool isCallingConvWin64(CallingConv::ID CC) const {
868     switch (CC) {
869     // On Win64, all these conventions just use the default convention.
870     case CallingConv::C:
871     case CallingConv::Fast:
872     case CallingConv::Tail:
873     case CallingConv::Swift:
874     case CallingConv::X86_FastCall:
875     case CallingConv::X86_StdCall:
876     case CallingConv::X86_ThisCall:
877     case CallingConv::X86_VectorCall:
878     case CallingConv::Intel_OCL_BI:
879       return isTargetWin64();
880     // This convention allows using the Win64 convention on other targets.
881     case CallingConv::Win64:
882       return true;
883     // This convention allows using the SysV convention on Windows targets.
884     case CallingConv::X86_64_SysV:
885       return false;
886     // Otherwise, who knows what this is.
887     default:
888       return false;
889     }
890   }
891 
892   /// Classify a global variable reference for the current subtarget according
893   /// to how we should reference it in a non-pcrel context.
894   unsigned char classifyLocalReference(const GlobalValue *GV) const;
895 
896   unsigned char classifyGlobalReference(const GlobalValue *GV,
897                                         const Module &M) const;
898   unsigned char classifyGlobalReference(const GlobalValue *GV) const;
899 
900   /// Classify a global function reference for the current subtarget.
901   unsigned char classifyGlobalFunctionReference(const GlobalValue *GV,
902                                                 const Module &M) const;
903   unsigned char classifyGlobalFunctionReference(const GlobalValue *GV) const;
904 
905   /// Classify a blockaddress reference for the current subtarget according to
906   /// how we should reference it in a non-pcrel context.
907   unsigned char classifyBlockAddressReference() const;
908 
909   /// Return true if the subtarget allows calls to immediate address.
910   bool isLegalToCallImmediateAddr() const;
911 
912   /// If we are using indirect thunks, we need to expand indirectbr to avoid it
913   /// lowering to an actual indirect jump.
914   bool enableIndirectBrExpand() const override {
915     return useIndirectThunkBranches();
916   }
917 
918   /// Enable the MachineScheduler pass for all X86 subtargets.
919   bool enableMachineScheduler() const override { return true; }
920 
921   bool enableEarlyIfConversion() const override;
922 
923   void getPostRAMutations(std::vector<std::unique_ptr<ScheduleDAGMutation>>
924                               &Mutations) const override;
925 
926   AntiDepBreakMode getAntiDepBreakMode() const override {
927     return TargetSubtargetInfo::ANTIDEP_CRITICAL;
928   }
929 
930   bool enableAdvancedRASplitCost() const override { return true; }
931 };
932 
933 } // end namespace llvm
934 
935 #endif // LLVM_LIB_TARGET_X86_X86SUBTARGET_H
936