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