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 a single uop BEXTR implementation. 407 bool HasFastBEXTR = false; 408 409 /// Try harder to combine to horizontal vector ops if they are fast. 410 bool HasFastHorizontalOps = false; 411 412 /// Prefer a left/right scalar logical shifts pair over a shift+and pair. 413 bool HasFastScalarShiftMasks = false; 414 415 /// Prefer a left/right vector logical shifts pair over a shift+and pair. 416 bool HasFastVectorShiftMasks = false; 417 418 /// Use a retpoline thunk rather than indirect calls to block speculative 419 /// execution. 420 bool UseRetpolineIndirectCalls = false; 421 422 /// Use a retpoline thunk or remove any indirect branch to block speculative 423 /// execution. 424 bool UseRetpolineIndirectBranches = false; 425 426 /// Deprecated flag, query `UseRetpolineIndirectCalls` and 427 /// `UseRetpolineIndirectBranches` instead. 428 bool DeprecatedUseRetpoline = false; 429 430 /// When using a retpoline thunk, call an externally provided thunk rather 431 /// than emitting one inside the compiler. 432 bool UseRetpolineExternalThunk = false; 433 434 /// Prevent generation of indirect call/branch instructions from memory, 435 /// and force all indirect call/branch instructions from a register to be 436 /// preceded by an LFENCE. Also decompose RET instructions into a 437 /// POP+LFENCE+JMP sequence. 438 bool UseLVIControlFlowIntegrity = false; 439 440 /// Use software floating point for code generation. 441 bool UseSoftFloat = false; 442 443 /// Use alias analysis during code generation. 444 bool UseAA = false; 445 446 /// The minimum alignment known to hold of the stack frame on 447 /// entry to the function and which must be maintained by every function. 448 Align stackAlignment = Align(4); 449 450 /// Max. memset / memcpy size that is turned into rep/movs, rep/stos ops. 451 /// 452 // FIXME: this is a known good value for Yonah. How about others? 453 unsigned MaxInlineSizeThreshold = 128; 454 455 /// Indicates target prefers 128 bit instructions. 456 bool Prefer128Bit = false; 457 458 /// Indicates target prefers 256 bit instructions. 459 bool Prefer256Bit = false; 460 461 /// Indicates target prefers AVX512 mask registers. 462 bool PreferMaskRegisters = false; 463 464 /// Threeway branch is profitable in this subtarget. 465 bool ThreewayBranchProfitable = false; 466 467 /// Use Goldmont specific floating point div/sqrt costs. 468 bool UseGLMDivSqrtCosts = false; 469 470 /// What processor and OS we're targeting. 471 Triple TargetTriple; 472 473 /// GlobalISel related APIs. 474 std::unique_ptr<CallLowering> CallLoweringInfo; 475 std::unique_ptr<LegalizerInfo> Legalizer; 476 std::unique_ptr<RegisterBankInfo> RegBankInfo; 477 std::unique_ptr<InstructionSelector> InstSelector; 478 479 private: 480 /// Override the stack alignment. 481 MaybeAlign StackAlignOverride; 482 483 /// Preferred vector width from function attribute. 484 unsigned PreferVectorWidthOverride; 485 486 /// Resolved preferred vector width from function attribute and subtarget 487 /// features. 488 unsigned PreferVectorWidth = UINT32_MAX; 489 490 /// Required vector width from function attribute. 491 unsigned RequiredVectorWidth; 492 493 /// True if compiling for 64-bit, false for 16-bit or 32-bit. 494 bool In64BitMode; 495 496 /// True if compiling for 32-bit, false for 16-bit or 64-bit. 497 bool In32BitMode; 498 499 /// True if compiling for 16-bit, false for 32-bit or 64-bit. 500 bool In16BitMode; 501 502 /// Contains the Overhead of gather\scatter instructions 503 int GatherOverhead = 1024; 504 int ScatterOverhead = 1024; 505 506 X86SelectionDAGInfo TSInfo; 507 // Ordering here is important. X86InstrInfo initializes X86RegisterInfo which 508 // X86TargetLowering needs. 509 X86InstrInfo InstrInfo; 510 X86TargetLowering TLInfo; 511 X86FrameLowering FrameLowering; 512 513 public: 514 /// This constructor initializes the data members to match that 515 /// of the specified triple. 516 /// 517 X86Subtarget(const Triple &TT, StringRef CPU, StringRef FS, 518 const X86TargetMachine &TM, MaybeAlign StackAlignOverride, 519 unsigned PreferVectorWidthOverride, 520 unsigned RequiredVectorWidth); 521 522 const X86TargetLowering *getTargetLowering() const override { 523 return &TLInfo; 524 } 525 526 const X86InstrInfo *getInstrInfo() const override { return &InstrInfo; } 527 528 const X86FrameLowering *getFrameLowering() const override { 529 return &FrameLowering; 530 } 531 532 const X86SelectionDAGInfo *getSelectionDAGInfo() const override { 533 return &TSInfo; 534 } 535 536 const X86RegisterInfo *getRegisterInfo() const override { 537 return &getInstrInfo()->getRegisterInfo(); 538 } 539 540 /// Returns the minimum alignment known to hold of the 541 /// stack frame on entry to the function and which must be maintained by every 542 /// function for this subtarget. 543 Align getStackAlignment() const { return stackAlignment; } 544 545 /// Returns the maximum memset / memcpy size 546 /// that still makes it profitable to inline the call. 547 unsigned getMaxInlineSizeThreshold() const { return MaxInlineSizeThreshold; } 548 549 /// ParseSubtargetFeatures - Parses features string setting specified 550 /// subtarget options. Definition of function is auto generated by tblgen. 551 void ParseSubtargetFeatures(StringRef CPU, StringRef FS); 552 553 /// Methods used by Global ISel 554 const CallLowering *getCallLowering() const override; 555 InstructionSelector *getInstructionSelector() const override; 556 const LegalizerInfo *getLegalizerInfo() const override; 557 const RegisterBankInfo *getRegBankInfo() const override; 558 559 private: 560 /// Initialize the full set of dependencies so we can use an initializer 561 /// list for X86Subtarget. 562 X86Subtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS); 563 void initSubtargetFeatures(StringRef CPU, StringRef FS); 564 565 public: 566 /// Is this x86_64? (disregarding specific ABI / programming model) 567 bool is64Bit() const { 568 return In64BitMode; 569 } 570 571 bool is32Bit() const { 572 return In32BitMode; 573 } 574 575 bool is16Bit() const { 576 return In16BitMode; 577 } 578 579 /// Is this x86_64 with the ILP32 programming model (x32 ABI)? 580 bool isTarget64BitILP32() const { 581 return In64BitMode && (TargetTriple.getEnvironment() == Triple::GNUX32 || 582 TargetTriple.isOSNaCl()); 583 } 584 585 /// Is this x86_64 with the LP64 programming model (standard AMD64, no x32)? 586 bool isTarget64BitLP64() const { 587 return In64BitMode && (TargetTriple.getEnvironment() != Triple::GNUX32 && 588 !TargetTriple.isOSNaCl()); 589 } 590 591 PICStyles::Style getPICStyle() const { return PICStyle; } 592 void setPICStyle(PICStyles::Style Style) { PICStyle = Style; } 593 594 bool hasX87() const { return HasX87; } 595 bool hasCmpxchg8b() const { return HasCmpxchg8b; } 596 bool hasNOPL() const { return HasNOPL; } 597 // SSE codegen depends on cmovs, and all SSE1+ processors support them. 598 // All 64-bit processors support cmov. 599 bool hasCMov() const { return HasCMov || X86SSELevel >= SSE1 || is64Bit(); } 600 bool hasSSE1() const { return X86SSELevel >= SSE1; } 601 bool hasSSE2() const { return X86SSELevel >= SSE2; } 602 bool hasSSE3() const { return X86SSELevel >= SSE3; } 603 bool hasSSSE3() const { return X86SSELevel >= SSSE3; } 604 bool hasSSE41() const { return X86SSELevel >= SSE41; } 605 bool hasSSE42() const { return X86SSELevel >= SSE42; } 606 bool hasAVX() const { return X86SSELevel >= AVX; } 607 bool hasAVX2() const { return X86SSELevel >= AVX2; } 608 bool hasAVX512() const { return X86SSELevel >= AVX512F; } 609 bool hasInt256() const { return hasAVX2(); } 610 bool hasSSE4A() const { return HasSSE4A; } 611 bool hasMMX() const { return X863DNowLevel >= MMX; } 612 bool has3DNow() const { return X863DNowLevel >= ThreeDNow; } 613 bool has3DNowA() const { return X863DNowLevel >= ThreeDNowA; } 614 bool hasPOPCNT() const { return HasPOPCNT; } 615 bool hasAES() const { return HasAES; } 616 bool hasVAES() const { return HasVAES; } 617 bool hasFXSR() const { return HasFXSR; } 618 bool hasXSAVE() const { return HasXSAVE; } 619 bool hasXSAVEOPT() const { return HasXSAVEOPT; } 620 bool hasXSAVEC() const { return HasXSAVEC; } 621 bool hasXSAVES() const { return HasXSAVES; } 622 bool hasPCLMUL() const { return HasPCLMUL; } 623 bool hasVPCLMULQDQ() const { return HasVPCLMULQDQ; } 624 bool hasGFNI() const { return HasGFNI; } 625 // Prefer FMA4 to FMA - its better for commutation/memory folding and 626 // has equal or better performance on all supported targets. 627 bool hasFMA() const { return HasFMA; } 628 bool hasFMA4() const { return HasFMA4; } 629 bool hasAnyFMA() const { return hasFMA() || hasFMA4(); } 630 bool hasXOP() const { return HasXOP; } 631 bool hasTBM() const { return HasTBM; } 632 bool hasLWP() const { return HasLWP; } 633 bool hasMOVBE() const { return HasMOVBE; } 634 bool hasRDRAND() const { return HasRDRAND; } 635 bool hasF16C() const { return HasF16C; } 636 bool hasFSGSBase() const { return HasFSGSBase; } 637 bool hasLZCNT() const { return HasLZCNT; } 638 bool hasBMI() const { return HasBMI; } 639 bool hasBMI2() const { return HasBMI2; } 640 bool hasVBMI() const { return HasVBMI; } 641 bool hasVBMI2() const { return HasVBMI2; } 642 bool hasIFMA() const { return HasIFMA; } 643 bool hasRTM() const { return HasRTM; } 644 bool hasADX() const { return HasADX; } 645 bool hasSHA() const { return HasSHA; } 646 bool hasPRFCHW() const { return HasPRFCHW || HasPREFETCHWT1; } 647 bool hasPREFETCHWT1() const { return HasPREFETCHWT1; } 648 bool hasSSEPrefetch() const { 649 // We implicitly enable these when we have a write prefix supporting cache 650 // level OR if we have prfchw, but don't already have a read prefetch from 651 // 3dnow. 652 return hasSSE1() || (hasPRFCHW() && !has3DNow()) || hasPREFETCHWT1(); 653 } 654 bool hasRDSEED() const { return HasRDSEED; } 655 bool hasLAHFSAHF() const { return HasLAHFSAHF; } 656 bool hasMWAITX() const { return HasMWAITX; } 657 bool hasCLZERO() const { return HasCLZERO; } 658 bool hasCLDEMOTE() const { return HasCLDEMOTE; } 659 bool hasMOVDIRI() const { return HasMOVDIRI; } 660 bool hasMOVDIR64B() const { return HasMOVDIR64B; } 661 bool hasPTWRITE() const { return HasPTWRITE; } 662 bool isSHLDSlow() const { return IsSHLDSlow; } 663 bool isPMULLDSlow() const { return IsPMULLDSlow; } 664 bool isPMADDWDSlow() const { return IsPMADDWDSlow; } 665 bool isUnalignedMem16Slow() const { return IsUAMem16Slow; } 666 bool isUnalignedMem32Slow() const { return IsUAMem32Slow; } 667 int getGatherOverhead() const { return GatherOverhead; } 668 int getScatterOverhead() const { return ScatterOverhead; } 669 bool hasSSEUnalignedMem() const { return HasSSEUnalignedMem; } 670 bool hasCmpxchg16b() const { return HasCmpxchg16b && is64Bit(); } 671 bool useLeaForSP() const { return UseLeaForSP; } 672 bool hasPOPCNTFalseDeps() const { return HasPOPCNTFalseDeps; } 673 bool hasLZCNTFalseDeps() const { return HasLZCNTFalseDeps; } 674 bool hasFastVariableShuffle() const { 675 return HasFastVariableShuffle; 676 } 677 bool insertVZEROUPPER() const { return InsertVZEROUPPER; } 678 bool hasFastGather() const { return HasFastGather; } 679 bool hasFastScalarFSQRT() const { return HasFastScalarFSQRT; } 680 bool hasFastVectorFSQRT() const { return HasFastVectorFSQRT; } 681 bool hasFastLZCNT() const { return HasFastLZCNT; } 682 bool hasFastSHLDRotate() const { return HasFastSHLDRotate; } 683 bool hasFastBEXTR() const { return HasFastBEXTR; } 684 bool hasFastHorizontalOps() const { return HasFastHorizontalOps; } 685 bool hasFastScalarShiftMasks() const { return HasFastScalarShiftMasks; } 686 bool hasFastVectorShiftMasks() const { return HasFastVectorShiftMasks; } 687 bool hasMacroFusion() const { return HasMacroFusion; } 688 bool hasBranchFusion() const { return HasBranchFusion; } 689 bool hasERMSB() const { return HasERMSB; } 690 bool hasSlowDivide32() const { return HasSlowDivide32; } 691 bool hasSlowDivide64() const { return HasSlowDivide64; } 692 bool padShortFunctions() const { return PadShortFunctions; } 693 bool slowTwoMemOps() const { return SlowTwoMemOps; } 694 bool LEAusesAG() const { return LEAUsesAG; } 695 bool slowLEA() const { return SlowLEA; } 696 bool slow3OpsLEA() const { return Slow3OpsLEA; } 697 bool slowIncDec() const { return SlowIncDec; } 698 bool hasCDI() const { return HasCDI; } 699 bool hasVPOPCNTDQ() const { return HasVPOPCNTDQ; } 700 bool hasPFI() const { return HasPFI; } 701 bool hasERI() const { return HasERI; } 702 bool hasDQI() const { return HasDQI; } 703 bool hasBWI() const { return HasBWI; } 704 bool hasVLX() const { return HasVLX; } 705 bool hasPKU() const { return HasPKU; } 706 bool hasVNNI() const { return HasVNNI; } 707 bool hasBF16() const { return HasBF16; } 708 bool hasVP2INTERSECT() const { return HasVP2INTERSECT; } 709 bool hasBITALG() const { return HasBITALG; } 710 bool hasSHSTK() const { return HasSHSTK; } 711 bool hasCLFLUSHOPT() const { return HasCLFLUSHOPT; } 712 bool hasCLWB() const { return HasCLWB; } 713 bool hasWBNOINVD() const { return HasWBNOINVD; } 714 bool hasRDPID() const { return HasRDPID; } 715 bool hasWAITPKG() const { return HasWAITPKG; } 716 bool hasPCONFIG() const { return HasPCONFIG; } 717 bool hasSGX() const { return HasSGX; } 718 bool threewayBranchProfitable() const { return ThreewayBranchProfitable; } 719 bool hasINVPCID() const { return HasINVPCID; } 720 bool hasENQCMD() const { return HasENQCMD; } 721 bool hasSERIALIZE() const { return HasSERIALIZE; } 722 bool hasTSXLDTRK() const { return HasTSXLDTRK; } 723 bool useRetpolineIndirectCalls() const { return UseRetpolineIndirectCalls; } 724 bool useRetpolineIndirectBranches() const { 725 return UseRetpolineIndirectBranches; 726 } 727 bool useRetpolineExternalThunk() const { return UseRetpolineExternalThunk; } 728 729 // These are generic getters that OR together all of the thunk types 730 // supported by the subtarget. Therefore useIndirectThunk*() will return true 731 // if any respective thunk feature is enabled. 732 bool useIndirectThunkCalls() const { 733 return useRetpolineIndirectCalls() || useLVIControlFlowIntegrity(); 734 } 735 bool useIndirectThunkBranches() const { 736 return useRetpolineIndirectBranches() || useLVIControlFlowIntegrity(); 737 } 738 739 bool preferMaskRegisters() const { return PreferMaskRegisters; } 740 bool useGLMDivSqrtCosts() const { return UseGLMDivSqrtCosts; } 741 bool useLVIControlFlowIntegrity() const { return UseLVIControlFlowIntegrity; } 742 743 unsigned getPreferVectorWidth() const { return PreferVectorWidth; } 744 unsigned getRequiredVectorWidth() const { return RequiredVectorWidth; } 745 746 // Helper functions to determine when we should allow widening to 512-bit 747 // during codegen. 748 // TODO: Currently we're always allowing widening on CPUs without VLX, 749 // because for many cases we don't have a better option. 750 bool canExtendTo512DQ() const { 751 return hasAVX512() && (!hasVLX() || getPreferVectorWidth() >= 512); 752 } 753 bool canExtendTo512BW() const { 754 return hasBWI() && canExtendTo512DQ(); 755 } 756 757 // If there are no 512-bit vectors and we prefer not to use 512-bit registers, 758 // disable them in the legalizer. 759 bool useAVX512Regs() const { 760 return hasAVX512() && (canExtendTo512DQ() || RequiredVectorWidth > 256); 761 } 762 763 bool useBWIRegs() const { 764 return hasBWI() && useAVX512Regs(); 765 } 766 767 bool isXRaySupported() const override { return is64Bit(); } 768 769 X86ProcFamilyEnum getProcFamily() const { return X86ProcFamily; } 770 771 /// TODO: to be removed later and replaced with suitable properties 772 bool isAtom() const { return X86ProcFamily == IntelAtom; } 773 bool isSLM() const { return X86ProcFamily == IntelSLM; } 774 bool useSoftFloat() const { return UseSoftFloat; } 775 bool useAA() const override { return UseAA; } 776 777 /// Use mfence if we have SSE2 or we're on x86-64 (even if we asked for 778 /// no-sse2). There isn't any reason to disable it if the target processor 779 /// supports it. 780 bool hasMFence() const { return hasSSE2() || is64Bit(); } 781 782 const Triple &getTargetTriple() const { return TargetTriple; } 783 784 bool isTargetDarwin() const { return TargetTriple.isOSDarwin(); } 785 bool isTargetFreeBSD() const { return TargetTriple.isOSFreeBSD(); } 786 bool isTargetDragonFly() const { return TargetTriple.isOSDragonFly(); } 787 bool isTargetSolaris() const { return TargetTriple.isOSSolaris(); } 788 bool isTargetPS4() const { return TargetTriple.isPS4CPU(); } 789 790 bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); } 791 bool isTargetCOFF() const { return TargetTriple.isOSBinFormatCOFF(); } 792 bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); } 793 794 bool isTargetLinux() const { return TargetTriple.isOSLinux(); } 795 bool isTargetKFreeBSD() const { return TargetTriple.isOSKFreeBSD(); } 796 bool isTargetGlibc() const { return TargetTriple.isOSGlibc(); } 797 bool isTargetAndroid() const { return TargetTriple.isAndroid(); } 798 bool isTargetNaCl() const { return TargetTriple.isOSNaCl(); } 799 bool isTargetNaCl32() const { return isTargetNaCl() && !is64Bit(); } 800 bool isTargetNaCl64() const { return isTargetNaCl() && is64Bit(); } 801 bool isTargetMCU() const { return TargetTriple.isOSIAMCU(); } 802 bool isTargetFuchsia() const { return TargetTriple.isOSFuchsia(); } 803 804 bool isTargetWindowsMSVC() const { 805 return TargetTriple.isWindowsMSVCEnvironment(); 806 } 807 808 bool isTargetWindowsCoreCLR() const { 809 return TargetTriple.isWindowsCoreCLREnvironment(); 810 } 811 812 bool isTargetWindowsCygwin() const { 813 return TargetTriple.isWindowsCygwinEnvironment(); 814 } 815 816 bool isTargetWindowsGNU() const { 817 return TargetTriple.isWindowsGNUEnvironment(); 818 } 819 820 bool isTargetWindowsItanium() const { 821 return TargetTriple.isWindowsItaniumEnvironment(); 822 } 823 824 bool isTargetCygMing() const { return TargetTriple.isOSCygMing(); } 825 826 bool isOSWindows() const { return TargetTriple.isOSWindows(); } 827 828 bool isTargetWin64() const { return In64BitMode && isOSWindows(); } 829 830 bool isTargetWin32() const { return !In64BitMode && isOSWindows(); } 831 832 bool isPICStyleGOT() const { return PICStyle == PICStyles::Style::GOT; } 833 bool isPICStyleRIPRel() const { return PICStyle == PICStyles::Style::RIPRel; } 834 835 bool isPICStyleStubPIC() const { 836 return PICStyle == PICStyles::Style::StubPIC; 837 } 838 839 bool isPositionIndependent() const { return TM.isPositionIndependent(); } 840 841 bool isCallingConvWin64(CallingConv::ID CC) const { 842 switch (CC) { 843 // On Win64, all these conventions just use the default convention. 844 case CallingConv::C: 845 case CallingConv::Fast: 846 case CallingConv::Tail: 847 case CallingConv::Swift: 848 case CallingConv::X86_FastCall: 849 case CallingConv::X86_StdCall: 850 case CallingConv::X86_ThisCall: 851 case CallingConv::X86_VectorCall: 852 case CallingConv::Intel_OCL_BI: 853 return isTargetWin64(); 854 // This convention allows using the Win64 convention on other targets. 855 case CallingConv::Win64: 856 return true; 857 // This convention allows using the SysV convention on Windows targets. 858 case CallingConv::X86_64_SysV: 859 return false; 860 // Otherwise, who knows what this is. 861 default: 862 return false; 863 } 864 } 865 866 /// Classify a global variable reference for the current subtarget according 867 /// to how we should reference it in a non-pcrel context. 868 unsigned char classifyLocalReference(const GlobalValue *GV) const; 869 870 unsigned char classifyGlobalReference(const GlobalValue *GV, 871 const Module &M) const; 872 unsigned char classifyGlobalReference(const GlobalValue *GV) const; 873 874 /// Classify a global function reference for the current subtarget. 875 unsigned char classifyGlobalFunctionReference(const GlobalValue *GV, 876 const Module &M) const; 877 unsigned char classifyGlobalFunctionReference(const GlobalValue *GV) const; 878 879 /// Classify a blockaddress reference for the current subtarget according to 880 /// how we should reference it in a non-pcrel context. 881 unsigned char classifyBlockAddressReference() const; 882 883 /// Return true if the subtarget allows calls to immediate address. 884 bool isLegalToCallImmediateAddr() const; 885 886 /// If we are using indirect thunks, we need to expand indirectbr to avoid it 887 /// lowering to an actual indirect jump. 888 bool enableIndirectBrExpand() const override { 889 return useIndirectThunkBranches(); 890 } 891 892 /// Enable the MachineScheduler pass for all X86 subtargets. 893 bool enableMachineScheduler() const override { return true; } 894 895 bool enableEarlyIfConversion() const override; 896 897 void getPostRAMutations(std::vector<std::unique_ptr<ScheduleDAGMutation>> 898 &Mutations) const override; 899 900 AntiDepBreakMode getAntiDepBreakMode() const override { 901 return TargetSubtargetInfo::ANTIDEP_CRITICAL; 902 } 903 904 bool enableAdvancedRASplitCost() const override { return true; } 905 }; 906 907 } // end namespace llvm 908 909 #endif // LLVM_LIB_TARGET_X86_X86SUBTARGET_H 910