1 //=====-- GCNSubtarget.h - Define GCN Subtarget for AMDGPU ------*- 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 /// \file 10 /// AMD GCN specific subclass of TargetSubtarget. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_LIB_TARGET_AMDGPU_GCNSUBTARGET_H 15 #define LLVM_LIB_TARGET_AMDGPU_GCNSUBTARGET_H 16 17 #include "AMDGPUCallLowering.h" 18 #include "AMDGPUSubtarget.h" 19 #include "SIFrameLowering.h" 20 #include "SIISelLowering.h" 21 #include "SIInstrInfo.h" 22 #include "llvm/CodeGen/SelectionDAGTargetInfo.h" 23 24 #define GET_SUBTARGETINFO_HEADER 25 #include "AMDGPUGenSubtargetInfo.inc" 26 27 namespace llvm { 28 29 class GCNTargetMachine; 30 31 class GCNSubtarget final : public AMDGPUGenSubtargetInfo, 32 public AMDGPUSubtarget { 33 34 using AMDGPUSubtarget::getMaxWavesPerEU; 35 36 public: 37 // Following 2 enums are documented at: 38 // - https://llvm.org/docs/AMDGPUUsage.html#trap-handler-abi 39 enum class TrapHandlerAbi { 40 NONE = 0x00, 41 AMDHSA = 0x01, 42 }; 43 44 enum class TrapID { 45 LLVMAMDHSATrap = 0x02, 46 LLVMAMDHSADebugTrap = 0x03, 47 }; 48 49 private: 50 /// GlobalISel related APIs. 51 std::unique_ptr<AMDGPUCallLowering> CallLoweringInfo; 52 std::unique_ptr<InlineAsmLowering> InlineAsmLoweringInfo; 53 std::unique_ptr<InstructionSelector> InstSelector; 54 std::unique_ptr<LegalizerInfo> Legalizer; 55 std::unique_ptr<RegisterBankInfo> RegBankInfo; 56 57 protected: 58 // Basic subtarget description. 59 Triple TargetTriple; 60 AMDGPU::IsaInfo::AMDGPUTargetID TargetID; 61 unsigned Gen; 62 InstrItineraryData InstrItins; 63 int LDSBankCount; 64 unsigned MaxPrivateElementSize; 65 66 // Possibly statically set by tablegen, but may want to be overridden. 67 bool FastFMAF32; 68 bool FastDenormalF32; 69 bool HalfRate64Ops; 70 bool FullRate64Ops; 71 72 // Dynamically set bits that enable features. 73 bool FlatForGlobal; 74 bool AutoWaitcntBeforeBarrier; 75 bool UnalignedScratchAccess; 76 bool UnalignedAccessMode; 77 bool HasApertureRegs; 78 bool SupportsXNACK; 79 80 // This should not be used directly. 'TargetID' tracks the dynamic settings 81 // for XNACK. 82 bool EnableXNACK; 83 84 bool EnableTgSplit; 85 bool EnableCuMode; 86 bool TrapHandler; 87 88 // Used as options. 89 bool EnableLoadStoreOpt; 90 bool EnableUnsafeDSOffsetFolding; 91 bool EnableSIScheduler; 92 bool EnableDS128; 93 bool EnablePRTStrictNull; 94 bool DumpCode; 95 96 // Subtarget statically properties set by tablegen 97 bool FP64; 98 bool FMA; 99 bool MIMG_R128; 100 bool IsGCN; 101 bool CIInsts; 102 bool GFX8Insts; 103 bool GFX9Insts; 104 bool GFX90AInsts; 105 bool GFX10Insts; 106 bool GFX10_3Insts; 107 bool GFX7GFX8GFX9Insts; 108 bool SGPRInitBug; 109 bool NegativeScratchOffsetBug; 110 bool NegativeUnalignedScratchOffsetBug; 111 bool HasSMemRealTime; 112 bool HasIntClamp; 113 bool HasFmaMixInsts; 114 bool HasMovrel; 115 bool HasVGPRIndexMode; 116 bool HasScalarStores; 117 bool HasScalarAtomics; 118 bool HasSDWAOmod; 119 bool HasSDWAScalar; 120 bool HasSDWASdst; 121 bool HasSDWAMac; 122 bool HasSDWAOutModsVOPC; 123 bool HasDPP; 124 bool HasDPP8; 125 bool Has64BitDPP; 126 bool HasPackedFP32Ops; 127 bool HasExtendedImageInsts; 128 bool HasR128A16; 129 bool HasGFX10A16; 130 bool HasG16; 131 bool HasNSAEncoding; 132 unsigned NSAMaxSize; 133 bool GFX10_AEncoding; 134 bool GFX10_BEncoding; 135 bool HasDLInsts; 136 bool HasDot1Insts; 137 bool HasDot2Insts; 138 bool HasDot3Insts; 139 bool HasDot4Insts; 140 bool HasDot5Insts; 141 bool HasDot6Insts; 142 bool HasDot7Insts; 143 bool HasMAIInsts; 144 bool HasPkFmacF16Inst; 145 bool HasAtomicFaddInsts; 146 bool SupportsSRAMECC; 147 148 // This should not be used directly. 'TargetID' tracks the dynamic settings 149 // for SRAMECC. 150 bool EnableSRAMECC; 151 152 bool HasNoSdstCMPX; 153 bool HasVscnt; 154 bool HasGetWaveIdInst; 155 bool HasSMemTimeInst; 156 bool HasShaderCyclesRegister; 157 bool HasRegisterBanking; 158 bool HasVOP3Literal; 159 bool HasNoDataDepHazard; 160 bool FlatAddressSpace; 161 bool FlatInstOffsets; 162 bool FlatGlobalInsts; 163 bool FlatScratchInsts; 164 bool ScalarFlatScratchInsts; 165 bool HasArchitectedFlatScratch; 166 bool AddNoCarryInsts; 167 bool HasUnpackedD16VMem; 168 bool R600ALUInst; 169 bool CaymanISA; 170 bool CFALUBug; 171 bool LDSMisalignedBug; 172 bool HasMFMAInlineLiteralBug; 173 bool HasVertexCache; 174 short TexVTXClauseSize; 175 bool UnalignedBufferAccess; 176 bool UnalignedDSAccess; 177 bool HasPackedTID; 178 bool ScalarizeGlobal; 179 180 bool HasVcmpxPermlaneHazard; 181 bool HasVMEMtoScalarWriteHazard; 182 bool HasSMEMtoVectorWriteHazard; 183 bool HasInstFwdPrefetchBug; 184 bool HasVcmpxExecWARHazard; 185 bool HasLdsBranchVmemWARHazard; 186 bool HasNSAtoVMEMBug; 187 bool HasNSAClauseBug; 188 bool HasOffset3fBug; 189 bool HasFlatSegmentOffsetBug; 190 bool HasImageStoreD16Bug; 191 bool HasImageGather4D16Bug; 192 193 // Dummy feature to use for assembler in tablegen. 194 bool FeatureDisable; 195 196 SelectionDAGTargetInfo TSInfo; 197 private: 198 SIInstrInfo InstrInfo; 199 SITargetLowering TLInfo; 200 SIFrameLowering FrameLowering; 201 202 public: 203 // See COMPUTE_TMPRING_SIZE.WAVESIZE, 13-bit field in units of 256-dword. 204 static const unsigned MaxWaveScratchSize = (256 * 4) * ((1 << 13) - 1); 205 206 GCNSubtarget(const Triple &TT, StringRef GPU, StringRef FS, 207 const GCNTargetMachine &TM); 208 ~GCNSubtarget() override; 209 210 GCNSubtarget &initializeSubtargetDependencies(const Triple &TT, 211 StringRef GPU, StringRef FS); 212 213 const SIInstrInfo *getInstrInfo() const override { 214 return &InstrInfo; 215 } 216 217 const SIFrameLowering *getFrameLowering() const override { 218 return &FrameLowering; 219 } 220 221 const SITargetLowering *getTargetLowering() const override { 222 return &TLInfo; 223 } 224 225 const SIRegisterInfo *getRegisterInfo() const override { 226 return &InstrInfo.getRegisterInfo(); 227 } 228 229 const CallLowering *getCallLowering() const override { 230 return CallLoweringInfo.get(); 231 } 232 233 const InlineAsmLowering *getInlineAsmLowering() const override { 234 return InlineAsmLoweringInfo.get(); 235 } 236 237 InstructionSelector *getInstructionSelector() const override { 238 return InstSelector.get(); 239 } 240 241 const LegalizerInfo *getLegalizerInfo() const override { 242 return Legalizer.get(); 243 } 244 245 const RegisterBankInfo *getRegBankInfo() const override { 246 return RegBankInfo.get(); 247 } 248 249 const AMDGPU::IsaInfo::AMDGPUTargetID &getTargetID() const { 250 return TargetID; 251 } 252 253 // Nothing implemented, just prevent crashes on use. 254 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override { 255 return &TSInfo; 256 } 257 258 const InstrItineraryData *getInstrItineraryData() const override { 259 return &InstrItins; 260 } 261 262 void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS); 263 264 Generation getGeneration() const { 265 return (Generation)Gen; 266 } 267 268 /// Return the number of high bits known to be zero fror a frame index. 269 unsigned getKnownHighZeroBitsForFrameIndex() const { 270 return countLeadingZeros(MaxWaveScratchSize) + getWavefrontSizeLog2(); 271 } 272 273 int getLDSBankCount() const { 274 return LDSBankCount; 275 } 276 277 unsigned getMaxPrivateElementSize(bool ForBufferRSrc = false) const { 278 return (ForBufferRSrc || !enableFlatScratch()) ? MaxPrivateElementSize : 16; 279 } 280 281 unsigned getConstantBusLimit(unsigned Opcode) const; 282 283 /// Returns if the result of this instruction with a 16-bit result returned in 284 /// a 32-bit register implicitly zeroes the high 16-bits, rather than preserve 285 /// the original value. 286 bool zeroesHigh16BitsOfDest(unsigned Opcode) const; 287 288 bool hasIntClamp() const { 289 return HasIntClamp; 290 } 291 292 bool hasFP64() const { 293 return FP64; 294 } 295 296 bool hasMIMG_R128() const { 297 return MIMG_R128; 298 } 299 300 bool hasHWFP64() const { 301 return FP64; 302 } 303 304 bool hasFastFMAF32() const { 305 return FastFMAF32; 306 } 307 308 bool hasHalfRate64Ops() const { 309 return HalfRate64Ops; 310 } 311 312 bool hasFullRate64Ops() const { 313 return FullRate64Ops; 314 } 315 316 bool hasAddr64() const { 317 return (getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS); 318 } 319 320 bool hasFlat() const { 321 return (getGeneration() > AMDGPUSubtarget::SOUTHERN_ISLANDS); 322 } 323 324 // Return true if the target only has the reverse operand versions of VALU 325 // shift instructions (e.g. v_lshrrev_b32, and no v_lshr_b32). 326 bool hasOnlyRevVALUShifts() const { 327 return getGeneration() >= VOLCANIC_ISLANDS; 328 } 329 330 bool hasFractBug() const { 331 return getGeneration() == SOUTHERN_ISLANDS; 332 } 333 334 bool hasBFE() const { 335 return true; 336 } 337 338 bool hasBFI() const { 339 return true; 340 } 341 342 bool hasBFM() const { 343 return hasBFE(); 344 } 345 346 bool hasBCNT(unsigned Size) const { 347 return true; 348 } 349 350 bool hasFFBL() const { 351 return true; 352 } 353 354 bool hasFFBH() const { 355 return true; 356 } 357 358 bool hasMed3_16() const { 359 return getGeneration() >= AMDGPUSubtarget::GFX9; 360 } 361 362 bool hasMin3Max3_16() const { 363 return getGeneration() >= AMDGPUSubtarget::GFX9; 364 } 365 366 bool hasFmaMixInsts() const { 367 return HasFmaMixInsts; 368 } 369 370 bool hasCARRY() const { 371 return true; 372 } 373 374 bool hasFMA() const { 375 return FMA; 376 } 377 378 bool hasSwap() const { 379 return GFX9Insts; 380 } 381 382 bool hasScalarPackInsts() const { 383 return GFX9Insts; 384 } 385 386 bool hasScalarMulHiInsts() const { 387 return GFX9Insts; 388 } 389 390 TrapHandlerAbi getTrapHandlerAbi() const { 391 return isAmdHsaOS() ? TrapHandlerAbi::AMDHSA : TrapHandlerAbi::NONE; 392 } 393 394 bool supportsGetDoorbellID() const { 395 // The S_GETREG DOORBELL_ID is supported by all GFX9 onward targets. 396 return getGeneration() >= GFX9; 397 } 398 399 /// True if the offset field of DS instructions works as expected. On SI, the 400 /// offset uses a 16-bit adder and does not always wrap properly. 401 bool hasUsableDSOffset() const { 402 return getGeneration() >= SEA_ISLANDS; 403 } 404 405 bool unsafeDSOffsetFoldingEnabled() const { 406 return EnableUnsafeDSOffsetFolding; 407 } 408 409 /// Condition output from div_scale is usable. 410 bool hasUsableDivScaleConditionOutput() const { 411 return getGeneration() != SOUTHERN_ISLANDS; 412 } 413 414 /// Extra wait hazard is needed in some cases before 415 /// s_cbranch_vccnz/s_cbranch_vccz. 416 bool hasReadVCCZBug() const { 417 return getGeneration() <= SEA_ISLANDS; 418 } 419 420 /// Writes to VCC_LO/VCC_HI update the VCCZ flag. 421 bool partialVCCWritesUpdateVCCZ() const { 422 return getGeneration() >= GFX10; 423 } 424 425 /// A read of an SGPR by SMRD instruction requires 4 wait states when the SGPR 426 /// was written by a VALU instruction. 427 bool hasSMRDReadVALUDefHazard() const { 428 return getGeneration() == SOUTHERN_ISLANDS; 429 } 430 431 /// A read of an SGPR by a VMEM instruction requires 5 wait states when the 432 /// SGPR was written by a VALU Instruction. 433 bool hasVMEMReadSGPRVALUDefHazard() const { 434 return getGeneration() >= VOLCANIC_ISLANDS; 435 } 436 437 bool hasRFEHazards() const { 438 return getGeneration() >= VOLCANIC_ISLANDS; 439 } 440 441 /// Number of hazard wait states for s_setreg_b32/s_setreg_imm32_b32. 442 unsigned getSetRegWaitStates() const { 443 return getGeneration() <= SEA_ISLANDS ? 1 : 2; 444 } 445 446 bool dumpCode() const { 447 return DumpCode; 448 } 449 450 /// Return the amount of LDS that can be used that will not restrict the 451 /// occupancy lower than WaveCount. 452 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount, 453 const Function &) const; 454 455 bool supportsMinMaxDenormModes() const { 456 return getGeneration() >= AMDGPUSubtarget::GFX9; 457 } 458 459 /// \returns If target supports S_DENORM_MODE. 460 bool hasDenormModeInst() const { 461 return getGeneration() >= AMDGPUSubtarget::GFX10; 462 } 463 464 bool useFlatForGlobal() const { 465 return FlatForGlobal; 466 } 467 468 /// \returns If target supports ds_read/write_b128 and user enables generation 469 /// of ds_read/write_b128. 470 bool useDS128() const { 471 return CIInsts && EnableDS128; 472 } 473 474 /// \return If target supports ds_read/write_b96/128. 475 bool hasDS96AndDS128() const { 476 return CIInsts; 477 } 478 479 /// Have v_trunc_f64, v_ceil_f64, v_rndne_f64 480 bool haveRoundOpsF64() const { 481 return CIInsts; 482 } 483 484 /// \returns If MUBUF instructions always perform range checking, even for 485 /// buffer resources used for private memory access. 486 bool privateMemoryResourceIsRangeChecked() const { 487 return getGeneration() < AMDGPUSubtarget::GFX9; 488 } 489 490 /// \returns If target requires PRT Struct NULL support (zero result registers 491 /// for sparse texture support). 492 bool usePRTStrictNull() const { 493 return EnablePRTStrictNull; 494 } 495 496 bool hasAutoWaitcntBeforeBarrier() const { 497 return AutoWaitcntBeforeBarrier; 498 } 499 500 bool hasUnalignedBufferAccess() const { 501 return UnalignedBufferAccess; 502 } 503 504 bool hasUnalignedBufferAccessEnabled() const { 505 return UnalignedBufferAccess && UnalignedAccessMode; 506 } 507 508 bool hasUnalignedDSAccess() const { 509 return UnalignedDSAccess; 510 } 511 512 bool hasUnalignedDSAccessEnabled() const { 513 return UnalignedDSAccess && UnalignedAccessMode; 514 } 515 516 bool hasUnalignedScratchAccess() const { 517 return UnalignedScratchAccess; 518 } 519 520 bool hasUnalignedAccessMode() const { 521 return UnalignedAccessMode; 522 } 523 524 bool hasApertureRegs() const { 525 return HasApertureRegs; 526 } 527 528 bool isTrapHandlerEnabled() const { 529 return TrapHandler; 530 } 531 532 bool isXNACKEnabled() const { 533 return TargetID.isXnackOnOrAny(); 534 } 535 536 bool isTgSplitEnabled() const { 537 return EnableTgSplit; 538 } 539 540 bool isCuModeEnabled() const { 541 return EnableCuMode; 542 } 543 544 bool hasFlatAddressSpace() const { 545 return FlatAddressSpace; 546 } 547 548 bool hasFlatScrRegister() const { 549 return hasFlatAddressSpace(); 550 } 551 552 bool hasFlatInstOffsets() const { 553 return FlatInstOffsets; 554 } 555 556 bool hasFlatGlobalInsts() const { 557 return FlatGlobalInsts; 558 } 559 560 bool hasFlatScratchInsts() const { 561 return FlatScratchInsts; 562 } 563 564 // Check if target supports ST addressing mode with FLAT scratch instructions. 565 // The ST addressing mode means no registers are used, either VGPR or SGPR, 566 // but only immediate offset is swizzled and added to the FLAT scratch base. 567 bool hasFlatScratchSTMode() const { 568 return hasFlatScratchInsts() && hasGFX10_3Insts(); 569 } 570 571 bool hasScalarFlatScratchInsts() const { 572 return ScalarFlatScratchInsts; 573 } 574 575 bool hasGlobalAddTidInsts() const { 576 return GFX10_BEncoding; 577 } 578 579 bool hasAtomicCSub() const { 580 return GFX10_BEncoding; 581 } 582 583 bool hasMultiDwordFlatScratchAddressing() const { 584 return getGeneration() >= GFX9; 585 } 586 587 bool hasFlatSegmentOffsetBug() const { 588 return HasFlatSegmentOffsetBug; 589 } 590 591 bool hasFlatLgkmVMemCountInOrder() const { 592 return getGeneration() > GFX9; 593 } 594 595 bool hasD16LoadStore() const { 596 return getGeneration() >= GFX9; 597 } 598 599 bool d16PreservesUnusedBits() const { 600 return hasD16LoadStore() && !TargetID.isSramEccOnOrAny(); 601 } 602 603 bool hasD16Images() const { 604 return getGeneration() >= VOLCANIC_ISLANDS; 605 } 606 607 /// Return if most LDS instructions have an m0 use that require m0 to be 608 /// iniitalized. 609 bool ldsRequiresM0Init() const { 610 return getGeneration() < GFX9; 611 } 612 613 // True if the hardware rewinds and replays GWS operations if a wave is 614 // preempted. 615 // 616 // If this is false, a GWS operation requires testing if a nack set the 617 // MEM_VIOL bit, and repeating if so. 618 bool hasGWSAutoReplay() const { 619 return getGeneration() >= GFX9; 620 } 621 622 /// \returns if target has ds_gws_sema_release_all instruction. 623 bool hasGWSSemaReleaseAll() const { 624 return CIInsts; 625 } 626 627 /// \returns true if the target has integer add/sub instructions that do not 628 /// produce a carry-out. This includes v_add_[iu]32, v_sub_[iu]32, 629 /// v_add_[iu]16, and v_sub_[iu]16, all of which support the clamp modifier 630 /// for saturation. 631 bool hasAddNoCarry() const { 632 return AddNoCarryInsts; 633 } 634 635 bool hasUnpackedD16VMem() const { 636 return HasUnpackedD16VMem; 637 } 638 639 // Covers VS/PS/CS graphics shaders 640 bool isMesaGfxShader(const Function &F) const { 641 return isMesa3DOS() && AMDGPU::isShader(F.getCallingConv()); 642 } 643 644 bool hasMad64_32() const { 645 return getGeneration() >= SEA_ISLANDS; 646 } 647 648 bool hasSDWAOmod() const { 649 return HasSDWAOmod; 650 } 651 652 bool hasSDWAScalar() const { 653 return HasSDWAScalar; 654 } 655 656 bool hasSDWASdst() const { 657 return HasSDWASdst; 658 } 659 660 bool hasSDWAMac() const { 661 return HasSDWAMac; 662 } 663 664 bool hasSDWAOutModsVOPC() const { 665 return HasSDWAOutModsVOPC; 666 } 667 668 bool hasDLInsts() const { 669 return HasDLInsts; 670 } 671 672 bool hasDot1Insts() const { 673 return HasDot1Insts; 674 } 675 676 bool hasDot2Insts() const { 677 return HasDot2Insts; 678 } 679 680 bool hasDot3Insts() const { 681 return HasDot3Insts; 682 } 683 684 bool hasDot4Insts() const { 685 return HasDot4Insts; 686 } 687 688 bool hasDot5Insts() const { 689 return HasDot5Insts; 690 } 691 692 bool hasDot6Insts() const { 693 return HasDot6Insts; 694 } 695 696 bool hasDot7Insts() const { 697 return HasDot7Insts; 698 } 699 700 bool hasMAIInsts() const { 701 return HasMAIInsts; 702 } 703 704 bool hasPkFmacF16Inst() const { 705 return HasPkFmacF16Inst; 706 } 707 708 bool hasAtomicFaddInsts() const { 709 return HasAtomicFaddInsts; 710 } 711 712 bool hasNoSdstCMPX() const { 713 return HasNoSdstCMPX; 714 } 715 716 bool hasVscnt() const { 717 return HasVscnt; 718 } 719 720 bool hasGetWaveIdInst() const { 721 return HasGetWaveIdInst; 722 } 723 724 bool hasSMemTimeInst() const { 725 return HasSMemTimeInst; 726 } 727 728 bool hasShaderCyclesRegister() const { 729 return HasShaderCyclesRegister; 730 } 731 732 bool hasRegisterBanking() const { 733 return HasRegisterBanking; 734 } 735 736 bool hasVOP3Literal() const { 737 return HasVOP3Literal; 738 } 739 740 bool hasNoDataDepHazard() const { 741 return HasNoDataDepHazard; 742 } 743 744 bool vmemWriteNeedsExpWaitcnt() const { 745 return getGeneration() < SEA_ISLANDS; 746 } 747 748 // Scratch is allocated in 256 dword per wave blocks for the entire 749 // wavefront. When viewed from the perspecive of an arbitrary workitem, this 750 // is 4-byte aligned. 751 // 752 // Only 4-byte alignment is really needed to access anything. Transformations 753 // on the pointer value itself may rely on the alignment / known low bits of 754 // the pointer. Set this to something above the minimum to avoid needing 755 // dynamic realignment in common cases. 756 Align getStackAlignment() const { return Align(16); } 757 758 bool enableMachineScheduler() const override { 759 return true; 760 } 761 762 bool useAA() const override; 763 764 bool enableSubRegLiveness() const override { 765 return true; 766 } 767 768 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b; } 769 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal; } 770 771 // static wrappers 772 static bool hasHalfRate64Ops(const TargetSubtargetInfo &STI); 773 774 // XXX - Why is this here if it isn't in the default pass set? 775 bool enableEarlyIfConversion() const override { 776 return true; 777 } 778 779 bool enableFlatScratch() const; 780 781 void overrideSchedPolicy(MachineSchedPolicy &Policy, 782 unsigned NumRegionInstrs) const override; 783 784 unsigned getMaxNumUserSGPRs() const { 785 return 16; 786 } 787 788 bool hasSMemRealTime() const { 789 return HasSMemRealTime; 790 } 791 792 bool hasMovrel() const { 793 return HasMovrel; 794 } 795 796 bool hasVGPRIndexMode() const { 797 return HasVGPRIndexMode; 798 } 799 800 bool useVGPRIndexMode() const; 801 802 bool hasScalarCompareEq64() const { 803 return getGeneration() >= VOLCANIC_ISLANDS; 804 } 805 806 bool hasScalarStores() const { 807 return HasScalarStores; 808 } 809 810 bool hasScalarAtomics() const { 811 return HasScalarAtomics; 812 } 813 814 bool hasLDSFPAtomicAdd() const { return GFX8Insts; } 815 816 /// \returns true if the subtarget has the v_permlanex16_b32 instruction. 817 bool hasPermLaneX16() const { return getGeneration() >= GFX10; } 818 819 bool hasDPP() const { 820 return HasDPP; 821 } 822 823 bool hasDPPBroadcasts() const { 824 return HasDPP && getGeneration() < GFX10; 825 } 826 827 bool hasDPPWavefrontShifts() const { 828 return HasDPP && getGeneration() < GFX10; 829 } 830 831 bool hasDPP8() const { 832 return HasDPP8; 833 } 834 835 bool has64BitDPP() const { 836 return Has64BitDPP; 837 } 838 839 bool hasPackedFP32Ops() const { 840 return HasPackedFP32Ops; 841 } 842 843 bool hasFmaakFmamkF32Insts() const { 844 return getGeneration() >= GFX10; 845 } 846 847 bool hasExtendedImageInsts() const { 848 return HasExtendedImageInsts; 849 } 850 851 bool hasR128A16() const { 852 return HasR128A16; 853 } 854 855 bool hasGFX10A16() const { 856 return HasGFX10A16; 857 } 858 859 bool hasA16() const { return hasR128A16() || hasGFX10A16(); } 860 861 bool hasG16() const { return HasG16; } 862 863 bool hasOffset3fBug() const { 864 return HasOffset3fBug; 865 } 866 867 bool hasImageStoreD16Bug() const { return HasImageStoreD16Bug; } 868 869 bool hasImageGather4D16Bug() const { return HasImageGather4D16Bug; } 870 871 bool hasNSAEncoding() const { return HasNSAEncoding; } 872 873 unsigned getNSAMaxSize() const { return NSAMaxSize; } 874 875 bool hasGFX10_AEncoding() const { 876 return GFX10_AEncoding; 877 } 878 879 bool hasGFX10_BEncoding() const { 880 return GFX10_BEncoding; 881 } 882 883 bool hasGFX10_3Insts() const { 884 return GFX10_3Insts; 885 } 886 887 bool hasMadF16() const; 888 889 bool enableSIScheduler() const { 890 return EnableSIScheduler; 891 } 892 893 bool loadStoreOptEnabled() const { 894 return EnableLoadStoreOpt; 895 } 896 897 bool hasSGPRInitBug() const { 898 return SGPRInitBug; 899 } 900 901 bool hasNegativeScratchOffsetBug() const { return NegativeScratchOffsetBug; } 902 903 bool hasNegativeUnalignedScratchOffsetBug() const { 904 return NegativeUnalignedScratchOffsetBug; 905 } 906 907 bool hasMFMAInlineLiteralBug() const { 908 return HasMFMAInlineLiteralBug; 909 } 910 911 bool has12DWordStoreHazard() const { 912 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS; 913 } 914 915 // \returns true if the subtarget supports DWORDX3 load/store instructions. 916 bool hasDwordx3LoadStores() const { 917 return CIInsts; 918 } 919 920 bool hasReadM0MovRelInterpHazard() const { 921 return getGeneration() == AMDGPUSubtarget::GFX9; 922 } 923 924 bool hasReadM0SendMsgHazard() const { 925 return getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS && 926 getGeneration() <= AMDGPUSubtarget::GFX9; 927 } 928 929 bool hasVcmpxPermlaneHazard() const { 930 return HasVcmpxPermlaneHazard; 931 } 932 933 bool hasVMEMtoScalarWriteHazard() const { 934 return HasVMEMtoScalarWriteHazard; 935 } 936 937 bool hasSMEMtoVectorWriteHazard() const { 938 return HasSMEMtoVectorWriteHazard; 939 } 940 941 bool hasLDSMisalignedBug() const { 942 return LDSMisalignedBug && !EnableCuMode; 943 } 944 945 bool hasInstFwdPrefetchBug() const { 946 return HasInstFwdPrefetchBug; 947 } 948 949 bool hasVcmpxExecWARHazard() const { 950 return HasVcmpxExecWARHazard; 951 } 952 953 bool hasLdsBranchVmemWARHazard() const { 954 return HasLdsBranchVmemWARHazard; 955 } 956 957 bool hasNSAtoVMEMBug() const { 958 return HasNSAtoVMEMBug; 959 } 960 961 bool hasNSAClauseBug() const { return HasNSAClauseBug; } 962 963 bool hasHardClauses() const { return getGeneration() >= GFX10; } 964 965 bool hasGFX90AInsts() const { return GFX90AInsts; } 966 967 /// Return if operations acting on VGPR tuples require even alignment. 968 bool needsAlignedVGPRs() const { return GFX90AInsts; } 969 970 bool hasPackedTID() const { return HasPackedTID; } 971 972 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs 973 /// SGPRs 974 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const; 975 976 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs 977 /// VGPRs 978 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const; 979 980 /// Return occupancy for the given function. Used LDS and a number of 981 /// registers if provided. 982 /// Note, occupancy can be affected by the scratch allocation as well, but 983 /// we do not have enough information to compute it. 984 unsigned computeOccupancy(const Function &F, unsigned LDSSize = 0, 985 unsigned NumSGPRs = 0, unsigned NumVGPRs = 0) const; 986 987 /// \returns true if the flat_scratch register should be initialized with the 988 /// pointer to the wave's scratch memory rather than a size and offset. 989 bool flatScratchIsPointer() const { 990 return getGeneration() >= AMDGPUSubtarget::GFX9; 991 } 992 993 /// \returns true if the flat_scratch register is initialized by the HW. 994 /// In this case it is readonly. 995 bool flatScratchIsArchitected() const { return HasArchitectedFlatScratch; } 996 997 /// \returns true if the machine has merged shaders in which s0-s7 are 998 /// reserved by the hardware and user SGPRs start at s8 999 bool hasMergedShaders() const { 1000 return getGeneration() >= GFX9; 1001 } 1002 1003 /// \returns SGPR allocation granularity supported by the subtarget. 1004 unsigned getSGPRAllocGranule() const { 1005 return AMDGPU::IsaInfo::getSGPRAllocGranule(this); 1006 } 1007 1008 /// \returns SGPR encoding granularity supported by the subtarget. 1009 unsigned getSGPREncodingGranule() const { 1010 return AMDGPU::IsaInfo::getSGPREncodingGranule(this); 1011 } 1012 1013 /// \returns Total number of SGPRs supported by the subtarget. 1014 unsigned getTotalNumSGPRs() const { 1015 return AMDGPU::IsaInfo::getTotalNumSGPRs(this); 1016 } 1017 1018 /// \returns Addressable number of SGPRs supported by the subtarget. 1019 unsigned getAddressableNumSGPRs() const { 1020 return AMDGPU::IsaInfo::getAddressableNumSGPRs(this); 1021 } 1022 1023 /// \returns Minimum number of SGPRs that meets the given number of waves per 1024 /// execution unit requirement supported by the subtarget. 1025 unsigned getMinNumSGPRs(unsigned WavesPerEU) const { 1026 return AMDGPU::IsaInfo::getMinNumSGPRs(this, WavesPerEU); 1027 } 1028 1029 /// \returns Maximum number of SGPRs that meets the given number of waves per 1030 /// execution unit requirement supported by the subtarget. 1031 unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const { 1032 return AMDGPU::IsaInfo::getMaxNumSGPRs(this, WavesPerEU, Addressable); 1033 } 1034 1035 /// \returns Reserved number of SGPRs. This is common 1036 /// utility function called by MachineFunction and 1037 /// Function variants of getReservedNumSGPRs. 1038 unsigned getBaseReservedNumSGPRs(const bool HasFlatScratchInit) const; 1039 /// \returns Reserved number of SGPRs for given machine function \p MF. 1040 unsigned getReservedNumSGPRs(const MachineFunction &MF) const; 1041 1042 /// \returns Reserved number of SGPRs for given function \p F. 1043 unsigned getReservedNumSGPRs(const Function &F) const; 1044 1045 /// \returns max num SGPRs. This is the common utility 1046 /// function called by MachineFunction and Function 1047 /// variants of getMaxNumSGPRs. 1048 unsigned getBaseMaxNumSGPRs(const Function &F, 1049 std::pair<unsigned, unsigned> WavesPerEU, 1050 unsigned PreloadedSGPRs, 1051 unsigned ReservedNumSGPRs) const; 1052 1053 /// \returns Maximum number of SGPRs that meets number of waves per execution 1054 /// unit requirement for function \p MF, or number of SGPRs explicitly 1055 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF. 1056 /// 1057 /// \returns Value that meets number of waves per execution unit requirement 1058 /// if explicitly requested value cannot be converted to integer, violates 1059 /// subtarget's specifications, or does not meet number of waves per execution 1060 /// unit requirement. 1061 unsigned getMaxNumSGPRs(const MachineFunction &MF) const; 1062 1063 /// \returns Maximum number of SGPRs that meets number of waves per execution 1064 /// unit requirement for function \p F, or number of SGPRs explicitly 1065 /// requested using "amdgpu-num-sgpr" attribute attached to function \p F. 1066 /// 1067 /// \returns Value that meets number of waves per execution unit requirement 1068 /// if explicitly requested value cannot be converted to integer, violates 1069 /// subtarget's specifications, or does not meet number of waves per execution 1070 /// unit requirement. 1071 unsigned getMaxNumSGPRs(const Function &F) const; 1072 1073 /// \returns VGPR allocation granularity supported by the subtarget. 1074 unsigned getVGPRAllocGranule() const { 1075 return AMDGPU::IsaInfo::getVGPRAllocGranule(this); 1076 } 1077 1078 /// \returns VGPR encoding granularity supported by the subtarget. 1079 unsigned getVGPREncodingGranule() const { 1080 return AMDGPU::IsaInfo::getVGPREncodingGranule(this); 1081 } 1082 1083 /// \returns Total number of VGPRs supported by the subtarget. 1084 unsigned getTotalNumVGPRs() const { 1085 return AMDGPU::IsaInfo::getTotalNumVGPRs(this); 1086 } 1087 1088 /// \returns Addressable number of VGPRs supported by the subtarget. 1089 unsigned getAddressableNumVGPRs() const { 1090 return AMDGPU::IsaInfo::getAddressableNumVGPRs(this); 1091 } 1092 1093 /// \returns Minimum number of VGPRs that meets given number of waves per 1094 /// execution unit requirement supported by the subtarget. 1095 unsigned getMinNumVGPRs(unsigned WavesPerEU) const { 1096 return AMDGPU::IsaInfo::getMinNumVGPRs(this, WavesPerEU); 1097 } 1098 1099 /// \returns Maximum number of VGPRs that meets given number of waves per 1100 /// execution unit requirement supported by the subtarget. 1101 unsigned getMaxNumVGPRs(unsigned WavesPerEU) const { 1102 return AMDGPU::IsaInfo::getMaxNumVGPRs(this, WavesPerEU); 1103 } 1104 1105 /// \returns max num VGPRs. This is the common utility function 1106 /// called by MachineFunction and Function variants of getMaxNumVGPRs. 1107 unsigned getBaseMaxNumVGPRs(const Function &F, 1108 std::pair<unsigned, unsigned> WavesPerEU) const; 1109 /// \returns Maximum number of VGPRs that meets number of waves per execution 1110 /// unit requirement for function \p F, or number of VGPRs explicitly 1111 /// requested using "amdgpu-num-vgpr" attribute attached to function \p F. 1112 /// 1113 /// \returns Value that meets number of waves per execution unit requirement 1114 /// if explicitly requested value cannot be converted to integer, violates 1115 /// subtarget's specifications, or does not meet number of waves per execution 1116 /// unit requirement. 1117 unsigned getMaxNumVGPRs(const Function &F) const; 1118 1119 /// \returns Maximum number of VGPRs that meets number of waves per execution 1120 /// unit requirement for function \p MF, or number of VGPRs explicitly 1121 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF. 1122 /// 1123 /// \returns Value that meets number of waves per execution unit requirement 1124 /// if explicitly requested value cannot be converted to integer, violates 1125 /// subtarget's specifications, or does not meet number of waves per execution 1126 /// unit requirement. 1127 unsigned getMaxNumVGPRs(const MachineFunction &MF) const; 1128 1129 void getPostRAMutations( 1130 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) 1131 const override; 1132 1133 bool isWave32() const { 1134 return getWavefrontSize() == 32; 1135 } 1136 1137 bool isWave64() const { 1138 return getWavefrontSize() == 64; 1139 } 1140 1141 const TargetRegisterClass *getBoolRC() const { 1142 return getRegisterInfo()->getBoolRC(); 1143 } 1144 1145 /// \returns Maximum number of work groups per compute unit supported by the 1146 /// subtarget and limited by given \p FlatWorkGroupSize. 1147 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const override { 1148 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(this, FlatWorkGroupSize); 1149 } 1150 1151 /// \returns Minimum flat work group size supported by the subtarget. 1152 unsigned getMinFlatWorkGroupSize() const override { 1153 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(this); 1154 } 1155 1156 /// \returns Maximum flat work group size supported by the subtarget. 1157 unsigned getMaxFlatWorkGroupSize() const override { 1158 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(this); 1159 } 1160 1161 /// \returns Number of waves per execution unit required to support the given 1162 /// \p FlatWorkGroupSize. 1163 unsigned 1164 getWavesPerEUForWorkGroup(unsigned FlatWorkGroupSize) const override { 1165 return AMDGPU::IsaInfo::getWavesPerEUForWorkGroup(this, FlatWorkGroupSize); 1166 } 1167 1168 /// \returns Minimum number of waves per execution unit supported by the 1169 /// subtarget. 1170 unsigned getMinWavesPerEU() const override { 1171 return AMDGPU::IsaInfo::getMinWavesPerEU(this); 1172 } 1173 1174 void adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use, int UseOpIdx, 1175 SDep &Dep) const override; 1176 }; 1177 1178 } // end namespace llvm 1179 1180 #endif // LLVM_LIB_TARGET_AMDGPU_GCNSUBTARGET_H 1181