xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AMDGPU/GCNSubtarget.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1e8d8bef9SDimitry Andric //=====-- GCNSubtarget.h - Define GCN Subtarget for AMDGPU ------*- C++ -*-===//
2e8d8bef9SDimitry Andric //
3e8d8bef9SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e8d8bef9SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5e8d8bef9SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e8d8bef9SDimitry Andric //
7e8d8bef9SDimitry Andric //==-----------------------------------------------------------------------===//
8e8d8bef9SDimitry Andric //
9e8d8bef9SDimitry Andric /// \file
10e8d8bef9SDimitry Andric /// AMD GCN specific subclass of TargetSubtarget.
11e8d8bef9SDimitry Andric //
12e8d8bef9SDimitry Andric //===----------------------------------------------------------------------===//
13e8d8bef9SDimitry Andric 
14e8d8bef9SDimitry Andric #ifndef LLVM_LIB_TARGET_AMDGPU_GCNSUBTARGET_H
15e8d8bef9SDimitry Andric #define LLVM_LIB_TARGET_AMDGPU_GCNSUBTARGET_H
16e8d8bef9SDimitry Andric 
17e8d8bef9SDimitry Andric #include "AMDGPUCallLowering.h"
1806c3fb27SDimitry Andric #include "AMDGPURegisterBankInfo.h"
19e8d8bef9SDimitry Andric #include "AMDGPUSubtarget.h"
20e8d8bef9SDimitry Andric #include "SIFrameLowering.h"
21e8d8bef9SDimitry Andric #include "SIISelLowering.h"
22e8d8bef9SDimitry Andric #include "SIInstrInfo.h"
2306c3fb27SDimitry Andric #include "Utils/AMDGPUBaseInfo.h"
24e8d8bef9SDimitry Andric #include "llvm/CodeGen/SelectionDAGTargetInfo.h"
255f757f3fSDimitry Andric #include "llvm/Support/ErrorHandling.h"
26e8d8bef9SDimitry Andric 
27e8d8bef9SDimitry Andric #define GET_SUBTARGETINFO_HEADER
28e8d8bef9SDimitry Andric #include "AMDGPUGenSubtargetInfo.inc"
29e8d8bef9SDimitry Andric 
30e8d8bef9SDimitry Andric namespace llvm {
31e8d8bef9SDimitry Andric 
32e8d8bef9SDimitry Andric class GCNTargetMachine;
33e8d8bef9SDimitry Andric 
34e8d8bef9SDimitry Andric class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
35e8d8bef9SDimitry Andric                            public AMDGPUSubtarget {
36bdd1243dSDimitry Andric public:
37e8d8bef9SDimitry Andric   using AMDGPUSubtarget::getMaxWavesPerEU;
38e8d8bef9SDimitry Andric 
39fe6060f1SDimitry Andric   // Following 2 enums are documented at:
40fe6060f1SDimitry Andric   //   - https://llvm.org/docs/AMDGPUUsage.html#trap-handler-abi
41fe6060f1SDimitry Andric   enum class TrapHandlerAbi {
42fe6060f1SDimitry Andric     NONE   = 0x00,
43fe6060f1SDimitry Andric     AMDHSA = 0x01,
44e8d8bef9SDimitry Andric   };
45e8d8bef9SDimitry Andric 
46fe6060f1SDimitry Andric   enum class TrapID {
47fe6060f1SDimitry Andric     LLVMAMDHSATrap      = 0x02,
48fe6060f1SDimitry Andric     LLVMAMDHSADebugTrap = 0x03,
49e8d8bef9SDimitry Andric   };
50e8d8bef9SDimitry Andric 
51e8d8bef9SDimitry Andric private:
52e8d8bef9SDimitry Andric   /// GlobalISel related APIs.
53e8d8bef9SDimitry Andric   std::unique_ptr<AMDGPUCallLowering> CallLoweringInfo;
54e8d8bef9SDimitry Andric   std::unique_ptr<InlineAsmLowering> InlineAsmLoweringInfo;
55e8d8bef9SDimitry Andric   std::unique_ptr<InstructionSelector> InstSelector;
56e8d8bef9SDimitry Andric   std::unique_ptr<LegalizerInfo> Legalizer;
5706c3fb27SDimitry Andric   std::unique_ptr<AMDGPURegisterBankInfo> RegBankInfo;
58e8d8bef9SDimitry Andric 
59e8d8bef9SDimitry Andric protected:
60e8d8bef9SDimitry Andric   // Basic subtarget description.
61e8d8bef9SDimitry Andric   Triple TargetTriple;
62e8d8bef9SDimitry Andric   AMDGPU::IsaInfo::AMDGPUTargetID TargetID;
6381ad6265SDimitry Andric   unsigned Gen = INVALID;
64e8d8bef9SDimitry Andric   InstrItineraryData InstrItins;
6581ad6265SDimitry Andric   int LDSBankCount = 0;
6681ad6265SDimitry Andric   unsigned MaxPrivateElementSize = 0;
67e8d8bef9SDimitry Andric 
68e8d8bef9SDimitry Andric   // Possibly statically set by tablegen, but may want to be overridden.
6981ad6265SDimitry Andric   bool FastDenormalF32 = false;
7081ad6265SDimitry Andric   bool HalfRate64Ops = false;
7181ad6265SDimitry Andric   bool FullRate64Ops = false;
72e8d8bef9SDimitry Andric 
73e8d8bef9SDimitry Andric   // Dynamically set bits that enable features.
7481ad6265SDimitry Andric   bool FlatForGlobal = false;
7581ad6265SDimitry Andric   bool AutoWaitcntBeforeBarrier = false;
76bdd1243dSDimitry Andric   bool BackOffBarrier = false;
7781ad6265SDimitry Andric   bool UnalignedScratchAccess = false;
7881ad6265SDimitry Andric   bool UnalignedAccessMode = false;
7981ad6265SDimitry Andric   bool HasApertureRegs = false;
8081ad6265SDimitry Andric   bool SupportsXNACK = false;
815f757f3fSDimitry Andric   bool KernargPreload = false;
82e8d8bef9SDimitry Andric 
83e8d8bef9SDimitry Andric   // This should not be used directly. 'TargetID' tracks the dynamic settings
84e8d8bef9SDimitry Andric   // for XNACK.
8581ad6265SDimitry Andric   bool EnableXNACK = false;
86e8d8bef9SDimitry Andric 
8781ad6265SDimitry Andric   bool EnableTgSplit = false;
8881ad6265SDimitry Andric   bool EnableCuMode = false;
8981ad6265SDimitry Andric   bool TrapHandler = false;
90*0fca6ea1SDimitry Andric   bool EnablePreciseMemory = false;
91e8d8bef9SDimitry Andric 
92e8d8bef9SDimitry Andric   // Used as options.
9381ad6265SDimitry Andric   bool EnableLoadStoreOpt = false;
9481ad6265SDimitry Andric   bool EnableUnsafeDSOffsetFolding = false;
9581ad6265SDimitry Andric   bool EnableSIScheduler = false;
9681ad6265SDimitry Andric   bool EnableDS128 = false;
9781ad6265SDimitry Andric   bool EnablePRTStrictNull = false;
9881ad6265SDimitry Andric   bool DumpCode = false;
99e8d8bef9SDimitry Andric 
100e8d8bef9SDimitry Andric   // Subtarget statically properties set by tablegen
10181ad6265SDimitry Andric   bool FP64 = false;
10281ad6265SDimitry Andric   bool FMA = false;
10381ad6265SDimitry Andric   bool MIMG_R128 = false;
10481ad6265SDimitry Andric   bool CIInsts = false;
10581ad6265SDimitry Andric   bool GFX8Insts = false;
10681ad6265SDimitry Andric   bool GFX9Insts = false;
10781ad6265SDimitry Andric   bool GFX90AInsts = false;
10881ad6265SDimitry Andric   bool GFX940Insts = false;
10981ad6265SDimitry Andric   bool GFX10Insts = false;
11081ad6265SDimitry Andric   bool GFX11Insts = false;
1115f757f3fSDimitry Andric   bool GFX12Insts = false;
11281ad6265SDimitry Andric   bool GFX10_3Insts = false;
11381ad6265SDimitry Andric   bool GFX7GFX8GFX9Insts = false;
11481ad6265SDimitry Andric   bool SGPRInitBug = false;
11581ad6265SDimitry Andric   bool UserSGPRInit16Bug = false;
11681ad6265SDimitry Andric   bool NegativeScratchOffsetBug = false;
11781ad6265SDimitry Andric   bool NegativeUnalignedScratchOffsetBug = false;
11881ad6265SDimitry Andric   bool HasSMemRealTime = false;
11981ad6265SDimitry Andric   bool HasIntClamp = false;
12081ad6265SDimitry Andric   bool HasFmaMixInsts = false;
12181ad6265SDimitry Andric   bool HasMovrel = false;
12281ad6265SDimitry Andric   bool HasVGPRIndexMode = false;
1235f757f3fSDimitry Andric   bool HasScalarDwordx3Loads = false;
12481ad6265SDimitry Andric   bool HasScalarStores = false;
12581ad6265SDimitry Andric   bool HasScalarAtomics = false;
12681ad6265SDimitry Andric   bool HasSDWAOmod = false;
12781ad6265SDimitry Andric   bool HasSDWAScalar = false;
12881ad6265SDimitry Andric   bool HasSDWASdst = false;
12981ad6265SDimitry Andric   bool HasSDWAMac = false;
13081ad6265SDimitry Andric   bool HasSDWAOutModsVOPC = false;
13181ad6265SDimitry Andric   bool HasDPP = false;
13281ad6265SDimitry Andric   bool HasDPP8 = false;
1335f757f3fSDimitry Andric   bool HasDPALU_DPP = false;
1345f757f3fSDimitry Andric   bool HasDPPSrc1SGPR = false;
13581ad6265SDimitry Andric   bool HasPackedFP32Ops = false;
13681ad6265SDimitry Andric   bool HasImageInsts = false;
13781ad6265SDimitry Andric   bool HasExtendedImageInsts = false;
13881ad6265SDimitry Andric   bool HasR128A16 = false;
139bdd1243dSDimitry Andric   bool HasA16 = false;
14081ad6265SDimitry Andric   bool HasG16 = false;
14181ad6265SDimitry Andric   bool HasNSAEncoding = false;
14206c3fb27SDimitry Andric   bool HasPartialNSAEncoding = false;
14381ad6265SDimitry Andric   bool GFX10_AEncoding = false;
14481ad6265SDimitry Andric   bool GFX10_BEncoding = false;
14581ad6265SDimitry Andric   bool HasDLInsts = false;
146bdd1243dSDimitry Andric   bool HasFmacF64Inst = false;
14781ad6265SDimitry Andric   bool HasDot1Insts = false;
14881ad6265SDimitry Andric   bool HasDot2Insts = false;
14981ad6265SDimitry Andric   bool HasDot3Insts = false;
15081ad6265SDimitry Andric   bool HasDot4Insts = false;
15181ad6265SDimitry Andric   bool HasDot5Insts = false;
15281ad6265SDimitry Andric   bool HasDot6Insts = false;
15381ad6265SDimitry Andric   bool HasDot7Insts = false;
15481ad6265SDimitry Andric   bool HasDot8Insts = false;
155bdd1243dSDimitry Andric   bool HasDot9Insts = false;
15606c3fb27SDimitry Andric   bool HasDot10Insts = false;
157*0fca6ea1SDimitry Andric   bool HasDot11Insts = false;
15881ad6265SDimitry Andric   bool HasMAIInsts = false;
159fcaf7f86SDimitry Andric   bool HasFP8Insts = false;
1607a6dacacSDimitry Andric   bool HasFP8ConversionInsts = false;
16181ad6265SDimitry Andric   bool HasPkFmacF16Inst = false;
162*0fca6ea1SDimitry Andric   bool HasAtomicFMinFMaxF32GlobalInsts = false;
163*0fca6ea1SDimitry Andric   bool HasAtomicFMinFMaxF64GlobalInsts = false;
164*0fca6ea1SDimitry Andric   bool HasAtomicFMinFMaxF32FlatInsts = false;
165*0fca6ea1SDimitry Andric   bool HasAtomicFMinFMaxF64FlatInsts = false;
16606c3fb27SDimitry Andric   bool HasAtomicDsPkAdd16Insts = false;
16706c3fb27SDimitry Andric   bool HasAtomicFlatPkAdd16Insts = false;
16881ad6265SDimitry Andric   bool HasAtomicFaddRtnInsts = false;
16981ad6265SDimitry Andric   bool HasAtomicFaddNoRtnInsts = false;
170*0fca6ea1SDimitry Andric   bool HasMemoryAtomicFaddF32DenormalSupport = false;
17106c3fb27SDimitry Andric   bool HasAtomicBufferGlobalPkAddF16NoRtnInsts = false;
17206c3fb27SDimitry Andric   bool HasAtomicBufferGlobalPkAddF16Insts = false;
1735f757f3fSDimitry Andric   bool HasAtomicCSubNoRtnInsts = false;
17406c3fb27SDimitry Andric   bool HasAtomicGlobalPkAddBF16Inst = false;
175*0fca6ea1SDimitry Andric   bool HasAtomicBufferPkAddBF16Inst = false;
176bdd1243dSDimitry Andric   bool HasFlatAtomicFaddF32Inst = false;
177*0fca6ea1SDimitry Andric   bool HasFlatBufferGlobalAtomicFaddF64Inst = false;
1787a6dacacSDimitry Andric   bool HasDefaultComponentZero = false;
179*0fca6ea1SDimitry Andric   bool HasAgentScopeFineGrainedRemoteMemoryAtomics = false;
1807a6dacacSDimitry Andric   bool HasDefaultComponentBroadcast = false;
181*0fca6ea1SDimitry Andric   /// The maximum number of instructions that may be placed within an S_CLAUSE,
182*0fca6ea1SDimitry Andric   /// which is one greater than the maximum argument to S_CLAUSE. A value of 0
183*0fca6ea1SDimitry Andric   /// indicates a lack of S_CLAUSE support.
184*0fca6ea1SDimitry Andric   unsigned MaxHardClauseLength = 0;
18581ad6265SDimitry Andric   bool SupportsSRAMECC = false;
186e8d8bef9SDimitry Andric 
187e8d8bef9SDimitry Andric   // This should not be used directly. 'TargetID' tracks the dynamic settings
188e8d8bef9SDimitry Andric   // for SRAMECC.
18981ad6265SDimitry Andric   bool EnableSRAMECC = false;
190e8d8bef9SDimitry Andric 
19181ad6265SDimitry Andric   bool HasNoSdstCMPX = false;
19281ad6265SDimitry Andric   bool HasVscnt = false;
19381ad6265SDimitry Andric   bool HasGetWaveIdInst = false;
19481ad6265SDimitry Andric   bool HasSMemTimeInst = false;
19581ad6265SDimitry Andric   bool HasShaderCyclesRegister = false;
1961db9f3b2SDimitry Andric   bool HasShaderCyclesHiLoRegisters = false;
19781ad6265SDimitry Andric   bool HasVOP3Literal = false;
19881ad6265SDimitry Andric   bool HasNoDataDepHazard = false;
19981ad6265SDimitry Andric   bool FlatAddressSpace = false;
20081ad6265SDimitry Andric   bool FlatInstOffsets = false;
20181ad6265SDimitry Andric   bool FlatGlobalInsts = false;
20281ad6265SDimitry Andric   bool FlatScratchInsts = false;
20381ad6265SDimitry Andric   bool ScalarFlatScratchInsts = false;
20481ad6265SDimitry Andric   bool HasArchitectedFlatScratch = false;
20581ad6265SDimitry Andric   bool EnableFlatScratch = false;
20606c3fb27SDimitry Andric   bool HasArchitectedSGPRs = false;
2075f757f3fSDimitry Andric   bool HasGDS = false;
2085f757f3fSDimitry Andric   bool HasGWS = false;
20981ad6265SDimitry Andric   bool AddNoCarryInsts = false;
21081ad6265SDimitry Andric   bool HasUnpackedD16VMem = false;
21181ad6265SDimitry Andric   bool LDSMisalignedBug = false;
21281ad6265SDimitry Andric   bool HasMFMAInlineLiteralBug = false;
21381ad6265SDimitry Andric   bool UnalignedBufferAccess = false;
21481ad6265SDimitry Andric   bool UnalignedDSAccess = false;
21581ad6265SDimitry Andric   bool HasPackedTID = false;
21681ad6265SDimitry Andric   bool ScalarizeGlobal = false;
2175f757f3fSDimitry Andric   bool HasSALUFloatInsts = false;
2185f757f3fSDimitry Andric   bool HasVGPRSingleUseHintInsts = false;
2195f757f3fSDimitry Andric   bool HasPseudoScalarTrans = false;
2205f757f3fSDimitry Andric   bool HasRestrictedSOffset = false;
221e8d8bef9SDimitry Andric 
22281ad6265SDimitry Andric   bool HasVcmpxPermlaneHazard = false;
22381ad6265SDimitry Andric   bool HasVMEMtoScalarWriteHazard = false;
22481ad6265SDimitry Andric   bool HasSMEMtoVectorWriteHazard = false;
22581ad6265SDimitry Andric   bool HasInstFwdPrefetchBug = false;
22681ad6265SDimitry Andric   bool HasVcmpxExecWARHazard = false;
22781ad6265SDimitry Andric   bool HasLdsBranchVmemWARHazard = false;
22881ad6265SDimitry Andric   bool HasNSAtoVMEMBug = false;
22981ad6265SDimitry Andric   bool HasNSAClauseBug = false;
23081ad6265SDimitry Andric   bool HasOffset3fBug = false;
23181ad6265SDimitry Andric   bool HasFlatSegmentOffsetBug = false;
23281ad6265SDimitry Andric   bool HasImageStoreD16Bug = false;
23381ad6265SDimitry Andric   bool HasImageGather4D16Bug = false;
2345f757f3fSDimitry Andric   bool HasMSAALoadDstSelBug = false;
235*0fca6ea1SDimitry Andric   bool HasPrivEnabledTrap2NopBug = false;
236*0fca6ea1SDimitry Andric   bool Has1_5xVGPRs = false;
237bdd1243dSDimitry Andric   bool HasMADIntraFwdBug = false;
23881ad6265SDimitry Andric   bool HasVOPDInsts = false;
239bdd1243dSDimitry Andric   bool HasVALUTransUseHazard = false;
24006c3fb27SDimitry Andric   bool HasForceStoreSC0SC1 = false;
241*0fca6ea1SDimitry Andric   bool HasRequiredExportPriority = false;
242*0fca6ea1SDimitry Andric 
243*0fca6ea1SDimitry Andric   bool RequiresCOV6 = false;
244e8d8bef9SDimitry Andric 
245e8d8bef9SDimitry Andric   // Dummy feature to use for assembler in tablegen.
24681ad6265SDimitry Andric   bool FeatureDisable = false;
247e8d8bef9SDimitry Andric 
248e8d8bef9SDimitry Andric   SelectionDAGTargetInfo TSInfo;
249e8d8bef9SDimitry Andric private:
250e8d8bef9SDimitry Andric   SIInstrInfo InstrInfo;
251e8d8bef9SDimitry Andric   SITargetLowering TLInfo;
252e8d8bef9SDimitry Andric   SIFrameLowering FrameLowering;
253e8d8bef9SDimitry Andric 
254e8d8bef9SDimitry Andric public:
255e8d8bef9SDimitry Andric   GCNSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
256e8d8bef9SDimitry Andric                const GCNTargetMachine &TM);
257e8d8bef9SDimitry Andric   ~GCNSubtarget() override;
258e8d8bef9SDimitry Andric 
259e8d8bef9SDimitry Andric   GCNSubtarget &initializeSubtargetDependencies(const Triple &TT,
260e8d8bef9SDimitry Andric                                                    StringRef GPU, StringRef FS);
261e8d8bef9SDimitry Andric 
262*0fca6ea1SDimitry Andric   /// Diagnose inconsistent subtarget features before attempting to codegen
263*0fca6ea1SDimitry Andric   /// function \p F.
264*0fca6ea1SDimitry Andric   void checkSubtargetFeatures(const Function &F) const;
265*0fca6ea1SDimitry Andric 
266e8d8bef9SDimitry Andric   const SIInstrInfo *getInstrInfo() const override {
267e8d8bef9SDimitry Andric     return &InstrInfo;
268e8d8bef9SDimitry Andric   }
269e8d8bef9SDimitry Andric 
270e8d8bef9SDimitry Andric   const SIFrameLowering *getFrameLowering() const override {
271e8d8bef9SDimitry Andric     return &FrameLowering;
272e8d8bef9SDimitry Andric   }
273e8d8bef9SDimitry Andric 
274e8d8bef9SDimitry Andric   const SITargetLowering *getTargetLowering() const override {
275e8d8bef9SDimitry Andric     return &TLInfo;
276e8d8bef9SDimitry Andric   }
277e8d8bef9SDimitry Andric 
278e8d8bef9SDimitry Andric   const SIRegisterInfo *getRegisterInfo() const override {
279e8d8bef9SDimitry Andric     return &InstrInfo.getRegisterInfo();
280e8d8bef9SDimitry Andric   }
281e8d8bef9SDimitry Andric 
282e8d8bef9SDimitry Andric   const CallLowering *getCallLowering() const override {
283e8d8bef9SDimitry Andric     return CallLoweringInfo.get();
284e8d8bef9SDimitry Andric   }
285e8d8bef9SDimitry Andric 
286e8d8bef9SDimitry Andric   const InlineAsmLowering *getInlineAsmLowering() const override {
287e8d8bef9SDimitry Andric     return InlineAsmLoweringInfo.get();
288e8d8bef9SDimitry Andric   }
289e8d8bef9SDimitry Andric 
290e8d8bef9SDimitry Andric   InstructionSelector *getInstructionSelector() const override {
291e8d8bef9SDimitry Andric     return InstSelector.get();
292e8d8bef9SDimitry Andric   }
293e8d8bef9SDimitry Andric 
294e8d8bef9SDimitry Andric   const LegalizerInfo *getLegalizerInfo() const override {
295e8d8bef9SDimitry Andric     return Legalizer.get();
296e8d8bef9SDimitry Andric   }
297e8d8bef9SDimitry Andric 
29806c3fb27SDimitry Andric   const AMDGPURegisterBankInfo *getRegBankInfo() const override {
299e8d8bef9SDimitry Andric     return RegBankInfo.get();
300e8d8bef9SDimitry Andric   }
301e8d8bef9SDimitry Andric 
302fe6060f1SDimitry Andric   const AMDGPU::IsaInfo::AMDGPUTargetID &getTargetID() const {
303fe6060f1SDimitry Andric     return TargetID;
304fe6060f1SDimitry Andric   }
305fe6060f1SDimitry Andric 
306e8d8bef9SDimitry Andric   // Nothing implemented, just prevent crashes on use.
307e8d8bef9SDimitry Andric   const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
308e8d8bef9SDimitry Andric     return &TSInfo;
309e8d8bef9SDimitry Andric   }
310e8d8bef9SDimitry Andric 
311e8d8bef9SDimitry Andric   const InstrItineraryData *getInstrItineraryData() const override {
312e8d8bef9SDimitry Andric     return &InstrItins;
313e8d8bef9SDimitry Andric   }
314e8d8bef9SDimitry Andric 
315e8d8bef9SDimitry Andric   void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
316e8d8bef9SDimitry Andric 
317e8d8bef9SDimitry Andric   Generation getGeneration() const {
318e8d8bef9SDimitry Andric     return (Generation)Gen;
319e8d8bef9SDimitry Andric   }
320e8d8bef9SDimitry Andric 
32181ad6265SDimitry Andric   unsigned getMaxWaveScratchSize() const {
32281ad6265SDimitry Andric     // See COMPUTE_TMPRING_SIZE.WAVESIZE.
3237a6dacacSDimitry Andric     if (getGeneration() >= GFX12) {
3247a6dacacSDimitry Andric       // 18-bit field in units of 64-dword.
3257a6dacacSDimitry Andric       return (64 * 4) * ((1 << 18) - 1);
32681ad6265SDimitry Andric     }
3277a6dacacSDimitry Andric     if (getGeneration() == GFX11) {
32881ad6265SDimitry Andric       // 15-bit field in units of 64-dword.
32981ad6265SDimitry Andric       return (64 * 4) * ((1 << 15) - 1);
33081ad6265SDimitry Andric     }
3317a6dacacSDimitry Andric     // 13-bit field in units of 256-dword.
3327a6dacacSDimitry Andric     return (256 * 4) * ((1 << 13) - 1);
3337a6dacacSDimitry Andric   }
33481ad6265SDimitry Andric 
335349cc55cSDimitry Andric   /// Return the number of high bits known to be zero for a frame index.
336e8d8bef9SDimitry Andric   unsigned getKnownHighZeroBitsForFrameIndex() const {
33706c3fb27SDimitry Andric     return llvm::countl_zero(getMaxWaveScratchSize()) + getWavefrontSizeLog2();
338e8d8bef9SDimitry Andric   }
339e8d8bef9SDimitry Andric 
340e8d8bef9SDimitry Andric   int getLDSBankCount() const {
341e8d8bef9SDimitry Andric     return LDSBankCount;
342e8d8bef9SDimitry Andric   }
343e8d8bef9SDimitry Andric 
344e8d8bef9SDimitry Andric   unsigned getMaxPrivateElementSize(bool ForBufferRSrc = false) const {
345e8d8bef9SDimitry Andric     return (ForBufferRSrc || !enableFlatScratch()) ? MaxPrivateElementSize : 16;
346e8d8bef9SDimitry Andric   }
347e8d8bef9SDimitry Andric 
348e8d8bef9SDimitry Andric   unsigned getConstantBusLimit(unsigned Opcode) const;
349e8d8bef9SDimitry Andric 
350fe6060f1SDimitry Andric   /// Returns if the result of this instruction with a 16-bit result returned in
351fe6060f1SDimitry Andric   /// a 32-bit register implicitly zeroes the high 16-bits, rather than preserve
352fe6060f1SDimitry Andric   /// the original value.
353fe6060f1SDimitry Andric   bool zeroesHigh16BitsOfDest(unsigned Opcode) const;
354fe6060f1SDimitry Andric 
355bdd1243dSDimitry Andric   bool supportsWGP() const { return getGeneration() >= GFX10; }
356bdd1243dSDimitry Andric 
357e8d8bef9SDimitry Andric   bool hasIntClamp() const {
358e8d8bef9SDimitry Andric     return HasIntClamp;
359e8d8bef9SDimitry Andric   }
360e8d8bef9SDimitry Andric 
361e8d8bef9SDimitry Andric   bool hasFP64() const {
362e8d8bef9SDimitry Andric     return FP64;
363e8d8bef9SDimitry Andric   }
364e8d8bef9SDimitry Andric 
365e8d8bef9SDimitry Andric   bool hasMIMG_R128() const {
366e8d8bef9SDimitry Andric     return MIMG_R128;
367e8d8bef9SDimitry Andric   }
368e8d8bef9SDimitry Andric 
369e8d8bef9SDimitry Andric   bool hasHWFP64() const {
370e8d8bef9SDimitry Andric     return FP64;
371e8d8bef9SDimitry Andric   }
372e8d8bef9SDimitry Andric 
373e8d8bef9SDimitry Andric   bool hasHalfRate64Ops() const {
374e8d8bef9SDimitry Andric     return HalfRate64Ops;
375e8d8bef9SDimitry Andric   }
376e8d8bef9SDimitry Andric 
377fe6060f1SDimitry Andric   bool hasFullRate64Ops() const {
378fe6060f1SDimitry Andric     return FullRate64Ops;
379fe6060f1SDimitry Andric   }
380fe6060f1SDimitry Andric 
381e8d8bef9SDimitry Andric   bool hasAddr64() const {
382e8d8bef9SDimitry Andric     return (getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS);
383e8d8bef9SDimitry Andric   }
384e8d8bef9SDimitry Andric 
385e8d8bef9SDimitry Andric   bool hasFlat() const {
386e8d8bef9SDimitry Andric     return (getGeneration() > AMDGPUSubtarget::SOUTHERN_ISLANDS);
387e8d8bef9SDimitry Andric   }
388e8d8bef9SDimitry Andric 
389e8d8bef9SDimitry Andric   // Return true if the target only has the reverse operand versions of VALU
390e8d8bef9SDimitry Andric   // shift instructions (e.g. v_lshrrev_b32, and no v_lshr_b32).
391e8d8bef9SDimitry Andric   bool hasOnlyRevVALUShifts() const {
392e8d8bef9SDimitry Andric     return getGeneration() >= VOLCANIC_ISLANDS;
393e8d8bef9SDimitry Andric   }
394e8d8bef9SDimitry Andric 
395e8d8bef9SDimitry Andric   bool hasFractBug() const {
396e8d8bef9SDimitry Andric     return getGeneration() == SOUTHERN_ISLANDS;
397e8d8bef9SDimitry Andric   }
398e8d8bef9SDimitry Andric 
399e8d8bef9SDimitry Andric   bool hasBFE() const {
400e8d8bef9SDimitry Andric     return true;
401e8d8bef9SDimitry Andric   }
402e8d8bef9SDimitry Andric 
403e8d8bef9SDimitry Andric   bool hasBFI() const {
404e8d8bef9SDimitry Andric     return true;
405e8d8bef9SDimitry Andric   }
406e8d8bef9SDimitry Andric 
407e8d8bef9SDimitry Andric   bool hasBFM() const {
408e8d8bef9SDimitry Andric     return hasBFE();
409e8d8bef9SDimitry Andric   }
410e8d8bef9SDimitry Andric 
411e8d8bef9SDimitry Andric   bool hasBCNT(unsigned Size) const {
412e8d8bef9SDimitry Andric     return true;
413e8d8bef9SDimitry Andric   }
414e8d8bef9SDimitry Andric 
415e8d8bef9SDimitry Andric   bool hasFFBL() const {
416e8d8bef9SDimitry Andric     return true;
417e8d8bef9SDimitry Andric   }
418e8d8bef9SDimitry Andric 
419e8d8bef9SDimitry Andric   bool hasFFBH() const {
420e8d8bef9SDimitry Andric     return true;
421e8d8bef9SDimitry Andric   }
422e8d8bef9SDimitry Andric 
423e8d8bef9SDimitry Andric   bool hasMed3_16() const {
424e8d8bef9SDimitry Andric     return getGeneration() >= AMDGPUSubtarget::GFX9;
425e8d8bef9SDimitry Andric   }
426e8d8bef9SDimitry Andric 
427e8d8bef9SDimitry Andric   bool hasMin3Max3_16() const {
428e8d8bef9SDimitry Andric     return getGeneration() >= AMDGPUSubtarget::GFX9;
429e8d8bef9SDimitry Andric   }
430e8d8bef9SDimitry Andric 
431e8d8bef9SDimitry Andric   bool hasFmaMixInsts() const {
432e8d8bef9SDimitry Andric     return HasFmaMixInsts;
433e8d8bef9SDimitry Andric   }
434e8d8bef9SDimitry Andric 
435e8d8bef9SDimitry Andric   bool hasCARRY() const {
436e8d8bef9SDimitry Andric     return true;
437e8d8bef9SDimitry Andric   }
438e8d8bef9SDimitry Andric 
439e8d8bef9SDimitry Andric   bool hasFMA() const {
440e8d8bef9SDimitry Andric     return FMA;
441e8d8bef9SDimitry Andric   }
442e8d8bef9SDimitry Andric 
443e8d8bef9SDimitry Andric   bool hasSwap() const {
444e8d8bef9SDimitry Andric     return GFX9Insts;
445e8d8bef9SDimitry Andric   }
446e8d8bef9SDimitry Andric 
447e8d8bef9SDimitry Andric   bool hasScalarPackInsts() const {
448e8d8bef9SDimitry Andric     return GFX9Insts;
449e8d8bef9SDimitry Andric   }
450e8d8bef9SDimitry Andric 
451e8d8bef9SDimitry Andric   bool hasScalarMulHiInsts() const {
452e8d8bef9SDimitry Andric     return GFX9Insts;
453e8d8bef9SDimitry Andric   }
454e8d8bef9SDimitry Andric 
4557a6dacacSDimitry Andric   bool hasScalarSubwordLoads() const { return getGeneration() >= GFX12; }
4567a6dacacSDimitry Andric 
457e8d8bef9SDimitry Andric   TrapHandlerAbi getTrapHandlerAbi() const {
458fe6060f1SDimitry Andric     return isAmdHsaOS() ? TrapHandlerAbi::AMDHSA : TrapHandlerAbi::NONE;
459fe6060f1SDimitry Andric   }
460fe6060f1SDimitry Andric 
461fe6060f1SDimitry Andric   bool supportsGetDoorbellID() const {
462fe6060f1SDimitry Andric     // The S_GETREG DOORBELL_ID is supported by all GFX9 onward targets.
463fe6060f1SDimitry Andric     return getGeneration() >= GFX9;
464e8d8bef9SDimitry Andric   }
465e8d8bef9SDimitry Andric 
466e8d8bef9SDimitry Andric   /// True if the offset field of DS instructions works as expected. On SI, the
467e8d8bef9SDimitry Andric   /// offset uses a 16-bit adder and does not always wrap properly.
468e8d8bef9SDimitry Andric   bool hasUsableDSOffset() const {
469e8d8bef9SDimitry Andric     return getGeneration() >= SEA_ISLANDS;
470e8d8bef9SDimitry Andric   }
471e8d8bef9SDimitry Andric 
472e8d8bef9SDimitry Andric   bool unsafeDSOffsetFoldingEnabled() const {
473e8d8bef9SDimitry Andric     return EnableUnsafeDSOffsetFolding;
474e8d8bef9SDimitry Andric   }
475e8d8bef9SDimitry Andric 
476e8d8bef9SDimitry Andric   /// Condition output from div_scale is usable.
477e8d8bef9SDimitry Andric   bool hasUsableDivScaleConditionOutput() const {
478e8d8bef9SDimitry Andric     return getGeneration() != SOUTHERN_ISLANDS;
479e8d8bef9SDimitry Andric   }
480e8d8bef9SDimitry Andric 
481e8d8bef9SDimitry Andric   /// Extra wait hazard is needed in some cases before
482e8d8bef9SDimitry Andric   /// s_cbranch_vccnz/s_cbranch_vccz.
483e8d8bef9SDimitry Andric   bool hasReadVCCZBug() const {
484e8d8bef9SDimitry Andric     return getGeneration() <= SEA_ISLANDS;
485e8d8bef9SDimitry Andric   }
486e8d8bef9SDimitry Andric 
487e8d8bef9SDimitry Andric   /// Writes to VCC_LO/VCC_HI update the VCCZ flag.
488e8d8bef9SDimitry Andric   bool partialVCCWritesUpdateVCCZ() const {
489e8d8bef9SDimitry Andric     return getGeneration() >= GFX10;
490e8d8bef9SDimitry Andric   }
491e8d8bef9SDimitry Andric 
492e8d8bef9SDimitry Andric   /// A read of an SGPR by SMRD instruction requires 4 wait states when the SGPR
493e8d8bef9SDimitry Andric   /// was written by a VALU instruction.
494e8d8bef9SDimitry Andric   bool hasSMRDReadVALUDefHazard() const {
495e8d8bef9SDimitry Andric     return getGeneration() == SOUTHERN_ISLANDS;
496e8d8bef9SDimitry Andric   }
497e8d8bef9SDimitry Andric 
498e8d8bef9SDimitry Andric   /// A read of an SGPR by a VMEM instruction requires 5 wait states when the
499e8d8bef9SDimitry Andric   /// SGPR was written by a VALU Instruction.
500e8d8bef9SDimitry Andric   bool hasVMEMReadSGPRVALUDefHazard() const {
501e8d8bef9SDimitry Andric     return getGeneration() >= VOLCANIC_ISLANDS;
502e8d8bef9SDimitry Andric   }
503e8d8bef9SDimitry Andric 
504e8d8bef9SDimitry Andric   bool hasRFEHazards() const {
505e8d8bef9SDimitry Andric     return getGeneration() >= VOLCANIC_ISLANDS;
506e8d8bef9SDimitry Andric   }
507e8d8bef9SDimitry Andric 
508e8d8bef9SDimitry Andric   /// Number of hazard wait states for s_setreg_b32/s_setreg_imm32_b32.
509e8d8bef9SDimitry Andric   unsigned getSetRegWaitStates() const {
510e8d8bef9SDimitry Andric     return getGeneration() <= SEA_ISLANDS ? 1 : 2;
511e8d8bef9SDimitry Andric   }
512e8d8bef9SDimitry Andric 
513e8d8bef9SDimitry Andric   bool dumpCode() const {
514e8d8bef9SDimitry Andric     return DumpCode;
515e8d8bef9SDimitry Andric   }
516e8d8bef9SDimitry Andric 
517e8d8bef9SDimitry Andric   /// Return the amount of LDS that can be used that will not restrict the
518e8d8bef9SDimitry Andric   /// occupancy lower than WaveCount.
519e8d8bef9SDimitry Andric   unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
520e8d8bef9SDimitry Andric                                            const Function &) const;
521e8d8bef9SDimitry Andric 
522e8d8bef9SDimitry Andric   bool supportsMinMaxDenormModes() const {
523e8d8bef9SDimitry Andric     return getGeneration() >= AMDGPUSubtarget::GFX9;
524e8d8bef9SDimitry Andric   }
525e8d8bef9SDimitry Andric 
526e8d8bef9SDimitry Andric   /// \returns If target supports S_DENORM_MODE.
527e8d8bef9SDimitry Andric   bool hasDenormModeInst() const {
528e8d8bef9SDimitry Andric     return getGeneration() >= AMDGPUSubtarget::GFX10;
529e8d8bef9SDimitry Andric   }
530e8d8bef9SDimitry Andric 
531e8d8bef9SDimitry Andric   bool useFlatForGlobal() const {
532e8d8bef9SDimitry Andric     return FlatForGlobal;
533e8d8bef9SDimitry Andric   }
534e8d8bef9SDimitry Andric 
535e8d8bef9SDimitry Andric   /// \returns If target supports ds_read/write_b128 and user enables generation
536e8d8bef9SDimitry Andric   /// of ds_read/write_b128.
537e8d8bef9SDimitry Andric   bool useDS128() const {
538e8d8bef9SDimitry Andric     return CIInsts && EnableDS128;
539e8d8bef9SDimitry Andric   }
540e8d8bef9SDimitry Andric 
541e8d8bef9SDimitry Andric   /// \return If target supports ds_read/write_b96/128.
542e8d8bef9SDimitry Andric   bool hasDS96AndDS128() const {
543e8d8bef9SDimitry Andric     return CIInsts;
544e8d8bef9SDimitry Andric   }
545e8d8bef9SDimitry Andric 
546e8d8bef9SDimitry Andric   /// Have v_trunc_f64, v_ceil_f64, v_rndne_f64
547e8d8bef9SDimitry Andric   bool haveRoundOpsF64() const {
548e8d8bef9SDimitry Andric     return CIInsts;
549e8d8bef9SDimitry Andric   }
550e8d8bef9SDimitry Andric 
551e8d8bef9SDimitry Andric   /// \returns If MUBUF instructions always perform range checking, even for
552e8d8bef9SDimitry Andric   /// buffer resources used for private memory access.
553e8d8bef9SDimitry Andric   bool privateMemoryResourceIsRangeChecked() const {
554e8d8bef9SDimitry Andric     return getGeneration() < AMDGPUSubtarget::GFX9;
555e8d8bef9SDimitry Andric   }
556e8d8bef9SDimitry Andric 
557e8d8bef9SDimitry Andric   /// \returns If target requires PRT Struct NULL support (zero result registers
558e8d8bef9SDimitry Andric   /// for sparse texture support).
559e8d8bef9SDimitry Andric   bool usePRTStrictNull() const {
560e8d8bef9SDimitry Andric     return EnablePRTStrictNull;
561e8d8bef9SDimitry Andric   }
562e8d8bef9SDimitry Andric 
563e8d8bef9SDimitry Andric   bool hasAutoWaitcntBeforeBarrier() const {
564e8d8bef9SDimitry Andric     return AutoWaitcntBeforeBarrier;
565e8d8bef9SDimitry Andric   }
566e8d8bef9SDimitry Andric 
567bdd1243dSDimitry Andric   /// \returns true if the target supports backing off of s_barrier instructions
568bdd1243dSDimitry Andric   /// when an exception is raised.
569bdd1243dSDimitry Andric   bool supportsBackOffBarrier() const {
570bdd1243dSDimitry Andric     return BackOffBarrier;
571bdd1243dSDimitry Andric   }
572bdd1243dSDimitry Andric 
573e8d8bef9SDimitry Andric   bool hasUnalignedBufferAccess() const {
574e8d8bef9SDimitry Andric     return UnalignedBufferAccess;
575e8d8bef9SDimitry Andric   }
576e8d8bef9SDimitry Andric 
577e8d8bef9SDimitry Andric   bool hasUnalignedBufferAccessEnabled() const {
578e8d8bef9SDimitry Andric     return UnalignedBufferAccess && UnalignedAccessMode;
579e8d8bef9SDimitry Andric   }
580e8d8bef9SDimitry Andric 
581e8d8bef9SDimitry Andric   bool hasUnalignedDSAccess() const {
582e8d8bef9SDimitry Andric     return UnalignedDSAccess;
583e8d8bef9SDimitry Andric   }
584e8d8bef9SDimitry Andric 
585e8d8bef9SDimitry Andric   bool hasUnalignedDSAccessEnabled() const {
586e8d8bef9SDimitry Andric     return UnalignedDSAccess && UnalignedAccessMode;
587e8d8bef9SDimitry Andric   }
588e8d8bef9SDimitry Andric 
589e8d8bef9SDimitry Andric   bool hasUnalignedScratchAccess() const {
590e8d8bef9SDimitry Andric     return UnalignedScratchAccess;
591e8d8bef9SDimitry Andric   }
592e8d8bef9SDimitry Andric 
593e8d8bef9SDimitry Andric   bool hasUnalignedAccessMode() const {
594e8d8bef9SDimitry Andric     return UnalignedAccessMode;
595e8d8bef9SDimitry Andric   }
596e8d8bef9SDimitry Andric 
597e8d8bef9SDimitry Andric   bool hasApertureRegs() const {
598e8d8bef9SDimitry Andric     return HasApertureRegs;
599e8d8bef9SDimitry Andric   }
600e8d8bef9SDimitry Andric 
601e8d8bef9SDimitry Andric   bool isTrapHandlerEnabled() const {
602e8d8bef9SDimitry Andric     return TrapHandler;
603e8d8bef9SDimitry Andric   }
604e8d8bef9SDimitry Andric 
605e8d8bef9SDimitry Andric   bool isXNACKEnabled() const {
606e8d8bef9SDimitry Andric     return TargetID.isXnackOnOrAny();
607e8d8bef9SDimitry Andric   }
608e8d8bef9SDimitry Andric 
609fe6060f1SDimitry Andric   bool isTgSplitEnabled() const {
610fe6060f1SDimitry Andric     return EnableTgSplit;
611fe6060f1SDimitry Andric   }
612fe6060f1SDimitry Andric 
613e8d8bef9SDimitry Andric   bool isCuModeEnabled() const {
614e8d8bef9SDimitry Andric     return EnableCuMode;
615e8d8bef9SDimitry Andric   }
616e8d8bef9SDimitry Andric 
617*0fca6ea1SDimitry Andric   bool isPreciseMemoryEnabled() const { return EnablePreciseMemory; }
618*0fca6ea1SDimitry Andric 
619e8d8bef9SDimitry Andric   bool hasFlatAddressSpace() const {
620e8d8bef9SDimitry Andric     return FlatAddressSpace;
621e8d8bef9SDimitry Andric   }
622e8d8bef9SDimitry Andric 
623e8d8bef9SDimitry Andric   bool hasFlatScrRegister() const {
624e8d8bef9SDimitry Andric     return hasFlatAddressSpace();
625e8d8bef9SDimitry Andric   }
626e8d8bef9SDimitry Andric 
627e8d8bef9SDimitry Andric   bool hasFlatInstOffsets() const {
628e8d8bef9SDimitry Andric     return FlatInstOffsets;
629e8d8bef9SDimitry Andric   }
630e8d8bef9SDimitry Andric 
631e8d8bef9SDimitry Andric   bool hasFlatGlobalInsts() const {
632e8d8bef9SDimitry Andric     return FlatGlobalInsts;
633e8d8bef9SDimitry Andric   }
634e8d8bef9SDimitry Andric 
635e8d8bef9SDimitry Andric   bool hasFlatScratchInsts() const {
636e8d8bef9SDimitry Andric     return FlatScratchInsts;
637e8d8bef9SDimitry Andric   }
638e8d8bef9SDimitry Andric 
639e8d8bef9SDimitry Andric   // Check if target supports ST addressing mode with FLAT scratch instructions.
640e8d8bef9SDimitry Andric   // The ST addressing mode means no registers are used, either VGPR or SGPR,
641e8d8bef9SDimitry Andric   // but only immediate offset is swizzled and added to the FLAT scratch base.
642e8d8bef9SDimitry Andric   bool hasFlatScratchSTMode() const {
64381ad6265SDimitry Andric     return hasFlatScratchInsts() && (hasGFX10_3Insts() || hasGFX940Insts());
644e8d8bef9SDimitry Andric   }
645e8d8bef9SDimitry Andric 
64681ad6265SDimitry Andric   bool hasFlatScratchSVSMode() const { return GFX940Insts || GFX11Insts; }
64781ad6265SDimitry Andric 
648e8d8bef9SDimitry Andric   bool hasScalarFlatScratchInsts() const {
649e8d8bef9SDimitry Andric     return ScalarFlatScratchInsts;
650e8d8bef9SDimitry Andric   }
651e8d8bef9SDimitry Andric 
65281ad6265SDimitry Andric   bool enableFlatScratch() const {
65381ad6265SDimitry Andric     return flatScratchIsArchitected() ||
65481ad6265SDimitry Andric            (EnableFlatScratch && hasFlatScratchInsts());
65581ad6265SDimitry Andric   }
65681ad6265SDimitry Andric 
657e8d8bef9SDimitry Andric   bool hasGlobalAddTidInsts() const {
658e8d8bef9SDimitry Andric     return GFX10_BEncoding;
659e8d8bef9SDimitry Andric   }
660e8d8bef9SDimitry Andric 
661e8d8bef9SDimitry Andric   bool hasAtomicCSub() const {
662e8d8bef9SDimitry Andric     return GFX10_BEncoding;
663e8d8bef9SDimitry Andric   }
664e8d8bef9SDimitry Andric 
665*0fca6ea1SDimitry Andric   bool hasExportInsts() const {
666*0fca6ea1SDimitry Andric     return !hasGFX940Insts();
667*0fca6ea1SDimitry Andric   }
668*0fca6ea1SDimitry Andric 
669*0fca6ea1SDimitry Andric   bool hasVINTERPEncoding() const {
670*0fca6ea1SDimitry Andric     return GFX11Insts;
671*0fca6ea1SDimitry Andric   }
672*0fca6ea1SDimitry Andric 
673*0fca6ea1SDimitry Andric   // DS_ADD_F64/DS_ADD_RTN_F64
674*0fca6ea1SDimitry Andric   bool hasLdsAtomicAddF64() const { return hasGFX90AInsts(); }
675*0fca6ea1SDimitry Andric 
676e8d8bef9SDimitry Andric   bool hasMultiDwordFlatScratchAddressing() const {
677e8d8bef9SDimitry Andric     return getGeneration() >= GFX9;
678e8d8bef9SDimitry Andric   }
679e8d8bef9SDimitry Andric 
680e8d8bef9SDimitry Andric   bool hasFlatSegmentOffsetBug() const {
681e8d8bef9SDimitry Andric     return HasFlatSegmentOffsetBug;
682e8d8bef9SDimitry Andric   }
683e8d8bef9SDimitry Andric 
684e8d8bef9SDimitry Andric   bool hasFlatLgkmVMemCountInOrder() const {
685e8d8bef9SDimitry Andric     return getGeneration() > GFX9;
686e8d8bef9SDimitry Andric   }
687e8d8bef9SDimitry Andric 
688e8d8bef9SDimitry Andric   bool hasD16LoadStore() const {
689e8d8bef9SDimitry Andric     return getGeneration() >= GFX9;
690e8d8bef9SDimitry Andric   }
691e8d8bef9SDimitry Andric 
692e8d8bef9SDimitry Andric   bool d16PreservesUnusedBits() const {
693e8d8bef9SDimitry Andric     return hasD16LoadStore() && !TargetID.isSramEccOnOrAny();
694e8d8bef9SDimitry Andric   }
695e8d8bef9SDimitry Andric 
696e8d8bef9SDimitry Andric   bool hasD16Images() const {
697e8d8bef9SDimitry Andric     return getGeneration() >= VOLCANIC_ISLANDS;
698e8d8bef9SDimitry Andric   }
699e8d8bef9SDimitry Andric 
700e8d8bef9SDimitry Andric   /// Return if most LDS instructions have an m0 use that require m0 to be
701349cc55cSDimitry Andric   /// initialized.
702e8d8bef9SDimitry Andric   bool ldsRequiresM0Init() const {
703e8d8bef9SDimitry Andric     return getGeneration() < GFX9;
704e8d8bef9SDimitry Andric   }
705e8d8bef9SDimitry Andric 
706e8d8bef9SDimitry Andric   // True if the hardware rewinds and replays GWS operations if a wave is
707e8d8bef9SDimitry Andric   // preempted.
708e8d8bef9SDimitry Andric   //
709e8d8bef9SDimitry Andric   // If this is false, a GWS operation requires testing if a nack set the
710e8d8bef9SDimitry Andric   // MEM_VIOL bit, and repeating if so.
711e8d8bef9SDimitry Andric   bool hasGWSAutoReplay() const {
712e8d8bef9SDimitry Andric     return getGeneration() >= GFX9;
713e8d8bef9SDimitry Andric   }
714e8d8bef9SDimitry Andric 
715e8d8bef9SDimitry Andric   /// \returns if target has ds_gws_sema_release_all instruction.
716e8d8bef9SDimitry Andric   bool hasGWSSemaReleaseAll() const {
717e8d8bef9SDimitry Andric     return CIInsts;
718e8d8bef9SDimitry Andric   }
719e8d8bef9SDimitry Andric 
720e8d8bef9SDimitry Andric   /// \returns true if the target has integer add/sub instructions that do not
721e8d8bef9SDimitry Andric   /// produce a carry-out. This includes v_add_[iu]32, v_sub_[iu]32,
722e8d8bef9SDimitry Andric   /// v_add_[iu]16, and v_sub_[iu]16, all of which support the clamp modifier
723e8d8bef9SDimitry Andric   /// for saturation.
724e8d8bef9SDimitry Andric   bool hasAddNoCarry() const {
725e8d8bef9SDimitry Andric     return AddNoCarryInsts;
726e8d8bef9SDimitry Andric   }
727e8d8bef9SDimitry Andric 
7285f757f3fSDimitry Andric   bool hasScalarAddSub64() const { return getGeneration() >= GFX12; }
7295f757f3fSDimitry Andric 
7301db9f3b2SDimitry Andric   bool hasScalarSMulU64() const { return getGeneration() >= GFX12; }
7311db9f3b2SDimitry Andric 
732e8d8bef9SDimitry Andric   bool hasUnpackedD16VMem() const {
733e8d8bef9SDimitry Andric     return HasUnpackedD16VMem;
734e8d8bef9SDimitry Andric   }
735e8d8bef9SDimitry Andric 
736e8d8bef9SDimitry Andric   // Covers VS/PS/CS graphics shaders
737e8d8bef9SDimitry Andric   bool isMesaGfxShader(const Function &F) const {
738e8d8bef9SDimitry Andric     return isMesa3DOS() && AMDGPU::isShader(F.getCallingConv());
739e8d8bef9SDimitry Andric   }
740e8d8bef9SDimitry Andric 
741e8d8bef9SDimitry Andric   bool hasMad64_32() const {
742e8d8bef9SDimitry Andric     return getGeneration() >= SEA_ISLANDS;
743e8d8bef9SDimitry Andric   }
744e8d8bef9SDimitry Andric 
745e8d8bef9SDimitry Andric   bool hasSDWAOmod() const {
746e8d8bef9SDimitry Andric     return HasSDWAOmod;
747e8d8bef9SDimitry Andric   }
748e8d8bef9SDimitry Andric 
749e8d8bef9SDimitry Andric   bool hasSDWAScalar() const {
750e8d8bef9SDimitry Andric     return HasSDWAScalar;
751e8d8bef9SDimitry Andric   }
752e8d8bef9SDimitry Andric 
753e8d8bef9SDimitry Andric   bool hasSDWASdst() const {
754e8d8bef9SDimitry Andric     return HasSDWASdst;
755e8d8bef9SDimitry Andric   }
756e8d8bef9SDimitry Andric 
757e8d8bef9SDimitry Andric   bool hasSDWAMac() const {
758e8d8bef9SDimitry Andric     return HasSDWAMac;
759e8d8bef9SDimitry Andric   }
760e8d8bef9SDimitry Andric 
761e8d8bef9SDimitry Andric   bool hasSDWAOutModsVOPC() const {
762e8d8bef9SDimitry Andric     return HasSDWAOutModsVOPC;
763e8d8bef9SDimitry Andric   }
764e8d8bef9SDimitry Andric 
765e8d8bef9SDimitry Andric   bool hasDLInsts() const {
766e8d8bef9SDimitry Andric     return HasDLInsts;
767e8d8bef9SDimitry Andric   }
768e8d8bef9SDimitry Andric 
769bdd1243dSDimitry Andric   bool hasFmacF64Inst() const { return HasFmacF64Inst; }
770bdd1243dSDimitry Andric 
771e8d8bef9SDimitry Andric   bool hasDot1Insts() const {
772e8d8bef9SDimitry Andric     return HasDot1Insts;
773e8d8bef9SDimitry Andric   }
774e8d8bef9SDimitry Andric 
775e8d8bef9SDimitry Andric   bool hasDot2Insts() const {
776e8d8bef9SDimitry Andric     return HasDot2Insts;
777e8d8bef9SDimitry Andric   }
778e8d8bef9SDimitry Andric 
779e8d8bef9SDimitry Andric   bool hasDot3Insts() const {
780e8d8bef9SDimitry Andric     return HasDot3Insts;
781e8d8bef9SDimitry Andric   }
782e8d8bef9SDimitry Andric 
783e8d8bef9SDimitry Andric   bool hasDot4Insts() const {
784e8d8bef9SDimitry Andric     return HasDot4Insts;
785e8d8bef9SDimitry Andric   }
786e8d8bef9SDimitry Andric 
787e8d8bef9SDimitry Andric   bool hasDot5Insts() const {
788e8d8bef9SDimitry Andric     return HasDot5Insts;
789e8d8bef9SDimitry Andric   }
790e8d8bef9SDimitry Andric 
791e8d8bef9SDimitry Andric   bool hasDot6Insts() const {
792e8d8bef9SDimitry Andric     return HasDot6Insts;
793e8d8bef9SDimitry Andric   }
794e8d8bef9SDimitry Andric 
795fe6060f1SDimitry Andric   bool hasDot7Insts() const {
796fe6060f1SDimitry Andric     return HasDot7Insts;
797fe6060f1SDimitry Andric   }
798fe6060f1SDimitry Andric 
79981ad6265SDimitry Andric   bool hasDot8Insts() const {
80081ad6265SDimitry Andric     return HasDot8Insts;
80181ad6265SDimitry Andric   }
80281ad6265SDimitry Andric 
803bdd1243dSDimitry Andric   bool hasDot9Insts() const {
804bdd1243dSDimitry Andric     return HasDot9Insts;
805bdd1243dSDimitry Andric   }
806bdd1243dSDimitry Andric 
80706c3fb27SDimitry Andric   bool hasDot10Insts() const {
80806c3fb27SDimitry Andric     return HasDot10Insts;
80906c3fb27SDimitry Andric   }
81006c3fb27SDimitry Andric 
811*0fca6ea1SDimitry Andric   bool hasDot11Insts() const {
812*0fca6ea1SDimitry Andric     return HasDot11Insts;
813*0fca6ea1SDimitry Andric   }
814*0fca6ea1SDimitry Andric 
815e8d8bef9SDimitry Andric   bool hasMAIInsts() const {
816e8d8bef9SDimitry Andric     return HasMAIInsts;
817e8d8bef9SDimitry Andric   }
818e8d8bef9SDimitry Andric 
819fcaf7f86SDimitry Andric   bool hasFP8Insts() const {
820fcaf7f86SDimitry Andric     return HasFP8Insts;
821fcaf7f86SDimitry Andric   }
822fcaf7f86SDimitry Andric 
8237a6dacacSDimitry Andric   bool hasFP8ConversionInsts() const { return HasFP8ConversionInsts; }
8247a6dacacSDimitry Andric 
825e8d8bef9SDimitry Andric   bool hasPkFmacF16Inst() const {
826e8d8bef9SDimitry Andric     return HasPkFmacF16Inst;
827e8d8bef9SDimitry Andric   }
828e8d8bef9SDimitry Andric 
829*0fca6ea1SDimitry Andric   bool hasAtomicFMinFMaxF32GlobalInsts() const {
830*0fca6ea1SDimitry Andric     return HasAtomicFMinFMaxF32GlobalInsts;
831*0fca6ea1SDimitry Andric   }
832*0fca6ea1SDimitry Andric 
833*0fca6ea1SDimitry Andric   bool hasAtomicFMinFMaxF64GlobalInsts() const {
834*0fca6ea1SDimitry Andric     return HasAtomicFMinFMaxF64GlobalInsts;
835*0fca6ea1SDimitry Andric   }
836*0fca6ea1SDimitry Andric 
837*0fca6ea1SDimitry Andric   bool hasAtomicFMinFMaxF32FlatInsts() const {
838*0fca6ea1SDimitry Andric     return HasAtomicFMinFMaxF32FlatInsts;
839*0fca6ea1SDimitry Andric   }
840*0fca6ea1SDimitry Andric 
841*0fca6ea1SDimitry Andric   bool hasAtomicFMinFMaxF64FlatInsts() const {
842*0fca6ea1SDimitry Andric     return HasAtomicFMinFMaxF64FlatInsts;
843*0fca6ea1SDimitry Andric   }
844*0fca6ea1SDimitry Andric 
84506c3fb27SDimitry Andric   bool hasAtomicDsPkAdd16Insts() const { return HasAtomicDsPkAdd16Insts; }
84606c3fb27SDimitry Andric 
84706c3fb27SDimitry Andric   bool hasAtomicFlatPkAdd16Insts() const { return HasAtomicFlatPkAdd16Insts; }
84806c3fb27SDimitry Andric 
849e8d8bef9SDimitry Andric   bool hasAtomicFaddInsts() const {
85081ad6265SDimitry Andric     return HasAtomicFaddRtnInsts || HasAtomicFaddNoRtnInsts;
851e8d8bef9SDimitry Andric   }
852e8d8bef9SDimitry Andric 
85381ad6265SDimitry Andric   bool hasAtomicFaddRtnInsts() const { return HasAtomicFaddRtnInsts; }
85481ad6265SDimitry Andric 
85581ad6265SDimitry Andric   bool hasAtomicFaddNoRtnInsts() const { return HasAtomicFaddNoRtnInsts; }
85681ad6265SDimitry Andric 
85706c3fb27SDimitry Andric   bool hasAtomicBufferGlobalPkAddF16NoRtnInsts() const {
85806c3fb27SDimitry Andric     return HasAtomicBufferGlobalPkAddF16NoRtnInsts;
85906c3fb27SDimitry Andric   }
86006c3fb27SDimitry Andric 
86106c3fb27SDimitry Andric   bool hasAtomicBufferGlobalPkAddF16Insts() const {
86206c3fb27SDimitry Andric     return HasAtomicBufferGlobalPkAddF16Insts;
86306c3fb27SDimitry Andric   }
86406c3fb27SDimitry Andric 
86506c3fb27SDimitry Andric   bool hasAtomicGlobalPkAddBF16Inst() const {
86606c3fb27SDimitry Andric     return HasAtomicGlobalPkAddBF16Inst;
86706c3fb27SDimitry Andric   }
86881ad6265SDimitry Andric 
869*0fca6ea1SDimitry Andric   bool hasAtomicBufferPkAddBF16Inst() const {
870*0fca6ea1SDimitry Andric     return HasAtomicBufferPkAddBF16Inst;
871*0fca6ea1SDimitry Andric   }
872*0fca6ea1SDimitry Andric 
873bdd1243dSDimitry Andric   bool hasFlatAtomicFaddF32Inst() const { return HasFlatAtomicFaddF32Inst; }
874bdd1243dSDimitry Andric 
875*0fca6ea1SDimitry Andric   /// \return true if the target has flat, global, and buffer atomic fadd for
876*0fca6ea1SDimitry Andric   /// double.
877*0fca6ea1SDimitry Andric   bool hasFlatBufferGlobalAtomicFaddF64Inst() const {
878*0fca6ea1SDimitry Andric     return HasFlatBufferGlobalAtomicFaddF64Inst;
879*0fca6ea1SDimitry Andric   }
880*0fca6ea1SDimitry Andric 
881*0fca6ea1SDimitry Andric   /// \return true if the target's flat, global, and buffer atomic fadd for
882*0fca6ea1SDimitry Andric   /// float supports denormal handling.
883*0fca6ea1SDimitry Andric   bool hasMemoryAtomicFaddF32DenormalSupport() const {
884*0fca6ea1SDimitry Andric     return HasMemoryAtomicFaddF32DenormalSupport;
885*0fca6ea1SDimitry Andric   }
886*0fca6ea1SDimitry Andric 
887*0fca6ea1SDimitry Andric   /// \return true if atomic operations targeting fine-grained memory work
888*0fca6ea1SDimitry Andric   /// correctly at device scope, in allocations in host or peer PCIe device
889*0fca6ea1SDimitry Andric   /// memory.
890*0fca6ea1SDimitry Andric   bool supportsAgentScopeFineGrainedRemoteMemoryAtomics() const {
891*0fca6ea1SDimitry Andric     return HasAgentScopeFineGrainedRemoteMemoryAtomics;
892*0fca6ea1SDimitry Andric   }
893*0fca6ea1SDimitry Andric 
8947a6dacacSDimitry Andric   bool hasDefaultComponentZero() const { return HasDefaultComponentZero; }
8957a6dacacSDimitry Andric 
8967a6dacacSDimitry Andric   bool hasDefaultComponentBroadcast() const {
8977a6dacacSDimitry Andric     return HasDefaultComponentBroadcast;
8987a6dacacSDimitry Andric   }
8997a6dacacSDimitry Andric 
900e8d8bef9SDimitry Andric   bool hasNoSdstCMPX() const {
901e8d8bef9SDimitry Andric     return HasNoSdstCMPX;
902e8d8bef9SDimitry Andric   }
903e8d8bef9SDimitry Andric 
904e8d8bef9SDimitry Andric   bool hasVscnt() const {
905e8d8bef9SDimitry Andric     return HasVscnt;
906e8d8bef9SDimitry Andric   }
907e8d8bef9SDimitry Andric 
908e8d8bef9SDimitry Andric   bool hasGetWaveIdInst() const {
909e8d8bef9SDimitry Andric     return HasGetWaveIdInst;
910e8d8bef9SDimitry Andric   }
911e8d8bef9SDimitry Andric 
912e8d8bef9SDimitry Andric   bool hasSMemTimeInst() const {
913e8d8bef9SDimitry Andric     return HasSMemTimeInst;
914e8d8bef9SDimitry Andric   }
915e8d8bef9SDimitry Andric 
916fe6060f1SDimitry Andric   bool hasShaderCyclesRegister() const {
917fe6060f1SDimitry Andric     return HasShaderCyclesRegister;
918fe6060f1SDimitry Andric   }
919fe6060f1SDimitry Andric 
9201db9f3b2SDimitry Andric   bool hasShaderCyclesHiLoRegisters() const {
9211db9f3b2SDimitry Andric     return HasShaderCyclesHiLoRegisters;
9221db9f3b2SDimitry Andric   }
9231db9f3b2SDimitry Andric 
924e8d8bef9SDimitry Andric   bool hasVOP3Literal() const {
925e8d8bef9SDimitry Andric     return HasVOP3Literal;
926e8d8bef9SDimitry Andric   }
927e8d8bef9SDimitry Andric 
928e8d8bef9SDimitry Andric   bool hasNoDataDepHazard() const {
929e8d8bef9SDimitry Andric     return HasNoDataDepHazard;
930e8d8bef9SDimitry Andric   }
931e8d8bef9SDimitry Andric 
932e8d8bef9SDimitry Andric   bool vmemWriteNeedsExpWaitcnt() const {
933e8d8bef9SDimitry Andric     return getGeneration() < SEA_ISLANDS;
934e8d8bef9SDimitry Andric   }
935e8d8bef9SDimitry Andric 
9367a6dacacSDimitry Andric   bool hasInstPrefetch() const {
9377a6dacacSDimitry Andric     return getGeneration() == GFX10 || getGeneration() == GFX11;
9387a6dacacSDimitry Andric   }
939bdd1243dSDimitry Andric 
9405f757f3fSDimitry Andric   bool hasPrefetch() const { return GFX12Insts; }
9415f757f3fSDimitry Andric 
9425f757f3fSDimitry Andric   // Has s_cmpk_* instructions.
9435f757f3fSDimitry Andric   bool hasSCmpK() const { return getGeneration() < GFX12; }
9445f757f3fSDimitry Andric 
945e8d8bef9SDimitry Andric   // Scratch is allocated in 256 dword per wave blocks for the entire
946349cc55cSDimitry Andric   // wavefront. When viewed from the perspective of an arbitrary workitem, this
947e8d8bef9SDimitry Andric   // is 4-byte aligned.
948e8d8bef9SDimitry Andric   //
949e8d8bef9SDimitry Andric   // Only 4-byte alignment is really needed to access anything. Transformations
950e8d8bef9SDimitry Andric   // on the pointer value itself may rely on the alignment / known low bits of
951e8d8bef9SDimitry Andric   // the pointer. Set this to something above the minimum to avoid needing
952e8d8bef9SDimitry Andric   // dynamic realignment in common cases.
953e8d8bef9SDimitry Andric   Align getStackAlignment() const { return Align(16); }
954e8d8bef9SDimitry Andric 
955e8d8bef9SDimitry Andric   bool enableMachineScheduler() const override {
956e8d8bef9SDimitry Andric     return true;
957e8d8bef9SDimitry Andric   }
958e8d8bef9SDimitry Andric 
959e8d8bef9SDimitry Andric   bool useAA() const override;
960e8d8bef9SDimitry Andric 
961e8d8bef9SDimitry Andric   bool enableSubRegLiveness() const override {
962e8d8bef9SDimitry Andric     return true;
963e8d8bef9SDimitry Andric   }
964e8d8bef9SDimitry Andric 
965e8d8bef9SDimitry Andric   void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b; }
966e8d8bef9SDimitry Andric   bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal; }
967e8d8bef9SDimitry Andric 
968e8d8bef9SDimitry Andric   // static wrappers
969e8d8bef9SDimitry Andric   static bool hasHalfRate64Ops(const TargetSubtargetInfo &STI);
970e8d8bef9SDimitry Andric 
971e8d8bef9SDimitry Andric   // XXX - Why is this here if it isn't in the default pass set?
972e8d8bef9SDimitry Andric   bool enableEarlyIfConversion() const override {
973e8d8bef9SDimitry Andric     return true;
974e8d8bef9SDimitry Andric   }
975e8d8bef9SDimitry Andric 
976e8d8bef9SDimitry Andric   void overrideSchedPolicy(MachineSchedPolicy &Policy,
977e8d8bef9SDimitry Andric                            unsigned NumRegionInstrs) const override;
978e8d8bef9SDimitry Andric 
979*0fca6ea1SDimitry Andric   void mirFileLoaded(MachineFunction &MF) const override;
980*0fca6ea1SDimitry Andric 
981e8d8bef9SDimitry Andric   unsigned getMaxNumUserSGPRs() const {
9825f757f3fSDimitry Andric     return AMDGPU::getMaxNumUserSGPRs(*this);
983e8d8bef9SDimitry Andric   }
984e8d8bef9SDimitry Andric 
985e8d8bef9SDimitry Andric   bool hasSMemRealTime() const {
986e8d8bef9SDimitry Andric     return HasSMemRealTime;
987e8d8bef9SDimitry Andric   }
988e8d8bef9SDimitry Andric 
989e8d8bef9SDimitry Andric   bool hasMovrel() const {
990e8d8bef9SDimitry Andric     return HasMovrel;
991e8d8bef9SDimitry Andric   }
992e8d8bef9SDimitry Andric 
993e8d8bef9SDimitry Andric   bool hasVGPRIndexMode() const {
994e8d8bef9SDimitry Andric     return HasVGPRIndexMode;
995e8d8bef9SDimitry Andric   }
996e8d8bef9SDimitry Andric 
997e8d8bef9SDimitry Andric   bool useVGPRIndexMode() const;
998e8d8bef9SDimitry Andric 
999e8d8bef9SDimitry Andric   bool hasScalarCompareEq64() const {
1000e8d8bef9SDimitry Andric     return getGeneration() >= VOLCANIC_ISLANDS;
1001e8d8bef9SDimitry Andric   }
1002e8d8bef9SDimitry Andric 
10035f757f3fSDimitry Andric   bool hasScalarDwordx3Loads() const { return HasScalarDwordx3Loads; }
10045f757f3fSDimitry Andric 
1005e8d8bef9SDimitry Andric   bool hasScalarStores() const {
1006e8d8bef9SDimitry Andric     return HasScalarStores;
1007e8d8bef9SDimitry Andric   }
1008e8d8bef9SDimitry Andric 
1009e8d8bef9SDimitry Andric   bool hasScalarAtomics() const {
1010e8d8bef9SDimitry Andric     return HasScalarAtomics;
1011e8d8bef9SDimitry Andric   }
1012e8d8bef9SDimitry Andric 
1013*0fca6ea1SDimitry Andric   bool hasLDSFPAtomicAddF32() const { return GFX8Insts; }
1014*0fca6ea1SDimitry Andric   bool hasLDSFPAtomicAddF64() const { return GFX90AInsts; }
1015e8d8bef9SDimitry Andric 
1016fe6060f1SDimitry Andric   /// \returns true if the subtarget has the v_permlanex16_b32 instruction.
1017fe6060f1SDimitry Andric   bool hasPermLaneX16() const { return getGeneration() >= GFX10; }
1018fe6060f1SDimitry Andric 
101981ad6265SDimitry Andric   /// \returns true if the subtarget has the v_permlane64_b32 instruction.
102081ad6265SDimitry Andric   bool hasPermLane64() const { return getGeneration() >= GFX11; }
102181ad6265SDimitry Andric 
1022e8d8bef9SDimitry Andric   bool hasDPP() const {
1023e8d8bef9SDimitry Andric     return HasDPP;
1024e8d8bef9SDimitry Andric   }
1025e8d8bef9SDimitry Andric 
1026e8d8bef9SDimitry Andric   bool hasDPPBroadcasts() const {
1027e8d8bef9SDimitry Andric     return HasDPP && getGeneration() < GFX10;
1028e8d8bef9SDimitry Andric   }
1029e8d8bef9SDimitry Andric 
1030e8d8bef9SDimitry Andric   bool hasDPPWavefrontShifts() const {
1031e8d8bef9SDimitry Andric     return HasDPP && getGeneration() < GFX10;
1032e8d8bef9SDimitry Andric   }
1033e8d8bef9SDimitry Andric 
1034e8d8bef9SDimitry Andric   bool hasDPP8() const {
1035e8d8bef9SDimitry Andric     return HasDPP8;
1036e8d8bef9SDimitry Andric   }
1037e8d8bef9SDimitry Andric 
10385f757f3fSDimitry Andric   bool hasDPALU_DPP() const {
10395f757f3fSDimitry Andric     return HasDPALU_DPP;
1040fe6060f1SDimitry Andric   }
1041fe6060f1SDimitry Andric 
10425f757f3fSDimitry Andric   bool hasDPPSrc1SGPR() const { return HasDPPSrc1SGPR; }
10435f757f3fSDimitry Andric 
1044fe6060f1SDimitry Andric   bool hasPackedFP32Ops() const {
1045fe6060f1SDimitry Andric     return HasPackedFP32Ops;
1046fe6060f1SDimitry Andric   }
1047fe6060f1SDimitry Andric 
10485f757f3fSDimitry Andric   // Has V_PK_MOV_B32 opcode
10495f757f3fSDimitry Andric   bool hasPkMovB32() const {
10505f757f3fSDimitry Andric     return GFX90AInsts;
10515f757f3fSDimitry Andric   }
10525f757f3fSDimitry Andric 
1053fe6060f1SDimitry Andric   bool hasFmaakFmamkF32Insts() const {
105481ad6265SDimitry Andric     return getGeneration() >= GFX10 || hasGFX940Insts();
105581ad6265SDimitry Andric   }
105681ad6265SDimitry Andric 
105781ad6265SDimitry Andric   bool hasImageInsts() const {
105881ad6265SDimitry Andric     return HasImageInsts;
1059fe6060f1SDimitry Andric   }
1060fe6060f1SDimitry Andric 
1061fe6060f1SDimitry Andric   bool hasExtendedImageInsts() const {
1062fe6060f1SDimitry Andric     return HasExtendedImageInsts;
1063fe6060f1SDimitry Andric   }
1064fe6060f1SDimitry Andric 
1065e8d8bef9SDimitry Andric   bool hasR128A16() const {
1066e8d8bef9SDimitry Andric     return HasR128A16;
1067e8d8bef9SDimitry Andric   }
1068e8d8bef9SDimitry Andric 
1069bdd1243dSDimitry Andric   bool hasA16() const { return HasA16; }
1070e8d8bef9SDimitry Andric 
1071e8d8bef9SDimitry Andric   bool hasG16() const { return HasG16; }
1072e8d8bef9SDimitry Andric 
1073e8d8bef9SDimitry Andric   bool hasOffset3fBug() const {
1074e8d8bef9SDimitry Andric     return HasOffset3fBug;
1075e8d8bef9SDimitry Andric   }
1076e8d8bef9SDimitry Andric 
1077e8d8bef9SDimitry Andric   bool hasImageStoreD16Bug() const { return HasImageStoreD16Bug; }
1078e8d8bef9SDimitry Andric 
1079e8d8bef9SDimitry Andric   bool hasImageGather4D16Bug() const { return HasImageGather4D16Bug; }
1080e8d8bef9SDimitry Andric 
1081bdd1243dSDimitry Andric   bool hasMADIntraFwdBug() const { return HasMADIntraFwdBug; }
1082bdd1243dSDimitry Andric 
10835f757f3fSDimitry Andric   bool hasMSAALoadDstSelBug() const { return HasMSAALoadDstSelBug; }
10845f757f3fSDimitry Andric 
1085*0fca6ea1SDimitry Andric   bool hasPrivEnabledTrap2NopBug() const { return HasPrivEnabledTrap2NopBug; }
1086*0fca6ea1SDimitry Andric 
1087e8d8bef9SDimitry Andric   bool hasNSAEncoding() const { return HasNSAEncoding; }
1088e8d8bef9SDimitry Andric 
10897a6dacacSDimitry Andric   bool hasNonNSAEncoding() const { return getGeneration() < GFX12; }
10907a6dacacSDimitry Andric 
109106c3fb27SDimitry Andric   bool hasPartialNSAEncoding() const { return HasPartialNSAEncoding; }
109206c3fb27SDimitry Andric 
10935f757f3fSDimitry Andric   unsigned getNSAMaxSize(bool HasSampler = false) const {
10945f757f3fSDimitry Andric     return AMDGPU::getNSAMaxSize(*this, HasSampler);
10955f757f3fSDimitry Andric   }
1096fe6060f1SDimitry Andric 
1097fe6060f1SDimitry Andric   bool hasGFX10_AEncoding() const {
1098fe6060f1SDimitry Andric     return GFX10_AEncoding;
1099fe6060f1SDimitry Andric   }
1100fe6060f1SDimitry Andric 
1101e8d8bef9SDimitry Andric   bool hasGFX10_BEncoding() const {
1102e8d8bef9SDimitry Andric     return GFX10_BEncoding;
1103e8d8bef9SDimitry Andric   }
1104e8d8bef9SDimitry Andric 
1105e8d8bef9SDimitry Andric   bool hasGFX10_3Insts() const {
1106e8d8bef9SDimitry Andric     return GFX10_3Insts;
1107e8d8bef9SDimitry Andric   }
1108e8d8bef9SDimitry Andric 
1109e8d8bef9SDimitry Andric   bool hasMadF16() const;
1110e8d8bef9SDimitry Andric 
111181ad6265SDimitry Andric   bool hasMovB64() const { return GFX940Insts; }
111281ad6265SDimitry Andric 
111381ad6265SDimitry Andric   bool hasLshlAddB64() const { return GFX940Insts; }
111481ad6265SDimitry Andric 
1115e8d8bef9SDimitry Andric   bool enableSIScheduler() const {
1116e8d8bef9SDimitry Andric     return EnableSIScheduler;
1117e8d8bef9SDimitry Andric   }
1118e8d8bef9SDimitry Andric 
1119e8d8bef9SDimitry Andric   bool loadStoreOptEnabled() const {
1120e8d8bef9SDimitry Andric     return EnableLoadStoreOpt;
1121e8d8bef9SDimitry Andric   }
1122e8d8bef9SDimitry Andric 
1123e8d8bef9SDimitry Andric   bool hasSGPRInitBug() const {
1124e8d8bef9SDimitry Andric     return SGPRInitBug;
1125e8d8bef9SDimitry Andric   }
1126e8d8bef9SDimitry Andric 
112781ad6265SDimitry Andric   bool hasUserSGPRInit16Bug() const {
1128fcaf7f86SDimitry Andric     return UserSGPRInit16Bug && isWave32();
112981ad6265SDimitry Andric   }
113081ad6265SDimitry Andric 
1131fe6060f1SDimitry Andric   bool hasNegativeScratchOffsetBug() const { return NegativeScratchOffsetBug; }
1132fe6060f1SDimitry Andric 
1133fe6060f1SDimitry Andric   bool hasNegativeUnalignedScratchOffsetBug() const {
1134fe6060f1SDimitry Andric     return NegativeUnalignedScratchOffsetBug;
1135fe6060f1SDimitry Andric   }
1136fe6060f1SDimitry Andric 
1137e8d8bef9SDimitry Andric   bool hasMFMAInlineLiteralBug() const {
1138e8d8bef9SDimitry Andric     return HasMFMAInlineLiteralBug;
1139e8d8bef9SDimitry Andric   }
1140e8d8bef9SDimitry Andric 
1141e8d8bef9SDimitry Andric   bool has12DWordStoreHazard() const {
1142e8d8bef9SDimitry Andric     return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
1143e8d8bef9SDimitry Andric   }
1144e8d8bef9SDimitry Andric 
1145e8d8bef9SDimitry Andric   // \returns true if the subtarget supports DWORDX3 load/store instructions.
1146e8d8bef9SDimitry Andric   bool hasDwordx3LoadStores() const {
1147e8d8bef9SDimitry Andric     return CIInsts;
1148e8d8bef9SDimitry Andric   }
1149e8d8bef9SDimitry Andric 
1150e8d8bef9SDimitry Andric   bool hasReadM0MovRelInterpHazard() const {
1151e8d8bef9SDimitry Andric     return getGeneration() == AMDGPUSubtarget::GFX9;
1152e8d8bef9SDimitry Andric   }
1153e8d8bef9SDimitry Andric 
1154e8d8bef9SDimitry Andric   bool hasReadM0SendMsgHazard() const {
1155e8d8bef9SDimitry Andric     return getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS &&
1156e8d8bef9SDimitry Andric            getGeneration() <= AMDGPUSubtarget::GFX9;
1157e8d8bef9SDimitry Andric   }
1158e8d8bef9SDimitry Andric 
115981ad6265SDimitry Andric   bool hasReadM0LdsDmaHazard() const {
116081ad6265SDimitry Andric     return getGeneration() == AMDGPUSubtarget::GFX9;
116181ad6265SDimitry Andric   }
116281ad6265SDimitry Andric 
116381ad6265SDimitry Andric   bool hasReadM0LdsDirectHazard() const {
116481ad6265SDimitry Andric     return getGeneration() == AMDGPUSubtarget::GFX9;
116581ad6265SDimitry Andric   }
116681ad6265SDimitry Andric 
1167e8d8bef9SDimitry Andric   bool hasVcmpxPermlaneHazard() const {
1168e8d8bef9SDimitry Andric     return HasVcmpxPermlaneHazard;
1169e8d8bef9SDimitry Andric   }
1170e8d8bef9SDimitry Andric 
1171e8d8bef9SDimitry Andric   bool hasVMEMtoScalarWriteHazard() const {
1172e8d8bef9SDimitry Andric     return HasVMEMtoScalarWriteHazard;
1173e8d8bef9SDimitry Andric   }
1174e8d8bef9SDimitry Andric 
1175e8d8bef9SDimitry Andric   bool hasSMEMtoVectorWriteHazard() const {
1176e8d8bef9SDimitry Andric     return HasSMEMtoVectorWriteHazard;
1177e8d8bef9SDimitry Andric   }
1178e8d8bef9SDimitry Andric 
1179e8d8bef9SDimitry Andric   bool hasLDSMisalignedBug() const {
1180e8d8bef9SDimitry Andric     return LDSMisalignedBug && !EnableCuMode;
1181e8d8bef9SDimitry Andric   }
1182e8d8bef9SDimitry Andric 
1183e8d8bef9SDimitry Andric   bool hasInstFwdPrefetchBug() const {
1184e8d8bef9SDimitry Andric     return HasInstFwdPrefetchBug;
1185e8d8bef9SDimitry Andric   }
1186e8d8bef9SDimitry Andric 
1187e8d8bef9SDimitry Andric   bool hasVcmpxExecWARHazard() const {
1188e8d8bef9SDimitry Andric     return HasVcmpxExecWARHazard;
1189e8d8bef9SDimitry Andric   }
1190e8d8bef9SDimitry Andric 
1191e8d8bef9SDimitry Andric   bool hasLdsBranchVmemWARHazard() const {
1192e8d8bef9SDimitry Andric     return HasLdsBranchVmemWARHazard;
1193e8d8bef9SDimitry Andric   }
1194e8d8bef9SDimitry Andric 
1195bdd1243dSDimitry Andric   // Shift amount of a 64 bit shift cannot be a highest allocated register
1196bdd1243dSDimitry Andric   // if also at the end of the allocation block.
1197bdd1243dSDimitry Andric   bool hasShift64HighRegBug() const {
1198bdd1243dSDimitry Andric     return GFX90AInsts && !GFX940Insts;
1199bdd1243dSDimitry Andric   }
1200bdd1243dSDimitry Andric 
120181ad6265SDimitry Andric   // Has one cycle hazard on transcendental instruction feeding a
120281ad6265SDimitry Andric   // non transcendental VALU.
120381ad6265SDimitry Andric   bool hasTransForwardingHazard() const { return GFX940Insts; }
120481ad6265SDimitry Andric 
120581ad6265SDimitry Andric   // Has one cycle hazard on a VALU instruction partially writing dst with
120681ad6265SDimitry Andric   // a shift of result bits feeding another VALU instruction.
120781ad6265SDimitry Andric   bool hasDstSelForwardingHazard() const { return GFX940Insts; }
120881ad6265SDimitry Andric 
120981ad6265SDimitry Andric   // Cannot use op_sel with v_dot instructions.
12101db9f3b2SDimitry Andric   bool hasDOTOpSelHazard() const { return GFX940Insts || GFX11Insts; }
121181ad6265SDimitry Andric 
121281ad6265SDimitry Andric   // Does not have HW interlocs for VALU writing and then reading SGPRs.
121381ad6265SDimitry Andric   bool hasVDecCoExecHazard() const {
121481ad6265SDimitry Andric     return GFX940Insts;
121581ad6265SDimitry Andric   }
121681ad6265SDimitry Andric 
1217e8d8bef9SDimitry Andric   bool hasNSAtoVMEMBug() const {
1218e8d8bef9SDimitry Andric     return HasNSAtoVMEMBug;
1219e8d8bef9SDimitry Andric   }
1220e8d8bef9SDimitry Andric 
1221fe6060f1SDimitry Andric   bool hasNSAClauseBug() const { return HasNSAClauseBug; }
1222fe6060f1SDimitry Andric 
1223*0fca6ea1SDimitry Andric   bool hasHardClauses() const { return MaxHardClauseLength > 0; }
1224e8d8bef9SDimitry Andric 
1225fe6060f1SDimitry Andric   bool hasGFX90AInsts() const { return GFX90AInsts; }
1226fe6060f1SDimitry Andric 
1227bdd1243dSDimitry Andric   bool hasFPAtomicToDenormModeHazard() const {
1228bdd1243dSDimitry Andric     return getGeneration() == GFX10;
1229bdd1243dSDimitry Andric   }
1230bdd1243dSDimitry Andric 
123181ad6265SDimitry Andric   bool hasVOP3DPP() const { return getGeneration() >= GFX11; }
123281ad6265SDimitry Andric 
123381ad6265SDimitry Andric   bool hasLdsDirect() const { return getGeneration() >= GFX11; }
123481ad6265SDimitry Andric 
1235297eecfbSDimitry Andric   bool hasLdsWaitVMSRC() const { return getGeneration() >= GFX12; }
1236297eecfbSDimitry Andric 
123781ad6265SDimitry Andric   bool hasVALUPartialForwardingHazard() const {
12387a6dacacSDimitry Andric     return getGeneration() == GFX11;
123981ad6265SDimitry Andric   }
124081ad6265SDimitry Andric 
1241bdd1243dSDimitry Andric   bool hasVALUTransUseHazard() const { return HasVALUTransUseHazard; }
1242bdd1243dSDimitry Andric 
124306c3fb27SDimitry Andric   bool hasForceStoreSC0SC1() const { return HasForceStoreSC0SC1; }
124406c3fb27SDimitry Andric 
1245*0fca6ea1SDimitry Andric   bool requiresCodeObjectV6() const { return RequiresCOV6; }
1246*0fca6ea1SDimitry Andric 
12477a6dacacSDimitry Andric   bool hasVALUMaskWriteHazard() const { return getGeneration() == GFX11; }
124881ad6265SDimitry Andric 
1249fe6060f1SDimitry Andric   /// Return if operations acting on VGPR tuples require even alignment.
1250fe6060f1SDimitry Andric   bool needsAlignedVGPRs() const { return GFX90AInsts; }
1251fe6060f1SDimitry Andric 
125281ad6265SDimitry Andric   /// Return true if the target has the S_PACK_HL_B32_B16 instruction.
125381ad6265SDimitry Andric   bool hasSPackHL() const { return GFX11Insts; }
125481ad6265SDimitry Andric 
125581ad6265SDimitry Andric   /// Return true if the target's EXP instruction has the COMPR flag, which
125681ad6265SDimitry Andric   /// affects the meaning of the EN (enable) bits.
125781ad6265SDimitry Andric   bool hasCompressedExport() const { return !GFX11Insts; }
125881ad6265SDimitry Andric 
125981ad6265SDimitry Andric   /// Return true if the target's EXP instruction supports the NULL export
126081ad6265SDimitry Andric   /// target.
126181ad6265SDimitry Andric   bool hasNullExportTarget() const { return !GFX11Insts; }
126281ad6265SDimitry Andric 
1263*0fca6ea1SDimitry Andric   bool has1_5xVGPRs() const { return Has1_5xVGPRs; }
1264bdd1243dSDimitry Andric 
126581ad6265SDimitry Andric   bool hasVOPDInsts() const { return HasVOPDInsts; }
126681ad6265SDimitry Andric 
126781ad6265SDimitry Andric   bool hasFlatScratchSVSSwizzleBug() const { return getGeneration() == GFX11; }
126881ad6265SDimitry Andric 
126981ad6265SDimitry Andric   /// Return true if the target has the S_DELAY_ALU instruction.
127081ad6265SDimitry Andric   bool hasDelayAlu() const { return GFX11Insts; }
127181ad6265SDimitry Andric 
1272fe6060f1SDimitry Andric   bool hasPackedTID() const { return HasPackedTID; }
1273fe6060f1SDimitry Andric 
127481ad6265SDimitry Andric   // GFX940 is a derivation to GFX90A. hasGFX940Insts() being true implies that
127581ad6265SDimitry Andric   // hasGFX90AInsts is also true.
127681ad6265SDimitry Andric   bool hasGFX940Insts() const { return GFX940Insts; }
127781ad6265SDimitry Andric 
12785f757f3fSDimitry Andric   bool hasSALUFloatInsts() const { return HasSALUFloatInsts; }
12795f757f3fSDimitry Andric 
12805f757f3fSDimitry Andric   bool hasVGPRSingleUseHintInsts() const { return HasVGPRSingleUseHintInsts; }
12815f757f3fSDimitry Andric 
12825f757f3fSDimitry Andric   bool hasPseudoScalarTrans() const { return HasPseudoScalarTrans; }
12835f757f3fSDimitry Andric 
12845f757f3fSDimitry Andric   bool hasRestrictedSOffset() const { return HasRestrictedSOffset; }
12855f757f3fSDimitry Andric 
1286*0fca6ea1SDimitry Andric   bool hasRequiredExportPriority() const { return HasRequiredExportPriority; }
1287*0fca6ea1SDimitry Andric 
12887a6dacacSDimitry Andric   /// \returns true if the target uses LOADcnt/SAMPLEcnt/BVHcnt, DScnt/KMcnt
12897a6dacacSDimitry Andric   /// and STOREcnt rather than VMcnt, LGKMcnt and VScnt respectively.
12907a6dacacSDimitry Andric   bool hasExtendedWaitCounts() const { return getGeneration() >= GFX12; }
12917a6dacacSDimitry Andric 
1292*0fca6ea1SDimitry Andric   /// \returns The maximum number of instructions that can be enclosed in an
1293*0fca6ea1SDimitry Andric   /// S_CLAUSE on the given subtarget, or 0 for targets that do not support that
1294*0fca6ea1SDimitry Andric   /// instruction.
1295*0fca6ea1SDimitry Andric   unsigned maxHardClauseLength() const { return MaxHardClauseLength; }
1296*0fca6ea1SDimitry Andric 
1297e8d8bef9SDimitry Andric   /// Return the maximum number of waves per SIMD for kernels using \p SGPRs
1298e8d8bef9SDimitry Andric   /// SGPRs
1299e8d8bef9SDimitry Andric   unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
1300e8d8bef9SDimitry Andric 
1301e8d8bef9SDimitry Andric   /// Return the maximum number of waves per SIMD for kernels using \p VGPRs
1302e8d8bef9SDimitry Andric   /// VGPRs
1303e8d8bef9SDimitry Andric   unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
1304e8d8bef9SDimitry Andric 
1305e8d8bef9SDimitry Andric   /// Return occupancy for the given function. Used LDS and a number of
1306e8d8bef9SDimitry Andric   /// registers if provided.
1307e8d8bef9SDimitry Andric   /// Note, occupancy can be affected by the scratch allocation as well, but
1308e8d8bef9SDimitry Andric   /// we do not have enough information to compute it.
1309e8d8bef9SDimitry Andric   unsigned computeOccupancy(const Function &F, unsigned LDSSize = 0,
1310e8d8bef9SDimitry Andric                             unsigned NumSGPRs = 0, unsigned NumVGPRs = 0) const;
1311e8d8bef9SDimitry Andric 
1312e8d8bef9SDimitry Andric   /// \returns true if the flat_scratch register should be initialized with the
1313e8d8bef9SDimitry Andric   /// pointer to the wave's scratch memory rather than a size and offset.
1314e8d8bef9SDimitry Andric   bool flatScratchIsPointer() const {
1315e8d8bef9SDimitry Andric     return getGeneration() >= AMDGPUSubtarget::GFX9;
1316e8d8bef9SDimitry Andric   }
1317e8d8bef9SDimitry Andric 
1318fe6060f1SDimitry Andric   /// \returns true if the flat_scratch register is initialized by the HW.
1319fe6060f1SDimitry Andric   /// In this case it is readonly.
1320fe6060f1SDimitry Andric   bool flatScratchIsArchitected() const { return HasArchitectedFlatScratch; }
1321fe6060f1SDimitry Andric 
132206c3fb27SDimitry Andric   /// \returns true if the architected SGPRs are enabled.
132306c3fb27SDimitry Andric   bool hasArchitectedSGPRs() const { return HasArchitectedSGPRs; }
132406c3fb27SDimitry Andric 
13255f757f3fSDimitry Andric   /// \returns true if Global Data Share is supported.
13265f757f3fSDimitry Andric   bool hasGDS() const { return HasGDS; }
13275f757f3fSDimitry Andric 
13285f757f3fSDimitry Andric   /// \returns true if Global Wave Sync is supported.
13295f757f3fSDimitry Andric   bool hasGWS() const { return HasGWS; }
13305f757f3fSDimitry Andric 
1331e8d8bef9SDimitry Andric   /// \returns true if the machine has merged shaders in which s0-s7 are
1332e8d8bef9SDimitry Andric   /// reserved by the hardware and user SGPRs start at s8
1333e8d8bef9SDimitry Andric   bool hasMergedShaders() const {
1334e8d8bef9SDimitry Andric     return getGeneration() >= GFX9;
1335e8d8bef9SDimitry Andric   }
1336e8d8bef9SDimitry Andric 
133781ad6265SDimitry Andric   // \returns true if the target supports the pre-NGG legacy geometry path.
133881ad6265SDimitry Andric   bool hasLegacyGeometry() const { return getGeneration() < GFX11; }
133981ad6265SDimitry Andric 
13405f757f3fSDimitry Andric   // \returns true if preloading kernel arguments is supported.
13415f757f3fSDimitry Andric   bool hasKernargPreload() const { return KernargPreload; }
13425f757f3fSDimitry Andric 
13435f757f3fSDimitry Andric   // \returns true if the target has split barriers feature
13445f757f3fSDimitry Andric   bool hasSplitBarriers() const { return getGeneration() >= GFX12; }
13455f757f3fSDimitry Andric 
13465f757f3fSDimitry Andric   // \returns true if FP8/BF8 VOP1 form of conversion to F32 is unreliable.
13475f757f3fSDimitry Andric   bool hasCvtFP8VOP1Bug() const { return true; }
13485f757f3fSDimitry Andric 
13495f757f3fSDimitry Andric   // \returns true if CSUB (a.k.a. SUB_CLAMP on GFX12) atomics support a
13505f757f3fSDimitry Andric   // no-return form.
13515f757f3fSDimitry Andric   bool hasAtomicCSubNoRtnInsts() const { return HasAtomicCSubNoRtnInsts; }
13525f757f3fSDimitry Andric 
13535f757f3fSDimitry Andric   // \returns true if the target has DX10_CLAMP kernel descriptor mode bit
13545f757f3fSDimitry Andric   bool hasDX10ClampMode() const { return getGeneration() < GFX12; }
13555f757f3fSDimitry Andric 
13565f757f3fSDimitry Andric   // \returns true if the target has IEEE kernel descriptor mode bit
13575f757f3fSDimitry Andric   bool hasIEEEMode() const { return getGeneration() < GFX12; }
13585f757f3fSDimitry Andric 
13595f757f3fSDimitry Andric   // \returns true if the target has IEEE fminimum/fmaximum instructions
13605f757f3fSDimitry Andric   bool hasIEEEMinMax() const { return getGeneration() >= GFX12; }
13615f757f3fSDimitry Andric 
1362*0fca6ea1SDimitry Andric   // \returns true if the target has IEEE fminimum3/fmaximum3 instructions
1363*0fca6ea1SDimitry Andric   bool hasIEEEMinMax3() const { return hasIEEEMinMax(); }
1364*0fca6ea1SDimitry Andric 
13655f757f3fSDimitry Andric   // \returns true if the target has WG_RR_MODE kernel descriptor mode bit
13665f757f3fSDimitry Andric   bool hasRrWGMode() const { return getGeneration() >= GFX12; }
13675f757f3fSDimitry Andric 
13687a6dacacSDimitry Andric   /// \returns true if VADDR and SADDR fields in VSCRATCH can use negative
13697a6dacacSDimitry Andric   /// values.
13707a6dacacSDimitry Andric   bool hasSignedScratchOffsets() const { return getGeneration() >= GFX12; }
13717a6dacacSDimitry Andric 
13727a6dacacSDimitry Andric   // \returns true if S_GETPC_B64 zero-extends the result from 48 bits instead
13737a6dacacSDimitry Andric   // of sign-extending.
13747a6dacacSDimitry Andric   bool hasGetPCZeroExtension() const { return GFX12Insts; }
13757a6dacacSDimitry Andric 
1376e8d8bef9SDimitry Andric   /// \returns SGPR allocation granularity supported by the subtarget.
1377e8d8bef9SDimitry Andric   unsigned getSGPRAllocGranule() const {
1378e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getSGPRAllocGranule(this);
1379e8d8bef9SDimitry Andric   }
1380e8d8bef9SDimitry Andric 
1381e8d8bef9SDimitry Andric   /// \returns SGPR encoding granularity supported by the subtarget.
1382e8d8bef9SDimitry Andric   unsigned getSGPREncodingGranule() const {
1383e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getSGPREncodingGranule(this);
1384e8d8bef9SDimitry Andric   }
1385e8d8bef9SDimitry Andric 
1386e8d8bef9SDimitry Andric   /// \returns Total number of SGPRs supported by the subtarget.
1387e8d8bef9SDimitry Andric   unsigned getTotalNumSGPRs() const {
1388e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getTotalNumSGPRs(this);
1389e8d8bef9SDimitry Andric   }
1390e8d8bef9SDimitry Andric 
1391e8d8bef9SDimitry Andric   /// \returns Addressable number of SGPRs supported by the subtarget.
1392e8d8bef9SDimitry Andric   unsigned getAddressableNumSGPRs() const {
1393e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getAddressableNumSGPRs(this);
1394e8d8bef9SDimitry Andric   }
1395e8d8bef9SDimitry Andric 
1396e8d8bef9SDimitry Andric   /// \returns Minimum number of SGPRs that meets the given number of waves per
1397e8d8bef9SDimitry Andric   /// execution unit requirement supported by the subtarget.
1398e8d8bef9SDimitry Andric   unsigned getMinNumSGPRs(unsigned WavesPerEU) const {
1399e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getMinNumSGPRs(this, WavesPerEU);
1400e8d8bef9SDimitry Andric   }
1401e8d8bef9SDimitry Andric 
1402e8d8bef9SDimitry Andric   /// \returns Maximum number of SGPRs that meets the given number of waves per
1403e8d8bef9SDimitry Andric   /// execution unit requirement supported by the subtarget.
1404e8d8bef9SDimitry Andric   unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
1405e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getMaxNumSGPRs(this, WavesPerEU, Addressable);
1406e8d8bef9SDimitry Andric   }
1407e8d8bef9SDimitry Andric 
1408fe6060f1SDimitry Andric   /// \returns Reserved number of SGPRs. This is common
1409fe6060f1SDimitry Andric   /// utility function called by MachineFunction and
1410fe6060f1SDimitry Andric   /// Function variants of getReservedNumSGPRs.
141104eeddc0SDimitry Andric   unsigned getBaseReservedNumSGPRs(const bool HasFlatScratch) const;
1412fe6060f1SDimitry Andric   /// \returns Reserved number of SGPRs for given machine function \p MF.
1413e8d8bef9SDimitry Andric   unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
1414e8d8bef9SDimitry Andric 
1415fe6060f1SDimitry Andric   /// \returns Reserved number of SGPRs for given function \p F.
1416fe6060f1SDimitry Andric   unsigned getReservedNumSGPRs(const Function &F) const;
1417fe6060f1SDimitry Andric 
1418fe6060f1SDimitry Andric   /// \returns max num SGPRs. This is the common utility
1419fe6060f1SDimitry Andric   /// function called by MachineFunction and Function
1420fe6060f1SDimitry Andric   /// variants of getMaxNumSGPRs.
1421fe6060f1SDimitry Andric   unsigned getBaseMaxNumSGPRs(const Function &F,
1422fe6060f1SDimitry Andric                               std::pair<unsigned, unsigned> WavesPerEU,
1423fe6060f1SDimitry Andric                               unsigned PreloadedSGPRs,
1424fe6060f1SDimitry Andric                               unsigned ReservedNumSGPRs) const;
1425fe6060f1SDimitry Andric 
1426e8d8bef9SDimitry Andric   /// \returns Maximum number of SGPRs that meets number of waves per execution
1427e8d8bef9SDimitry Andric   /// unit requirement for function \p MF, or number of SGPRs explicitly
1428e8d8bef9SDimitry Andric   /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
1429e8d8bef9SDimitry Andric   ///
1430e8d8bef9SDimitry Andric   /// \returns Value that meets number of waves per execution unit requirement
1431e8d8bef9SDimitry Andric   /// if explicitly requested value cannot be converted to integer, violates
1432e8d8bef9SDimitry Andric   /// subtarget's specifications, or does not meet number of waves per execution
1433e8d8bef9SDimitry Andric   /// unit requirement.
1434e8d8bef9SDimitry Andric   unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
1435e8d8bef9SDimitry Andric 
1436fe6060f1SDimitry Andric   /// \returns Maximum number of SGPRs that meets number of waves per execution
1437fe6060f1SDimitry Andric   /// unit requirement for function \p F, or number of SGPRs explicitly
1438fe6060f1SDimitry Andric   /// requested using "amdgpu-num-sgpr" attribute attached to function \p F.
1439fe6060f1SDimitry Andric   ///
1440fe6060f1SDimitry Andric   /// \returns Value that meets number of waves per execution unit requirement
1441fe6060f1SDimitry Andric   /// if explicitly requested value cannot be converted to integer, violates
1442fe6060f1SDimitry Andric   /// subtarget's specifications, or does not meet number of waves per execution
1443fe6060f1SDimitry Andric   /// unit requirement.
1444fe6060f1SDimitry Andric   unsigned getMaxNumSGPRs(const Function &F) const;
1445fe6060f1SDimitry Andric 
1446e8d8bef9SDimitry Andric   /// \returns VGPR allocation granularity supported by the subtarget.
1447e8d8bef9SDimitry Andric   unsigned getVGPRAllocGranule() const {
1448e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getVGPRAllocGranule(this);
1449e8d8bef9SDimitry Andric   }
1450e8d8bef9SDimitry Andric 
1451e8d8bef9SDimitry Andric   /// \returns VGPR encoding granularity supported by the subtarget.
1452e8d8bef9SDimitry Andric   unsigned getVGPREncodingGranule() const {
1453e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getVGPREncodingGranule(this);
1454e8d8bef9SDimitry Andric   }
1455e8d8bef9SDimitry Andric 
1456e8d8bef9SDimitry Andric   /// \returns Total number of VGPRs supported by the subtarget.
1457e8d8bef9SDimitry Andric   unsigned getTotalNumVGPRs() const {
1458e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getTotalNumVGPRs(this);
1459e8d8bef9SDimitry Andric   }
1460e8d8bef9SDimitry Andric 
1461*0fca6ea1SDimitry Andric   /// \returns Addressable number of architectural VGPRs supported by the
1462*0fca6ea1SDimitry Andric   /// subtarget.
1463*0fca6ea1SDimitry Andric   unsigned getAddressableNumArchVGPRs() const {
1464*0fca6ea1SDimitry Andric     return AMDGPU::IsaInfo::getAddressableNumArchVGPRs(this);
1465*0fca6ea1SDimitry Andric   }
1466*0fca6ea1SDimitry Andric 
1467e8d8bef9SDimitry Andric   /// \returns Addressable number of VGPRs supported by the subtarget.
1468e8d8bef9SDimitry Andric   unsigned getAddressableNumVGPRs() const {
1469e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getAddressableNumVGPRs(this);
1470e8d8bef9SDimitry Andric   }
1471e8d8bef9SDimitry Andric 
1472bdd1243dSDimitry Andric   /// \returns the minimum number of VGPRs that will prevent achieving more than
1473bdd1243dSDimitry Andric   /// the specified number of waves \p WavesPerEU.
1474e8d8bef9SDimitry Andric   unsigned getMinNumVGPRs(unsigned WavesPerEU) const {
1475e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getMinNumVGPRs(this, WavesPerEU);
1476e8d8bef9SDimitry Andric   }
1477e8d8bef9SDimitry Andric 
1478bdd1243dSDimitry Andric   /// \returns the maximum number of VGPRs that can be used and still achieved
1479bdd1243dSDimitry Andric   /// at least the specified number of waves \p WavesPerEU.
1480e8d8bef9SDimitry Andric   unsigned getMaxNumVGPRs(unsigned WavesPerEU) const {
1481e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getMaxNumVGPRs(this, WavesPerEU);
1482e8d8bef9SDimitry Andric   }
1483e8d8bef9SDimitry Andric 
1484fe6060f1SDimitry Andric   /// \returns max num VGPRs. This is the common utility function
1485fe6060f1SDimitry Andric   /// called by MachineFunction and Function variants of getMaxNumVGPRs.
1486fe6060f1SDimitry Andric   unsigned getBaseMaxNumVGPRs(const Function &F,
1487fe6060f1SDimitry Andric                               std::pair<unsigned, unsigned> WavesPerEU) const;
1488fe6060f1SDimitry Andric   /// \returns Maximum number of VGPRs that meets number of waves per execution
1489fe6060f1SDimitry Andric   /// unit requirement for function \p F, or number of VGPRs explicitly
1490fe6060f1SDimitry Andric   /// requested using "amdgpu-num-vgpr" attribute attached to function \p F.
1491fe6060f1SDimitry Andric   ///
1492fe6060f1SDimitry Andric   /// \returns Value that meets number of waves per execution unit requirement
1493fe6060f1SDimitry Andric   /// if explicitly requested value cannot be converted to integer, violates
1494fe6060f1SDimitry Andric   /// subtarget's specifications, or does not meet number of waves per execution
1495fe6060f1SDimitry Andric   /// unit requirement.
1496fe6060f1SDimitry Andric   unsigned getMaxNumVGPRs(const Function &F) const;
1497fe6060f1SDimitry Andric 
149881ad6265SDimitry Andric   unsigned getMaxNumAGPRs(const Function &F) const {
149981ad6265SDimitry Andric     return getMaxNumVGPRs(F);
150081ad6265SDimitry Andric   }
150181ad6265SDimitry Andric 
1502e8d8bef9SDimitry Andric   /// \returns Maximum number of VGPRs that meets number of waves per execution
1503e8d8bef9SDimitry Andric   /// unit requirement for function \p MF, or number of VGPRs explicitly
1504e8d8bef9SDimitry Andric   /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
1505e8d8bef9SDimitry Andric   ///
1506e8d8bef9SDimitry Andric   /// \returns Value that meets number of waves per execution unit requirement
1507e8d8bef9SDimitry Andric   /// if explicitly requested value cannot be converted to integer, violates
1508e8d8bef9SDimitry Andric   /// subtarget's specifications, or does not meet number of waves per execution
1509e8d8bef9SDimitry Andric   /// unit requirement.
1510e8d8bef9SDimitry Andric   unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
1511e8d8bef9SDimitry Andric 
1512e8d8bef9SDimitry Andric   void getPostRAMutations(
1513e8d8bef9SDimitry Andric       std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
1514e8d8bef9SDimitry Andric       const override;
1515e8d8bef9SDimitry Andric 
1516349cc55cSDimitry Andric   std::unique_ptr<ScheduleDAGMutation>
1517349cc55cSDimitry Andric   createFillMFMAShadowMutation(const TargetInstrInfo *TII) const;
1518349cc55cSDimitry Andric 
1519e8d8bef9SDimitry Andric   bool isWave32() const {
1520e8d8bef9SDimitry Andric     return getWavefrontSize() == 32;
1521e8d8bef9SDimitry Andric   }
1522e8d8bef9SDimitry Andric 
1523e8d8bef9SDimitry Andric   bool isWave64() const {
1524e8d8bef9SDimitry Andric     return getWavefrontSize() == 64;
1525e8d8bef9SDimitry Andric   }
1526e8d8bef9SDimitry Andric 
1527e8d8bef9SDimitry Andric   const TargetRegisterClass *getBoolRC() const {
1528e8d8bef9SDimitry Andric     return getRegisterInfo()->getBoolRC();
1529e8d8bef9SDimitry Andric   }
1530e8d8bef9SDimitry Andric 
1531e8d8bef9SDimitry Andric   /// \returns Maximum number of work groups per compute unit supported by the
1532e8d8bef9SDimitry Andric   /// subtarget and limited by given \p FlatWorkGroupSize.
1533e8d8bef9SDimitry Andric   unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const override {
1534e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(this, FlatWorkGroupSize);
1535e8d8bef9SDimitry Andric   }
1536e8d8bef9SDimitry Andric 
1537e8d8bef9SDimitry Andric   /// \returns Minimum flat work group size supported by the subtarget.
1538e8d8bef9SDimitry Andric   unsigned getMinFlatWorkGroupSize() const override {
1539e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(this);
1540e8d8bef9SDimitry Andric   }
1541e8d8bef9SDimitry Andric 
1542e8d8bef9SDimitry Andric   /// \returns Maximum flat work group size supported by the subtarget.
1543e8d8bef9SDimitry Andric   unsigned getMaxFlatWorkGroupSize() const override {
1544e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(this);
1545e8d8bef9SDimitry Andric   }
1546e8d8bef9SDimitry Andric 
1547e8d8bef9SDimitry Andric   /// \returns Number of waves per execution unit required to support the given
1548e8d8bef9SDimitry Andric   /// \p FlatWorkGroupSize.
1549e8d8bef9SDimitry Andric   unsigned
1550e8d8bef9SDimitry Andric   getWavesPerEUForWorkGroup(unsigned FlatWorkGroupSize) const override {
1551e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getWavesPerEUForWorkGroup(this, FlatWorkGroupSize);
1552e8d8bef9SDimitry Andric   }
1553e8d8bef9SDimitry Andric 
1554e8d8bef9SDimitry Andric   /// \returns Minimum number of waves per execution unit supported by the
1555e8d8bef9SDimitry Andric   /// subtarget.
1556e8d8bef9SDimitry Andric   unsigned getMinWavesPerEU() const override {
1557e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getMinWavesPerEU(this);
1558e8d8bef9SDimitry Andric   }
1559e8d8bef9SDimitry Andric 
1560e8d8bef9SDimitry Andric   void adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use, int UseOpIdx,
1561*0fca6ea1SDimitry Andric                              SDep &Dep,
1562*0fca6ea1SDimitry Andric                              const TargetSchedModel *SchedModel) const override;
156381ad6265SDimitry Andric 
156481ad6265SDimitry Andric   // \returns true if it's beneficial on this subtarget for the scheduler to
156581ad6265SDimitry Andric   // cluster stores as well as loads.
156681ad6265SDimitry Andric   bool shouldClusterStores() const { return getGeneration() >= GFX11; }
1567bdd1243dSDimitry Andric 
1568bdd1243dSDimitry Andric   // \returns the number of address arguments from which to enable MIMG NSA
1569bdd1243dSDimitry Andric   // on supported architectures.
1570bdd1243dSDimitry Andric   unsigned getNSAThreshold(const MachineFunction &MF) const;
157106c3fb27SDimitry Andric 
157206c3fb27SDimitry Andric   // \returns true if the subtarget has a hazard requiring an "s_nop 0"
157306c3fb27SDimitry Andric   // instruction before "s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)".
157406c3fb27SDimitry Andric   bool requiresNopBeforeDeallocVGPRs() const {
157506c3fb27SDimitry Andric     // Currently all targets that support the dealloc VGPRs message also require
157606c3fb27SDimitry Andric     // the nop.
157706c3fb27SDimitry Andric     return true;
157806c3fb27SDimitry Andric   }
1579e8d8bef9SDimitry Andric };
1580e8d8bef9SDimitry Andric 
15815f757f3fSDimitry Andric class GCNUserSGPRUsageInfo {
15825f757f3fSDimitry Andric public:
15835f757f3fSDimitry Andric   bool hasImplicitBufferPtr() const { return ImplicitBufferPtr; }
15845f757f3fSDimitry Andric 
15855f757f3fSDimitry Andric   bool hasPrivateSegmentBuffer() const { return PrivateSegmentBuffer; }
15865f757f3fSDimitry Andric 
15875f757f3fSDimitry Andric   bool hasDispatchPtr() const { return DispatchPtr; }
15885f757f3fSDimitry Andric 
15895f757f3fSDimitry Andric   bool hasQueuePtr() const { return QueuePtr; }
15905f757f3fSDimitry Andric 
15915f757f3fSDimitry Andric   bool hasKernargSegmentPtr() const { return KernargSegmentPtr; }
15925f757f3fSDimitry Andric 
15935f757f3fSDimitry Andric   bool hasDispatchID() const { return DispatchID; }
15945f757f3fSDimitry Andric 
15955f757f3fSDimitry Andric   bool hasFlatScratchInit() const { return FlatScratchInit; }
15965f757f3fSDimitry Andric 
1597*0fca6ea1SDimitry Andric   bool hasPrivateSegmentSize() const { return PrivateSegmentSize; }
1598*0fca6ea1SDimitry Andric 
15995f757f3fSDimitry Andric   unsigned getNumKernargPreloadSGPRs() const { return NumKernargPreloadSGPRs; }
16005f757f3fSDimitry Andric 
16015f757f3fSDimitry Andric   unsigned getNumUsedUserSGPRs() const { return NumUsedUserSGPRs; }
16025f757f3fSDimitry Andric 
16035f757f3fSDimitry Andric   unsigned getNumFreeUserSGPRs();
16045f757f3fSDimitry Andric 
16055f757f3fSDimitry Andric   void allocKernargPreloadSGPRs(unsigned NumSGPRs);
16065f757f3fSDimitry Andric 
16075f757f3fSDimitry Andric   enum UserSGPRID : unsigned {
16085f757f3fSDimitry Andric     ImplicitBufferPtrID = 0,
16095f757f3fSDimitry Andric     PrivateSegmentBufferID = 1,
16105f757f3fSDimitry Andric     DispatchPtrID = 2,
16115f757f3fSDimitry Andric     QueuePtrID = 3,
16125f757f3fSDimitry Andric     KernargSegmentPtrID = 4,
16135f757f3fSDimitry Andric     DispatchIdID = 5,
16145f757f3fSDimitry Andric     FlatScratchInitID = 6,
16155f757f3fSDimitry Andric     PrivateSegmentSizeID = 7
16165f757f3fSDimitry Andric   };
16175f757f3fSDimitry Andric 
16185f757f3fSDimitry Andric   // Returns the size in number of SGPRs for preload user SGPR field.
16195f757f3fSDimitry Andric   static unsigned getNumUserSGPRForField(UserSGPRID ID) {
16205f757f3fSDimitry Andric     switch (ID) {
16215f757f3fSDimitry Andric     case ImplicitBufferPtrID:
16225f757f3fSDimitry Andric       return 2;
16235f757f3fSDimitry Andric     case PrivateSegmentBufferID:
16245f757f3fSDimitry Andric       return 4;
16255f757f3fSDimitry Andric     case DispatchPtrID:
16265f757f3fSDimitry Andric       return 2;
16275f757f3fSDimitry Andric     case QueuePtrID:
16285f757f3fSDimitry Andric       return 2;
16295f757f3fSDimitry Andric     case KernargSegmentPtrID:
16305f757f3fSDimitry Andric       return 2;
16315f757f3fSDimitry Andric     case DispatchIdID:
16325f757f3fSDimitry Andric       return 2;
16335f757f3fSDimitry Andric     case FlatScratchInitID:
16345f757f3fSDimitry Andric       return 2;
16355f757f3fSDimitry Andric     case PrivateSegmentSizeID:
16365f757f3fSDimitry Andric       return 1;
16375f757f3fSDimitry Andric     }
16385f757f3fSDimitry Andric     llvm_unreachable("Unknown UserSGPRID.");
16395f757f3fSDimitry Andric   }
16405f757f3fSDimitry Andric 
16415f757f3fSDimitry Andric   GCNUserSGPRUsageInfo(const Function &F, const GCNSubtarget &ST);
16425f757f3fSDimitry Andric 
16435f757f3fSDimitry Andric private:
16445f757f3fSDimitry Andric   const GCNSubtarget &ST;
16455f757f3fSDimitry Andric 
16465f757f3fSDimitry Andric   // Private memory buffer
16475f757f3fSDimitry Andric   // Compute directly in sgpr[0:1]
16485f757f3fSDimitry Andric   // Other shaders indirect 64-bits at sgpr[0:1]
16495f757f3fSDimitry Andric   bool ImplicitBufferPtr = false;
16505f757f3fSDimitry Andric 
16515f757f3fSDimitry Andric   bool PrivateSegmentBuffer = false;
16525f757f3fSDimitry Andric 
16535f757f3fSDimitry Andric   bool DispatchPtr = false;
16545f757f3fSDimitry Andric 
16555f757f3fSDimitry Andric   bool QueuePtr = false;
16565f757f3fSDimitry Andric 
16575f757f3fSDimitry Andric   bool KernargSegmentPtr = false;
16585f757f3fSDimitry Andric 
16595f757f3fSDimitry Andric   bool DispatchID = false;
16605f757f3fSDimitry Andric 
16615f757f3fSDimitry Andric   bool FlatScratchInit = false;
16625f757f3fSDimitry Andric 
1663*0fca6ea1SDimitry Andric   bool PrivateSegmentSize = false;
1664*0fca6ea1SDimitry Andric 
16655f757f3fSDimitry Andric   unsigned NumKernargPreloadSGPRs = 0;
16665f757f3fSDimitry Andric 
16675f757f3fSDimitry Andric   unsigned NumUsedUserSGPRs = 0;
16685f757f3fSDimitry Andric };
16695f757f3fSDimitry Andric 
1670e8d8bef9SDimitry Andric } // end namespace llvm
1671e8d8bef9SDimitry Andric 
1672e8d8bef9SDimitry Andric #endif // LLVM_LIB_TARGET_AMDGPU_GCNSUBTARGET_H
1673