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