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 hasFlatScratchSVSMode() const { return GFX940Insts; } 575 576 bool hasScalarFlatScratchInsts() const { 577 return ScalarFlatScratchInsts; 578 } 579 580 bool enableFlatScratch() const { 581 return flatScratchIsArchitected() || 582 (EnableFlatScratch && hasFlatScratchInsts()); 583 } 584 585 bool hasGlobalAddTidInsts() const { 586 return GFX10_BEncoding; 587 } 588 589 bool hasAtomicCSub() const { 590 return GFX10_BEncoding; 591 } 592 593 bool hasMultiDwordFlatScratchAddressing() const { 594 return getGeneration() >= GFX9; 595 } 596 597 bool hasFlatSegmentOffsetBug() const { 598 return HasFlatSegmentOffsetBug; 599 } 600 601 bool hasFlatLgkmVMemCountInOrder() const { 602 return getGeneration() > GFX9; 603 } 604 605 bool hasD16LoadStore() const { 606 return getGeneration() >= GFX9; 607 } 608 609 bool d16PreservesUnusedBits() const { 610 return hasD16LoadStore() && !TargetID.isSramEccOnOrAny(); 611 } 612 613 bool hasD16Images() const { 614 return getGeneration() >= VOLCANIC_ISLANDS; 615 } 616 617 /// Return if most LDS instructions have an m0 use that require m0 to be 618 /// initialized. 619 bool ldsRequiresM0Init() const { 620 return getGeneration() < GFX9; 621 } 622 623 // True if the hardware rewinds and replays GWS operations if a wave is 624 // preempted. 625 // 626 // If this is false, a GWS operation requires testing if a nack set the 627 // MEM_VIOL bit, and repeating if so. 628 bool hasGWSAutoReplay() const { 629 return getGeneration() >= GFX9; 630 } 631 632 /// \returns if target has ds_gws_sema_release_all instruction. 633 bool hasGWSSemaReleaseAll() const { 634 return CIInsts; 635 } 636 637 /// \returns true if the target has integer add/sub instructions that do not 638 /// produce a carry-out. This includes v_add_[iu]32, v_sub_[iu]32, 639 /// v_add_[iu]16, and v_sub_[iu]16, all of which support the clamp modifier 640 /// for saturation. 641 bool hasAddNoCarry() const { 642 return AddNoCarryInsts; 643 } 644 645 bool hasUnpackedD16VMem() const { 646 return HasUnpackedD16VMem; 647 } 648 649 // Covers VS/PS/CS graphics shaders 650 bool isMesaGfxShader(const Function &F) const { 651 return isMesa3DOS() && AMDGPU::isShader(F.getCallingConv()); 652 } 653 654 bool hasMad64_32() const { 655 return getGeneration() >= SEA_ISLANDS; 656 } 657 658 bool hasSDWAOmod() const { 659 return HasSDWAOmod; 660 } 661 662 bool hasSDWAScalar() const { 663 return HasSDWAScalar; 664 } 665 666 bool hasSDWASdst() const { 667 return HasSDWASdst; 668 } 669 670 bool hasSDWAMac() const { 671 return HasSDWAMac; 672 } 673 674 bool hasSDWAOutModsVOPC() const { 675 return HasSDWAOutModsVOPC; 676 } 677 678 bool hasDLInsts() const { 679 return HasDLInsts; 680 } 681 682 bool hasDot1Insts() const { 683 return HasDot1Insts; 684 } 685 686 bool hasDot2Insts() const { 687 return HasDot2Insts; 688 } 689 690 bool hasDot3Insts() const { 691 return HasDot3Insts; 692 } 693 694 bool hasDot4Insts() const { 695 return HasDot4Insts; 696 } 697 698 bool hasDot5Insts() const { 699 return HasDot5Insts; 700 } 701 702 bool hasDot6Insts() const { 703 return HasDot6Insts; 704 } 705 706 bool hasDot7Insts() const { 707 return HasDot7Insts; 708 } 709 710 bool hasMAIInsts() const { 711 return HasMAIInsts; 712 } 713 714 bool hasPkFmacF16Inst() const { 715 return HasPkFmacF16Inst; 716 } 717 718 bool hasAtomicFaddInsts() const { 719 return HasAtomicFaddInsts; 720 } 721 722 bool hasNoSdstCMPX() const { 723 return HasNoSdstCMPX; 724 } 725 726 bool hasVscnt() const { 727 return HasVscnt; 728 } 729 730 bool hasGetWaveIdInst() const { 731 return HasGetWaveIdInst; 732 } 733 734 bool hasSMemTimeInst() const { 735 return HasSMemTimeInst; 736 } 737 738 bool hasShaderCyclesRegister() const { 739 return HasShaderCyclesRegister; 740 } 741 742 bool hasVOP3Literal() const { 743 return HasVOP3Literal; 744 } 745 746 bool hasNoDataDepHazard() const { 747 return HasNoDataDepHazard; 748 } 749 750 bool vmemWriteNeedsExpWaitcnt() const { 751 return getGeneration() < SEA_ISLANDS; 752 } 753 754 // Scratch is allocated in 256 dword per wave blocks for the entire 755 // wavefront. When viewed from the perspective of an arbitrary workitem, this 756 // is 4-byte aligned. 757 // 758 // Only 4-byte alignment is really needed to access anything. Transformations 759 // on the pointer value itself may rely on the alignment / known low bits of 760 // the pointer. Set this to something above the minimum to avoid needing 761 // dynamic realignment in common cases. 762 Align getStackAlignment() const { return Align(16); } 763 764 bool enableMachineScheduler() const override { 765 return true; 766 } 767 768 bool useAA() const override; 769 770 bool enableSubRegLiveness() const override { 771 return true; 772 } 773 774 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b; } 775 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal; } 776 777 // static wrappers 778 static bool hasHalfRate64Ops(const TargetSubtargetInfo &STI); 779 780 // XXX - Why is this here if it isn't in the default pass set? 781 bool enableEarlyIfConversion() const override { 782 return true; 783 } 784 785 void overrideSchedPolicy(MachineSchedPolicy &Policy, 786 unsigned NumRegionInstrs) const override; 787 788 unsigned getMaxNumUserSGPRs() const { 789 return 16; 790 } 791 792 bool hasSMemRealTime() const { 793 return HasSMemRealTime; 794 } 795 796 bool hasMovrel() const { 797 return HasMovrel; 798 } 799 800 bool hasVGPRIndexMode() const { 801 return HasVGPRIndexMode; 802 } 803 804 bool useVGPRIndexMode() const; 805 806 bool hasScalarCompareEq64() const { 807 return getGeneration() >= VOLCANIC_ISLANDS; 808 } 809 810 bool hasScalarStores() const { 811 return HasScalarStores; 812 } 813 814 bool hasScalarAtomics() const { 815 return HasScalarAtomics; 816 } 817 818 bool hasLDSFPAtomicAdd() const { return GFX8Insts; } 819 820 /// \returns true if the subtarget has the v_permlanex16_b32 instruction. 821 bool hasPermLaneX16() const { return getGeneration() >= GFX10; } 822 823 bool hasDPP() const { 824 return HasDPP; 825 } 826 827 bool hasDPPBroadcasts() const { 828 return HasDPP && getGeneration() < GFX10; 829 } 830 831 bool hasDPPWavefrontShifts() const { 832 return HasDPP && getGeneration() < GFX10; 833 } 834 835 bool hasDPP8() const { 836 return HasDPP8; 837 } 838 839 bool has64BitDPP() const { 840 return Has64BitDPP; 841 } 842 843 bool hasPackedFP32Ops() const { 844 return HasPackedFP32Ops; 845 } 846 847 bool hasFmaakFmamkF32Insts() const { 848 return getGeneration() >= GFX10 || hasGFX940Insts(); 849 } 850 851 bool hasImageInsts() const { 852 return HasImageInsts; 853 } 854 855 bool hasExtendedImageInsts() const { 856 return HasExtendedImageInsts; 857 } 858 859 bool hasR128A16() const { 860 return HasR128A16; 861 } 862 863 bool hasGFX10A16() const { 864 return HasGFX10A16; 865 } 866 867 bool hasA16() const { return hasR128A16() || hasGFX10A16(); } 868 869 bool hasG16() const { return HasG16; } 870 871 bool hasOffset3fBug() const { 872 return HasOffset3fBug; 873 } 874 875 bool hasImageStoreD16Bug() const { return HasImageStoreD16Bug; } 876 877 bool hasImageGather4D16Bug() const { return HasImageGather4D16Bug; } 878 879 bool hasNSAEncoding() const { return HasNSAEncoding; } 880 881 unsigned getNSAMaxSize() const { return NSAMaxSize; } 882 883 bool hasGFX10_AEncoding() const { 884 return GFX10_AEncoding; 885 } 886 887 bool hasGFX10_BEncoding() const { 888 return GFX10_BEncoding; 889 } 890 891 bool hasGFX10_3Insts() const { 892 return GFX10_3Insts; 893 } 894 895 bool hasMadF16() const; 896 897 bool hasMovB64() const { return GFX940Insts; } 898 899 bool hasLshlAddB64() const { return GFX940Insts; } 900 901 bool enableSIScheduler() const { 902 return EnableSIScheduler; 903 } 904 905 bool loadStoreOptEnabled() const { 906 return EnableLoadStoreOpt; 907 } 908 909 bool hasSGPRInitBug() const { 910 return SGPRInitBug; 911 } 912 913 bool hasNegativeScratchOffsetBug() const { return NegativeScratchOffsetBug; } 914 915 bool hasNegativeUnalignedScratchOffsetBug() const { 916 return NegativeUnalignedScratchOffsetBug; 917 } 918 919 bool hasMFMAInlineLiteralBug() const { 920 return HasMFMAInlineLiteralBug; 921 } 922 923 bool has12DWordStoreHazard() const { 924 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS; 925 } 926 927 // \returns true if the subtarget supports DWORDX3 load/store instructions. 928 bool hasDwordx3LoadStores() const { 929 return CIInsts; 930 } 931 932 bool hasReadM0MovRelInterpHazard() const { 933 return getGeneration() == AMDGPUSubtarget::GFX9; 934 } 935 936 bool hasReadM0SendMsgHazard() const { 937 return getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS && 938 getGeneration() <= AMDGPUSubtarget::GFX9; 939 } 940 941 bool hasVcmpxPermlaneHazard() const { 942 return HasVcmpxPermlaneHazard; 943 } 944 945 bool hasVMEMtoScalarWriteHazard() const { 946 return HasVMEMtoScalarWriteHazard; 947 } 948 949 bool hasSMEMtoVectorWriteHazard() const { 950 return HasSMEMtoVectorWriteHazard; 951 } 952 953 bool hasLDSMisalignedBug() const { 954 return LDSMisalignedBug && !EnableCuMode; 955 } 956 957 bool hasInstFwdPrefetchBug() const { 958 return HasInstFwdPrefetchBug; 959 } 960 961 bool hasVcmpxExecWARHazard() const { 962 return HasVcmpxExecWARHazard; 963 } 964 965 bool hasLdsBranchVmemWARHazard() const { 966 return HasLdsBranchVmemWARHazard; 967 } 968 969 // Cannot use op_sel with v_dot instructions. 970 bool hasDOTOpSelHazard() const { 971 return GFX940Insts; 972 } 973 974 bool hasNSAtoVMEMBug() const { 975 return HasNSAtoVMEMBug; 976 } 977 978 bool hasNSAClauseBug() const { return HasNSAClauseBug; } 979 980 bool hasHardClauses() const { return getGeneration() >= GFX10; } 981 982 bool hasGFX90AInsts() const { return GFX90AInsts; } 983 984 /// Return if operations acting on VGPR tuples require even alignment. 985 bool needsAlignedVGPRs() const { return GFX90AInsts; } 986 987 bool hasPackedTID() const { return HasPackedTID; } 988 989 // GFX940 is a derivation to GFX90A. hasGFX940Insts() being true implies that 990 // hasGFX90AInsts is also true. 991 bool hasGFX940Insts() const { return GFX940Insts; } 992 993 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs 994 /// SGPRs 995 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const; 996 997 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs 998 /// VGPRs 999 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const; 1000 1001 /// Return occupancy for the given function. Used LDS and a number of 1002 /// registers if provided. 1003 /// Note, occupancy can be affected by the scratch allocation as well, but 1004 /// we do not have enough information to compute it. 1005 unsigned computeOccupancy(const Function &F, unsigned LDSSize = 0, 1006 unsigned NumSGPRs = 0, unsigned NumVGPRs = 0) const; 1007 1008 /// \returns true if the flat_scratch register should be initialized with the 1009 /// pointer to the wave's scratch memory rather than a size and offset. 1010 bool flatScratchIsPointer() const { 1011 return getGeneration() >= AMDGPUSubtarget::GFX9; 1012 } 1013 1014 /// \returns true if the flat_scratch register is initialized by the HW. 1015 /// In this case it is readonly. 1016 bool flatScratchIsArchitected() const { return HasArchitectedFlatScratch; } 1017 1018 /// \returns true if the machine has merged shaders in which s0-s7 are 1019 /// reserved by the hardware and user SGPRs start at s8 1020 bool hasMergedShaders() const { 1021 return getGeneration() >= GFX9; 1022 } 1023 1024 /// \returns SGPR allocation granularity supported by the subtarget. 1025 unsigned getSGPRAllocGranule() const { 1026 return AMDGPU::IsaInfo::getSGPRAllocGranule(this); 1027 } 1028 1029 /// \returns SGPR encoding granularity supported by the subtarget. 1030 unsigned getSGPREncodingGranule() const { 1031 return AMDGPU::IsaInfo::getSGPREncodingGranule(this); 1032 } 1033 1034 /// \returns Total number of SGPRs supported by the subtarget. 1035 unsigned getTotalNumSGPRs() const { 1036 return AMDGPU::IsaInfo::getTotalNumSGPRs(this); 1037 } 1038 1039 /// \returns Addressable number of SGPRs supported by the subtarget. 1040 unsigned getAddressableNumSGPRs() const { 1041 return AMDGPU::IsaInfo::getAddressableNumSGPRs(this); 1042 } 1043 1044 /// \returns Minimum number of SGPRs that meets the given number of waves per 1045 /// execution unit requirement supported by the subtarget. 1046 unsigned getMinNumSGPRs(unsigned WavesPerEU) const { 1047 return AMDGPU::IsaInfo::getMinNumSGPRs(this, WavesPerEU); 1048 } 1049 1050 /// \returns Maximum number of SGPRs that meets the given number of waves per 1051 /// execution unit requirement supported by the subtarget. 1052 unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const { 1053 return AMDGPU::IsaInfo::getMaxNumSGPRs(this, WavesPerEU, Addressable); 1054 } 1055 1056 /// \returns Reserved number of SGPRs. This is common 1057 /// utility function called by MachineFunction and 1058 /// Function variants of getReservedNumSGPRs. 1059 unsigned getBaseReservedNumSGPRs(const bool HasFlatScratch) const; 1060 /// \returns Reserved number of SGPRs for given machine function \p MF. 1061 unsigned getReservedNumSGPRs(const MachineFunction &MF) const; 1062 1063 /// \returns Reserved number of SGPRs for given function \p F. 1064 unsigned getReservedNumSGPRs(const Function &F) const; 1065 1066 /// \returns max num SGPRs. This is the common utility 1067 /// function called by MachineFunction and Function 1068 /// variants of getMaxNumSGPRs. 1069 unsigned getBaseMaxNumSGPRs(const Function &F, 1070 std::pair<unsigned, unsigned> WavesPerEU, 1071 unsigned PreloadedSGPRs, 1072 unsigned ReservedNumSGPRs) const; 1073 1074 /// \returns Maximum number of SGPRs that meets number of waves per execution 1075 /// unit requirement for function \p MF, or number of SGPRs explicitly 1076 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF. 1077 /// 1078 /// \returns Value that meets number of waves per execution unit requirement 1079 /// if explicitly requested value cannot be converted to integer, violates 1080 /// subtarget's specifications, or does not meet number of waves per execution 1081 /// unit requirement. 1082 unsigned getMaxNumSGPRs(const MachineFunction &MF) const; 1083 1084 /// \returns Maximum number of SGPRs that meets number of waves per execution 1085 /// unit requirement for function \p F, or number of SGPRs explicitly 1086 /// requested using "amdgpu-num-sgpr" attribute attached to function \p F. 1087 /// 1088 /// \returns Value that meets number of waves per execution unit requirement 1089 /// if explicitly requested value cannot be converted to integer, violates 1090 /// subtarget's specifications, or does not meet number of waves per execution 1091 /// unit requirement. 1092 unsigned getMaxNumSGPRs(const Function &F) const; 1093 1094 /// \returns VGPR allocation granularity supported by the subtarget. 1095 unsigned getVGPRAllocGranule() const { 1096 return AMDGPU::IsaInfo::getVGPRAllocGranule(this); 1097 } 1098 1099 /// \returns VGPR encoding granularity supported by the subtarget. 1100 unsigned getVGPREncodingGranule() const { 1101 return AMDGPU::IsaInfo::getVGPREncodingGranule(this); 1102 } 1103 1104 /// \returns Total number of VGPRs supported by the subtarget. 1105 unsigned getTotalNumVGPRs() const { 1106 return AMDGPU::IsaInfo::getTotalNumVGPRs(this); 1107 } 1108 1109 /// \returns Addressable number of VGPRs supported by the subtarget. 1110 unsigned getAddressableNumVGPRs() const { 1111 return AMDGPU::IsaInfo::getAddressableNumVGPRs(this); 1112 } 1113 1114 /// \returns Minimum number of VGPRs that meets given number of waves per 1115 /// execution unit requirement supported by the subtarget. 1116 unsigned getMinNumVGPRs(unsigned WavesPerEU) const { 1117 return AMDGPU::IsaInfo::getMinNumVGPRs(this, WavesPerEU); 1118 } 1119 1120 /// \returns Maximum number of VGPRs that meets given number of waves per 1121 /// execution unit requirement supported by the subtarget. 1122 unsigned getMaxNumVGPRs(unsigned WavesPerEU) const { 1123 return AMDGPU::IsaInfo::getMaxNumVGPRs(this, WavesPerEU); 1124 } 1125 1126 /// \returns max num VGPRs. This is the common utility function 1127 /// called by MachineFunction and Function variants of getMaxNumVGPRs. 1128 unsigned getBaseMaxNumVGPRs(const Function &F, 1129 std::pair<unsigned, unsigned> WavesPerEU) const; 1130 /// \returns Maximum number of VGPRs that meets number of waves per execution 1131 /// unit requirement for function \p F, or number of VGPRs explicitly 1132 /// requested using "amdgpu-num-vgpr" attribute attached to function \p F. 1133 /// 1134 /// \returns Value that meets number of waves per execution unit requirement 1135 /// if explicitly requested value cannot be converted to integer, violates 1136 /// subtarget's specifications, or does not meet number of waves per execution 1137 /// unit requirement. 1138 unsigned getMaxNumVGPRs(const Function &F) const; 1139 1140 unsigned getMaxNumAGPRs(const Function &F) const { 1141 return getMaxNumVGPRs(F); 1142 } 1143 1144 /// \returns Maximum number of VGPRs that meets number of waves per execution 1145 /// unit requirement for function \p MF, or number of VGPRs explicitly 1146 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF. 1147 /// 1148 /// \returns Value that meets number of waves per execution unit requirement 1149 /// if explicitly requested value cannot be converted to integer, violates 1150 /// subtarget's specifications, or does not meet number of waves per execution 1151 /// unit requirement. 1152 unsigned getMaxNumVGPRs(const MachineFunction &MF) const; 1153 1154 void getPostRAMutations( 1155 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) 1156 const override; 1157 1158 std::unique_ptr<ScheduleDAGMutation> 1159 createFillMFMAShadowMutation(const TargetInstrInfo *TII) const; 1160 1161 bool isWave32() const { 1162 return getWavefrontSize() == 32; 1163 } 1164 1165 bool isWave64() const { 1166 return getWavefrontSize() == 64; 1167 } 1168 1169 const TargetRegisterClass *getBoolRC() const { 1170 return getRegisterInfo()->getBoolRC(); 1171 } 1172 1173 /// \returns Maximum number of work groups per compute unit supported by the 1174 /// subtarget and limited by given \p FlatWorkGroupSize. 1175 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const override { 1176 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(this, FlatWorkGroupSize); 1177 } 1178 1179 /// \returns Minimum flat work group size supported by the subtarget. 1180 unsigned getMinFlatWorkGroupSize() const override { 1181 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(this); 1182 } 1183 1184 /// \returns Maximum flat work group size supported by the subtarget. 1185 unsigned getMaxFlatWorkGroupSize() const override { 1186 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(this); 1187 } 1188 1189 /// \returns Number of waves per execution unit required to support the given 1190 /// \p FlatWorkGroupSize. 1191 unsigned 1192 getWavesPerEUForWorkGroup(unsigned FlatWorkGroupSize) const override { 1193 return AMDGPU::IsaInfo::getWavesPerEUForWorkGroup(this, FlatWorkGroupSize); 1194 } 1195 1196 /// \returns Minimum number of waves per execution unit supported by the 1197 /// subtarget. 1198 unsigned getMinWavesPerEU() const override { 1199 return AMDGPU::IsaInfo::getMinWavesPerEU(this); 1200 } 1201 1202 void adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use, int UseOpIdx, 1203 SDep &Dep) const override; 1204 }; 1205 1206 } // end namespace llvm 1207 1208 #endif // LLVM_LIB_TARGET_AMDGPU_GCNSUBTARGET_H 1209