1//=====-- GCNSubtarget.h - Define GCN Subtarget for AMDGPU ------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//==-----------------------------------------------------------------------===//
8//
9/// \file
10/// AMD GCN specific subclass of TargetSubtarget.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TARGET_AMDGPU_GCNSUBTARGET_H
15#define LLVM_LIB_TARGET_AMDGPU_GCNSUBTARGET_H
16
17#include "AMDGPUCallLowering.h"
18#include "AMDGPURegisterBankInfo.h"
19#include "AMDGPUSubtarget.h"
20#include "SIFrameLowering.h"
21#include "SIISelLowering.h"
22#include "SIInstrInfo.h"
23#include "Utils/AMDGPUBaseInfo.h"
24#include "llvm/Support/AMDHSAKernelDescriptor.h"
25#include "llvm/Support/ErrorHandling.h"
26#include <optional>
27
28#define GET_SUBTARGETINFO_HEADER
29#include "AMDGPUGenSubtargetInfo.inc"
30
31namespace llvm {
32
33class GCNTargetMachine;
34
35/// Module flag names controlling out-of-bounds buffer access semantics.
36/// Each flag is an i32 with Module::Max merge behaviour and tri-state values:
37/// 0 = any (absent/default - backend currently treats as strict)
38/// 1 = relaxed
39/// 2 = strict
40namespace AMDGPUOOBMode {
41inline constexpr StringLiteral BufferFlag("amdgpu.buffer.oob.mode");
42inline constexpr StringLiteral TBufferFlag("amdgpu.tbuffer.oob.mode");
43} // namespace AMDGPUOOBMode
44
45class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
46 public AMDGPUSubtarget {
47public:
48 using AMDGPUSubtarget::getMaxWavesPerEU;
49
50 // Following 2 enums are documented at:
51 // - https://llvm.org/docs/AMDGPUUsage.html#trap-handler-abi
52 enum class TrapHandlerAbi {
53 NONE = 0x00,
54 AMDHSA = 0x01,
55 };
56
57 enum class TrapID {
58 LLVMAMDHSATrap = 0x02,
59 LLVMAMDHSADebugTrap = 0x03,
60 };
61
62private:
63 /// SelectionDAGISel related APIs.
64 std::unique_ptr<const SelectionDAGTargetInfo> TSInfo;
65
66 /// GlobalISel related APIs.
67 std::unique_ptr<AMDGPUCallLowering> CallLoweringInfo;
68 std::unique_ptr<InlineAsmLowering> InlineAsmLoweringInfo;
69 std::unique_ptr<InstructionSelector> InstSelector;
70 std::unique_ptr<LegalizerInfo> Legalizer;
71 std::unique_ptr<AMDGPURegisterBankInfo> RegBankInfo;
72
73protected:
74 // Basic subtarget description.
75 AMDGPU::TargetID TargetID;
76 unsigned Gen = INVALID;
77 InstrItineraryData InstrItins;
78 int LDSBankCount = 0;
79 unsigned MaxPrivateElementSize = 0;
80
81 // Instruction cache line size in bytes; set from TableGen subtarget features.
82 unsigned InstCacheLineSize = 0;
83
84 // Data (VMEM) cache line size in bytes; set from TableGen subtarget features.
85 unsigned DataCacheLineSize = 0;
86
87 /// The width, in bits, of the num_records field of a buffer resource (V#),
88 /// set from tablegen subtarget features, 0 is unknown.
89 unsigned BufferResourceNumRecordsWidth = 0;
90
91 // Dynamically set bits that enable features.
92 const bool BufferOOBRelaxed;
93 const bool TBufferOOBRelaxed;
94
95 /// The maximum number of instructions that may be placed within an S_CLAUSE,
96 /// which is one greater than the maximum argument to S_CLAUSE. A value of 0
97 /// indicates a lack of S_CLAUSE support.
98 unsigned MaxHardClauseLength = 0;
99
100#define GET_SUBTARGETINFO_MACRO(ATTRIBUTE, DEFAULT, GETTER) \
101 bool ATTRIBUTE = DEFAULT;
102#include "AMDGPUGenSubtargetInfo.inc"
103
104private:
105 SIInstrInfo InstrInfo;
106 SITargetLowering TLInfo;
107 SIFrameLowering FrameLowering;
108
109 /// Get the register that represents the actual dependency between the
110 /// definition and the use. The definition might only affect a subregister
111 /// that is not actually used. Works for both virtual and physical registers.
112 /// Note: Currently supports VOP3P instructions (without WMMA an SWMMAC).
113 /// Returns the definition register if there is a real dependency and no
114 /// better match is found.
115 Register getRealSchedDependency(const MachineInstr &DefI, int DefOpIdx,
116 const MachineInstr &UseI, int UseOpIdx) const;
117
118public:
119 GCNSubtarget(
120 const Triple &TT, StringRef GPU, StringRef FS, const GCNTargetMachine &TM,
121 bool BufferOOBRelaxed = false, bool TBufferOOBRelaxed = false,
122 AMDGPU::TargetIDSetting XnackSetting = AMDGPU::TargetIDSetting::Any,
123 AMDGPU::TargetIDSetting SramEccSetting = AMDGPU::TargetIDSetting::Any);
124 ~GCNSubtarget() override;
125
126 GCNSubtarget &
127 initializeSubtargetDependencies(const Triple &TT, StringRef GPU, StringRef FS,
128 AMDGPU::TargetIDSetting XnackSetting,
129 AMDGPU::TargetIDSetting SramEccSetting);
130
131 /// Diagnose inconsistent subtarget features before attempting to codegen
132 /// function \p F.
133 void checkSubtargetFeatures(const Function &F) const;
134
135 const SIInstrInfo *getInstrInfo() const override { return &InstrInfo; }
136
137 const SIFrameLowering *getFrameLowering() const override {
138 return &FrameLowering;
139 }
140
141 const SITargetLowering *getTargetLowering() const override { return &TLInfo; }
142
143 const SIRegisterInfo *getRegisterInfo() const override {
144 return &InstrInfo.getRegisterInfo();
145 }
146
147 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override;
148
149 const CallLowering *getCallLowering() const override {
150 return CallLoweringInfo.get();
151 }
152
153 const InlineAsmLowering *getInlineAsmLowering() const override {
154 return InlineAsmLoweringInfo.get();
155 }
156
157 InstructionSelector *getInstructionSelector() const override {
158 return InstSelector.get();
159 }
160
161 const LegalizerInfo *getLegalizerInfo() const override {
162 return Legalizer.get();
163 }
164
165 const AMDGPURegisterBankInfo *getRegBankInfo() const override {
166 return RegBankInfo.get();
167 }
168
169 const AMDGPU::TargetID &getTargetID() const { return TargetID; }
170
171 const InstrItineraryData *getInstrItineraryData() const override {
172 return &InstrItins;
173 }
174
175 void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
176
177 Generation getGeneration() const { return (Generation)Gen; }
178
179 bool isGFX11Plus() const { return getGeneration() >= GFX11; }
180
181#define GET_SUBTARGETINFO_MACRO(ATTRIBUTE, DEFAULT, GETTER) \
182 bool GETTER() const override { return ATTRIBUTE; }
183#include "AMDGPUGenSubtargetInfo.inc"
184
185 unsigned getMaxWaveScratchSize() const {
186 // See COMPUTE_TMPRING_SIZE.WAVESIZE.
187 if (getGeneration() >= GFX12) {
188 // 18-bit field in units of 64-dword.
189 return (64 * 4) * ((1 << 18) - 1);
190 }
191 if (getGeneration() == GFX11) {
192 // 15-bit field in units of 64-dword.
193 return (64 * 4) * ((1 << 15) - 1);
194 }
195 // 13-bit field in units of 256-dword.
196 return (256 * 4) * ((1 << 13) - 1);
197 }
198
199 /// Return the number of high bits known to be zero for a frame index.
200 unsigned getKnownHighZeroBitsForFrameIndex() const {
201 return llvm::countl_zero(Val: getMaxWaveScratchSize()) + getWavefrontSizeLog2();
202 }
203
204 int getLDSBankCount() const { return LDSBankCount; }
205
206 /// Instruction cache line size in bytes (64 for pre-GFX11, 128 for GFX11+).
207 unsigned getInstCacheLineSize() const { return InstCacheLineSize; }
208
209 /// Data (VMEM) cache line size in bytes (128 for gfx12), has no use before
210 /// GFX12.
211 unsigned getDataCacheLineSize() const { return DataCacheLineSize; }
212
213 unsigned getMaxPrivateElementSize(bool ForBufferRSrc = false) const {
214 return (ForBufferRSrc || !hasFlatScratchEnabled()) ? MaxPrivateElementSize
215 : 16;
216 }
217
218 unsigned getConstantBusLimit(unsigned Opcode) const;
219
220 /// Returns if the result of this instruction with a 16-bit result returned in
221 /// a 32-bit register implicitly zeroes the high 16-bits, rather than preserve
222 /// the original value.
223 bool zeroesHigh16BitsOfDest(unsigned Opcode) const;
224
225 bool hasAddr64() const {
226 return (getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS);
227 }
228
229 bool hasFlat() const {
230 return (getGeneration() > AMDGPUSubtarget::SOUTHERN_ISLANDS);
231 }
232
233 // Return true if the target only has the reverse operand versions of VALU
234 // shift instructions (e.g. v_lshrrev_b32, and no v_lshr_b32).
235 bool hasOnlyRevVALUShifts() const {
236 return getGeneration() >= VOLCANIC_ISLANDS;
237 }
238
239 bool hasFractBug() const { return getGeneration() == SOUTHERN_ISLANDS; }
240
241 bool hasMed3_16() const { return getGeneration() >= AMDGPUSubtarget::GFX9; }
242
243 bool hasMin3Max3_16() const {
244 return getGeneration() >= AMDGPUSubtarget::GFX9;
245 }
246
247 bool hasSwap() const { return HasGFX9Insts; }
248
249 bool hasScalarPackInsts() const { return HasGFX9Insts; }
250
251 bool hasScalarMulHiInsts() const { return HasGFX9Insts; }
252
253 bool hasScalarSubwordLoads() const { return getGeneration() >= GFX12; }
254
255 bool hasAsyncMark() const { return hasVMemToLDSLoad() || HasAsynccnt; }
256
257 TrapHandlerAbi getTrapHandlerAbi() const {
258 return isAmdHsaOS() ? TrapHandlerAbi::AMDHSA : TrapHandlerAbi::NONE;
259 }
260
261 bool supportsGetDoorbellID() const {
262 // The S_GETREG DOORBELL_ID is supported by all GFX9 onward targets.
263 return getGeneration() >= GFX9;
264 }
265
266 /// True if the offset field of DS instructions works as expected. On SI, the
267 /// offset uses a 16-bit adder and does not always wrap properly.
268 bool hasUsableDSOffset() const { return getGeneration() >= SEA_ISLANDS; }
269
270 bool unsafeDSOffsetFoldingEnabled() const {
271 return EnableUnsafeDSOffsetFolding;
272 }
273
274 /// Condition output from div_scale is usable.
275 bool hasUsableDivScaleConditionOutput() const {
276 return getGeneration() != SOUTHERN_ISLANDS;
277 }
278
279 /// Extra wait hazard is needed in some cases before
280 /// s_cbranch_vccnz/s_cbranch_vccz.
281 bool hasReadVCCZBug() const { return getGeneration() <= SEA_ISLANDS; }
282
283 /// Writes to VCC_LO/VCC_HI update the VCCZ flag.
284 bool partialVCCWritesUpdateVCCZ() const { return getGeneration() >= GFX10; }
285
286 /// A read of an SGPR by SMRD instruction requires 4 wait states when the SGPR
287 /// was written by a VALU instruction.
288 bool hasSMRDReadVALUDefHazard() const {
289 return getGeneration() == SOUTHERN_ISLANDS;
290 }
291
292 /// A read of an SGPR by a VMEM instruction requires 5 wait states when the
293 /// SGPR was written by a VALU Instruction.
294 bool hasVMEMReadSGPRVALUDefHazard() const {
295 return getGeneration() >= VOLCANIC_ISLANDS;
296 }
297
298 bool hasRFEHazards() const { return getGeneration() >= VOLCANIC_ISLANDS; }
299
300 /// Number of hazard wait states for s_setreg_b32/s_setreg_imm32_b32.
301 unsigned getSetRegWaitStates() const {
302 return getGeneration() <= SEA_ISLANDS ? 1 : 2;
303 }
304
305 bool supportsMinMaxDenormModes() const {
306 return getGeneration() >= AMDGPUSubtarget::GFX9;
307 }
308
309 /// \returns If target supports S_DENORM_MODE.
310 bool hasDenormModeInst() const {
311 return getGeneration() >= AMDGPUSubtarget::GFX10;
312 }
313
314 /// \returns If target supports ds_read/write_b128 and user enables generation
315 /// of ds_read/write_b128.
316 bool useDS128() const { return HasCIInsts && EnableDS128; }
317
318 /// \return If target supports ds_read/write_b96/128.
319 bool hasDS96AndDS128() const { return HasCIInsts; }
320
321 /// Have v_trunc_f64, v_ceil_f64, v_rndne_f64
322 bool haveRoundOpsF64() const { return HasCIInsts; }
323
324 /// \returns If MUBUF instructions always perform range checking, even for
325 /// buffer resources used for private memory access.
326 bool privateMemoryResourceIsRangeChecked() const {
327 return getGeneration() < AMDGPUSubtarget::GFX9;
328 }
329
330 /// \returns If target requires PRT Struct NULL support (zero result registers
331 /// for sparse texture support).
332 bool usePRTStrictNull() const { return EnablePRTStrictNull; }
333
334 bool hasUnalignedBufferAccessEnabled() const {
335 return HasUnalignedBufferAccess && HasUnalignedAccessMode;
336 }
337
338 bool hasUnalignedDSAccessEnabled() const {
339 return HasUnalignedDSAccess && HasUnalignedAccessMode;
340 }
341
342 bool hasUnalignedScratchAccessEnabled() const {
343 return HasUnalignedScratchAccess && HasUnalignedAccessMode;
344 }
345
346 bool isXNACKEnabled() const { return TargetID.isXnackOnOrAny(); }
347
348 bool needsAsyncBarrierArriveReplayWorkaround() const {
349 // Generic 12.5 code has no explicit XNACK setting; keep the workaround.
350 return hasAsyncBarrierArriveReplayBug() &&
351 TargetID.getXnackSetting() != AMDGPU::TargetIDSetting::Off;
352 }
353
354 bool hasRelaxedBufferOOBMode() const { return BufferOOBRelaxed; }
355 bool hasRelaxedTBufferOOBMode() const { return TBufferOOBRelaxed; }
356
357 /// Return the maximum allowed load/store width for the given type and
358 /// alignment combination based on subtarget flags.
359 /// 1. If unaligned accesses are not enabled, then any load/store that is less
360 /// than word-aligned has to be handled one byte or ushort at a time.
361 /// 2. If relaxed OOB mode is not set, we must ensure that the in-bounds
362 /// part of a partially out of bounds read/write is performed correctly. This
363 /// means that any load that isn't naturally aligned has to be split into
364 /// parts that are naturally aligned, so that, after bitcasting, we don't have
365 /// unaligned loads that could discard valid data.
366 ///
367 /// For example, if we're loading a <8 x i8>, that's actually a load of a <2 x
368 /// i32>, and if we load from an align(2) address, that address might be 2
369 /// bytes from the end of the buffer. The hardware will, when performing the
370 /// <2 x i32> load, mask off the entire first word, causing the two in-bounds
371 /// bytes to be masked off. However, if we know the offset can't be too close
372 /// to the number of records in the buffer (if known), we can skip this
373 /// expansion.
374 ///
375 /// Unlike the complete disablement of unaligned accesses from point 1,
376 /// this does not apply to unaligned scalars, but will apply to cases like
377 /// `load <2 x i32>, align 4` since the left element might be out of bounds.
378 /// Note that if we know that the base offset is known to be
379 /// less than `uint32_max - byte_size(Ty)`, we can skip these alignment
380 /// checks.
381 uint64_t getMaxBufferIntrinsicWidth(const DataLayout &DL, Type *T, Align A,
382 bool NoWrapFromMax,
383 bool NoPartialOOB) const;
384
385 /// Return the width, in bits, of the num_records field of a buffer resource
386 /// (V#) on this subtarget, or std::nullopt if not yet known.
387 std::optional<unsigned> getBufferResourceNumRecordsWidth() const {
388 if (BufferResourceNumRecordsWidth == 0)
389 return std::nullopt;
390 return BufferResourceNumRecordsWidth;
391 }
392
393 bool isCuModeEnabled() const { return EnableCuMode; }
394
395 /// \returns Whether a work-group runs on all of the block's SIMDs.
396 bool isFullSIMDMode() const {
397 return (HasGFX1250Insts && getGeneration() < GFX13) || !EnableCuMode;
398 }
399
400 bool isPreciseMemoryEnabled() const { return EnablePreciseMemory; }
401
402 bool hasFlatScrRegister() const { return hasFlatAddressSpace(); }
403
404 // Check if target supports ST addressing mode with FLAT scratch instructions.
405 // The ST addressing mode means no registers are used, either VGPR or SGPR,
406 // but only immediate offset is swizzled and added to the FLAT scratch base.
407 bool hasFlatScratchSTMode() const {
408 return hasFlatScratchInsts() && (hasGFX10_3Insts() || hasGFX940Insts());
409 }
410
411 bool hasFlatScratchSVSMode() const { return HasGFX940Insts || HasGFX11Insts; }
412
413 bool hasFlatScratchEnabled() const {
414 return hasArchitectedFlatScratch() ||
415 (EnableFlatScratch && hasFlatScratchInsts());
416 }
417
418 bool hasExportInsts() const {
419 return !hasGFX940Insts() && !hasGFX1250Insts();
420 }
421
422 bool hasVINTERPEncoding() const {
423 return HasGFX11Insts && !hasGFX1250Insts();
424 }
425
426 bool hasMultiDwordFlatScratchAddressing() const {
427 return getGeneration() >= GFX9;
428 }
429
430 bool hasFlatLgkmVMemCountInOrder() const { return getGeneration() > GFX9; }
431
432 bool hasD16LoadStore() const { return getGeneration() >= GFX9; }
433
434 bool d16PreservesUnusedBits() const {
435 return hasD16LoadStore() && !TargetID.isSramEccOnOrAny();
436 }
437
438 bool hasD16Images() const { return getGeneration() >= VOLCANIC_ISLANDS; }
439
440 /// Return if most LDS instructions have an m0 use that require m0 to be
441 /// initialized.
442 bool ldsRequiresM0Init() const { return getGeneration() < GFX9; }
443
444 // True if the hardware rewinds and replays GWS operations if a wave is
445 // preempted.
446 //
447 // If this is false, a GWS operation requires testing if a nack set the
448 // MEM_VIOL bit, and repeating if so.
449 bool hasGWSAutoReplay() const { return getGeneration() >= GFX9; }
450
451 /// \returns if target has ds_gws_sema_release_all instruction.
452 bool hasGWSSemaReleaseAll() const { return HasCIInsts; }
453
454 bool hasScalarAddSub64() const { return getGeneration() >= GFX12; }
455
456 bool hasScalarSMulU64() const { return getGeneration() >= GFX12; }
457
458 // Covers VS/PS/CS graphics shaders
459 bool isMesaGfxShader(const Function &F) const {
460 return isMesa3DOS() && AMDGPU::isShader(CC: F.getCallingConv());
461 }
462
463 bool hasMad64_32() const { return getGeneration() >= SEA_ISLANDS; }
464
465 bool hasAtomicFaddInsts() const {
466 return HasAtomicFaddRtnInsts || HasAtomicFaddNoRtnInsts;
467 }
468
469 bool vmemWriteNeedsExpWaitcnt() const {
470 return getGeneration() < SEA_ISLANDS;
471 }
472
473 bool hasInstPrefetch() const {
474 return getGeneration() == GFX10 || getGeneration() == GFX11;
475 }
476
477 bool hasPrefetch() const { return HasGFX12Insts; }
478
479 bool hasInstPrefSize() const { return isGFX11Plus(); }
480
481 void getInstPrefSizeArgs(uint32_t &Mask, uint32_t &Shift, uint32_t &Width,
482 uint32_t &CacheLineSize) const {
483 assert(isGFX11Plus());
484 CacheLineSize = getInstCacheLineSize();
485 if (getGeneration() == GFX11) {
486 Mask = amdhsa::COMPUTE_PGM_RSRC3_GFX11_INST_PREF_SIZE;
487 Shift = amdhsa::COMPUTE_PGM_RSRC3_GFX11_INST_PREF_SIZE_SHIFT;
488 Width = amdhsa::COMPUTE_PGM_RSRC3_GFX11_INST_PREF_SIZE_WIDTH;
489 } else {
490 Mask = amdhsa::COMPUTE_PGM_RSRC3_GFX12_PLUS_INST_PREF_SIZE;
491 Shift = amdhsa::COMPUTE_PGM_RSRC3_GFX12_PLUS_INST_PREF_SIZE_SHIFT;
492 Width = amdhsa::COMPUTE_PGM_RSRC3_GFX12_PLUS_INST_PREF_SIZE_WIDTH;
493 }
494 }
495
496 // Has s_cmpk_* instructions.
497 bool hasSCmpK() const { return getGeneration() < GFX12; }
498
499 // Scratch is allocated in 256 dword per wave blocks for the entire
500 // wavefront. When viewed from the perspective of an arbitrary workitem, this
501 // is 4-byte aligned.
502 //
503 // Only 4-byte alignment is really needed to access anything. Transformations
504 // on the pointer value itself may rely on the alignment / known low bits of
505 // the pointer. Set this to something above the minimum to avoid needing
506 // dynamic realignment in common cases.
507 Align getStackAlignment() const { return Align(16); }
508
509 bool enableMachineScheduler() const override { return true; }
510
511 bool enableSSAMachineScheduler() const override { return true; }
512
513 bool useAA() const override;
514
515 bool enableSubRegLiveness() const override { return true; }
516
517 // canReassign() walks the whole allocation order of the evictee on every
518 // local eviction query, which is expensive with a very large VGPR file.
519 bool enableRALocalReassignment(CodeGenOptLevel OptLevel) const override {
520 return !hasVGPRMSBs();
521 }
522
523 // XXX - Why is this here if it isn't in the default pass set?
524 bool enableEarlyIfConversion() const override { return true; }
525
526 void overrideSchedPolicy(MachineSchedPolicy &Policy,
527 const SchedRegion &Region) const override;
528
529 void overridePostRASchedPolicy(MachineSchedPolicy &Policy,
530 const SchedRegion &Region) const override;
531
532 void overridePipelinerPolicy(MachinePipelinerPolicy &Policy) const override;
533
534 void mirFileLoaded(MachineFunction &MF) const override;
535
536 unsigned getMaxNumUserSGPRs() const {
537 return AMDGPU::getMaxNumUserSGPRs(STI: *this);
538 }
539
540 bool useVGPRIndexMode() const;
541
542 bool hasScalarCompareEq64() const {
543 return getGeneration() >= VOLCANIC_ISLANDS;
544 }
545
546 bool hasLDSFPAtomicAddF32() const { return HasGFX8Insts; }
547
548 /// \returns true if the subtarget has the v_permlane64_b32 instruction.
549 bool hasPermLane64() const { return getGeneration() >= GFX11; }
550
551 /// \returns true if the subtarget supports the ds_swizzle rotate and FFT
552 /// swizzle modes (GFX9+).
553 bool hasDsSwizzleRotateMode() const { return getGeneration() >= GFX9; }
554
555 bool hasDPPRowShare() const {
556 return HasDPP && (HasGFX90AInsts || getGeneration() >= GFX10);
557 }
558
559 // Has V_PK_MOV_B32 opcode
560 bool hasPkMovB32() const { return HasGFX90AInsts; }
561
562 bool hasBufferTFEFormatD16() const { return !HasGFX90AInsts; }
563
564 bool hasFmaakFmamkF32Insts() const {
565 return getGeneration() >= GFX10 || hasGFX940Insts();
566 }
567
568 bool hasFmaakFmamkF64Insts() const { return hasGFX1250Insts(); }
569
570 bool hasNonNSAEncoding() const { return getGeneration() < GFX12; }
571
572 unsigned getNSAMaxSize(bool HasSampler = false) const {
573 return AMDGPU::getNSAMaxSize(STI: *this, HasSampler);
574 }
575
576 bool hasMadF16() const;
577
578 // FLAT GLOBAL VOffset is signed
579 bool hasSignedGVSOffset() const { return HasGFX1250Insts; }
580
581 bool loadStoreOptEnabled() const { return EnableLoadStoreOpt; }
582
583 bool hasUserSGPRInit16BugInWave32() const {
584 return HasUserSGPRInit16Bug && isWave32();
585 }
586
587 bool has12DWordStoreHazard() const {
588 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
589 }
590
591 // \returns true if the subtarget supports DWORDX3 load/store instructions.
592 bool hasDwordx3LoadStores() const { return HasCIInsts; }
593
594 bool hasReadM0MovRelInterpHazard() const {
595 return getGeneration() == AMDGPUSubtarget::GFX9;
596 }
597
598 bool hasReadM0SendMsgHazard() const {
599 return getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS &&
600 getGeneration() <= AMDGPUSubtarget::GFX9;
601 }
602
603 bool hasReadM0LdsDmaHazard() const {
604 return getGeneration() == AMDGPUSubtarget::GFX9;
605 }
606
607 bool hasReadM0LdsDirectHazard() const {
608 return getGeneration() == AMDGPUSubtarget::GFX9;
609 }
610
611 bool hasLDSMisalignedBugInWGPMode() const {
612 return HasLDSMisalignedBug && !EnableCuMode;
613 }
614
615 // Shift amount of a 64 bit shift cannot be a highest allocated register
616 // if also at the end of the allocation block.
617 bool hasShift64HighRegBug() const { return HasGFX90AInsts; }
618
619 // v_dot2c_f32_f16 unconditionally flushes f16 subnormal inputs to zero
620 // regardless of the MODE register, unlike v_fma_mix_f32 which respects it.
621 bool dot2UnconditionalFlush() const {
622 return HasGFX90AInsts && !HasGFX940Insts;
623 }
624
625 // Has one cycle hazard on transcendental instruction feeding a
626 // non transcendental VALU.
627 bool hasTransForwardingHazard() const { return HasGFX940Insts; }
628
629 // Has one cycle hazard on a VALU instruction partially writing dst with
630 // a shift of result bits feeding another VALU instruction.
631 bool hasDstSelForwardingHazard() const { return HasGFX940Insts; }
632
633 // Cannot use op_sel with v_dot instructions.
634 bool hasDOTOpSelHazard() const { return HasGFX940Insts || HasGFX11Insts; }
635
636 // Does not have HW interlocs for VALU writing and then reading SGPRs.
637 bool hasVDecCoExecHazard() const { return HasGFX940Insts; }
638
639 bool hasHardClauses() const { return MaxHardClauseLength > 0; }
640
641 bool hasFPAtomicToDenormModeHazard() const {
642 return getGeneration() == GFX10;
643 }
644
645 bool hasVOP3DPP() const { return getGeneration() >= GFX11; }
646
647 bool hasLdsDirect() const { return getGeneration() >= GFX11; }
648
649 bool hasLdsWaitVMSRC() const { return getGeneration() >= GFX12; }
650
651 bool hasVALUPartialForwardingHazard() const {
652 return getGeneration() == GFX11;
653 }
654
655 bool hasPkF32InvalidOpSel() const { return HasGFX950Insts; }
656
657 bool hasCvtScaleForwardingHazard() const { return HasGFX950Insts; }
658
659 bool hasPermlaneForwardingHazard() const { return HasGFX950Insts; }
660
661 // All GFX9 targets experience a fetch delay when an instruction at the start
662 // of a loop header is split by a 32-byte fetch window boundary, but GFX950
663 // is uniquely sensitive to this: the delay triggers further performance
664 // degradation beyond the fetch latency itself.
665 bool hasLoopHeadInstSplitSensitivity() const { return HasGFX950Insts; }
666
667 bool requiresCodeObjectV6() const { return RequiresCOV6; }
668
669 bool useVGPRBlockOpsForCSR() const { return UseBlockVGPROpsForCSR; }
670
671 bool hasVALUMaskWriteHazard() const { return getGeneration() == GFX11; }
672
673 bool hasVALUReadSGPRHazard() const {
674 return HasGFX12Insts && !HasGFX1250Insts;
675 }
676
677 bool setRegModeNeedsVNOPs() const {
678 return HasGFX1250Insts && getGeneration() == GFX12;
679 }
680
681 /// Return if operations acting on VGPR tuples require even alignment.
682 bool needsAlignedVGPRs() const { return RequiresAlignVGPR; }
683
684 /// Return true if the target has the S_PACK_HL_B32_B16 instruction.
685 bool hasSPackHL() const { return HasGFX11Insts; }
686
687 /// Return true if the target has the V_CVT_PK_I16_F32/V_CVT_PK_U16_F32
688 /// instructions.
689 bool hasVCvtPkIU16F32() const { return HasGFX11Insts; }
690
691 /// Return true if the target's EXP instruction supports the NULL export
692 /// target.
693 bool hasNullExportTarget() const { return !HasGFX11Insts; }
694
695 bool hasFlatScratchSVSSwizzleBug() const { return getGeneration() == GFX11; }
696
697 /// Return true if the target has the S_DELAY_ALU instruction.
698 bool hasDelayAlu() const { return HasGFX11Insts; }
699
700 /// Returns true if the target supports
701 /// global_load_lds_dwordx3/global_load_lds_dwordx4 or
702 /// buffer_load_dwordx3/buffer_load_dwordx4 with the lds bit.
703 bool hasLDSLoadB96_B128() const { return hasGFX950Insts(); }
704
705 /// \returns true if the target uses LOADcnt/SAMPLEcnt/BVHcnt, DScnt/KMcnt
706 /// and STOREcnt rather than VMcnt, LGKMcnt and VScnt respectively.
707 bool hasExtendedWaitCounts() const { return getGeneration() >= GFX12; }
708
709 /// \returns true if the target has packed f32 instructions that only read 32
710 /// bits from a scalar operand (SGPR or literal) and replicates the bits to
711 /// both channels.
712 bool hasPKF32InstsReplicatingLower32BitsOfScalarInput() const {
713 return getGeneration() == GFX12 && HasGFX1250Insts;
714 }
715
716 bool useAddPCI64Inst() const {
717 return hasSAddPCI64Inst() && !hasUnusableSAddPCI64();
718 }
719
720 /// \returns true if the target supports expert scheduling mode 2 which relies
721 /// on the compiler to insert waits to avoid hazards between VMEM and VALU
722 /// instructions in some instances.
723 bool hasExpertSchedulingMode() const { return getGeneration() >= GFX12; }
724
725 /// \returns The maximum number of instructions that can be enclosed in an
726 /// S_CLAUSE on the given subtarget, or 0 for targets that do not support that
727 /// instruction.
728 unsigned maxHardClauseLength() const { return MaxHardClauseLength; }
729
730 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs
731 /// SGPRs
732 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
733
734 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs
735 /// VGPRs
736 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs,
737 unsigned DynamicVGPRBlockSize) const;
738
739 /// Subtarget's minimum/maximum occupancy, in number of waves per EU, that can
740 /// be achieved when the only function running on a CU is \p F, each workgroup
741 /// uses \p LDSSize bytes of LDS, and each wave uses \p NumSGPRs SGPRs and \p
742 /// NumVGPRs VGPRs. The flat workgroup sizes associated to the function are a
743 /// range, so this returns a range as well.
744 ///
745 /// Note that occupancy can be affected by the scratch allocation as well, but
746 /// we do not have enough information to compute it.
747 std::pair<unsigned, unsigned> computeOccupancy(const Function &F,
748 unsigned LDSSize = 0,
749 unsigned NumSGPRs = 0,
750 unsigned NumVGPRs = 0) const;
751
752 /// \returns true if the flat_scratch register should be initialized with the
753 /// pointer to the wave's scratch memory rather than a size and offset.
754 bool flatScratchIsPointer() const {
755 return getGeneration() >= AMDGPUSubtarget::GFX9;
756 }
757
758 /// \returns true if the machine has merged shaders in which s0-s7 are
759 /// reserved by the hardware and user SGPRs start at s8
760 bool hasMergedShaders() const { return getGeneration() >= GFX9; }
761
762 // \returns true if the target supports the pre-NGG legacy geometry path.
763 bool hasLegacyGeometry() const { return getGeneration() < GFX11; }
764
765 // \returns true if the target has split barriers feature
766 bool hasSplitBarriers() const { return getGeneration() >= GFX12; }
767
768 // \returns true if the target has WG_RR_MODE kernel descriptor mode bit
769 bool hasRrWGMode() const { return getGeneration() >= GFX12; }
770
771 /// \returns true if VADDR and SADDR fields in VSCRATCH can use negative
772 /// values.
773 bool hasSignedScratchOffsets() const { return getGeneration() >= GFX12; }
774
775 bool hasINVWBL2WaitCntRequirement() const { return HasGFX1250Insts; }
776
777 bool hasVOPD3() const { return HasGFX1250Insts; }
778
779 // \returns true if the target has V_PK_{MIN|MAX}3_{I|U}16 instructions.
780 bool hasPkMinMax3Insts() const { return HasGFX1250Insts; }
781
782 // \returns ture if target has S_GET_SHADER_CYCLES_U64 instruction.
783 bool hasSGetShaderCyclesInst() const { return HasGFX1250Insts; }
784
785 // \returns true if S_GETPC_B64 zero-extends the result from 48 bits instead
786 // of sign-extending. Note that GFX1250 has not only fixed the bug but also
787 // extended VA to 57 bits.
788 bool hasGetPCZeroExtension() const {
789 return HasGFX12Insts && !HasGFX1250Insts;
790 }
791
792 // \returns true if the target needs to create a prolog for backward
793 // compatibility when preloading kernel arguments.
794 bool needsKernArgPreloadProlog() const {
795 return hasKernargPreload() && !HasGFX1250Insts;
796 }
797
798 bool hasCondSubInsts() const { return HasGFX12Insts; }
799
800 bool hasSubClampInsts() const { return hasGFX10_3Insts(); }
801
802 bool hasAnyBVHInsts() const {
803 return hasBVHRayTracingInsts() || hasBVHDualAndBVH8Insts();
804 }
805
806 bool hasAnyPackedFP32Ops() const {
807 return hasPackedFP32Ops() || hasPackedFP32SingleSGPROps();
808 };
809
810 bool hasAnyPackedFP64Ops() const { return hasPackedFP64SingleSGPROps(); };
811
812 bool hasAnyPackedU64Ops() const { return hasPackedU64SingleSGPROps(); };
813
814 /// \returns SGPR allocation granularity supported by the subtarget.
815 unsigned getSGPRAllocGranule() const {
816 return AMDGPU::getSGPRAllocGranule(AK: getTargetID().getGPUKind());
817 }
818
819 /// \returns SGPR encoding granularity supported by the subtarget.
820 unsigned getSGPREncodingGranule() const {
821 return AMDGPU::IsaInfo::getSGPREncodingGranule(STI: *this);
822 }
823
824 /// \returns Total number of SGPRs supported by the subtarget.
825 unsigned getTotalNumSGPRs() const {
826 return AMDGPU::getTotalNumSGPRs(AK: getTargetID().getGPUKind());
827 }
828
829 /// \returns Addressable number of SGPRs supported by the subtarget.
830 unsigned getAddressableNumSGPRs() const {
831 return AMDGPU::getAddressableNumSGPRs(AK: getTargetID().getGPUKind());
832 }
833
834 /// \returns Minimum number of SGPRs that meets the given number of waves per
835 /// execution unit requirement supported by the subtarget.
836 unsigned getMinNumSGPRs(unsigned WavesPerEU) const {
837 return AMDGPU::IsaInfo::getMinNumSGPRs(STI: *this, WavesPerEU);
838 }
839
840 /// \returns Maximum number of SGPRs that meets the given number of waves per
841 /// execution unit requirement supported by the subtarget.
842 unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
843 return AMDGPU::IsaInfo::getMaxNumSGPRs(STI: *this, WavesPerEU, Addressable);
844 }
845
846 /// \returns Reserved number of SGPRs. This is common
847 /// utility function called by MachineFunction and
848 /// Function variants of getReservedNumSGPRs.
849 unsigned getBaseReservedNumSGPRs(const bool HasFlatScratch) const;
850 /// \returns Reserved number of SGPRs for given machine function \p MF.
851 unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
852
853 /// \returns Reserved number of SGPRs for given function \p F.
854 unsigned getReservedNumSGPRs(const Function &F) const;
855
856 /// \returns Maximum number of preloaded SGPRs for the subtarget.
857 unsigned getMaxNumPreloadedSGPRs() const;
858
859 /// \returns max num SGPRs. This is the common utility
860 /// function called by MachineFunction and Function
861 /// variants of getMaxNumSGPRs.
862 unsigned getBaseMaxNumSGPRs(const Function &F,
863 std::pair<unsigned, unsigned> WavesPerEU,
864 unsigned PreloadedSGPRs,
865 unsigned ReservedNumSGPRs) const;
866
867 /// \returns Maximum number of SGPRs that meets number of waves per execution
868 /// unit requirement for function \p MF, or number of SGPRs explicitly
869 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
870 ///
871 /// \returns Value that meets number of waves per execution unit requirement
872 /// if explicitly requested value cannot be converted to integer, violates
873 /// subtarget's specifications, or does not meet number of waves per execution
874 /// unit requirement.
875 unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
876
877 /// \returns Maximum number of SGPRs that meets number of waves per execution
878 /// unit requirement for function \p F, or number of SGPRs explicitly
879 /// requested using "amdgpu-num-sgpr" attribute attached to function \p F.
880 ///
881 /// \returns Value that meets number of waves per execution unit requirement
882 /// if explicitly requested value cannot be converted to integer, violates
883 /// subtarget's specifications, or does not meet number of waves per execution
884 /// unit requirement.
885 unsigned getMaxNumSGPRs(const Function &F) const;
886
887 /// \returns VGPR allocation granularity supported by the subtarget.
888 unsigned getVGPRAllocGranule(unsigned DynamicVGPRBlockSize) const {
889 return AMDGPU::IsaInfo::getVGPRAllocGranule(STI: *this, DynamicVGPRBlockSize);
890 }
891
892 /// \returns VGPR encoding granularity supported by the subtarget.
893 unsigned getVGPREncodingGranule() const {
894 return AMDGPU::IsaInfo::getVGPREncodingGranule(STI: *this);
895 }
896
897 /// \returns Total number of VGPRs supported by the subtarget.
898 unsigned getTotalNumVGPRs() const {
899 return AMDGPU::getTotalNumVGPRs(AK: getTargetID().getGPUKind(), IsWave32: isWave32());
900 }
901
902 /// \returns Addressable number of architectural VGPRs supported by the
903 /// subtarget.
904 unsigned getAddressableNumArchVGPRs() const {
905 return AMDGPU::IsaInfo::getAddressableNumArchVGPRs(STI: *this);
906 }
907
908 /// \returns Addressable number of VGPRs supported by the subtarget.
909 unsigned getAddressableNumVGPRs(unsigned DynamicVGPRBlockSize) const {
910 // Dynamic VGPR mode is a per-kernel mode, so it is not covered by the
911 // TargetParser query.
912 if (DynamicVGPRBlockSize != 0) {
913 return AMDGPU::IsaInfo::getAddressableNumVGPRs(STI: *this,
914 DynamicVGPRBlockSize);
915 }
916 return AMDGPU::getAddressableNumVGPRs(AK: getTargetID().getGPUKind(),
917 IsWave32: isWave32());
918 }
919
920 /// \returns the minimum number of VGPRs that will prevent achieving more than
921 /// the specified number of waves \p WavesPerEU.
922 unsigned getMinNumVGPRs(unsigned WavesPerEU,
923 unsigned DynamicVGPRBlockSize) const {
924 return AMDGPU::IsaInfo::getMinNumVGPRs(STI: *this, WavesPerEU,
925 DynamicVGPRBlockSize);
926 }
927
928 /// \returns the maximum number of VGPRs that can be used and still achieved
929 /// at least the specified number of waves \p WavesPerEU.
930 unsigned getMaxNumVGPRs(unsigned WavesPerEU,
931 unsigned DynamicVGPRBlockSize) const {
932 return AMDGPU::IsaInfo::getMaxNumVGPRs(STI: *this, WavesPerEU,
933 DynamicVGPRBlockSize);
934 }
935
936 /// \returns max num VGPRs. This is the common utility function
937 /// called by MachineFunction and Function variants of getMaxNumVGPRs.
938 unsigned
939 getBaseMaxNumVGPRs(const Function &F,
940 std::pair<unsigned, unsigned> NumVGPRBounds) const;
941
942 /// \returns Maximum number of VGPRs that meets number of waves per execution
943 /// unit requirement for function \p F, or number of VGPRs explicitly
944 /// requested using "amdgpu-num-vgpr" attribute attached to function \p F.
945 ///
946 /// \returns Value that meets number of waves per execution unit requirement
947 /// if explicitly requested value cannot be converted to integer, violates
948 /// subtarget's specifications, or does not meet number of waves per execution
949 /// unit requirement.
950 unsigned getMaxNumVGPRs(const Function &F) const;
951
952 /// Return a pair of maximum numbers of VGPRs and AGPRs that meet the number
953 /// of waves per execution unit required for the function \p MF.
954 std::pair<unsigned, unsigned> getMaxNumVectorRegs(const Function &F) const;
955
956 /// \returns Maximum number of VGPRs that meets number of waves per execution
957 /// unit requirement for function \p MF, or number of VGPRs explicitly
958 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
959 ///
960 /// \returns Value that meets number of waves per execution unit requirement
961 /// if explicitly requested value cannot be converted to integer, violates
962 /// subtarget's specifications, or does not meet number of waves per execution
963 /// unit requirement.
964 unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
965
966 bool isWave32() const { return getWavefrontSize() == 32; }
967
968 bool isWave64() const { return getWavefrontSize() == 64; }
969
970 /// Returns if the wavesize of this subtarget is known reliable. This is false
971 /// only for the a default target-cpu that does not have an explicit
972 /// +wavefrontsize target feature.
973 bool isWaveSizeKnown() const {
974 return hasFeature(Feature: AMDGPU::FeatureWavefrontSize32) ||
975 hasFeature(Feature: AMDGPU::FeatureWavefrontSize64);
976 }
977
978 const TargetRegisterClass *getBoolRC() const {
979 return getRegisterInfo()->getBoolRC();
980 }
981
982 /// \returns Maximum number of work groups per compute unit supported by the
983 /// subtarget and limited by given \p FlatWorkGroupSize.
984 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const override {
985 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(STI: *this, FlatWorkGroupSize);
986 }
987
988 /// \returns Minimum flat work group size supported by the subtarget.
989 unsigned getMinFlatWorkGroupSize() const override {
990 return AMDGPU::getMinFlatWorkGroupSize();
991 }
992
993 /// \returns Maximum flat work group size supported by the subtarget.
994 unsigned getMaxFlatWorkGroupSize() const override {
995 return AMDGPU::getMaxFlatWorkGroupSize();
996 }
997
998 /// \returns Number of waves per execution unit required to support the given
999 /// \p FlatWorkGroupSize.
1000 unsigned
1001 getWavesPerEUForWorkGroup(unsigned FlatWorkGroupSize) const override {
1002 return AMDGPU::IsaInfo::getWavesPerEUForWorkGroup(STI: *this, FlatWorkGroupSize);
1003 }
1004
1005 /// \returns Minimum number of waves per execution unit supported by the
1006 /// subtarget.
1007 unsigned getMinWavesPerEU() const override {
1008 return AMDGPU::getMinWavesPerEU();
1009 }
1010
1011 void adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use, int UseOpIdx,
1012 SDep &Dep,
1013 const TargetSchedModel *SchedModel) const override;
1014
1015 // \returns true if it's beneficial on this subtarget for the scheduler to
1016 // cluster stores as well as loads.
1017 bool shouldClusterStores() const { return getGeneration() >= GFX11; }
1018
1019 // \returns the number of address arguments from which to enable MIMG NSA
1020 // on supported architectures.
1021 unsigned getNSAThreshold(const MachineFunction &MF) const;
1022
1023 // \returns true if the subtarget has a hazard requiring an "s_nop 0"
1024 // instruction before "s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)".
1025 bool requiresNopBeforeDeallocVGPRs() const { return !HasGFX1250Insts; }
1026
1027 // \returns true if the subtarget needs S_WAIT_ALU 0 before S_GETREG_B32 on
1028 // STATUS, STATE_PRIV, EXCP_FLAG_PRIV, or EXCP_FLAG_USER.
1029 bool requiresWaitIdleBeforeGetReg() const { return HasGFX1250Insts; }
1030
1031 bool requiresDisjointEarlyClobberAndUndef() const override {
1032 // AMDGPU doesn't care if early-clobber and undef operands are allocated
1033 // to the same register.
1034 return false;
1035 }
1036
1037 // DS_ATOMIC_ASYNC_BARRIER_ARRIVE_B64 shall not be claused with anything
1038 // and surronded by S_WAIT_ALU(0xFFE3).
1039 bool hasDsAtomicAsyncBarrierArriveB64PipeBug() const {
1040 return getGeneration() == GFX12;
1041 }
1042
1043 // Requires s_wait_alu(0) after s102/s103 write and src_flat_scratch_base
1044 // read.
1045 bool hasScratchBaseForwardingHazard() const {
1046 return HasGFX1250Insts && getGeneration() == GFX12;
1047 }
1048
1049 // src_flat_scratch_hi cannot be used as a source in SALU producing a 64-bit
1050 // result.
1051 bool hasFlatScratchHiInB64InstHazard() const {
1052 return HasGFX1250Insts && getGeneration() == GFX12;
1053 }
1054
1055 /// \returns true if the subtarget requires a wait for xcnt before VMEM
1056 /// accesses that must never be repeated in the event of a page fault/re-try.
1057 /// Atomic stores/rmw and all volatile accesses fall under this criteria.
1058 bool requiresWaitXCntForSingleAccessInstructions() const {
1059 return HasGFX1250Insts;
1060 }
1061
1062 /// \returns the number of significant bits in the immediate field of the
1063 /// S_NOP instruction.
1064 unsigned getSNopBits() const {
1065 if (getGeneration() >= AMDGPUSubtarget::GFX12)
1066 return 7;
1067 if (getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS)
1068 return 4;
1069 return 3;
1070 }
1071
1072 bool supportsBPermute() const {
1073 return getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS;
1074 }
1075
1076 bool supportsWaveWideBPermute() const {
1077 return (getGeneration() <= AMDGPUSubtarget::GFX9 ||
1078 getGeneration() == AMDGPUSubtarget::GFX12) ||
1079 isWave32();
1080 }
1081
1082 /// Return true if real (non-fake) variants of True16 instructions using
1083 /// 16-bit registers should be code-generated. Fake True16 instructions are
1084 /// identical to non-fake ones except that they take 32-bit registers as
1085 /// operands and always use their low halves.
1086 // TODO: Remove and use hasTrue16BitInsts() instead once True16 is fully
1087 // supported and the support for fake True16 instructions is removed.
1088 bool useRealTrue16Insts() const {
1089 return hasTrue16BitInsts() && EnableRealTrue16Insts;
1090 }
1091
1092 bool requiresWaitOnWorkgroupReleaseFence(bool TgSplit) const {
1093 return getGeneration() >= GFX10 || TgSplit;
1094 }
1095
1096 bool useDFAforSMS() const override { return false; }
1097
1098 bool enableWindowScheduler() const override { return false; }
1099
1100 // \returns true if ISel should select the native i64 min/max instructions
1101 // (V_MIN/MAX_{I|U}64).
1102 bool useMinMaxI64Insts() const {
1103 return hasMinMaxI64Insts() && !hasSlowMaxMinMulI64Insts();
1104 }
1105
1106 // \returns true if ISel should select the native i64 mul instruction
1107 // V_MUL_U64.
1108 bool useVMulU64Inst() const {
1109 return hasVMulU64Inst() && !hasSlowMaxMinMulI64Insts();
1110 }
1111};
1112
1113class GCNUserSGPRUsageInfo {
1114public:
1115 bool hasImplicitBufferPtr() const { return ImplicitBufferPtr; }
1116
1117 bool hasPrivateSegmentBuffer() const { return PrivateSegmentBuffer; }
1118
1119 bool hasDispatchPtr() const { return DispatchPtr; }
1120
1121 bool hasQueuePtr() const { return QueuePtr; }
1122
1123 bool hasKernargSegmentPtr() const { return KernargSegmentPtr; }
1124
1125 bool hasDispatchID() const { return DispatchID; }
1126
1127 bool hasFlatScratchInit() const { return FlatScratchInit; }
1128
1129 bool hasPrivateSegmentSize() const { return PrivateSegmentSize; }
1130
1131 unsigned getNumKernargPreloadSGPRs() const { return NumKernargPreloadSGPRs; }
1132
1133 unsigned getNumFreeUserSGPRs();
1134
1135 void allocKernargPreloadSGPRs(unsigned NumSGPRs);
1136
1137 enum UserSGPRID : unsigned {
1138 ImplicitBufferPtrID = 0,
1139 PrivateSegmentBufferID = 1,
1140 DispatchPtrID = 2,
1141 QueuePtrID = 3,
1142 KernargSegmentPtrID = 4,
1143 DispatchIdID = 5,
1144 FlatScratchInitID = 6,
1145 PrivateSegmentSizeID = 7
1146 };
1147
1148 // Returns the size in number of SGPRs for preload user SGPR field.
1149 static unsigned getNumUserSGPRForField(UserSGPRID ID) {
1150 switch (ID) {
1151 case ImplicitBufferPtrID:
1152 return 2;
1153 case PrivateSegmentBufferID:
1154 return 4;
1155 case DispatchPtrID:
1156 return 2;
1157 case QueuePtrID:
1158 return 2;
1159 case KernargSegmentPtrID:
1160 return 2;
1161 case DispatchIdID:
1162 return 2;
1163 case FlatScratchInitID:
1164 return 2;
1165 case PrivateSegmentSizeID:
1166 return 1;
1167 }
1168 llvm_unreachable("Unknown UserSGPRID.");
1169 }
1170
1171 GCNUserSGPRUsageInfo(const Function &F, const GCNSubtarget &ST);
1172
1173private:
1174 const GCNSubtarget &ST;
1175
1176 // Private memory buffer
1177 // Compute directly in sgpr[0:1]
1178 // Other shaders indirect 64-bits at sgpr[0:1]
1179 bool ImplicitBufferPtr = false;
1180
1181 bool PrivateSegmentBuffer = false;
1182
1183 bool DispatchPtr = false;
1184
1185 bool QueuePtr = false;
1186
1187 bool KernargSegmentPtr = false;
1188
1189 bool DispatchID = false;
1190
1191 bool FlatScratchInit = false;
1192
1193 bool PrivateSegmentSize = false;
1194
1195 unsigned NumKernargPreloadSGPRs = 0;
1196
1197 unsigned NumUsedUserSGPRs = 0;
1198};
1199
1200} // end namespace llvm
1201
1202#endif // LLVM_LIB_TARGET_AMDGPU_GCNSUBTARGET_H
1203