]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r307894, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / AMDGPU / AMDGPUSubtarget.h
1 //=====-- AMDGPUSubtarget.h - Define Subtarget for AMDGPU ------*- C++ -*-====//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //==-----------------------------------------------------------------------===//
9 //
10 /// \file
11 /// \brief AMDGPU specific subclass of TargetSubtarget.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H
16 #define LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H
17
18 #include "AMDGPU.h"
19 #include "R600FrameLowering.h"
20 #include "R600ISelLowering.h"
21 #include "R600InstrInfo.h"
22 #include "SIFrameLowering.h"
23 #include "SIISelLowering.h"
24 #include "SIInstrInfo.h"
25 #include "SIMachineFunctionInfo.h"
26 #include "Utils/AMDGPUBaseInfo.h"
27 #include "llvm/ADT/Triple.h"
28 #include "llvm/CodeGen/GlobalISel/GISelAccessor.h"
29 #include "llvm/CodeGen/MachineFunction.h"
30 #include "llvm/CodeGen/SelectionDAGTargetInfo.h"
31 #include "llvm/MC/MCInstrItineraries.h"
32 #include "llvm/Support/MathExtras.h"
33 #include <cassert>
34 #include <cstdint>
35 #include <memory>
36 #include <utility>
37
38 #define GET_SUBTARGETINFO_HEADER
39 #include "AMDGPUGenSubtargetInfo.inc"
40
41 namespace llvm {
42
43 class StringRef;
44
45 class AMDGPUSubtarget : public AMDGPUGenSubtargetInfo {
46 public:
47   enum Generation {
48     R600 = 0,
49     R700,
50     EVERGREEN,
51     NORTHERN_ISLANDS,
52     SOUTHERN_ISLANDS,
53     SEA_ISLANDS,
54     VOLCANIC_ISLANDS,
55     GFX9,
56   };
57
58   enum {
59     ISAVersion0_0_0,
60     ISAVersion6_0_0,
61     ISAVersion6_0_1,
62     ISAVersion7_0_0,
63     ISAVersion7_0_1,
64     ISAVersion7_0_2,
65     ISAVersion7_0_3,
66     ISAVersion8_0_0,
67     ISAVersion8_0_1,
68     ISAVersion8_0_2,
69     ISAVersion8_0_3,
70     ISAVersion8_0_4,
71     ISAVersion8_1_0,
72     ISAVersion9_0_0,
73     ISAVersion9_0_1,
74     ISAVersion9_0_2,
75     ISAVersion9_0_3
76   };
77
78   enum TrapHandlerAbi {
79     TrapHandlerAbiNone = 0,
80     TrapHandlerAbiHsa = 1
81   };
82
83   enum TrapID {
84     TrapIDHardwareReserved = 0,
85     TrapIDHSADebugTrap = 1,
86     TrapIDLLVMTrap = 2,
87     TrapIDLLVMDebugTrap = 3,
88     TrapIDDebugBreakpoint = 7,
89     TrapIDDebugReserved8 = 8,
90     TrapIDDebugReservedFE = 0xfe,
91     TrapIDDebugReservedFF = 0xff
92   };
93
94   enum TrapRegValues {
95     LLVMTrapHandlerRegValue = 1
96   };
97
98 protected:
99   // Basic subtarget description.
100   Triple TargetTriple;
101   Generation Gen;
102   unsigned IsaVersion;
103   unsigned WavefrontSize;
104   int LocalMemorySize;
105   int LDSBankCount;
106   unsigned MaxPrivateElementSize;
107
108   // Possibly statically set by tablegen, but may want to be overridden.
109   bool FastFMAF32;
110   bool HalfRate64Ops;
111
112   // Dynamially set bits that enable features.
113   bool FP32Denormals;
114   bool FP64FP16Denormals;
115   bool FPExceptions;
116   bool DX10Clamp;
117   bool FlatForGlobal;
118   bool AutoWaitcntBeforeBarrier;
119   bool UnalignedScratchAccess;
120   bool UnalignedBufferAccess;
121   bool HasApertureRegs;
122   bool EnableXNACK;
123   bool TrapHandler;
124   bool DebuggerInsertNops;
125   bool DebuggerReserveRegs;
126   bool DebuggerEmitPrologue;
127
128   // Used as options.
129   bool EnableVGPRSpilling;
130   bool EnablePromoteAlloca;
131   bool EnableLoadStoreOpt;
132   bool EnableUnsafeDSOffsetFolding;
133   bool EnableSIScheduler;
134   bool DumpCode;
135
136   // Subtarget statically properties set by tablegen
137   bool FP64;
138   bool IsGCN;
139   bool GCN1Encoding;
140   bool GCN3Encoding;
141   bool CIInsts;
142   bool GFX9Insts;
143   bool SGPRInitBug;
144   bool HasSMemRealTime;
145   bool Has16BitInsts;
146   bool HasVOP3PInsts;
147   bool HasMovrel;
148   bool HasVGPRIndexMode;
149   bool HasScalarStores;
150   bool HasInv2PiInlineImm;
151   bool HasSDWA;
152   bool HasSDWAOmod;
153   bool HasSDWAScalar;
154   bool HasSDWASdst;
155   bool HasSDWAMac;
156   bool HasSDWAOutModsVOPC;
157   bool HasDPP;
158   bool FlatAddressSpace;
159   bool FlatInstOffsets;
160   bool FlatGlobalInsts;
161   bool FlatScratchInsts;
162   bool R600ALUInst;
163   bool CaymanISA;
164   bool CFALUBug;
165   bool HasVertexCache;
166   short TexVTXClauseSize;
167   bool ScalarizeGlobal;
168
169   // Dummy feature to use for assembler in tablegen.
170   bool FeatureDisable;
171
172   InstrItineraryData InstrItins;
173   SelectionDAGTargetInfo TSInfo;
174   AMDGPUAS AS;
175
176 public:
177   AMDGPUSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
178                   const TargetMachine &TM);
179   ~AMDGPUSubtarget() override;
180
181   AMDGPUSubtarget &initializeSubtargetDependencies(const Triple &TT,
182                                                    StringRef GPU, StringRef FS);
183
184   const AMDGPUInstrInfo *getInstrInfo() const override = 0;
185   const AMDGPUFrameLowering *getFrameLowering() const override = 0;
186   const AMDGPUTargetLowering *getTargetLowering() const override = 0;
187   const AMDGPURegisterInfo *getRegisterInfo() const override = 0;
188
189   const InstrItineraryData *getInstrItineraryData() const override {
190     return &InstrItins;
191   }
192
193   // Nothing implemented, just prevent crashes on use.
194   const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
195     return &TSInfo;
196   }
197
198   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
199
200   bool isAmdHsaOS() const {
201     return TargetTriple.getOS() == Triple::AMDHSA;
202   }
203
204   bool isMesa3DOS() const {
205     return TargetTriple.getOS() == Triple::Mesa3D;
206   }
207
208   bool isOpenCLEnv() const {
209     return TargetTriple.getEnvironment() == Triple::OpenCL ||
210            TargetTriple.getEnvironmentName() == "amdgizcl";
211   }
212
213   Generation getGeneration() const {
214     return Gen;
215   }
216
217   unsigned getWavefrontSize() const {
218     return WavefrontSize;
219   }
220
221   int getLocalMemorySize() const {
222     return LocalMemorySize;
223   }
224
225   int getLDSBankCount() const {
226     return LDSBankCount;
227   }
228
229   unsigned getMaxPrivateElementSize() const {
230     return MaxPrivateElementSize;
231   }
232
233   AMDGPUAS getAMDGPUAS() const {
234     return AS;
235   }
236
237   bool has16BitInsts() const {
238     return Has16BitInsts;
239   }
240
241   bool hasVOP3PInsts() const {
242     return HasVOP3PInsts;
243   }
244
245   bool hasHWFP64() const {
246     return FP64;
247   }
248
249   bool hasFastFMAF32() const {
250     return FastFMAF32;
251   }
252
253   bool hasHalfRate64Ops() const {
254     return HalfRate64Ops;
255   }
256
257   bool hasAddr64() const {
258     return (getGeneration() < VOLCANIC_ISLANDS);
259   }
260
261   bool hasBFE() const {
262     return (getGeneration() >= EVERGREEN);
263   }
264
265   bool hasBFI() const {
266     return (getGeneration() >= EVERGREEN);
267   }
268
269   bool hasBFM() const {
270     return hasBFE();
271   }
272
273   bool hasBCNT(unsigned Size) const {
274     if (Size == 32)
275       return (getGeneration() >= EVERGREEN);
276
277     if (Size == 64)
278       return (getGeneration() >= SOUTHERN_ISLANDS);
279
280     return false;
281   }
282
283   bool hasMulU24() const {
284     return (getGeneration() >= EVERGREEN);
285   }
286
287   bool hasMulI24() const {
288     return (getGeneration() >= SOUTHERN_ISLANDS ||
289             hasCaymanISA());
290   }
291
292   bool hasFFBL() const {
293     return (getGeneration() >= EVERGREEN);
294   }
295
296   bool hasFFBH() const {
297     return (getGeneration() >= EVERGREEN);
298   }
299
300   bool hasMed3_16() const {
301     return getGeneration() >= GFX9;
302   }
303
304   bool hasMin3Max3_16() const {
305     return getGeneration() >= GFX9;
306   }
307
308   bool hasCARRY() const {
309     return (getGeneration() >= EVERGREEN);
310   }
311
312   bool hasBORROW() const {
313     return (getGeneration() >= EVERGREEN);
314   }
315
316   bool hasCaymanISA() const {
317     return CaymanISA;
318   }
319
320   TrapHandlerAbi getTrapHandlerAbi() const {
321     return isAmdHsaOS() ? TrapHandlerAbiHsa : TrapHandlerAbiNone;
322   }
323
324   bool isPromoteAllocaEnabled() const {
325     return EnablePromoteAlloca;
326   }
327
328   bool unsafeDSOffsetFoldingEnabled() const {
329     return EnableUnsafeDSOffsetFolding;
330   }
331
332   bool dumpCode() const {
333     return DumpCode;
334   }
335
336   /// Return the amount of LDS that can be used that will not restrict the
337   /// occupancy lower than WaveCount.
338   unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
339                                            const Function &) const;
340
341   /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
342   /// the given LDS memory size is the only constraint.
343   unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const;
344
345   unsigned getOccupancyWithLocalMemSize(const MachineFunction &MF) const {
346     const auto *MFI = MF.getInfo<SIMachineFunctionInfo>();
347     return getOccupancyWithLocalMemSize(MFI->getLDSSize(), *MF.getFunction());
348   }
349
350   bool hasFP16Denormals() const {
351     return FP64FP16Denormals;
352   }
353
354   bool hasFP32Denormals() const {
355     return FP32Denormals;
356   }
357
358   bool hasFP64Denormals() const {
359     return FP64FP16Denormals;
360   }
361
362   bool hasFPExceptions() const {
363     return FPExceptions;
364   }
365
366   bool enableDX10Clamp() const {
367     return DX10Clamp;
368   }
369
370   bool enableIEEEBit(const MachineFunction &MF) const {
371     return AMDGPU::isCompute(MF.getFunction()->getCallingConv());
372   }
373
374   bool useFlatForGlobal() const {
375     return FlatForGlobal;
376   }
377
378   bool hasAutoWaitcntBeforeBarrier() const {
379     return AutoWaitcntBeforeBarrier;
380   }
381
382   bool hasUnalignedBufferAccess() const {
383     return UnalignedBufferAccess;
384   }
385
386   bool hasUnalignedScratchAccess() const {
387     return UnalignedScratchAccess;
388   }
389
390   bool hasApertureRegs() const {
391    return HasApertureRegs;
392   }
393
394   bool isTrapHandlerEnabled() const {
395     return TrapHandler;
396   }
397
398   bool isXNACKEnabled() const {
399     return EnableXNACK;
400   }
401
402   bool hasFlatAddressSpace() const {
403     return FlatAddressSpace;
404   }
405
406   bool hasFlatInstOffsets() const {
407     return FlatInstOffsets;
408   }
409
410   bool hasFlatGlobalInsts() const {
411     return FlatGlobalInsts;
412   }
413
414   bool hasFlatScratchInsts() const {
415     return FlatScratchInsts;
416   }
417
418   bool isMesaKernel(const MachineFunction &MF) const {
419     return isMesa3DOS() && !AMDGPU::isShader(MF.getFunction()->getCallingConv());
420   }
421
422   // Covers VS/PS/CS graphics shaders
423   bool isMesaGfxShader(const MachineFunction &MF) const {
424     return isMesa3DOS() && AMDGPU::isShader(MF.getFunction()->getCallingConv());
425   }
426
427   bool isAmdCodeObjectV2(const MachineFunction &MF) const {
428     return isAmdHsaOS() || isMesaKernel(MF);
429   }
430
431   bool hasFminFmaxLegacy() const {
432     return getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS;
433   }
434
435   bool hasSDWA() const {
436     return HasSDWA;
437   }
438
439   bool hasSDWAOmod() const {
440     return HasSDWAOmod;
441   }
442
443   bool hasSDWAScalar() const {
444     return HasSDWAScalar;
445   }
446
447   bool hasSDWASdst() const {
448     return HasSDWASdst;
449   }
450
451   bool hasSDWAMac() const {
452     return HasSDWAMac;
453   }
454
455   bool hasSDWAOutModsVOPC() const {
456     return HasSDWAOutModsVOPC;
457   }
458
459   /// \brief Returns the offset in bytes from the start of the input buffer
460   ///        of the first explicit kernel argument.
461   unsigned getExplicitKernelArgOffset(const MachineFunction &MF) const {
462     return isAmdCodeObjectV2(MF) ? 0 : 36;
463   }
464
465   unsigned getAlignmentForImplicitArgPtr() const {
466     return isAmdHsaOS() ? 8 : 4;
467   }
468
469   unsigned getImplicitArgNumBytes(const MachineFunction &MF) const {
470     if (isMesaKernel(MF))
471       return 16;
472     if (isAmdHsaOS() && isOpenCLEnv())
473       return 32;
474     return 0;
475   }
476
477   // Scratch is allocated in 256 dword per wave blocks for the entire
478   // wavefront. When viewed from the perspecive of an arbitrary workitem, this
479   // is 4-byte aligned.
480   unsigned getStackAlignment() const {
481     return 4;
482   }
483
484   bool enableMachineScheduler() const override {
485     return true;
486   }
487
488   bool enableSubRegLiveness() const override {
489     return true;
490   }
491
492   void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b;}
493   bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal;}
494
495   /// \returns Number of execution units per compute unit supported by the
496   /// subtarget.
497   unsigned getEUsPerCU() const {
498     return AMDGPU::IsaInfo::getEUsPerCU(getFeatureBits());
499   }
500
501   /// \returns Maximum number of work groups per compute unit supported by the
502   /// subtarget and limited by given \p FlatWorkGroupSize.
503   unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const {
504     return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(getFeatureBits(),
505                                                   FlatWorkGroupSize);
506   }
507
508   /// \returns Maximum number of waves per compute unit supported by the
509   /// subtarget without any kind of limitation.
510   unsigned getMaxWavesPerCU() const {
511     return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits());
512   }
513
514   /// \returns Maximum number of waves per compute unit supported by the
515   /// subtarget and limited by given \p FlatWorkGroupSize.
516   unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
517     return AMDGPU::IsaInfo::getMaxWavesPerCU(getFeatureBits(),
518                                              FlatWorkGroupSize);
519   }
520
521   /// \returns Minimum number of waves per execution unit supported by the
522   /// subtarget.
523   unsigned getMinWavesPerEU() const {
524     return AMDGPU::IsaInfo::getMinWavesPerEU(getFeatureBits());
525   }
526
527   /// \returns Maximum number of waves per execution unit supported by the
528   /// subtarget without any kind of limitation.
529   unsigned getMaxWavesPerEU() const {
530     return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits());
531   }
532
533   /// \returns Maximum number of waves per execution unit supported by the
534   /// subtarget and limited by given \p FlatWorkGroupSize.
535   unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const {
536     return AMDGPU::IsaInfo::getMaxWavesPerEU(getFeatureBits(),
537                                              FlatWorkGroupSize);
538   }
539
540   /// \returns Minimum flat work group size supported by the subtarget.
541   unsigned getMinFlatWorkGroupSize() const {
542     return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(getFeatureBits());
543   }
544
545   /// \returns Maximum flat work group size supported by the subtarget.
546   unsigned getMaxFlatWorkGroupSize() const {
547     return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(getFeatureBits());
548   }
549
550   /// \returns Number of waves per work group supported by the subtarget and
551   /// limited by given \p FlatWorkGroupSize.
552   unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
553     return AMDGPU::IsaInfo::getWavesPerWorkGroup(getFeatureBits(),
554                                                  FlatWorkGroupSize);
555   }
556
557   /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
558   /// for function \p F, or minimum/maximum flat work group sizes explicitly
559   /// requested using "amdgpu-flat-work-group-size" attribute attached to
560   /// function \p F.
561   ///
562   /// \returns Subtarget's default values if explicitly requested values cannot
563   /// be converted to integer, or violate subtarget's specifications.
564   std::pair<unsigned, unsigned> getFlatWorkGroupSizes(const Function &F) const;
565
566   /// \returns Subtarget's default pair of minimum/maximum number of waves per
567   /// execution unit for function \p F, or minimum/maximum number of waves per
568   /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
569   /// attached to function \p F.
570   ///
571   /// \returns Subtarget's default values if explicitly requested values cannot
572   /// be converted to integer, violate subtarget's specifications, or are not
573   /// compatible with minimum/maximum number of waves limited by flat work group
574   /// size, register usage, and/or lds usage.
575   std::pair<unsigned, unsigned> getWavesPerEU(const Function &F) const;
576
577   /// Creates value range metadata on an workitemid.* inrinsic call or load.
578   bool makeLIDRangeMetadata(Instruction *I) const;
579 };
580
581 class R600Subtarget final : public AMDGPUSubtarget {
582 private:
583   R600InstrInfo InstrInfo;
584   R600FrameLowering FrameLowering;
585   R600TargetLowering TLInfo;
586
587 public:
588   R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
589                 const TargetMachine &TM);
590
591   const R600InstrInfo *getInstrInfo() const override {
592     return &InstrInfo;
593   }
594
595   const R600FrameLowering *getFrameLowering() const override {
596     return &FrameLowering;
597   }
598
599   const R600TargetLowering *getTargetLowering() const override {
600     return &TLInfo;
601   }
602
603   const R600RegisterInfo *getRegisterInfo() const override {
604     return &InstrInfo.getRegisterInfo();
605   }
606
607   bool hasCFAluBug() const {
608     return CFALUBug;
609   }
610
611   bool hasVertexCache() const {
612     return HasVertexCache;
613   }
614
615   short getTexVTXClauseSize() const {
616     return TexVTXClauseSize;
617   }
618 };
619
620 class SISubtarget final : public AMDGPUSubtarget {
621 private:
622   SIInstrInfo InstrInfo;
623   SIFrameLowering FrameLowering;
624   SITargetLowering TLInfo;
625   std::unique_ptr<GISelAccessor> GISel;
626
627 public:
628   SISubtarget(const Triple &TT, StringRef CPU, StringRef FS,
629               const TargetMachine &TM);
630
631   const SIInstrInfo *getInstrInfo() const override {
632     return &InstrInfo;
633   }
634
635   const SIFrameLowering *getFrameLowering() const override {
636     return &FrameLowering;
637   }
638
639   const SITargetLowering *getTargetLowering() const override {
640     return &TLInfo;
641   }
642
643   const CallLowering *getCallLowering() const override {
644     assert(GISel && "Access to GlobalISel APIs not set");
645     return GISel->getCallLowering();
646   }
647
648   const InstructionSelector *getInstructionSelector() const override {
649     assert(GISel && "Access to GlobalISel APIs not set");
650     return GISel->getInstructionSelector();
651   }
652
653   const LegalizerInfo *getLegalizerInfo() const override {
654     assert(GISel && "Access to GlobalISel APIs not set");
655     return GISel->getLegalizerInfo();
656   }
657
658   const RegisterBankInfo *getRegBankInfo() const override {
659     assert(GISel && "Access to GlobalISel APIs not set");
660     return GISel->getRegBankInfo();
661   }
662
663   const SIRegisterInfo *getRegisterInfo() const override {
664     return &InstrInfo.getRegisterInfo();
665   }
666
667   void setGISelAccessor(GISelAccessor &GISel) {
668     this->GISel.reset(&GISel);
669   }
670
671   // XXX - Why is this here if it isn't in the default pass set?
672   bool enableEarlyIfConversion() const override {
673     return true;
674   }
675
676   void overrideSchedPolicy(MachineSchedPolicy &Policy,
677                            unsigned NumRegionInstrs) const override;
678
679   bool isVGPRSpillingEnabled(const Function& F) const;
680
681   unsigned getMaxNumUserSGPRs() const {
682     return 16;
683   }
684
685   bool hasSMemRealTime() const {
686     return HasSMemRealTime;
687   }
688
689   bool hasMovrel() const {
690     return HasMovrel;
691   }
692
693   bool hasVGPRIndexMode() const {
694     return HasVGPRIndexMode;
695   }
696
697   bool useVGPRIndexMode(bool UserEnable) const {
698     return !hasMovrel() || (UserEnable && hasVGPRIndexMode());
699   }
700
701   bool hasScalarCompareEq64() const {
702     return getGeneration() >= VOLCANIC_ISLANDS;
703   }
704
705   bool hasScalarStores() const {
706     return HasScalarStores;
707   }
708
709   bool hasInv2PiInlineImm() const {
710     return HasInv2PiInlineImm;
711   }
712
713   bool hasDPP() const {
714     return HasDPP;
715   }
716
717   bool enableSIScheduler() const {
718     return EnableSIScheduler;
719   }
720
721   bool debuggerSupported() const {
722     return debuggerInsertNops() && debuggerReserveRegs() &&
723       debuggerEmitPrologue();
724   }
725
726   bool debuggerInsertNops() const {
727     return DebuggerInsertNops;
728   }
729
730   bool debuggerReserveRegs() const {
731     return DebuggerReserveRegs;
732   }
733
734   bool debuggerEmitPrologue() const {
735     return DebuggerEmitPrologue;
736   }
737
738   bool loadStoreOptEnabled() const {
739     return EnableLoadStoreOpt;
740   }
741
742   bool hasSGPRInitBug() const {
743     return SGPRInitBug;
744   }
745
746   bool has12DWordStoreHazard() const {
747     return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
748   }
749
750   bool hasSMovFedHazard() const {
751     return getGeneration() >= AMDGPUSubtarget::GFX9;
752   }
753
754   bool hasReadM0Hazard() const {
755     return getGeneration() >= AMDGPUSubtarget::GFX9;
756   }
757
758   unsigned getKernArgSegmentSize(const MachineFunction &MF, unsigned ExplictArgBytes) const;
759
760   /// Return the maximum number of waves per SIMD for kernels using \p SGPRs SGPRs
761   unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
762
763   /// Return the maximum number of waves per SIMD for kernels using \p VGPRs VGPRs
764   unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
765
766   /// \returns true if the flat_scratch register should be initialized with the
767   /// pointer to the wave's scratch memory rather than a size and offset.
768   bool flatScratchIsPointer() const {
769     return getGeneration() >= GFX9;
770   }
771
772   /// \returns SGPR allocation granularity supported by the subtarget.
773   unsigned getSGPRAllocGranule() const {
774     return AMDGPU::IsaInfo::getSGPRAllocGranule(getFeatureBits());
775   }
776
777   /// \returns SGPR encoding granularity supported by the subtarget.
778   unsigned getSGPREncodingGranule() const {
779     return AMDGPU::IsaInfo::getSGPREncodingGranule(getFeatureBits());
780   }
781
782   /// \returns Total number of SGPRs supported by the subtarget.
783   unsigned getTotalNumSGPRs() const {
784     return AMDGPU::IsaInfo::getTotalNumSGPRs(getFeatureBits());
785   }
786
787   /// \returns Addressable number of SGPRs supported by the subtarget.
788   unsigned getAddressableNumSGPRs() const {
789     return AMDGPU::IsaInfo::getAddressableNumSGPRs(getFeatureBits());
790   }
791
792   /// \returns Minimum number of SGPRs that meets the given number of waves per
793   /// execution unit requirement supported by the subtarget.
794   unsigned getMinNumSGPRs(unsigned WavesPerEU) const {
795     return AMDGPU::IsaInfo::getMinNumSGPRs(getFeatureBits(), WavesPerEU);
796   }
797
798   /// \returns Maximum number of SGPRs that meets the given number of waves per
799   /// execution unit requirement supported by the subtarget.
800   unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
801     return AMDGPU::IsaInfo::getMaxNumSGPRs(getFeatureBits(), WavesPerEU,
802                                            Addressable);
803   }
804
805   /// \returns Reserved number of SGPRs for given function \p MF.
806   unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
807
808   /// \returns Maximum number of SGPRs that meets number of waves per execution
809   /// unit requirement for function \p MF, or number of SGPRs explicitly
810   /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
811   ///
812   /// \returns Value that meets number of waves per execution unit requirement
813   /// if explicitly requested value cannot be converted to integer, violates
814   /// subtarget's specifications, or does not meet number of waves per execution
815   /// unit requirement.
816   unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
817
818   /// \returns VGPR allocation granularity supported by the subtarget.
819   unsigned getVGPRAllocGranule() const {
820     return AMDGPU::IsaInfo::getVGPRAllocGranule(getFeatureBits());
821   }
822
823   /// \returns VGPR encoding granularity supported by the subtarget.
824   unsigned getVGPREncodingGranule() const {
825     return AMDGPU::IsaInfo::getVGPREncodingGranule(getFeatureBits());
826   }
827
828   /// \returns Total number of VGPRs supported by the subtarget.
829   unsigned getTotalNumVGPRs() const {
830     return AMDGPU::IsaInfo::getTotalNumVGPRs(getFeatureBits());
831   }
832
833   /// \returns Addressable number of VGPRs supported by the subtarget.
834   unsigned getAddressableNumVGPRs() const {
835     return AMDGPU::IsaInfo::getAddressableNumVGPRs(getFeatureBits());
836   }
837
838   /// \returns Minimum number of VGPRs that meets given number of waves per
839   /// execution unit requirement supported by the subtarget.
840   unsigned getMinNumVGPRs(unsigned WavesPerEU) const {
841     return AMDGPU::IsaInfo::getMinNumVGPRs(getFeatureBits(), WavesPerEU);
842   }
843
844   /// \returns Maximum number of VGPRs that meets given number of waves per
845   /// execution unit requirement supported by the subtarget.
846   unsigned getMaxNumVGPRs(unsigned WavesPerEU) const {
847     return AMDGPU::IsaInfo::getMaxNumVGPRs(getFeatureBits(), WavesPerEU);
848   }
849
850   /// \returns Reserved number of VGPRs for given function \p MF.
851   unsigned getReservedNumVGPRs(const MachineFunction &MF) const {
852     return debuggerReserveRegs() ? 4 : 0;
853   }
854
855   /// \returns Maximum number of VGPRs that meets number of waves per execution
856   /// unit requirement for function \p MF, or number of VGPRs explicitly
857   /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
858   ///
859   /// \returns Value that meets number of waves per execution unit requirement
860   /// if explicitly requested value cannot be converted to integer, violates
861   /// subtarget's specifications, or does not meet number of waves per execution
862   /// unit requirement.
863   unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
864 };
865
866 } // end namespace llvm
867
868 #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H