[PowerPC] Materialize more constants with CR-field set in late peephole
[llvm-core.git] / lib / Target / AMDGPU / AMDGPUSubtarget.h
blobd9806d6133c69db5e8a1a1671f59b8a8634ca70a
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 /// AMDGPU specific subclass of TargetSubtarget.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H
16 #define LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H
18 #include "AMDGPU.h"
19 #include "AMDGPUCallLowering.h"
20 #include "R600FrameLowering.h"
21 #include "R600ISelLowering.h"
22 #include "R600InstrInfo.h"
23 #include "SIFrameLowering.h"
24 #include "SIISelLowering.h"
25 #include "SIInstrInfo.h"
26 #include "Utils/AMDGPUBaseInfo.h"
27 #include "llvm/ADT/Triple.h"
28 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
29 #include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
30 #include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h"
31 #include "llvm/CodeGen/MachineFunction.h"
32 #include "llvm/CodeGen/SelectionDAGTargetInfo.h"
33 #include "llvm/MC/MCInstrItineraries.h"
34 #include "llvm/Support/MathExtras.h"
35 #include <cassert>
36 #include <cstdint>
37 #include <memory>
38 #include <utility>
40 #define GET_SUBTARGETINFO_HEADER
41 #include "AMDGPUGenSubtargetInfo.inc"
42 #define GET_SUBTARGETINFO_HEADER
43 #include "R600GenSubtargetInfo.inc"
45 namespace llvm {
47 class StringRef;
49 class AMDGPUSubtarget {
50 public:
51 enum Generation {
52 R600 = 0,
53 R700 = 1,
54 EVERGREEN = 2,
55 NORTHERN_ISLANDS = 3,
56 SOUTHERN_ISLANDS = 4,
57 SEA_ISLANDS = 5,
58 VOLCANIC_ISLANDS = 6,
59 GFX9 = 7
62 private:
63 Triple TargetTriple;
65 protected:
66 const FeatureBitset &SubtargetFeatureBits;
67 bool Has16BitInsts;
68 bool HasMadMixInsts;
69 bool FP32Denormals;
70 bool FPExceptions;
71 bool HasSDWA;
72 bool HasVOP3PInsts;
73 bool HasMulI24;
74 bool HasMulU24;
75 bool HasFminFmaxLegacy;
76 bool EnablePromoteAlloca;
77 int LocalMemorySize;
78 unsigned WavefrontSize;
80 public:
81 AMDGPUSubtarget(const Triple &TT, const FeatureBitset &FeatureBits);
83 static const AMDGPUSubtarget &get(const MachineFunction &MF);
84 static const AMDGPUSubtarget &get(const TargetMachine &TM,
85 const Function &F);
87 /// \returns Default range flat work group size for a calling convention.
88 std::pair<unsigned, unsigned> getDefaultFlatWorkGroupSize(CallingConv::ID CC) const;
90 /// \returns Subtarget's default pair of minimum/maximum flat work group sizes
91 /// for function \p F, or minimum/maximum flat work group sizes explicitly
92 /// requested using "amdgpu-flat-work-group-size" attribute attached to
93 /// function \p F.
94 ///
95 /// \returns Subtarget's default values if explicitly requested values cannot
96 /// be converted to integer, or violate subtarget's specifications.
97 std::pair<unsigned, unsigned> getFlatWorkGroupSizes(const Function &F) const;
99 /// \returns Subtarget's default pair of minimum/maximum number of waves per
100 /// execution unit for function \p F, or minimum/maximum number of waves per
101 /// execution unit explicitly requested using "amdgpu-waves-per-eu" attribute
102 /// attached to function \p F.
104 /// \returns Subtarget's default values if explicitly requested values cannot
105 /// be converted to integer, violate subtarget's specifications, or are not
106 /// compatible with minimum/maximum number of waves limited by flat work group
107 /// size, register usage, and/or lds usage.
108 std::pair<unsigned, unsigned> getWavesPerEU(const Function &F) const;
110 /// Return the amount of LDS that can be used that will not restrict the
111 /// occupancy lower than WaveCount.
112 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
113 const Function &) const;
115 /// Inverse of getMaxLocalMemWithWaveCount. Return the maximum wavecount if
116 /// the given LDS memory size is the only constraint.
117 unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const;
119 unsigned getOccupancyWithLocalMemSize(const MachineFunction &MF) const;
121 bool isAmdHsaOS() const {
122 return TargetTriple.getOS() == Triple::AMDHSA;
125 bool isAmdPalOS() const {
126 return TargetTriple.getOS() == Triple::AMDPAL;
129 bool isMesa3DOS() const {
130 return TargetTriple.getOS() == Triple::Mesa3D;
133 bool isMesaKernel(const Function &F) const {
134 return isMesa3DOS() && !AMDGPU::isShader(F.getCallingConv());
137 bool isAmdCodeObjectV2(const Function &F) const {
138 return isAmdHsaOS() || isMesaKernel(F);
141 bool has16BitInsts() const {
142 return Has16BitInsts;
145 bool hasMadMixInsts() const {
146 return HasMadMixInsts;
149 bool hasFP32Denormals() const {
150 return FP32Denormals;
153 bool hasFPExceptions() const {
154 return FPExceptions;
157 bool hasSDWA() const {
158 return HasSDWA;
161 bool hasVOP3PInsts() const {
162 return HasVOP3PInsts;
165 bool hasMulI24() const {
166 return HasMulI24;
169 bool hasMulU24() const {
170 return HasMulU24;
173 bool hasFminFmaxLegacy() const {
174 return HasFminFmaxLegacy;
177 bool isPromoteAllocaEnabled() const {
178 return EnablePromoteAlloca;
181 unsigned getWavefrontSize() const {
182 return WavefrontSize;
185 int getLocalMemorySize() const {
186 return LocalMemorySize;
189 unsigned getAlignmentForImplicitArgPtr() const {
190 return isAmdHsaOS() ? 8 : 4;
193 /// Returns the offset in bytes from the start of the input buffer
194 /// of the first explicit kernel argument.
195 unsigned getExplicitKernelArgOffset(const Function &F) const {
196 return isAmdCodeObjectV2(F) ? 0 : 36;
199 /// \returns Maximum number of work groups per compute unit supported by the
200 /// subtarget and limited by given \p FlatWorkGroupSize.
201 unsigned getMaxWorkGroupsPerCU(unsigned FlatWorkGroupSize) const {
202 return AMDGPU::IsaInfo::getMaxWorkGroupsPerCU(SubtargetFeatureBits,
203 FlatWorkGroupSize);
206 /// \returns Minimum flat work group size supported by the subtarget.
207 unsigned getMinFlatWorkGroupSize() const {
208 return AMDGPU::IsaInfo::getMinFlatWorkGroupSize(SubtargetFeatureBits);
211 /// \returns Maximum flat work group size supported by the subtarget.
212 unsigned getMaxFlatWorkGroupSize() const {
213 return AMDGPU::IsaInfo::getMaxFlatWorkGroupSize(SubtargetFeatureBits);
216 /// \returns Maximum number of waves per execution unit supported by the
217 /// subtarget and limited by given \p FlatWorkGroupSize.
218 unsigned getMaxWavesPerEU(unsigned FlatWorkGroupSize) const {
219 return AMDGPU::IsaInfo::getMaxWavesPerEU(SubtargetFeatureBits,
220 FlatWorkGroupSize);
223 /// \returns Minimum number of waves per execution unit supported by the
224 /// subtarget.
225 unsigned getMinWavesPerEU() const {
226 return AMDGPU::IsaInfo::getMinWavesPerEU(SubtargetFeatureBits);
229 unsigned getMaxWavesPerEU() const { return 10; }
231 /// Creates value range metadata on an workitemid.* inrinsic call or load.
232 bool makeLIDRangeMetadata(Instruction *I) const;
234 virtual ~AMDGPUSubtarget() {}
237 class GCNSubtarget : public AMDGPUGenSubtargetInfo,
238 public AMDGPUSubtarget {
239 public:
240 enum {
241 ISAVersion0_0_0,
242 ISAVersion6_0_0,
243 ISAVersion6_0_1,
244 ISAVersion7_0_0,
245 ISAVersion7_0_1,
246 ISAVersion7_0_2,
247 ISAVersion7_0_3,
248 ISAVersion7_0_4,
249 ISAVersion8_0_1,
250 ISAVersion8_0_2,
251 ISAVersion8_0_3,
252 ISAVersion8_1_0,
253 ISAVersion9_0_0,
254 ISAVersion9_0_2,
255 ISAVersion9_0_4,
256 ISAVersion9_0_6,
259 enum TrapHandlerAbi {
260 TrapHandlerAbiNone = 0,
261 TrapHandlerAbiHsa = 1
264 enum TrapID {
265 TrapIDHardwareReserved = 0,
266 TrapIDHSADebugTrap = 1,
267 TrapIDLLVMTrap = 2,
268 TrapIDLLVMDebugTrap = 3,
269 TrapIDDebugBreakpoint = 7,
270 TrapIDDebugReserved8 = 8,
271 TrapIDDebugReservedFE = 0xfe,
272 TrapIDDebugReservedFF = 0xff
275 enum TrapRegValues {
276 LLVMTrapHandlerRegValue = 1
279 private:
280 /// GlobalISel related APIs.
281 std::unique_ptr<AMDGPUCallLowering> CallLoweringInfo;
282 std::unique_ptr<InstructionSelector> InstSelector;
283 std::unique_ptr<LegalizerInfo> Legalizer;
284 std::unique_ptr<RegisterBankInfo> RegBankInfo;
286 protected:
287 // Basic subtarget description.
288 Triple TargetTriple;
289 unsigned Gen;
290 unsigned IsaVersion;
291 int LDSBankCount;
292 unsigned MaxPrivateElementSize;
294 // Possibly statically set by tablegen, but may want to be overridden.
295 bool FastFMAF32;
296 bool HalfRate64Ops;
298 // Dynamially set bits that enable features.
299 bool FP64FP16Denormals;
300 bool DX10Clamp;
301 bool FlatForGlobal;
302 bool AutoWaitcntBeforeBarrier;
303 bool CodeObjectV3;
304 bool UnalignedScratchAccess;
305 bool UnalignedBufferAccess;
306 bool HasApertureRegs;
307 bool EnableXNACK;
308 bool TrapHandler;
309 bool DebuggerInsertNops;
310 bool DebuggerEmitPrologue;
312 // Used as options.
313 bool EnableHugePrivateBuffer;
314 bool EnableVGPRSpilling;
315 bool EnableLoadStoreOpt;
316 bool EnableUnsafeDSOffsetFolding;
317 bool EnableSIScheduler;
318 bool EnableDS128;
319 bool DumpCode;
321 // Subtarget statically properties set by tablegen
322 bool FP64;
323 bool FMA;
324 bool MIMG_R128;
325 bool IsGCN;
326 bool GCN3Encoding;
327 bool CIInsts;
328 bool GFX9Insts;
329 bool SGPRInitBug;
330 bool HasSMemRealTime;
331 bool HasIntClamp;
332 bool HasFmaMixInsts;
333 bool HasMovrel;
334 bool HasVGPRIndexMode;
335 bool HasScalarStores;
336 bool HasScalarAtomics;
337 bool HasInv2PiInlineImm;
338 bool HasSDWAOmod;
339 bool HasSDWAScalar;
340 bool HasSDWASdst;
341 bool HasSDWAMac;
342 bool HasSDWAOutModsVOPC;
343 bool HasDPP;
344 bool HasDLInsts;
345 bool D16PreservesUnusedBits;
346 bool FlatAddressSpace;
347 bool FlatInstOffsets;
348 bool FlatGlobalInsts;
349 bool FlatScratchInsts;
350 bool AddNoCarryInsts;
351 bool HasUnpackedD16VMem;
352 bool R600ALUInst;
353 bool CaymanISA;
354 bool CFALUBug;
355 bool HasVertexCache;
356 short TexVTXClauseSize;
357 bool ScalarizeGlobal;
359 // Dummy feature to use for assembler in tablegen.
360 bool FeatureDisable;
362 SelectionDAGTargetInfo TSInfo;
363 AMDGPUAS AS;
364 private:
365 SIInstrInfo InstrInfo;
366 SITargetLowering TLInfo;
367 SIFrameLowering FrameLowering;
369 public:
370 GCNSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
371 const GCNTargetMachine &TM);
372 ~GCNSubtarget() override;
374 GCNSubtarget &initializeSubtargetDependencies(const Triple &TT,
375 StringRef GPU, StringRef FS);
377 const SIInstrInfo *getInstrInfo() const override {
378 return &InstrInfo;
381 const SIFrameLowering *getFrameLowering() const override {
382 return &FrameLowering;
385 const SITargetLowering *getTargetLowering() const override {
386 return &TLInfo;
389 const SIRegisterInfo *getRegisterInfo() const override {
390 return &InstrInfo.getRegisterInfo();
393 const CallLowering *getCallLowering() const override {
394 return CallLoweringInfo.get();
397 const InstructionSelector *getInstructionSelector() const override {
398 return InstSelector.get();
401 const LegalizerInfo *getLegalizerInfo() const override {
402 return Legalizer.get();
405 const RegisterBankInfo *getRegBankInfo() const override {
406 return RegBankInfo.get();
409 // Nothing implemented, just prevent crashes on use.
410 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
411 return &TSInfo;
414 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
416 Generation getGeneration() const {
417 return (Generation)Gen;
420 unsigned getWavefrontSizeLog2() const {
421 return Log2_32(WavefrontSize);
424 int getLDSBankCount() const {
425 return LDSBankCount;
428 unsigned getMaxPrivateElementSize() const {
429 return MaxPrivateElementSize;
432 AMDGPUAS getAMDGPUAS() const {
433 return AS;
436 bool hasIntClamp() const {
437 return HasIntClamp;
440 bool hasFP64() const {
441 return FP64;
444 bool hasMIMG_R128() const {
445 return MIMG_R128;
448 bool hasHWFP64() const {
449 return FP64;
452 bool hasFastFMAF32() const {
453 return FastFMAF32;
456 bool hasHalfRate64Ops() const {
457 return HalfRate64Ops;
460 bool hasAddr64() const {
461 return (getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS);
464 bool hasBFE() const {
465 return true;
468 bool hasBFI() const {
469 return true;
472 bool hasBFM() const {
473 return hasBFE();
476 bool hasBCNT(unsigned Size) const {
477 return true;
480 bool hasFFBL() const {
481 return true;
484 bool hasFFBH() const {
485 return true;
488 bool hasMed3_16() const {
489 return getGeneration() >= AMDGPUSubtarget::GFX9;
492 bool hasMin3Max3_16() const {
493 return getGeneration() >= AMDGPUSubtarget::GFX9;
496 bool hasFmaMixInsts() const {
497 return HasFmaMixInsts;
500 bool hasCARRY() const {
501 return true;
504 bool hasFMA() const {
505 return FMA;
508 TrapHandlerAbi getTrapHandlerAbi() const {
509 return isAmdHsaOS() ? TrapHandlerAbiHsa : TrapHandlerAbiNone;
512 bool enableHugePrivateBuffer() const {
513 return EnableHugePrivateBuffer;
516 bool unsafeDSOffsetFoldingEnabled() const {
517 return EnableUnsafeDSOffsetFolding;
520 bool dumpCode() const {
521 return DumpCode;
524 /// Return the amount of LDS that can be used that will not restrict the
525 /// occupancy lower than WaveCount.
526 unsigned getMaxLocalMemSizeWithWaveCount(unsigned WaveCount,
527 const Function &) const;
529 bool hasFP16Denormals() const {
530 return FP64FP16Denormals;
533 bool hasFP64Denormals() const {
534 return FP64FP16Denormals;
537 bool supportsMinMaxDenormModes() const {
538 return getGeneration() >= AMDGPUSubtarget::GFX9;
541 bool enableDX10Clamp() const {
542 return DX10Clamp;
545 bool enableIEEEBit(const MachineFunction &MF) const {
546 return AMDGPU::isCompute(MF.getFunction().getCallingConv());
549 bool useFlatForGlobal() const {
550 return FlatForGlobal;
553 /// \returns If target supports ds_read/write_b128 and user enables generation
554 /// of ds_read/write_b128.
555 bool useDS128() const {
556 return CIInsts && EnableDS128;
559 /// \returns If MUBUF instructions always perform range checking, even for
560 /// buffer resources used for private memory access.
561 bool privateMemoryResourceIsRangeChecked() const {
562 return getGeneration() < AMDGPUSubtarget::GFX9;
565 bool hasAutoWaitcntBeforeBarrier() const {
566 return AutoWaitcntBeforeBarrier;
569 bool hasCodeObjectV3() const {
570 return CodeObjectV3;
573 bool hasUnalignedBufferAccess() const {
574 return UnalignedBufferAccess;
577 bool hasUnalignedScratchAccess() const {
578 return UnalignedScratchAccess;
581 bool hasApertureRegs() const {
582 return HasApertureRegs;
585 bool isTrapHandlerEnabled() const {
586 return TrapHandler;
589 bool isXNACKEnabled() const {
590 return EnableXNACK;
593 bool hasFlatAddressSpace() const {
594 return FlatAddressSpace;
597 bool hasFlatInstOffsets() const {
598 return FlatInstOffsets;
601 bool hasFlatGlobalInsts() const {
602 return FlatGlobalInsts;
605 bool hasFlatScratchInsts() const {
606 return FlatScratchInsts;
609 bool hasFlatLgkmVMemCountInOrder() const {
610 return getGeneration() > GFX9;
613 bool hasD16LoadStore() const {
614 return getGeneration() >= GFX9;
617 /// Return if most LDS instructions have an m0 use that require m0 to be
618 /// iniitalized.
619 bool ldsRequiresM0Init() const {
620 return getGeneration() < GFX9;
623 bool hasAddNoCarry() const {
624 return AddNoCarryInsts;
627 bool hasUnpackedD16VMem() const {
628 return HasUnpackedD16VMem;
631 // Covers VS/PS/CS graphics shaders
632 bool isMesaGfxShader(const Function &F) const {
633 return isMesa3DOS() && AMDGPU::isShader(F.getCallingConv());
636 bool hasMad64_32() const {
637 return getGeneration() >= SEA_ISLANDS;
640 bool hasSDWAOmod() const {
641 return HasSDWAOmod;
644 bool hasSDWAScalar() const {
645 return HasSDWAScalar;
648 bool hasSDWASdst() const {
649 return HasSDWASdst;
652 bool hasSDWAMac() const {
653 return HasSDWAMac;
656 bool hasSDWAOutModsVOPC() const {
657 return HasSDWAOutModsVOPC;
660 bool vmemWriteNeedsExpWaitcnt() const {
661 return getGeneration() < SEA_ISLANDS;
664 bool hasDLInsts() const {
665 return HasDLInsts;
668 bool d16PreservesUnusedBits() const {
669 return D16PreservesUnusedBits;
672 /// \returns Number of bytes of arguments that are passed to a shader or
673 /// kernel in addition to the explicit ones declared for the function.
674 unsigned getImplicitArgNumBytes(const Function &F) const {
675 if (isMesaKernel(F))
676 return 16;
677 return AMDGPU::getIntegerAttribute(F, "amdgpu-implicitarg-num-bytes", 0);
680 // Scratch is allocated in 256 dword per wave blocks for the entire
681 // wavefront. When viewed from the perspecive of an arbitrary workitem, this
682 // is 4-byte aligned.
684 // Only 4-byte alignment is really needed to access anything. Transformations
685 // on the pointer value itself may rely on the alignment / known low bits of
686 // the pointer. Set this to something above the minimum to avoid needing
687 // dynamic realignment in common cases.
688 unsigned getStackAlignment() const {
689 return 16;
692 bool enableMachineScheduler() const override {
693 return true;
696 bool enableSubRegLiveness() const override {
697 return true;
700 void setScalarizeGlobalBehavior(bool b) { ScalarizeGlobal = b; }
701 bool getScalarizeGlobalBehavior() const { return ScalarizeGlobal; }
703 /// \returns Number of execution units per compute unit supported by the
704 /// subtarget.
705 unsigned getEUsPerCU() const {
706 return AMDGPU::IsaInfo::getEUsPerCU(MCSubtargetInfo::getFeatureBits());
709 /// \returns Maximum number of waves per compute unit supported by the
710 /// subtarget without any kind of limitation.
711 unsigned getMaxWavesPerCU() const {
712 return AMDGPU::IsaInfo::getMaxWavesPerCU(MCSubtargetInfo::getFeatureBits());
715 /// \returns Maximum number of waves per compute unit supported by the
716 /// subtarget and limited by given \p FlatWorkGroupSize.
717 unsigned getMaxWavesPerCU(unsigned FlatWorkGroupSize) const {
718 return AMDGPU::IsaInfo::getMaxWavesPerCU(MCSubtargetInfo::getFeatureBits(),
719 FlatWorkGroupSize);
722 /// \returns Maximum number of waves per execution unit supported by the
723 /// subtarget without any kind of limitation.
724 unsigned getMaxWavesPerEU() const {
725 return AMDGPU::IsaInfo::getMaxWavesPerEU();
728 /// \returns Number of waves per work group supported by the subtarget and
729 /// limited by given \p FlatWorkGroupSize.
730 unsigned getWavesPerWorkGroup(unsigned FlatWorkGroupSize) const {
731 return AMDGPU::IsaInfo::getWavesPerWorkGroup(
732 MCSubtargetInfo::getFeatureBits(), FlatWorkGroupSize);
735 // static wrappers
736 static bool hasHalfRate64Ops(const TargetSubtargetInfo &STI);
738 // XXX - Why is this here if it isn't in the default pass set?
739 bool enableEarlyIfConversion() const override {
740 return true;
743 void overrideSchedPolicy(MachineSchedPolicy &Policy,
744 unsigned NumRegionInstrs) const override;
746 bool isVGPRSpillingEnabled(const Function &F) const;
748 unsigned getMaxNumUserSGPRs() const {
749 return 16;
752 bool hasSMemRealTime() const {
753 return HasSMemRealTime;
756 bool hasMovrel() const {
757 return HasMovrel;
760 bool hasVGPRIndexMode() const {
761 return HasVGPRIndexMode;
764 bool useVGPRIndexMode(bool UserEnable) const {
765 return !hasMovrel() || (UserEnable && hasVGPRIndexMode());
768 bool hasScalarCompareEq64() const {
769 return getGeneration() >= VOLCANIC_ISLANDS;
772 bool hasScalarStores() const {
773 return HasScalarStores;
776 bool hasScalarAtomics() const {
777 return HasScalarAtomics;
780 bool hasInv2PiInlineImm() const {
781 return HasInv2PiInlineImm;
784 bool hasDPP() const {
785 return HasDPP;
788 bool enableSIScheduler() const {
789 return EnableSIScheduler;
792 bool debuggerSupported() const {
793 return debuggerInsertNops() && debuggerEmitPrologue();
796 bool debuggerInsertNops() const {
797 return DebuggerInsertNops;
800 bool debuggerEmitPrologue() const {
801 return DebuggerEmitPrologue;
804 bool loadStoreOptEnabled() const {
805 return EnableLoadStoreOpt;
808 bool hasSGPRInitBug() const {
809 return SGPRInitBug;
812 bool has12DWordStoreHazard() const {
813 return getGeneration() != AMDGPUSubtarget::SOUTHERN_ISLANDS;
816 bool hasSMovFedHazard() const {
817 return getGeneration() >= AMDGPUSubtarget::GFX9;
820 bool hasReadM0MovRelInterpHazard() const {
821 return getGeneration() >= AMDGPUSubtarget::GFX9;
824 bool hasReadM0SendMsgHazard() const {
825 return getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS;
828 uint64_t getExplicitKernArgSize(const Function &F) const;
829 unsigned getKernArgSegmentSize(const Function &F,
830 int64_t ExplicitArgBytes = -1) const;
832 /// Return the maximum number of waves per SIMD for kernels using \p SGPRs
833 /// SGPRs
834 unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const;
836 /// Return the maximum number of waves per SIMD for kernels using \p VGPRs
837 /// VGPRs
838 unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const;
840 /// \returns true if the flat_scratch register should be initialized with the
841 /// pointer to the wave's scratch memory rather than a size and offset.
842 bool flatScratchIsPointer() const {
843 return getGeneration() >= AMDGPUSubtarget::GFX9;
846 /// \returns true if the machine has merged shaders in which s0-s7 are
847 /// reserved by the hardware and user SGPRs start at s8
848 bool hasMergedShaders() const {
849 return getGeneration() >= GFX9;
852 /// \returns SGPR allocation granularity supported by the subtarget.
853 unsigned getSGPRAllocGranule() const {
854 return AMDGPU::IsaInfo::getSGPRAllocGranule(
855 MCSubtargetInfo::getFeatureBits());
858 /// \returns SGPR encoding granularity supported by the subtarget.
859 unsigned getSGPREncodingGranule() const {
860 return AMDGPU::IsaInfo::getSGPREncodingGranule(
861 MCSubtargetInfo::getFeatureBits());
864 /// \returns Total number of SGPRs supported by the subtarget.
865 unsigned getTotalNumSGPRs() const {
866 return AMDGPU::IsaInfo::getTotalNumSGPRs(MCSubtargetInfo::getFeatureBits());
869 /// \returns Addressable number of SGPRs supported by the subtarget.
870 unsigned getAddressableNumSGPRs() const {
871 return AMDGPU::IsaInfo::getAddressableNumSGPRs(
872 MCSubtargetInfo::getFeatureBits());
875 /// \returns Minimum number of SGPRs that meets the given number of waves per
876 /// execution unit requirement supported by the subtarget.
877 unsigned getMinNumSGPRs(unsigned WavesPerEU) const {
878 return AMDGPU::IsaInfo::getMinNumSGPRs(MCSubtargetInfo::getFeatureBits(),
879 WavesPerEU);
882 /// \returns Maximum number of SGPRs that meets the given number of waves per
883 /// execution unit requirement supported by the subtarget.
884 unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const {
885 return AMDGPU::IsaInfo::getMaxNumSGPRs(MCSubtargetInfo::getFeatureBits(),
886 WavesPerEU, Addressable);
889 /// \returns Reserved number of SGPRs for given function \p MF.
890 unsigned getReservedNumSGPRs(const MachineFunction &MF) const;
892 /// \returns Maximum number of SGPRs that meets number of waves per execution
893 /// unit requirement for function \p MF, or number of SGPRs explicitly
894 /// requested using "amdgpu-num-sgpr" attribute attached to function \p MF.
896 /// \returns Value that meets number of waves per execution unit requirement
897 /// if explicitly requested value cannot be converted to integer, violates
898 /// subtarget's specifications, or does not meet number of waves per execution
899 /// unit requirement.
900 unsigned getMaxNumSGPRs(const MachineFunction &MF) const;
902 /// \returns VGPR allocation granularity supported by the subtarget.
903 unsigned getVGPRAllocGranule() const {
904 return AMDGPU::IsaInfo::getVGPRAllocGranule(
905 MCSubtargetInfo::getFeatureBits());
908 /// \returns VGPR encoding granularity supported by the subtarget.
909 unsigned getVGPREncodingGranule() const {
910 return AMDGPU::IsaInfo::getVGPREncodingGranule(
911 MCSubtargetInfo::getFeatureBits());
914 /// \returns Total number of VGPRs supported by the subtarget.
915 unsigned getTotalNumVGPRs() const {
916 return AMDGPU::IsaInfo::getTotalNumVGPRs(MCSubtargetInfo::getFeatureBits());
919 /// \returns Addressable number of VGPRs supported by the subtarget.
920 unsigned getAddressableNumVGPRs() const {
921 return AMDGPU::IsaInfo::getAddressableNumVGPRs(
922 MCSubtargetInfo::getFeatureBits());
925 /// \returns Minimum number of VGPRs that meets given number of waves per
926 /// execution unit requirement supported by the subtarget.
927 unsigned getMinNumVGPRs(unsigned WavesPerEU) const {
928 return AMDGPU::IsaInfo::getMinNumVGPRs(MCSubtargetInfo::getFeatureBits(),
929 WavesPerEU);
932 /// \returns Maximum number of VGPRs that meets given number of waves per
933 /// execution unit requirement supported by the subtarget.
934 unsigned getMaxNumVGPRs(unsigned WavesPerEU) const {
935 return AMDGPU::IsaInfo::getMaxNumVGPRs(MCSubtargetInfo::getFeatureBits(),
936 WavesPerEU);
939 /// \returns Maximum number of VGPRs that meets number of waves per execution
940 /// unit requirement for function \p MF, or number of VGPRs explicitly
941 /// requested using "amdgpu-num-vgpr" attribute attached to function \p MF.
943 /// \returns Value that meets number of waves per execution unit requirement
944 /// if explicitly requested value cannot be converted to integer, violates
945 /// subtarget's specifications, or does not meet number of waves per execution
946 /// unit requirement.
947 unsigned getMaxNumVGPRs(const MachineFunction &MF) const;
949 void getPostRAMutations(
950 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations)
951 const override;
954 class R600Subtarget final : public R600GenSubtargetInfo,
955 public AMDGPUSubtarget {
956 private:
957 R600InstrInfo InstrInfo;
958 R600FrameLowering FrameLowering;
959 bool FMA;
960 bool CaymanISA;
961 bool CFALUBug;
962 bool DX10Clamp;
963 bool HasVertexCache;
964 bool R600ALUInst;
965 bool FP64;
966 short TexVTXClauseSize;
967 Generation Gen;
968 R600TargetLowering TLInfo;
969 InstrItineraryData InstrItins;
970 SelectionDAGTargetInfo TSInfo;
971 AMDGPUAS AS;
973 public:
974 R600Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
975 const TargetMachine &TM);
977 const R600InstrInfo *getInstrInfo() const override { return &InstrInfo; }
979 const R600FrameLowering *getFrameLowering() const override {
980 return &FrameLowering;
983 const R600TargetLowering *getTargetLowering() const override {
984 return &TLInfo;
987 const R600RegisterInfo *getRegisterInfo() const override {
988 return &InstrInfo.getRegisterInfo();
991 const InstrItineraryData *getInstrItineraryData() const override {
992 return &InstrItins;
995 // Nothing implemented, just prevent crashes on use.
996 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
997 return &TSInfo;
1000 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
1002 Generation getGeneration() const {
1003 return Gen;
1006 unsigned getStackAlignment() const {
1007 return 4;
1010 R600Subtarget &initializeSubtargetDependencies(const Triple &TT,
1011 StringRef GPU, StringRef FS);
1013 bool hasBFE() const {
1014 return (getGeneration() >= EVERGREEN);
1017 bool hasBFI() const {
1018 return (getGeneration() >= EVERGREEN);
1021 bool hasBCNT(unsigned Size) const {
1022 if (Size == 32)
1023 return (getGeneration() >= EVERGREEN);
1025 return false;
1028 bool hasBORROW() const {
1029 return (getGeneration() >= EVERGREEN);
1032 bool hasCARRY() const {
1033 return (getGeneration() >= EVERGREEN);
1036 bool hasCaymanISA() const {
1037 return CaymanISA;
1040 bool hasFFBL() const {
1041 return (getGeneration() >= EVERGREEN);
1044 bool hasFFBH() const {
1045 return (getGeneration() >= EVERGREEN);
1048 bool hasFMA() const { return FMA; }
1050 bool hasCFAluBug() const { return CFALUBug; }
1052 bool hasVertexCache() const { return HasVertexCache; }
1054 short getTexVTXClauseSize() const { return TexVTXClauseSize; }
1056 AMDGPUAS getAMDGPUAS() const { return AS; }
1058 bool enableMachineScheduler() const override {
1059 return true;
1062 bool enableSubRegLiveness() const override {
1063 return true;
1067 } // end namespace llvm
1069 #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUSUBTARGET_H