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" 195f757f3fSDimitry Andric #include "GCNSubtarget.h" 200b57cec5SDimitry Andric #include "MCTargetDesc/AMDGPUMCTargetDesc.h" 210b57cec5SDimitry Andric #include "SIInstrInfo.h" 2206c3fb27SDimitry Andric #include "SIModeRegisterDefaults.h" 2381ad6265SDimitry Andric #include "llvm/ADT/SetVector.h" 245f757f3fSDimitry Andric #include "llvm/ADT/SmallVector.h" 250b57cec5SDimitry Andric #include "llvm/CodeGen/MIRYamlMapping.h" 260b57cec5SDimitry Andric #include "llvm/CodeGen/PseudoSourceValue.h" 27e8d8bef9SDimitry Andric #include "llvm/Support/raw_ostream.h" 28bdd1243dSDimitry Andric #include <optional> 290b57cec5SDimitry Andric 300b57cec5SDimitry Andric namespace llvm { 310b57cec5SDimitry Andric 320b57cec5SDimitry Andric class MachineFrameInfo; 330b57cec5SDimitry Andric class MachineFunction; 34e8d8bef9SDimitry Andric class SIMachineFunctionInfo; 35e8d8bef9SDimitry Andric class SIRegisterInfo; 36349cc55cSDimitry Andric class TargetRegisterClass; 370b57cec5SDimitry Andric 380b57cec5SDimitry Andric class AMDGPUPseudoSourceValue : public PseudoSourceValue { 390b57cec5SDimitry Andric public: 400b57cec5SDimitry Andric enum AMDGPUPSVKind : unsigned { 41bdd1243dSDimitry Andric PSVImage = PseudoSourceValue::TargetCustom, 420b57cec5SDimitry Andric GWSResource 430b57cec5SDimitry Andric }; 440b57cec5SDimitry Andric 450b57cec5SDimitry Andric protected: 4681ad6265SDimitry Andric AMDGPUPseudoSourceValue(unsigned Kind, const AMDGPUTargetMachine &TM) 4781ad6265SDimitry Andric : PseudoSourceValue(Kind, TM) {} 480b57cec5SDimitry Andric 490b57cec5SDimitry Andric public: 500b57cec5SDimitry Andric bool isConstant(const MachineFrameInfo *) const override { 510b57cec5SDimitry Andric // This should probably be true for most images, but we will start by being 520b57cec5SDimitry Andric // conservative. 530b57cec5SDimitry Andric return false; 540b57cec5SDimitry Andric } 550b57cec5SDimitry Andric 560b57cec5SDimitry Andric bool isAliased(const MachineFrameInfo *) const override { 570b57cec5SDimitry Andric return true; 580b57cec5SDimitry Andric } 590b57cec5SDimitry Andric 600b57cec5SDimitry Andric bool mayAlias(const MachineFrameInfo *) const override { 610b57cec5SDimitry Andric return true; 620b57cec5SDimitry Andric } 630b57cec5SDimitry Andric }; 640b57cec5SDimitry Andric 650b57cec5SDimitry Andric class AMDGPUGWSResourcePseudoSourceValue final : public AMDGPUPseudoSourceValue { 660b57cec5SDimitry Andric public: 6781ad6265SDimitry Andric explicit AMDGPUGWSResourcePseudoSourceValue(const AMDGPUTargetMachine &TM) 6881ad6265SDimitry Andric : AMDGPUPseudoSourceValue(GWSResource, TM) {} 690b57cec5SDimitry Andric 700b57cec5SDimitry Andric static bool classof(const PseudoSourceValue *V) { 710b57cec5SDimitry Andric return V->kind() == GWSResource; 720b57cec5SDimitry Andric } 730b57cec5SDimitry Andric 740b57cec5SDimitry Andric // These are inaccessible memory from IR. 750b57cec5SDimitry Andric bool isAliased(const MachineFrameInfo *) const override { 760b57cec5SDimitry Andric return false; 770b57cec5SDimitry Andric } 780b57cec5SDimitry Andric 790b57cec5SDimitry Andric // These are inaccessible memory from IR. 800b57cec5SDimitry Andric bool mayAlias(const MachineFrameInfo *) const override { 810b57cec5SDimitry Andric return false; 820b57cec5SDimitry Andric } 830b57cec5SDimitry Andric 840b57cec5SDimitry Andric void printCustom(raw_ostream &OS) const override { 850b57cec5SDimitry Andric OS << "GWSResource"; 860b57cec5SDimitry Andric } 870b57cec5SDimitry Andric }; 880b57cec5SDimitry Andric 890b57cec5SDimitry Andric namespace yaml { 900b57cec5SDimitry Andric 910b57cec5SDimitry Andric struct SIArgument { 920b57cec5SDimitry Andric bool IsRegister; 930b57cec5SDimitry Andric union { 940b57cec5SDimitry Andric StringValue RegisterName; 950b57cec5SDimitry Andric unsigned StackOffset; 960b57cec5SDimitry Andric }; 97bdd1243dSDimitry Andric std::optional<unsigned> Mask; 980b57cec5SDimitry Andric 990b57cec5SDimitry Andric // Default constructor, which creates a stack argument. 1000b57cec5SDimitry Andric SIArgument() : IsRegister(false), StackOffset(0) {} 1010b57cec5SDimitry Andric SIArgument(const SIArgument &Other) { 1020b57cec5SDimitry Andric IsRegister = Other.IsRegister; 1030b57cec5SDimitry Andric if (IsRegister) { 1040b57cec5SDimitry Andric ::new ((void *)std::addressof(RegisterName)) 1050b57cec5SDimitry Andric StringValue(Other.RegisterName); 1060b57cec5SDimitry Andric } else 1070b57cec5SDimitry Andric StackOffset = Other.StackOffset; 1080b57cec5SDimitry Andric Mask = Other.Mask; 1090b57cec5SDimitry Andric } 1100b57cec5SDimitry Andric SIArgument &operator=(const SIArgument &Other) { 1110b57cec5SDimitry Andric IsRegister = Other.IsRegister; 1120b57cec5SDimitry Andric if (IsRegister) { 1130b57cec5SDimitry Andric ::new ((void *)std::addressof(RegisterName)) 1140b57cec5SDimitry Andric StringValue(Other.RegisterName); 1150b57cec5SDimitry Andric } else 1160b57cec5SDimitry Andric StackOffset = Other.StackOffset; 1170b57cec5SDimitry Andric Mask = Other.Mask; 1180b57cec5SDimitry Andric return *this; 1190b57cec5SDimitry Andric } 1200b57cec5SDimitry Andric ~SIArgument() { 1210b57cec5SDimitry Andric if (IsRegister) 1220b57cec5SDimitry Andric RegisterName.~StringValue(); 1230b57cec5SDimitry Andric } 1240b57cec5SDimitry Andric 1250b57cec5SDimitry Andric // Helper to create a register or stack argument. 1260b57cec5SDimitry Andric static inline SIArgument createArgument(bool IsReg) { 1270b57cec5SDimitry Andric if (IsReg) 1280b57cec5SDimitry Andric return SIArgument(IsReg); 1290b57cec5SDimitry Andric return SIArgument(); 1300b57cec5SDimitry Andric } 1310b57cec5SDimitry Andric 1320b57cec5SDimitry Andric private: 1330b57cec5SDimitry Andric // Construct a register argument. 1340b57cec5SDimitry Andric SIArgument(bool) : IsRegister(true), RegisterName() {} 1350b57cec5SDimitry Andric }; 1360b57cec5SDimitry Andric 1370b57cec5SDimitry Andric template <> struct MappingTraits<SIArgument> { 1380b57cec5SDimitry Andric static void mapping(IO &YamlIO, SIArgument &A) { 1390b57cec5SDimitry Andric if (YamlIO.outputting()) { 1400b57cec5SDimitry Andric if (A.IsRegister) 1410b57cec5SDimitry Andric YamlIO.mapRequired("reg", A.RegisterName); 1420b57cec5SDimitry Andric else 1430b57cec5SDimitry Andric YamlIO.mapRequired("offset", A.StackOffset); 1440b57cec5SDimitry Andric } else { 1450b57cec5SDimitry Andric auto Keys = YamlIO.keys(); 1460b57cec5SDimitry Andric if (is_contained(Keys, "reg")) { 1470b57cec5SDimitry Andric A = SIArgument::createArgument(true); 1480b57cec5SDimitry Andric YamlIO.mapRequired("reg", A.RegisterName); 1490b57cec5SDimitry Andric } else if (is_contained(Keys, "offset")) 1500b57cec5SDimitry Andric YamlIO.mapRequired("offset", A.StackOffset); 1510b57cec5SDimitry Andric else 1520b57cec5SDimitry Andric YamlIO.setError("missing required key 'reg' or 'offset'"); 1530b57cec5SDimitry Andric } 1540b57cec5SDimitry Andric YamlIO.mapOptional("mask", A.Mask); 1550b57cec5SDimitry Andric } 1560b57cec5SDimitry Andric static const bool flow = true; 1570b57cec5SDimitry Andric }; 1580b57cec5SDimitry Andric 1590b57cec5SDimitry Andric struct SIArgumentInfo { 160bdd1243dSDimitry Andric std::optional<SIArgument> PrivateSegmentBuffer; 161bdd1243dSDimitry Andric std::optional<SIArgument> DispatchPtr; 162bdd1243dSDimitry Andric std::optional<SIArgument> QueuePtr; 163bdd1243dSDimitry Andric std::optional<SIArgument> KernargSegmentPtr; 164bdd1243dSDimitry Andric std::optional<SIArgument> DispatchID; 165bdd1243dSDimitry Andric std::optional<SIArgument> FlatScratchInit; 166bdd1243dSDimitry Andric std::optional<SIArgument> PrivateSegmentSize; 1670b57cec5SDimitry Andric 168bdd1243dSDimitry Andric std::optional<SIArgument> WorkGroupIDX; 169bdd1243dSDimitry Andric std::optional<SIArgument> WorkGroupIDY; 170bdd1243dSDimitry Andric std::optional<SIArgument> WorkGroupIDZ; 171bdd1243dSDimitry Andric std::optional<SIArgument> WorkGroupInfo; 172bdd1243dSDimitry Andric std::optional<SIArgument> LDSKernelId; 173bdd1243dSDimitry Andric std::optional<SIArgument> PrivateSegmentWaveByteOffset; 1740b57cec5SDimitry Andric 175bdd1243dSDimitry Andric std::optional<SIArgument> ImplicitArgPtr; 176bdd1243dSDimitry Andric std::optional<SIArgument> ImplicitBufferPtr; 1770b57cec5SDimitry Andric 178bdd1243dSDimitry Andric std::optional<SIArgument> WorkItemIDX; 179bdd1243dSDimitry Andric std::optional<SIArgument> WorkItemIDY; 180bdd1243dSDimitry Andric std::optional<SIArgument> WorkItemIDZ; 1810b57cec5SDimitry Andric }; 1820b57cec5SDimitry Andric 1830b57cec5SDimitry Andric template <> struct MappingTraits<SIArgumentInfo> { 1840b57cec5SDimitry Andric static void mapping(IO &YamlIO, SIArgumentInfo &AI) { 1850b57cec5SDimitry Andric YamlIO.mapOptional("privateSegmentBuffer", AI.PrivateSegmentBuffer); 1860b57cec5SDimitry Andric YamlIO.mapOptional("dispatchPtr", AI.DispatchPtr); 1870b57cec5SDimitry Andric YamlIO.mapOptional("queuePtr", AI.QueuePtr); 1880b57cec5SDimitry Andric YamlIO.mapOptional("kernargSegmentPtr", AI.KernargSegmentPtr); 1890b57cec5SDimitry Andric YamlIO.mapOptional("dispatchID", AI.DispatchID); 1900b57cec5SDimitry Andric YamlIO.mapOptional("flatScratchInit", AI.FlatScratchInit); 1910b57cec5SDimitry Andric YamlIO.mapOptional("privateSegmentSize", AI.PrivateSegmentSize); 1920b57cec5SDimitry Andric 1930b57cec5SDimitry Andric YamlIO.mapOptional("workGroupIDX", AI.WorkGroupIDX); 1940b57cec5SDimitry Andric YamlIO.mapOptional("workGroupIDY", AI.WorkGroupIDY); 1950b57cec5SDimitry Andric YamlIO.mapOptional("workGroupIDZ", AI.WorkGroupIDZ); 1960b57cec5SDimitry Andric YamlIO.mapOptional("workGroupInfo", AI.WorkGroupInfo); 197fcaf7f86SDimitry Andric YamlIO.mapOptional("LDSKernelId", AI.LDSKernelId); 1980b57cec5SDimitry Andric YamlIO.mapOptional("privateSegmentWaveByteOffset", 1990b57cec5SDimitry Andric AI.PrivateSegmentWaveByteOffset); 2000b57cec5SDimitry Andric 2010b57cec5SDimitry Andric YamlIO.mapOptional("implicitArgPtr", AI.ImplicitArgPtr); 2020b57cec5SDimitry Andric YamlIO.mapOptional("implicitBufferPtr", AI.ImplicitBufferPtr); 2030b57cec5SDimitry Andric 2040b57cec5SDimitry Andric YamlIO.mapOptional("workItemIDX", AI.WorkItemIDX); 2050b57cec5SDimitry Andric YamlIO.mapOptional("workItemIDY", AI.WorkItemIDY); 2060b57cec5SDimitry Andric YamlIO.mapOptional("workItemIDZ", AI.WorkItemIDZ); 2070b57cec5SDimitry Andric } 2080b57cec5SDimitry Andric }; 2090b57cec5SDimitry Andric 2100b57cec5SDimitry Andric // Default to default mode for default calling convention. 2110b57cec5SDimitry Andric struct SIMode { 2120b57cec5SDimitry Andric bool IEEE = true; 2130b57cec5SDimitry Andric bool DX10Clamp = true; 2145ffd83dbSDimitry Andric bool FP32InputDenormals = true; 2155ffd83dbSDimitry Andric bool FP32OutputDenormals = true; 2165ffd83dbSDimitry Andric bool FP64FP16InputDenormals = true; 2175ffd83dbSDimitry Andric bool FP64FP16OutputDenormals = true; 2180b57cec5SDimitry Andric 2190b57cec5SDimitry Andric SIMode() = default; 2200b57cec5SDimitry Andric 22106c3fb27SDimitry Andric SIMode(const SIModeRegisterDefaults &Mode) { 2220b57cec5SDimitry Andric IEEE = Mode.IEEE; 2230b57cec5SDimitry Andric DX10Clamp = Mode.DX10Clamp; 224bdd1243dSDimitry Andric FP32InputDenormals = Mode.FP32Denormals.Input != DenormalMode::PreserveSign; 225bdd1243dSDimitry Andric FP32OutputDenormals = 226bdd1243dSDimitry Andric Mode.FP32Denormals.Output != DenormalMode::PreserveSign; 227bdd1243dSDimitry Andric FP64FP16InputDenormals = 228bdd1243dSDimitry Andric Mode.FP64FP16Denormals.Input != DenormalMode::PreserveSign; 229bdd1243dSDimitry Andric FP64FP16OutputDenormals = 230bdd1243dSDimitry Andric Mode.FP64FP16Denormals.Output != DenormalMode::PreserveSign; 2310b57cec5SDimitry Andric } 2320b57cec5SDimitry Andric 2330b57cec5SDimitry Andric bool operator ==(const SIMode Other) const { 234480093f4SDimitry Andric return IEEE == Other.IEEE && 235480093f4SDimitry Andric DX10Clamp == Other.DX10Clamp && 2365ffd83dbSDimitry Andric FP32InputDenormals == Other.FP32InputDenormals && 2375ffd83dbSDimitry Andric FP32OutputDenormals == Other.FP32OutputDenormals && 2385ffd83dbSDimitry Andric FP64FP16InputDenormals == Other.FP64FP16InputDenormals && 2395ffd83dbSDimitry Andric FP64FP16OutputDenormals == Other.FP64FP16OutputDenormals; 2400b57cec5SDimitry Andric } 2410b57cec5SDimitry Andric }; 2420b57cec5SDimitry Andric 2430b57cec5SDimitry Andric template <> struct MappingTraits<SIMode> { 2440b57cec5SDimitry Andric static void mapping(IO &YamlIO, SIMode &Mode) { 2450b57cec5SDimitry Andric YamlIO.mapOptional("ieee", Mode.IEEE, true); 2460b57cec5SDimitry Andric YamlIO.mapOptional("dx10-clamp", Mode.DX10Clamp, true); 2475ffd83dbSDimitry Andric YamlIO.mapOptional("fp32-input-denormals", Mode.FP32InputDenormals, true); 2485ffd83dbSDimitry Andric YamlIO.mapOptional("fp32-output-denormals", Mode.FP32OutputDenormals, true); 2495ffd83dbSDimitry Andric YamlIO.mapOptional("fp64-fp16-input-denormals", Mode.FP64FP16InputDenormals, true); 2505ffd83dbSDimitry Andric YamlIO.mapOptional("fp64-fp16-output-denormals", Mode.FP64FP16OutputDenormals, true); 2510b57cec5SDimitry Andric } 2520b57cec5SDimitry Andric }; 2530b57cec5SDimitry Andric 2540b57cec5SDimitry Andric struct SIMachineFunctionInfo final : public yaml::MachineFunctionInfo { 2550b57cec5SDimitry Andric uint64_t ExplicitKernArgSize = 0; 25681ad6265SDimitry Andric Align MaxKernArgAlign; 25781ad6265SDimitry Andric uint32_t LDSSize = 0; 25881ad6265SDimitry Andric uint32_t GDSSize = 0; 259e8d8bef9SDimitry Andric Align DynLDSAlign; 2600b57cec5SDimitry Andric bool IsEntryFunction = false; 2615f757f3fSDimitry Andric bool IsChainFunction = false; 2620b57cec5SDimitry Andric bool NoSignedZerosFPMath = false; 2630b57cec5SDimitry Andric bool MemoryBound = false; 2640b57cec5SDimitry Andric bool WaveLimiter = false; 265e8d8bef9SDimitry Andric bool HasSpilledSGPRs = false; 266e8d8bef9SDimitry Andric bool HasSpilledVGPRs = false; 2678bcb0991SDimitry Andric uint32_t HighBitsOf32BitAddress = 0; 2680b57cec5SDimitry Andric 269e8d8bef9SDimitry Andric // TODO: 10 may be a better default since it's the maximum. 270e8d8bef9SDimitry Andric unsigned Occupancy = 0; 271e8d8bef9SDimitry Andric 27281ad6265SDimitry Andric SmallVector<StringValue> WWMReservedRegs; 27381ad6265SDimitry Andric 2740b57cec5SDimitry Andric StringValue ScratchRSrcReg = "$private_rsrc_reg"; 2750b57cec5SDimitry Andric StringValue FrameOffsetReg = "$fp_reg"; 2760b57cec5SDimitry Andric StringValue StackPtrOffsetReg = "$sp_reg"; 2770b57cec5SDimitry Andric 27881ad6265SDimitry Andric unsigned BytesInStackArgArea = 0; 27981ad6265SDimitry Andric bool ReturnsVoid = true; 28081ad6265SDimitry Andric 281bdd1243dSDimitry Andric std::optional<SIArgumentInfo> ArgInfo; 28206c3fb27SDimitry Andric 28306c3fb27SDimitry Andric unsigned PSInputAddr = 0; 28406c3fb27SDimitry Andric unsigned PSInputEnable = 0; 28506c3fb27SDimitry Andric 2860b57cec5SDimitry Andric SIMode Mode; 287bdd1243dSDimitry Andric std::optional<FrameIndex> ScavengeFI; 28881ad6265SDimitry Andric StringValue VGPRForAGPRCopy; 28906c3fb27SDimitry Andric StringValue SGPRForEXECCopy; 29006c3fb27SDimitry Andric StringValue LongBranchReservedReg; 2910b57cec5SDimitry Andric 2920b57cec5SDimitry Andric SIMachineFunctionInfo() = default; 2930b57cec5SDimitry Andric SIMachineFunctionInfo(const llvm::SIMachineFunctionInfo &, 294fe6060f1SDimitry Andric const TargetRegisterInfo &TRI, 295fe6060f1SDimitry Andric const llvm::MachineFunction &MF); 2960b57cec5SDimitry Andric 2970b57cec5SDimitry Andric void mappingImpl(yaml::IO &YamlIO) override; 2980b57cec5SDimitry Andric ~SIMachineFunctionInfo() = default; 2990b57cec5SDimitry Andric }; 3000b57cec5SDimitry Andric 3010b57cec5SDimitry Andric template <> struct MappingTraits<SIMachineFunctionInfo> { 3020b57cec5SDimitry Andric static void mapping(IO &YamlIO, SIMachineFunctionInfo &MFI) { 3030b57cec5SDimitry Andric YamlIO.mapOptional("explicitKernArgSize", MFI.ExplicitKernArgSize, 3040b57cec5SDimitry Andric UINT64_C(0)); 30581ad6265SDimitry Andric YamlIO.mapOptional("maxKernArgAlign", MFI.MaxKernArgAlign); 3060b57cec5SDimitry Andric YamlIO.mapOptional("ldsSize", MFI.LDSSize, 0u); 30781ad6265SDimitry Andric YamlIO.mapOptional("gdsSize", MFI.GDSSize, 0u); 308e8d8bef9SDimitry Andric YamlIO.mapOptional("dynLDSAlign", MFI.DynLDSAlign, Align()); 3090b57cec5SDimitry Andric YamlIO.mapOptional("isEntryFunction", MFI.IsEntryFunction, false); 3105f757f3fSDimitry Andric YamlIO.mapOptional("isChainFunction", MFI.IsChainFunction, false); 3110b57cec5SDimitry Andric YamlIO.mapOptional("noSignedZerosFPMath", MFI.NoSignedZerosFPMath, false); 3120b57cec5SDimitry Andric YamlIO.mapOptional("memoryBound", MFI.MemoryBound, false); 3130b57cec5SDimitry Andric YamlIO.mapOptional("waveLimiter", MFI.WaveLimiter, false); 314e8d8bef9SDimitry Andric YamlIO.mapOptional("hasSpilledSGPRs", MFI.HasSpilledSGPRs, false); 315e8d8bef9SDimitry Andric YamlIO.mapOptional("hasSpilledVGPRs", MFI.HasSpilledVGPRs, false); 3160b57cec5SDimitry Andric YamlIO.mapOptional("scratchRSrcReg", MFI.ScratchRSrcReg, 3170b57cec5SDimitry Andric StringValue("$private_rsrc_reg")); 3180b57cec5SDimitry Andric YamlIO.mapOptional("frameOffsetReg", MFI.FrameOffsetReg, 3190b57cec5SDimitry Andric StringValue("$fp_reg")); 3200b57cec5SDimitry Andric YamlIO.mapOptional("stackPtrOffsetReg", MFI.StackPtrOffsetReg, 3210b57cec5SDimitry Andric StringValue("$sp_reg")); 32281ad6265SDimitry Andric YamlIO.mapOptional("bytesInStackArgArea", MFI.BytesInStackArgArea, 0u); 32381ad6265SDimitry Andric YamlIO.mapOptional("returnsVoid", MFI.ReturnsVoid, true); 3240b57cec5SDimitry Andric YamlIO.mapOptional("argumentInfo", MFI.ArgInfo); 32506c3fb27SDimitry Andric YamlIO.mapOptional("psInputAddr", MFI.PSInputAddr, 0u); 32606c3fb27SDimitry Andric YamlIO.mapOptional("psInputEnable", MFI.PSInputEnable, 0u); 3270b57cec5SDimitry Andric YamlIO.mapOptional("mode", MFI.Mode, SIMode()); 3288bcb0991SDimitry Andric YamlIO.mapOptional("highBitsOf32BitAddress", 3298bcb0991SDimitry Andric MFI.HighBitsOf32BitAddress, 0u); 330e8d8bef9SDimitry Andric YamlIO.mapOptional("occupancy", MFI.Occupancy, 0); 33181ad6265SDimitry Andric YamlIO.mapOptional("wwmReservedRegs", MFI.WWMReservedRegs); 332fe6060f1SDimitry Andric YamlIO.mapOptional("scavengeFI", MFI.ScavengeFI); 33381ad6265SDimitry Andric YamlIO.mapOptional("vgprForAGPRCopy", MFI.VGPRForAGPRCopy, 33481ad6265SDimitry Andric StringValue()); // Don't print out when it's empty. 33506c3fb27SDimitry Andric YamlIO.mapOptional("sgprForEXECCopy", MFI.SGPRForEXECCopy, 33606c3fb27SDimitry Andric StringValue()); // Don't print out when it's empty. 33706c3fb27SDimitry Andric YamlIO.mapOptional("longBranchReservedReg", MFI.LongBranchReservedReg, 33806c3fb27SDimitry Andric StringValue()); 3390b57cec5SDimitry Andric } 3400b57cec5SDimitry Andric }; 3410b57cec5SDimitry Andric 3420b57cec5SDimitry Andric } // end namespace yaml 3430b57cec5SDimitry Andric 344bdd1243dSDimitry Andric // A CSR SGPR value can be preserved inside a callee using one of the following 345bdd1243dSDimitry Andric // methods. 346bdd1243dSDimitry Andric // 1. Copy to an unused scratch SGPR. 347bdd1243dSDimitry Andric // 2. Spill to a VGPR lane. 348bdd1243dSDimitry Andric // 3. Spill to memory via. a scratch VGPR. 349bdd1243dSDimitry Andric // class PrologEpilogSGPRSaveRestoreInfo represents the save/restore method used 350bdd1243dSDimitry Andric // for an SGPR at function prolog/epilog. 351bdd1243dSDimitry Andric enum class SGPRSaveKind : uint8_t { 352bdd1243dSDimitry Andric COPY_TO_SCRATCH_SGPR, 353bdd1243dSDimitry Andric SPILL_TO_VGPR_LANE, 354bdd1243dSDimitry Andric SPILL_TO_MEM 355bdd1243dSDimitry Andric }; 356bdd1243dSDimitry Andric 357bdd1243dSDimitry Andric class PrologEpilogSGPRSaveRestoreInfo { 358bdd1243dSDimitry Andric SGPRSaveKind Kind; 359bdd1243dSDimitry Andric union { 360bdd1243dSDimitry Andric int Index; 361bdd1243dSDimitry Andric Register Reg; 362bdd1243dSDimitry Andric }; 363bdd1243dSDimitry Andric 364bdd1243dSDimitry Andric public: 365bdd1243dSDimitry Andric PrologEpilogSGPRSaveRestoreInfo(SGPRSaveKind K, int I) : Kind(K), Index(I) {} 366bdd1243dSDimitry Andric PrologEpilogSGPRSaveRestoreInfo(SGPRSaveKind K, Register R) 367bdd1243dSDimitry Andric : Kind(K), Reg(R) {} 368bdd1243dSDimitry Andric Register getReg() const { return Reg; } 369bdd1243dSDimitry Andric int getIndex() const { return Index; } 370bdd1243dSDimitry Andric SGPRSaveKind getKind() const { return Kind; } 371bdd1243dSDimitry Andric }; 372bdd1243dSDimitry Andric 3730b57cec5SDimitry Andric /// This class keeps track of the SPI_SP_INPUT_ADDR config register, which 3740b57cec5SDimitry Andric /// tells the hardware which interpolation parameters to load. 37506c3fb27SDimitry Andric class SIMachineFunctionInfo final : public AMDGPUMachineFunction, 37606c3fb27SDimitry Andric private MachineRegisterInfo::Delegate { 3770b57cec5SDimitry Andric friend class GCNTargetMachine; 3780b57cec5SDimitry Andric 379bdd1243dSDimitry Andric // State of MODE register, assumed FP mode. 38006c3fb27SDimitry Andric SIModeRegisterDefaults Mode; 381bdd1243dSDimitry Andric 3820b57cec5SDimitry Andric // Registers that may be reserved for spilling purposes. These may be the same 3830b57cec5SDimitry Andric // as the input registers. 3845ffd83dbSDimitry Andric Register ScratchRSrcReg = AMDGPU::PRIVATE_RSRC_REG; 3850b57cec5SDimitry Andric 386bdd1243dSDimitry Andric // This is the unswizzled offset from the current dispatch's scratch wave 3875ffd83dbSDimitry Andric // base to the beginning of the current function's frame. 3885ffd83dbSDimitry Andric Register FrameOffsetReg = AMDGPU::FP_REG; 3890b57cec5SDimitry Andric 3905ffd83dbSDimitry Andric // This is an ABI register used in the non-entry calling convention to 3915ffd83dbSDimitry Andric // communicate the unswizzled offset from the current dispatch's scratch wave 3925ffd83dbSDimitry Andric // base to the beginning of the new function's frame. 3935ffd83dbSDimitry Andric Register StackPtrOffsetReg = AMDGPU::SP_REG; 3940b57cec5SDimitry Andric 39506c3fb27SDimitry Andric // Registers that may be reserved when RA doesn't allocate enough 39606c3fb27SDimitry Andric // registers to plan for the case where an indirect branch ends up 39706c3fb27SDimitry Andric // being needed during branch relaxation. 39806c3fb27SDimitry Andric Register LongBranchReservedReg; 39906c3fb27SDimitry Andric 4000b57cec5SDimitry Andric AMDGPUFunctionArgInfo ArgInfo; 4010b57cec5SDimitry Andric 4020b57cec5SDimitry Andric // Graphics info. 4030b57cec5SDimitry Andric unsigned PSInputAddr = 0; 4040b57cec5SDimitry Andric unsigned PSInputEnable = 0; 4050b57cec5SDimitry Andric 4060b57cec5SDimitry Andric /// Number of bytes of arguments this function has on the stack. If the callee 4070b57cec5SDimitry Andric /// is expected to restore the argument stack this should be a multiple of 16, 4080b57cec5SDimitry Andric /// all usable during a tail call. 4090b57cec5SDimitry Andric /// 4100b57cec5SDimitry Andric /// The alternative would forbid tail call optimisation in some cases: if we 4110b57cec5SDimitry Andric /// want to transfer control from a function with 8-bytes of stack-argument 4120b57cec5SDimitry Andric /// space to a function with 16-bytes then misalignment of this value would 4130b57cec5SDimitry Andric /// make a stack adjustment necessary, which could not be undone by the 4140b57cec5SDimitry Andric /// callee. 4150b57cec5SDimitry Andric unsigned BytesInStackArgArea = 0; 4160b57cec5SDimitry Andric 4170b57cec5SDimitry Andric bool ReturnsVoid = true; 4180b57cec5SDimitry Andric 4190b57cec5SDimitry Andric // A pair of default/requested minimum/maximum flat work group sizes. 4200b57cec5SDimitry Andric // Minimum - first, maximum - second. 4210b57cec5SDimitry Andric std::pair<unsigned, unsigned> FlatWorkGroupSizes = {0, 0}; 4220b57cec5SDimitry Andric 4230b57cec5SDimitry Andric // A pair of default/requested minimum/maximum number of waves per execution 4240b57cec5SDimitry Andric // unit. Minimum - first, maximum - second. 4250b57cec5SDimitry Andric std::pair<unsigned, unsigned> WavesPerEU = {0, 0}; 4260b57cec5SDimitry Andric 42781ad6265SDimitry Andric const AMDGPUGWSResourcePseudoSourceValue GWSResourcePSV; 4280b57cec5SDimitry Andric 429*0fca6ea1SDimitry Andric // Default/requested number of work groups for the function. 430*0fca6ea1SDimitry Andric SmallVector<unsigned> MaxNumWorkGroups = {0, 0, 0}; 431*0fca6ea1SDimitry Andric 4320b57cec5SDimitry Andric private: 4330b57cec5SDimitry Andric unsigned NumUserSGPRs = 0; 4340b57cec5SDimitry Andric unsigned NumSystemSGPRs = 0; 4350b57cec5SDimitry Andric 4360b57cec5SDimitry Andric bool HasSpilledSGPRs = false; 4370b57cec5SDimitry Andric bool HasSpilledVGPRs = false; 4380b57cec5SDimitry Andric bool HasNonSpillStackObjects = false; 4390b57cec5SDimitry Andric bool IsStackRealigned = false; 4400b57cec5SDimitry Andric 4410b57cec5SDimitry Andric unsigned NumSpilledSGPRs = 0; 4420b57cec5SDimitry Andric unsigned NumSpilledVGPRs = 0; 4430b57cec5SDimitry Andric 4445f757f3fSDimitry Andric // Tracks information about user SGPRs that will be setup by hardware which 4455f757f3fSDimitry Andric // will apply to all wavefronts of the grid. 4465f757f3fSDimitry Andric GCNUserSGPRUsageInfo UserSGPRInfo; 4470b57cec5SDimitry Andric 4480b57cec5SDimitry Andric // Feature bits required for inputs passed in system SGPRs. 4490b57cec5SDimitry Andric bool WorkGroupIDX : 1; // Always initialized. 4500b57cec5SDimitry Andric bool WorkGroupIDY : 1; 4510b57cec5SDimitry Andric bool WorkGroupIDZ : 1; 4520b57cec5SDimitry Andric bool WorkGroupInfo : 1; 453fcaf7f86SDimitry Andric bool LDSKernelId : 1; 4540b57cec5SDimitry Andric bool PrivateSegmentWaveByteOffset : 1; 4550b57cec5SDimitry Andric 4560b57cec5SDimitry Andric bool WorkItemIDX : 1; // Always initialized. 4570b57cec5SDimitry Andric bool WorkItemIDY : 1; 4580b57cec5SDimitry Andric bool WorkItemIDZ : 1; 4590b57cec5SDimitry Andric 4600b57cec5SDimitry Andric // Pointer to where the ABI inserts special kernel arguments separate from the 4610b57cec5SDimitry Andric // user arguments. This is an offset from the KernargSegmentPtr. 4620b57cec5SDimitry Andric bool ImplicitArgPtr : 1; 4630b57cec5SDimitry Andric 46481ad6265SDimitry Andric bool MayNeedAGPRs : 1; 46581ad6265SDimitry Andric 4660b57cec5SDimitry Andric // The hard-wired high half of the address of the global information table 4670b57cec5SDimitry Andric // for AMDPAL OS type. 0xffffffff represents no hard-wired high half, since 4680b57cec5SDimitry Andric // current hardware only allows a 16 bit value. 4690b57cec5SDimitry Andric unsigned GITPtrHigh; 4700b57cec5SDimitry Andric 4710b57cec5SDimitry Andric unsigned HighBitsOf32BitAddress; 4720b57cec5SDimitry Andric 47306c3fb27SDimitry Andric // Flags associated with the virtual registers. 47406c3fb27SDimitry Andric IndexedMap<uint8_t, VirtReg2IndexFunctor> VRegFlags; 47506c3fb27SDimitry Andric 4760b57cec5SDimitry Andric // Current recorded maximum possible occupancy. 4770b57cec5SDimitry Andric unsigned Occupancy; 4780b57cec5SDimitry Andric 479bdd1243dSDimitry Andric mutable std::optional<bool> UsesAGPRs; 480349cc55cSDimitry Andric 4810b57cec5SDimitry Andric MCPhysReg getNextUserSGPR() const; 4820b57cec5SDimitry Andric 4830b57cec5SDimitry Andric MCPhysReg getNextSystemSGPR() const; 4840b57cec5SDimitry Andric 48506c3fb27SDimitry Andric // MachineRegisterInfo callback functions to notify events. 48606c3fb27SDimitry Andric void MRI_NoteNewVirtualRegister(Register Reg) override; 48706c3fb27SDimitry Andric void MRI_NoteCloneVirtualRegister(Register NewReg, Register SrcReg) override; 48806c3fb27SDimitry Andric 4890b57cec5SDimitry Andric public: 4900b57cec5SDimitry Andric struct VGPRSpillToAGPR { 4910b57cec5SDimitry Andric SmallVector<MCPhysReg, 32> Lanes; 4920b57cec5SDimitry Andric bool FullyAllocated = false; 4930eae32dcSDimitry Andric bool IsDead = false; 4940b57cec5SDimitry Andric }; 4950b57cec5SDimitry Andric 4960b57cec5SDimitry Andric private: 4975f757f3fSDimitry Andric // To track virtual VGPR + lane index for each subregister of the SGPR spilled 4985f757f3fSDimitry Andric // to frameindex key during SILowerSGPRSpills pass. 499bdd1243dSDimitry Andric DenseMap<int, std::vector<SIRegisterInfo::SpilledReg>> 5005f757f3fSDimitry Andric SGPRSpillsToVirtualVGPRLanes; 5015f757f3fSDimitry Andric // To track physical VGPR + lane index for CSR SGPR spills and special SGPRs 5025f757f3fSDimitry Andric // like Frame Pointer identified during PrologEpilogInserter. 5035f757f3fSDimitry Andric DenseMap<int, std::vector<SIRegisterInfo::SpilledReg>> 5045f757f3fSDimitry Andric SGPRSpillsToPhysicalVGPRLanes; 5055f757f3fSDimitry Andric unsigned NumVirtualVGPRSpillLanes = 0; 5065f757f3fSDimitry Andric unsigned NumPhysicalVGPRSpillLanes = 0; 507bdd1243dSDimitry Andric SmallVector<Register, 2> SpillVGPRs; 5085f757f3fSDimitry Andric SmallVector<Register, 2> SpillPhysVGPRs; 509bdd1243dSDimitry Andric using WWMSpillsMap = MapVector<Register, int>; 510bdd1243dSDimitry Andric // To track the registers used in instructions that can potentially modify the 511bdd1243dSDimitry Andric // inactive lanes. The WWM instructions and the writelane instructions for 512bdd1243dSDimitry Andric // spilling SGPRs to VGPRs fall under such category of operations. The VGPRs 513bdd1243dSDimitry Andric // modified by them should be spilled/restored at function prolog/epilog to 514bdd1243dSDimitry Andric // avoid any undesired outcome. Each entry in this map holds a pair of values, 515bdd1243dSDimitry Andric // the VGPR and its stack slot index. 516bdd1243dSDimitry Andric WWMSpillsMap WWMSpills; 517bdd1243dSDimitry Andric 518bdd1243dSDimitry Andric using ReservedRegSet = SmallSetVector<Register, 8>; 519bdd1243dSDimitry Andric // To track the VGPRs reserved for WWM instructions. They get stack slots 520bdd1243dSDimitry Andric // later during PrologEpilogInserter and get added into the superset WWMSpills 521bdd1243dSDimitry Andric // for actual spilling. A separate set makes the register reserved part and 522bdd1243dSDimitry Andric // the serialization easier. 523bdd1243dSDimitry Andric ReservedRegSet WWMReservedRegs; 524bdd1243dSDimitry Andric 525*0fca6ea1SDimitry Andric using PrologEpilogSGPRSpill = 526*0fca6ea1SDimitry Andric std::pair<Register, PrologEpilogSGPRSaveRestoreInfo>; 527bdd1243dSDimitry Andric // To track the SGPR spill method used for a CSR SGPR register during 528bdd1243dSDimitry Andric // frame lowering. Even though the SGPR spills are handled during 529bdd1243dSDimitry Andric // SILowerSGPRSpills pass, some special handling needed later during the 530bdd1243dSDimitry Andric // PrologEpilogInserter. 531*0fca6ea1SDimitry Andric SmallVector<PrologEpilogSGPRSpill, 3> PrologEpilogSGPRSpills; 5320b57cec5SDimitry Andric 53306c3fb27SDimitry Andric // To save/restore EXEC MASK around WWM spills and copies. 53406c3fb27SDimitry Andric Register SGPRForEXECCopy; 53506c3fb27SDimitry Andric 5360b57cec5SDimitry Andric DenseMap<int, VGPRSpillToAGPR> VGPRToAGPRSpills; 5370b57cec5SDimitry Andric 5380b57cec5SDimitry Andric // AGPRs used for VGPR spills. 5390b57cec5SDimitry Andric SmallVector<MCPhysReg, 32> SpillAGPR; 5400b57cec5SDimitry Andric 5410b57cec5SDimitry Andric // VGPRs used for AGPR spills. 5420b57cec5SDimitry Andric SmallVector<MCPhysReg, 32> SpillVGPR; 5430b57cec5SDimitry Andric 544fe6060f1SDimitry Andric // Emergency stack slot. Sometimes, we create this before finalizing the stack 545fe6060f1SDimitry Andric // frame, so save it here and add it to the RegScavenger later. 546bdd1243dSDimitry Andric std::optional<int> ScavengeFI; 547fe6060f1SDimitry Andric 54881ad6265SDimitry Andric private: 54981ad6265SDimitry Andric Register VGPRForAGPRCopy; 55081ad6265SDimitry Andric 5515f757f3fSDimitry Andric bool allocateVirtualVGPRForSGPRSpills(MachineFunction &MF, int FI, 552bdd1243dSDimitry Andric unsigned LaneIndex); 5535f757f3fSDimitry Andric bool allocatePhysicalVGPRForSGPRSpills(MachineFunction &MF, int FI, 5547a6dacacSDimitry Andric unsigned LaneIndex, 5557a6dacacSDimitry Andric bool IsPrologEpilog); 556bdd1243dSDimitry Andric 55781ad6265SDimitry Andric public: 55881ad6265SDimitry Andric Register getVGPRForAGPRCopy() const { 55981ad6265SDimitry Andric return VGPRForAGPRCopy; 56081ad6265SDimitry Andric } 56181ad6265SDimitry Andric 56281ad6265SDimitry Andric void setVGPRForAGPRCopy(Register NewVGPRForAGPRCopy) { 56381ad6265SDimitry Andric VGPRForAGPRCopy = NewVGPRForAGPRCopy; 56481ad6265SDimitry Andric } 56581ad6265SDimitry Andric 566bdd1243dSDimitry Andric bool isCalleeSavedReg(const MCPhysReg *CSRegs, MCPhysReg Reg) const; 5675ffd83dbSDimitry Andric 5680b57cec5SDimitry Andric public: 56981ad6265SDimitry Andric SIMachineFunctionInfo(const SIMachineFunctionInfo &MFI) = default; 570bdd1243dSDimitry Andric SIMachineFunctionInfo(const Function &F, const GCNSubtarget *STI); 57181ad6265SDimitry Andric 57281ad6265SDimitry Andric MachineFunctionInfo * 57381ad6265SDimitry Andric clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF, 57481ad6265SDimitry Andric const DenseMap<MachineBasicBlock *, MachineBasicBlock *> &Src2DstMBB) 57581ad6265SDimitry Andric const override; 5760b57cec5SDimitry Andric 577fe6060f1SDimitry Andric bool initializeBaseYamlFields(const yaml::SIMachineFunctionInfo &YamlMFI, 578fe6060f1SDimitry Andric const MachineFunction &MF, 579fe6060f1SDimitry Andric PerFunctionMIParsingState &PFS, 580fe6060f1SDimitry Andric SMDiagnostic &Error, SMRange &SourceRange); 581fe6060f1SDimitry Andric 582bdd1243dSDimitry Andric void reserveWWMRegister(Register Reg) { WWMReservedRegs.insert(Reg); } 583bdd1243dSDimitry Andric 58406c3fb27SDimitry Andric SIModeRegisterDefaults getMode() const { return Mode; } 5850b57cec5SDimitry Andric 58681ad6265SDimitry Andric ArrayRef<SIRegisterInfo::SpilledReg> 5875f757f3fSDimitry Andric getSGPRSpillToVirtualVGPRLanes(int FrameIndex) const { 5885f757f3fSDimitry Andric auto I = SGPRSpillsToVirtualVGPRLanes.find(FrameIndex); 5895f757f3fSDimitry Andric return (I == SGPRSpillsToVirtualVGPRLanes.end()) 59081ad6265SDimitry Andric ? ArrayRef<SIRegisterInfo::SpilledReg>() 591bdd1243dSDimitry Andric : ArrayRef(I->second); 5920b57cec5SDimitry Andric } 5930b57cec5SDimitry Andric 594bdd1243dSDimitry Andric ArrayRef<Register> getSGPRSpillVGPRs() const { return SpillVGPRs; } 5957a6dacacSDimitry Andric 596bdd1243dSDimitry Andric const WWMSpillsMap &getWWMSpills() const { return WWMSpills; } 597bdd1243dSDimitry Andric const ReservedRegSet &getWWMReservedRegs() const { return WWMReservedRegs; } 598bdd1243dSDimitry Andric 599*0fca6ea1SDimitry Andric ArrayRef<PrologEpilogSGPRSpill> getPrologEpilogSGPRSpills() const { 600*0fca6ea1SDimitry Andric assert(is_sorted(PrologEpilogSGPRSpills, llvm::less_first())); 601bdd1243dSDimitry Andric return PrologEpilogSGPRSpills; 602bdd1243dSDimitry Andric } 603bdd1243dSDimitry Andric 6045f757f3fSDimitry Andric GCNUserSGPRUsageInfo &getUserSGPRInfo() { return UserSGPRInfo; } 6055f757f3fSDimitry Andric 6065f757f3fSDimitry Andric const GCNUserSGPRUsageInfo &getUserSGPRInfo() const { return UserSGPRInfo; } 6075f757f3fSDimitry Andric 608bdd1243dSDimitry Andric void addToPrologEpilogSGPRSpills(Register Reg, 609bdd1243dSDimitry Andric PrologEpilogSGPRSaveRestoreInfo SI) { 610*0fca6ea1SDimitry Andric assert(!hasPrologEpilogSGPRSpillEntry(Reg)); 611*0fca6ea1SDimitry Andric 612*0fca6ea1SDimitry Andric // Insert a new entry in the right place to keep the vector in sorted order. 613*0fca6ea1SDimitry Andric // This should be cheap since the vector is expected to be very short. 614*0fca6ea1SDimitry Andric PrologEpilogSGPRSpills.insert( 615*0fca6ea1SDimitry Andric upper_bound( 616*0fca6ea1SDimitry Andric PrologEpilogSGPRSpills, Reg, 617*0fca6ea1SDimitry Andric [](const auto &LHS, const auto &RHS) { return LHS < RHS.first; }), 618*0fca6ea1SDimitry Andric std::make_pair(Reg, SI)); 619bdd1243dSDimitry Andric } 620bdd1243dSDimitry Andric 621bdd1243dSDimitry Andric // Check if an entry created for \p Reg in PrologEpilogSGPRSpills. Return true 622bdd1243dSDimitry Andric // on success and false otherwise. 623bdd1243dSDimitry Andric bool hasPrologEpilogSGPRSpillEntry(Register Reg) const { 624*0fca6ea1SDimitry Andric auto I = find_if(PrologEpilogSGPRSpills, 625*0fca6ea1SDimitry Andric [&Reg](const auto &Spill) { return Spill.first == Reg; }); 626*0fca6ea1SDimitry Andric return I != PrologEpilogSGPRSpills.end(); 627bdd1243dSDimitry Andric } 628bdd1243dSDimitry Andric 629bdd1243dSDimitry Andric // Get the scratch SGPR if allocated to save/restore \p Reg. 630bdd1243dSDimitry Andric Register getScratchSGPRCopyDstReg(Register Reg) const { 631*0fca6ea1SDimitry Andric auto I = find_if(PrologEpilogSGPRSpills, 632*0fca6ea1SDimitry Andric [&Reg](const auto &Spill) { return Spill.first == Reg; }); 633bdd1243dSDimitry Andric if (I != PrologEpilogSGPRSpills.end() && 634bdd1243dSDimitry Andric I->second.getKind() == SGPRSaveKind::COPY_TO_SCRATCH_SGPR) 635bdd1243dSDimitry Andric return I->second.getReg(); 636bdd1243dSDimitry Andric 637bdd1243dSDimitry Andric return AMDGPU::NoRegister; 638bdd1243dSDimitry Andric } 639bdd1243dSDimitry Andric 640bdd1243dSDimitry Andric // Get all scratch SGPRs allocated to copy/restore the SGPR spills. 641bdd1243dSDimitry Andric void getAllScratchSGPRCopyDstRegs(SmallVectorImpl<Register> &Regs) const { 642bdd1243dSDimitry Andric for (const auto &SI : PrologEpilogSGPRSpills) { 643bdd1243dSDimitry Andric if (SI.second.getKind() == SGPRSaveKind::COPY_TO_SCRATCH_SGPR) 644bdd1243dSDimitry Andric Regs.push_back(SI.second.getReg()); 645bdd1243dSDimitry Andric } 646bdd1243dSDimitry Andric } 647bdd1243dSDimitry Andric 648bdd1243dSDimitry Andric // Check if \p FI is allocated for any SGPR spill to a VGPR lane during PEI. 649bdd1243dSDimitry Andric bool checkIndexInPrologEpilogSGPRSpills(int FI) const { 650bdd1243dSDimitry Andric return find_if(PrologEpilogSGPRSpills, 651bdd1243dSDimitry Andric [FI](const std::pair<Register, 652bdd1243dSDimitry Andric PrologEpilogSGPRSaveRestoreInfo> &SI) { 653bdd1243dSDimitry Andric return SI.second.getKind() == 654bdd1243dSDimitry Andric SGPRSaveKind::SPILL_TO_VGPR_LANE && 655bdd1243dSDimitry Andric SI.second.getIndex() == FI; 656bdd1243dSDimitry Andric }) != PrologEpilogSGPRSpills.end(); 657bdd1243dSDimitry Andric } 658bdd1243dSDimitry Andric 659bdd1243dSDimitry Andric const PrologEpilogSGPRSaveRestoreInfo & 660bdd1243dSDimitry Andric getPrologEpilogSGPRSaveRestoreInfo(Register Reg) const { 661*0fca6ea1SDimitry Andric auto I = find_if(PrologEpilogSGPRSpills, 662*0fca6ea1SDimitry Andric [&Reg](const auto &Spill) { return Spill.first == Reg; }); 663bdd1243dSDimitry Andric assert(I != PrologEpilogSGPRSpills.end()); 664bdd1243dSDimitry Andric 665bdd1243dSDimitry Andric return I->second; 666bdd1243dSDimitry Andric } 667bdd1243dSDimitry Andric 668bdd1243dSDimitry Andric ArrayRef<SIRegisterInfo::SpilledReg> 6695f757f3fSDimitry Andric getSGPRSpillToPhysicalVGPRLanes(int FrameIndex) const { 6705f757f3fSDimitry Andric auto I = SGPRSpillsToPhysicalVGPRLanes.find(FrameIndex); 6715f757f3fSDimitry Andric return (I == SGPRSpillsToPhysicalVGPRLanes.end()) 672bdd1243dSDimitry Andric ? ArrayRef<SIRegisterInfo::SpilledReg>() 673bdd1243dSDimitry Andric : ArrayRef(I->second); 674bdd1243dSDimitry Andric } 675bdd1243dSDimitry Andric 67606c3fb27SDimitry Andric void setFlag(Register Reg, uint8_t Flag) { 67706c3fb27SDimitry Andric assert(Reg.isVirtual()); 67806c3fb27SDimitry Andric if (VRegFlags.inBounds(Reg)) 67906c3fb27SDimitry Andric VRegFlags[Reg] |= Flag; 68006c3fb27SDimitry Andric } 68106c3fb27SDimitry Andric 68206c3fb27SDimitry Andric bool checkFlag(Register Reg, uint8_t Flag) const { 68306c3fb27SDimitry Andric if (Reg.isPhysical()) 68406c3fb27SDimitry Andric return false; 68506c3fb27SDimitry Andric 68606c3fb27SDimitry Andric return VRegFlags.inBounds(Reg) && VRegFlags[Reg] & Flag; 68706c3fb27SDimitry Andric } 68806c3fb27SDimitry Andric 6895f757f3fSDimitry Andric bool hasVRegFlags() { return VRegFlags.size(); } 6905f757f3fSDimitry Andric 691bdd1243dSDimitry Andric void allocateWWMSpill(MachineFunction &MF, Register VGPR, uint64_t Size = 4, 692bdd1243dSDimitry Andric Align Alignment = Align(4)); 693bdd1243dSDimitry Andric 694bdd1243dSDimitry Andric void splitWWMSpillRegisters( 695bdd1243dSDimitry Andric MachineFunction &MF, 696bdd1243dSDimitry Andric SmallVectorImpl<std::pair<Register, int>> &CalleeSavedRegs, 697bdd1243dSDimitry Andric SmallVectorImpl<std::pair<Register, int>> &ScratchRegs) const; 6980b57cec5SDimitry Andric 6990b57cec5SDimitry Andric ArrayRef<MCPhysReg> getAGPRSpillVGPRs() const { 7000b57cec5SDimitry Andric return SpillAGPR; 7010b57cec5SDimitry Andric } 7020b57cec5SDimitry Andric 70306c3fb27SDimitry Andric Register getSGPRForEXECCopy() const { return SGPRForEXECCopy; } 70406c3fb27SDimitry Andric 70506c3fb27SDimitry Andric void setSGPRForEXECCopy(Register Reg) { SGPRForEXECCopy = Reg; } 70606c3fb27SDimitry Andric 7070b57cec5SDimitry Andric ArrayRef<MCPhysReg> getVGPRSpillAGPRs() const { 7080b57cec5SDimitry Andric return SpillVGPR; 7090b57cec5SDimitry Andric } 7100b57cec5SDimitry Andric 7110b57cec5SDimitry Andric MCPhysReg getVGPRToAGPRSpill(int FrameIndex, unsigned Lane) const { 7120b57cec5SDimitry Andric auto I = VGPRToAGPRSpills.find(FrameIndex); 7130b57cec5SDimitry Andric return (I == VGPRToAGPRSpills.end()) ? (MCPhysReg)AMDGPU::NoRegister 7140b57cec5SDimitry Andric : I->second.Lanes[Lane]; 7150b57cec5SDimitry Andric } 7160b57cec5SDimitry Andric 7170eae32dcSDimitry Andric void setVGPRToAGPRSpillDead(int FrameIndex) { 7180eae32dcSDimitry Andric auto I = VGPRToAGPRSpills.find(FrameIndex); 7190eae32dcSDimitry Andric if (I != VGPRToAGPRSpills.end()) 7200eae32dcSDimitry Andric I->second.IsDead = true; 7210eae32dcSDimitry Andric } 7220eae32dcSDimitry Andric 7237a6dacacSDimitry Andric // To bring the Physical VGPRs in the highest range allocated for CSR SGPR 7247a6dacacSDimitry Andric // spilling into the lowest available range. 7257a6dacacSDimitry Andric void shiftSpillPhysVGPRsToLowestRange(MachineFunction &MF); 7267a6dacacSDimitry Andric 727bdd1243dSDimitry Andric bool allocateSGPRSpillToVGPRLane(MachineFunction &MF, int FI, 7287a6dacacSDimitry Andric bool SpillToPhysVGPRLane = false, 729bdd1243dSDimitry Andric bool IsPrologEpilog = false); 7300b57cec5SDimitry Andric bool allocateVGPRSpillToAGPR(MachineFunction &MF, int FI, bool isAGPRtoVGPR); 73181ad6265SDimitry Andric 73281ad6265SDimitry Andric /// If \p ResetSGPRSpillStackIDs is true, reset the stack ID from sgpr-spill 73381ad6265SDimitry Andric /// to the default stack. 73481ad6265SDimitry Andric bool removeDeadFrameIndices(MachineFrameInfo &MFI, 73581ad6265SDimitry Andric bool ResetSGPRSpillStackIDs); 7360b57cec5SDimitry Andric 737fe6060f1SDimitry Andric int getScavengeFI(MachineFrameInfo &MFI, const SIRegisterInfo &TRI); 738bdd1243dSDimitry Andric std::optional<int> getOptionalScavengeFI() const { return ScavengeFI; } 739fe6060f1SDimitry Andric 7400b57cec5SDimitry Andric unsigned getBytesInStackArgArea() const { 7410b57cec5SDimitry Andric return BytesInStackArgArea; 7420b57cec5SDimitry Andric } 7430b57cec5SDimitry Andric 7440b57cec5SDimitry Andric void setBytesInStackArgArea(unsigned Bytes) { 7450b57cec5SDimitry Andric BytesInStackArgArea = Bytes; 7460b57cec5SDimitry Andric } 7470b57cec5SDimitry Andric 7480b57cec5SDimitry Andric // Add user SGPRs. 7495ffd83dbSDimitry Andric Register addPrivateSegmentBuffer(const SIRegisterInfo &TRI); 7505ffd83dbSDimitry Andric Register addDispatchPtr(const SIRegisterInfo &TRI); 7515ffd83dbSDimitry Andric Register addQueuePtr(const SIRegisterInfo &TRI); 7525ffd83dbSDimitry Andric Register addKernargSegmentPtr(const SIRegisterInfo &TRI); 7535ffd83dbSDimitry Andric Register addDispatchID(const SIRegisterInfo &TRI); 7545ffd83dbSDimitry Andric Register addFlatScratchInit(const SIRegisterInfo &TRI); 755*0fca6ea1SDimitry Andric Register addPrivateSegmentSize(const SIRegisterInfo &TRI); 7565ffd83dbSDimitry Andric Register addImplicitBufferPtr(const SIRegisterInfo &TRI); 757fcaf7f86SDimitry Andric Register addLDSKernelId(); 7585f757f3fSDimitry Andric SmallVectorImpl<MCRegister> * 7595f757f3fSDimitry Andric addPreloadedKernArg(const SIRegisterInfo &TRI, const TargetRegisterClass *RC, 7605f757f3fSDimitry Andric unsigned AllocSizeDWord, int KernArgIdx, 7615f757f3fSDimitry Andric int PaddingSGPRs); 7620b57cec5SDimitry Andric 76381ad6265SDimitry Andric /// Increment user SGPRs used for padding the argument list only. 76481ad6265SDimitry Andric Register addReservedUserSGPR() { 76581ad6265SDimitry Andric Register Next = getNextUserSGPR(); 76681ad6265SDimitry Andric ++NumUserSGPRs; 76781ad6265SDimitry Andric return Next; 76881ad6265SDimitry Andric } 76981ad6265SDimitry Andric 7700b57cec5SDimitry Andric // Add system SGPRs. 771b3edf446SDimitry Andric Register addWorkGroupIDX() { 772b3edf446SDimitry Andric ArgInfo.WorkGroupIDX = ArgDescriptor::createRegister(getNextSystemSGPR()); 7730b57cec5SDimitry Andric NumSystemSGPRs += 1; 7740b57cec5SDimitry Andric return ArgInfo.WorkGroupIDX.getRegister(); 7750b57cec5SDimitry Andric } 7760b57cec5SDimitry Andric 777b3edf446SDimitry Andric Register addWorkGroupIDY() { 778b3edf446SDimitry Andric ArgInfo.WorkGroupIDY = ArgDescriptor::createRegister(getNextSystemSGPR()); 7790b57cec5SDimitry Andric NumSystemSGPRs += 1; 7800b57cec5SDimitry Andric return ArgInfo.WorkGroupIDY.getRegister(); 7810b57cec5SDimitry Andric } 7820b57cec5SDimitry Andric 783b3edf446SDimitry Andric Register addWorkGroupIDZ() { 784b3edf446SDimitry Andric ArgInfo.WorkGroupIDZ = ArgDescriptor::createRegister(getNextSystemSGPR()); 7850b57cec5SDimitry Andric NumSystemSGPRs += 1; 7860b57cec5SDimitry Andric return ArgInfo.WorkGroupIDZ.getRegister(); 7870b57cec5SDimitry Andric } 7880b57cec5SDimitry Andric 7895ffd83dbSDimitry Andric Register addWorkGroupInfo() { 7900b57cec5SDimitry Andric ArgInfo.WorkGroupInfo = ArgDescriptor::createRegister(getNextSystemSGPR()); 7910b57cec5SDimitry Andric NumSystemSGPRs += 1; 7920b57cec5SDimitry Andric return ArgInfo.WorkGroupInfo.getRegister(); 7930b57cec5SDimitry Andric } 7940b57cec5SDimitry Andric 7955f757f3fSDimitry Andric bool hasLDSKernelId() const { return LDSKernelId; } 7965f757f3fSDimitry Andric 7970b57cec5SDimitry Andric // Add special VGPR inputs 7980b57cec5SDimitry Andric void setWorkItemIDX(ArgDescriptor Arg) { 7990b57cec5SDimitry Andric ArgInfo.WorkItemIDX = Arg; 8000b57cec5SDimitry Andric } 8010b57cec5SDimitry Andric 8020b57cec5SDimitry Andric void setWorkItemIDY(ArgDescriptor Arg) { 8030b57cec5SDimitry Andric ArgInfo.WorkItemIDY = Arg; 8040b57cec5SDimitry Andric } 8050b57cec5SDimitry Andric 8060b57cec5SDimitry Andric void setWorkItemIDZ(ArgDescriptor Arg) { 8070b57cec5SDimitry Andric ArgInfo.WorkItemIDZ = Arg; 8080b57cec5SDimitry Andric } 8090b57cec5SDimitry Andric 8105ffd83dbSDimitry Andric Register addPrivateSegmentWaveByteOffset() { 8110b57cec5SDimitry Andric ArgInfo.PrivateSegmentWaveByteOffset 8120b57cec5SDimitry Andric = ArgDescriptor::createRegister(getNextSystemSGPR()); 8130b57cec5SDimitry Andric NumSystemSGPRs += 1; 8140b57cec5SDimitry Andric return ArgInfo.PrivateSegmentWaveByteOffset.getRegister(); 8150b57cec5SDimitry Andric } 8160b57cec5SDimitry Andric 8175ffd83dbSDimitry Andric void setPrivateSegmentWaveByteOffset(Register Reg) { 8180b57cec5SDimitry Andric ArgInfo.PrivateSegmentWaveByteOffset = ArgDescriptor::createRegister(Reg); 8190b57cec5SDimitry Andric } 8200b57cec5SDimitry Andric 8210b57cec5SDimitry Andric bool hasWorkGroupIDX() const { 8220b57cec5SDimitry Andric return WorkGroupIDX; 8230b57cec5SDimitry Andric } 8240b57cec5SDimitry Andric 8250b57cec5SDimitry Andric bool hasWorkGroupIDY() const { 8260b57cec5SDimitry Andric return WorkGroupIDY; 8270b57cec5SDimitry Andric } 8280b57cec5SDimitry Andric 8290b57cec5SDimitry Andric bool hasWorkGroupIDZ() const { 8300b57cec5SDimitry Andric return WorkGroupIDZ; 8310b57cec5SDimitry Andric } 8320b57cec5SDimitry Andric 8330b57cec5SDimitry Andric bool hasWorkGroupInfo() const { 8340b57cec5SDimitry Andric return WorkGroupInfo; 8350b57cec5SDimitry Andric } 8360b57cec5SDimitry Andric 8370b57cec5SDimitry Andric bool hasPrivateSegmentWaveByteOffset() const { 8380b57cec5SDimitry Andric return PrivateSegmentWaveByteOffset; 8390b57cec5SDimitry Andric } 8400b57cec5SDimitry Andric 8410b57cec5SDimitry Andric bool hasWorkItemIDX() const { 8420b57cec5SDimitry Andric return WorkItemIDX; 8430b57cec5SDimitry Andric } 8440b57cec5SDimitry Andric 8450b57cec5SDimitry Andric bool hasWorkItemIDY() const { 8460b57cec5SDimitry Andric return WorkItemIDY; 8470b57cec5SDimitry Andric } 8480b57cec5SDimitry Andric 8490b57cec5SDimitry Andric bool hasWorkItemIDZ() const { 8500b57cec5SDimitry Andric return WorkItemIDZ; 8510b57cec5SDimitry Andric } 8520b57cec5SDimitry Andric 8530b57cec5SDimitry Andric bool hasImplicitArgPtr() const { 8540b57cec5SDimitry Andric return ImplicitArgPtr; 8550b57cec5SDimitry Andric } 8560b57cec5SDimitry Andric 8570b57cec5SDimitry Andric AMDGPUFunctionArgInfo &getArgInfo() { 8580b57cec5SDimitry Andric return ArgInfo; 8590b57cec5SDimitry Andric } 8600b57cec5SDimitry Andric 8610b57cec5SDimitry Andric const AMDGPUFunctionArgInfo &getArgInfo() const { 8620b57cec5SDimitry Andric return ArgInfo; 8630b57cec5SDimitry Andric } 8640b57cec5SDimitry Andric 8655ffd83dbSDimitry Andric std::tuple<const ArgDescriptor *, const TargetRegisterClass *, LLT> 8660b57cec5SDimitry Andric getPreloadedValue(AMDGPUFunctionArgInfo::PreloadedValue Value) const { 8670b57cec5SDimitry Andric return ArgInfo.getPreloadedValue(Value); 8680b57cec5SDimitry Andric } 8690b57cec5SDimitry Andric 870e8d8bef9SDimitry Andric MCRegister getPreloadedReg(AMDGPUFunctionArgInfo::PreloadedValue Value) const { 8715ffd83dbSDimitry Andric auto Arg = std::get<0>(ArgInfo.getPreloadedValue(Value)); 872e8d8bef9SDimitry Andric return Arg ? Arg->getRegister() : MCRegister(); 8730b57cec5SDimitry Andric } 8740b57cec5SDimitry Andric 8750b57cec5SDimitry Andric unsigned getGITPtrHigh() const { 8760b57cec5SDimitry Andric return GITPtrHigh; 8770b57cec5SDimitry Andric } 8780b57cec5SDimitry Andric 8795ffd83dbSDimitry Andric Register getGITPtrLoReg(const MachineFunction &MF) const; 8805ffd83dbSDimitry Andric 8818bcb0991SDimitry Andric uint32_t get32BitAddressHighBits() const { 8820b57cec5SDimitry Andric return HighBitsOf32BitAddress; 8830b57cec5SDimitry Andric } 8840b57cec5SDimitry Andric 8850b57cec5SDimitry Andric unsigned getNumUserSGPRs() const { 8860b57cec5SDimitry Andric return NumUserSGPRs; 8870b57cec5SDimitry Andric } 8880b57cec5SDimitry Andric 8890b57cec5SDimitry Andric unsigned getNumPreloadedSGPRs() const { 8900b57cec5SDimitry Andric return NumUserSGPRs + NumSystemSGPRs; 8910b57cec5SDimitry Andric } 8920b57cec5SDimitry Andric 8935f757f3fSDimitry Andric unsigned getNumKernargPreloadedSGPRs() const { 8945f757f3fSDimitry Andric return UserSGPRInfo.getNumKernargPreloadSGPRs(); 8955f757f3fSDimitry Andric } 8965f757f3fSDimitry Andric 8975ffd83dbSDimitry Andric Register getPrivateSegmentWaveByteOffsetSystemSGPR() const { 8980b57cec5SDimitry Andric return ArgInfo.PrivateSegmentWaveByteOffset.getRegister(); 8990b57cec5SDimitry Andric } 9000b57cec5SDimitry Andric 9010b57cec5SDimitry Andric /// Returns the physical register reserved for use as the resource 9020b57cec5SDimitry Andric /// descriptor for scratch accesses. 9035ffd83dbSDimitry Andric Register getScratchRSrcReg() const { 9040b57cec5SDimitry Andric return ScratchRSrcReg; 9050b57cec5SDimitry Andric } 9060b57cec5SDimitry Andric 9075ffd83dbSDimitry Andric void setScratchRSrcReg(Register Reg) { 9080b57cec5SDimitry Andric assert(Reg != 0 && "Should never be unset"); 9090b57cec5SDimitry Andric ScratchRSrcReg = Reg; 9100b57cec5SDimitry Andric } 9110b57cec5SDimitry Andric 9125ffd83dbSDimitry Andric Register getFrameOffsetReg() const { 9130b57cec5SDimitry Andric return FrameOffsetReg; 9140b57cec5SDimitry Andric } 9150b57cec5SDimitry Andric 9165ffd83dbSDimitry Andric void setFrameOffsetReg(Register Reg) { 9170b57cec5SDimitry Andric assert(Reg != 0 && "Should never be unset"); 9180b57cec5SDimitry Andric FrameOffsetReg = Reg; 9190b57cec5SDimitry Andric } 9200b57cec5SDimitry Andric 9215ffd83dbSDimitry Andric void setStackPtrOffsetReg(Register Reg) { 9220b57cec5SDimitry Andric assert(Reg != 0 && "Should never be unset"); 9230b57cec5SDimitry Andric StackPtrOffsetReg = Reg; 9240b57cec5SDimitry Andric } 9250b57cec5SDimitry Andric 92606c3fb27SDimitry Andric void setLongBranchReservedReg(Register Reg) { LongBranchReservedReg = Reg; } 92706c3fb27SDimitry Andric 9280b57cec5SDimitry Andric // Note the unset value for this is AMDGPU::SP_REG rather than 9290b57cec5SDimitry Andric // NoRegister. This is mostly a workaround for MIR tests where state that 9300b57cec5SDimitry Andric // can't be directly computed from the function is not preserved in serialized 9310b57cec5SDimitry Andric // MIR. 9325ffd83dbSDimitry Andric Register getStackPtrOffsetReg() const { 9330b57cec5SDimitry Andric return StackPtrOffsetReg; 9340b57cec5SDimitry Andric } 9350b57cec5SDimitry Andric 93606c3fb27SDimitry Andric Register getLongBranchReservedReg() const { return LongBranchReservedReg; } 93706c3fb27SDimitry Andric 9385ffd83dbSDimitry Andric Register getQueuePtrUserSGPR() const { 9390b57cec5SDimitry Andric return ArgInfo.QueuePtr.getRegister(); 9400b57cec5SDimitry Andric } 9410b57cec5SDimitry Andric 9425ffd83dbSDimitry Andric Register getImplicitBufferPtrUserSGPR() const { 9430b57cec5SDimitry Andric return ArgInfo.ImplicitBufferPtr.getRegister(); 9440b57cec5SDimitry Andric } 9450b57cec5SDimitry Andric 9460b57cec5SDimitry Andric bool hasSpilledSGPRs() const { 9470b57cec5SDimitry Andric return HasSpilledSGPRs; 9480b57cec5SDimitry Andric } 9490b57cec5SDimitry Andric 9500b57cec5SDimitry Andric void setHasSpilledSGPRs(bool Spill = true) { 9510b57cec5SDimitry Andric HasSpilledSGPRs = Spill; 9520b57cec5SDimitry Andric } 9530b57cec5SDimitry Andric 9540b57cec5SDimitry Andric bool hasSpilledVGPRs() const { 9550b57cec5SDimitry Andric return HasSpilledVGPRs; 9560b57cec5SDimitry Andric } 9570b57cec5SDimitry Andric 9580b57cec5SDimitry Andric void setHasSpilledVGPRs(bool Spill = true) { 9590b57cec5SDimitry Andric HasSpilledVGPRs = Spill; 9600b57cec5SDimitry Andric } 9610b57cec5SDimitry Andric 9620b57cec5SDimitry Andric bool hasNonSpillStackObjects() const { 9630b57cec5SDimitry Andric return HasNonSpillStackObjects; 9640b57cec5SDimitry Andric } 9650b57cec5SDimitry Andric 9660b57cec5SDimitry Andric void setHasNonSpillStackObjects(bool StackObject = true) { 9670b57cec5SDimitry Andric HasNonSpillStackObjects = StackObject; 9680b57cec5SDimitry Andric } 9690b57cec5SDimitry Andric 9700b57cec5SDimitry Andric bool isStackRealigned() const { 9710b57cec5SDimitry Andric return IsStackRealigned; 9720b57cec5SDimitry Andric } 9730b57cec5SDimitry Andric 9740b57cec5SDimitry Andric void setIsStackRealigned(bool Realigned = true) { 9750b57cec5SDimitry Andric IsStackRealigned = Realigned; 9760b57cec5SDimitry Andric } 9770b57cec5SDimitry Andric 9780b57cec5SDimitry Andric unsigned getNumSpilledSGPRs() const { 9790b57cec5SDimitry Andric return NumSpilledSGPRs; 9800b57cec5SDimitry Andric } 9810b57cec5SDimitry Andric 9820b57cec5SDimitry Andric unsigned getNumSpilledVGPRs() const { 9830b57cec5SDimitry Andric return NumSpilledVGPRs; 9840b57cec5SDimitry Andric } 9850b57cec5SDimitry Andric 9860b57cec5SDimitry Andric void addToSpilledSGPRs(unsigned num) { 9870b57cec5SDimitry Andric NumSpilledSGPRs += num; 9880b57cec5SDimitry Andric } 9890b57cec5SDimitry Andric 9900b57cec5SDimitry Andric void addToSpilledVGPRs(unsigned num) { 9910b57cec5SDimitry Andric NumSpilledVGPRs += num; 9920b57cec5SDimitry Andric } 9930b57cec5SDimitry Andric 9940b57cec5SDimitry Andric unsigned getPSInputAddr() const { 9950b57cec5SDimitry Andric return PSInputAddr; 9960b57cec5SDimitry Andric } 9970b57cec5SDimitry Andric 9980b57cec5SDimitry Andric unsigned getPSInputEnable() const { 9990b57cec5SDimitry Andric return PSInputEnable; 10000b57cec5SDimitry Andric } 10010b57cec5SDimitry Andric 10020b57cec5SDimitry Andric bool isPSInputAllocated(unsigned Index) const { 10030b57cec5SDimitry Andric return PSInputAddr & (1 << Index); 10040b57cec5SDimitry Andric } 10050b57cec5SDimitry Andric 10060b57cec5SDimitry Andric void markPSInputAllocated(unsigned Index) { 10070b57cec5SDimitry Andric PSInputAddr |= 1 << Index; 10080b57cec5SDimitry Andric } 10090b57cec5SDimitry Andric 10100b57cec5SDimitry Andric void markPSInputEnabled(unsigned Index) { 10110b57cec5SDimitry Andric PSInputEnable |= 1 << Index; 10120b57cec5SDimitry Andric } 10130b57cec5SDimitry Andric 10140b57cec5SDimitry Andric bool returnsVoid() const { 10150b57cec5SDimitry Andric return ReturnsVoid; 10160b57cec5SDimitry Andric } 10170b57cec5SDimitry Andric 10180b57cec5SDimitry Andric void setIfReturnsVoid(bool Value) { 10190b57cec5SDimitry Andric ReturnsVoid = Value; 10200b57cec5SDimitry Andric } 10210b57cec5SDimitry Andric 10220b57cec5SDimitry Andric /// \returns A pair of default/requested minimum/maximum flat work group sizes 10230b57cec5SDimitry Andric /// for this function. 10240b57cec5SDimitry Andric std::pair<unsigned, unsigned> getFlatWorkGroupSizes() const { 10250b57cec5SDimitry Andric return FlatWorkGroupSizes; 10260b57cec5SDimitry Andric } 10270b57cec5SDimitry Andric 10280b57cec5SDimitry Andric /// \returns Default/requested minimum flat work group size for this function. 10290b57cec5SDimitry Andric unsigned getMinFlatWorkGroupSize() const { 10300b57cec5SDimitry Andric return FlatWorkGroupSizes.first; 10310b57cec5SDimitry Andric } 10320b57cec5SDimitry Andric 10330b57cec5SDimitry Andric /// \returns Default/requested maximum flat work group size for this function. 10340b57cec5SDimitry Andric unsigned getMaxFlatWorkGroupSize() const { 10350b57cec5SDimitry Andric return FlatWorkGroupSizes.second; 10360b57cec5SDimitry Andric } 10370b57cec5SDimitry Andric 10380b57cec5SDimitry Andric /// \returns A pair of default/requested minimum/maximum number of waves per 10390b57cec5SDimitry Andric /// execution unit. 10400b57cec5SDimitry Andric std::pair<unsigned, unsigned> getWavesPerEU() const { 10410b57cec5SDimitry Andric return WavesPerEU; 10420b57cec5SDimitry Andric } 10430b57cec5SDimitry Andric 10440b57cec5SDimitry Andric /// \returns Default/requested minimum number of waves per execution unit. 10450b57cec5SDimitry Andric unsigned getMinWavesPerEU() const { 10460b57cec5SDimitry Andric return WavesPerEU.first; 10470b57cec5SDimitry Andric } 10480b57cec5SDimitry Andric 10490b57cec5SDimitry Andric /// \returns Default/requested maximum number of waves per execution unit. 10500b57cec5SDimitry Andric unsigned getMaxWavesPerEU() const { 10510b57cec5SDimitry Andric return WavesPerEU.second; 10520b57cec5SDimitry Andric } 10530b57cec5SDimitry Andric 105481ad6265SDimitry Andric const AMDGPUGWSResourcePseudoSourceValue * 105581ad6265SDimitry Andric getGWSPSV(const AMDGPUTargetMachine &TM) { 105681ad6265SDimitry Andric return &GWSResourcePSV; 10570b57cec5SDimitry Andric } 10580b57cec5SDimitry Andric 10590b57cec5SDimitry Andric unsigned getOccupancy() const { 10600b57cec5SDimitry Andric return Occupancy; 10610b57cec5SDimitry Andric } 10620b57cec5SDimitry Andric 10630b57cec5SDimitry Andric unsigned getMinAllowedOccupancy() const { 10640b57cec5SDimitry Andric if (!isMemoryBound() && !needsWaveLimiter()) 10650b57cec5SDimitry Andric return Occupancy; 10660b57cec5SDimitry Andric return (Occupancy < 4) ? Occupancy : 4; 10670b57cec5SDimitry Andric } 10680b57cec5SDimitry Andric 10690b57cec5SDimitry Andric void limitOccupancy(const MachineFunction &MF); 10700b57cec5SDimitry Andric 10710b57cec5SDimitry Andric void limitOccupancy(unsigned Limit) { 10720b57cec5SDimitry Andric if (Occupancy > Limit) 10730b57cec5SDimitry Andric Occupancy = Limit; 10740b57cec5SDimitry Andric } 10750b57cec5SDimitry Andric 10760b57cec5SDimitry Andric void increaseOccupancy(const MachineFunction &MF, unsigned Limit) { 10770b57cec5SDimitry Andric if (Occupancy < Limit) 10780b57cec5SDimitry Andric Occupancy = Limit; 10790b57cec5SDimitry Andric limitOccupancy(MF); 10800b57cec5SDimitry Andric } 1081349cc55cSDimitry Andric 108281ad6265SDimitry Andric bool mayNeedAGPRs() const { 108381ad6265SDimitry Andric return MayNeedAGPRs; 108481ad6265SDimitry Andric } 108581ad6265SDimitry Andric 108681ad6265SDimitry Andric // \returns true if a function has a use of AGPRs via inline asm or 108781ad6265SDimitry Andric // has a call which may use it. 1088bdd1243dSDimitry Andric bool mayUseAGPRs(const Function &F) const; 108981ad6265SDimitry Andric 1090349cc55cSDimitry Andric // \returns true if a function needs or may need AGPRs. 1091349cc55cSDimitry Andric bool usesAGPRs(const MachineFunction &MF) const; 1092*0fca6ea1SDimitry Andric 1093*0fca6ea1SDimitry Andric /// \returns Default/requested number of work groups for this function. 1094*0fca6ea1SDimitry Andric SmallVector<unsigned> getMaxNumWorkGroups() const { return MaxNumWorkGroups; } 1095*0fca6ea1SDimitry Andric 1096*0fca6ea1SDimitry Andric unsigned getMaxNumWorkGroupsX() const { return MaxNumWorkGroups[0]; } 1097*0fca6ea1SDimitry Andric unsigned getMaxNumWorkGroupsY() const { return MaxNumWorkGroups[1]; } 1098*0fca6ea1SDimitry Andric unsigned getMaxNumWorkGroupsZ() const { return MaxNumWorkGroups[2]; } 10990b57cec5SDimitry Andric }; 11000b57cec5SDimitry Andric 11010b57cec5SDimitry Andric } // end namespace llvm 11020b57cec5SDimitry Andric 11030b57cec5SDimitry Andric #endif // LLVM_LIB_TARGET_AMDGPU_SIMACHINEFUNCTIONINFO_H 1104