1 //=====-- AMDGPUSubtarget.h - Define Subtarget for AMDGPU ------*- C++ -*-====//
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
7 //==-----------------------------------------------------------------------===//
10 /// AMDGPU specific subclass of TargetSubtarget.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H
15 #define LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H
18 #include "AMDGPUCallLowering.h"
19 #include "R600FrameLowering.h"
20 #include "R600ISelLowering.h"
21 #include "R600InstrInfo.h"
22 #include "SIFrameLowering.h"
23 #include "SIISelLowering.h"
24 #include "SIInstrInfo.h"
25 #include "Utils/AMDGPUBaseInfo.h"
26 #include "llvm/ADT/Triple.h"
27 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
28 #include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
29 #include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h"
30 #include "llvm/CodeGen/MachineFunction.h"
31 #include "llvm/CodeGen/SelectionDAGTargetInfo.h"
32 #include "llvm/MC/MCInstrItineraries.h"
33 #include "llvm/Support/MathExtras.h"
39 #define GET_SUBTARGETINFO_HEADER
40 #include "AMDGPUGenSubtargetInfo.inc"
41 #define GET_SUBTARGETINFO_HEADER
42 #include "R600GenSubtargetInfo.inc"
48 class AMDGPUSubtarget
{
74 bool HasInv2PiInlineImm
;
75 bool HasFminFmaxLegacy
;
76 bool EnablePromoteAlloca
;
77 bool HasTrigReducedRange
;
78 unsigned MaxWavesPerEU
;
80 unsigned WavefrontSize
;
83 AMDGPUSubtarget(const Triple
&TT
);
85 static const AMDGPUSubtarget
&get(const MachineFunction
&MF
);
86 static const AMDGPUSubtarget
&get(const TargetMachine
&TM
,
89 /// \returns Default range flat work group size for a calling convention.
90 std::pair
<unsigned, unsigned> getDefaultFlatWorkGroupSize(CallingConv::ID CC
) const;
92 /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
93 /// for function \p F, or minimum/maximum flat work group sizes explicitly
94 /// requested using "amdgpu-flat-work-group-size" attribute attached to
97 /// \returns Subtarget's default values if explicitly requested values cannot
98 /// be converted to integer, or violate subtarget's specifications.
99 std::pair
<unsigned, unsigned> getFlatWorkGroupSizes(const Function
&F
) const;
101 /// \returns Subtarget's default pair of minimum/maximum number of waves per
102 /// execution unit for function \p F, or minimum/maximum number of waves per
103 /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
104 /// attached to function \p F.
106 /// \returns Subtarget's default values if explicitly requested values cannot
107 /// be converted to integer, violate subtarget's specifications, or are not
108 /// compatible with minimum/maximum number of waves limited by flat work group
109 /// size, register usage, and/or lds usage.
110 std::pair
<unsigned, unsigned> getWavesPerEU(const Function
&F
) const;
112 /// Return the amount of LDS that can be used that will not restrict the
113 /// occupancy lower than WaveCount.
114 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount
,
115 const Function
&) const;
117 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
118 /// the given LDS memory size is the only constraint.
119 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes
, const Function
&) const;
121 unsigned getOccupancyWithLocalMemSize(const MachineFunction
&MF
) const;
123 bool isAmdHsaOS() const {
124 return TargetTriple
.getOS() == Triple::AMDHSA
;
127 bool isAmdPalOS() const {
128 return TargetTriple
.getOS() == Triple::AMDPAL
;
131 bool isMesa3DOS() const {
132 return TargetTriple
.getOS() == Triple::Mesa3D
;
135 bool isMesaKernel(const Function
&F
) const {
136 return isMesa3DOS() && !AMDGPU::isShader(F
.getCallingConv());
139 bool isAmdHsaOrMesa(const Function
&F
) const {
140 return isAmdHsaOS() || isMesaKernel(F
);
143 bool has16BitInsts() const {
144 return Has16BitInsts
;
147 bool hasMadMixInsts() const {
148 return HasMadMixInsts
;
151 bool hasFP32Denormals() const {
152 return FP32Denormals
;
155 bool hasFPExceptions() const {
159 bool hasSDWA() const {
163 bool hasVOP3PInsts() const {
164 return HasVOP3PInsts
;
167 bool hasMulI24() const {
171 bool hasMulU24() const {
175 bool hasInv2PiInlineImm() const {
176 return HasInv2PiInlineImm
;
179 bool hasFminFmaxLegacy() const {
180 return HasFminFmaxLegacy
;
183 bool hasTrigReducedRange() const {
184 return HasTrigReducedRange
;
187 bool isPromoteAllocaEnabled() const {
188 return EnablePromoteAlloca
;
191 unsigned getWavefrontSize() const {
192 return WavefrontSize
;
195 int getLocalMemorySize() const {
196 return LocalMemorySize
;
199 unsigned getAlignmentForImplicitArgPtr() const {
200 return isAmdHsaOS() ? 8 : 4;
203 /// Returns the offset in bytes from the start of the input buffer
204 /// of the first explicit kernel argument.
205 unsigned getExplicitKernelArgOffset(const Function
&F
) const {
206 return isAmdHsaOrMesa(F
) ? 0 : 36;
209 /// \returns Maximum number of work groups per compute unit supported by the
210 /// subtarget and limited by given \p FlatWorkGroupSize.
211 virtual unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize
) const = 0;
213 /// \returns Minimum flat work group size supported by the subtarget.
214 virtual unsigned getMinFlatWorkGroupSize() const = 0;
216 /// \returns Maximum flat work group size supported by the subtarget.
217 virtual unsigned getMaxFlatWorkGroupSize() const = 0;
219 /// \returns Maximum number of waves per execution unit supported by the
220 /// subtarget and limited by given \p FlatWorkGroupSize.
221 virtual unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize
) const = 0;
223 /// \returns Minimum number of waves per execution unit supported by the
225 virtual unsigned getMinWavesPerEU() const = 0;
227 /// \returns Maximum number of waves per execution unit supported by the
228 /// subtarget without any kind of limitation.
229 unsigned getMaxWavesPerEU() const { return MaxWavesPerEU
; }
231 /// Creates value range metadata on an workitemid.* inrinsic call or load.
232 bool makeLIDRangeMetadata(Instruction
*I
) const;
234 /// \returns Number of bytes of arguments that are passed to a shader or
235 /// kernel in addition to the explicit ones declared for the function.
236 unsigned getImplicitArgNumBytes(const Function
&F
) const {
239 return AMDGPU::getIntegerAttribute(F
, "amdgpu-implicitarg-num-bytes", 0);
241 uint64_t getExplicitKernArgSize(const Function
&F
,
242 unsigned &MaxAlign
) const;
243 unsigned getKernArgSegmentSize(const Function
&F
,
244 unsigned &MaxAlign
) const;
246 virtual ~AMDGPUSubtarget() {}
249 class GCNSubtarget
: public AMDGPUGenSubtargetInfo
,
250 public AMDGPUSubtarget
{
252 using AMDGPUSubtarget::getMaxWavesPerEU
;
255 enum TrapHandlerAbi
{
256 TrapHandlerAbiNone
= 0,
257 TrapHandlerAbiHsa
= 1
261 TrapIDHardwareReserved
= 0,
262 TrapIDHSADebugTrap
= 1,
264 TrapIDLLVMDebugTrap
= 3,
265 TrapIDDebugBreakpoint
= 7,
266 TrapIDDebugReserved8
= 8,
267 TrapIDDebugReservedFE
= 0xfe,
268 TrapIDDebugReservedFF
= 0xff
272 LLVMTrapHandlerRegValue
= 1
276 /// GlobalISel related APIs.
277 std::unique_ptr
<AMDGPUCallLowering
> CallLoweringInfo
;
278 std::unique_ptr
<InstructionSelector
> InstSelector
;
279 std::unique_ptr
<LegalizerInfo
> Legalizer
;
280 std::unique_ptr
<RegisterBankInfo
> RegBankInfo
;
283 // Basic subtarget description.
286 InstrItineraryData InstrItins
;
288 unsigned MaxPrivateElementSize
;
290 // Possibly statically set by tablegen, but may want to be overridden.
294 // Dynamially set bits that enable features.
295 bool FP64FP16Denormals
;
297 bool AutoWaitcntBeforeBarrier
;
299 bool UnalignedScratchAccess
;
300 bool UnalignedBufferAccess
;
301 bool HasApertureRegs
;
303 bool DoesNotSupportXNACK
;
308 bool EnableLoadStoreOpt
;
309 bool EnableUnsafeDSOffsetFolding
;
310 bool EnableSIScheduler
;
312 bool EnablePRTStrictNull
;
315 // Subtarget statically properties set by tablegen
325 bool GFX7GFX8GFX9Insts
;
327 bool HasSMemRealTime
;
331 bool HasVGPRIndexMode
;
332 bool HasScalarStores
;
333 bool HasScalarAtomics
;
338 bool HasSDWAOutModsVOPC
;
351 bool HasPkFmacF16Inst
;
352 bool HasAtomicFaddInsts
;
354 bool DoesNotSupportSRAMECC
;
357 bool HasRegisterBanking
;
359 bool HasNoDataDepHazard
;
360 bool FlatAddressSpace
;
361 bool FlatInstOffsets
;
362 bool FlatGlobalInsts
;
363 bool FlatScratchInsts
;
364 bool ScalarFlatScratchInsts
;
365 bool AddNoCarryInsts
;
366 bool HasUnpackedD16VMem
;
370 bool LDSMisalignedBug
;
371 bool HasMFMAInlineLiteralBug
;
373 short TexVTXClauseSize
;
374 bool ScalarizeGlobal
;
376 bool HasVcmpxPermlaneHazard
;
377 bool HasVMEMtoScalarWriteHazard
;
378 bool HasSMEMtoVectorWriteHazard
;
379 bool HasInstFwdPrefetchBug
;
380 bool HasVcmpxExecWARHazard
;
381 bool HasLdsBranchVmemWARHazard
;
382 bool HasNSAtoVMEMBug
;
384 bool HasFlatSegmentOffsetBug
;
386 // Dummy feature to use for assembler in tablegen.
389 SelectionDAGTargetInfo TSInfo
;
391 SIInstrInfo InstrInfo
;
392 SITargetLowering TLInfo
;
393 SIFrameLowering FrameLowering
;
395 // See COMPUTE_TMPRING_SIZE.WAVESIZE, 13-bit field in units of 256-dword.
396 static const unsigned MaxWaveScratchSize
= (256 * 4) * ((1 << 13) - 1);
399 GCNSubtarget(const Triple
&TT
, StringRef GPU
, StringRef FS
,
400 const GCNTargetMachine
&TM
);
401 ~GCNSubtarget() override
;
403 GCNSubtarget
&initializeSubtargetDependencies(const Triple
&TT
,
404 StringRef GPU
, StringRef FS
);
406 const SIInstrInfo
*getInstrInfo() const override
{
410 const SIFrameLowering
*getFrameLowering() const override
{
411 return &FrameLowering
;
414 const SITargetLowering
*getTargetLowering() const override
{
418 const SIRegisterInfo
*getRegisterInfo() const override
{
419 return &InstrInfo
.getRegisterInfo();
422 const CallLowering
*getCallLowering() const override
{
423 return CallLoweringInfo
.get();
426 InstructionSelector
*getInstructionSelector() const override
{
427 return InstSelector
.get();
430 const LegalizerInfo
*getLegalizerInfo() const override
{
431 return Legalizer
.get();
434 const RegisterBankInfo
*getRegBankInfo() const override
{
435 return RegBankInfo
.get();
438 // Nothing implemented, just prevent crashes on use.
439 const SelectionDAGTargetInfo
*getSelectionDAGInfo() const override
{
443 const InstrItineraryData
*getInstrItineraryData() const override
{
447 void ParseSubtargetFeatures(StringRef CPU
, StringRef FS
);
449 Generation
getGeneration() const {
450 return (Generation
)Gen
;
453 unsigned getWavefrontSizeLog2() const {
454 return Log2_32(WavefrontSize
);
457 /// Return the number of high bits known to be zero fror a frame index.
458 unsigned getKnownHighZeroBitsForFrameIndex() const {
459 return countLeadingZeros(MaxWaveScratchSize
) + getWavefrontSizeLog2();
462 int getLDSBankCount() const {
466 unsigned getMaxPrivateElementSize() const {
467 return MaxPrivateElementSize
;
470 unsigned getConstantBusLimit(unsigned Opcode
) const;
472 bool hasIntClamp() const {
476 bool hasFP64() const {
480 bool hasMIMG_R128() const {
484 bool hasHWFP64() const {
488 bool hasFastFMAF32() const {
492 bool hasHalfRate64Ops() const {
493 return HalfRate64Ops
;
496 bool hasAddr64() const {
497 return (getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS
);
500 // Return true if the target only has the reverse operand versions of VALU
501 // shift instructions (e.g. v_lshrrev_b32, and no v_lshr_b32).
502 bool hasOnlyRevVALUShifts() const {
503 return getGeneration() >= VOLCANIC_ISLANDS
;
506 bool hasBFE() const {
510 bool hasBFI() const {
514 bool hasBFM() const {
518 bool hasBCNT(unsigned Size
) const {
522 bool hasFFBL() const {
526 bool hasFFBH() const {
530 bool hasMed3_16() const {
531 return getGeneration() >= AMDGPUSubtarget::GFX9
;
534 bool hasMin3Max3_16() const {
535 return getGeneration() >= AMDGPUSubtarget::GFX9
;
538 bool hasFmaMixInsts() const {
539 return HasFmaMixInsts
;
542 bool hasCARRY() const {
546 bool hasFMA() const {
550 bool hasSwap() const {
554 TrapHandlerAbi
getTrapHandlerAbi() const {
555 return isAmdHsaOS() ? TrapHandlerAbiHsa
: TrapHandlerAbiNone
;
558 /// True if the offset field of DS instructions works as expected. On SI, the
559 /// offset uses a 16-bit adder and does not always wrap properly.
560 bool hasUsableDSOffset() const {
561 return getGeneration() >= SEA_ISLANDS
;
564 bool unsafeDSOffsetFoldingEnabled() const {
565 return EnableUnsafeDSOffsetFolding
;
568 /// Condition output from div_scale is usable.
569 bool hasUsableDivScaleConditionOutput() const {
570 return getGeneration() != SOUTHERN_ISLANDS
;
573 /// Extra wait hazard is needed in some cases before
574 /// s_cbranch_vccnz/s_cbranch_vccz.
575 bool hasReadVCCZBug() const {
576 return getGeneration() <= SEA_ISLANDS
;
579 /// A read of an SGPR by SMRD instruction requires 4 wait states when the SGPR
580 /// was written by a VALU instruction.
581 bool hasSMRDReadVALUDefHazard() const {
582 return getGeneration() == SOUTHERN_ISLANDS
;
585 /// A read of an SGPR by a VMEM instruction requires 5 wait states when the
586 /// SGPR was written by a VALU Instruction.
587 bool hasVMEMReadSGPRVALUDefHazard() const {
588 return getGeneration() >= VOLCANIC_ISLANDS
;
591 bool hasRFEHazards() const {
592 return getGeneration() >= VOLCANIC_ISLANDS
;
595 /// Number of hazard wait states for s_setreg_b32/s_setreg_imm32_b32.
596 unsigned getSetRegWaitStates() const {
597 return getGeneration() <= SEA_ISLANDS
? 1 : 2;
600 bool dumpCode() const {
604 /// Return the amount of LDS that can be used that will not restrict the
605 /// occupancy lower than WaveCount.
606 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount
,
607 const Function
&) const;
609 bool hasFP16Denormals() const {
610 return FP64FP16Denormals
;
613 bool hasFP64Denormals() const {
614 return FP64FP16Denormals
;
617 bool supportsMinMaxDenormModes() const {
618 return getGeneration() >= AMDGPUSubtarget::GFX9
;
621 /// \returns If target supports S_DENORM_MODE.
622 bool hasDenormModeInst() const {
623 return getGeneration() >= AMDGPUSubtarget::GFX10
;
626 bool useFlatForGlobal() const {
627 return FlatForGlobal
;
630 /// \returns If target supports ds_read/write_b128 and user enables generation
631 /// of ds_read/write_b128.
632 bool useDS128() const {
633 return CIInsts
&& EnableDS128
;
636 /// Have v_trunc_f64, v_ceil_f64, v_rndne_f64
637 bool haveRoundOpsF64() const {
641 /// \returns If MUBUF instructions always perform range checking, even for
642 /// buffer resources used for private memory access.
643 bool privateMemoryResourceIsRangeChecked() const {
644 return getGeneration() < AMDGPUSubtarget::GFX9
;
647 /// \returns If target requires PRT Struct NULL support (zero result registers
648 /// for sparse texture support).
649 bool usePRTStrictNull() const {
650 return EnablePRTStrictNull
;
653 bool hasAutoWaitcntBeforeBarrier() const {
654 return AutoWaitcntBeforeBarrier
;
657 bool hasCodeObjectV3() const {
658 // FIXME: Need to add code object v3 support for mesa and pal.
659 return isAmdHsaOS() ? CodeObjectV3
: false;
662 bool hasUnalignedBufferAccess() const {
663 return UnalignedBufferAccess
;
666 bool hasUnalignedScratchAccess() const {
667 return UnalignedScratchAccess
;
670 bool hasApertureRegs() const {
671 return HasApertureRegs
;
674 bool isTrapHandlerEnabled() const {
678 bool isXNACKEnabled() const {
682 bool isCuModeEnabled() const {
686 bool hasFlatAddressSpace() const {
687 return FlatAddressSpace
;
690 bool hasFlatScrRegister() const {
691 return hasFlatAddressSpace();
694 bool hasFlatInstOffsets() const {
695 return FlatInstOffsets
;
698 bool hasFlatGlobalInsts() const {
699 return FlatGlobalInsts
;
702 bool hasFlatScratchInsts() const {
703 return FlatScratchInsts
;
706 bool hasScalarFlatScratchInsts() const {
707 return ScalarFlatScratchInsts
;
710 bool hasFlatSegmentOffsetBug() const {
711 return HasFlatSegmentOffsetBug
;
714 bool hasFlatLgkmVMemCountInOrder() const {
715 return getGeneration() > GFX9
;
718 bool hasD16LoadStore() const {
719 return getGeneration() >= GFX9
;
722 bool d16PreservesUnusedBits() const {
723 return hasD16LoadStore() && !isSRAMECCEnabled();
726 bool hasD16Images() const {
727 return getGeneration() >= VOLCANIC_ISLANDS
;
730 /// Return if most LDS instructions have an m0 use that require m0 to be
732 bool ldsRequiresM0Init() const {
733 return getGeneration() < GFX9
;
736 // True if the hardware rewinds and replays GWS operations if a wave is
739 // If this is false, a GWS operation requires testing if a nack set the
740 // MEM_VIOL bit, and repeating if so.
741 bool hasGWSAutoReplay() const {
742 return getGeneration() >= GFX9
;
745 /// \returns if target has ds_gws_sema_release_all instruction.
746 bool hasGWSSemaReleaseAll() const {
750 bool hasAddNoCarry() const {
751 return AddNoCarryInsts
;
754 bool hasUnpackedD16VMem() const {
755 return HasUnpackedD16VMem
;
758 // Covers VS/PS/CS graphics shaders
759 bool isMesaGfxShader(const Function
&F
) const {
760 return isMesa3DOS() && AMDGPU::isShader(F
.getCallingConv());
763 bool hasMad64_32() const {
764 return getGeneration() >= SEA_ISLANDS
;
767 bool hasSDWAOmod() const {
771 bool hasSDWAScalar() const {
772 return HasSDWAScalar
;
775 bool hasSDWASdst() const {
779 bool hasSDWAMac() const {
783 bool hasSDWAOutModsVOPC() const {
784 return HasSDWAOutModsVOPC
;
787 bool hasDLInsts() const {
791 bool hasDot1Insts() const {
795 bool hasDot2Insts() const {
799 bool hasDot3Insts() const {
803 bool hasDot4Insts() const {
807 bool hasDot5Insts() const {
811 bool hasDot6Insts() const {
815 bool hasMAIInsts() const {
819 bool hasPkFmacF16Inst() const {
820 return HasPkFmacF16Inst
;
823 bool hasAtomicFaddInsts() const {
824 return HasAtomicFaddInsts
;
827 bool isSRAMECCEnabled() const {
828 return EnableSRAMECC
;
831 bool hasNoSdstCMPX() const {
832 return HasNoSdstCMPX
;
835 bool hasVscnt() const {
839 bool hasRegisterBanking() const {
840 return HasRegisterBanking
;
843 bool hasVOP3Literal() const {
844 return HasVOP3Literal
;
847 bool hasNoDataDepHazard() const {
848 return HasNoDataDepHazard
;
851 bool vmemWriteNeedsExpWaitcnt() const {
852 return getGeneration() < SEA_ISLANDS
;
855 // Scratch is allocated in 256 dword per wave blocks for the entire
856 // wavefront. When viewed from the perspecive of an arbitrary workitem, this
857 // is 4-byte aligned.
859 // Only 4-byte alignment is really needed to access anything. Transformations
860 // on the pointer value itself may rely on the alignment / known low bits of
861 // the pointer. Set this to something above the minimum to avoid needing
862 // dynamic realignment in common cases.
863 unsigned getStackAlignment() const {
867 bool enableMachineScheduler() const override
{
871 bool enableSubRegLiveness() const override
{
875 void setScalarizeGlobalBehavior(bool b
) { ScalarizeGlobal
= b
; }
876 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal
; }
878 /// \returns Number of execution units per compute unit supported by the
880 unsigned getEUsPerCU() const {
881 return AMDGPU::IsaInfo::getEUsPerCU(this);
884 /// \returns Maximum number of waves per compute unit supported by the
885 /// subtarget without any kind of limitation.
886 unsigned getMaxWavesPerCU() const {
887 return AMDGPU::IsaInfo::getMaxWavesPerCU(this);
890 /// \returns Maximum number of waves per compute unit supported by the
891 /// subtarget and limited by given \p FlatWorkGroupSize.
892 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize
) const {
893 return AMDGPU::IsaInfo::getMaxWavesPerCU(this, FlatWorkGroupSize
);
896 /// \returns Number of waves per work group supported by the subtarget and
897 /// limited by given \p FlatWorkGroupSize.
898 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize
) const {
899 return AMDGPU::IsaInfo::getWavesPerWorkGroup(this, FlatWorkGroupSize
);
903 static bool hasHalfRate64Ops(const TargetSubtargetInfo
&STI
);
905 // XXX - Why is this here if it isn't in the default pass set?
906 bool enableEarlyIfConversion() const override
{
910 void overrideSchedPolicy(MachineSchedPolicy
&Policy
,
911 unsigned NumRegionInstrs
) const override
;
913 unsigned getMaxNumUserSGPRs() const {
917 bool hasSMemRealTime() const {
918 return HasSMemRealTime
;
921 bool hasMovrel() const {
925 bool hasVGPRIndexMode() const {
926 return HasVGPRIndexMode
;
929 bool useVGPRIndexMode(bool UserEnable
) const {
930 return !hasMovrel() || (UserEnable
&& hasVGPRIndexMode());
933 bool hasScalarCompareEq64() const {
934 return getGeneration() >= VOLCANIC_ISLANDS
;
937 bool hasScalarStores() const {
938 return HasScalarStores
;
941 bool hasScalarAtomics() const {
942 return HasScalarAtomics
;
945 bool hasLDSFPAtomics() const {
949 bool hasDPP() const {
953 bool hasDPPBroadcasts() const {
954 return HasDPP
&& getGeneration() < GFX10
;
957 bool hasDPPWavefrontShifts() const {
958 return HasDPP
&& getGeneration() < GFX10
;
961 bool hasDPP8() const {
965 bool hasR128A16() const {
969 bool hasOffset3fBug() const {
970 return HasOffset3fBug
;
973 bool hasNSAEncoding() const {
974 return HasNSAEncoding
;
977 bool hasMadF16() const;
979 bool enableSIScheduler() const {
980 return EnableSIScheduler
;
983 bool loadStoreOptEnabled() const {
984 return EnableLoadStoreOpt
;
987 bool hasSGPRInitBug() const {
991 bool hasMFMAInlineLiteralBug() const {
992 return HasMFMAInlineLiteralBug
;
995 bool has12DWordStoreHazard() const {
996 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS
;
999 // \returns true if the subtarget supports DWORDX3 load/store instructions.
1000 bool hasDwordx3LoadStores() const {
1004 bool hasSMovFedHazard() const {
1005 return getGeneration() == AMDGPUSubtarget::GFX9
;
1008 bool hasReadM0MovRelInterpHazard() const {
1009 return getGeneration() == AMDGPUSubtarget::GFX9
;
1012 bool hasReadM0SendMsgHazard() const {
1013 return getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS
&&
1014 getGeneration() <= AMDGPUSubtarget::GFX9
;
1017 bool hasVcmpxPermlaneHazard() const {
1018 return HasVcmpxPermlaneHazard
;
1021 bool hasVMEMtoScalarWriteHazard() const {
1022 return HasVMEMtoScalarWriteHazard
;
1025 bool hasSMEMtoVectorWriteHazard() const {
1026 return HasSMEMtoVectorWriteHazard
;
1029 bool hasLDSMisalignedBug() const {
1030 return LDSMisalignedBug
&& !EnableCuMode
;
1033 bool hasInstFwdPrefetchBug() const {
1034 return HasInstFwdPrefetchBug
;
1037 bool hasVcmpxExecWARHazard() const {
1038 return HasVcmpxExecWARHazard
;
1041 bool hasLdsBranchVmemWARHazard() const {
1042 return HasLdsBranchVmemWARHazard
;
1045 bool hasNSAtoVMEMBug() const {
1046 return HasNSAtoVMEMBug
;
1049 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs
1051 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs
) const;
1053 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs
1055 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs
) const;
1057 /// Return occupancy for the given function. Used LDS and a number of
1058 /// registers if provided.
1059 /// Note, occupancy can be affected by the scratch allocation as well, but
1060 /// we do not have enough information to compute it.
1061 unsigned computeOccupancy(const MachineFunction
&MF
, unsigned LDSSize
= 0,
1062 unsigned NumSGPRs
= 0, unsigned NumVGPRs
= 0) const;
1064 /// \returns true if the flat_scratch register should be initialized with the
1065 /// pointer to the wave's scratch memory rather than a size and offset.
1066 bool flatScratchIsPointer() const {
1067 return getGeneration() >= AMDGPUSubtarget::GFX9
;
1070 /// \returns true if the machine has merged shaders in which s0-s7 are
1071 /// reserved by the hardware and user SGPRs start at s8
1072 bool hasMergedShaders() const {
1073 return getGeneration() >= GFX9
;
1076 /// \returns SGPR allocation granularity supported by the subtarget.
1077 unsigned getSGPRAllocGranule() const {
1078 return AMDGPU::IsaInfo::getSGPRAllocGranule(this);
1081 /// \returns SGPR encoding granularity supported by the subtarget.
1082 unsigned getSGPREncodingGranule() const {
1083 return AMDGPU::IsaInfo::getSGPREncodingGranule(this);
1086 /// \returns Total number of SGPRs supported by the subtarget.
1087 unsigned getTotalNumSGPRs() const {
1088 return AMDGPU::IsaInfo::getTotalNumSGPRs(this);
1091 /// \returns Addressable number of SGPRs supported by the subtarget.
1092 unsigned getAddressableNumSGPRs() const {
1093 return AMDGPU::IsaInfo::getAddressableNumSGPRs(this);
1096 /// \returns Minimum number of SGPRs that meets the given number of waves per
1097 /// execution unit requirement supported by the subtarget.
1098 unsigned getMinNumSGPRs(unsigned WavesPerEU
) const {
1099 return AMDGPU::IsaInfo::getMinNumSGPRs(this, WavesPerEU
);
1102 /// \returns Maximum number of SGPRs that meets the given number of waves per
1103 /// execution unit requirement supported by the subtarget.
1104 unsigned getMaxNumSGPRs(unsigned WavesPerEU
, bool Addressable
) const {
1105 return AMDGPU::IsaInfo::getMaxNumSGPRs(this, WavesPerEU
, Addressable
);
1108 /// \returns Reserved number of SGPRs for given function \p MF.
1109 unsigned getReservedNumSGPRs(const MachineFunction
&MF
) const;
1111 /// \returns Maximum number of SGPRs that meets number of waves per execution
1112 /// unit requirement for function \p MF, or number of SGPRs explicitly
1113 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
1115 /// \returns Value that meets number of waves per execution unit requirement
1116 /// if explicitly requested value cannot be converted to integer, violates
1117 /// subtarget's specifications, or does not meet number of waves per execution
1118 /// unit requirement.
1119 unsigned getMaxNumSGPRs(const MachineFunction
&MF
) const;
1121 /// \returns VGPR allocation granularity supported by the subtarget.
1122 unsigned getVGPRAllocGranule() const {
1123 return AMDGPU::IsaInfo::getVGPRAllocGranule(this);
1126 /// \returns VGPR encoding granularity supported by the subtarget.
1127 unsigned getVGPREncodingGranule() const {
1128 return AMDGPU::IsaInfo::getVGPREncodingGranule(this);
1131 /// \returns Total number of VGPRs supported by the subtarget.
1132 unsigned getTotalNumVGPRs() const {
1133 return AMDGPU::IsaInfo::getTotalNumVGPRs(this);
1136 /// \returns Addressable number of VGPRs supported by the subtarget.
1137 unsigned getAddressableNumVGPRs() const {
1138 return AMDGPU::IsaInfo::getAddressableNumVGPRs(this);
1141 /// \returns Minimum number of VGPRs that meets given number of waves per
1142 /// execution unit requirement supported by the subtarget.
1143 unsigned getMinNumVGPRs(unsigned WavesPerEU
) const {
1144 return AMDGPU::IsaInfo::getMinNumVGPRs(this, WavesPerEU
);
1147 /// \returns Maximum number of VGPRs that meets given number of waves per
1148 /// execution unit requirement supported by the subtarget.
1149 unsigned getMaxNumVGPRs(unsigned WavesPerEU
) const {
1150 return AMDGPU::IsaInfo::getMaxNumVGPRs(this, WavesPerEU
);
1153 /// \returns Maximum number of VGPRs that meets number of waves per execution
1154 /// unit requirement for function \p MF, or number of VGPRs explicitly
1155 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
1157 /// \returns Value that meets number of waves per execution unit requirement
1158 /// if explicitly requested value cannot be converted to integer, violates
1159 /// subtarget's specifications, or does not meet number of waves per execution
1160 /// unit requirement.
1161 unsigned getMaxNumVGPRs(const MachineFunction
&MF
) const;
1163 void getPostRAMutations(
1164 std::vector
<std::unique_ptr
<ScheduleDAGMutation
>> &Mutations
)
1167 bool isWave32() const {
1168 return WavefrontSize
== 32;
1171 const TargetRegisterClass
*getBoolRC() const {
1172 return getRegisterInfo()->getBoolRC();
1175 /// \returns Maximum number of work groups per compute unit supported by the
1176 /// subtarget and limited by given \p FlatWorkGroupSize.
1177 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize
) const override
{
1178 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(this, FlatWorkGroupSize
);
1181 /// \returns Minimum flat work group size supported by the subtarget.
1182 unsigned getMinFlatWorkGroupSize() const override
{
1183 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(this);
1186 /// \returns Maximum flat work group size supported by the subtarget.
1187 unsigned getMaxFlatWorkGroupSize() const override
{
1188 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(this);
1191 /// \returns Maximum number of waves per execution unit supported by the
1192 /// subtarget and limited by given \p FlatWorkGroupSize.
1193 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize
) const override
{
1194 return AMDGPU::IsaInfo::getMaxWavesPerEU(this, FlatWorkGroupSize
);
1197 /// \returns Minimum number of waves per execution unit supported by the
1199 unsigned getMinWavesPerEU() const override
{
1200 return AMDGPU::IsaInfo::getMinWavesPerEU(this);
1204 class R600Subtarget final
: public R600GenSubtargetInfo
,
1205 public AMDGPUSubtarget
{
1207 R600InstrInfo InstrInfo
;
1208 R600FrameLowering FrameLowering
;
1212 bool HasVertexCache
;
1215 short TexVTXClauseSize
;
1217 R600TargetLowering TLInfo
;
1218 InstrItineraryData InstrItins
;
1219 SelectionDAGTargetInfo TSInfo
;
1222 R600Subtarget(const Triple
&TT
, StringRef CPU
, StringRef FS
,
1223 const TargetMachine
&TM
);
1225 const R600InstrInfo
*getInstrInfo() const override
{ return &InstrInfo
; }
1227 const R600FrameLowering
*getFrameLowering() const override
{
1228 return &FrameLowering
;
1231 const R600TargetLowering
*getTargetLowering() const override
{
1235 const R600RegisterInfo
*getRegisterInfo() const override
{
1236 return &InstrInfo
.getRegisterInfo();
1239 const InstrItineraryData
*getInstrItineraryData() const override
{
1243 // Nothing implemented, just prevent crashes on use.
1244 const SelectionDAGTargetInfo
*getSelectionDAGInfo() const override
{
1248 void ParseSubtargetFeatures(StringRef CPU
, StringRef FS
);
1250 Generation
getGeneration() const {
1254 unsigned getStackAlignment() const {
1258 R600Subtarget
&initializeSubtargetDependencies(const Triple
&TT
,
1259 StringRef GPU
, StringRef FS
);
1261 bool hasBFE() const {
1262 return (getGeneration() >= EVERGREEN
);
1265 bool hasBFI() const {
1266 return (getGeneration() >= EVERGREEN
);
1269 bool hasBCNT(unsigned Size
) const {
1271 return (getGeneration() >= EVERGREEN
);
1276 bool hasBORROW() const {
1277 return (getGeneration() >= EVERGREEN
);
1280 bool hasCARRY() const {
1281 return (getGeneration() >= EVERGREEN
);
1284 bool hasCaymanISA() const {
1288 bool hasFFBL() const {
1289 return (getGeneration() >= EVERGREEN
);
1292 bool hasFFBH() const {
1293 return (getGeneration() >= EVERGREEN
);
1296 bool hasFMA() const { return FMA
; }
1298 bool hasCFAluBug() const { return CFALUBug
; }
1300 bool hasVertexCache() const { return HasVertexCache
; }
1302 short getTexVTXClauseSize() const { return TexVTXClauseSize
; }
1304 bool enableMachineScheduler() const override
{
1308 bool enableSubRegLiveness() const override
{
1312 /// \returns Maximum number of work groups per compute unit supported by the
1313 /// subtarget and limited by given \p FlatWorkGroupSize.
1314 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize
) const override
{
1315 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(this, FlatWorkGroupSize
);
1318 /// \returns Minimum flat work group size supported by the subtarget.
1319 unsigned getMinFlatWorkGroupSize() const override
{
1320 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(this);
1323 /// \returns Maximum flat work group size supported by the subtarget.
1324 unsigned getMaxFlatWorkGroupSize() const override
{
1325 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(this);
1328 /// \returns Maximum number of waves per execution unit supported by the
1329 /// subtarget and limited by given \p FlatWorkGroupSize.
1330 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize
) const override
{
1331 return AMDGPU::IsaInfo::getMaxWavesPerEU(this, FlatWorkGroupSize
);
1334 /// \returns Minimum number of waves per execution unit supported by the
1336 unsigned getMinWavesPerEU() const override
{
1337 return AMDGPU::IsaInfo::getMinWavesPerEU(this);
1341 } // end namespace llvm
1343 #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H