xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AMDGPU/GCNSubtarget.h (revision fcaf7f8644a9988098ac6be2165bce3ea4786e91)
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"
18e8d8bef9SDimitry Andric #include "AMDGPUSubtarget.h"
19e8d8bef9SDimitry Andric #include "SIFrameLowering.h"
20e8d8bef9SDimitry Andric #include "SIISelLowering.h"
21e8d8bef9SDimitry Andric #include "SIInstrInfo.h"
22e8d8bef9SDimitry Andric #include "llvm/CodeGen/SelectionDAGTargetInfo.h"
23e8d8bef9SDimitry Andric 
24e8d8bef9SDimitry Andric #define GET_SUBTARGETINFO_HEADER
25e8d8bef9SDimitry Andric #include "AMDGPUGenSubtargetInfo.inc"
26e8d8bef9SDimitry Andric 
27e8d8bef9SDimitry Andric namespace llvm {
28e8d8bef9SDimitry Andric 
29e8d8bef9SDimitry Andric class GCNTargetMachine;
30e8d8bef9SDimitry Andric 
31e8d8bef9SDimitry Andric class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
32e8d8bef9SDimitry Andric                            public AMDGPUSubtarget {
33e8d8bef9SDimitry Andric 
34e8d8bef9SDimitry Andric   using AMDGPUSubtarget::getMaxWavesPerEU;
35e8d8bef9SDimitry Andric 
36e8d8bef9SDimitry Andric public:
37fe6060f1SDimitry Andric   // Following 2 enums are documented at:
38fe6060f1SDimitry Andric   //   - https://llvm.org/docs/AMDGPUUsage.html#trap-handler-abi
39fe6060f1SDimitry Andric   enum class TrapHandlerAbi {
40fe6060f1SDimitry Andric     NONE   = 0x00,
41fe6060f1SDimitry Andric     AMDHSA = 0x01,
42e8d8bef9SDimitry Andric   };
43e8d8bef9SDimitry Andric 
44fe6060f1SDimitry Andric   enum class TrapID {
45fe6060f1SDimitry Andric     LLVMAMDHSATrap      = 0x02,
46fe6060f1SDimitry Andric     LLVMAMDHSADebugTrap = 0x03,
47e8d8bef9SDimitry Andric   };
48e8d8bef9SDimitry Andric 
49e8d8bef9SDimitry Andric private:
50e8d8bef9SDimitry Andric   /// GlobalISel related APIs.
51e8d8bef9SDimitry Andric   std::unique_ptr<AMDGPUCallLowering> CallLoweringInfo;
52e8d8bef9SDimitry Andric   std::unique_ptr<InlineAsmLowering> InlineAsmLoweringInfo;
53e8d8bef9SDimitry Andric   std::unique_ptr<InstructionSelector> InstSelector;
54e8d8bef9SDimitry Andric   std::unique_ptr<LegalizerInfo> Legalizer;
55e8d8bef9SDimitry Andric   std::unique_ptr<RegisterBankInfo> RegBankInfo;
56e8d8bef9SDimitry Andric 
57e8d8bef9SDimitry Andric protected:
58e8d8bef9SDimitry Andric   // Basic subtarget description.
59e8d8bef9SDimitry Andric   Triple TargetTriple;
60e8d8bef9SDimitry Andric   AMDGPU::IsaInfo::AMDGPUTargetID TargetID;
6181ad6265SDimitry Andric   unsigned Gen = INVALID;
62e8d8bef9SDimitry Andric   InstrItineraryData InstrItins;
6381ad6265SDimitry Andric   int LDSBankCount = 0;
6481ad6265SDimitry Andric   unsigned MaxPrivateElementSize = 0;
65e8d8bef9SDimitry Andric 
66e8d8bef9SDimitry Andric   // Possibly statically set by tablegen, but may want to be overridden.
6781ad6265SDimitry Andric   bool FastFMAF32 = false;
6881ad6265SDimitry Andric   bool FastDenormalF32 = false;
6981ad6265SDimitry Andric   bool HalfRate64Ops = false;
7081ad6265SDimitry Andric   bool FullRate64Ops = false;
71e8d8bef9SDimitry Andric 
72e8d8bef9SDimitry Andric   // Dynamically set bits that enable features.
7381ad6265SDimitry Andric   bool FlatForGlobal = false;
7481ad6265SDimitry Andric   bool AutoWaitcntBeforeBarrier = false;
7581ad6265SDimitry Andric   bool UnalignedScratchAccess = false;
7681ad6265SDimitry Andric   bool UnalignedAccessMode = false;
7781ad6265SDimitry Andric   bool HasApertureRegs = false;
7881ad6265SDimitry Andric   bool SupportsXNACK = false;
79e8d8bef9SDimitry Andric 
80e8d8bef9SDimitry Andric   // This should not be used directly. 'TargetID' tracks the dynamic settings
81e8d8bef9SDimitry Andric   // for XNACK.
8281ad6265SDimitry Andric   bool EnableXNACK = false;
83e8d8bef9SDimitry Andric 
8481ad6265SDimitry Andric   bool EnableTgSplit = false;
8581ad6265SDimitry Andric   bool EnableCuMode = false;
8681ad6265SDimitry Andric   bool TrapHandler = false;
87e8d8bef9SDimitry Andric 
88e8d8bef9SDimitry Andric   // Used as options.
8981ad6265SDimitry Andric   bool EnableLoadStoreOpt = false;
9081ad6265SDimitry Andric   bool EnableUnsafeDSOffsetFolding = false;
9181ad6265SDimitry Andric   bool EnableSIScheduler = false;
9281ad6265SDimitry Andric   bool EnableDS128 = false;
9381ad6265SDimitry Andric   bool EnablePRTStrictNull = false;
9481ad6265SDimitry Andric   bool DumpCode = false;
95e8d8bef9SDimitry Andric 
96e8d8bef9SDimitry Andric   // Subtarget statically properties set by tablegen
9781ad6265SDimitry Andric   bool FP64 = false;
9881ad6265SDimitry Andric   bool FMA = false;
9981ad6265SDimitry Andric   bool MIMG_R128 = false;
10081ad6265SDimitry Andric   bool CIInsts = false;
10181ad6265SDimitry Andric   bool GFX8Insts = false;
10281ad6265SDimitry Andric   bool GFX9Insts = false;
10381ad6265SDimitry Andric   bool GFX90AInsts = false;
10481ad6265SDimitry Andric   bool GFX940Insts = false;
10581ad6265SDimitry Andric   bool GFX10Insts = false;
10681ad6265SDimitry Andric   bool GFX11Insts = false;
10781ad6265SDimitry Andric   bool GFX10_3Insts = false;
10881ad6265SDimitry Andric   bool GFX7GFX8GFX9Insts = false;
10981ad6265SDimitry Andric   bool SGPRInitBug = false;
11081ad6265SDimitry Andric   bool UserSGPRInit16Bug = false;
11181ad6265SDimitry Andric   bool NegativeScratchOffsetBug = false;
11281ad6265SDimitry Andric   bool NegativeUnalignedScratchOffsetBug = false;
11381ad6265SDimitry Andric   bool HasSMemRealTime = false;
11481ad6265SDimitry Andric   bool HasIntClamp = false;
11581ad6265SDimitry Andric   bool HasFmaMixInsts = false;
11681ad6265SDimitry Andric   bool HasMovrel = false;
11781ad6265SDimitry Andric   bool HasVGPRIndexMode = false;
11881ad6265SDimitry Andric   bool HasScalarStores = false;
11981ad6265SDimitry Andric   bool HasScalarAtomics = false;
12081ad6265SDimitry Andric   bool HasSDWAOmod = false;
12181ad6265SDimitry Andric   bool HasSDWAScalar = false;
12281ad6265SDimitry Andric   bool HasSDWASdst = false;
12381ad6265SDimitry Andric   bool HasSDWAMac = false;
12481ad6265SDimitry Andric   bool HasSDWAOutModsVOPC = false;
12581ad6265SDimitry Andric   bool HasDPP = false;
12681ad6265SDimitry Andric   bool HasDPP8 = false;
12781ad6265SDimitry Andric   bool Has64BitDPP = false;
12881ad6265SDimitry Andric   bool HasPackedFP32Ops = false;
12981ad6265SDimitry Andric   bool HasImageInsts = false;
13081ad6265SDimitry Andric   bool HasExtendedImageInsts = false;
13181ad6265SDimitry Andric   bool HasR128A16 = false;
13281ad6265SDimitry Andric   bool HasGFX10A16 = false;
13381ad6265SDimitry Andric   bool HasG16 = false;
13481ad6265SDimitry Andric   bool HasNSAEncoding = false;
13581ad6265SDimitry Andric   unsigned NSAMaxSize = 0;
13681ad6265SDimitry Andric   bool GFX10_AEncoding = false;
13781ad6265SDimitry Andric   bool GFX10_BEncoding = false;
13881ad6265SDimitry Andric   bool HasDLInsts = false;
13981ad6265SDimitry Andric   bool HasDot1Insts = false;
14081ad6265SDimitry Andric   bool HasDot2Insts = false;
14181ad6265SDimitry Andric   bool HasDot3Insts = false;
14281ad6265SDimitry Andric   bool HasDot4Insts = false;
14381ad6265SDimitry Andric   bool HasDot5Insts = false;
14481ad6265SDimitry Andric   bool HasDot6Insts = false;
14581ad6265SDimitry Andric   bool HasDot7Insts = false;
14681ad6265SDimitry Andric   bool HasDot8Insts = false;
14781ad6265SDimitry Andric   bool HasMAIInsts = false;
148*fcaf7f86SDimitry Andric   bool HasFP8Insts = false;
14981ad6265SDimitry Andric   bool HasPkFmacF16Inst = false;
15081ad6265SDimitry Andric   bool HasAtomicFaddRtnInsts = false;
15181ad6265SDimitry Andric   bool HasAtomicFaddNoRtnInsts = false;
15281ad6265SDimitry Andric   bool HasAtomicPkFaddNoRtnInsts = false;
15381ad6265SDimitry Andric   bool SupportsSRAMECC = false;
154e8d8bef9SDimitry Andric 
155e8d8bef9SDimitry Andric   // This should not be used directly. 'TargetID' tracks the dynamic settings
156e8d8bef9SDimitry Andric   // for SRAMECC.
15781ad6265SDimitry Andric   bool EnableSRAMECC = false;
158e8d8bef9SDimitry Andric 
15981ad6265SDimitry Andric   bool HasNoSdstCMPX = false;
16081ad6265SDimitry Andric   bool HasVscnt = false;
16181ad6265SDimitry Andric   bool HasGetWaveIdInst = false;
16281ad6265SDimitry Andric   bool HasSMemTimeInst = false;
16381ad6265SDimitry Andric   bool HasShaderCyclesRegister = false;
16481ad6265SDimitry Andric   bool HasVOP3Literal = false;
16581ad6265SDimitry Andric   bool HasNoDataDepHazard = false;
16681ad6265SDimitry Andric   bool FlatAddressSpace = false;
16781ad6265SDimitry Andric   bool FlatInstOffsets = false;
16881ad6265SDimitry Andric   bool FlatGlobalInsts = false;
16981ad6265SDimitry Andric   bool FlatScratchInsts = false;
17081ad6265SDimitry Andric   bool ScalarFlatScratchInsts = false;
17181ad6265SDimitry Andric   bool HasArchitectedFlatScratch = false;
17281ad6265SDimitry Andric   bool EnableFlatScratch = false;
17381ad6265SDimitry Andric   bool AddNoCarryInsts = false;
17481ad6265SDimitry Andric   bool HasUnpackedD16VMem = false;
17581ad6265SDimitry Andric   bool LDSMisalignedBug = false;
17681ad6265SDimitry Andric   bool HasMFMAInlineLiteralBug = false;
17781ad6265SDimitry Andric   bool UnalignedBufferAccess = false;
17881ad6265SDimitry Andric   bool UnalignedDSAccess = false;
17981ad6265SDimitry Andric   bool HasPackedTID = false;
18081ad6265SDimitry Andric   bool ScalarizeGlobal = false;
181e8d8bef9SDimitry Andric 
18281ad6265SDimitry Andric   bool HasVcmpxPermlaneHazard = false;
18381ad6265SDimitry Andric   bool HasVMEMtoScalarWriteHazard = false;
18481ad6265SDimitry Andric   bool HasSMEMtoVectorWriteHazard = false;
18581ad6265SDimitry Andric   bool HasInstFwdPrefetchBug = false;
18681ad6265SDimitry Andric   bool HasVcmpxExecWARHazard = false;
18781ad6265SDimitry Andric   bool HasLdsBranchVmemWARHazard = false;
18881ad6265SDimitry Andric   bool HasNSAtoVMEMBug = false;
18981ad6265SDimitry Andric   bool HasNSAClauseBug = false;
19081ad6265SDimitry Andric   bool HasOffset3fBug = false;
19181ad6265SDimitry Andric   bool HasFlatSegmentOffsetBug = false;
19281ad6265SDimitry Andric   bool HasImageStoreD16Bug = false;
19381ad6265SDimitry Andric   bool HasImageGather4D16Bug = false;
19481ad6265SDimitry Andric   bool HasVOPDInsts = false;
195e8d8bef9SDimitry Andric 
196e8d8bef9SDimitry Andric   // Dummy feature to use for assembler in tablegen.
19781ad6265SDimitry Andric   bool FeatureDisable = false;
198e8d8bef9SDimitry Andric 
199e8d8bef9SDimitry Andric   SelectionDAGTargetInfo TSInfo;
200e8d8bef9SDimitry Andric private:
201e8d8bef9SDimitry Andric   SIInstrInfo InstrInfo;
202e8d8bef9SDimitry Andric   SITargetLowering TLInfo;
203e8d8bef9SDimitry Andric   SIFrameLowering FrameLowering;
204e8d8bef9SDimitry Andric 
205e8d8bef9SDimitry Andric public:
206e8d8bef9SDimitry Andric   GCNSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
207e8d8bef9SDimitry Andric                const GCNTargetMachine &TM);
208e8d8bef9SDimitry Andric   ~GCNSubtarget() override;
209e8d8bef9SDimitry Andric 
210e8d8bef9SDimitry Andric   GCNSubtarget &initializeSubtargetDependencies(const Triple &TT,
211e8d8bef9SDimitry Andric                                                    StringRef GPU, StringRef FS);
212e8d8bef9SDimitry Andric 
213e8d8bef9SDimitry Andric   const SIInstrInfo *getInstrInfo() const override {
214e8d8bef9SDimitry Andric     return &InstrInfo;
215e8d8bef9SDimitry Andric   }
216e8d8bef9SDimitry Andric 
217e8d8bef9SDimitry Andric   const SIFrameLowering *getFrameLowering() const override {
218e8d8bef9SDimitry Andric     return &FrameLowering;
219e8d8bef9SDimitry Andric   }
220e8d8bef9SDimitry Andric 
221e8d8bef9SDimitry Andric   const SITargetLowering *getTargetLowering() const override {
222e8d8bef9SDimitry Andric     return &TLInfo;
223e8d8bef9SDimitry Andric   }
224e8d8bef9SDimitry Andric 
225e8d8bef9SDimitry Andric   const SIRegisterInfo *getRegisterInfo() const override {
226e8d8bef9SDimitry Andric     return &InstrInfo.getRegisterInfo();
227e8d8bef9SDimitry Andric   }
228e8d8bef9SDimitry Andric 
229e8d8bef9SDimitry Andric   const CallLowering *getCallLowering() const override {
230e8d8bef9SDimitry Andric     return CallLoweringInfo.get();
231e8d8bef9SDimitry Andric   }
232e8d8bef9SDimitry Andric 
233e8d8bef9SDimitry Andric   const InlineAsmLowering *getInlineAsmLowering() const override {
234e8d8bef9SDimitry Andric     return InlineAsmLoweringInfo.get();
235e8d8bef9SDimitry Andric   }
236e8d8bef9SDimitry Andric 
237e8d8bef9SDimitry Andric   InstructionSelector *getInstructionSelector() const override {
238e8d8bef9SDimitry Andric     return InstSelector.get();
239e8d8bef9SDimitry Andric   }
240e8d8bef9SDimitry Andric 
241e8d8bef9SDimitry Andric   const LegalizerInfo *getLegalizerInfo() const override {
242e8d8bef9SDimitry Andric     return Legalizer.get();
243e8d8bef9SDimitry Andric   }
244e8d8bef9SDimitry Andric 
245e8d8bef9SDimitry Andric   const RegisterBankInfo *getRegBankInfo() const override {
246e8d8bef9SDimitry Andric     return RegBankInfo.get();
247e8d8bef9SDimitry Andric   }
248e8d8bef9SDimitry Andric 
249fe6060f1SDimitry Andric   const AMDGPU::IsaInfo::AMDGPUTargetID &getTargetID() const {
250fe6060f1SDimitry Andric     return TargetID;
251fe6060f1SDimitry Andric   }
252fe6060f1SDimitry Andric 
253e8d8bef9SDimitry Andric   // Nothing implemented, just prevent crashes on use.
254e8d8bef9SDimitry Andric   const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
255e8d8bef9SDimitry Andric     return &TSInfo;
256e8d8bef9SDimitry Andric   }
257e8d8bef9SDimitry Andric 
258e8d8bef9SDimitry Andric   const InstrItineraryData *getInstrItineraryData() const override {
259e8d8bef9SDimitry Andric     return &InstrItins;
260e8d8bef9SDimitry Andric   }
261e8d8bef9SDimitry Andric 
262e8d8bef9SDimitry Andric   void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
263e8d8bef9SDimitry Andric 
264e8d8bef9SDimitry Andric   Generation getGeneration() const {
265e8d8bef9SDimitry Andric     return (Generation)Gen;
266e8d8bef9SDimitry Andric   }
267e8d8bef9SDimitry Andric 
26881ad6265SDimitry Andric   unsigned getMaxWaveScratchSize() const {
26981ad6265SDimitry Andric     // See COMPUTE_TMPRING_SIZE.WAVESIZE.
27081ad6265SDimitry Andric     if (getGeneration() < GFX11) {
27181ad6265SDimitry Andric       // 13-bit field in units of 256-dword.
27281ad6265SDimitry Andric       return (256 * 4) * ((1 << 13) - 1);
27381ad6265SDimitry Andric     }
27481ad6265SDimitry Andric     // 15-bit field in units of 64-dword.
27581ad6265SDimitry Andric     return (64 * 4) * ((1 << 15) - 1);
27681ad6265SDimitry Andric   }
27781ad6265SDimitry Andric 
278349cc55cSDimitry Andric   /// Return the number of high bits known to be zero for a frame index.
279e8d8bef9SDimitry Andric   unsigned getKnownHighZeroBitsForFrameIndex() const {
28081ad6265SDimitry Andric     return countLeadingZeros(getMaxWaveScratchSize()) + getWavefrontSizeLog2();
281e8d8bef9SDimitry Andric   }
282e8d8bef9SDimitry Andric 
283e8d8bef9SDimitry Andric   int getLDSBankCount() const {
284e8d8bef9SDimitry Andric     return LDSBankCount;
285e8d8bef9SDimitry Andric   }
286e8d8bef9SDimitry Andric 
287e8d8bef9SDimitry Andric   unsigned getMaxPrivateElementSize(bool ForBufferRSrc = false) const {
288e8d8bef9SDimitry Andric     return (ForBufferRSrc || !enableFlatScratch()) ? MaxPrivateElementSize : 16;
289e8d8bef9SDimitry Andric   }
290e8d8bef9SDimitry Andric 
291e8d8bef9SDimitry Andric   unsigned getConstantBusLimit(unsigned Opcode) const;
292e8d8bef9SDimitry Andric 
293fe6060f1SDimitry Andric   /// Returns if the result of this instruction with a 16-bit result returned in
294fe6060f1SDimitry Andric   /// a 32-bit register implicitly zeroes the high 16-bits, rather than preserve
295fe6060f1SDimitry Andric   /// the original value.
296fe6060f1SDimitry Andric   bool zeroesHigh16BitsOfDest(unsigned Opcode) const;
297fe6060f1SDimitry Andric 
298e8d8bef9SDimitry Andric   bool hasIntClamp() const {
299e8d8bef9SDimitry Andric     return HasIntClamp;
300e8d8bef9SDimitry Andric   }
301e8d8bef9SDimitry Andric 
302e8d8bef9SDimitry Andric   bool hasFP64() const {
303e8d8bef9SDimitry Andric     return FP64;
304e8d8bef9SDimitry Andric   }
305e8d8bef9SDimitry Andric 
306e8d8bef9SDimitry Andric   bool hasMIMG_R128() const {
307e8d8bef9SDimitry Andric     return MIMG_R128;
308e8d8bef9SDimitry Andric   }
309e8d8bef9SDimitry Andric 
310e8d8bef9SDimitry Andric   bool hasHWFP64() const {
311e8d8bef9SDimitry Andric     return FP64;
312e8d8bef9SDimitry Andric   }
313e8d8bef9SDimitry Andric 
314e8d8bef9SDimitry Andric   bool hasFastFMAF32() const {
315e8d8bef9SDimitry Andric     return FastFMAF32;
316e8d8bef9SDimitry Andric   }
317e8d8bef9SDimitry Andric 
318e8d8bef9SDimitry Andric   bool hasHalfRate64Ops() const {
319e8d8bef9SDimitry Andric     return HalfRate64Ops;
320e8d8bef9SDimitry Andric   }
321e8d8bef9SDimitry Andric 
322fe6060f1SDimitry Andric   bool hasFullRate64Ops() const {
323fe6060f1SDimitry Andric     return FullRate64Ops;
324fe6060f1SDimitry Andric   }
325fe6060f1SDimitry Andric 
326e8d8bef9SDimitry Andric   bool hasAddr64() const {
327e8d8bef9SDimitry Andric     return (getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS);
328e8d8bef9SDimitry Andric   }
329e8d8bef9SDimitry Andric 
330e8d8bef9SDimitry Andric   bool hasFlat() const {
331e8d8bef9SDimitry Andric     return (getGeneration() > AMDGPUSubtarget::SOUTHERN_ISLANDS);
332e8d8bef9SDimitry Andric   }
333e8d8bef9SDimitry Andric 
334e8d8bef9SDimitry Andric   // Return true if the target only has the reverse operand versions of VALU
335e8d8bef9SDimitry Andric   // shift instructions (e.g. v_lshrrev_b32, and no v_lshr_b32).
336e8d8bef9SDimitry Andric   bool hasOnlyRevVALUShifts() const {
337e8d8bef9SDimitry Andric     return getGeneration() >= VOLCANIC_ISLANDS;
338e8d8bef9SDimitry Andric   }
339e8d8bef9SDimitry Andric 
340e8d8bef9SDimitry Andric   bool hasFractBug() const {
341e8d8bef9SDimitry Andric     return getGeneration() == SOUTHERN_ISLANDS;
342e8d8bef9SDimitry Andric   }
343e8d8bef9SDimitry Andric 
344e8d8bef9SDimitry Andric   bool hasBFE() const {
345e8d8bef9SDimitry Andric     return true;
346e8d8bef9SDimitry Andric   }
347e8d8bef9SDimitry Andric 
348e8d8bef9SDimitry Andric   bool hasBFI() const {
349e8d8bef9SDimitry Andric     return true;
350e8d8bef9SDimitry Andric   }
351e8d8bef9SDimitry Andric 
352e8d8bef9SDimitry Andric   bool hasBFM() const {
353e8d8bef9SDimitry Andric     return hasBFE();
354e8d8bef9SDimitry Andric   }
355e8d8bef9SDimitry Andric 
356e8d8bef9SDimitry Andric   bool hasBCNT(unsigned Size) const {
357e8d8bef9SDimitry Andric     return true;
358e8d8bef9SDimitry Andric   }
359e8d8bef9SDimitry Andric 
360e8d8bef9SDimitry Andric   bool hasFFBL() const {
361e8d8bef9SDimitry Andric     return true;
362e8d8bef9SDimitry Andric   }
363e8d8bef9SDimitry Andric 
364e8d8bef9SDimitry Andric   bool hasFFBH() const {
365e8d8bef9SDimitry Andric     return true;
366e8d8bef9SDimitry Andric   }
367e8d8bef9SDimitry Andric 
368e8d8bef9SDimitry Andric   bool hasMed3_16() const {
369e8d8bef9SDimitry Andric     return getGeneration() >= AMDGPUSubtarget::GFX9;
370e8d8bef9SDimitry Andric   }
371e8d8bef9SDimitry Andric 
372e8d8bef9SDimitry Andric   bool hasMin3Max3_16() const {
373e8d8bef9SDimitry Andric     return getGeneration() >= AMDGPUSubtarget::GFX9;
374e8d8bef9SDimitry Andric   }
375e8d8bef9SDimitry Andric 
376e8d8bef9SDimitry Andric   bool hasFmaMixInsts() const {
377e8d8bef9SDimitry Andric     return HasFmaMixInsts;
378e8d8bef9SDimitry Andric   }
379e8d8bef9SDimitry Andric 
380e8d8bef9SDimitry Andric   bool hasCARRY() const {
381e8d8bef9SDimitry Andric     return true;
382e8d8bef9SDimitry Andric   }
383e8d8bef9SDimitry Andric 
384e8d8bef9SDimitry Andric   bool hasFMA() const {
385e8d8bef9SDimitry Andric     return FMA;
386e8d8bef9SDimitry Andric   }
387e8d8bef9SDimitry Andric 
388e8d8bef9SDimitry Andric   bool hasSwap() const {
389e8d8bef9SDimitry Andric     return GFX9Insts;
390e8d8bef9SDimitry Andric   }
391e8d8bef9SDimitry Andric 
392e8d8bef9SDimitry Andric   bool hasScalarPackInsts() const {
393e8d8bef9SDimitry Andric     return GFX9Insts;
394e8d8bef9SDimitry Andric   }
395e8d8bef9SDimitry Andric 
396e8d8bef9SDimitry Andric   bool hasScalarMulHiInsts() const {
397e8d8bef9SDimitry Andric     return GFX9Insts;
398e8d8bef9SDimitry Andric   }
399e8d8bef9SDimitry Andric 
400e8d8bef9SDimitry Andric   TrapHandlerAbi getTrapHandlerAbi() const {
401fe6060f1SDimitry Andric     return isAmdHsaOS() ? TrapHandlerAbi::AMDHSA : TrapHandlerAbi::NONE;
402fe6060f1SDimitry Andric   }
403fe6060f1SDimitry Andric 
404fe6060f1SDimitry Andric   bool supportsGetDoorbellID() const {
405fe6060f1SDimitry Andric     // The S_GETREG DOORBELL_ID is supported by all GFX9 onward targets.
406fe6060f1SDimitry Andric     return getGeneration() >= GFX9;
407e8d8bef9SDimitry Andric   }
408e8d8bef9SDimitry Andric 
409e8d8bef9SDimitry Andric   /// True if the offset field of DS instructions works as expected. On SI, the
410e8d8bef9SDimitry Andric   /// offset uses a 16-bit adder and does not always wrap properly.
411e8d8bef9SDimitry Andric   bool hasUsableDSOffset() const {
412e8d8bef9SDimitry Andric     return getGeneration() >= SEA_ISLANDS;
413e8d8bef9SDimitry Andric   }
414e8d8bef9SDimitry Andric 
415e8d8bef9SDimitry Andric   bool unsafeDSOffsetFoldingEnabled() const {
416e8d8bef9SDimitry Andric     return EnableUnsafeDSOffsetFolding;
417e8d8bef9SDimitry Andric   }
418e8d8bef9SDimitry Andric 
419e8d8bef9SDimitry Andric   /// Condition output from div_scale is usable.
420e8d8bef9SDimitry Andric   bool hasUsableDivScaleConditionOutput() const {
421e8d8bef9SDimitry Andric     return getGeneration() != SOUTHERN_ISLANDS;
422e8d8bef9SDimitry Andric   }
423e8d8bef9SDimitry Andric 
424e8d8bef9SDimitry Andric   /// Extra wait hazard is needed in some cases before
425e8d8bef9SDimitry Andric   /// s_cbranch_vccnz/s_cbranch_vccz.
426e8d8bef9SDimitry Andric   bool hasReadVCCZBug() const {
427e8d8bef9SDimitry Andric     return getGeneration() <= SEA_ISLANDS;
428e8d8bef9SDimitry Andric   }
429e8d8bef9SDimitry Andric 
430e8d8bef9SDimitry Andric   /// Writes to VCC_LO/VCC_HI update the VCCZ flag.
431e8d8bef9SDimitry Andric   bool partialVCCWritesUpdateVCCZ() const {
432e8d8bef9SDimitry Andric     return getGeneration() >= GFX10;
433e8d8bef9SDimitry Andric   }
434e8d8bef9SDimitry Andric 
435e8d8bef9SDimitry Andric   /// A read of an SGPR by SMRD instruction requires 4 wait states when the SGPR
436e8d8bef9SDimitry Andric   /// was written by a VALU instruction.
437e8d8bef9SDimitry Andric   bool hasSMRDReadVALUDefHazard() const {
438e8d8bef9SDimitry Andric     return getGeneration() == SOUTHERN_ISLANDS;
439e8d8bef9SDimitry Andric   }
440e8d8bef9SDimitry Andric 
441e8d8bef9SDimitry Andric   /// A read of an SGPR by a VMEM instruction requires 5 wait states when the
442e8d8bef9SDimitry Andric   /// SGPR was written by a VALU Instruction.
443e8d8bef9SDimitry Andric   bool hasVMEMReadSGPRVALUDefHazard() const {
444e8d8bef9SDimitry Andric     return getGeneration() >= VOLCANIC_ISLANDS;
445e8d8bef9SDimitry Andric   }
446e8d8bef9SDimitry Andric 
447e8d8bef9SDimitry Andric   bool hasRFEHazards() const {
448e8d8bef9SDimitry Andric     return getGeneration() >= VOLCANIC_ISLANDS;
449e8d8bef9SDimitry Andric   }
450e8d8bef9SDimitry Andric 
451e8d8bef9SDimitry Andric   /// Number of hazard wait states for s_setreg_b32/s_setreg_imm32_b32.
452e8d8bef9SDimitry Andric   unsigned getSetRegWaitStates() const {
453e8d8bef9SDimitry Andric     return getGeneration() <= SEA_ISLANDS ? 1 : 2;
454e8d8bef9SDimitry Andric   }
455e8d8bef9SDimitry Andric 
456e8d8bef9SDimitry Andric   bool dumpCode() const {
457e8d8bef9SDimitry Andric     return DumpCode;
458e8d8bef9SDimitry Andric   }
459e8d8bef9SDimitry Andric 
460e8d8bef9SDimitry Andric   /// Return the amount of LDS that can be used that will not restrict the
461e8d8bef9SDimitry Andric   /// occupancy lower than WaveCount.
462e8d8bef9SDimitry Andric   unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
463e8d8bef9SDimitry Andric                                            const Function &) const;
464e8d8bef9SDimitry Andric 
465e8d8bef9SDimitry Andric   bool supportsMinMaxDenormModes() const {
466e8d8bef9SDimitry Andric     return getGeneration() >= AMDGPUSubtarget::GFX9;
467e8d8bef9SDimitry Andric   }
468e8d8bef9SDimitry Andric 
469e8d8bef9SDimitry Andric   /// \returns If target supports S_DENORM_MODE.
470e8d8bef9SDimitry Andric   bool hasDenormModeInst() const {
471e8d8bef9SDimitry Andric     return getGeneration() >= AMDGPUSubtarget::GFX10;
472e8d8bef9SDimitry Andric   }
473e8d8bef9SDimitry Andric 
474e8d8bef9SDimitry Andric   bool useFlatForGlobal() const {
475e8d8bef9SDimitry Andric     return FlatForGlobal;
476e8d8bef9SDimitry Andric   }
477e8d8bef9SDimitry Andric 
478e8d8bef9SDimitry Andric   /// \returns If target supports ds_read/write_b128 and user enables generation
479e8d8bef9SDimitry Andric   /// of ds_read/write_b128.
480e8d8bef9SDimitry Andric   bool useDS128() const {
481e8d8bef9SDimitry Andric     return CIInsts && EnableDS128;
482e8d8bef9SDimitry Andric   }
483e8d8bef9SDimitry Andric 
484e8d8bef9SDimitry Andric   /// \return If target supports ds_read/write_b96/128.
485e8d8bef9SDimitry Andric   bool hasDS96AndDS128() const {
486e8d8bef9SDimitry Andric     return CIInsts;
487e8d8bef9SDimitry Andric   }
488e8d8bef9SDimitry Andric 
489e8d8bef9SDimitry Andric   /// Have v_trunc_f64, v_ceil_f64, v_rndne_f64
490e8d8bef9SDimitry Andric   bool haveRoundOpsF64() const {
491e8d8bef9SDimitry Andric     return CIInsts;
492e8d8bef9SDimitry Andric   }
493e8d8bef9SDimitry Andric 
494e8d8bef9SDimitry Andric   /// \returns If MUBUF instructions always perform range checking, even for
495e8d8bef9SDimitry Andric   /// buffer resources used for private memory access.
496e8d8bef9SDimitry Andric   bool privateMemoryResourceIsRangeChecked() const {
497e8d8bef9SDimitry Andric     return getGeneration() < AMDGPUSubtarget::GFX9;
498e8d8bef9SDimitry Andric   }
499e8d8bef9SDimitry Andric 
500e8d8bef9SDimitry Andric   /// \returns If target requires PRT Struct NULL support (zero result registers
501e8d8bef9SDimitry Andric   /// for sparse texture support).
502e8d8bef9SDimitry Andric   bool usePRTStrictNull() const {
503e8d8bef9SDimitry Andric     return EnablePRTStrictNull;
504e8d8bef9SDimitry Andric   }
505e8d8bef9SDimitry Andric 
506e8d8bef9SDimitry Andric   bool hasAutoWaitcntBeforeBarrier() const {
507e8d8bef9SDimitry Andric     return AutoWaitcntBeforeBarrier;
508e8d8bef9SDimitry Andric   }
509e8d8bef9SDimitry Andric 
510e8d8bef9SDimitry Andric   bool hasUnalignedBufferAccess() const {
511e8d8bef9SDimitry Andric     return UnalignedBufferAccess;
512e8d8bef9SDimitry Andric   }
513e8d8bef9SDimitry Andric 
514e8d8bef9SDimitry Andric   bool hasUnalignedBufferAccessEnabled() const {
515e8d8bef9SDimitry Andric     return UnalignedBufferAccess && UnalignedAccessMode;
516e8d8bef9SDimitry Andric   }
517e8d8bef9SDimitry Andric 
518e8d8bef9SDimitry Andric   bool hasUnalignedDSAccess() const {
519e8d8bef9SDimitry Andric     return UnalignedDSAccess;
520e8d8bef9SDimitry Andric   }
521e8d8bef9SDimitry Andric 
522e8d8bef9SDimitry Andric   bool hasUnalignedDSAccessEnabled() const {
523e8d8bef9SDimitry Andric     return UnalignedDSAccess && UnalignedAccessMode;
524e8d8bef9SDimitry Andric   }
525e8d8bef9SDimitry Andric 
526e8d8bef9SDimitry Andric   bool hasUnalignedScratchAccess() const {
527e8d8bef9SDimitry Andric     return UnalignedScratchAccess;
528e8d8bef9SDimitry Andric   }
529e8d8bef9SDimitry Andric 
530e8d8bef9SDimitry Andric   bool hasUnalignedAccessMode() const {
531e8d8bef9SDimitry Andric     return UnalignedAccessMode;
532e8d8bef9SDimitry Andric   }
533e8d8bef9SDimitry Andric 
534e8d8bef9SDimitry Andric   bool hasApertureRegs() const {
535e8d8bef9SDimitry Andric     return HasApertureRegs;
536e8d8bef9SDimitry Andric   }
537e8d8bef9SDimitry Andric 
538e8d8bef9SDimitry Andric   bool isTrapHandlerEnabled() const {
539e8d8bef9SDimitry Andric     return TrapHandler;
540e8d8bef9SDimitry Andric   }
541e8d8bef9SDimitry Andric 
542e8d8bef9SDimitry Andric   bool isXNACKEnabled() const {
543e8d8bef9SDimitry Andric     return TargetID.isXnackOnOrAny();
544e8d8bef9SDimitry Andric   }
545e8d8bef9SDimitry Andric 
546fe6060f1SDimitry Andric   bool isTgSplitEnabled() const {
547fe6060f1SDimitry Andric     return EnableTgSplit;
548fe6060f1SDimitry Andric   }
549fe6060f1SDimitry Andric 
550e8d8bef9SDimitry Andric   bool isCuModeEnabled() const {
551e8d8bef9SDimitry Andric     return EnableCuMode;
552e8d8bef9SDimitry Andric   }
553e8d8bef9SDimitry Andric 
554e8d8bef9SDimitry Andric   bool hasFlatAddressSpace() const {
555e8d8bef9SDimitry Andric     return FlatAddressSpace;
556e8d8bef9SDimitry Andric   }
557e8d8bef9SDimitry Andric 
558e8d8bef9SDimitry Andric   bool hasFlatScrRegister() const {
559e8d8bef9SDimitry Andric     return hasFlatAddressSpace();
560e8d8bef9SDimitry Andric   }
561e8d8bef9SDimitry Andric 
562e8d8bef9SDimitry Andric   bool hasFlatInstOffsets() const {
563e8d8bef9SDimitry Andric     return FlatInstOffsets;
564e8d8bef9SDimitry Andric   }
565e8d8bef9SDimitry Andric 
566e8d8bef9SDimitry Andric   bool hasFlatGlobalInsts() const {
567e8d8bef9SDimitry Andric     return FlatGlobalInsts;
568e8d8bef9SDimitry Andric   }
569e8d8bef9SDimitry Andric 
570e8d8bef9SDimitry Andric   bool hasFlatScratchInsts() const {
571e8d8bef9SDimitry Andric     return FlatScratchInsts;
572e8d8bef9SDimitry Andric   }
573e8d8bef9SDimitry Andric 
574e8d8bef9SDimitry Andric   // Check if target supports ST addressing mode with FLAT scratch instructions.
575e8d8bef9SDimitry Andric   // The ST addressing mode means no registers are used, either VGPR or SGPR,
576e8d8bef9SDimitry Andric   // but only immediate offset is swizzled and added to the FLAT scratch base.
577e8d8bef9SDimitry Andric   bool hasFlatScratchSTMode() const {
57881ad6265SDimitry Andric     return hasFlatScratchInsts() && (hasGFX10_3Insts() || hasGFX940Insts());
579e8d8bef9SDimitry Andric   }
580e8d8bef9SDimitry Andric 
58181ad6265SDimitry Andric   bool hasFlatScratchSVSMode() const { return GFX940Insts || GFX11Insts; }
58281ad6265SDimitry Andric 
583e8d8bef9SDimitry Andric   bool hasScalarFlatScratchInsts() const {
584e8d8bef9SDimitry Andric     return ScalarFlatScratchInsts;
585e8d8bef9SDimitry Andric   }
586e8d8bef9SDimitry Andric 
58781ad6265SDimitry Andric   bool enableFlatScratch() const {
58881ad6265SDimitry Andric     return flatScratchIsArchitected() ||
58981ad6265SDimitry Andric            (EnableFlatScratch && hasFlatScratchInsts());
59081ad6265SDimitry Andric   }
59181ad6265SDimitry Andric 
592e8d8bef9SDimitry Andric   bool hasGlobalAddTidInsts() const {
593e8d8bef9SDimitry Andric     return GFX10_BEncoding;
594e8d8bef9SDimitry Andric   }
595e8d8bef9SDimitry Andric 
596e8d8bef9SDimitry Andric   bool hasAtomicCSub() const {
597e8d8bef9SDimitry Andric     return GFX10_BEncoding;
598e8d8bef9SDimitry Andric   }
599e8d8bef9SDimitry Andric 
600e8d8bef9SDimitry Andric   bool hasMultiDwordFlatScratchAddressing() const {
601e8d8bef9SDimitry Andric     return getGeneration() >= GFX9;
602e8d8bef9SDimitry Andric   }
603e8d8bef9SDimitry Andric 
604e8d8bef9SDimitry Andric   bool hasFlatSegmentOffsetBug() const {
605e8d8bef9SDimitry Andric     return HasFlatSegmentOffsetBug;
606e8d8bef9SDimitry Andric   }
607e8d8bef9SDimitry Andric 
608e8d8bef9SDimitry Andric   bool hasFlatLgkmVMemCountInOrder() const {
609e8d8bef9SDimitry Andric     return getGeneration() > GFX9;
610e8d8bef9SDimitry Andric   }
611e8d8bef9SDimitry Andric 
612e8d8bef9SDimitry Andric   bool hasD16LoadStore() const {
613e8d8bef9SDimitry Andric     return getGeneration() >= GFX9;
614e8d8bef9SDimitry Andric   }
615e8d8bef9SDimitry Andric 
616e8d8bef9SDimitry Andric   bool d16PreservesUnusedBits() const {
617e8d8bef9SDimitry Andric     return hasD16LoadStore() && !TargetID.isSramEccOnOrAny();
618e8d8bef9SDimitry Andric   }
619e8d8bef9SDimitry Andric 
620e8d8bef9SDimitry Andric   bool hasD16Images() const {
621e8d8bef9SDimitry Andric     return getGeneration() >= VOLCANIC_ISLANDS;
622e8d8bef9SDimitry Andric   }
623e8d8bef9SDimitry Andric 
624e8d8bef9SDimitry Andric   /// Return if most LDS instructions have an m0 use that require m0 to be
625349cc55cSDimitry Andric   /// initialized.
626e8d8bef9SDimitry Andric   bool ldsRequiresM0Init() const {
627e8d8bef9SDimitry Andric     return getGeneration() < GFX9;
628e8d8bef9SDimitry Andric   }
629e8d8bef9SDimitry Andric 
630e8d8bef9SDimitry Andric   // True if the hardware rewinds and replays GWS operations if a wave is
631e8d8bef9SDimitry Andric   // preempted.
632e8d8bef9SDimitry Andric   //
633e8d8bef9SDimitry Andric   // If this is false, a GWS operation requires testing if a nack set the
634e8d8bef9SDimitry Andric   // MEM_VIOL bit, and repeating if so.
635e8d8bef9SDimitry Andric   bool hasGWSAutoReplay() const {
636e8d8bef9SDimitry Andric     return getGeneration() >= GFX9;
637e8d8bef9SDimitry Andric   }
638e8d8bef9SDimitry Andric 
639e8d8bef9SDimitry Andric   /// \returns if target has ds_gws_sema_release_all instruction.
640e8d8bef9SDimitry Andric   bool hasGWSSemaReleaseAll() const {
641e8d8bef9SDimitry Andric     return CIInsts;
642e8d8bef9SDimitry Andric   }
643e8d8bef9SDimitry Andric 
644e8d8bef9SDimitry Andric   /// \returns true if the target has integer add/sub instructions that do not
645e8d8bef9SDimitry Andric   /// produce a carry-out. This includes v_add_[iu]32, v_sub_[iu]32,
646e8d8bef9SDimitry Andric   /// v_add_[iu]16, and v_sub_[iu]16, all of which support the clamp modifier
647e8d8bef9SDimitry Andric   /// for saturation.
648e8d8bef9SDimitry Andric   bool hasAddNoCarry() const {
649e8d8bef9SDimitry Andric     return AddNoCarryInsts;
650e8d8bef9SDimitry Andric   }
651e8d8bef9SDimitry Andric 
652e8d8bef9SDimitry Andric   bool hasUnpackedD16VMem() const {
653e8d8bef9SDimitry Andric     return HasUnpackedD16VMem;
654e8d8bef9SDimitry Andric   }
655e8d8bef9SDimitry Andric 
656e8d8bef9SDimitry Andric   // Covers VS/PS/CS graphics shaders
657e8d8bef9SDimitry Andric   bool isMesaGfxShader(const Function &F) const {
658e8d8bef9SDimitry Andric     return isMesa3DOS() && AMDGPU::isShader(F.getCallingConv());
659e8d8bef9SDimitry Andric   }
660e8d8bef9SDimitry Andric 
661e8d8bef9SDimitry Andric   bool hasMad64_32() const {
662e8d8bef9SDimitry Andric     return getGeneration() >= SEA_ISLANDS;
663e8d8bef9SDimitry Andric   }
664e8d8bef9SDimitry Andric 
665e8d8bef9SDimitry Andric   bool hasSDWAOmod() const {
666e8d8bef9SDimitry Andric     return HasSDWAOmod;
667e8d8bef9SDimitry Andric   }
668e8d8bef9SDimitry Andric 
669e8d8bef9SDimitry Andric   bool hasSDWAScalar() const {
670e8d8bef9SDimitry Andric     return HasSDWAScalar;
671e8d8bef9SDimitry Andric   }
672e8d8bef9SDimitry Andric 
673e8d8bef9SDimitry Andric   bool hasSDWASdst() const {
674e8d8bef9SDimitry Andric     return HasSDWASdst;
675e8d8bef9SDimitry Andric   }
676e8d8bef9SDimitry Andric 
677e8d8bef9SDimitry Andric   bool hasSDWAMac() const {
678e8d8bef9SDimitry Andric     return HasSDWAMac;
679e8d8bef9SDimitry Andric   }
680e8d8bef9SDimitry Andric 
681e8d8bef9SDimitry Andric   bool hasSDWAOutModsVOPC() const {
682e8d8bef9SDimitry Andric     return HasSDWAOutModsVOPC;
683e8d8bef9SDimitry Andric   }
684e8d8bef9SDimitry Andric 
685e8d8bef9SDimitry Andric   bool hasDLInsts() const {
686e8d8bef9SDimitry Andric     return HasDLInsts;
687e8d8bef9SDimitry Andric   }
688e8d8bef9SDimitry Andric 
689e8d8bef9SDimitry Andric   bool hasDot1Insts() const {
690e8d8bef9SDimitry Andric     return HasDot1Insts;
691e8d8bef9SDimitry Andric   }
692e8d8bef9SDimitry Andric 
693e8d8bef9SDimitry Andric   bool hasDot2Insts() const {
694e8d8bef9SDimitry Andric     return HasDot2Insts;
695e8d8bef9SDimitry Andric   }
696e8d8bef9SDimitry Andric 
697e8d8bef9SDimitry Andric   bool hasDot3Insts() const {
698e8d8bef9SDimitry Andric     return HasDot3Insts;
699e8d8bef9SDimitry Andric   }
700e8d8bef9SDimitry Andric 
701e8d8bef9SDimitry Andric   bool hasDot4Insts() const {
702e8d8bef9SDimitry Andric     return HasDot4Insts;
703e8d8bef9SDimitry Andric   }
704e8d8bef9SDimitry Andric 
705e8d8bef9SDimitry Andric   bool hasDot5Insts() const {
706e8d8bef9SDimitry Andric     return HasDot5Insts;
707e8d8bef9SDimitry Andric   }
708e8d8bef9SDimitry Andric 
709e8d8bef9SDimitry Andric   bool hasDot6Insts() const {
710e8d8bef9SDimitry Andric     return HasDot6Insts;
711e8d8bef9SDimitry Andric   }
712e8d8bef9SDimitry Andric 
713fe6060f1SDimitry Andric   bool hasDot7Insts() const {
714fe6060f1SDimitry Andric     return HasDot7Insts;
715fe6060f1SDimitry Andric   }
716fe6060f1SDimitry Andric 
71781ad6265SDimitry Andric   bool hasDot8Insts() const {
71881ad6265SDimitry Andric     return HasDot8Insts;
71981ad6265SDimitry Andric   }
72081ad6265SDimitry Andric 
721e8d8bef9SDimitry Andric   bool hasMAIInsts() const {
722e8d8bef9SDimitry Andric     return HasMAIInsts;
723e8d8bef9SDimitry Andric   }
724e8d8bef9SDimitry Andric 
725*fcaf7f86SDimitry Andric   bool hasFP8Insts() const {
726*fcaf7f86SDimitry Andric     return HasFP8Insts;
727*fcaf7f86SDimitry Andric   }
728*fcaf7f86SDimitry Andric 
729e8d8bef9SDimitry Andric   bool hasPkFmacF16Inst() const {
730e8d8bef9SDimitry Andric     return HasPkFmacF16Inst;
731e8d8bef9SDimitry Andric   }
732e8d8bef9SDimitry Andric 
733e8d8bef9SDimitry Andric   bool hasAtomicFaddInsts() const {
73481ad6265SDimitry Andric     return HasAtomicFaddRtnInsts || HasAtomicFaddNoRtnInsts;
735e8d8bef9SDimitry Andric   }
736e8d8bef9SDimitry Andric 
73781ad6265SDimitry Andric   bool hasAtomicFaddRtnInsts() const { return HasAtomicFaddRtnInsts; }
73881ad6265SDimitry Andric 
73981ad6265SDimitry Andric   bool hasAtomicFaddNoRtnInsts() const { return HasAtomicFaddNoRtnInsts; }
74081ad6265SDimitry Andric 
74181ad6265SDimitry Andric   bool hasAtomicPkFaddNoRtnInsts() const { return HasAtomicPkFaddNoRtnInsts; }
74281ad6265SDimitry Andric 
743e8d8bef9SDimitry Andric   bool hasNoSdstCMPX() const {
744e8d8bef9SDimitry Andric     return HasNoSdstCMPX;
745e8d8bef9SDimitry Andric   }
746e8d8bef9SDimitry Andric 
747e8d8bef9SDimitry Andric   bool hasVscnt() const {
748e8d8bef9SDimitry Andric     return HasVscnt;
749e8d8bef9SDimitry Andric   }
750e8d8bef9SDimitry Andric 
751e8d8bef9SDimitry Andric   bool hasGetWaveIdInst() const {
752e8d8bef9SDimitry Andric     return HasGetWaveIdInst;
753e8d8bef9SDimitry Andric   }
754e8d8bef9SDimitry Andric 
755e8d8bef9SDimitry Andric   bool hasSMemTimeInst() const {
756e8d8bef9SDimitry Andric     return HasSMemTimeInst;
757e8d8bef9SDimitry Andric   }
758e8d8bef9SDimitry Andric 
759fe6060f1SDimitry Andric   bool hasShaderCyclesRegister() const {
760fe6060f1SDimitry Andric     return HasShaderCyclesRegister;
761fe6060f1SDimitry Andric   }
762fe6060f1SDimitry Andric 
763e8d8bef9SDimitry Andric   bool hasVOP3Literal() const {
764e8d8bef9SDimitry Andric     return HasVOP3Literal;
765e8d8bef9SDimitry Andric   }
766e8d8bef9SDimitry Andric 
767e8d8bef9SDimitry Andric   bool hasNoDataDepHazard() const {
768e8d8bef9SDimitry Andric     return HasNoDataDepHazard;
769e8d8bef9SDimitry Andric   }
770e8d8bef9SDimitry Andric 
771e8d8bef9SDimitry Andric   bool vmemWriteNeedsExpWaitcnt() const {
772e8d8bef9SDimitry Andric     return getGeneration() < SEA_ISLANDS;
773e8d8bef9SDimitry Andric   }
774e8d8bef9SDimitry Andric 
775e8d8bef9SDimitry Andric   // Scratch is allocated in 256 dword per wave blocks for the entire
776349cc55cSDimitry Andric   // wavefront. When viewed from the perspective of an arbitrary workitem, this
777e8d8bef9SDimitry Andric   // is 4-byte aligned.
778e8d8bef9SDimitry Andric   //
779e8d8bef9SDimitry Andric   // Only 4-byte alignment is really needed to access anything. Transformations
780e8d8bef9SDimitry Andric   // on the pointer value itself may rely on the alignment / known low bits of
781e8d8bef9SDimitry Andric   // the pointer. Set this to something above the minimum to avoid needing
782e8d8bef9SDimitry Andric   // dynamic realignment in common cases.
783e8d8bef9SDimitry Andric   Align getStackAlignment() const { return Align(16); }
784e8d8bef9SDimitry Andric 
785e8d8bef9SDimitry Andric   bool enableMachineScheduler() const override {
786e8d8bef9SDimitry Andric     return true;
787e8d8bef9SDimitry Andric   }
788e8d8bef9SDimitry Andric 
789e8d8bef9SDimitry Andric   bool useAA() const override;
790e8d8bef9SDimitry Andric 
791e8d8bef9SDimitry Andric   bool enableSubRegLiveness() const override {
792e8d8bef9SDimitry Andric     return true;
793e8d8bef9SDimitry Andric   }
794e8d8bef9SDimitry Andric 
795e8d8bef9SDimitry Andric   void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b; }
796e8d8bef9SDimitry Andric   bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal; }
797e8d8bef9SDimitry Andric 
798e8d8bef9SDimitry Andric   // static wrappers
799e8d8bef9SDimitry Andric   static bool hasHalfRate64Ops(const TargetSubtargetInfo &STI);
800e8d8bef9SDimitry Andric 
801e8d8bef9SDimitry Andric   // XXX - Why is this here if it isn't in the default pass set?
802e8d8bef9SDimitry Andric   bool enableEarlyIfConversion() const override {
803e8d8bef9SDimitry Andric     return true;
804e8d8bef9SDimitry Andric   }
805e8d8bef9SDimitry Andric 
806e8d8bef9SDimitry Andric   void overrideSchedPolicy(MachineSchedPolicy &Policy,
807e8d8bef9SDimitry Andric                            unsigned NumRegionInstrs) const override;
808e8d8bef9SDimitry Andric 
809e8d8bef9SDimitry Andric   unsigned getMaxNumUserSGPRs() const {
810e8d8bef9SDimitry Andric     return 16;
811e8d8bef9SDimitry Andric   }
812e8d8bef9SDimitry Andric 
813e8d8bef9SDimitry Andric   bool hasSMemRealTime() const {
814e8d8bef9SDimitry Andric     return HasSMemRealTime;
815e8d8bef9SDimitry Andric   }
816e8d8bef9SDimitry Andric 
817e8d8bef9SDimitry Andric   bool hasMovrel() const {
818e8d8bef9SDimitry Andric     return HasMovrel;
819e8d8bef9SDimitry Andric   }
820e8d8bef9SDimitry Andric 
821e8d8bef9SDimitry Andric   bool hasVGPRIndexMode() const {
822e8d8bef9SDimitry Andric     return HasVGPRIndexMode;
823e8d8bef9SDimitry Andric   }
824e8d8bef9SDimitry Andric 
825e8d8bef9SDimitry Andric   bool useVGPRIndexMode() const;
826e8d8bef9SDimitry Andric 
827e8d8bef9SDimitry Andric   bool hasScalarCompareEq64() const {
828e8d8bef9SDimitry Andric     return getGeneration() >= VOLCANIC_ISLANDS;
829e8d8bef9SDimitry Andric   }
830e8d8bef9SDimitry Andric 
831e8d8bef9SDimitry Andric   bool hasScalarStores() const {
832e8d8bef9SDimitry Andric     return HasScalarStores;
833e8d8bef9SDimitry Andric   }
834e8d8bef9SDimitry Andric 
835e8d8bef9SDimitry Andric   bool hasScalarAtomics() const {
836e8d8bef9SDimitry Andric     return HasScalarAtomics;
837e8d8bef9SDimitry Andric   }
838e8d8bef9SDimitry Andric 
839349cc55cSDimitry Andric   bool hasLDSFPAtomicAdd() const { return GFX8Insts; }
840e8d8bef9SDimitry Andric 
841fe6060f1SDimitry Andric   /// \returns true if the subtarget has the v_permlanex16_b32 instruction.
842fe6060f1SDimitry Andric   bool hasPermLaneX16() const { return getGeneration() >= GFX10; }
843fe6060f1SDimitry Andric 
84481ad6265SDimitry Andric   /// \returns true if the subtarget has the v_permlane64_b32 instruction.
84581ad6265SDimitry Andric   bool hasPermLane64() const { return getGeneration() >= GFX11; }
84681ad6265SDimitry Andric 
847e8d8bef9SDimitry Andric   bool hasDPP() const {
848e8d8bef9SDimitry Andric     return HasDPP;
849e8d8bef9SDimitry Andric   }
850e8d8bef9SDimitry Andric 
851e8d8bef9SDimitry Andric   bool hasDPPBroadcasts() const {
852e8d8bef9SDimitry Andric     return HasDPP && getGeneration() < GFX10;
853e8d8bef9SDimitry Andric   }
854e8d8bef9SDimitry Andric 
855e8d8bef9SDimitry Andric   bool hasDPPWavefrontShifts() const {
856e8d8bef9SDimitry Andric     return HasDPP && getGeneration() < GFX10;
857e8d8bef9SDimitry Andric   }
858e8d8bef9SDimitry Andric 
859e8d8bef9SDimitry Andric   bool hasDPP8() const {
860e8d8bef9SDimitry Andric     return HasDPP8;
861e8d8bef9SDimitry Andric   }
862e8d8bef9SDimitry Andric 
863fe6060f1SDimitry Andric   bool has64BitDPP() const {
864fe6060f1SDimitry Andric     return Has64BitDPP;
865fe6060f1SDimitry Andric   }
866fe6060f1SDimitry Andric 
867fe6060f1SDimitry Andric   bool hasPackedFP32Ops() const {
868fe6060f1SDimitry Andric     return HasPackedFP32Ops;
869fe6060f1SDimitry Andric   }
870fe6060f1SDimitry Andric 
871fe6060f1SDimitry Andric   bool hasFmaakFmamkF32Insts() const {
87281ad6265SDimitry Andric     return getGeneration() >= GFX10 || hasGFX940Insts();
87381ad6265SDimitry Andric   }
87481ad6265SDimitry Andric 
87581ad6265SDimitry Andric   bool hasImageInsts() const {
87681ad6265SDimitry Andric     return HasImageInsts;
877fe6060f1SDimitry Andric   }
878fe6060f1SDimitry Andric 
879fe6060f1SDimitry Andric   bool hasExtendedImageInsts() const {
880fe6060f1SDimitry Andric     return HasExtendedImageInsts;
881fe6060f1SDimitry Andric   }
882fe6060f1SDimitry Andric 
883e8d8bef9SDimitry Andric   bool hasR128A16() const {
884e8d8bef9SDimitry Andric     return HasR128A16;
885e8d8bef9SDimitry Andric   }
886e8d8bef9SDimitry Andric 
887e8d8bef9SDimitry Andric   bool hasGFX10A16() const {
888e8d8bef9SDimitry Andric     return HasGFX10A16;
889e8d8bef9SDimitry Andric   }
890e8d8bef9SDimitry Andric 
891e8d8bef9SDimitry Andric   bool hasA16() const { return hasR128A16() || hasGFX10A16(); }
892e8d8bef9SDimitry Andric 
893e8d8bef9SDimitry Andric   bool hasG16() const { return HasG16; }
894e8d8bef9SDimitry Andric 
895e8d8bef9SDimitry Andric   bool hasOffset3fBug() const {
896e8d8bef9SDimitry Andric     return HasOffset3fBug;
897e8d8bef9SDimitry Andric   }
898e8d8bef9SDimitry Andric 
899e8d8bef9SDimitry Andric   bool hasImageStoreD16Bug() const { return HasImageStoreD16Bug; }
900e8d8bef9SDimitry Andric 
901e8d8bef9SDimitry Andric   bool hasImageGather4D16Bug() const { return HasImageGather4D16Bug; }
902e8d8bef9SDimitry Andric 
903e8d8bef9SDimitry Andric   bool hasNSAEncoding() const { return HasNSAEncoding; }
904e8d8bef9SDimitry Andric 
905fe6060f1SDimitry Andric   unsigned getNSAMaxSize() const { return NSAMaxSize; }
906fe6060f1SDimitry Andric 
907fe6060f1SDimitry Andric   bool hasGFX10_AEncoding() const {
908fe6060f1SDimitry Andric     return GFX10_AEncoding;
909fe6060f1SDimitry Andric   }
910fe6060f1SDimitry Andric 
911e8d8bef9SDimitry Andric   bool hasGFX10_BEncoding() const {
912e8d8bef9SDimitry Andric     return GFX10_BEncoding;
913e8d8bef9SDimitry Andric   }
914e8d8bef9SDimitry Andric 
915e8d8bef9SDimitry Andric   bool hasGFX10_3Insts() const {
916e8d8bef9SDimitry Andric     return GFX10_3Insts;
917e8d8bef9SDimitry Andric   }
918e8d8bef9SDimitry Andric 
919e8d8bef9SDimitry Andric   bool hasMadF16() const;
920e8d8bef9SDimitry Andric 
92181ad6265SDimitry Andric   bool hasMovB64() const { return GFX940Insts; }
92281ad6265SDimitry Andric 
92381ad6265SDimitry Andric   bool hasLshlAddB64() const { return GFX940Insts; }
92481ad6265SDimitry Andric 
925e8d8bef9SDimitry Andric   bool enableSIScheduler() const {
926e8d8bef9SDimitry Andric     return EnableSIScheduler;
927e8d8bef9SDimitry Andric   }
928e8d8bef9SDimitry Andric 
929e8d8bef9SDimitry Andric   bool loadStoreOptEnabled() const {
930e8d8bef9SDimitry Andric     return EnableLoadStoreOpt;
931e8d8bef9SDimitry Andric   }
932e8d8bef9SDimitry Andric 
933e8d8bef9SDimitry Andric   bool hasSGPRInitBug() const {
934e8d8bef9SDimitry Andric     return SGPRInitBug;
935e8d8bef9SDimitry Andric   }
936e8d8bef9SDimitry Andric 
93781ad6265SDimitry Andric   bool hasUserSGPRInit16Bug() const {
938*fcaf7f86SDimitry Andric     return UserSGPRInit16Bug && isWave32();
93981ad6265SDimitry Andric   }
94081ad6265SDimitry Andric 
941fe6060f1SDimitry Andric   bool hasNegativeScratchOffsetBug() const { return NegativeScratchOffsetBug; }
942fe6060f1SDimitry Andric 
943fe6060f1SDimitry Andric   bool hasNegativeUnalignedScratchOffsetBug() const {
944fe6060f1SDimitry Andric     return NegativeUnalignedScratchOffsetBug;
945fe6060f1SDimitry Andric   }
946fe6060f1SDimitry Andric 
947e8d8bef9SDimitry Andric   bool hasMFMAInlineLiteralBug() const {
948e8d8bef9SDimitry Andric     return HasMFMAInlineLiteralBug;
949e8d8bef9SDimitry Andric   }
950e8d8bef9SDimitry Andric 
951e8d8bef9SDimitry Andric   bool has12DWordStoreHazard() const {
952e8d8bef9SDimitry Andric     return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
953e8d8bef9SDimitry Andric   }
954e8d8bef9SDimitry Andric 
955e8d8bef9SDimitry Andric   // \returns true if the subtarget supports DWORDX3 load/store instructions.
956e8d8bef9SDimitry Andric   bool hasDwordx3LoadStores() const {
957e8d8bef9SDimitry Andric     return CIInsts;
958e8d8bef9SDimitry Andric   }
959e8d8bef9SDimitry Andric 
960e8d8bef9SDimitry Andric   bool hasReadM0MovRelInterpHazard() const {
961e8d8bef9SDimitry Andric     return getGeneration() == AMDGPUSubtarget::GFX9;
962e8d8bef9SDimitry Andric   }
963e8d8bef9SDimitry Andric 
964e8d8bef9SDimitry Andric   bool hasReadM0SendMsgHazard() const {
965e8d8bef9SDimitry Andric     return getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS &&
966e8d8bef9SDimitry Andric            getGeneration() <= AMDGPUSubtarget::GFX9;
967e8d8bef9SDimitry Andric   }
968e8d8bef9SDimitry Andric 
96981ad6265SDimitry Andric   bool hasReadM0LdsDmaHazard() const {
97081ad6265SDimitry Andric     return getGeneration() == AMDGPUSubtarget::GFX9;
97181ad6265SDimitry Andric   }
97281ad6265SDimitry Andric 
97381ad6265SDimitry Andric   bool hasReadM0LdsDirectHazard() const {
97481ad6265SDimitry Andric     return getGeneration() == AMDGPUSubtarget::GFX9;
97581ad6265SDimitry Andric   }
97681ad6265SDimitry Andric 
977e8d8bef9SDimitry Andric   bool hasVcmpxPermlaneHazard() const {
978e8d8bef9SDimitry Andric     return HasVcmpxPermlaneHazard;
979e8d8bef9SDimitry Andric   }
980e8d8bef9SDimitry Andric 
981e8d8bef9SDimitry Andric   bool hasVMEMtoScalarWriteHazard() const {
982e8d8bef9SDimitry Andric     return HasVMEMtoScalarWriteHazard;
983e8d8bef9SDimitry Andric   }
984e8d8bef9SDimitry Andric 
985e8d8bef9SDimitry Andric   bool hasSMEMtoVectorWriteHazard() const {
986e8d8bef9SDimitry Andric     return HasSMEMtoVectorWriteHazard;
987e8d8bef9SDimitry Andric   }
988e8d8bef9SDimitry Andric 
989e8d8bef9SDimitry Andric   bool hasLDSMisalignedBug() const {
990e8d8bef9SDimitry Andric     return LDSMisalignedBug && !EnableCuMode;
991e8d8bef9SDimitry Andric   }
992e8d8bef9SDimitry Andric 
993e8d8bef9SDimitry Andric   bool hasInstFwdPrefetchBug() const {
994e8d8bef9SDimitry Andric     return HasInstFwdPrefetchBug;
995e8d8bef9SDimitry Andric   }
996e8d8bef9SDimitry Andric 
997e8d8bef9SDimitry Andric   bool hasVcmpxExecWARHazard() const {
998e8d8bef9SDimitry Andric     return HasVcmpxExecWARHazard;
999e8d8bef9SDimitry Andric   }
1000e8d8bef9SDimitry Andric 
1001e8d8bef9SDimitry Andric   bool hasLdsBranchVmemWARHazard() const {
1002e8d8bef9SDimitry Andric     return HasLdsBranchVmemWARHazard;
1003e8d8bef9SDimitry Andric   }
1004e8d8bef9SDimitry Andric 
100581ad6265SDimitry Andric   // Has one cycle hazard on transcendental instruction feeding a
100681ad6265SDimitry Andric   // non transcendental VALU.
100781ad6265SDimitry Andric   bool hasTransForwardingHazard() const { return GFX940Insts; }
100881ad6265SDimitry Andric 
100981ad6265SDimitry Andric   // Has one cycle hazard on a VALU instruction partially writing dst with
101081ad6265SDimitry Andric   // a shift of result bits feeding another VALU instruction.
101181ad6265SDimitry Andric   bool hasDstSelForwardingHazard() const { return GFX940Insts; }
101281ad6265SDimitry Andric 
101381ad6265SDimitry Andric   // Cannot use op_sel with v_dot instructions.
101481ad6265SDimitry Andric   bool hasDOTOpSelHazard() const { return GFX940Insts; }
101581ad6265SDimitry Andric 
101681ad6265SDimitry Andric   // Does not have HW interlocs for VALU writing and then reading SGPRs.
101781ad6265SDimitry Andric   bool hasVDecCoExecHazard() const {
101881ad6265SDimitry Andric     return GFX940Insts;
101981ad6265SDimitry Andric   }
102081ad6265SDimitry Andric 
1021e8d8bef9SDimitry Andric   bool hasNSAtoVMEMBug() const {
1022e8d8bef9SDimitry Andric     return HasNSAtoVMEMBug;
1023e8d8bef9SDimitry Andric   }
1024e8d8bef9SDimitry Andric 
1025fe6060f1SDimitry Andric   bool hasNSAClauseBug() const { return HasNSAClauseBug; }
1026fe6060f1SDimitry Andric 
1027e8d8bef9SDimitry Andric   bool hasHardClauses() const { return getGeneration() >= GFX10; }
1028e8d8bef9SDimitry Andric 
1029fe6060f1SDimitry Andric   bool hasGFX90AInsts() const { return GFX90AInsts; }
1030fe6060f1SDimitry Andric 
103181ad6265SDimitry Andric   bool hasVOP3DPP() const { return getGeneration() >= GFX11; }
103281ad6265SDimitry Andric 
103381ad6265SDimitry Andric   bool hasLdsDirect() const { return getGeneration() >= GFX11; }
103481ad6265SDimitry Andric 
103581ad6265SDimitry Andric   bool hasVALUPartialForwardingHazard() const {
103681ad6265SDimitry Andric     return getGeneration() >= GFX11;
103781ad6265SDimitry Andric   }
103881ad6265SDimitry Andric 
103981ad6265SDimitry Andric   bool hasVALUTransUseHazard() const { return getGeneration() >= GFX11; }
104081ad6265SDimitry Andric 
1041fe6060f1SDimitry Andric   /// Return if operations acting on VGPR tuples require even alignment.
1042fe6060f1SDimitry Andric   bool needsAlignedVGPRs() const { return GFX90AInsts; }
1043fe6060f1SDimitry Andric 
104481ad6265SDimitry Andric   /// Return true if the target has the S_PACK_HL_B32_B16 instruction.
104581ad6265SDimitry Andric   bool hasSPackHL() const { return GFX11Insts; }
104681ad6265SDimitry Andric 
104781ad6265SDimitry Andric   /// Return true if the target's EXP instruction has the COMPR flag, which
104881ad6265SDimitry Andric   /// affects the meaning of the EN (enable) bits.
104981ad6265SDimitry Andric   bool hasCompressedExport() const { return !GFX11Insts; }
105081ad6265SDimitry Andric 
105181ad6265SDimitry Andric   /// Return true if the target's EXP instruction supports the NULL export
105281ad6265SDimitry Andric   /// target.
105381ad6265SDimitry Andric   bool hasNullExportTarget() const { return !GFX11Insts; }
105481ad6265SDimitry Andric 
105581ad6265SDimitry Andric   bool hasVOPDInsts() const { return HasVOPDInsts; }
105681ad6265SDimitry Andric 
105781ad6265SDimitry Andric   bool hasFlatScratchSVSSwizzleBug() const { return getGeneration() == GFX11; }
105881ad6265SDimitry Andric 
105981ad6265SDimitry Andric   /// Return true if the target has the S_DELAY_ALU instruction.
106081ad6265SDimitry Andric   bool hasDelayAlu() const { return GFX11Insts; }
106181ad6265SDimitry Andric 
1062fe6060f1SDimitry Andric   bool hasPackedTID() const { return HasPackedTID; }
1063fe6060f1SDimitry Andric 
106481ad6265SDimitry Andric   // GFX940 is a derivation to GFX90A. hasGFX940Insts() being true implies that
106581ad6265SDimitry Andric   // hasGFX90AInsts is also true.
106681ad6265SDimitry Andric   bool hasGFX940Insts() const { return GFX940Insts; }
106781ad6265SDimitry Andric 
1068e8d8bef9SDimitry Andric   /// Return the maximum number of waves per SIMD for kernels using \p SGPRs
1069e8d8bef9SDimitry Andric   /// SGPRs
1070e8d8bef9SDimitry Andric   unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
1071e8d8bef9SDimitry Andric 
1072e8d8bef9SDimitry Andric   /// Return the maximum number of waves per SIMD for kernels using \p VGPRs
1073e8d8bef9SDimitry Andric   /// VGPRs
1074e8d8bef9SDimitry Andric   unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
1075e8d8bef9SDimitry Andric 
1076e8d8bef9SDimitry Andric   /// Return occupancy for the given function. Used LDS and a number of
1077e8d8bef9SDimitry Andric   /// registers if provided.
1078e8d8bef9SDimitry Andric   /// Note, occupancy can be affected by the scratch allocation as well, but
1079e8d8bef9SDimitry Andric   /// we do not have enough information to compute it.
1080e8d8bef9SDimitry Andric   unsigned computeOccupancy(const Function &F, unsigned LDSSize = 0,
1081e8d8bef9SDimitry Andric                             unsigned NumSGPRs = 0, unsigned NumVGPRs = 0) const;
1082e8d8bef9SDimitry Andric 
1083e8d8bef9SDimitry Andric   /// \returns true if the flat_scratch register should be initialized with the
1084e8d8bef9SDimitry Andric   /// pointer to the wave's scratch memory rather than a size and offset.
1085e8d8bef9SDimitry Andric   bool flatScratchIsPointer() const {
1086e8d8bef9SDimitry Andric     return getGeneration() >= AMDGPUSubtarget::GFX9;
1087e8d8bef9SDimitry Andric   }
1088e8d8bef9SDimitry Andric 
1089fe6060f1SDimitry Andric   /// \returns true if the flat_scratch register is initialized by the HW.
1090fe6060f1SDimitry Andric   /// In this case it is readonly.
1091fe6060f1SDimitry Andric   bool flatScratchIsArchitected() const { return HasArchitectedFlatScratch; }
1092fe6060f1SDimitry Andric 
1093e8d8bef9SDimitry Andric   /// \returns true if the machine has merged shaders in which s0-s7 are
1094e8d8bef9SDimitry Andric   /// reserved by the hardware and user SGPRs start at s8
1095e8d8bef9SDimitry Andric   bool hasMergedShaders() const {
1096e8d8bef9SDimitry Andric     return getGeneration() >= GFX9;
1097e8d8bef9SDimitry Andric   }
1098e8d8bef9SDimitry Andric 
109981ad6265SDimitry Andric   // \returns true if the target supports the pre-NGG legacy geometry path.
110081ad6265SDimitry Andric   bool hasLegacyGeometry() const { return getGeneration() < GFX11; }
110181ad6265SDimitry Andric 
1102e8d8bef9SDimitry Andric   /// \returns SGPR allocation granularity supported by the subtarget.
1103e8d8bef9SDimitry Andric   unsigned getSGPRAllocGranule() const {
1104e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getSGPRAllocGranule(this);
1105e8d8bef9SDimitry Andric   }
1106e8d8bef9SDimitry Andric 
1107e8d8bef9SDimitry Andric   /// \returns SGPR encoding granularity supported by the subtarget.
1108e8d8bef9SDimitry Andric   unsigned getSGPREncodingGranule() const {
1109e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getSGPREncodingGranule(this);
1110e8d8bef9SDimitry Andric   }
1111e8d8bef9SDimitry Andric 
1112e8d8bef9SDimitry Andric   /// \returns Total number of SGPRs supported by the subtarget.
1113e8d8bef9SDimitry Andric   unsigned getTotalNumSGPRs() const {
1114e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getTotalNumSGPRs(this);
1115e8d8bef9SDimitry Andric   }
1116e8d8bef9SDimitry Andric 
1117e8d8bef9SDimitry Andric   /// \returns Addressable number of SGPRs supported by the subtarget.
1118e8d8bef9SDimitry Andric   unsigned getAddressableNumSGPRs() const {
1119e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getAddressableNumSGPRs(this);
1120e8d8bef9SDimitry Andric   }
1121e8d8bef9SDimitry Andric 
1122e8d8bef9SDimitry Andric   /// \returns Minimum number of SGPRs that meets the given number of waves per
1123e8d8bef9SDimitry Andric   /// execution unit requirement supported by the subtarget.
1124e8d8bef9SDimitry Andric   unsigned getMinNumSGPRs(unsigned WavesPerEU) const {
1125e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getMinNumSGPRs(this, WavesPerEU);
1126e8d8bef9SDimitry Andric   }
1127e8d8bef9SDimitry Andric 
1128e8d8bef9SDimitry Andric   /// \returns Maximum number of SGPRs that meets the given number of waves per
1129e8d8bef9SDimitry Andric   /// execution unit requirement supported by the subtarget.
1130e8d8bef9SDimitry Andric   unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
1131e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getMaxNumSGPRs(this, WavesPerEU, Addressable);
1132e8d8bef9SDimitry Andric   }
1133e8d8bef9SDimitry Andric 
1134fe6060f1SDimitry Andric   /// \returns Reserved number of SGPRs. This is common
1135fe6060f1SDimitry Andric   /// utility function called by MachineFunction and
1136fe6060f1SDimitry Andric   /// Function variants of getReservedNumSGPRs.
113704eeddc0SDimitry Andric   unsigned getBaseReservedNumSGPRs(const bool HasFlatScratch) const;
1138fe6060f1SDimitry Andric   /// \returns Reserved number of SGPRs for given machine function \p MF.
1139e8d8bef9SDimitry Andric   unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
1140e8d8bef9SDimitry Andric 
1141fe6060f1SDimitry Andric   /// \returns Reserved number of SGPRs for given function \p F.
1142fe6060f1SDimitry Andric   unsigned getReservedNumSGPRs(const Function &F) const;
1143fe6060f1SDimitry Andric 
1144fe6060f1SDimitry Andric   /// \returns max num SGPRs. This is the common utility
1145fe6060f1SDimitry Andric   /// function called by MachineFunction and Function
1146fe6060f1SDimitry Andric   /// variants of getMaxNumSGPRs.
1147fe6060f1SDimitry Andric   unsigned getBaseMaxNumSGPRs(const Function &F,
1148fe6060f1SDimitry Andric                               std::pair<unsigned, unsigned> WavesPerEU,
1149fe6060f1SDimitry Andric                               unsigned PreloadedSGPRs,
1150fe6060f1SDimitry Andric                               unsigned ReservedNumSGPRs) const;
1151fe6060f1SDimitry Andric 
1152e8d8bef9SDimitry Andric   /// \returns Maximum number of SGPRs that meets number of waves per execution
1153e8d8bef9SDimitry Andric   /// unit requirement for function \p MF, or number of SGPRs explicitly
1154e8d8bef9SDimitry Andric   /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
1155e8d8bef9SDimitry Andric   ///
1156e8d8bef9SDimitry Andric   /// \returns Value that meets number of waves per execution unit requirement
1157e8d8bef9SDimitry Andric   /// if explicitly requested value cannot be converted to integer, violates
1158e8d8bef9SDimitry Andric   /// subtarget's specifications, or does not meet number of waves per execution
1159e8d8bef9SDimitry Andric   /// unit requirement.
1160e8d8bef9SDimitry Andric   unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
1161e8d8bef9SDimitry Andric 
1162fe6060f1SDimitry Andric   /// \returns Maximum number of SGPRs that meets number of waves per execution
1163fe6060f1SDimitry Andric   /// unit requirement for function \p F, or number of SGPRs explicitly
1164fe6060f1SDimitry Andric   /// requested using "amdgpu-num-sgpr" attribute attached to function \p F.
1165fe6060f1SDimitry Andric   ///
1166fe6060f1SDimitry Andric   /// \returns Value that meets number of waves per execution unit requirement
1167fe6060f1SDimitry Andric   /// if explicitly requested value cannot be converted to integer, violates
1168fe6060f1SDimitry Andric   /// subtarget's specifications, or does not meet number of waves per execution
1169fe6060f1SDimitry Andric   /// unit requirement.
1170fe6060f1SDimitry Andric   unsigned getMaxNumSGPRs(const Function &F) const;
1171fe6060f1SDimitry Andric 
1172e8d8bef9SDimitry Andric   /// \returns VGPR allocation granularity supported by the subtarget.
1173e8d8bef9SDimitry Andric   unsigned getVGPRAllocGranule() const {
1174e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getVGPRAllocGranule(this);
1175e8d8bef9SDimitry Andric   }
1176e8d8bef9SDimitry Andric 
1177e8d8bef9SDimitry Andric   /// \returns VGPR encoding granularity supported by the subtarget.
1178e8d8bef9SDimitry Andric   unsigned getVGPREncodingGranule() const {
1179e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getVGPREncodingGranule(this);
1180e8d8bef9SDimitry Andric   }
1181e8d8bef9SDimitry Andric 
1182e8d8bef9SDimitry Andric   /// \returns Total number of VGPRs supported by the subtarget.
1183e8d8bef9SDimitry Andric   unsigned getTotalNumVGPRs() const {
1184e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getTotalNumVGPRs(this);
1185e8d8bef9SDimitry Andric   }
1186e8d8bef9SDimitry Andric 
1187e8d8bef9SDimitry Andric   /// \returns Addressable number of VGPRs supported by the subtarget.
1188e8d8bef9SDimitry Andric   unsigned getAddressableNumVGPRs() const {
1189e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getAddressableNumVGPRs(this);
1190e8d8bef9SDimitry Andric   }
1191e8d8bef9SDimitry Andric 
1192e8d8bef9SDimitry Andric   /// \returns Minimum number of VGPRs that meets given number of waves per
1193e8d8bef9SDimitry Andric   /// execution unit requirement supported by the subtarget.
1194e8d8bef9SDimitry Andric   unsigned getMinNumVGPRs(unsigned WavesPerEU) const {
1195e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getMinNumVGPRs(this, WavesPerEU);
1196e8d8bef9SDimitry Andric   }
1197e8d8bef9SDimitry Andric 
1198e8d8bef9SDimitry Andric   /// \returns Maximum number of VGPRs that meets given number of waves per
1199e8d8bef9SDimitry Andric   /// execution unit requirement supported by the subtarget.
1200e8d8bef9SDimitry Andric   unsigned getMaxNumVGPRs(unsigned WavesPerEU) const {
1201e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getMaxNumVGPRs(this, WavesPerEU);
1202e8d8bef9SDimitry Andric   }
1203e8d8bef9SDimitry Andric 
1204fe6060f1SDimitry Andric   /// \returns max num VGPRs. This is the common utility function
1205fe6060f1SDimitry Andric   /// called by MachineFunction and Function variants of getMaxNumVGPRs.
1206fe6060f1SDimitry Andric   unsigned getBaseMaxNumVGPRs(const Function &F,
1207fe6060f1SDimitry Andric                               std::pair<unsigned, unsigned> WavesPerEU) const;
1208fe6060f1SDimitry Andric   /// \returns Maximum number of VGPRs that meets number of waves per execution
1209fe6060f1SDimitry Andric   /// unit requirement for function \p F, or number of VGPRs explicitly
1210fe6060f1SDimitry Andric   /// requested using "amdgpu-num-vgpr" attribute attached to function \p F.
1211fe6060f1SDimitry Andric   ///
1212fe6060f1SDimitry Andric   /// \returns Value that meets number of waves per execution unit requirement
1213fe6060f1SDimitry Andric   /// if explicitly requested value cannot be converted to integer, violates
1214fe6060f1SDimitry Andric   /// subtarget's specifications, or does not meet number of waves per execution
1215fe6060f1SDimitry Andric   /// unit requirement.
1216fe6060f1SDimitry Andric   unsigned getMaxNumVGPRs(const Function &F) const;
1217fe6060f1SDimitry Andric 
121881ad6265SDimitry Andric   unsigned getMaxNumAGPRs(const Function &F) const {
121981ad6265SDimitry Andric     return getMaxNumVGPRs(F);
122081ad6265SDimitry Andric   }
122181ad6265SDimitry Andric 
1222e8d8bef9SDimitry Andric   /// \returns Maximum number of VGPRs that meets number of waves per execution
1223e8d8bef9SDimitry Andric   /// unit requirement for function \p MF, or number of VGPRs explicitly
1224e8d8bef9SDimitry Andric   /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
1225e8d8bef9SDimitry Andric   ///
1226e8d8bef9SDimitry Andric   /// \returns Value that meets number of waves per execution unit requirement
1227e8d8bef9SDimitry Andric   /// if explicitly requested value cannot be converted to integer, violates
1228e8d8bef9SDimitry Andric   /// subtarget's specifications, or does not meet number of waves per execution
1229e8d8bef9SDimitry Andric   /// unit requirement.
1230e8d8bef9SDimitry Andric   unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
1231e8d8bef9SDimitry Andric 
1232e8d8bef9SDimitry Andric   void getPostRAMutations(
1233e8d8bef9SDimitry Andric       std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
1234e8d8bef9SDimitry Andric       const override;
1235e8d8bef9SDimitry Andric 
1236349cc55cSDimitry Andric   std::unique_ptr<ScheduleDAGMutation>
1237349cc55cSDimitry Andric   createFillMFMAShadowMutation(const TargetInstrInfo *TII) const;
1238349cc55cSDimitry Andric 
1239e8d8bef9SDimitry Andric   bool isWave32() const {
1240e8d8bef9SDimitry Andric     return getWavefrontSize() == 32;
1241e8d8bef9SDimitry Andric   }
1242e8d8bef9SDimitry Andric 
1243e8d8bef9SDimitry Andric   bool isWave64() const {
1244e8d8bef9SDimitry Andric     return getWavefrontSize() == 64;
1245e8d8bef9SDimitry Andric   }
1246e8d8bef9SDimitry Andric 
1247e8d8bef9SDimitry Andric   const TargetRegisterClass *getBoolRC() const {
1248e8d8bef9SDimitry Andric     return getRegisterInfo()->getBoolRC();
1249e8d8bef9SDimitry Andric   }
1250e8d8bef9SDimitry Andric 
1251e8d8bef9SDimitry Andric   /// \returns Maximum number of work groups per compute unit supported by the
1252e8d8bef9SDimitry Andric   /// subtarget and limited by given \p FlatWorkGroupSize.
1253e8d8bef9SDimitry Andric   unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const override {
1254e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(this, FlatWorkGroupSize);
1255e8d8bef9SDimitry Andric   }
1256e8d8bef9SDimitry Andric 
1257e8d8bef9SDimitry Andric   /// \returns Minimum flat work group size supported by the subtarget.
1258e8d8bef9SDimitry Andric   unsigned getMinFlatWorkGroupSize() const override {
1259e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(this);
1260e8d8bef9SDimitry Andric   }
1261e8d8bef9SDimitry Andric 
1262e8d8bef9SDimitry Andric   /// \returns Maximum flat work group size supported by the subtarget.
1263e8d8bef9SDimitry Andric   unsigned getMaxFlatWorkGroupSize() const override {
1264e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(this);
1265e8d8bef9SDimitry Andric   }
1266e8d8bef9SDimitry Andric 
1267e8d8bef9SDimitry Andric   /// \returns Number of waves per execution unit required to support the given
1268e8d8bef9SDimitry Andric   /// \p FlatWorkGroupSize.
1269e8d8bef9SDimitry Andric   unsigned
1270e8d8bef9SDimitry Andric   getWavesPerEUForWorkGroup(unsigned FlatWorkGroupSize) const override {
1271e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getWavesPerEUForWorkGroup(this, FlatWorkGroupSize);
1272e8d8bef9SDimitry Andric   }
1273e8d8bef9SDimitry Andric 
1274e8d8bef9SDimitry Andric   /// \returns Minimum number of waves per execution unit supported by the
1275e8d8bef9SDimitry Andric   /// subtarget.
1276e8d8bef9SDimitry Andric   unsigned getMinWavesPerEU() const override {
1277e8d8bef9SDimitry Andric     return AMDGPU::IsaInfo::getMinWavesPerEU(this);
1278e8d8bef9SDimitry Andric   }
1279e8d8bef9SDimitry Andric 
1280e8d8bef9SDimitry Andric   void adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use, int UseOpIdx,
1281e8d8bef9SDimitry Andric                              SDep &Dep) const override;
128281ad6265SDimitry Andric 
128381ad6265SDimitry Andric   // \returns true if it's beneficial on this subtarget for the scheduler to
128481ad6265SDimitry Andric   // cluster stores as well as loads.
128581ad6265SDimitry Andric   bool shouldClusterStores() const { return getGeneration() >= GFX11; }
1286e8d8bef9SDimitry Andric };
1287e8d8bef9SDimitry Andric 
1288e8d8bef9SDimitry Andric } // end namespace llvm
1289e8d8bef9SDimitry Andric 
1290e8d8bef9SDimitry Andric #endif // LLVM_LIB_TARGET_AMDGPU_GCNSUBTARGET_H
1291