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" 19*5f757f3fSDimitry 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" 24*5f757f3fSDimitry 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; 261*5f757f3fSDimitry 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); 310*5f757f3fSDimitry 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 4290b57cec5SDimitry Andric private: 4300b57cec5SDimitry Andric unsigned NumUserSGPRs = 0; 4310b57cec5SDimitry Andric unsigned NumSystemSGPRs = 0; 4320b57cec5SDimitry Andric 4330b57cec5SDimitry Andric bool HasSpilledSGPRs = false; 4340b57cec5SDimitry Andric bool HasSpilledVGPRs = false; 4350b57cec5SDimitry Andric bool HasNonSpillStackObjects = false; 4360b57cec5SDimitry Andric bool IsStackRealigned = false; 4370b57cec5SDimitry Andric 4380b57cec5SDimitry Andric unsigned NumSpilledSGPRs = 0; 4390b57cec5SDimitry Andric unsigned NumSpilledVGPRs = 0; 4400b57cec5SDimitry Andric 441*5f757f3fSDimitry Andric // Tracks information about user SGPRs that will be setup by hardware which 442*5f757f3fSDimitry Andric // will apply to all wavefronts of the grid. 443*5f757f3fSDimitry Andric GCNUserSGPRUsageInfo UserSGPRInfo; 4440b57cec5SDimitry Andric 4450b57cec5SDimitry Andric // Feature bits required for inputs passed in system SGPRs. 4460b57cec5SDimitry Andric bool WorkGroupIDX : 1; // Always initialized. 4470b57cec5SDimitry Andric bool WorkGroupIDY : 1; 4480b57cec5SDimitry Andric bool WorkGroupIDZ : 1; 4490b57cec5SDimitry Andric bool WorkGroupInfo : 1; 450fcaf7f86SDimitry Andric bool LDSKernelId : 1; 4510b57cec5SDimitry Andric bool PrivateSegmentWaveByteOffset : 1; 4520b57cec5SDimitry Andric 4530b57cec5SDimitry Andric bool WorkItemIDX : 1; // Always initialized. 4540b57cec5SDimitry Andric bool WorkItemIDY : 1; 4550b57cec5SDimitry Andric bool WorkItemIDZ : 1; 4560b57cec5SDimitry Andric 4570b57cec5SDimitry Andric // Pointer to where the ABI inserts special kernel arguments separate from the 4580b57cec5SDimitry Andric // user arguments. This is an offset from the KernargSegmentPtr. 4590b57cec5SDimitry Andric bool ImplicitArgPtr : 1; 4600b57cec5SDimitry Andric 46181ad6265SDimitry Andric bool MayNeedAGPRs : 1; 46281ad6265SDimitry Andric 4630b57cec5SDimitry Andric // The hard-wired high half of the address of the global information table 4640b57cec5SDimitry Andric // for AMDPAL OS type. 0xffffffff represents no hard-wired high half, since 4650b57cec5SDimitry Andric // current hardware only allows a 16 bit value. 4660b57cec5SDimitry Andric unsigned GITPtrHigh; 4670b57cec5SDimitry Andric 4680b57cec5SDimitry Andric unsigned HighBitsOf32BitAddress; 4690b57cec5SDimitry Andric 47006c3fb27SDimitry Andric // Flags associated with the virtual registers. 47106c3fb27SDimitry Andric IndexedMap<uint8_t, VirtReg2IndexFunctor> VRegFlags; 47206c3fb27SDimitry Andric 4730b57cec5SDimitry Andric // Current recorded maximum possible occupancy. 4740b57cec5SDimitry Andric unsigned Occupancy; 4750b57cec5SDimitry Andric 476bdd1243dSDimitry Andric mutable std::optional<bool> UsesAGPRs; 477349cc55cSDimitry Andric 4780b57cec5SDimitry Andric MCPhysReg getNextUserSGPR() const; 4790b57cec5SDimitry Andric 4800b57cec5SDimitry Andric MCPhysReg getNextSystemSGPR() const; 4810b57cec5SDimitry Andric 48206c3fb27SDimitry Andric // MachineRegisterInfo callback functions to notify events. 48306c3fb27SDimitry Andric void MRI_NoteNewVirtualRegister(Register Reg) override; 48406c3fb27SDimitry Andric void MRI_NoteCloneVirtualRegister(Register NewReg, Register SrcReg) override; 48506c3fb27SDimitry Andric 4860b57cec5SDimitry Andric public: 4870b57cec5SDimitry Andric struct VGPRSpillToAGPR { 4880b57cec5SDimitry Andric SmallVector<MCPhysReg, 32> Lanes; 4890b57cec5SDimitry Andric bool FullyAllocated = false; 4900eae32dcSDimitry Andric bool IsDead = false; 4910b57cec5SDimitry Andric }; 4920b57cec5SDimitry Andric 4930b57cec5SDimitry Andric private: 494*5f757f3fSDimitry Andric // To track virtual VGPR + lane index for each subregister of the SGPR spilled 495*5f757f3fSDimitry Andric // to frameindex key during SILowerSGPRSpills pass. 496bdd1243dSDimitry Andric DenseMap<int, std::vector<SIRegisterInfo::SpilledReg>> 497*5f757f3fSDimitry Andric SGPRSpillsToVirtualVGPRLanes; 498*5f757f3fSDimitry Andric // To track physical VGPR + lane index for CSR SGPR spills and special SGPRs 499*5f757f3fSDimitry Andric // like Frame Pointer identified during PrologEpilogInserter. 500*5f757f3fSDimitry Andric DenseMap<int, std::vector<SIRegisterInfo::SpilledReg>> 501*5f757f3fSDimitry Andric SGPRSpillsToPhysicalVGPRLanes; 502*5f757f3fSDimitry Andric unsigned NumVirtualVGPRSpillLanes = 0; 503*5f757f3fSDimitry Andric unsigned NumPhysicalVGPRSpillLanes = 0; 504bdd1243dSDimitry Andric SmallVector<Register, 2> SpillVGPRs; 505*5f757f3fSDimitry Andric SmallVector<Register, 2> SpillPhysVGPRs; 506bdd1243dSDimitry Andric using WWMSpillsMap = MapVector<Register, int>; 507bdd1243dSDimitry Andric // To track the registers used in instructions that can potentially modify the 508bdd1243dSDimitry Andric // inactive lanes. The WWM instructions and the writelane instructions for 509bdd1243dSDimitry Andric // spilling SGPRs to VGPRs fall under such category of operations. The VGPRs 510bdd1243dSDimitry Andric // modified by them should be spilled/restored at function prolog/epilog to 511bdd1243dSDimitry Andric // avoid any undesired outcome. Each entry in this map holds a pair of values, 512bdd1243dSDimitry Andric // the VGPR and its stack slot index. 513bdd1243dSDimitry Andric WWMSpillsMap WWMSpills; 514bdd1243dSDimitry Andric 515bdd1243dSDimitry Andric using ReservedRegSet = SmallSetVector<Register, 8>; 516bdd1243dSDimitry Andric // To track the VGPRs reserved for WWM instructions. They get stack slots 517bdd1243dSDimitry Andric // later during PrologEpilogInserter and get added into the superset WWMSpills 518bdd1243dSDimitry Andric // for actual spilling. A separate set makes the register reserved part and 519bdd1243dSDimitry Andric // the serialization easier. 520bdd1243dSDimitry Andric ReservedRegSet WWMReservedRegs; 521bdd1243dSDimitry Andric 522bdd1243dSDimitry Andric using PrologEpilogSGPRSpillsMap = 523bdd1243dSDimitry Andric DenseMap<Register, PrologEpilogSGPRSaveRestoreInfo>; 524bdd1243dSDimitry Andric // To track the SGPR spill method used for a CSR SGPR register during 525bdd1243dSDimitry Andric // frame lowering. Even though the SGPR spills are handled during 526bdd1243dSDimitry Andric // SILowerSGPRSpills pass, some special handling needed later during the 527bdd1243dSDimitry Andric // PrologEpilogInserter. 528bdd1243dSDimitry Andric PrologEpilogSGPRSpillsMap PrologEpilogSGPRSpills; 5290b57cec5SDimitry Andric 53006c3fb27SDimitry Andric // To save/restore EXEC MASK around WWM spills and copies. 53106c3fb27SDimitry Andric Register SGPRForEXECCopy; 53206c3fb27SDimitry Andric 5330b57cec5SDimitry Andric DenseMap<int, VGPRSpillToAGPR> VGPRToAGPRSpills; 5340b57cec5SDimitry Andric 5350b57cec5SDimitry Andric // AGPRs used for VGPR spills. 5360b57cec5SDimitry Andric SmallVector<MCPhysReg, 32> SpillAGPR; 5370b57cec5SDimitry Andric 5380b57cec5SDimitry Andric // VGPRs used for AGPR spills. 5390b57cec5SDimitry Andric SmallVector<MCPhysReg, 32> SpillVGPR; 5400b57cec5SDimitry Andric 541fe6060f1SDimitry Andric // Emergency stack slot. Sometimes, we create this before finalizing the stack 542fe6060f1SDimitry Andric // frame, so save it here and add it to the RegScavenger later. 543bdd1243dSDimitry Andric std::optional<int> ScavengeFI; 544fe6060f1SDimitry Andric 54581ad6265SDimitry Andric private: 54681ad6265SDimitry Andric Register VGPRForAGPRCopy; 54781ad6265SDimitry Andric 548*5f757f3fSDimitry Andric bool allocateVirtualVGPRForSGPRSpills(MachineFunction &MF, int FI, 549bdd1243dSDimitry Andric unsigned LaneIndex); 550*5f757f3fSDimitry Andric bool allocatePhysicalVGPRForSGPRSpills(MachineFunction &MF, int FI, 551bdd1243dSDimitry Andric unsigned LaneIndex); 552bdd1243dSDimitry Andric 55381ad6265SDimitry Andric public: 55481ad6265SDimitry Andric Register getVGPRForAGPRCopy() const { 55581ad6265SDimitry Andric return VGPRForAGPRCopy; 55681ad6265SDimitry Andric } 55781ad6265SDimitry Andric 55881ad6265SDimitry Andric void setVGPRForAGPRCopy(Register NewVGPRForAGPRCopy) { 55981ad6265SDimitry Andric VGPRForAGPRCopy = NewVGPRForAGPRCopy; 56081ad6265SDimitry Andric } 56181ad6265SDimitry Andric 562bdd1243dSDimitry Andric bool isCalleeSavedReg(const MCPhysReg *CSRegs, MCPhysReg Reg) const; 5635ffd83dbSDimitry Andric 5640b57cec5SDimitry Andric public: 56581ad6265SDimitry Andric SIMachineFunctionInfo(const SIMachineFunctionInfo &MFI) = default; 566bdd1243dSDimitry Andric SIMachineFunctionInfo(const Function &F, const GCNSubtarget *STI); 56781ad6265SDimitry Andric 56881ad6265SDimitry Andric MachineFunctionInfo * 56981ad6265SDimitry Andric clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF, 57081ad6265SDimitry Andric const DenseMap<MachineBasicBlock *, MachineBasicBlock *> &Src2DstMBB) 57181ad6265SDimitry Andric const override; 5720b57cec5SDimitry Andric 573fe6060f1SDimitry Andric bool initializeBaseYamlFields(const yaml::SIMachineFunctionInfo &YamlMFI, 574fe6060f1SDimitry Andric const MachineFunction &MF, 575fe6060f1SDimitry Andric PerFunctionMIParsingState &PFS, 576fe6060f1SDimitry Andric SMDiagnostic &Error, SMRange &SourceRange); 577fe6060f1SDimitry Andric 578bdd1243dSDimitry Andric void reserveWWMRegister(Register Reg) { WWMReservedRegs.insert(Reg); } 579bdd1243dSDimitry Andric 58006c3fb27SDimitry Andric SIModeRegisterDefaults getMode() const { return Mode; } 5810b57cec5SDimitry Andric 58281ad6265SDimitry Andric ArrayRef<SIRegisterInfo::SpilledReg> 583*5f757f3fSDimitry Andric getSGPRSpillToVirtualVGPRLanes(int FrameIndex) const { 584*5f757f3fSDimitry Andric auto I = SGPRSpillsToVirtualVGPRLanes.find(FrameIndex); 585*5f757f3fSDimitry Andric return (I == SGPRSpillsToVirtualVGPRLanes.end()) 58681ad6265SDimitry Andric ? ArrayRef<SIRegisterInfo::SpilledReg>() 587bdd1243dSDimitry Andric : ArrayRef(I->second); 5880b57cec5SDimitry Andric } 5890b57cec5SDimitry Andric 590bdd1243dSDimitry Andric ArrayRef<Register> getSGPRSpillVGPRs() const { return SpillVGPRs; } 591bdd1243dSDimitry Andric const WWMSpillsMap &getWWMSpills() const { return WWMSpills; } 592bdd1243dSDimitry Andric const ReservedRegSet &getWWMReservedRegs() const { return WWMReservedRegs; } 593bdd1243dSDimitry Andric 594bdd1243dSDimitry Andric const PrologEpilogSGPRSpillsMap &getPrologEpilogSGPRSpills() const { 595bdd1243dSDimitry Andric return PrologEpilogSGPRSpills; 596bdd1243dSDimitry Andric } 597bdd1243dSDimitry Andric 598*5f757f3fSDimitry Andric GCNUserSGPRUsageInfo &getUserSGPRInfo() { return UserSGPRInfo; } 599*5f757f3fSDimitry Andric 600*5f757f3fSDimitry Andric const GCNUserSGPRUsageInfo &getUserSGPRInfo() const { return UserSGPRInfo; } 601*5f757f3fSDimitry Andric 602bdd1243dSDimitry Andric void addToPrologEpilogSGPRSpills(Register Reg, 603bdd1243dSDimitry Andric PrologEpilogSGPRSaveRestoreInfo SI) { 604bdd1243dSDimitry Andric PrologEpilogSGPRSpills.insert(std::make_pair(Reg, SI)); 605bdd1243dSDimitry Andric } 606bdd1243dSDimitry Andric 607bdd1243dSDimitry Andric // Check if an entry created for \p Reg in PrologEpilogSGPRSpills. Return true 608bdd1243dSDimitry Andric // on success and false otherwise. 609bdd1243dSDimitry Andric bool hasPrologEpilogSGPRSpillEntry(Register Reg) const { 61006c3fb27SDimitry Andric return PrologEpilogSGPRSpills.contains(Reg); 611bdd1243dSDimitry Andric } 612bdd1243dSDimitry Andric 613bdd1243dSDimitry Andric // Get the scratch SGPR if allocated to save/restore \p Reg. 614bdd1243dSDimitry Andric Register getScratchSGPRCopyDstReg(Register Reg) const { 615bdd1243dSDimitry Andric auto I = PrologEpilogSGPRSpills.find(Reg); 616bdd1243dSDimitry Andric if (I != PrologEpilogSGPRSpills.end() && 617bdd1243dSDimitry Andric I->second.getKind() == SGPRSaveKind::COPY_TO_SCRATCH_SGPR) 618bdd1243dSDimitry Andric return I->second.getReg(); 619bdd1243dSDimitry Andric 620bdd1243dSDimitry Andric return AMDGPU::NoRegister; 621bdd1243dSDimitry Andric } 622bdd1243dSDimitry Andric 623bdd1243dSDimitry Andric // Get all scratch SGPRs allocated to copy/restore the SGPR spills. 624bdd1243dSDimitry Andric void getAllScratchSGPRCopyDstRegs(SmallVectorImpl<Register> &Regs) const { 625bdd1243dSDimitry Andric for (const auto &SI : PrologEpilogSGPRSpills) { 626bdd1243dSDimitry Andric if (SI.second.getKind() == SGPRSaveKind::COPY_TO_SCRATCH_SGPR) 627bdd1243dSDimitry Andric Regs.push_back(SI.second.getReg()); 628bdd1243dSDimitry Andric } 629bdd1243dSDimitry Andric } 630bdd1243dSDimitry Andric 631bdd1243dSDimitry Andric // Check if \p FI is allocated for any SGPR spill to a VGPR lane during PEI. 632bdd1243dSDimitry Andric bool checkIndexInPrologEpilogSGPRSpills(int FI) const { 633bdd1243dSDimitry Andric return find_if(PrologEpilogSGPRSpills, 634bdd1243dSDimitry Andric [FI](const std::pair<Register, 635bdd1243dSDimitry Andric PrologEpilogSGPRSaveRestoreInfo> &SI) { 636bdd1243dSDimitry Andric return SI.second.getKind() == 637bdd1243dSDimitry Andric SGPRSaveKind::SPILL_TO_VGPR_LANE && 638bdd1243dSDimitry Andric SI.second.getIndex() == FI; 639bdd1243dSDimitry Andric }) != PrologEpilogSGPRSpills.end(); 640bdd1243dSDimitry Andric } 641bdd1243dSDimitry Andric 642bdd1243dSDimitry Andric const PrologEpilogSGPRSaveRestoreInfo & 643bdd1243dSDimitry Andric getPrologEpilogSGPRSaveRestoreInfo(Register Reg) const { 644bdd1243dSDimitry Andric auto I = PrologEpilogSGPRSpills.find(Reg); 645bdd1243dSDimitry Andric assert(I != PrologEpilogSGPRSpills.end()); 646bdd1243dSDimitry Andric 647bdd1243dSDimitry Andric return I->second; 648bdd1243dSDimitry Andric } 649bdd1243dSDimitry Andric 650bdd1243dSDimitry Andric ArrayRef<SIRegisterInfo::SpilledReg> 651*5f757f3fSDimitry Andric getSGPRSpillToPhysicalVGPRLanes(int FrameIndex) const { 652*5f757f3fSDimitry Andric auto I = SGPRSpillsToPhysicalVGPRLanes.find(FrameIndex); 653*5f757f3fSDimitry Andric return (I == SGPRSpillsToPhysicalVGPRLanes.end()) 654bdd1243dSDimitry Andric ? ArrayRef<SIRegisterInfo::SpilledReg>() 655bdd1243dSDimitry Andric : ArrayRef(I->second); 656bdd1243dSDimitry Andric } 657bdd1243dSDimitry Andric 65806c3fb27SDimitry Andric void setFlag(Register Reg, uint8_t Flag) { 65906c3fb27SDimitry Andric assert(Reg.isVirtual()); 66006c3fb27SDimitry Andric if (VRegFlags.inBounds(Reg)) 66106c3fb27SDimitry Andric VRegFlags[Reg] |= Flag; 66206c3fb27SDimitry Andric } 66306c3fb27SDimitry Andric 66406c3fb27SDimitry Andric bool checkFlag(Register Reg, uint8_t Flag) const { 66506c3fb27SDimitry Andric if (Reg.isPhysical()) 66606c3fb27SDimitry Andric return false; 66706c3fb27SDimitry Andric 66806c3fb27SDimitry Andric return VRegFlags.inBounds(Reg) && VRegFlags[Reg] & Flag; 66906c3fb27SDimitry Andric } 67006c3fb27SDimitry Andric 671*5f757f3fSDimitry Andric bool hasVRegFlags() { return VRegFlags.size(); } 672*5f757f3fSDimitry Andric 673bdd1243dSDimitry Andric void allocateWWMSpill(MachineFunction &MF, Register VGPR, uint64_t Size = 4, 674bdd1243dSDimitry Andric Align Alignment = Align(4)); 675bdd1243dSDimitry Andric 676bdd1243dSDimitry Andric void splitWWMSpillRegisters( 677bdd1243dSDimitry Andric MachineFunction &MF, 678bdd1243dSDimitry Andric SmallVectorImpl<std::pair<Register, int>> &CalleeSavedRegs, 679bdd1243dSDimitry Andric SmallVectorImpl<std::pair<Register, int>> &ScratchRegs) const; 6800b57cec5SDimitry Andric 6810b57cec5SDimitry Andric ArrayRef<MCPhysReg> getAGPRSpillVGPRs() const { 6820b57cec5SDimitry Andric return SpillAGPR; 6830b57cec5SDimitry Andric } 6840b57cec5SDimitry Andric 68506c3fb27SDimitry Andric Register getSGPRForEXECCopy() const { return SGPRForEXECCopy; } 68606c3fb27SDimitry Andric 68706c3fb27SDimitry Andric void setSGPRForEXECCopy(Register Reg) { SGPRForEXECCopy = Reg; } 68806c3fb27SDimitry Andric 6890b57cec5SDimitry Andric ArrayRef<MCPhysReg> getVGPRSpillAGPRs() const { 6900b57cec5SDimitry Andric return SpillVGPR; 6910b57cec5SDimitry Andric } 6920b57cec5SDimitry Andric 6930b57cec5SDimitry Andric MCPhysReg getVGPRToAGPRSpill(int FrameIndex, unsigned Lane) const { 6940b57cec5SDimitry Andric auto I = VGPRToAGPRSpills.find(FrameIndex); 6950b57cec5SDimitry Andric return (I == VGPRToAGPRSpills.end()) ? (MCPhysReg)AMDGPU::NoRegister 6960b57cec5SDimitry Andric : I->second.Lanes[Lane]; 6970b57cec5SDimitry Andric } 6980b57cec5SDimitry Andric 6990eae32dcSDimitry Andric void setVGPRToAGPRSpillDead(int FrameIndex) { 7000eae32dcSDimitry Andric auto I = VGPRToAGPRSpills.find(FrameIndex); 7010eae32dcSDimitry Andric if (I != VGPRToAGPRSpills.end()) 7020eae32dcSDimitry Andric I->second.IsDead = true; 7030eae32dcSDimitry Andric } 7040eae32dcSDimitry Andric 705bdd1243dSDimitry Andric bool allocateSGPRSpillToVGPRLane(MachineFunction &MF, int FI, 706bdd1243dSDimitry Andric bool IsPrologEpilog = false); 7070b57cec5SDimitry Andric bool allocateVGPRSpillToAGPR(MachineFunction &MF, int FI, bool isAGPRtoVGPR); 70881ad6265SDimitry Andric 70981ad6265SDimitry Andric /// If \p ResetSGPRSpillStackIDs is true, reset the stack ID from sgpr-spill 71081ad6265SDimitry Andric /// to the default stack. 71181ad6265SDimitry Andric bool removeDeadFrameIndices(MachineFrameInfo &MFI, 71281ad6265SDimitry Andric bool ResetSGPRSpillStackIDs); 7130b57cec5SDimitry Andric 714fe6060f1SDimitry Andric int getScavengeFI(MachineFrameInfo &MFI, const SIRegisterInfo &TRI); 715bdd1243dSDimitry Andric std::optional<int> getOptionalScavengeFI() const { return ScavengeFI; } 716fe6060f1SDimitry Andric 7170b57cec5SDimitry Andric unsigned getBytesInStackArgArea() const { 7180b57cec5SDimitry Andric return BytesInStackArgArea; 7190b57cec5SDimitry Andric } 7200b57cec5SDimitry Andric 7210b57cec5SDimitry Andric void setBytesInStackArgArea(unsigned Bytes) { 7220b57cec5SDimitry Andric BytesInStackArgArea = Bytes; 7230b57cec5SDimitry Andric } 7240b57cec5SDimitry Andric 7250b57cec5SDimitry Andric // Add user SGPRs. 7265ffd83dbSDimitry Andric Register addPrivateSegmentBuffer(const SIRegisterInfo &TRI); 7275ffd83dbSDimitry Andric Register addDispatchPtr(const SIRegisterInfo &TRI); 7285ffd83dbSDimitry Andric Register addQueuePtr(const SIRegisterInfo &TRI); 7295ffd83dbSDimitry Andric Register addKernargSegmentPtr(const SIRegisterInfo &TRI); 7305ffd83dbSDimitry Andric Register addDispatchID(const SIRegisterInfo &TRI); 7315ffd83dbSDimitry Andric Register addFlatScratchInit(const SIRegisterInfo &TRI); 7325ffd83dbSDimitry Andric Register addImplicitBufferPtr(const SIRegisterInfo &TRI); 733fcaf7f86SDimitry Andric Register addLDSKernelId(); 734*5f757f3fSDimitry Andric SmallVectorImpl<MCRegister> * 735*5f757f3fSDimitry Andric addPreloadedKernArg(const SIRegisterInfo &TRI, const TargetRegisterClass *RC, 736*5f757f3fSDimitry Andric unsigned AllocSizeDWord, int KernArgIdx, 737*5f757f3fSDimitry Andric int PaddingSGPRs); 7380b57cec5SDimitry Andric 73981ad6265SDimitry Andric /// Increment user SGPRs used for padding the argument list only. 74081ad6265SDimitry Andric Register addReservedUserSGPR() { 74181ad6265SDimitry Andric Register Next = getNextUserSGPR(); 74281ad6265SDimitry Andric ++NumUserSGPRs; 74381ad6265SDimitry Andric return Next; 74481ad6265SDimitry Andric } 74581ad6265SDimitry Andric 7460b57cec5SDimitry Andric // Add system SGPRs. 74706c3fb27SDimitry Andric Register addWorkGroupIDX(bool HasArchitectedSGPRs) { 74806c3fb27SDimitry Andric Register Reg = 74906c3fb27SDimitry Andric HasArchitectedSGPRs ? (MCPhysReg)AMDGPU::TTMP9 : getNextSystemSGPR(); 75006c3fb27SDimitry Andric ArgInfo.WorkGroupIDX = ArgDescriptor::createRegister(Reg); 75106c3fb27SDimitry Andric if (!HasArchitectedSGPRs) 7520b57cec5SDimitry Andric NumSystemSGPRs += 1; 75306c3fb27SDimitry Andric 7540b57cec5SDimitry Andric return ArgInfo.WorkGroupIDX.getRegister(); 7550b57cec5SDimitry Andric } 7560b57cec5SDimitry Andric 75706c3fb27SDimitry Andric Register addWorkGroupIDY(bool HasArchitectedSGPRs) { 75806c3fb27SDimitry Andric Register Reg = 75906c3fb27SDimitry Andric HasArchitectedSGPRs ? (MCPhysReg)AMDGPU::TTMP7 : getNextSystemSGPR(); 76006c3fb27SDimitry Andric unsigned Mask = HasArchitectedSGPRs && hasWorkGroupIDZ() ? 0xffff : ~0u; 76106c3fb27SDimitry Andric ArgInfo.WorkGroupIDY = ArgDescriptor::createRegister(Reg, Mask); 76206c3fb27SDimitry Andric if (!HasArchitectedSGPRs) 7630b57cec5SDimitry Andric NumSystemSGPRs += 1; 76406c3fb27SDimitry Andric 7650b57cec5SDimitry Andric return ArgInfo.WorkGroupIDY.getRegister(); 7660b57cec5SDimitry Andric } 7670b57cec5SDimitry Andric 76806c3fb27SDimitry Andric Register addWorkGroupIDZ(bool HasArchitectedSGPRs) { 76906c3fb27SDimitry Andric Register Reg = 77006c3fb27SDimitry Andric HasArchitectedSGPRs ? (MCPhysReg)AMDGPU::TTMP7 : getNextSystemSGPR(); 77106c3fb27SDimitry Andric unsigned Mask = HasArchitectedSGPRs ? 0xffff << 16 : ~0u; 77206c3fb27SDimitry Andric ArgInfo.WorkGroupIDZ = ArgDescriptor::createRegister(Reg, Mask); 77306c3fb27SDimitry Andric if (!HasArchitectedSGPRs) 7740b57cec5SDimitry Andric NumSystemSGPRs += 1; 77506c3fb27SDimitry Andric 7760b57cec5SDimitry Andric return ArgInfo.WorkGroupIDZ.getRegister(); 7770b57cec5SDimitry Andric } 7780b57cec5SDimitry Andric 7795ffd83dbSDimitry Andric Register addWorkGroupInfo() { 7800b57cec5SDimitry Andric ArgInfo.WorkGroupInfo = ArgDescriptor::createRegister(getNextSystemSGPR()); 7810b57cec5SDimitry Andric NumSystemSGPRs += 1; 7820b57cec5SDimitry Andric return ArgInfo.WorkGroupInfo.getRegister(); 7830b57cec5SDimitry Andric } 7840b57cec5SDimitry Andric 785*5f757f3fSDimitry Andric bool hasLDSKernelId() const { return LDSKernelId; } 786*5f757f3fSDimitry Andric 7870b57cec5SDimitry Andric // Add special VGPR inputs 7880b57cec5SDimitry Andric void setWorkItemIDX(ArgDescriptor Arg) { 7890b57cec5SDimitry Andric ArgInfo.WorkItemIDX = Arg; 7900b57cec5SDimitry Andric } 7910b57cec5SDimitry Andric 7920b57cec5SDimitry Andric void setWorkItemIDY(ArgDescriptor Arg) { 7930b57cec5SDimitry Andric ArgInfo.WorkItemIDY = Arg; 7940b57cec5SDimitry Andric } 7950b57cec5SDimitry Andric 7960b57cec5SDimitry Andric void setWorkItemIDZ(ArgDescriptor Arg) { 7970b57cec5SDimitry Andric ArgInfo.WorkItemIDZ = Arg; 7980b57cec5SDimitry Andric } 7990b57cec5SDimitry Andric 8005ffd83dbSDimitry Andric Register addPrivateSegmentWaveByteOffset() { 8010b57cec5SDimitry Andric ArgInfo.PrivateSegmentWaveByteOffset 8020b57cec5SDimitry Andric = ArgDescriptor::createRegister(getNextSystemSGPR()); 8030b57cec5SDimitry Andric NumSystemSGPRs += 1; 8040b57cec5SDimitry Andric return ArgInfo.PrivateSegmentWaveByteOffset.getRegister(); 8050b57cec5SDimitry Andric } 8060b57cec5SDimitry Andric 8075ffd83dbSDimitry Andric void setPrivateSegmentWaveByteOffset(Register Reg) { 8080b57cec5SDimitry Andric ArgInfo.PrivateSegmentWaveByteOffset = ArgDescriptor::createRegister(Reg); 8090b57cec5SDimitry Andric } 8100b57cec5SDimitry Andric 8110b57cec5SDimitry Andric bool hasWorkGroupIDX() const { 8120b57cec5SDimitry Andric return WorkGroupIDX; 8130b57cec5SDimitry Andric } 8140b57cec5SDimitry Andric 8150b57cec5SDimitry Andric bool hasWorkGroupIDY() const { 8160b57cec5SDimitry Andric return WorkGroupIDY; 8170b57cec5SDimitry Andric } 8180b57cec5SDimitry Andric 8190b57cec5SDimitry Andric bool hasWorkGroupIDZ() const { 8200b57cec5SDimitry Andric return WorkGroupIDZ; 8210b57cec5SDimitry Andric } 8220b57cec5SDimitry Andric 8230b57cec5SDimitry Andric bool hasWorkGroupInfo() const { 8240b57cec5SDimitry Andric return WorkGroupInfo; 8250b57cec5SDimitry Andric } 8260b57cec5SDimitry Andric 8270b57cec5SDimitry Andric bool hasPrivateSegmentWaveByteOffset() const { 8280b57cec5SDimitry Andric return PrivateSegmentWaveByteOffset; 8290b57cec5SDimitry Andric } 8300b57cec5SDimitry Andric 8310b57cec5SDimitry Andric bool hasWorkItemIDX() const { 8320b57cec5SDimitry Andric return WorkItemIDX; 8330b57cec5SDimitry Andric } 8340b57cec5SDimitry Andric 8350b57cec5SDimitry Andric bool hasWorkItemIDY() const { 8360b57cec5SDimitry Andric return WorkItemIDY; 8370b57cec5SDimitry Andric } 8380b57cec5SDimitry Andric 8390b57cec5SDimitry Andric bool hasWorkItemIDZ() const { 8400b57cec5SDimitry Andric return WorkItemIDZ; 8410b57cec5SDimitry Andric } 8420b57cec5SDimitry Andric 8430b57cec5SDimitry Andric bool hasImplicitArgPtr() const { 8440b57cec5SDimitry Andric return ImplicitArgPtr; 8450b57cec5SDimitry Andric } 8460b57cec5SDimitry Andric 8470b57cec5SDimitry Andric AMDGPUFunctionArgInfo &getArgInfo() { 8480b57cec5SDimitry Andric return ArgInfo; 8490b57cec5SDimitry Andric } 8500b57cec5SDimitry Andric 8510b57cec5SDimitry Andric const AMDGPUFunctionArgInfo &getArgInfo() const { 8520b57cec5SDimitry Andric return ArgInfo; 8530b57cec5SDimitry Andric } 8540b57cec5SDimitry Andric 8555ffd83dbSDimitry Andric std::tuple<const ArgDescriptor *, const TargetRegisterClass *, LLT> 8560b57cec5SDimitry Andric getPreloadedValue(AMDGPUFunctionArgInfo::PreloadedValue Value) const { 8570b57cec5SDimitry Andric return ArgInfo.getPreloadedValue(Value); 8580b57cec5SDimitry Andric } 8590b57cec5SDimitry Andric 860e8d8bef9SDimitry Andric MCRegister getPreloadedReg(AMDGPUFunctionArgInfo::PreloadedValue Value) const { 8615ffd83dbSDimitry Andric auto Arg = std::get<0>(ArgInfo.getPreloadedValue(Value)); 862e8d8bef9SDimitry Andric return Arg ? Arg->getRegister() : MCRegister(); 8630b57cec5SDimitry Andric } 8640b57cec5SDimitry Andric 8650b57cec5SDimitry Andric unsigned getGITPtrHigh() const { 8660b57cec5SDimitry Andric return GITPtrHigh; 8670b57cec5SDimitry Andric } 8680b57cec5SDimitry Andric 8695ffd83dbSDimitry Andric Register getGITPtrLoReg(const MachineFunction &MF) const; 8705ffd83dbSDimitry Andric 8718bcb0991SDimitry Andric uint32_t get32BitAddressHighBits() const { 8720b57cec5SDimitry Andric return HighBitsOf32BitAddress; 8730b57cec5SDimitry Andric } 8740b57cec5SDimitry Andric 8750b57cec5SDimitry Andric unsigned getNumUserSGPRs() const { 8760b57cec5SDimitry Andric return NumUserSGPRs; 8770b57cec5SDimitry Andric } 8780b57cec5SDimitry Andric 8790b57cec5SDimitry Andric unsigned getNumPreloadedSGPRs() const { 8800b57cec5SDimitry Andric return NumUserSGPRs + NumSystemSGPRs; 8810b57cec5SDimitry Andric } 8820b57cec5SDimitry Andric 883*5f757f3fSDimitry Andric unsigned getNumKernargPreloadedSGPRs() const { 884*5f757f3fSDimitry Andric return UserSGPRInfo.getNumKernargPreloadSGPRs(); 885*5f757f3fSDimitry Andric } 886*5f757f3fSDimitry Andric 8875ffd83dbSDimitry Andric Register getPrivateSegmentWaveByteOffsetSystemSGPR() const { 8880b57cec5SDimitry Andric return ArgInfo.PrivateSegmentWaveByteOffset.getRegister(); 8890b57cec5SDimitry Andric } 8900b57cec5SDimitry Andric 8910b57cec5SDimitry Andric /// Returns the physical register reserved for use as the resource 8920b57cec5SDimitry Andric /// descriptor for scratch accesses. 8935ffd83dbSDimitry Andric Register getScratchRSrcReg() const { 8940b57cec5SDimitry Andric return ScratchRSrcReg; 8950b57cec5SDimitry Andric } 8960b57cec5SDimitry Andric 8975ffd83dbSDimitry Andric void setScratchRSrcReg(Register Reg) { 8980b57cec5SDimitry Andric assert(Reg != 0 && "Should never be unset"); 8990b57cec5SDimitry Andric ScratchRSrcReg = Reg; 9000b57cec5SDimitry Andric } 9010b57cec5SDimitry Andric 9025ffd83dbSDimitry Andric Register getFrameOffsetReg() const { 9030b57cec5SDimitry Andric return FrameOffsetReg; 9040b57cec5SDimitry Andric } 9050b57cec5SDimitry Andric 9065ffd83dbSDimitry Andric void setFrameOffsetReg(Register Reg) { 9070b57cec5SDimitry Andric assert(Reg != 0 && "Should never be unset"); 9080b57cec5SDimitry Andric FrameOffsetReg = Reg; 9090b57cec5SDimitry Andric } 9100b57cec5SDimitry Andric 9115ffd83dbSDimitry Andric void setStackPtrOffsetReg(Register Reg) { 9120b57cec5SDimitry Andric assert(Reg != 0 && "Should never be unset"); 9130b57cec5SDimitry Andric StackPtrOffsetReg = Reg; 9140b57cec5SDimitry Andric } 9150b57cec5SDimitry Andric 91606c3fb27SDimitry Andric void setLongBranchReservedReg(Register Reg) { LongBranchReservedReg = Reg; } 91706c3fb27SDimitry Andric 9180b57cec5SDimitry Andric // Note the unset value for this is AMDGPU::SP_REG rather than 9190b57cec5SDimitry Andric // NoRegister. This is mostly a workaround for MIR tests where state that 9200b57cec5SDimitry Andric // can't be directly computed from the function is not preserved in serialized 9210b57cec5SDimitry Andric // MIR. 9225ffd83dbSDimitry Andric Register getStackPtrOffsetReg() const { 9230b57cec5SDimitry Andric return StackPtrOffsetReg; 9240b57cec5SDimitry Andric } 9250b57cec5SDimitry Andric 92606c3fb27SDimitry Andric Register getLongBranchReservedReg() const { return LongBranchReservedReg; } 92706c3fb27SDimitry Andric 9285ffd83dbSDimitry Andric Register getQueuePtrUserSGPR() const { 9290b57cec5SDimitry Andric return ArgInfo.QueuePtr.getRegister(); 9300b57cec5SDimitry Andric } 9310b57cec5SDimitry Andric 9325ffd83dbSDimitry Andric Register getImplicitBufferPtrUserSGPR() const { 9330b57cec5SDimitry Andric return ArgInfo.ImplicitBufferPtr.getRegister(); 9340b57cec5SDimitry Andric } 9350b57cec5SDimitry Andric 9360b57cec5SDimitry Andric bool hasSpilledSGPRs() const { 9370b57cec5SDimitry Andric return HasSpilledSGPRs; 9380b57cec5SDimitry Andric } 9390b57cec5SDimitry Andric 9400b57cec5SDimitry Andric void setHasSpilledSGPRs(bool Spill = true) { 9410b57cec5SDimitry Andric HasSpilledSGPRs = Spill; 9420b57cec5SDimitry Andric } 9430b57cec5SDimitry Andric 9440b57cec5SDimitry Andric bool hasSpilledVGPRs() const { 9450b57cec5SDimitry Andric return HasSpilledVGPRs; 9460b57cec5SDimitry Andric } 9470b57cec5SDimitry Andric 9480b57cec5SDimitry Andric void setHasSpilledVGPRs(bool Spill = true) { 9490b57cec5SDimitry Andric HasSpilledVGPRs = Spill; 9500b57cec5SDimitry Andric } 9510b57cec5SDimitry Andric 9520b57cec5SDimitry Andric bool hasNonSpillStackObjects() const { 9530b57cec5SDimitry Andric return HasNonSpillStackObjects; 9540b57cec5SDimitry Andric } 9550b57cec5SDimitry Andric 9560b57cec5SDimitry Andric void setHasNonSpillStackObjects(bool StackObject = true) { 9570b57cec5SDimitry Andric HasNonSpillStackObjects = StackObject; 9580b57cec5SDimitry Andric } 9590b57cec5SDimitry Andric 9600b57cec5SDimitry Andric bool isStackRealigned() const { 9610b57cec5SDimitry Andric return IsStackRealigned; 9620b57cec5SDimitry Andric } 9630b57cec5SDimitry Andric 9640b57cec5SDimitry Andric void setIsStackRealigned(bool Realigned = true) { 9650b57cec5SDimitry Andric IsStackRealigned = Realigned; 9660b57cec5SDimitry Andric } 9670b57cec5SDimitry Andric 9680b57cec5SDimitry Andric unsigned getNumSpilledSGPRs() const { 9690b57cec5SDimitry Andric return NumSpilledSGPRs; 9700b57cec5SDimitry Andric } 9710b57cec5SDimitry Andric 9720b57cec5SDimitry Andric unsigned getNumSpilledVGPRs() const { 9730b57cec5SDimitry Andric return NumSpilledVGPRs; 9740b57cec5SDimitry Andric } 9750b57cec5SDimitry Andric 9760b57cec5SDimitry Andric void addToSpilledSGPRs(unsigned num) { 9770b57cec5SDimitry Andric NumSpilledSGPRs += num; 9780b57cec5SDimitry Andric } 9790b57cec5SDimitry Andric 9800b57cec5SDimitry Andric void addToSpilledVGPRs(unsigned num) { 9810b57cec5SDimitry Andric NumSpilledVGPRs += num; 9820b57cec5SDimitry Andric } 9830b57cec5SDimitry Andric 9840b57cec5SDimitry Andric unsigned getPSInputAddr() const { 9850b57cec5SDimitry Andric return PSInputAddr; 9860b57cec5SDimitry Andric } 9870b57cec5SDimitry Andric 9880b57cec5SDimitry Andric unsigned getPSInputEnable() const { 9890b57cec5SDimitry Andric return PSInputEnable; 9900b57cec5SDimitry Andric } 9910b57cec5SDimitry Andric 9920b57cec5SDimitry Andric bool isPSInputAllocated(unsigned Index) const { 9930b57cec5SDimitry Andric return PSInputAddr & (1 << Index); 9940b57cec5SDimitry Andric } 9950b57cec5SDimitry Andric 9960b57cec5SDimitry Andric void markPSInputAllocated(unsigned Index) { 9970b57cec5SDimitry Andric PSInputAddr |= 1 << Index; 9980b57cec5SDimitry Andric } 9990b57cec5SDimitry Andric 10000b57cec5SDimitry Andric void markPSInputEnabled(unsigned Index) { 10010b57cec5SDimitry Andric PSInputEnable |= 1 << Index; 10020b57cec5SDimitry Andric } 10030b57cec5SDimitry Andric 10040b57cec5SDimitry Andric bool returnsVoid() const { 10050b57cec5SDimitry Andric return ReturnsVoid; 10060b57cec5SDimitry Andric } 10070b57cec5SDimitry Andric 10080b57cec5SDimitry Andric void setIfReturnsVoid(bool Value) { 10090b57cec5SDimitry Andric ReturnsVoid = Value; 10100b57cec5SDimitry Andric } 10110b57cec5SDimitry Andric 10120b57cec5SDimitry Andric /// \returns A pair of default/requested minimum/maximum flat work group sizes 10130b57cec5SDimitry Andric /// for this function. 10140b57cec5SDimitry Andric std::pair<unsigned, unsigned> getFlatWorkGroupSizes() const { 10150b57cec5SDimitry Andric return FlatWorkGroupSizes; 10160b57cec5SDimitry Andric } 10170b57cec5SDimitry Andric 10180b57cec5SDimitry Andric /// \returns Default/requested minimum flat work group size for this function. 10190b57cec5SDimitry Andric unsigned getMinFlatWorkGroupSize() const { 10200b57cec5SDimitry Andric return FlatWorkGroupSizes.first; 10210b57cec5SDimitry Andric } 10220b57cec5SDimitry Andric 10230b57cec5SDimitry Andric /// \returns Default/requested maximum flat work group size for this function. 10240b57cec5SDimitry Andric unsigned getMaxFlatWorkGroupSize() const { 10250b57cec5SDimitry Andric return FlatWorkGroupSizes.second; 10260b57cec5SDimitry Andric } 10270b57cec5SDimitry Andric 10280b57cec5SDimitry Andric /// \returns A pair of default/requested minimum/maximum number of waves per 10290b57cec5SDimitry Andric /// execution unit. 10300b57cec5SDimitry Andric std::pair<unsigned, unsigned> getWavesPerEU() const { 10310b57cec5SDimitry Andric return WavesPerEU; 10320b57cec5SDimitry Andric } 10330b57cec5SDimitry Andric 10340b57cec5SDimitry Andric /// \returns Default/requested minimum number of waves per execution unit. 10350b57cec5SDimitry Andric unsigned getMinWavesPerEU() const { 10360b57cec5SDimitry Andric return WavesPerEU.first; 10370b57cec5SDimitry Andric } 10380b57cec5SDimitry Andric 10390b57cec5SDimitry Andric /// \returns Default/requested maximum number of waves per execution unit. 10400b57cec5SDimitry Andric unsigned getMaxWavesPerEU() const { 10410b57cec5SDimitry Andric return WavesPerEU.second; 10420b57cec5SDimitry Andric } 10430b57cec5SDimitry Andric 10440b57cec5SDimitry Andric /// \returns SGPR used for \p Dim's work group ID. 10455ffd83dbSDimitry Andric Register getWorkGroupIDSGPR(unsigned Dim) const { 10460b57cec5SDimitry Andric switch (Dim) { 10470b57cec5SDimitry Andric case 0: 10480b57cec5SDimitry Andric assert(hasWorkGroupIDX()); 10490b57cec5SDimitry Andric return ArgInfo.WorkGroupIDX.getRegister(); 10500b57cec5SDimitry Andric case 1: 10510b57cec5SDimitry Andric assert(hasWorkGroupIDY()); 10520b57cec5SDimitry Andric return ArgInfo.WorkGroupIDY.getRegister(); 10530b57cec5SDimitry Andric case 2: 10540b57cec5SDimitry Andric assert(hasWorkGroupIDZ()); 10550b57cec5SDimitry Andric return ArgInfo.WorkGroupIDZ.getRegister(); 10560b57cec5SDimitry Andric } 10570b57cec5SDimitry Andric llvm_unreachable("unexpected dimension"); 10580b57cec5SDimitry Andric } 10590b57cec5SDimitry Andric 106081ad6265SDimitry Andric const AMDGPUGWSResourcePseudoSourceValue * 106181ad6265SDimitry Andric getGWSPSV(const AMDGPUTargetMachine &TM) { 106281ad6265SDimitry Andric return &GWSResourcePSV; 10630b57cec5SDimitry Andric } 10640b57cec5SDimitry Andric 10650b57cec5SDimitry Andric unsigned getOccupancy() const { 10660b57cec5SDimitry Andric return Occupancy; 10670b57cec5SDimitry Andric } 10680b57cec5SDimitry Andric 10690b57cec5SDimitry Andric unsigned getMinAllowedOccupancy() const { 10700b57cec5SDimitry Andric if (!isMemoryBound() && !needsWaveLimiter()) 10710b57cec5SDimitry Andric return Occupancy; 10720b57cec5SDimitry Andric return (Occupancy < 4) ? Occupancy : 4; 10730b57cec5SDimitry Andric } 10740b57cec5SDimitry Andric 10750b57cec5SDimitry Andric void limitOccupancy(const MachineFunction &MF); 10760b57cec5SDimitry Andric 10770b57cec5SDimitry Andric void limitOccupancy(unsigned Limit) { 10780b57cec5SDimitry Andric if (Occupancy > Limit) 10790b57cec5SDimitry Andric Occupancy = Limit; 10800b57cec5SDimitry Andric } 10810b57cec5SDimitry Andric 10820b57cec5SDimitry Andric void increaseOccupancy(const MachineFunction &MF, unsigned Limit) { 10830b57cec5SDimitry Andric if (Occupancy < Limit) 10840b57cec5SDimitry Andric Occupancy = Limit; 10850b57cec5SDimitry Andric limitOccupancy(MF); 10860b57cec5SDimitry Andric } 1087349cc55cSDimitry Andric 108881ad6265SDimitry Andric bool mayNeedAGPRs() const { 108981ad6265SDimitry Andric return MayNeedAGPRs; 109081ad6265SDimitry Andric } 109181ad6265SDimitry Andric 109281ad6265SDimitry Andric // \returns true if a function has a use of AGPRs via inline asm or 109381ad6265SDimitry Andric // has a call which may use it. 1094bdd1243dSDimitry Andric bool mayUseAGPRs(const Function &F) const; 109581ad6265SDimitry Andric 1096349cc55cSDimitry Andric // \returns true if a function needs or may need AGPRs. 1097349cc55cSDimitry Andric bool usesAGPRs(const MachineFunction &MF) const; 10980b57cec5SDimitry Andric }; 10990b57cec5SDimitry Andric 11000b57cec5SDimitry Andric } // end namespace llvm 11010b57cec5SDimitry Andric 11020b57cec5SDimitry Andric #endif // LLVM_LIB_TARGET_AMDGPU_SIMACHINEFUNCTIONINFO_H 1103