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 "AMDGPUSubtarget.h"
19 #include "SIFrameLowering.h"
20 #include "SIISelLowering.h"
21 #include "SIInstrInfo.h"
22 #include "llvm/CodeGen/SelectionDAGTargetInfo.h"
23 
24 namespace llvm {
25 
26 class MCInst;
27 class MCInstrInfo;
28 
29 } // namespace llvm
30 
31 #define GET_SUBTARGETINFO_HEADER
32 #include "AMDGPUGenSubtargetInfo.inc"
33 
34 namespace llvm {
35 
36 class GCNTargetMachine;
37 
38 class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
39                            public AMDGPUSubtarget {
40 
41   using AMDGPUSubtarget::getMaxWavesPerEU;
42 
43 public:
44   // Following 2 enums are documented at:
45   //   - https://llvm.org/docs/AMDGPUUsage.html#trap-handler-abi
46   enum class TrapHandlerAbi {
47     NONE   = 0x00,
48     AMDHSA = 0x01,
49   };
50 
51   enum class TrapID {
52     LLVMAMDHSATrap      = 0x02,
53     LLVMAMDHSADebugTrap = 0x03,
54   };
55 
56 private:
57   /// GlobalISel related APIs.
58   std::unique_ptr<AMDGPUCallLowering> CallLoweringInfo;
59   std::unique_ptr<InlineAsmLowering> InlineAsmLoweringInfo;
60   std::unique_ptr<InstructionSelector> InstSelector;
61   std::unique_ptr<LegalizerInfo> Legalizer;
62   std::unique_ptr<RegisterBankInfo> RegBankInfo;
63 
64 protected:
65   // Basic subtarget description.
66   Triple TargetTriple;
67   AMDGPU::IsaInfo::AMDGPUTargetID TargetID;
68   unsigned Gen;
69   InstrItineraryData InstrItins;
70   int LDSBankCount;
71   unsigned MaxPrivateElementSize;
72 
73   // Possibly statically set by tablegen, but may want to be overridden.
74   bool FastFMAF32;
75   bool FastDenormalF32;
76   bool HalfRate64Ops;
77   bool FullRate64Ops;
78 
79   // Dynamically set bits that enable features.
80   bool FlatForGlobal;
81   bool AutoWaitcntBeforeBarrier;
82   bool UnalignedScratchAccess;
83   bool UnalignedAccessMode;
84   bool HasApertureRegs;
85   bool SupportsXNACK;
86 
87   // This should not be used directly. 'TargetID' tracks the dynamic settings
88   // for XNACK.
89   bool EnableXNACK;
90 
91   bool EnableTgSplit;
92   bool EnableCuMode;
93   bool TrapHandler;
94 
95   // Used as options.
96   bool EnableLoadStoreOpt;
97   bool EnableUnsafeDSOffsetFolding;
98   bool EnableSIScheduler;
99   bool EnableDS128;
100   bool EnablePRTStrictNull;
101   bool DumpCode;
102 
103   // Subtarget statically properties set by tablegen
104   bool FP64;
105   bool FMA;
106   bool MIMG_R128;
107   bool IsGCN;
108   bool CIInsts;
109   bool GFX8Insts;
110   bool GFX9Insts;
111   bool GFX90AInsts;
112   bool GFX10Insts;
113   bool GFX10_3Insts;
114   bool GFX7GFX8GFX9Insts;
115   bool SGPRInitBug;
116   bool NegativeScratchOffsetBug;
117   bool NegativeUnalignedScratchOffsetBug;
118   bool HasSMemRealTime;
119   bool HasIntClamp;
120   bool HasFmaMixInsts;
121   bool HasMovrel;
122   bool HasVGPRIndexMode;
123   bool HasScalarStores;
124   bool HasScalarAtomics;
125   bool HasSDWAOmod;
126   bool HasSDWAScalar;
127   bool HasSDWASdst;
128   bool HasSDWAMac;
129   bool HasSDWAOutModsVOPC;
130   bool HasDPP;
131   bool HasDPP8;
132   bool Has64BitDPP;
133   bool HasPackedFP32Ops;
134   bool HasExtendedImageInsts;
135   bool HasR128A16;
136   bool HasGFX10A16;
137   bool HasG16;
138   bool HasNSAEncoding;
139   bool GFX10_BEncoding;
140   bool HasDLInsts;
141   bool HasDot1Insts;
142   bool HasDot2Insts;
143   bool HasDot3Insts;
144   bool HasDot4Insts;
145   bool HasDot5Insts;
146   bool HasDot6Insts;
147   bool HasDot7Insts;
148   bool HasMAIInsts;
149   bool HasPkFmacF16Inst;
150   bool HasAtomicFaddInsts;
151   bool SupportsSRAMECC;
152 
153   // This should not be used directly. 'TargetID' tracks the dynamic settings
154   // for SRAMECC.
155   bool EnableSRAMECC;
156 
157   bool HasNoSdstCMPX;
158   bool HasVscnt;
159   bool HasGetWaveIdInst;
160   bool HasSMemTimeInst;
161   bool HasShaderCyclesRegister;
162   bool HasRegisterBanking;
163   bool HasVOP3Literal;
164   bool HasNoDataDepHazard;
165   bool FlatAddressSpace;
166   bool FlatInstOffsets;
167   bool FlatGlobalInsts;
168   bool FlatScratchInsts;
169   bool ScalarFlatScratchInsts;
170   bool AddNoCarryInsts;
171   bool HasUnpackedD16VMem;
172   bool R600ALUInst;
173   bool CaymanISA;
174   bool CFALUBug;
175   bool LDSMisalignedBug;
176   bool HasMFMAInlineLiteralBug;
177   bool HasVertexCache;
178   short TexVTXClauseSize;
179   bool UnalignedBufferAccess;
180   bool UnalignedDSAccess;
181   bool HasPackedTID;
182   bool ScalarizeGlobal;
183 
184   bool HasVcmpxPermlaneHazard;
185   bool HasVMEMtoScalarWriteHazard;
186   bool HasSMEMtoVectorWriteHazard;
187   bool HasInstFwdPrefetchBug;
188   bool HasVcmpxExecWARHazard;
189   bool HasLdsBranchVmemWARHazard;
190   bool HasNSAtoVMEMBug;
191   bool HasOffset3fBug;
192   bool HasFlatSegmentOffsetBug;
193   bool HasImageStoreD16Bug;
194   bool HasImageGather4D16Bug;
195 
196   // Dummy feature to use for assembler in tablegen.
197   bool FeatureDisable;
198 
199   SelectionDAGTargetInfo TSInfo;
200 private:
201   SIInstrInfo InstrInfo;
202   SITargetLowering TLInfo;
203   SIFrameLowering FrameLowering;
204 
205 public:
206   // See COMPUTE_TMPRING_SIZE.WAVESIZE, 13-bit field in units of 256-dword.
207   static const unsigned MaxWaveScratchSize = (256 * 4) * ((1 << 13) - 1);
208 
209   GCNSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
210                const GCNTargetMachine &TM);
211   ~GCNSubtarget() override;
212 
213   GCNSubtarget &initializeSubtargetDependencies(const Triple &TT,
214                                                    StringRef GPU, StringRef FS);
215 
216   const SIInstrInfo *getInstrInfo() const override {
217     return &InstrInfo;
218   }
219 
220   const SIFrameLowering *getFrameLowering() const override {
221     return &FrameLowering;
222   }
223 
224   const SITargetLowering *getTargetLowering() const override {
225     return &TLInfo;
226   }
227 
228   const SIRegisterInfo *getRegisterInfo() const override {
229     return &InstrInfo.getRegisterInfo();
230   }
231 
232   const CallLowering *getCallLowering() const override {
233     return CallLoweringInfo.get();
234   }
235 
236   const InlineAsmLowering *getInlineAsmLowering() const override {
237     return InlineAsmLoweringInfo.get();
238   }
239 
240   InstructionSelector *getInstructionSelector() const override {
241     return InstSelector.get();
242   }
243 
244   const LegalizerInfo *getLegalizerInfo() const override {
245     return Legalizer.get();
246   }
247 
248   const RegisterBankInfo *getRegBankInfo() const override {
249     return RegBankInfo.get();
250   }
251 
252   const AMDGPU::IsaInfo::AMDGPUTargetID &getTargetID() const {
253     return TargetID;
254   }
255 
256   // Nothing implemented, just prevent crashes on use.
257   const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
258     return &TSInfo;
259   }
260 
261   const InstrItineraryData *getInstrItineraryData() const override {
262     return &InstrItins;
263   }
264 
265   void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
266 
267   Generation getGeneration() const {
268     return (Generation)Gen;
269   }
270 
271   /// Return the number of high bits known to be zero fror a frame index.
272   unsigned getKnownHighZeroBitsForFrameIndex() const {
273     return countLeadingZeros(MaxWaveScratchSize) + getWavefrontSizeLog2();
274   }
275 
276   int getLDSBankCount() const {
277     return LDSBankCount;
278   }
279 
280   unsigned getMaxPrivateElementSize(bool ForBufferRSrc = false) const {
281     return (ForBufferRSrc || !enableFlatScratch()) ? MaxPrivateElementSize : 16;
282   }
283 
284   unsigned getConstantBusLimit(unsigned Opcode) const;
285 
286   bool hasIntClamp() const {
287     return HasIntClamp;
288   }
289 
290   bool hasFP64() const {
291     return FP64;
292   }
293 
294   bool hasMIMG_R128() const {
295     return MIMG_R128;
296   }
297 
298   bool hasHWFP64() const {
299     return FP64;
300   }
301 
302   bool hasFastFMAF32() const {
303     return FastFMAF32;
304   }
305 
306   bool hasHalfRate64Ops() const {
307     return HalfRate64Ops;
308   }
309 
310   bool hasFullRate64Ops() const {
311     return FullRate64Ops;
312   }
313 
314   bool hasAddr64() const {
315     return (getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS);
316   }
317 
318   bool hasFlat() const {
319     return (getGeneration() > AMDGPUSubtarget::SOUTHERN_ISLANDS);
320   }
321 
322   // Return true if the target only has the reverse operand versions of VALU
323   // shift instructions (e.g. v_lshrrev_b32, and no v_lshr_b32).
324   bool hasOnlyRevVALUShifts() const {
325     return getGeneration() >= VOLCANIC_ISLANDS;
326   }
327 
328   bool hasFractBug() const {
329     return getGeneration() == SOUTHERN_ISLANDS;
330   }
331 
332   bool hasBFE() const {
333     return true;
334   }
335 
336   bool hasBFI() const {
337     return true;
338   }
339 
340   bool hasBFM() const {
341     return hasBFE();
342   }
343 
344   bool hasBCNT(unsigned Size) const {
345     return true;
346   }
347 
348   bool hasFFBL() const {
349     return true;
350   }
351 
352   bool hasFFBH() const {
353     return true;
354   }
355 
356   bool hasMed3_16() const {
357     return getGeneration() >= AMDGPUSubtarget::GFX9;
358   }
359 
360   bool hasMin3Max3_16() const {
361     return getGeneration() >= AMDGPUSubtarget::GFX9;
362   }
363 
364   bool hasFmaMixInsts() const {
365     return HasFmaMixInsts;
366   }
367 
368   bool hasCARRY() const {
369     return true;
370   }
371 
372   bool hasFMA() const {
373     return FMA;
374   }
375 
376   bool hasSwap() const {
377     return GFX9Insts;
378   }
379 
380   bool hasScalarPackInsts() const {
381     return GFX9Insts;
382   }
383 
384   bool hasScalarMulHiInsts() const {
385     return GFX9Insts;
386   }
387 
388   TrapHandlerAbi getTrapHandlerAbi() const {
389     return isAmdHsaOS() ? TrapHandlerAbi::AMDHSA : TrapHandlerAbi::NONE;
390   }
391 
392   bool supportsGetDoorbellID() const {
393     // The S_GETREG DOORBELL_ID is supported by all GFX9 onward targets.
394     return getGeneration() >= GFX9;
395   }
396 
397   /// True if the offset field of DS instructions works as expected. On SI, the
398   /// offset uses a 16-bit adder and does not always wrap properly.
399   bool hasUsableDSOffset() const {
400     return getGeneration() >= SEA_ISLANDS;
401   }
402 
403   bool unsafeDSOffsetFoldingEnabled() const {
404     return EnableUnsafeDSOffsetFolding;
405   }
406 
407   /// Condition output from div_scale is usable.
408   bool hasUsableDivScaleConditionOutput() const {
409     return getGeneration() != SOUTHERN_ISLANDS;
410   }
411 
412   /// Extra wait hazard is needed in some cases before
413   /// s_cbranch_vccnz/s_cbranch_vccz.
414   bool hasReadVCCZBug() const {
415     return getGeneration() <= SEA_ISLANDS;
416   }
417 
418   /// Writes to VCC_LO/VCC_HI update the VCCZ flag.
419   bool partialVCCWritesUpdateVCCZ() const {
420     return getGeneration() >= GFX10;
421   }
422 
423   /// A read of an SGPR by SMRD instruction requires 4 wait states when the SGPR
424   /// was written by a VALU instruction.
425   bool hasSMRDReadVALUDefHazard() const {
426     return getGeneration() == SOUTHERN_ISLANDS;
427   }
428 
429   /// A read of an SGPR by a VMEM instruction requires 5 wait states when the
430   /// SGPR was written by a VALU Instruction.
431   bool hasVMEMReadSGPRVALUDefHazard() const {
432     return getGeneration() >= VOLCANIC_ISLANDS;
433   }
434 
435   bool hasRFEHazards() const {
436     return getGeneration() >= VOLCANIC_ISLANDS;
437   }
438 
439   /// Number of hazard wait states for s_setreg_b32/s_setreg_imm32_b32.
440   unsigned getSetRegWaitStates() const {
441     return getGeneration() <= SEA_ISLANDS ? 1 : 2;
442   }
443 
444   bool dumpCode() const {
445     return DumpCode;
446   }
447 
448   /// Return the amount of LDS that can be used that will not restrict the
449   /// occupancy lower than WaveCount.
450   unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
451                                            const Function &) const;
452 
453   bool supportsMinMaxDenormModes() const {
454     return getGeneration() >= AMDGPUSubtarget::GFX9;
455   }
456 
457   /// \returns If target supports S_DENORM_MODE.
458   bool hasDenormModeInst() const {
459     return getGeneration() >= AMDGPUSubtarget::GFX10;
460   }
461 
462   bool useFlatForGlobal() const {
463     return FlatForGlobal;
464   }
465 
466   /// \returns If target supports ds_read/write_b128 and user enables generation
467   /// of ds_read/write_b128.
468   bool useDS128() const {
469     return CIInsts && EnableDS128;
470   }
471 
472   /// \return If target supports ds_read/write_b96/128.
473   bool hasDS96AndDS128() const {
474     return CIInsts;
475   }
476 
477   /// Have v_trunc_f64, v_ceil_f64, v_rndne_f64
478   bool haveRoundOpsF64() const {
479     return CIInsts;
480   }
481 
482   /// \returns If MUBUF instructions always perform range checking, even for
483   /// buffer resources used for private memory access.
484   bool privateMemoryResourceIsRangeChecked() const {
485     return getGeneration() < AMDGPUSubtarget::GFX9;
486   }
487 
488   /// \returns If target requires PRT Struct NULL support (zero result registers
489   /// for sparse texture support).
490   bool usePRTStrictNull() const {
491     return EnablePRTStrictNull;
492   }
493 
494   bool hasAutoWaitcntBeforeBarrier() const {
495     return AutoWaitcntBeforeBarrier;
496   }
497 
498   bool hasUnalignedBufferAccess() const {
499     return UnalignedBufferAccess;
500   }
501 
502   bool hasUnalignedBufferAccessEnabled() const {
503     return UnalignedBufferAccess && UnalignedAccessMode;
504   }
505 
506   bool hasUnalignedDSAccess() const {
507     return UnalignedDSAccess;
508   }
509 
510   bool hasUnalignedDSAccessEnabled() const {
511     return UnalignedDSAccess && UnalignedAccessMode;
512   }
513 
514   bool hasUnalignedScratchAccess() const {
515     return UnalignedScratchAccess;
516   }
517 
518   bool hasUnalignedAccessMode() const {
519     return UnalignedAccessMode;
520   }
521 
522   bool hasApertureRegs() const {
523     return HasApertureRegs;
524   }
525 
526   bool isTrapHandlerEnabled() const {
527     return TrapHandler;
528   }
529 
530   bool isXNACKEnabled() const {
531     return TargetID.isXnackOnOrAny();
532   }
533 
534   bool isTgSplitEnabled() const {
535     return EnableTgSplit;
536   }
537 
538   bool isCuModeEnabled() const {
539     return EnableCuMode;
540   }
541 
542   bool hasFlatAddressSpace() const {
543     return FlatAddressSpace;
544   }
545 
546   bool hasFlatScrRegister() const {
547     return hasFlatAddressSpace();
548   }
549 
550   bool hasFlatInstOffsets() const {
551     return FlatInstOffsets;
552   }
553 
554   bool hasFlatGlobalInsts() const {
555     return FlatGlobalInsts;
556   }
557 
558   bool hasFlatScratchInsts() const {
559     return FlatScratchInsts;
560   }
561 
562   // Check if target supports ST addressing mode with FLAT scratch instructions.
563   // The ST addressing mode means no registers are used, either VGPR or SGPR,
564   // but only immediate offset is swizzled and added to the FLAT scratch base.
565   bool hasFlatScratchSTMode() const {
566     return hasFlatScratchInsts() && hasGFX10_3Insts();
567   }
568 
569   bool hasScalarFlatScratchInsts() const {
570     return ScalarFlatScratchInsts;
571   }
572 
573   bool hasGlobalAddTidInsts() const {
574     return GFX10_BEncoding;
575   }
576 
577   bool hasAtomicCSub() const {
578     return GFX10_BEncoding;
579   }
580 
581   bool hasMultiDwordFlatScratchAddressing() const {
582     return getGeneration() >= GFX9;
583   }
584 
585   bool hasFlatSegmentOffsetBug() const {
586     return HasFlatSegmentOffsetBug;
587   }
588 
589   bool hasFlatLgkmVMemCountInOrder() const {
590     return getGeneration() > GFX9;
591   }
592 
593   bool hasD16LoadStore() const {
594     return getGeneration() >= GFX9;
595   }
596 
597   bool d16PreservesUnusedBits() const {
598     return hasD16LoadStore() && !TargetID.isSramEccOnOrAny();
599   }
600 
601   bool hasD16Images() const {
602     return getGeneration() >= VOLCANIC_ISLANDS;
603   }
604 
605   /// Return if most LDS instructions have an m0 use that require m0 to be
606   /// iniitalized.
607   bool ldsRequiresM0Init() const {
608     return getGeneration() < GFX9;
609   }
610 
611   // True if the hardware rewinds and replays GWS operations if a wave is
612   // preempted.
613   //
614   // If this is false, a GWS operation requires testing if a nack set the
615   // MEM_VIOL bit, and repeating if so.
616   bool hasGWSAutoReplay() const {
617     return getGeneration() >= GFX9;
618   }
619 
620   /// \returns if target has ds_gws_sema_release_all instruction.
621   bool hasGWSSemaReleaseAll() const {
622     return CIInsts;
623   }
624 
625   /// \returns true if the target has integer add/sub instructions that do not
626   /// produce a carry-out. This includes v_add_[iu]32, v_sub_[iu]32,
627   /// v_add_[iu]16, and v_sub_[iu]16, all of which support the clamp modifier
628   /// for saturation.
629   bool hasAddNoCarry() const {
630     return AddNoCarryInsts;
631   }
632 
633   bool hasUnpackedD16VMem() const {
634     return HasUnpackedD16VMem;
635   }
636 
637   // Covers VS/PS/CS graphics shaders
638   bool isMesaGfxShader(const Function &F) const {
639     return isMesa3DOS() && AMDGPU::isShader(F.getCallingConv());
640   }
641 
642   bool hasMad64_32() const {
643     return getGeneration() >= SEA_ISLANDS;
644   }
645 
646   bool hasSDWAOmod() const {
647     return HasSDWAOmod;
648   }
649 
650   bool hasSDWAScalar() const {
651     return HasSDWAScalar;
652   }
653 
654   bool hasSDWASdst() const {
655     return HasSDWASdst;
656   }
657 
658   bool hasSDWAMac() const {
659     return HasSDWAMac;
660   }
661 
662   bool hasSDWAOutModsVOPC() const {
663     return HasSDWAOutModsVOPC;
664   }
665 
666   bool hasDLInsts() const {
667     return HasDLInsts;
668   }
669 
670   bool hasDot1Insts() const {
671     return HasDot1Insts;
672   }
673 
674   bool hasDot2Insts() const {
675     return HasDot2Insts;
676   }
677 
678   bool hasDot3Insts() const {
679     return HasDot3Insts;
680   }
681 
682   bool hasDot4Insts() const {
683     return HasDot4Insts;
684   }
685 
686   bool hasDot5Insts() const {
687     return HasDot5Insts;
688   }
689 
690   bool hasDot6Insts() const {
691     return HasDot6Insts;
692   }
693 
694   bool hasDot7Insts() const {
695     return HasDot7Insts;
696   }
697 
698   bool hasMAIInsts() const {
699     return HasMAIInsts;
700   }
701 
702   bool hasPkFmacF16Inst() const {
703     return HasPkFmacF16Inst;
704   }
705 
706   bool hasAtomicFaddInsts() const {
707     return HasAtomicFaddInsts;
708   }
709 
710   bool hasNoSdstCMPX() const {
711     return HasNoSdstCMPX;
712   }
713 
714   bool hasVscnt() const {
715     return HasVscnt;
716   }
717 
718   bool hasGetWaveIdInst() const {
719     return HasGetWaveIdInst;
720   }
721 
722   bool hasSMemTimeInst() const {
723     return HasSMemTimeInst;
724   }
725 
726   bool hasShaderCyclesRegister() const {
727     return HasShaderCyclesRegister;
728   }
729 
730   bool hasRegisterBanking() const {
731     return HasRegisterBanking;
732   }
733 
734   bool hasVOP3Literal() const {
735     return HasVOP3Literal;
736   }
737 
738   bool hasNoDataDepHazard() const {
739     return HasNoDataDepHazard;
740   }
741 
742   bool vmemWriteNeedsExpWaitcnt() const {
743     return getGeneration() < SEA_ISLANDS;
744   }
745 
746   // Scratch is allocated in 256 dword per wave blocks for the entire
747   // wavefront. When viewed from the perspecive of an arbitrary workitem, this
748   // is 4-byte aligned.
749   //
750   // Only 4-byte alignment is really needed to access anything. Transformations
751   // on the pointer value itself may rely on the alignment / known low bits of
752   // the pointer. Set this to something above the minimum to avoid needing
753   // dynamic realignment in common cases.
754   Align getStackAlignment() const { return Align(16); }
755 
756   bool enableMachineScheduler() const override {
757     return true;
758   }
759 
760   bool useAA() const override;
761 
762   bool enableSubRegLiveness() const override {
763     return true;
764   }
765 
766   void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b; }
767   bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal; }
768 
769   // static wrappers
770   static bool hasHalfRate64Ops(const TargetSubtargetInfo &STI);
771 
772   // XXX - Why is this here if it isn't in the default pass set?
773   bool enableEarlyIfConversion() const override {
774     return true;
775   }
776 
777   bool enableFlatScratch() const;
778 
779   void overrideSchedPolicy(MachineSchedPolicy &Policy,
780                            unsigned NumRegionInstrs) const override;
781 
782   unsigned getMaxNumUserSGPRs() const {
783     return 16;
784   }
785 
786   bool hasSMemRealTime() const {
787     return HasSMemRealTime;
788   }
789 
790   bool hasMovrel() const {
791     return HasMovrel;
792   }
793 
794   bool hasVGPRIndexMode() const {
795     return HasVGPRIndexMode;
796   }
797 
798   bool useVGPRIndexMode() const;
799 
800   bool hasScalarCompareEq64() const {
801     return getGeneration() >= VOLCANIC_ISLANDS;
802   }
803 
804   bool hasScalarStores() const {
805     return HasScalarStores;
806   }
807 
808   bool hasScalarAtomics() const {
809     return HasScalarAtomics;
810   }
811 
812   bool hasLDSFPAtomics() const {
813     return GFX8Insts;
814   }
815 
816   /// \returns true if the subtarget has the v_permlanex16_b32 instruction.
817   bool hasPermLaneX16() const { return getGeneration() >= GFX10; }
818 
819   bool hasDPP() const {
820     return HasDPP;
821   }
822 
823   bool hasDPPBroadcasts() const {
824     return HasDPP && getGeneration() < GFX10;
825   }
826 
827   bool hasDPPWavefrontShifts() const {
828     return HasDPP && getGeneration() < GFX10;
829   }
830 
831   bool hasDPP8() const {
832     return HasDPP8;
833   }
834 
835   bool has64BitDPP() const {
836     return Has64BitDPP;
837   }
838 
839   bool hasPackedFP32Ops() const {
840     return HasPackedFP32Ops;
841   }
842 
843   bool hasFmaakFmamkF32Insts() const {
844     return getGeneration() >= GFX10;
845   }
846 
847   bool hasExtendedImageInsts() const {
848     return HasExtendedImageInsts;
849   }
850 
851   bool hasR128A16() const {
852     return HasR128A16;
853   }
854 
855   bool hasGFX10A16() const {
856     return HasGFX10A16;
857   }
858 
859   bool hasA16() const { return hasR128A16() || hasGFX10A16(); }
860 
861   bool hasG16() const { return HasG16; }
862 
863   bool hasOffset3fBug() const {
864     return HasOffset3fBug;
865   }
866 
867   bool hasImageStoreD16Bug() const { return HasImageStoreD16Bug; }
868 
869   bool hasImageGather4D16Bug() const { return HasImageGather4D16Bug; }
870 
871   bool hasNSAEncoding() const { return HasNSAEncoding; }
872 
873   bool hasGFX10_BEncoding() const {
874     return GFX10_BEncoding;
875   }
876 
877   bool hasGFX10_3Insts() const {
878     return GFX10_3Insts;
879   }
880 
881   bool hasMadF16() const;
882 
883   bool enableSIScheduler() const {
884     return EnableSIScheduler;
885   }
886 
887   bool loadStoreOptEnabled() const {
888     return EnableLoadStoreOpt;
889   }
890 
891   bool hasSGPRInitBug() const {
892     return SGPRInitBug;
893   }
894 
895   bool hasNegativeScratchOffsetBug() const { return NegativeScratchOffsetBug; }
896 
897   bool hasNegativeUnalignedScratchOffsetBug() const {
898     return NegativeUnalignedScratchOffsetBug;
899   }
900 
901   bool hasMFMAInlineLiteralBug() const {
902     return HasMFMAInlineLiteralBug;
903   }
904 
905   bool has12DWordStoreHazard() const {
906     return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
907   }
908 
909   // \returns true if the subtarget supports DWORDX3 load/store instructions.
910   bool hasDwordx3LoadStores() const {
911     return CIInsts;
912   }
913 
914   bool hasReadM0MovRelInterpHazard() const {
915     return getGeneration() == AMDGPUSubtarget::GFX9;
916   }
917 
918   bool hasReadM0SendMsgHazard() const {
919     return getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS &&
920            getGeneration() <= AMDGPUSubtarget::GFX9;
921   }
922 
923   bool hasVcmpxPermlaneHazard() const {
924     return HasVcmpxPermlaneHazard;
925   }
926 
927   bool hasVMEMtoScalarWriteHazard() const {
928     return HasVMEMtoScalarWriteHazard;
929   }
930 
931   bool hasSMEMtoVectorWriteHazard() const {
932     return HasSMEMtoVectorWriteHazard;
933   }
934 
935   bool hasLDSMisalignedBug() const {
936     return LDSMisalignedBug && !EnableCuMode;
937   }
938 
939   bool hasInstFwdPrefetchBug() const {
940     return HasInstFwdPrefetchBug;
941   }
942 
943   bool hasVcmpxExecWARHazard() const {
944     return HasVcmpxExecWARHazard;
945   }
946 
947   bool hasLdsBranchVmemWARHazard() const {
948     return HasLdsBranchVmemWARHazard;
949   }
950 
951   bool hasNSAtoVMEMBug() const {
952     return HasNSAtoVMEMBug;
953   }
954 
955   bool hasHardClauses() const { return getGeneration() >= GFX10; }
956 
957   bool hasGFX90AInsts() const { return GFX90AInsts; }
958 
959   /// Return if operations acting on VGPR tuples require even alignment.
960   bool needsAlignedVGPRs() const { return GFX90AInsts; }
961 
962   bool hasPackedTID() const { return HasPackedTID; }
963 
964   /// Return the maximum number of waves per SIMD for kernels using \p SGPRs
965   /// SGPRs
966   unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
967 
968   /// Return the maximum number of waves per SIMD for kernels using \p VGPRs
969   /// VGPRs
970   unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
971 
972   /// Return occupancy for the given function. Used LDS and a number of
973   /// registers if provided.
974   /// Note, occupancy can be affected by the scratch allocation as well, but
975   /// we do not have enough information to compute it.
976   unsigned computeOccupancy(const Function &F, unsigned LDSSize = 0,
977                             unsigned NumSGPRs = 0, unsigned NumVGPRs = 0) const;
978 
979   /// \returns true if the flat_scratch register should be initialized with the
980   /// pointer to the wave's scratch memory rather than a size and offset.
981   bool flatScratchIsPointer() const {
982     return getGeneration() >= AMDGPUSubtarget::GFX9;
983   }
984 
985   /// \returns true if the machine has merged shaders in which s0-s7 are
986   /// reserved by the hardware and user SGPRs start at s8
987   bool hasMergedShaders() const {
988     return getGeneration() >= GFX9;
989   }
990 
991   /// \returns SGPR allocation granularity supported by the subtarget.
992   unsigned getSGPRAllocGranule() const {
993     return AMDGPU::IsaInfo::getSGPRAllocGranule(this);
994   }
995 
996   /// \returns SGPR encoding granularity supported by the subtarget.
997   unsigned getSGPREncodingGranule() const {
998     return AMDGPU::IsaInfo::getSGPREncodingGranule(this);
999   }
1000 
1001   /// \returns Total number of SGPRs supported by the subtarget.
1002   unsigned getTotalNumSGPRs() const {
1003     return AMDGPU::IsaInfo::getTotalNumSGPRs(this);
1004   }
1005 
1006   /// \returns Addressable number of SGPRs supported by the subtarget.
1007   unsigned getAddressableNumSGPRs() const {
1008     return AMDGPU::IsaInfo::getAddressableNumSGPRs(this);
1009   }
1010 
1011   /// \returns Minimum number of SGPRs that meets the given number of waves per
1012   /// execution unit requirement supported by the subtarget.
1013   unsigned getMinNumSGPRs(unsigned WavesPerEU) const {
1014     return AMDGPU::IsaInfo::getMinNumSGPRs(this, WavesPerEU);
1015   }
1016 
1017   /// \returns Maximum number of SGPRs that meets the given number of waves per
1018   /// execution unit requirement supported by the subtarget.
1019   unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
1020     return AMDGPU::IsaInfo::getMaxNumSGPRs(this, WavesPerEU, Addressable);
1021   }
1022 
1023   /// \returns Reserved number of SGPRs for given function \p MF.
1024   unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
1025 
1026   /// \returns Maximum number of SGPRs that meets number of waves per execution
1027   /// unit requirement for function \p MF, or number of SGPRs explicitly
1028   /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
1029   ///
1030   /// \returns Value that meets number of waves per execution unit requirement
1031   /// if explicitly requested value cannot be converted to integer, violates
1032   /// subtarget's specifications, or does not meet number of waves per execution
1033   /// unit requirement.
1034   unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
1035 
1036   /// \returns VGPR allocation granularity supported by the subtarget.
1037   unsigned getVGPRAllocGranule() const {
1038     return AMDGPU::IsaInfo::getVGPRAllocGranule(this);
1039   }
1040 
1041   /// \returns VGPR encoding granularity supported by the subtarget.
1042   unsigned getVGPREncodingGranule() const {
1043     return AMDGPU::IsaInfo::getVGPREncodingGranule(this);
1044   }
1045 
1046   /// \returns Total number of VGPRs supported by the subtarget.
1047   unsigned getTotalNumVGPRs() const {
1048     return AMDGPU::IsaInfo::getTotalNumVGPRs(this);
1049   }
1050 
1051   /// \returns Addressable number of VGPRs supported by the subtarget.
1052   unsigned getAddressableNumVGPRs() const {
1053     return AMDGPU::IsaInfo::getAddressableNumVGPRs(this);
1054   }
1055 
1056   /// \returns Minimum number of VGPRs that meets given number of waves per
1057   /// execution unit requirement supported by the subtarget.
1058   unsigned getMinNumVGPRs(unsigned WavesPerEU) const {
1059     return AMDGPU::IsaInfo::getMinNumVGPRs(this, WavesPerEU);
1060   }
1061 
1062   /// \returns Maximum number of VGPRs that meets given number of waves per
1063   /// execution unit requirement supported by the subtarget.
1064   unsigned getMaxNumVGPRs(unsigned WavesPerEU) const {
1065     return AMDGPU::IsaInfo::getMaxNumVGPRs(this, WavesPerEU);
1066   }
1067 
1068   /// \returns Maximum number of VGPRs that meets number of waves per execution
1069   /// unit requirement for function \p MF, or number of VGPRs explicitly
1070   /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
1071   ///
1072   /// \returns Value that meets number of waves per execution unit requirement
1073   /// if explicitly requested value cannot be converted to integer, violates
1074   /// subtarget's specifications, or does not meet number of waves per execution
1075   /// unit requirement.
1076   unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
1077 
1078   void getPostRAMutations(
1079       std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
1080       const override;
1081 
1082   bool isWave32() const {
1083     return getWavefrontSize() == 32;
1084   }
1085 
1086   bool isWave64() const {
1087     return getWavefrontSize() == 64;
1088   }
1089 
1090   const TargetRegisterClass *getBoolRC() const {
1091     return getRegisterInfo()->getBoolRC();
1092   }
1093 
1094   /// \returns Maximum number of work groups per compute unit supported by the
1095   /// subtarget and limited by given \p FlatWorkGroupSize.
1096   unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const override {
1097     return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(this, FlatWorkGroupSize);
1098   }
1099 
1100   /// \returns Minimum flat work group size supported by the subtarget.
1101   unsigned getMinFlatWorkGroupSize() const override {
1102     return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(this);
1103   }
1104 
1105   /// \returns Maximum flat work group size supported by the subtarget.
1106   unsigned getMaxFlatWorkGroupSize() const override {
1107     return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(this);
1108   }
1109 
1110   /// \returns Number of waves per execution unit required to support the given
1111   /// \p FlatWorkGroupSize.
1112   unsigned
1113   getWavesPerEUForWorkGroup(unsigned FlatWorkGroupSize) const override {
1114     return AMDGPU::IsaInfo::getWavesPerEUForWorkGroup(this, FlatWorkGroupSize);
1115   }
1116 
1117   /// \returns Minimum number of waves per execution unit supported by the
1118   /// subtarget.
1119   unsigned getMinWavesPerEU() const override {
1120     return AMDGPU::IsaInfo::getMinWavesPerEU(this);
1121   }
1122 
1123   void adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use, int UseOpIdx,
1124                              SDep &Dep) const override;
1125 };
1126 
1127 } // end namespace llvm
1128 
1129 #endif // LLVM_LIB_TARGET_AMDGPU_GCNSUBTARGET_H
1130