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