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