xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
10b57cec5SDimitry Andric //==- SIMachineFunctionInfo.h - SIMachineFunctionInfo interface --*- C++ -*-==//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric /// \file
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_AMDGPU_SIMACHINEFUNCTIONINFO_H
140b57cec5SDimitry Andric #define LLVM_LIB_TARGET_AMDGPU_SIMACHINEFUNCTIONINFO_H
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #include "AMDGPUArgumentUsageInfo.h"
170b57cec5SDimitry Andric #include "AMDGPUMachineFunction.h"
1881ad6265SDimitry Andric #include "AMDGPUTargetMachine.h"
190b57cec5SDimitry Andric #include "MCTargetDesc/AMDGPUMCTargetDesc.h"
200b57cec5SDimitry Andric #include "SIInstrInfo.h"
2181ad6265SDimitry Andric #include "llvm/ADT/SetVector.h"
220b57cec5SDimitry Andric #include "llvm/CodeGen/MIRYamlMapping.h"
230b57cec5SDimitry Andric #include "llvm/CodeGen/PseudoSourceValue.h"
24e8d8bef9SDimitry Andric #include "llvm/Support/raw_ostream.h"
25*bdd1243dSDimitry Andric #include <optional>
260b57cec5SDimitry Andric 
270b57cec5SDimitry Andric namespace llvm {
280b57cec5SDimitry Andric 
290b57cec5SDimitry Andric class MachineFrameInfo;
300b57cec5SDimitry Andric class MachineFunction;
31e8d8bef9SDimitry Andric class SIMachineFunctionInfo;
32e8d8bef9SDimitry Andric class SIRegisterInfo;
33349cc55cSDimitry Andric class TargetRegisterClass;
340b57cec5SDimitry Andric 
350b57cec5SDimitry Andric class AMDGPUPseudoSourceValue : public PseudoSourceValue {
360b57cec5SDimitry Andric public:
370b57cec5SDimitry Andric   enum AMDGPUPSVKind : unsigned {
38*bdd1243dSDimitry Andric     PSVImage = PseudoSourceValue::TargetCustom,
390b57cec5SDimitry Andric     GWSResource
400b57cec5SDimitry Andric   };
410b57cec5SDimitry Andric 
420b57cec5SDimitry Andric protected:
4381ad6265SDimitry Andric   AMDGPUPseudoSourceValue(unsigned Kind, const AMDGPUTargetMachine &TM)
4481ad6265SDimitry Andric       : PseudoSourceValue(Kind, TM) {}
450b57cec5SDimitry Andric 
460b57cec5SDimitry Andric public:
470b57cec5SDimitry Andric   bool isConstant(const MachineFrameInfo *) const override {
480b57cec5SDimitry Andric     // This should probably be true for most images, but we will start by being
490b57cec5SDimitry Andric     // conservative.
500b57cec5SDimitry Andric     return false;
510b57cec5SDimitry Andric   }
520b57cec5SDimitry Andric 
530b57cec5SDimitry Andric   bool isAliased(const MachineFrameInfo *) const override {
540b57cec5SDimitry Andric     return true;
550b57cec5SDimitry Andric   }
560b57cec5SDimitry Andric 
570b57cec5SDimitry Andric   bool mayAlias(const MachineFrameInfo *) const override {
580b57cec5SDimitry Andric     return true;
590b57cec5SDimitry Andric   }
600b57cec5SDimitry Andric };
610b57cec5SDimitry Andric 
620b57cec5SDimitry Andric class AMDGPUGWSResourcePseudoSourceValue final : public AMDGPUPseudoSourceValue {
630b57cec5SDimitry Andric public:
6481ad6265SDimitry Andric   explicit AMDGPUGWSResourcePseudoSourceValue(const AMDGPUTargetMachine &TM)
6581ad6265SDimitry Andric       : AMDGPUPseudoSourceValue(GWSResource, TM) {}
660b57cec5SDimitry Andric 
670b57cec5SDimitry Andric   static bool classof(const PseudoSourceValue *V) {
680b57cec5SDimitry Andric     return V->kind() == GWSResource;
690b57cec5SDimitry Andric   }
700b57cec5SDimitry Andric 
710b57cec5SDimitry Andric   // These are inaccessible memory from IR.
720b57cec5SDimitry Andric   bool isAliased(const MachineFrameInfo *) const override {
730b57cec5SDimitry Andric     return false;
740b57cec5SDimitry Andric   }
750b57cec5SDimitry Andric 
760b57cec5SDimitry Andric   // These are inaccessible memory from IR.
770b57cec5SDimitry Andric   bool mayAlias(const MachineFrameInfo *) const override {
780b57cec5SDimitry Andric     return false;
790b57cec5SDimitry Andric   }
800b57cec5SDimitry Andric 
810b57cec5SDimitry Andric   void printCustom(raw_ostream &OS) const override {
820b57cec5SDimitry Andric     OS << "GWSResource";
830b57cec5SDimitry Andric   }
840b57cec5SDimitry Andric };
850b57cec5SDimitry Andric 
860b57cec5SDimitry Andric namespace yaml {
870b57cec5SDimitry Andric 
880b57cec5SDimitry Andric struct SIArgument {
890b57cec5SDimitry Andric   bool IsRegister;
900b57cec5SDimitry Andric   union {
910b57cec5SDimitry Andric     StringValue RegisterName;
920b57cec5SDimitry Andric     unsigned StackOffset;
930b57cec5SDimitry Andric   };
94*bdd1243dSDimitry Andric   std::optional<unsigned> Mask;
950b57cec5SDimitry Andric 
960b57cec5SDimitry Andric   // Default constructor, which creates a stack argument.
970b57cec5SDimitry Andric   SIArgument() : IsRegister(false), StackOffset(0) {}
980b57cec5SDimitry Andric   SIArgument(const SIArgument &Other) {
990b57cec5SDimitry Andric     IsRegister = Other.IsRegister;
1000b57cec5SDimitry Andric     if (IsRegister) {
1010b57cec5SDimitry Andric       ::new ((void *)std::addressof(RegisterName))
1020b57cec5SDimitry Andric           StringValue(Other.RegisterName);
1030b57cec5SDimitry Andric     } else
1040b57cec5SDimitry Andric       StackOffset = Other.StackOffset;
1050b57cec5SDimitry Andric     Mask = Other.Mask;
1060b57cec5SDimitry Andric   }
1070b57cec5SDimitry Andric   SIArgument &operator=(const SIArgument &Other) {
1080b57cec5SDimitry Andric     IsRegister = Other.IsRegister;
1090b57cec5SDimitry Andric     if (IsRegister) {
1100b57cec5SDimitry Andric       ::new ((void *)std::addressof(RegisterName))
1110b57cec5SDimitry Andric           StringValue(Other.RegisterName);
1120b57cec5SDimitry Andric     } else
1130b57cec5SDimitry Andric       StackOffset = Other.StackOffset;
1140b57cec5SDimitry Andric     Mask = Other.Mask;
1150b57cec5SDimitry Andric     return *this;
1160b57cec5SDimitry Andric   }
1170b57cec5SDimitry Andric   ~SIArgument() {
1180b57cec5SDimitry Andric     if (IsRegister)
1190b57cec5SDimitry Andric       RegisterName.~StringValue();
1200b57cec5SDimitry Andric   }
1210b57cec5SDimitry Andric 
1220b57cec5SDimitry Andric   // Helper to create a register or stack argument.
1230b57cec5SDimitry Andric   static inline SIArgument createArgument(bool IsReg) {
1240b57cec5SDimitry Andric     if (IsReg)
1250b57cec5SDimitry Andric       return SIArgument(IsReg);
1260b57cec5SDimitry Andric     return SIArgument();
1270b57cec5SDimitry Andric   }
1280b57cec5SDimitry Andric 
1290b57cec5SDimitry Andric private:
1300b57cec5SDimitry Andric   // Construct a register argument.
1310b57cec5SDimitry Andric   SIArgument(bool) : IsRegister(true), RegisterName() {}
1320b57cec5SDimitry Andric };
1330b57cec5SDimitry Andric 
1340b57cec5SDimitry Andric template <> struct MappingTraits<SIArgument> {
1350b57cec5SDimitry Andric   static void mapping(IO &YamlIO, SIArgument &A) {
1360b57cec5SDimitry Andric     if (YamlIO.outputting()) {
1370b57cec5SDimitry Andric       if (A.IsRegister)
1380b57cec5SDimitry Andric         YamlIO.mapRequired("reg", A.RegisterName);
1390b57cec5SDimitry Andric       else
1400b57cec5SDimitry Andric         YamlIO.mapRequired("offset", A.StackOffset);
1410b57cec5SDimitry Andric     } else {
1420b57cec5SDimitry Andric       auto Keys = YamlIO.keys();
1430b57cec5SDimitry Andric       if (is_contained(Keys, "reg")) {
1440b57cec5SDimitry Andric         A = SIArgument::createArgument(true);
1450b57cec5SDimitry Andric         YamlIO.mapRequired("reg", A.RegisterName);
1460b57cec5SDimitry Andric       } else if (is_contained(Keys, "offset"))
1470b57cec5SDimitry Andric         YamlIO.mapRequired("offset", A.StackOffset);
1480b57cec5SDimitry Andric       else
1490b57cec5SDimitry Andric         YamlIO.setError("missing required key 'reg' or 'offset'");
1500b57cec5SDimitry Andric     }
1510b57cec5SDimitry Andric     YamlIO.mapOptional("mask", A.Mask);
1520b57cec5SDimitry Andric   }
1530b57cec5SDimitry Andric   static const bool flow = true;
1540b57cec5SDimitry Andric };
1550b57cec5SDimitry Andric 
1560b57cec5SDimitry Andric struct SIArgumentInfo {
157*bdd1243dSDimitry Andric   std::optional<SIArgument> PrivateSegmentBuffer;
158*bdd1243dSDimitry Andric   std::optional<SIArgument> DispatchPtr;
159*bdd1243dSDimitry Andric   std::optional<SIArgument> QueuePtr;
160*bdd1243dSDimitry Andric   std::optional<SIArgument> KernargSegmentPtr;
161*bdd1243dSDimitry Andric   std::optional<SIArgument> DispatchID;
162*bdd1243dSDimitry Andric   std::optional<SIArgument> FlatScratchInit;
163*bdd1243dSDimitry Andric   std::optional<SIArgument> PrivateSegmentSize;
1640b57cec5SDimitry Andric 
165*bdd1243dSDimitry Andric   std::optional<SIArgument> WorkGroupIDX;
166*bdd1243dSDimitry Andric   std::optional<SIArgument> WorkGroupIDY;
167*bdd1243dSDimitry Andric   std::optional<SIArgument> WorkGroupIDZ;
168*bdd1243dSDimitry Andric   std::optional<SIArgument> WorkGroupInfo;
169*bdd1243dSDimitry Andric   std::optional<SIArgument> LDSKernelId;
170*bdd1243dSDimitry Andric   std::optional<SIArgument> PrivateSegmentWaveByteOffset;
1710b57cec5SDimitry Andric 
172*bdd1243dSDimitry Andric   std::optional<SIArgument> ImplicitArgPtr;
173*bdd1243dSDimitry Andric   std::optional<SIArgument> ImplicitBufferPtr;
1740b57cec5SDimitry Andric 
175*bdd1243dSDimitry Andric   std::optional<SIArgument> WorkItemIDX;
176*bdd1243dSDimitry Andric   std::optional<SIArgument> WorkItemIDY;
177*bdd1243dSDimitry Andric   std::optional<SIArgument> WorkItemIDZ;
1780b57cec5SDimitry Andric };
1790b57cec5SDimitry Andric 
1800b57cec5SDimitry Andric template <> struct MappingTraits<SIArgumentInfo> {
1810b57cec5SDimitry Andric   static void mapping(IO &YamlIO, SIArgumentInfo &AI) {
1820b57cec5SDimitry Andric     YamlIO.mapOptional("privateSegmentBuffer", AI.PrivateSegmentBuffer);
1830b57cec5SDimitry Andric     YamlIO.mapOptional("dispatchPtr", AI.DispatchPtr);
1840b57cec5SDimitry Andric     YamlIO.mapOptional("queuePtr", AI.QueuePtr);
1850b57cec5SDimitry Andric     YamlIO.mapOptional("kernargSegmentPtr", AI.KernargSegmentPtr);
1860b57cec5SDimitry Andric     YamlIO.mapOptional("dispatchID", AI.DispatchID);
1870b57cec5SDimitry Andric     YamlIO.mapOptional("flatScratchInit", AI.FlatScratchInit);
1880b57cec5SDimitry Andric     YamlIO.mapOptional("privateSegmentSize", AI.PrivateSegmentSize);
1890b57cec5SDimitry Andric 
1900b57cec5SDimitry Andric     YamlIO.mapOptional("workGroupIDX", AI.WorkGroupIDX);
1910b57cec5SDimitry Andric     YamlIO.mapOptional("workGroupIDY", AI.WorkGroupIDY);
1920b57cec5SDimitry Andric     YamlIO.mapOptional("workGroupIDZ", AI.WorkGroupIDZ);
1930b57cec5SDimitry Andric     YamlIO.mapOptional("workGroupInfo", AI.WorkGroupInfo);
194fcaf7f86SDimitry Andric     YamlIO.mapOptional("LDSKernelId", AI.LDSKernelId);
1950b57cec5SDimitry Andric     YamlIO.mapOptional("privateSegmentWaveByteOffset",
1960b57cec5SDimitry Andric                        AI.PrivateSegmentWaveByteOffset);
1970b57cec5SDimitry Andric 
1980b57cec5SDimitry Andric     YamlIO.mapOptional("implicitArgPtr", AI.ImplicitArgPtr);
1990b57cec5SDimitry Andric     YamlIO.mapOptional("implicitBufferPtr", AI.ImplicitBufferPtr);
2000b57cec5SDimitry Andric 
2010b57cec5SDimitry Andric     YamlIO.mapOptional("workItemIDX", AI.WorkItemIDX);
2020b57cec5SDimitry Andric     YamlIO.mapOptional("workItemIDY", AI.WorkItemIDY);
2030b57cec5SDimitry Andric     YamlIO.mapOptional("workItemIDZ", AI.WorkItemIDZ);
2040b57cec5SDimitry Andric   }
2050b57cec5SDimitry Andric };
2060b57cec5SDimitry Andric 
2070b57cec5SDimitry Andric // Default to default mode for default calling convention.
2080b57cec5SDimitry Andric struct SIMode {
2090b57cec5SDimitry Andric   bool IEEE = true;
2100b57cec5SDimitry Andric   bool DX10Clamp = true;
2115ffd83dbSDimitry Andric   bool FP32InputDenormals = true;
2125ffd83dbSDimitry Andric   bool FP32OutputDenormals = true;
2135ffd83dbSDimitry Andric   bool FP64FP16InputDenormals = true;
2145ffd83dbSDimitry Andric   bool FP64FP16OutputDenormals = true;
2150b57cec5SDimitry Andric 
2160b57cec5SDimitry Andric   SIMode() = default;
2170b57cec5SDimitry Andric 
2180b57cec5SDimitry Andric   SIMode(const AMDGPU::SIModeRegisterDefaults &Mode) {
2190b57cec5SDimitry Andric     IEEE = Mode.IEEE;
2200b57cec5SDimitry Andric     DX10Clamp = Mode.DX10Clamp;
221*bdd1243dSDimitry Andric     FP32InputDenormals = Mode.FP32Denormals.Input != DenormalMode::PreserveSign;
222*bdd1243dSDimitry Andric     FP32OutputDenormals =
223*bdd1243dSDimitry Andric         Mode.FP32Denormals.Output != DenormalMode::PreserveSign;
224*bdd1243dSDimitry Andric     FP64FP16InputDenormals =
225*bdd1243dSDimitry Andric         Mode.FP64FP16Denormals.Input != DenormalMode::PreserveSign;
226*bdd1243dSDimitry Andric     FP64FP16OutputDenormals =
227*bdd1243dSDimitry Andric         Mode.FP64FP16Denormals.Output != DenormalMode::PreserveSign;
2280b57cec5SDimitry Andric   }
2290b57cec5SDimitry Andric 
2300b57cec5SDimitry Andric   bool operator ==(const SIMode Other) const {
231480093f4SDimitry Andric     return IEEE == Other.IEEE &&
232480093f4SDimitry Andric            DX10Clamp == Other.DX10Clamp &&
2335ffd83dbSDimitry Andric            FP32InputDenormals == Other.FP32InputDenormals &&
2345ffd83dbSDimitry Andric            FP32OutputDenormals == Other.FP32OutputDenormals &&
2355ffd83dbSDimitry Andric            FP64FP16InputDenormals == Other.FP64FP16InputDenormals &&
2365ffd83dbSDimitry Andric            FP64FP16OutputDenormals == Other.FP64FP16OutputDenormals;
2370b57cec5SDimitry Andric   }
2380b57cec5SDimitry Andric };
2390b57cec5SDimitry Andric 
2400b57cec5SDimitry Andric template <> struct MappingTraits<SIMode> {
2410b57cec5SDimitry Andric   static void mapping(IO &YamlIO, SIMode &Mode) {
2420b57cec5SDimitry Andric     YamlIO.mapOptional("ieee", Mode.IEEE, true);
2430b57cec5SDimitry Andric     YamlIO.mapOptional("dx10-clamp", Mode.DX10Clamp, true);
2445ffd83dbSDimitry Andric     YamlIO.mapOptional("fp32-input-denormals", Mode.FP32InputDenormals, true);
2455ffd83dbSDimitry Andric     YamlIO.mapOptional("fp32-output-denormals", Mode.FP32OutputDenormals, true);
2465ffd83dbSDimitry Andric     YamlIO.mapOptional("fp64-fp16-input-denormals", Mode.FP64FP16InputDenormals, true);
2475ffd83dbSDimitry Andric     YamlIO.mapOptional("fp64-fp16-output-denormals", Mode.FP64FP16OutputDenormals, true);
2480b57cec5SDimitry Andric   }
2490b57cec5SDimitry Andric };
2500b57cec5SDimitry Andric 
2510b57cec5SDimitry Andric struct SIMachineFunctionInfo final : public yaml::MachineFunctionInfo {
2520b57cec5SDimitry Andric   uint64_t ExplicitKernArgSize = 0;
25381ad6265SDimitry Andric   Align MaxKernArgAlign;
25481ad6265SDimitry Andric   uint32_t LDSSize = 0;
25581ad6265SDimitry Andric   uint32_t GDSSize = 0;
256e8d8bef9SDimitry Andric   Align DynLDSAlign;
2570b57cec5SDimitry Andric   bool IsEntryFunction = false;
2580b57cec5SDimitry Andric   bool NoSignedZerosFPMath = false;
2590b57cec5SDimitry Andric   bool MemoryBound = false;
2600b57cec5SDimitry Andric   bool WaveLimiter = false;
261e8d8bef9SDimitry Andric   bool HasSpilledSGPRs = false;
262e8d8bef9SDimitry Andric   bool HasSpilledVGPRs = false;
2638bcb0991SDimitry Andric   uint32_t HighBitsOf32BitAddress = 0;
2640b57cec5SDimitry Andric 
265e8d8bef9SDimitry Andric   // TODO: 10 may be a better default since it's the maximum.
266e8d8bef9SDimitry Andric   unsigned Occupancy = 0;
267e8d8bef9SDimitry Andric 
26881ad6265SDimitry Andric   SmallVector<StringValue> WWMReservedRegs;
26981ad6265SDimitry Andric 
2700b57cec5SDimitry Andric   StringValue ScratchRSrcReg = "$private_rsrc_reg";
2710b57cec5SDimitry Andric   StringValue FrameOffsetReg = "$fp_reg";
2720b57cec5SDimitry Andric   StringValue StackPtrOffsetReg = "$sp_reg";
2730b57cec5SDimitry Andric 
27481ad6265SDimitry Andric   unsigned BytesInStackArgArea = 0;
27581ad6265SDimitry Andric   bool ReturnsVoid = true;
27681ad6265SDimitry Andric 
277*bdd1243dSDimitry Andric   std::optional<SIArgumentInfo> ArgInfo;
2780b57cec5SDimitry Andric   SIMode Mode;
279*bdd1243dSDimitry Andric   std::optional<FrameIndex> ScavengeFI;
28081ad6265SDimitry Andric   StringValue VGPRForAGPRCopy;
2810b57cec5SDimitry Andric 
2820b57cec5SDimitry Andric   SIMachineFunctionInfo() = default;
2830b57cec5SDimitry Andric   SIMachineFunctionInfo(const llvm::SIMachineFunctionInfo &,
284fe6060f1SDimitry Andric                         const TargetRegisterInfo &TRI,
285fe6060f1SDimitry Andric                         const llvm::MachineFunction &MF);
2860b57cec5SDimitry Andric 
2870b57cec5SDimitry Andric   void mappingImpl(yaml::IO &YamlIO) override;
2880b57cec5SDimitry Andric   ~SIMachineFunctionInfo() = default;
2890b57cec5SDimitry Andric };
2900b57cec5SDimitry Andric 
2910b57cec5SDimitry Andric template <> struct MappingTraits<SIMachineFunctionInfo> {
2920b57cec5SDimitry Andric   static void mapping(IO &YamlIO, SIMachineFunctionInfo &MFI) {
2930b57cec5SDimitry Andric     YamlIO.mapOptional("explicitKernArgSize", MFI.ExplicitKernArgSize,
2940b57cec5SDimitry Andric                        UINT64_C(0));
29581ad6265SDimitry Andric     YamlIO.mapOptional("maxKernArgAlign", MFI.MaxKernArgAlign);
2960b57cec5SDimitry Andric     YamlIO.mapOptional("ldsSize", MFI.LDSSize, 0u);
29781ad6265SDimitry Andric     YamlIO.mapOptional("gdsSize", MFI.GDSSize, 0u);
298e8d8bef9SDimitry Andric     YamlIO.mapOptional("dynLDSAlign", MFI.DynLDSAlign, Align());
2990b57cec5SDimitry Andric     YamlIO.mapOptional("isEntryFunction", MFI.IsEntryFunction, false);
3000b57cec5SDimitry Andric     YamlIO.mapOptional("noSignedZerosFPMath", MFI.NoSignedZerosFPMath, false);
3010b57cec5SDimitry Andric     YamlIO.mapOptional("memoryBound", MFI.MemoryBound, false);
3020b57cec5SDimitry Andric     YamlIO.mapOptional("waveLimiter", MFI.WaveLimiter, false);
303e8d8bef9SDimitry Andric     YamlIO.mapOptional("hasSpilledSGPRs", MFI.HasSpilledSGPRs, false);
304e8d8bef9SDimitry Andric     YamlIO.mapOptional("hasSpilledVGPRs", MFI.HasSpilledVGPRs, false);
3050b57cec5SDimitry Andric     YamlIO.mapOptional("scratchRSrcReg", MFI.ScratchRSrcReg,
3060b57cec5SDimitry Andric                        StringValue("$private_rsrc_reg"));
3070b57cec5SDimitry Andric     YamlIO.mapOptional("frameOffsetReg", MFI.FrameOffsetReg,
3080b57cec5SDimitry Andric                        StringValue("$fp_reg"));
3090b57cec5SDimitry Andric     YamlIO.mapOptional("stackPtrOffsetReg", MFI.StackPtrOffsetReg,
3100b57cec5SDimitry Andric                        StringValue("$sp_reg"));
31181ad6265SDimitry Andric     YamlIO.mapOptional("bytesInStackArgArea", MFI.BytesInStackArgArea, 0u);
31281ad6265SDimitry Andric     YamlIO.mapOptional("returnsVoid", MFI.ReturnsVoid, true);
3130b57cec5SDimitry Andric     YamlIO.mapOptional("argumentInfo", MFI.ArgInfo);
3140b57cec5SDimitry Andric     YamlIO.mapOptional("mode", MFI.Mode, SIMode());
3158bcb0991SDimitry Andric     YamlIO.mapOptional("highBitsOf32BitAddress",
3168bcb0991SDimitry Andric                        MFI.HighBitsOf32BitAddress, 0u);
317e8d8bef9SDimitry Andric     YamlIO.mapOptional("occupancy", MFI.Occupancy, 0);
31881ad6265SDimitry Andric     YamlIO.mapOptional("wwmReservedRegs", MFI.WWMReservedRegs);
319fe6060f1SDimitry Andric     YamlIO.mapOptional("scavengeFI", MFI.ScavengeFI);
32081ad6265SDimitry Andric     YamlIO.mapOptional("vgprForAGPRCopy", MFI.VGPRForAGPRCopy,
32181ad6265SDimitry Andric                        StringValue()); // Don't print out when it's empty.
3220b57cec5SDimitry Andric   }
3230b57cec5SDimitry Andric };
3240b57cec5SDimitry Andric 
3250b57cec5SDimitry Andric } // end namespace yaml
3260b57cec5SDimitry Andric 
327*bdd1243dSDimitry Andric // A CSR SGPR value can be preserved inside a callee using one of the following
328*bdd1243dSDimitry Andric // methods.
329*bdd1243dSDimitry Andric //   1. Copy to an unused scratch SGPR.
330*bdd1243dSDimitry Andric //   2. Spill to a VGPR lane.
331*bdd1243dSDimitry Andric //   3. Spill to memory via. a scratch VGPR.
332*bdd1243dSDimitry Andric // class PrologEpilogSGPRSaveRestoreInfo represents the save/restore method used
333*bdd1243dSDimitry Andric // for an SGPR at function prolog/epilog.
334*bdd1243dSDimitry Andric enum class SGPRSaveKind : uint8_t {
335*bdd1243dSDimitry Andric   COPY_TO_SCRATCH_SGPR,
336*bdd1243dSDimitry Andric   SPILL_TO_VGPR_LANE,
337*bdd1243dSDimitry Andric   SPILL_TO_MEM
338*bdd1243dSDimitry Andric };
339*bdd1243dSDimitry Andric 
340*bdd1243dSDimitry Andric class PrologEpilogSGPRSaveRestoreInfo {
341*bdd1243dSDimitry Andric   SGPRSaveKind Kind;
342*bdd1243dSDimitry Andric   union {
343*bdd1243dSDimitry Andric     int Index;
344*bdd1243dSDimitry Andric     Register Reg;
345*bdd1243dSDimitry Andric   };
346*bdd1243dSDimitry Andric 
347*bdd1243dSDimitry Andric public:
348*bdd1243dSDimitry Andric   PrologEpilogSGPRSaveRestoreInfo(SGPRSaveKind K, int I) : Kind(K), Index(I) {}
349*bdd1243dSDimitry Andric   PrologEpilogSGPRSaveRestoreInfo(SGPRSaveKind K, Register R)
350*bdd1243dSDimitry Andric       : Kind(K), Reg(R) {}
351*bdd1243dSDimitry Andric   Register getReg() const { return Reg; }
352*bdd1243dSDimitry Andric   int getIndex() const { return Index; }
353*bdd1243dSDimitry Andric   SGPRSaveKind getKind() const { return Kind; }
354*bdd1243dSDimitry Andric };
355*bdd1243dSDimitry Andric 
3560b57cec5SDimitry Andric /// This class keeps track of the SPI_SP_INPUT_ADDR config register, which
3570b57cec5SDimitry Andric /// tells the hardware which interpolation parameters to load.
3580b57cec5SDimitry Andric class SIMachineFunctionInfo final : public AMDGPUMachineFunction {
3590b57cec5SDimitry Andric   friend class GCNTargetMachine;
3600b57cec5SDimitry Andric 
361*bdd1243dSDimitry Andric   // State of MODE register, assumed FP mode.
362*bdd1243dSDimitry Andric   AMDGPU::SIModeRegisterDefaults Mode;
363*bdd1243dSDimitry Andric 
3640b57cec5SDimitry Andric   // Registers that may be reserved for spilling purposes. These may be the same
3650b57cec5SDimitry Andric   // as the input registers.
3665ffd83dbSDimitry Andric   Register ScratchRSrcReg = AMDGPU::PRIVATE_RSRC_REG;
3670b57cec5SDimitry Andric 
368*bdd1243dSDimitry Andric   // This is the unswizzled offset from the current dispatch's scratch wave
3695ffd83dbSDimitry Andric   // base to the beginning of the current function's frame.
3705ffd83dbSDimitry Andric   Register FrameOffsetReg = AMDGPU::FP_REG;
3710b57cec5SDimitry Andric 
3725ffd83dbSDimitry Andric   // This is an ABI register used in the non-entry calling convention to
3735ffd83dbSDimitry Andric   // communicate the unswizzled offset from the current dispatch's scratch wave
3745ffd83dbSDimitry Andric   // base to the beginning of the new function's frame.
3755ffd83dbSDimitry Andric   Register StackPtrOffsetReg = AMDGPU::SP_REG;
3760b57cec5SDimitry Andric 
3770b57cec5SDimitry Andric   AMDGPUFunctionArgInfo ArgInfo;
3780b57cec5SDimitry Andric 
3790b57cec5SDimitry Andric   // Graphics info.
3800b57cec5SDimitry Andric   unsigned PSInputAddr = 0;
3810b57cec5SDimitry Andric   unsigned PSInputEnable = 0;
3820b57cec5SDimitry Andric 
3830b57cec5SDimitry Andric   /// Number of bytes of arguments this function has on the stack. If the callee
3840b57cec5SDimitry Andric   /// is expected to restore the argument stack this should be a multiple of 16,
3850b57cec5SDimitry Andric   /// all usable during a tail call.
3860b57cec5SDimitry Andric   ///
3870b57cec5SDimitry Andric   /// The alternative would forbid tail call optimisation in some cases: if we
3880b57cec5SDimitry Andric   /// want to transfer control from a function with 8-bytes of stack-argument
3890b57cec5SDimitry Andric   /// space to a function with 16-bytes then misalignment of this value would
3900b57cec5SDimitry Andric   /// make a stack adjustment necessary, which could not be undone by the
3910b57cec5SDimitry Andric   /// callee.
3920b57cec5SDimitry Andric   unsigned BytesInStackArgArea = 0;
3930b57cec5SDimitry Andric 
3940b57cec5SDimitry Andric   bool ReturnsVoid = true;
3950b57cec5SDimitry Andric 
3960b57cec5SDimitry Andric   // A pair of default/requested minimum/maximum flat work group sizes.
3970b57cec5SDimitry Andric   // Minimum - first, maximum - second.
3980b57cec5SDimitry Andric   std::pair<unsigned, unsigned> FlatWorkGroupSizes = {0, 0};
3990b57cec5SDimitry Andric 
4000b57cec5SDimitry Andric   // A pair of default/requested minimum/maximum number of waves per execution
4010b57cec5SDimitry Andric   // unit. Minimum - first, maximum - second.
4020b57cec5SDimitry Andric   std::pair<unsigned, unsigned> WavesPerEU = {0, 0};
4030b57cec5SDimitry Andric 
40481ad6265SDimitry Andric   const AMDGPUGWSResourcePseudoSourceValue GWSResourcePSV;
4050b57cec5SDimitry Andric 
4060b57cec5SDimitry Andric private:
4070b57cec5SDimitry Andric   unsigned NumUserSGPRs = 0;
4080b57cec5SDimitry Andric   unsigned NumSystemSGPRs = 0;
4090b57cec5SDimitry Andric 
4100b57cec5SDimitry Andric   bool HasSpilledSGPRs = false;
4110b57cec5SDimitry Andric   bool HasSpilledVGPRs = false;
4120b57cec5SDimitry Andric   bool HasNonSpillStackObjects = false;
4130b57cec5SDimitry Andric   bool IsStackRealigned = false;
4140b57cec5SDimitry Andric 
4150b57cec5SDimitry Andric   unsigned NumSpilledSGPRs = 0;
4160b57cec5SDimitry Andric   unsigned NumSpilledVGPRs = 0;
4170b57cec5SDimitry Andric 
4180b57cec5SDimitry Andric   // Feature bits required for inputs passed in user SGPRs.
4190b57cec5SDimitry Andric   bool PrivateSegmentBuffer : 1;
4200b57cec5SDimitry Andric   bool DispatchPtr : 1;
4210b57cec5SDimitry Andric   bool QueuePtr : 1;
4220b57cec5SDimitry Andric   bool KernargSegmentPtr : 1;
4230b57cec5SDimitry Andric   bool DispatchID : 1;
4240b57cec5SDimitry Andric   bool FlatScratchInit : 1;
4250b57cec5SDimitry Andric 
4260b57cec5SDimitry Andric   // Feature bits required for inputs passed in system SGPRs.
4270b57cec5SDimitry Andric   bool WorkGroupIDX : 1; // Always initialized.
4280b57cec5SDimitry Andric   bool WorkGroupIDY : 1;
4290b57cec5SDimitry Andric   bool WorkGroupIDZ : 1;
4300b57cec5SDimitry Andric   bool WorkGroupInfo : 1;
431fcaf7f86SDimitry Andric   bool LDSKernelId : 1;
4320b57cec5SDimitry Andric   bool PrivateSegmentWaveByteOffset : 1;
4330b57cec5SDimitry Andric 
4340b57cec5SDimitry Andric   bool WorkItemIDX : 1; // Always initialized.
4350b57cec5SDimitry Andric   bool WorkItemIDY : 1;
4360b57cec5SDimitry Andric   bool WorkItemIDZ : 1;
4370b57cec5SDimitry Andric 
4380b57cec5SDimitry Andric   // Private memory buffer
4390b57cec5SDimitry Andric   // Compute directly in sgpr[0:1]
4400b57cec5SDimitry Andric   // Other shaders indirect 64-bits at sgpr[0:1]
4410b57cec5SDimitry Andric   bool ImplicitBufferPtr : 1;
4420b57cec5SDimitry Andric 
4430b57cec5SDimitry Andric   // Pointer to where the ABI inserts special kernel arguments separate from the
4440b57cec5SDimitry Andric   // user arguments. This is an offset from the KernargSegmentPtr.
4450b57cec5SDimitry Andric   bool ImplicitArgPtr : 1;
4460b57cec5SDimitry Andric 
44781ad6265SDimitry Andric   bool MayNeedAGPRs : 1;
44881ad6265SDimitry Andric 
4490b57cec5SDimitry Andric   // The hard-wired high half of the address of the global information table
4500b57cec5SDimitry Andric   // for AMDPAL OS type. 0xffffffff represents no hard-wired high half, since
4510b57cec5SDimitry Andric   // current hardware only allows a 16 bit value.
4520b57cec5SDimitry Andric   unsigned GITPtrHigh;
4530b57cec5SDimitry Andric 
4540b57cec5SDimitry Andric   unsigned HighBitsOf32BitAddress;
4550b57cec5SDimitry Andric 
4560b57cec5SDimitry Andric   // Current recorded maximum possible occupancy.
4570b57cec5SDimitry Andric   unsigned Occupancy;
4580b57cec5SDimitry Andric 
459*bdd1243dSDimitry Andric   mutable std::optional<bool> UsesAGPRs;
460349cc55cSDimitry Andric 
4610b57cec5SDimitry Andric   MCPhysReg getNextUserSGPR() const;
4620b57cec5SDimitry Andric 
4630b57cec5SDimitry Andric   MCPhysReg getNextSystemSGPR() const;
4640b57cec5SDimitry Andric 
4650b57cec5SDimitry Andric public:
4660b57cec5SDimitry Andric   struct VGPRSpillToAGPR {
4670b57cec5SDimitry Andric     SmallVector<MCPhysReg, 32> Lanes;
4680b57cec5SDimitry Andric     bool FullyAllocated = false;
4690eae32dcSDimitry Andric     bool IsDead = false;
4700b57cec5SDimitry Andric   };
4710b57cec5SDimitry Andric 
4720b57cec5SDimitry Andric private:
473*bdd1243dSDimitry Andric   // To track VGPR + lane index for each subregister of the SGPR spilled to
474*bdd1243dSDimitry Andric   // frameindex key during SILowerSGPRSpills pass.
475*bdd1243dSDimitry Andric   DenseMap<int, std::vector<SIRegisterInfo::SpilledReg>> SGPRSpillToVGPRLanes;
476*bdd1243dSDimitry Andric   // To track VGPR + lane index for spilling special SGPRs like Frame Pointer
477*bdd1243dSDimitry Andric   // identified during PrologEpilogInserter.
478*bdd1243dSDimitry Andric   DenseMap<int, std::vector<SIRegisterInfo::SpilledReg>>
479*bdd1243dSDimitry Andric       PrologEpilogSGPRSpillToVGPRLanes;
4800b57cec5SDimitry Andric   unsigned NumVGPRSpillLanes = 0;
481*bdd1243dSDimitry Andric   unsigned NumVGPRPrologEpilogSpillLanes = 0;
482*bdd1243dSDimitry Andric   SmallVector<Register, 2> SpillVGPRs;
483*bdd1243dSDimitry Andric   using WWMSpillsMap = MapVector<Register, int>;
484*bdd1243dSDimitry Andric   // To track the registers used in instructions that can potentially modify the
485*bdd1243dSDimitry Andric   // inactive lanes. The WWM instructions and the writelane instructions for
486*bdd1243dSDimitry Andric   // spilling SGPRs to VGPRs fall under such category of operations. The VGPRs
487*bdd1243dSDimitry Andric   // modified by them should be spilled/restored at function prolog/epilog to
488*bdd1243dSDimitry Andric   // avoid any undesired outcome. Each entry in this map holds a pair of values,
489*bdd1243dSDimitry Andric   // the VGPR and its stack slot index.
490*bdd1243dSDimitry Andric   WWMSpillsMap WWMSpills;
491*bdd1243dSDimitry Andric 
492*bdd1243dSDimitry Andric   using ReservedRegSet = SmallSetVector<Register, 8>;
493*bdd1243dSDimitry Andric   // To track the VGPRs reserved for WWM instructions. They get stack slots
494*bdd1243dSDimitry Andric   // later during PrologEpilogInserter and get added into the superset WWMSpills
495*bdd1243dSDimitry Andric   // for actual spilling. A separate set makes the register reserved part and
496*bdd1243dSDimitry Andric   // the serialization easier.
497*bdd1243dSDimitry Andric   ReservedRegSet WWMReservedRegs;
498*bdd1243dSDimitry Andric 
499*bdd1243dSDimitry Andric   using PrologEpilogSGPRSpillsMap =
500*bdd1243dSDimitry Andric       DenseMap<Register, PrologEpilogSGPRSaveRestoreInfo>;
501*bdd1243dSDimitry Andric   // To track the SGPR spill method used for a CSR SGPR register during
502*bdd1243dSDimitry Andric   // frame lowering. Even though the SGPR spills are handled during
503*bdd1243dSDimitry Andric   // SILowerSGPRSpills pass, some special handling needed later during the
504*bdd1243dSDimitry Andric   // PrologEpilogInserter.
505*bdd1243dSDimitry Andric   PrologEpilogSGPRSpillsMap PrologEpilogSGPRSpills;
5060b57cec5SDimitry Andric 
5070b57cec5SDimitry Andric   DenseMap<int, VGPRSpillToAGPR> VGPRToAGPRSpills;
5080b57cec5SDimitry Andric 
5090b57cec5SDimitry Andric   // AGPRs used for VGPR spills.
5100b57cec5SDimitry Andric   SmallVector<MCPhysReg, 32> SpillAGPR;
5110b57cec5SDimitry Andric 
5120b57cec5SDimitry Andric   // VGPRs used for AGPR spills.
5130b57cec5SDimitry Andric   SmallVector<MCPhysReg, 32> SpillVGPR;
5140b57cec5SDimitry Andric 
515fe6060f1SDimitry Andric   // Emergency stack slot. Sometimes, we create this before finalizing the stack
516fe6060f1SDimitry Andric   // frame, so save it here and add it to the RegScavenger later.
517*bdd1243dSDimitry Andric   std::optional<int> ScavengeFI;
518fe6060f1SDimitry Andric 
51981ad6265SDimitry Andric private:
52081ad6265SDimitry Andric   Register VGPRForAGPRCopy;
52181ad6265SDimitry Andric 
522*bdd1243dSDimitry Andric   bool allocateVGPRForSGPRSpills(MachineFunction &MF, int FI,
523*bdd1243dSDimitry Andric                                  unsigned LaneIndex);
524*bdd1243dSDimitry Andric   bool allocateVGPRForPrologEpilogSGPRSpills(MachineFunction &MF, int FI,
525*bdd1243dSDimitry Andric                                              unsigned LaneIndex);
526*bdd1243dSDimitry Andric 
52781ad6265SDimitry Andric public:
52881ad6265SDimitry Andric   Register getVGPRForAGPRCopy() const {
52981ad6265SDimitry Andric     return VGPRForAGPRCopy;
53081ad6265SDimitry Andric   }
53181ad6265SDimitry Andric 
53281ad6265SDimitry Andric   void setVGPRForAGPRCopy(Register NewVGPRForAGPRCopy) {
53381ad6265SDimitry Andric     VGPRForAGPRCopy = NewVGPRForAGPRCopy;
53481ad6265SDimitry Andric   }
53581ad6265SDimitry Andric 
536*bdd1243dSDimitry Andric   bool isCalleeSavedReg(const MCPhysReg *CSRegs, MCPhysReg Reg) const;
5375ffd83dbSDimitry Andric 
5380b57cec5SDimitry Andric public:
53981ad6265SDimitry Andric   SIMachineFunctionInfo(const SIMachineFunctionInfo &MFI) = default;
540*bdd1243dSDimitry Andric   SIMachineFunctionInfo(const Function &F, const GCNSubtarget *STI);
54181ad6265SDimitry Andric 
54281ad6265SDimitry Andric   MachineFunctionInfo *
54381ad6265SDimitry Andric   clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF,
54481ad6265SDimitry Andric         const DenseMap<MachineBasicBlock *, MachineBasicBlock *> &Src2DstMBB)
54581ad6265SDimitry Andric       const override;
5460b57cec5SDimitry Andric 
547fe6060f1SDimitry Andric   bool initializeBaseYamlFields(const yaml::SIMachineFunctionInfo &YamlMFI,
548fe6060f1SDimitry Andric                                 const MachineFunction &MF,
549fe6060f1SDimitry Andric                                 PerFunctionMIParsingState &PFS,
550fe6060f1SDimitry Andric                                 SMDiagnostic &Error, SMRange &SourceRange);
551fe6060f1SDimitry Andric 
552*bdd1243dSDimitry Andric   void reserveWWMRegister(Register Reg) { WWMReservedRegs.insert(Reg); }
553*bdd1243dSDimitry Andric 
554*bdd1243dSDimitry Andric   AMDGPU::SIModeRegisterDefaults getMode() const {
555*bdd1243dSDimitry Andric     return Mode;
556fe6060f1SDimitry Andric   }
5570b57cec5SDimitry Andric 
55881ad6265SDimitry Andric   ArrayRef<SIRegisterInfo::SpilledReg>
559*bdd1243dSDimitry Andric   getSGPRSpillToVGPRLanes(int FrameIndex) const {
560*bdd1243dSDimitry Andric     auto I = SGPRSpillToVGPRLanes.find(FrameIndex);
561*bdd1243dSDimitry Andric     return (I == SGPRSpillToVGPRLanes.end())
56281ad6265SDimitry Andric                ? ArrayRef<SIRegisterInfo::SpilledReg>()
563*bdd1243dSDimitry Andric                : ArrayRef(I->second);
5640b57cec5SDimitry Andric   }
5650b57cec5SDimitry Andric 
566*bdd1243dSDimitry Andric   ArrayRef<Register> getSGPRSpillVGPRs() const { return SpillVGPRs; }
567*bdd1243dSDimitry Andric   const WWMSpillsMap &getWWMSpills() const { return WWMSpills; }
568*bdd1243dSDimitry Andric   const ReservedRegSet &getWWMReservedRegs() const { return WWMReservedRegs; }
569*bdd1243dSDimitry Andric 
570*bdd1243dSDimitry Andric   const PrologEpilogSGPRSpillsMap &getPrologEpilogSGPRSpills() const {
571*bdd1243dSDimitry Andric     return PrologEpilogSGPRSpills;
572*bdd1243dSDimitry Andric   }
573*bdd1243dSDimitry Andric 
574*bdd1243dSDimitry Andric   void addToPrologEpilogSGPRSpills(Register Reg,
575*bdd1243dSDimitry Andric                                    PrologEpilogSGPRSaveRestoreInfo SI) {
576*bdd1243dSDimitry Andric     PrologEpilogSGPRSpills.insert(std::make_pair(Reg, SI));
577*bdd1243dSDimitry Andric   }
578*bdd1243dSDimitry Andric 
579*bdd1243dSDimitry Andric   // Check if an entry created for \p Reg in PrologEpilogSGPRSpills. Return true
580*bdd1243dSDimitry Andric   // on success and false otherwise.
581*bdd1243dSDimitry Andric   bool hasPrologEpilogSGPRSpillEntry(Register Reg) const {
582*bdd1243dSDimitry Andric     return PrologEpilogSGPRSpills.find(Reg) != PrologEpilogSGPRSpills.end();
583*bdd1243dSDimitry Andric   }
584*bdd1243dSDimitry Andric 
585*bdd1243dSDimitry Andric   // Get the scratch SGPR if allocated to save/restore \p Reg.
586*bdd1243dSDimitry Andric   Register getScratchSGPRCopyDstReg(Register Reg) const {
587*bdd1243dSDimitry Andric     auto I = PrologEpilogSGPRSpills.find(Reg);
588*bdd1243dSDimitry Andric     if (I != PrologEpilogSGPRSpills.end() &&
589*bdd1243dSDimitry Andric         I->second.getKind() == SGPRSaveKind::COPY_TO_SCRATCH_SGPR)
590*bdd1243dSDimitry Andric       return I->second.getReg();
591*bdd1243dSDimitry Andric 
592*bdd1243dSDimitry Andric     return AMDGPU::NoRegister;
593*bdd1243dSDimitry Andric   }
594*bdd1243dSDimitry Andric 
595*bdd1243dSDimitry Andric   // Get all scratch SGPRs allocated to copy/restore the SGPR spills.
596*bdd1243dSDimitry Andric   void getAllScratchSGPRCopyDstRegs(SmallVectorImpl<Register> &Regs) const {
597*bdd1243dSDimitry Andric     for (const auto &SI : PrologEpilogSGPRSpills) {
598*bdd1243dSDimitry Andric       if (SI.second.getKind() == SGPRSaveKind::COPY_TO_SCRATCH_SGPR)
599*bdd1243dSDimitry Andric         Regs.push_back(SI.second.getReg());
600*bdd1243dSDimitry Andric     }
601*bdd1243dSDimitry Andric   }
602*bdd1243dSDimitry Andric 
603*bdd1243dSDimitry Andric   // Check if \p FI is allocated for any SGPR spill to a VGPR lane during PEI.
604*bdd1243dSDimitry Andric   bool checkIndexInPrologEpilogSGPRSpills(int FI) const {
605*bdd1243dSDimitry Andric     return find_if(PrologEpilogSGPRSpills,
606*bdd1243dSDimitry Andric                    [FI](const std::pair<Register,
607*bdd1243dSDimitry Andric                                         PrologEpilogSGPRSaveRestoreInfo> &SI) {
608*bdd1243dSDimitry Andric                      return SI.second.getKind() ==
609*bdd1243dSDimitry Andric                                 SGPRSaveKind::SPILL_TO_VGPR_LANE &&
610*bdd1243dSDimitry Andric                             SI.second.getIndex() == FI;
611*bdd1243dSDimitry Andric                    }) != PrologEpilogSGPRSpills.end();
612*bdd1243dSDimitry Andric   }
613*bdd1243dSDimitry Andric 
614*bdd1243dSDimitry Andric   const PrologEpilogSGPRSaveRestoreInfo &
615*bdd1243dSDimitry Andric   getPrologEpilogSGPRSaveRestoreInfo(Register Reg) const {
616*bdd1243dSDimitry Andric     auto I = PrologEpilogSGPRSpills.find(Reg);
617*bdd1243dSDimitry Andric     assert(I != PrologEpilogSGPRSpills.end());
618*bdd1243dSDimitry Andric 
619*bdd1243dSDimitry Andric     return I->second;
620*bdd1243dSDimitry Andric   }
621*bdd1243dSDimitry Andric 
622*bdd1243dSDimitry Andric   ArrayRef<SIRegisterInfo::SpilledReg>
623*bdd1243dSDimitry Andric   getPrologEpilogSGPRSpillToVGPRLanes(int FrameIndex) const {
624*bdd1243dSDimitry Andric     auto I = PrologEpilogSGPRSpillToVGPRLanes.find(FrameIndex);
625*bdd1243dSDimitry Andric     return (I == PrologEpilogSGPRSpillToVGPRLanes.end())
626*bdd1243dSDimitry Andric                ? ArrayRef<SIRegisterInfo::SpilledReg>()
627*bdd1243dSDimitry Andric                : ArrayRef(I->second);
628*bdd1243dSDimitry Andric   }
629*bdd1243dSDimitry Andric 
630*bdd1243dSDimitry Andric   void allocateWWMSpill(MachineFunction &MF, Register VGPR, uint64_t Size = 4,
631*bdd1243dSDimitry Andric                         Align Alignment = Align(4));
632*bdd1243dSDimitry Andric 
633*bdd1243dSDimitry Andric   void splitWWMSpillRegisters(
634*bdd1243dSDimitry Andric       MachineFunction &MF,
635*bdd1243dSDimitry Andric       SmallVectorImpl<std::pair<Register, int>> &CalleeSavedRegs,
636*bdd1243dSDimitry Andric       SmallVectorImpl<std::pair<Register, int>> &ScratchRegs) const;
6370b57cec5SDimitry Andric 
6380b57cec5SDimitry Andric   ArrayRef<MCPhysReg> getAGPRSpillVGPRs() const {
6390b57cec5SDimitry Andric     return SpillAGPR;
6400b57cec5SDimitry Andric   }
6410b57cec5SDimitry Andric 
6420b57cec5SDimitry Andric   ArrayRef<MCPhysReg> getVGPRSpillAGPRs() const {
6430b57cec5SDimitry Andric     return SpillVGPR;
6440b57cec5SDimitry Andric   }
6450b57cec5SDimitry Andric 
6460b57cec5SDimitry Andric   MCPhysReg getVGPRToAGPRSpill(int FrameIndex, unsigned Lane) const {
6470b57cec5SDimitry Andric     auto I = VGPRToAGPRSpills.find(FrameIndex);
6480b57cec5SDimitry Andric     return (I == VGPRToAGPRSpills.end()) ? (MCPhysReg)AMDGPU::NoRegister
6490b57cec5SDimitry Andric                                          : I->second.Lanes[Lane];
6500b57cec5SDimitry Andric   }
6510b57cec5SDimitry Andric 
6520eae32dcSDimitry Andric   void setVGPRToAGPRSpillDead(int FrameIndex) {
6530eae32dcSDimitry Andric     auto I = VGPRToAGPRSpills.find(FrameIndex);
6540eae32dcSDimitry Andric     if (I != VGPRToAGPRSpills.end())
6550eae32dcSDimitry Andric       I->second.IsDead = true;
6560eae32dcSDimitry Andric   }
6570eae32dcSDimitry Andric 
658*bdd1243dSDimitry Andric   bool allocateSGPRSpillToVGPRLane(MachineFunction &MF, int FI,
659*bdd1243dSDimitry Andric                                    bool IsPrologEpilog = false);
6600b57cec5SDimitry Andric   bool allocateVGPRSpillToAGPR(MachineFunction &MF, int FI, bool isAGPRtoVGPR);
66181ad6265SDimitry Andric 
66281ad6265SDimitry Andric   /// If \p ResetSGPRSpillStackIDs is true, reset the stack ID from sgpr-spill
66381ad6265SDimitry Andric   /// to the default stack.
66481ad6265SDimitry Andric   bool removeDeadFrameIndices(MachineFrameInfo &MFI,
66581ad6265SDimitry Andric                               bool ResetSGPRSpillStackIDs);
6660b57cec5SDimitry Andric 
667fe6060f1SDimitry Andric   int getScavengeFI(MachineFrameInfo &MFI, const SIRegisterInfo &TRI);
668*bdd1243dSDimitry Andric   std::optional<int> getOptionalScavengeFI() const { return ScavengeFI; }
669fe6060f1SDimitry Andric 
6700b57cec5SDimitry Andric   unsigned getBytesInStackArgArea() const {
6710b57cec5SDimitry Andric     return BytesInStackArgArea;
6720b57cec5SDimitry Andric   }
6730b57cec5SDimitry Andric 
6740b57cec5SDimitry Andric   void setBytesInStackArgArea(unsigned Bytes) {
6750b57cec5SDimitry Andric     BytesInStackArgArea = Bytes;
6760b57cec5SDimitry Andric   }
6770b57cec5SDimitry Andric 
6780b57cec5SDimitry Andric   // Add user SGPRs.
6795ffd83dbSDimitry Andric   Register addPrivateSegmentBuffer(const SIRegisterInfo &TRI);
6805ffd83dbSDimitry Andric   Register addDispatchPtr(const SIRegisterInfo &TRI);
6815ffd83dbSDimitry Andric   Register addQueuePtr(const SIRegisterInfo &TRI);
6825ffd83dbSDimitry Andric   Register addKernargSegmentPtr(const SIRegisterInfo &TRI);
6835ffd83dbSDimitry Andric   Register addDispatchID(const SIRegisterInfo &TRI);
6845ffd83dbSDimitry Andric   Register addFlatScratchInit(const SIRegisterInfo &TRI);
6855ffd83dbSDimitry Andric   Register addImplicitBufferPtr(const SIRegisterInfo &TRI);
686fcaf7f86SDimitry Andric   Register addLDSKernelId();
6870b57cec5SDimitry Andric 
68881ad6265SDimitry Andric   /// Increment user SGPRs used for padding the argument list only.
68981ad6265SDimitry Andric   Register addReservedUserSGPR() {
69081ad6265SDimitry Andric     Register Next = getNextUserSGPR();
69181ad6265SDimitry Andric     ++NumUserSGPRs;
69281ad6265SDimitry Andric     return Next;
69381ad6265SDimitry Andric   }
69481ad6265SDimitry Andric 
6950b57cec5SDimitry Andric   // Add system SGPRs.
6965ffd83dbSDimitry Andric   Register addWorkGroupIDX() {
6970b57cec5SDimitry Andric     ArgInfo.WorkGroupIDX = ArgDescriptor::createRegister(getNextSystemSGPR());
6980b57cec5SDimitry Andric     NumSystemSGPRs += 1;
6990b57cec5SDimitry Andric     return ArgInfo.WorkGroupIDX.getRegister();
7000b57cec5SDimitry Andric   }
7010b57cec5SDimitry Andric 
7025ffd83dbSDimitry Andric   Register addWorkGroupIDY() {
7030b57cec5SDimitry Andric     ArgInfo.WorkGroupIDY = ArgDescriptor::createRegister(getNextSystemSGPR());
7040b57cec5SDimitry Andric     NumSystemSGPRs += 1;
7050b57cec5SDimitry Andric     return ArgInfo.WorkGroupIDY.getRegister();
7060b57cec5SDimitry Andric   }
7070b57cec5SDimitry Andric 
7085ffd83dbSDimitry Andric   Register addWorkGroupIDZ() {
7090b57cec5SDimitry Andric     ArgInfo.WorkGroupIDZ = ArgDescriptor::createRegister(getNextSystemSGPR());
7100b57cec5SDimitry Andric     NumSystemSGPRs += 1;
7110b57cec5SDimitry Andric     return ArgInfo.WorkGroupIDZ.getRegister();
7120b57cec5SDimitry Andric   }
7130b57cec5SDimitry Andric 
7145ffd83dbSDimitry Andric   Register addWorkGroupInfo() {
7150b57cec5SDimitry Andric     ArgInfo.WorkGroupInfo = ArgDescriptor::createRegister(getNextSystemSGPR());
7160b57cec5SDimitry Andric     NumSystemSGPRs += 1;
7170b57cec5SDimitry Andric     return ArgInfo.WorkGroupInfo.getRegister();
7180b57cec5SDimitry Andric   }
7190b57cec5SDimitry Andric 
7200b57cec5SDimitry Andric   // Add special VGPR inputs
7210b57cec5SDimitry Andric   void setWorkItemIDX(ArgDescriptor Arg) {
7220b57cec5SDimitry Andric     ArgInfo.WorkItemIDX = Arg;
7230b57cec5SDimitry Andric   }
7240b57cec5SDimitry Andric 
7250b57cec5SDimitry Andric   void setWorkItemIDY(ArgDescriptor Arg) {
7260b57cec5SDimitry Andric     ArgInfo.WorkItemIDY = Arg;
7270b57cec5SDimitry Andric   }
7280b57cec5SDimitry Andric 
7290b57cec5SDimitry Andric   void setWorkItemIDZ(ArgDescriptor Arg) {
7300b57cec5SDimitry Andric     ArgInfo.WorkItemIDZ = Arg;
7310b57cec5SDimitry Andric   }
7320b57cec5SDimitry Andric 
7335ffd83dbSDimitry Andric   Register addPrivateSegmentWaveByteOffset() {
7340b57cec5SDimitry Andric     ArgInfo.PrivateSegmentWaveByteOffset
7350b57cec5SDimitry Andric       = ArgDescriptor::createRegister(getNextSystemSGPR());
7360b57cec5SDimitry Andric     NumSystemSGPRs += 1;
7370b57cec5SDimitry Andric     return ArgInfo.PrivateSegmentWaveByteOffset.getRegister();
7380b57cec5SDimitry Andric   }
7390b57cec5SDimitry Andric 
7405ffd83dbSDimitry Andric   void setPrivateSegmentWaveByteOffset(Register Reg) {
7410b57cec5SDimitry Andric     ArgInfo.PrivateSegmentWaveByteOffset = ArgDescriptor::createRegister(Reg);
7420b57cec5SDimitry Andric   }
7430b57cec5SDimitry Andric 
7440b57cec5SDimitry Andric   bool hasPrivateSegmentBuffer() const {
7450b57cec5SDimitry Andric     return PrivateSegmentBuffer;
7460b57cec5SDimitry Andric   }
7470b57cec5SDimitry Andric 
7480b57cec5SDimitry Andric   bool hasDispatchPtr() const {
7490b57cec5SDimitry Andric     return DispatchPtr;
7500b57cec5SDimitry Andric   }
7510b57cec5SDimitry Andric 
7520b57cec5SDimitry Andric   bool hasQueuePtr() const {
7530b57cec5SDimitry Andric     return QueuePtr;
7540b57cec5SDimitry Andric   }
7550b57cec5SDimitry Andric 
7560b57cec5SDimitry Andric   bool hasKernargSegmentPtr() const {
7570b57cec5SDimitry Andric     return KernargSegmentPtr;
7580b57cec5SDimitry Andric   }
7590b57cec5SDimitry Andric 
7600b57cec5SDimitry Andric   bool hasDispatchID() const {
7610b57cec5SDimitry Andric     return DispatchID;
7620b57cec5SDimitry Andric   }
7630b57cec5SDimitry Andric 
7640b57cec5SDimitry Andric   bool hasFlatScratchInit() const {
7650b57cec5SDimitry Andric     return FlatScratchInit;
7660b57cec5SDimitry Andric   }
7670b57cec5SDimitry Andric 
7680b57cec5SDimitry Andric   bool hasWorkGroupIDX() const {
7690b57cec5SDimitry Andric     return WorkGroupIDX;
7700b57cec5SDimitry Andric   }
7710b57cec5SDimitry Andric 
7720b57cec5SDimitry Andric   bool hasWorkGroupIDY() const {
7730b57cec5SDimitry Andric     return WorkGroupIDY;
7740b57cec5SDimitry Andric   }
7750b57cec5SDimitry Andric 
7760b57cec5SDimitry Andric   bool hasWorkGroupIDZ() const {
7770b57cec5SDimitry Andric     return WorkGroupIDZ;
7780b57cec5SDimitry Andric   }
7790b57cec5SDimitry Andric 
7800b57cec5SDimitry Andric   bool hasWorkGroupInfo() const {
7810b57cec5SDimitry Andric     return WorkGroupInfo;
7820b57cec5SDimitry Andric   }
7830b57cec5SDimitry Andric 
784fcaf7f86SDimitry Andric   bool hasLDSKernelId() const { return LDSKernelId; }
785fcaf7f86SDimitry Andric 
7860b57cec5SDimitry Andric   bool hasPrivateSegmentWaveByteOffset() const {
7870b57cec5SDimitry Andric     return PrivateSegmentWaveByteOffset;
7880b57cec5SDimitry Andric   }
7890b57cec5SDimitry Andric 
7900b57cec5SDimitry Andric   bool hasWorkItemIDX() const {
7910b57cec5SDimitry Andric     return WorkItemIDX;
7920b57cec5SDimitry Andric   }
7930b57cec5SDimitry Andric 
7940b57cec5SDimitry Andric   bool hasWorkItemIDY() const {
7950b57cec5SDimitry Andric     return WorkItemIDY;
7960b57cec5SDimitry Andric   }
7970b57cec5SDimitry Andric 
7980b57cec5SDimitry Andric   bool hasWorkItemIDZ() const {
7990b57cec5SDimitry Andric     return WorkItemIDZ;
8000b57cec5SDimitry Andric   }
8010b57cec5SDimitry Andric 
8020b57cec5SDimitry Andric   bool hasImplicitArgPtr() const {
8030b57cec5SDimitry Andric     return ImplicitArgPtr;
8040b57cec5SDimitry Andric   }
8050b57cec5SDimitry Andric 
8060b57cec5SDimitry Andric   bool hasImplicitBufferPtr() const {
8070b57cec5SDimitry Andric     return ImplicitBufferPtr;
8080b57cec5SDimitry Andric   }
8090b57cec5SDimitry Andric 
8100b57cec5SDimitry Andric   AMDGPUFunctionArgInfo &getArgInfo() {
8110b57cec5SDimitry Andric     return ArgInfo;
8120b57cec5SDimitry Andric   }
8130b57cec5SDimitry Andric 
8140b57cec5SDimitry Andric   const AMDGPUFunctionArgInfo &getArgInfo() const {
8150b57cec5SDimitry Andric     return ArgInfo;
8160b57cec5SDimitry Andric   }
8170b57cec5SDimitry Andric 
8185ffd83dbSDimitry Andric   std::tuple<const ArgDescriptor *, const TargetRegisterClass *, LLT>
8190b57cec5SDimitry Andric   getPreloadedValue(AMDGPUFunctionArgInfo::PreloadedValue Value) const {
8200b57cec5SDimitry Andric     return ArgInfo.getPreloadedValue(Value);
8210b57cec5SDimitry Andric   }
8220b57cec5SDimitry Andric 
823e8d8bef9SDimitry Andric   MCRegister getPreloadedReg(AMDGPUFunctionArgInfo::PreloadedValue Value) const {
8245ffd83dbSDimitry Andric     auto Arg = std::get<0>(ArgInfo.getPreloadedValue(Value));
825e8d8bef9SDimitry Andric     return Arg ? Arg->getRegister() : MCRegister();
8260b57cec5SDimitry Andric   }
8270b57cec5SDimitry Andric 
8280b57cec5SDimitry Andric   unsigned getGITPtrHigh() const {
8290b57cec5SDimitry Andric     return GITPtrHigh;
8300b57cec5SDimitry Andric   }
8310b57cec5SDimitry Andric 
8325ffd83dbSDimitry Andric   Register getGITPtrLoReg(const MachineFunction &MF) const;
8335ffd83dbSDimitry Andric 
8348bcb0991SDimitry Andric   uint32_t get32BitAddressHighBits() const {
8350b57cec5SDimitry Andric     return HighBitsOf32BitAddress;
8360b57cec5SDimitry Andric   }
8370b57cec5SDimitry Andric 
8380b57cec5SDimitry Andric   unsigned getNumUserSGPRs() const {
8390b57cec5SDimitry Andric     return NumUserSGPRs;
8400b57cec5SDimitry Andric   }
8410b57cec5SDimitry Andric 
8420b57cec5SDimitry Andric   unsigned getNumPreloadedSGPRs() const {
8430b57cec5SDimitry Andric     return NumUserSGPRs + NumSystemSGPRs;
8440b57cec5SDimitry Andric   }
8450b57cec5SDimitry Andric 
8465ffd83dbSDimitry Andric   Register getPrivateSegmentWaveByteOffsetSystemSGPR() const {
8470b57cec5SDimitry Andric     return ArgInfo.PrivateSegmentWaveByteOffset.getRegister();
8480b57cec5SDimitry Andric   }
8490b57cec5SDimitry Andric 
8500b57cec5SDimitry Andric   /// Returns the physical register reserved for use as the resource
8510b57cec5SDimitry Andric   /// descriptor for scratch accesses.
8525ffd83dbSDimitry Andric   Register getScratchRSrcReg() const {
8530b57cec5SDimitry Andric     return ScratchRSrcReg;
8540b57cec5SDimitry Andric   }
8550b57cec5SDimitry Andric 
8565ffd83dbSDimitry Andric   void setScratchRSrcReg(Register Reg) {
8570b57cec5SDimitry Andric     assert(Reg != 0 && "Should never be unset");
8580b57cec5SDimitry Andric     ScratchRSrcReg = Reg;
8590b57cec5SDimitry Andric   }
8600b57cec5SDimitry Andric 
8615ffd83dbSDimitry Andric   Register getFrameOffsetReg() const {
8620b57cec5SDimitry Andric     return FrameOffsetReg;
8630b57cec5SDimitry Andric   }
8640b57cec5SDimitry Andric 
8655ffd83dbSDimitry Andric   void setFrameOffsetReg(Register Reg) {
8660b57cec5SDimitry Andric     assert(Reg != 0 && "Should never be unset");
8670b57cec5SDimitry Andric     FrameOffsetReg = Reg;
8680b57cec5SDimitry Andric   }
8690b57cec5SDimitry Andric 
8705ffd83dbSDimitry Andric   void setStackPtrOffsetReg(Register Reg) {
8710b57cec5SDimitry Andric     assert(Reg != 0 && "Should never be unset");
8720b57cec5SDimitry Andric     StackPtrOffsetReg = Reg;
8730b57cec5SDimitry Andric   }
8740b57cec5SDimitry Andric 
8750b57cec5SDimitry Andric   // Note the unset value for this is AMDGPU::SP_REG rather than
8760b57cec5SDimitry Andric   // NoRegister. This is mostly a workaround for MIR tests where state that
8770b57cec5SDimitry Andric   // can't be directly computed from the function is not preserved in serialized
8780b57cec5SDimitry Andric   // MIR.
8795ffd83dbSDimitry Andric   Register getStackPtrOffsetReg() const {
8800b57cec5SDimitry Andric     return StackPtrOffsetReg;
8810b57cec5SDimitry Andric   }
8820b57cec5SDimitry Andric 
8835ffd83dbSDimitry Andric   Register getQueuePtrUserSGPR() const {
8840b57cec5SDimitry Andric     return ArgInfo.QueuePtr.getRegister();
8850b57cec5SDimitry Andric   }
8860b57cec5SDimitry Andric 
8875ffd83dbSDimitry Andric   Register getImplicitBufferPtrUserSGPR() const {
8880b57cec5SDimitry Andric     return ArgInfo.ImplicitBufferPtr.getRegister();
8890b57cec5SDimitry Andric   }
8900b57cec5SDimitry Andric 
8910b57cec5SDimitry Andric   bool hasSpilledSGPRs() const {
8920b57cec5SDimitry Andric     return HasSpilledSGPRs;
8930b57cec5SDimitry Andric   }
8940b57cec5SDimitry Andric 
8950b57cec5SDimitry Andric   void setHasSpilledSGPRs(bool Spill = true) {
8960b57cec5SDimitry Andric     HasSpilledSGPRs = Spill;
8970b57cec5SDimitry Andric   }
8980b57cec5SDimitry Andric 
8990b57cec5SDimitry Andric   bool hasSpilledVGPRs() const {
9000b57cec5SDimitry Andric     return HasSpilledVGPRs;
9010b57cec5SDimitry Andric   }
9020b57cec5SDimitry Andric 
9030b57cec5SDimitry Andric   void setHasSpilledVGPRs(bool Spill = true) {
9040b57cec5SDimitry Andric     HasSpilledVGPRs = Spill;
9050b57cec5SDimitry Andric   }
9060b57cec5SDimitry Andric 
9070b57cec5SDimitry Andric   bool hasNonSpillStackObjects() const {
9080b57cec5SDimitry Andric     return HasNonSpillStackObjects;
9090b57cec5SDimitry Andric   }
9100b57cec5SDimitry Andric 
9110b57cec5SDimitry Andric   void setHasNonSpillStackObjects(bool StackObject = true) {
9120b57cec5SDimitry Andric     HasNonSpillStackObjects = StackObject;
9130b57cec5SDimitry Andric   }
9140b57cec5SDimitry Andric 
9150b57cec5SDimitry Andric   bool isStackRealigned() const {
9160b57cec5SDimitry Andric     return IsStackRealigned;
9170b57cec5SDimitry Andric   }
9180b57cec5SDimitry Andric 
9190b57cec5SDimitry Andric   void setIsStackRealigned(bool Realigned = true) {
9200b57cec5SDimitry Andric     IsStackRealigned = Realigned;
9210b57cec5SDimitry Andric   }
9220b57cec5SDimitry Andric 
9230b57cec5SDimitry Andric   unsigned getNumSpilledSGPRs() const {
9240b57cec5SDimitry Andric     return NumSpilledSGPRs;
9250b57cec5SDimitry Andric   }
9260b57cec5SDimitry Andric 
9270b57cec5SDimitry Andric   unsigned getNumSpilledVGPRs() const {
9280b57cec5SDimitry Andric     return NumSpilledVGPRs;
9290b57cec5SDimitry Andric   }
9300b57cec5SDimitry Andric 
9310b57cec5SDimitry Andric   void addToSpilledSGPRs(unsigned num) {
9320b57cec5SDimitry Andric     NumSpilledSGPRs += num;
9330b57cec5SDimitry Andric   }
9340b57cec5SDimitry Andric 
9350b57cec5SDimitry Andric   void addToSpilledVGPRs(unsigned num) {
9360b57cec5SDimitry Andric     NumSpilledVGPRs += num;
9370b57cec5SDimitry Andric   }
9380b57cec5SDimitry Andric 
9390b57cec5SDimitry Andric   unsigned getPSInputAddr() const {
9400b57cec5SDimitry Andric     return PSInputAddr;
9410b57cec5SDimitry Andric   }
9420b57cec5SDimitry Andric 
9430b57cec5SDimitry Andric   unsigned getPSInputEnable() const {
9440b57cec5SDimitry Andric     return PSInputEnable;
9450b57cec5SDimitry Andric   }
9460b57cec5SDimitry Andric 
9470b57cec5SDimitry Andric   bool isPSInputAllocated(unsigned Index) const {
9480b57cec5SDimitry Andric     return PSInputAddr & (1 << Index);
9490b57cec5SDimitry Andric   }
9500b57cec5SDimitry Andric 
9510b57cec5SDimitry Andric   void markPSInputAllocated(unsigned Index) {
9520b57cec5SDimitry Andric     PSInputAddr |= 1 << Index;
9530b57cec5SDimitry Andric   }
9540b57cec5SDimitry Andric 
9550b57cec5SDimitry Andric   void markPSInputEnabled(unsigned Index) {
9560b57cec5SDimitry Andric     PSInputEnable |= 1 << Index;
9570b57cec5SDimitry Andric   }
9580b57cec5SDimitry Andric 
9590b57cec5SDimitry Andric   bool returnsVoid() const {
9600b57cec5SDimitry Andric     return ReturnsVoid;
9610b57cec5SDimitry Andric   }
9620b57cec5SDimitry Andric 
9630b57cec5SDimitry Andric   void setIfReturnsVoid(bool Value) {
9640b57cec5SDimitry Andric     ReturnsVoid = Value;
9650b57cec5SDimitry Andric   }
9660b57cec5SDimitry Andric 
9670b57cec5SDimitry Andric   /// \returns A pair of default/requested minimum/maximum flat work group sizes
9680b57cec5SDimitry Andric   /// for this function.
9690b57cec5SDimitry Andric   std::pair<unsigned, unsigned> getFlatWorkGroupSizes() const {
9700b57cec5SDimitry Andric     return FlatWorkGroupSizes;
9710b57cec5SDimitry Andric   }
9720b57cec5SDimitry Andric 
9730b57cec5SDimitry Andric   /// \returns Default/requested minimum flat work group size for this function.
9740b57cec5SDimitry Andric   unsigned getMinFlatWorkGroupSize() const {
9750b57cec5SDimitry Andric     return FlatWorkGroupSizes.first;
9760b57cec5SDimitry Andric   }
9770b57cec5SDimitry Andric 
9780b57cec5SDimitry Andric   /// \returns Default/requested maximum flat work group size for this function.
9790b57cec5SDimitry Andric   unsigned getMaxFlatWorkGroupSize() const {
9800b57cec5SDimitry Andric     return FlatWorkGroupSizes.second;
9810b57cec5SDimitry Andric   }
9820b57cec5SDimitry Andric 
9830b57cec5SDimitry Andric   /// \returns A pair of default/requested minimum/maximum number of waves per
9840b57cec5SDimitry Andric   /// execution unit.
9850b57cec5SDimitry Andric   std::pair<unsigned, unsigned> getWavesPerEU() const {
9860b57cec5SDimitry Andric     return WavesPerEU;
9870b57cec5SDimitry Andric   }
9880b57cec5SDimitry Andric 
9890b57cec5SDimitry Andric   /// \returns Default/requested minimum number of waves per execution unit.
9900b57cec5SDimitry Andric   unsigned getMinWavesPerEU() const {
9910b57cec5SDimitry Andric     return WavesPerEU.first;
9920b57cec5SDimitry Andric   }
9930b57cec5SDimitry Andric 
9940b57cec5SDimitry Andric   /// \returns Default/requested maximum number of waves per execution unit.
9950b57cec5SDimitry Andric   unsigned getMaxWavesPerEU() const {
9960b57cec5SDimitry Andric     return WavesPerEU.second;
9970b57cec5SDimitry Andric   }
9980b57cec5SDimitry Andric 
9990b57cec5SDimitry Andric   /// \returns SGPR used for \p Dim's work group ID.
10005ffd83dbSDimitry Andric   Register getWorkGroupIDSGPR(unsigned Dim) const {
10010b57cec5SDimitry Andric     switch (Dim) {
10020b57cec5SDimitry Andric     case 0:
10030b57cec5SDimitry Andric       assert(hasWorkGroupIDX());
10040b57cec5SDimitry Andric       return ArgInfo.WorkGroupIDX.getRegister();
10050b57cec5SDimitry Andric     case 1:
10060b57cec5SDimitry Andric       assert(hasWorkGroupIDY());
10070b57cec5SDimitry Andric       return ArgInfo.WorkGroupIDY.getRegister();
10080b57cec5SDimitry Andric     case 2:
10090b57cec5SDimitry Andric       assert(hasWorkGroupIDZ());
10100b57cec5SDimitry Andric       return ArgInfo.WorkGroupIDZ.getRegister();
10110b57cec5SDimitry Andric     }
10120b57cec5SDimitry Andric     llvm_unreachable("unexpected dimension");
10130b57cec5SDimitry Andric   }
10140b57cec5SDimitry Andric 
101581ad6265SDimitry Andric   const AMDGPUGWSResourcePseudoSourceValue *
101681ad6265SDimitry Andric   getGWSPSV(const AMDGPUTargetMachine &TM) {
101781ad6265SDimitry Andric     return &GWSResourcePSV;
10180b57cec5SDimitry Andric   }
10190b57cec5SDimitry Andric 
10200b57cec5SDimitry Andric   unsigned getOccupancy() const {
10210b57cec5SDimitry Andric     return Occupancy;
10220b57cec5SDimitry Andric   }
10230b57cec5SDimitry Andric 
10240b57cec5SDimitry Andric   unsigned getMinAllowedOccupancy() const {
10250b57cec5SDimitry Andric     if (!isMemoryBound() && !needsWaveLimiter())
10260b57cec5SDimitry Andric       return Occupancy;
10270b57cec5SDimitry Andric     return (Occupancy < 4) ? Occupancy : 4;
10280b57cec5SDimitry Andric   }
10290b57cec5SDimitry Andric 
10300b57cec5SDimitry Andric   void limitOccupancy(const MachineFunction &MF);
10310b57cec5SDimitry Andric 
10320b57cec5SDimitry Andric   void limitOccupancy(unsigned Limit) {
10330b57cec5SDimitry Andric     if (Occupancy > Limit)
10340b57cec5SDimitry Andric       Occupancy = Limit;
10350b57cec5SDimitry Andric   }
10360b57cec5SDimitry Andric 
10370b57cec5SDimitry Andric   void increaseOccupancy(const MachineFunction &MF, unsigned Limit) {
10380b57cec5SDimitry Andric     if (Occupancy < Limit)
10390b57cec5SDimitry Andric       Occupancy = Limit;
10400b57cec5SDimitry Andric     limitOccupancy(MF);
10410b57cec5SDimitry Andric   }
1042349cc55cSDimitry Andric 
104381ad6265SDimitry Andric   bool mayNeedAGPRs() const {
104481ad6265SDimitry Andric     return MayNeedAGPRs;
104581ad6265SDimitry Andric   }
104681ad6265SDimitry Andric 
104781ad6265SDimitry Andric   // \returns true if a function has a use of AGPRs via inline asm or
104881ad6265SDimitry Andric   // has a call which may use it.
1049*bdd1243dSDimitry Andric   bool mayUseAGPRs(const Function &F) const;
105081ad6265SDimitry Andric 
1051349cc55cSDimitry Andric   // \returns true if a function needs or may need AGPRs.
1052349cc55cSDimitry Andric   bool usesAGPRs(const MachineFunction &MF) const;
10530b57cec5SDimitry Andric };
10540b57cec5SDimitry Andric 
10550b57cec5SDimitry Andric } // end namespace llvm
10560b57cec5SDimitry Andric 
10570b57cec5SDimitry Andric #endif // LLVM_LIB_TARGET_AMDGPU_SIMACHINEFUNCTIONINFO_H
1058