[AMDGPU] Check for immediate SrcC in mfma in AsmParser
[llvm-core.git] / lib / Target / AMDGPU / AMDGPUSubtarget.h
blob2da723a1166038a51c15dd338b0ad2bf8fc403e1
1 //=====-- AMDGPUSubtarget.h - Define 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 /// AMDGPU specific subclass of TargetSubtarget.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H
15 #define LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H
17 #include "AMDGPU.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"
34 #include <cassert>
35 #include <cstdint>
36 #include <memory>
37 #include <utility>
39 #define GET_SUBTARGETINFO_HEADER
40 #include "AMDGPUGenSubtargetInfo.inc"
41 #define GET_SUBTARGETINFO_HEADER
42 #include "R600GenSubtargetInfo.inc"
44 namespace llvm {
46 class StringRef;
48 class AMDGPUSubtarget {
49 public:
50 enum Generation {
51 R600 = 0,
52 R700 = 1,
53 EVERGREEN = 2,
54 NORTHERN_ISLANDS = 3,
55 SOUTHERN_ISLANDS = 4,
56 SEA_ISLANDS = 5,
57 VOLCANIC_ISLANDS = 6,
58 GFX9 = 7,
59 GFX10 = 8
62 private:
63 Triple TargetTriple;
65 protected:
66 bool Has16BitInsts;
67 bool HasMadMixInsts;
68 bool FP32Denormals;
69 bool FPExceptions;
70 bool HasSDWA;
71 bool HasVOP3PInsts;
72 bool HasMulI24;
73 bool HasMulU24;
74 bool HasInv2PiInlineImm;
75 bool HasFminFmaxLegacy;
76 bool EnablePromoteAlloca;
77 bool HasTrigReducedRange;
78 unsigned MaxWavesPerEU;
79 int LocalMemorySize;
80 unsigned WavefrontSize;
82 public:
83 AMDGPUSubtarget(const Triple &TT);
85 static const AMDGPUSubtarget &get(const MachineFunction &MF);
86 static const AMDGPUSubtarget &get(const TargetMachine &TM,
87 const Function &F);
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
95 /// function \p F.
96 ///
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 {
156 return FPExceptions;
159 bool hasSDWA() const {
160 return HasSDWA;
163 bool hasVOP3PInsts() const {
164 return HasVOP3PInsts;
167 bool hasMulI24() const {
168 return HasMulI24;
171 bool hasMulU24() const {
172 return HasMulU24;
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
224 /// subtarget.
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 {
237 if (isMesaKernel(F))
238 return 16;
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;
254 public:
255 enum TrapHandlerAbi {
256 TrapHandlerAbiNone = 0,
257 TrapHandlerAbiHsa = 1
260 enum TrapID {
261 TrapIDHardwareReserved = 0,
262 TrapIDHSADebugTrap = 1,
263 TrapIDLLVMTrap = 2,
264 TrapIDLLVMDebugTrap = 3,
265 TrapIDDebugBreakpoint = 7,
266 TrapIDDebugReserved8 = 8,
267 TrapIDDebugReservedFE = 0xfe,
268 TrapIDDebugReservedFF = 0xff
271 enum TrapRegValues {
272 LLVMTrapHandlerRegValue = 1
275 private:
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;
282 protected:
283 // Basic subtarget description.
284 Triple TargetTriple;
285 unsigned Gen;
286 InstrItineraryData InstrItins;
287 int LDSBankCount;
288 unsigned MaxPrivateElementSize;
290 // Possibly statically set by tablegen, but may want to be overridden.
291 bool FastFMAF32;
292 bool HalfRate64Ops;
294 // Dynamially set bits that enable features.
295 bool FP64FP16Denormals;
296 bool FlatForGlobal;
297 bool AutoWaitcntBeforeBarrier;
298 bool CodeObjectV3;
299 bool UnalignedScratchAccess;
300 bool UnalignedBufferAccess;
301 bool HasApertureRegs;
302 bool EnableXNACK;
303 bool DoesNotSupportXNACK;
304 bool EnableCuMode;
305 bool TrapHandler;
307 // Used as options.
308 bool EnableLoadStoreOpt;
309 bool EnableUnsafeDSOffsetFolding;
310 bool EnableSIScheduler;
311 bool EnableDS128;
312 bool EnablePRTStrictNull;
313 bool DumpCode;
315 // Subtarget statically properties set by tablegen
316 bool FP64;
317 bool FMA;
318 bool MIMG_R128;
319 bool IsGCN;
320 bool GCN3Encoding;
321 bool CIInsts;
322 bool GFX8Insts;
323 bool GFX9Insts;
324 bool GFX10Insts;
325 bool GFX7GFX8GFX9Insts;
326 bool SGPRInitBug;
327 bool HasSMemRealTime;
328 bool HasIntClamp;
329 bool HasFmaMixInsts;
330 bool HasMovrel;
331 bool HasVGPRIndexMode;
332 bool HasScalarStores;
333 bool HasScalarAtomics;
334 bool HasSDWAOmod;
335 bool HasSDWAScalar;
336 bool HasSDWASdst;
337 bool HasSDWAMac;
338 bool HasSDWAOutModsVOPC;
339 bool HasDPP;
340 bool HasDPP8;
341 bool HasR128A16;
342 bool HasNSAEncoding;
343 bool HasDLInsts;
344 bool HasDot1Insts;
345 bool HasDot2Insts;
346 bool HasDot3Insts;
347 bool HasDot4Insts;
348 bool HasDot5Insts;
349 bool HasDot6Insts;
350 bool HasMAIInsts;
351 bool HasPkFmacF16Inst;
352 bool HasAtomicFaddInsts;
353 bool EnableSRAMECC;
354 bool DoesNotSupportSRAMECC;
355 bool HasNoSdstCMPX;
356 bool HasVscnt;
357 bool HasRegisterBanking;
358 bool HasVOP3Literal;
359 bool HasNoDataDepHazard;
360 bool FlatAddressSpace;
361 bool FlatInstOffsets;
362 bool FlatGlobalInsts;
363 bool FlatScratchInsts;
364 bool ScalarFlatScratchInsts;
365 bool AddNoCarryInsts;
366 bool HasUnpackedD16VMem;
367 bool R600ALUInst;
368 bool CaymanISA;
369 bool CFALUBug;
370 bool LDSMisalignedBug;
371 bool HasMFMAInlineLiteralBug;
372 bool HasVertexCache;
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;
383 bool HasOffset3fBug;
384 bool HasFlatSegmentOffsetBug;
386 // Dummy feature to use for assembler in tablegen.
387 bool FeatureDisable;
389 SelectionDAGTargetInfo TSInfo;
390 private:
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);
398 public:
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 {
407 return &InstrInfo;
410 const SIFrameLowering *getFrameLowering() const override {
411 return &FrameLowering;
414 const SITargetLowering *getTargetLowering() const override {
415 return &TLInfo;
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 {
440 return &TSInfo;
443 const InstrItineraryData *getInstrItineraryData() const override {
444 return &InstrItins;
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 {
463 return LDSBankCount;
466 unsigned getMaxPrivateElementSize() const {
467 return MaxPrivateElementSize;
470 unsigned getConstantBusLimit(unsigned Opcode) const;
472 bool hasIntClamp() const {
473 return HasIntClamp;
476 bool hasFP64() const {
477 return FP64;
480 bool hasMIMG_R128() const {
481 return MIMG_R128;
484 bool hasHWFP64() const {
485 return FP64;
488 bool hasFastFMAF32() const {
489 return FastFMAF32;
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 {
507 return true;
510 bool hasBFI() const {
511 return true;
514 bool hasBFM() const {
515 return hasBFE();
518 bool hasBCNT(unsigned Size) const {
519 return true;
522 bool hasFFBL() const {
523 return true;
526 bool hasFFBH() const {
527 return true;
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 {
543 return true;
546 bool hasFMA() const {
547 return FMA;
550 bool hasSwap() const {
551 return GFX9Insts;
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 {
601 return DumpCode;
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 {
638 return CIInsts;
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 {
675 return TrapHandler;
678 bool isXNACKEnabled() const {
679 return EnableXNACK;
682 bool isCuModeEnabled() const {
683 return EnableCuMode;
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
731 /// iniitalized.
732 bool ldsRequiresM0Init() const {
733 return getGeneration() < GFX9;
736 // True if the hardware rewinds and replays GWS operations if a wave is
737 // preempted.
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 {
747 return CIInsts;
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 {
768 return HasSDWAOmod;
771 bool hasSDWAScalar() const {
772 return HasSDWAScalar;
775 bool hasSDWASdst() const {
776 return HasSDWASdst;
779 bool hasSDWAMac() const {
780 return HasSDWAMac;
783 bool hasSDWAOutModsVOPC() const {
784 return HasSDWAOutModsVOPC;
787 bool hasDLInsts() const {
788 return HasDLInsts;
791 bool hasDot1Insts() const {
792 return HasDot1Insts;
795 bool hasDot2Insts() const {
796 return HasDot2Insts;
799 bool hasDot3Insts() const {
800 return HasDot3Insts;
803 bool hasDot4Insts() const {
804 return HasDot4Insts;
807 bool hasDot5Insts() const {
808 return HasDot5Insts;
811 bool hasDot6Insts() const {
812 return HasDot6Insts;
815 bool hasMAIInsts() const {
816 return HasMAIInsts;
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 {
836 return HasVscnt;
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 {
864 return 16;
867 bool enableMachineScheduler() const override {
868 return true;
871 bool enableSubRegLiveness() const override {
872 return true;
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
879 /// subtarget.
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);
902 // static wrappers
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 {
907 return true;
910 void overrideSchedPolicy(MachineSchedPolicy &Policy,
911 unsigned NumRegionInstrs) const override;
913 unsigned getMaxNumUserSGPRs() const {
914 return 16;
917 bool hasSMemRealTime() const {
918 return HasSMemRealTime;
921 bool hasMovrel() const {
922 return HasMovrel;
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 {
946 return GFX8Insts;
949 bool hasDPP() const {
950 return HasDPP;
953 bool hasDPPBroadcasts() const {
954 return HasDPP && getGeneration() < GFX10;
957 bool hasDPPWavefrontShifts() const {
958 return HasDPP && getGeneration() < GFX10;
961 bool hasDPP8() const {
962 return HasDPP8;
965 bool hasR128A16() const {
966 return HasR128A16;
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 {
988 return SGPRInitBug;
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 {
1001 return CIInsts;
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
1050 /// SGPRs
1051 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
1053 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs
1054 /// 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)
1165 const override;
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
1198 /// subtarget.
1199 unsigned getMinWavesPerEU() const override {
1200 return AMDGPU::IsaInfo::getMinWavesPerEU(this);
1204 class R600Subtarget final : public R600GenSubtargetInfo,
1205 public AMDGPUSubtarget {
1206 private:
1207 R600InstrInfo InstrInfo;
1208 R600FrameLowering FrameLowering;
1209 bool FMA;
1210 bool CaymanISA;
1211 bool CFALUBug;
1212 bool HasVertexCache;
1213 bool R600ALUInst;
1214 bool FP64;
1215 short TexVTXClauseSize;
1216 Generation Gen;
1217 R600TargetLowering TLInfo;
1218 InstrItineraryData InstrItins;
1219 SelectionDAGTargetInfo TSInfo;
1221 public:
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 {
1232 return &TLInfo;
1235 const R600RegisterInfo *getRegisterInfo() const override {
1236 return &InstrInfo.getRegisterInfo();
1239 const InstrItineraryData *getInstrItineraryData() const override {
1240 return &InstrItins;
1243 // Nothing implemented, just prevent crashes on use.
1244 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
1245 return &TSInfo;
1248 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
1250 Generation getGeneration() const {
1251 return Gen;
1254 unsigned getStackAlignment() const {
1255 return 4;
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 {
1270 if (Size == 32)
1271 return (getGeneration() >= EVERGREEN);
1273 return false;
1276 bool hasBORROW() const {
1277 return (getGeneration() >= EVERGREEN);
1280 bool hasCARRY() const {
1281 return (getGeneration() >= EVERGREEN);
1284 bool hasCaymanISA() const {
1285 return CaymanISA;
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 {
1305 return true;
1308 bool enableSubRegLiveness() const override {
1309 return true;
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
1335 /// subtarget.
1336 unsigned getMinWavesPerEU() const override {
1337 return AMDGPU::IsaInfo::getMinWavesPerEU(this);
1341 } // end namespace llvm
1343 #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H