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