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" 180b57cec5SDimitry Andric #include "MCTargetDesc/AMDGPUMCTargetDesc.h" 190b57cec5SDimitry Andric #include "SIInstrInfo.h" 200b57cec5SDimitry Andric #include "SIRegisterInfo.h" 210b57cec5SDimitry Andric #include "llvm/ADT/ArrayRef.h" 220b57cec5SDimitry Andric #include "llvm/ADT/DenseMap.h" 230b57cec5SDimitry Andric #include "llvm/ADT/Optional.h" 240b57cec5SDimitry Andric #include "llvm/ADT/STLExtras.h" 250b57cec5SDimitry Andric #include "llvm/ADT/SmallVector.h" 260b57cec5SDimitry Andric #include "llvm/ADT/SparseBitVector.h" 270b57cec5SDimitry Andric #include "llvm/CodeGen/MIRYamlMapping.h" 280b57cec5SDimitry Andric #include "llvm/CodeGen/PseudoSourceValue.h" 290b57cec5SDimitry Andric #include "llvm/CodeGen/TargetInstrInfo.h" 300b57cec5SDimitry Andric #include "llvm/MC/MCRegisterInfo.h" 310b57cec5SDimitry Andric #include "llvm/Support/ErrorHandling.h" 320b57cec5SDimitry Andric #include <array> 330b57cec5SDimitry Andric #include <cassert> 340b57cec5SDimitry Andric #include <utility> 350b57cec5SDimitry Andric #include <vector> 360b57cec5SDimitry Andric 370b57cec5SDimitry Andric namespace llvm { 380b57cec5SDimitry Andric 390b57cec5SDimitry Andric class MachineFrameInfo; 400b57cec5SDimitry Andric class MachineFunction; 410b57cec5SDimitry Andric class TargetRegisterClass; 420b57cec5SDimitry Andric 430b57cec5SDimitry Andric class AMDGPUPseudoSourceValue : public PseudoSourceValue { 440b57cec5SDimitry Andric public: 450b57cec5SDimitry Andric enum AMDGPUPSVKind : unsigned { 460b57cec5SDimitry Andric PSVBuffer = PseudoSourceValue::TargetCustom, 470b57cec5SDimitry Andric PSVImage, 480b57cec5SDimitry Andric GWSResource 490b57cec5SDimitry Andric }; 500b57cec5SDimitry Andric 510b57cec5SDimitry Andric protected: 520b57cec5SDimitry Andric AMDGPUPseudoSourceValue(unsigned Kind, const TargetInstrInfo &TII) 530b57cec5SDimitry Andric : PseudoSourceValue(Kind, TII) {} 540b57cec5SDimitry Andric 550b57cec5SDimitry Andric public: 560b57cec5SDimitry Andric bool isConstant(const MachineFrameInfo *) const override { 570b57cec5SDimitry Andric // This should probably be true for most images, but we will start by being 580b57cec5SDimitry Andric // conservative. 590b57cec5SDimitry Andric return false; 600b57cec5SDimitry Andric } 610b57cec5SDimitry Andric 620b57cec5SDimitry Andric bool isAliased(const MachineFrameInfo *) const override { 630b57cec5SDimitry Andric return true; 640b57cec5SDimitry Andric } 650b57cec5SDimitry Andric 660b57cec5SDimitry Andric bool mayAlias(const MachineFrameInfo *) const override { 670b57cec5SDimitry Andric return true; 680b57cec5SDimitry Andric } 690b57cec5SDimitry Andric }; 700b57cec5SDimitry Andric 710b57cec5SDimitry Andric class AMDGPUBufferPseudoSourceValue final : public AMDGPUPseudoSourceValue { 720b57cec5SDimitry Andric public: 730b57cec5SDimitry Andric explicit AMDGPUBufferPseudoSourceValue(const TargetInstrInfo &TII) 740b57cec5SDimitry Andric : AMDGPUPseudoSourceValue(PSVBuffer, TII) {} 750b57cec5SDimitry Andric 760b57cec5SDimitry Andric static bool classof(const PseudoSourceValue *V) { 770b57cec5SDimitry Andric return V->kind() == PSVBuffer; 780b57cec5SDimitry Andric } 790b57cec5SDimitry Andric }; 800b57cec5SDimitry Andric 810b57cec5SDimitry Andric class AMDGPUImagePseudoSourceValue final : public AMDGPUPseudoSourceValue { 820b57cec5SDimitry Andric public: 830b57cec5SDimitry Andric // TODO: Is the img rsrc useful? 840b57cec5SDimitry Andric explicit AMDGPUImagePseudoSourceValue(const TargetInstrInfo &TII) 850b57cec5SDimitry Andric : AMDGPUPseudoSourceValue(PSVImage, TII) {} 860b57cec5SDimitry Andric 870b57cec5SDimitry Andric static bool classof(const PseudoSourceValue *V) { 880b57cec5SDimitry Andric return V->kind() == PSVImage; 890b57cec5SDimitry Andric } 900b57cec5SDimitry Andric }; 910b57cec5SDimitry Andric 920b57cec5SDimitry Andric class AMDGPUGWSResourcePseudoSourceValue final : public AMDGPUPseudoSourceValue { 930b57cec5SDimitry Andric public: 940b57cec5SDimitry Andric explicit AMDGPUGWSResourcePseudoSourceValue(const TargetInstrInfo &TII) 950b57cec5SDimitry Andric : AMDGPUPseudoSourceValue(GWSResource, TII) {} 960b57cec5SDimitry Andric 970b57cec5SDimitry Andric static bool classof(const PseudoSourceValue *V) { 980b57cec5SDimitry Andric return V->kind() == GWSResource; 990b57cec5SDimitry Andric } 1000b57cec5SDimitry Andric 1010b57cec5SDimitry Andric // These are inaccessible memory from IR. 1020b57cec5SDimitry Andric bool isAliased(const MachineFrameInfo *) const override { 1030b57cec5SDimitry Andric return false; 1040b57cec5SDimitry Andric } 1050b57cec5SDimitry Andric 1060b57cec5SDimitry Andric // These are inaccessible memory from IR. 1070b57cec5SDimitry Andric bool mayAlias(const MachineFrameInfo *) const override { 1080b57cec5SDimitry Andric return false; 1090b57cec5SDimitry Andric } 1100b57cec5SDimitry Andric 1110b57cec5SDimitry Andric void printCustom(raw_ostream &OS) const override { 1120b57cec5SDimitry Andric OS << "GWSResource"; 1130b57cec5SDimitry Andric } 1140b57cec5SDimitry Andric }; 1150b57cec5SDimitry Andric 1160b57cec5SDimitry Andric namespace yaml { 1170b57cec5SDimitry Andric 1180b57cec5SDimitry Andric struct SIArgument { 1190b57cec5SDimitry Andric bool IsRegister; 1200b57cec5SDimitry Andric union { 1210b57cec5SDimitry Andric StringValue RegisterName; 1220b57cec5SDimitry Andric unsigned StackOffset; 1230b57cec5SDimitry Andric }; 1240b57cec5SDimitry Andric Optional<unsigned> Mask; 1250b57cec5SDimitry Andric 1260b57cec5SDimitry Andric // Default constructor, which creates a stack argument. 1270b57cec5SDimitry Andric SIArgument() : IsRegister(false), StackOffset(0) {} 1280b57cec5SDimitry Andric SIArgument(const SIArgument &Other) { 1290b57cec5SDimitry Andric IsRegister = Other.IsRegister; 1300b57cec5SDimitry Andric if (IsRegister) { 1310b57cec5SDimitry Andric ::new ((void *)std::addressof(RegisterName)) 1320b57cec5SDimitry Andric StringValue(Other.RegisterName); 1330b57cec5SDimitry Andric } else 1340b57cec5SDimitry Andric StackOffset = Other.StackOffset; 1350b57cec5SDimitry Andric Mask = Other.Mask; 1360b57cec5SDimitry Andric } 1370b57cec5SDimitry Andric SIArgument &operator=(const SIArgument &Other) { 1380b57cec5SDimitry Andric IsRegister = Other.IsRegister; 1390b57cec5SDimitry Andric if (IsRegister) { 1400b57cec5SDimitry Andric ::new ((void *)std::addressof(RegisterName)) 1410b57cec5SDimitry Andric StringValue(Other.RegisterName); 1420b57cec5SDimitry Andric } else 1430b57cec5SDimitry Andric StackOffset = Other.StackOffset; 1440b57cec5SDimitry Andric Mask = Other.Mask; 1450b57cec5SDimitry Andric return *this; 1460b57cec5SDimitry Andric } 1470b57cec5SDimitry Andric ~SIArgument() { 1480b57cec5SDimitry Andric if (IsRegister) 1490b57cec5SDimitry Andric RegisterName.~StringValue(); 1500b57cec5SDimitry Andric } 1510b57cec5SDimitry Andric 1520b57cec5SDimitry Andric // Helper to create a register or stack argument. 1530b57cec5SDimitry Andric static inline SIArgument createArgument(bool IsReg) { 1540b57cec5SDimitry Andric if (IsReg) 1550b57cec5SDimitry Andric return SIArgument(IsReg); 1560b57cec5SDimitry Andric return SIArgument(); 1570b57cec5SDimitry Andric } 1580b57cec5SDimitry Andric 1590b57cec5SDimitry Andric private: 1600b57cec5SDimitry Andric // Construct a register argument. 1610b57cec5SDimitry Andric SIArgument(bool) : IsRegister(true), RegisterName() {} 1620b57cec5SDimitry Andric }; 1630b57cec5SDimitry Andric 1640b57cec5SDimitry Andric template <> struct MappingTraits<SIArgument> { 1650b57cec5SDimitry Andric static void mapping(IO &YamlIO, SIArgument &A) { 1660b57cec5SDimitry Andric if (YamlIO.outputting()) { 1670b57cec5SDimitry Andric if (A.IsRegister) 1680b57cec5SDimitry Andric YamlIO.mapRequired("reg", A.RegisterName); 1690b57cec5SDimitry Andric else 1700b57cec5SDimitry Andric YamlIO.mapRequired("offset", A.StackOffset); 1710b57cec5SDimitry Andric } else { 1720b57cec5SDimitry Andric auto Keys = YamlIO.keys(); 1730b57cec5SDimitry Andric if (is_contained(Keys, "reg")) { 1740b57cec5SDimitry Andric A = SIArgument::createArgument(true); 1750b57cec5SDimitry Andric YamlIO.mapRequired("reg", A.RegisterName); 1760b57cec5SDimitry Andric } else if (is_contained(Keys, "offset")) 1770b57cec5SDimitry Andric YamlIO.mapRequired("offset", A.StackOffset); 1780b57cec5SDimitry Andric else 1790b57cec5SDimitry Andric YamlIO.setError("missing required key 'reg' or 'offset'"); 1800b57cec5SDimitry Andric } 1810b57cec5SDimitry Andric YamlIO.mapOptional("mask", A.Mask); 1820b57cec5SDimitry Andric } 1830b57cec5SDimitry Andric static const bool flow = true; 1840b57cec5SDimitry Andric }; 1850b57cec5SDimitry Andric 1860b57cec5SDimitry Andric struct SIArgumentInfo { 1870b57cec5SDimitry Andric Optional<SIArgument> PrivateSegmentBuffer; 1880b57cec5SDimitry Andric Optional<SIArgument> DispatchPtr; 1890b57cec5SDimitry Andric Optional<SIArgument> QueuePtr; 1900b57cec5SDimitry Andric Optional<SIArgument> KernargSegmentPtr; 1910b57cec5SDimitry Andric Optional<SIArgument> DispatchID; 1920b57cec5SDimitry Andric Optional<SIArgument> FlatScratchInit; 1930b57cec5SDimitry Andric Optional<SIArgument> PrivateSegmentSize; 1940b57cec5SDimitry Andric 1950b57cec5SDimitry Andric Optional<SIArgument> WorkGroupIDX; 1960b57cec5SDimitry Andric Optional<SIArgument> WorkGroupIDY; 1970b57cec5SDimitry Andric Optional<SIArgument> WorkGroupIDZ; 1980b57cec5SDimitry Andric Optional<SIArgument> WorkGroupInfo; 1990b57cec5SDimitry Andric Optional<SIArgument> PrivateSegmentWaveByteOffset; 2000b57cec5SDimitry Andric 2010b57cec5SDimitry Andric Optional<SIArgument> ImplicitArgPtr; 2020b57cec5SDimitry Andric Optional<SIArgument> ImplicitBufferPtr; 2030b57cec5SDimitry Andric 2040b57cec5SDimitry Andric Optional<SIArgument> WorkItemIDX; 2050b57cec5SDimitry Andric Optional<SIArgument> WorkItemIDY; 2060b57cec5SDimitry Andric Optional<SIArgument> WorkItemIDZ; 2070b57cec5SDimitry Andric }; 2080b57cec5SDimitry Andric 2090b57cec5SDimitry Andric template <> struct MappingTraits<SIArgumentInfo> { 2100b57cec5SDimitry Andric static void mapping(IO &YamlIO, SIArgumentInfo &AI) { 2110b57cec5SDimitry Andric YamlIO.mapOptional("privateSegmentBuffer", AI.PrivateSegmentBuffer); 2120b57cec5SDimitry Andric YamlIO.mapOptional("dispatchPtr", AI.DispatchPtr); 2130b57cec5SDimitry Andric YamlIO.mapOptional("queuePtr", AI.QueuePtr); 2140b57cec5SDimitry Andric YamlIO.mapOptional("kernargSegmentPtr", AI.KernargSegmentPtr); 2150b57cec5SDimitry Andric YamlIO.mapOptional("dispatchID", AI.DispatchID); 2160b57cec5SDimitry Andric YamlIO.mapOptional("flatScratchInit", AI.FlatScratchInit); 2170b57cec5SDimitry Andric YamlIO.mapOptional("privateSegmentSize", AI.PrivateSegmentSize); 2180b57cec5SDimitry Andric 2190b57cec5SDimitry Andric YamlIO.mapOptional("workGroupIDX", AI.WorkGroupIDX); 2200b57cec5SDimitry Andric YamlIO.mapOptional("workGroupIDY", AI.WorkGroupIDY); 2210b57cec5SDimitry Andric YamlIO.mapOptional("workGroupIDZ", AI.WorkGroupIDZ); 2220b57cec5SDimitry Andric YamlIO.mapOptional("workGroupInfo", AI.WorkGroupInfo); 2230b57cec5SDimitry Andric YamlIO.mapOptional("privateSegmentWaveByteOffset", 2240b57cec5SDimitry Andric AI.PrivateSegmentWaveByteOffset); 2250b57cec5SDimitry Andric 2260b57cec5SDimitry Andric YamlIO.mapOptional("implicitArgPtr", AI.ImplicitArgPtr); 2270b57cec5SDimitry Andric YamlIO.mapOptional("implicitBufferPtr", AI.ImplicitBufferPtr); 2280b57cec5SDimitry Andric 2290b57cec5SDimitry Andric YamlIO.mapOptional("workItemIDX", AI.WorkItemIDX); 2300b57cec5SDimitry Andric YamlIO.mapOptional("workItemIDY", AI.WorkItemIDY); 2310b57cec5SDimitry Andric YamlIO.mapOptional("workItemIDZ", AI.WorkItemIDZ); 2320b57cec5SDimitry Andric } 2330b57cec5SDimitry Andric }; 2340b57cec5SDimitry Andric 2350b57cec5SDimitry Andric // Default to default mode for default calling convention. 2360b57cec5SDimitry Andric struct SIMode { 2370b57cec5SDimitry Andric bool IEEE = true; 2380b57cec5SDimitry Andric bool DX10Clamp = true; 239*480093f4SDimitry Andric bool FP32Denormals = true; 240*480093f4SDimitry Andric bool FP64FP16Denormals = true; 2410b57cec5SDimitry Andric 2420b57cec5SDimitry Andric SIMode() = default; 2430b57cec5SDimitry Andric 2440b57cec5SDimitry Andric SIMode(const AMDGPU::SIModeRegisterDefaults &Mode) { 2450b57cec5SDimitry Andric IEEE = Mode.IEEE; 2460b57cec5SDimitry Andric DX10Clamp = Mode.DX10Clamp; 247*480093f4SDimitry Andric FP32Denormals = Mode.FP32Denormals; 248*480093f4SDimitry Andric FP64FP16Denormals = Mode.FP64FP16Denormals; 2490b57cec5SDimitry Andric } 2500b57cec5SDimitry Andric 2510b57cec5SDimitry Andric bool operator ==(const SIMode Other) const { 252*480093f4SDimitry Andric return IEEE == Other.IEEE && 253*480093f4SDimitry Andric DX10Clamp == Other.DX10Clamp && 254*480093f4SDimitry Andric FP32Denormals == Other.FP32Denormals && 255*480093f4SDimitry Andric FP64FP16Denormals == Other.FP64FP16Denormals; 2560b57cec5SDimitry Andric } 2570b57cec5SDimitry Andric }; 2580b57cec5SDimitry Andric 2590b57cec5SDimitry Andric template <> struct MappingTraits<SIMode> { 2600b57cec5SDimitry Andric static void mapping(IO &YamlIO, SIMode &Mode) { 2610b57cec5SDimitry Andric YamlIO.mapOptional("ieee", Mode.IEEE, true); 2620b57cec5SDimitry Andric YamlIO.mapOptional("dx10-clamp", Mode.DX10Clamp, true); 263*480093f4SDimitry Andric YamlIO.mapOptional("fp32-denormals", Mode.FP32Denormals, true); 264*480093f4SDimitry Andric YamlIO.mapOptional("fp64-fp16-denormals", Mode.FP64FP16Denormals, true); 2650b57cec5SDimitry Andric } 2660b57cec5SDimitry Andric }; 2670b57cec5SDimitry Andric 2680b57cec5SDimitry Andric struct SIMachineFunctionInfo final : public yaml::MachineFunctionInfo { 2690b57cec5SDimitry Andric uint64_t ExplicitKernArgSize = 0; 2700b57cec5SDimitry Andric unsigned MaxKernArgAlign = 0; 2710b57cec5SDimitry Andric unsigned LDSSize = 0; 2720b57cec5SDimitry Andric bool IsEntryFunction = false; 2730b57cec5SDimitry Andric bool NoSignedZerosFPMath = false; 2740b57cec5SDimitry Andric bool MemoryBound = false; 2750b57cec5SDimitry Andric bool WaveLimiter = false; 2768bcb0991SDimitry Andric uint32_t HighBitsOf32BitAddress = 0; 2770b57cec5SDimitry Andric 2780b57cec5SDimitry Andric StringValue ScratchRSrcReg = "$private_rsrc_reg"; 2790b57cec5SDimitry Andric StringValue ScratchWaveOffsetReg = "$scratch_wave_offset_reg"; 2800b57cec5SDimitry Andric StringValue FrameOffsetReg = "$fp_reg"; 2810b57cec5SDimitry Andric StringValue StackPtrOffsetReg = "$sp_reg"; 2820b57cec5SDimitry Andric 2830b57cec5SDimitry Andric Optional<SIArgumentInfo> ArgInfo; 2840b57cec5SDimitry Andric SIMode Mode; 2850b57cec5SDimitry Andric 2860b57cec5SDimitry Andric SIMachineFunctionInfo() = default; 2870b57cec5SDimitry Andric SIMachineFunctionInfo(const llvm::SIMachineFunctionInfo &, 2880b57cec5SDimitry Andric const TargetRegisterInfo &TRI); 2890b57cec5SDimitry Andric 2900b57cec5SDimitry Andric void mappingImpl(yaml::IO &YamlIO) override; 2910b57cec5SDimitry Andric ~SIMachineFunctionInfo() = default; 2920b57cec5SDimitry Andric }; 2930b57cec5SDimitry Andric 2940b57cec5SDimitry Andric template <> struct MappingTraits<SIMachineFunctionInfo> { 2950b57cec5SDimitry Andric static void mapping(IO &YamlIO, SIMachineFunctionInfo &MFI) { 2960b57cec5SDimitry Andric YamlIO.mapOptional("explicitKernArgSize", MFI.ExplicitKernArgSize, 2970b57cec5SDimitry Andric UINT64_C(0)); 2980b57cec5SDimitry Andric YamlIO.mapOptional("maxKernArgAlign", MFI.MaxKernArgAlign, 0u); 2990b57cec5SDimitry Andric YamlIO.mapOptional("ldsSize", MFI.LDSSize, 0u); 3000b57cec5SDimitry Andric YamlIO.mapOptional("isEntryFunction", MFI.IsEntryFunction, false); 3010b57cec5SDimitry Andric YamlIO.mapOptional("noSignedZerosFPMath", MFI.NoSignedZerosFPMath, false); 3020b57cec5SDimitry Andric YamlIO.mapOptional("memoryBound", MFI.MemoryBound, false); 3030b57cec5SDimitry Andric YamlIO.mapOptional("waveLimiter", MFI.WaveLimiter, false); 3040b57cec5SDimitry Andric YamlIO.mapOptional("scratchRSrcReg", MFI.ScratchRSrcReg, 3050b57cec5SDimitry Andric StringValue("$private_rsrc_reg")); 3060b57cec5SDimitry Andric YamlIO.mapOptional("scratchWaveOffsetReg", MFI.ScratchWaveOffsetReg, 3070b57cec5SDimitry Andric StringValue("$scratch_wave_offset_reg")); 3080b57cec5SDimitry Andric YamlIO.mapOptional("frameOffsetReg", MFI.FrameOffsetReg, 3090b57cec5SDimitry Andric StringValue("$fp_reg")); 3100b57cec5SDimitry Andric YamlIO.mapOptional("stackPtrOffsetReg", MFI.StackPtrOffsetReg, 3110b57cec5SDimitry Andric StringValue("$sp_reg")); 3120b57cec5SDimitry Andric YamlIO.mapOptional("argumentInfo", MFI.ArgInfo); 3130b57cec5SDimitry Andric YamlIO.mapOptional("mode", MFI.Mode, SIMode()); 3148bcb0991SDimitry Andric YamlIO.mapOptional("highBitsOf32BitAddress", 3158bcb0991SDimitry Andric MFI.HighBitsOf32BitAddress, 0u); 3160b57cec5SDimitry Andric } 3170b57cec5SDimitry Andric }; 3180b57cec5SDimitry Andric 3190b57cec5SDimitry Andric } // end namespace yaml 3200b57cec5SDimitry Andric 3210b57cec5SDimitry Andric /// This class keeps track of the SPI_SP_INPUT_ADDR config register, which 3220b57cec5SDimitry Andric /// tells the hardware which interpolation parameters to load. 3230b57cec5SDimitry Andric class SIMachineFunctionInfo final : public AMDGPUMachineFunction { 3240b57cec5SDimitry Andric friend class GCNTargetMachine; 3250b57cec5SDimitry Andric 3260b57cec5SDimitry Andric unsigned TIDReg = AMDGPU::NoRegister; 3270b57cec5SDimitry Andric 3280b57cec5SDimitry Andric // Registers that may be reserved for spilling purposes. These may be the same 3290b57cec5SDimitry Andric // as the input registers. 3300b57cec5SDimitry Andric unsigned ScratchRSrcReg = AMDGPU::PRIVATE_RSRC_REG; 3310b57cec5SDimitry Andric unsigned ScratchWaveOffsetReg = AMDGPU::SCRATCH_WAVE_OFFSET_REG; 3320b57cec5SDimitry Andric 3330b57cec5SDimitry Andric // This is the current function's incremented size from the kernel's scratch 3340b57cec5SDimitry Andric // wave offset register. For an entry function, this is exactly the same as 3350b57cec5SDimitry Andric // the ScratchWaveOffsetReg. 3360b57cec5SDimitry Andric unsigned FrameOffsetReg = AMDGPU::FP_REG; 3370b57cec5SDimitry Andric 3380b57cec5SDimitry Andric // Top of the stack SGPR offset derived from the ScratchWaveOffsetReg. 3390b57cec5SDimitry Andric unsigned StackPtrOffsetReg = AMDGPU::SP_REG; 3400b57cec5SDimitry Andric 3410b57cec5SDimitry Andric AMDGPUFunctionArgInfo ArgInfo; 3420b57cec5SDimitry Andric 3430b57cec5SDimitry Andric // Graphics info. 3440b57cec5SDimitry Andric unsigned PSInputAddr = 0; 3450b57cec5SDimitry Andric unsigned PSInputEnable = 0; 3460b57cec5SDimitry Andric 3470b57cec5SDimitry Andric /// Number of bytes of arguments this function has on the stack. If the callee 3480b57cec5SDimitry Andric /// is expected to restore the argument stack this should be a multiple of 16, 3490b57cec5SDimitry Andric /// all usable during a tail call. 3500b57cec5SDimitry Andric /// 3510b57cec5SDimitry Andric /// The alternative would forbid tail call optimisation in some cases: if we 3520b57cec5SDimitry Andric /// want to transfer control from a function with 8-bytes of stack-argument 3530b57cec5SDimitry Andric /// space to a function with 16-bytes then misalignment of this value would 3540b57cec5SDimitry Andric /// make a stack adjustment necessary, which could not be undone by the 3550b57cec5SDimitry Andric /// callee. 3560b57cec5SDimitry Andric unsigned BytesInStackArgArea = 0; 3570b57cec5SDimitry Andric 3580b57cec5SDimitry Andric bool ReturnsVoid = true; 3590b57cec5SDimitry Andric 3600b57cec5SDimitry Andric // A pair of default/requested minimum/maximum flat work group sizes. 3610b57cec5SDimitry Andric // Minimum - first, maximum - second. 3620b57cec5SDimitry Andric std::pair<unsigned, unsigned> FlatWorkGroupSizes = {0, 0}; 3630b57cec5SDimitry Andric 3640b57cec5SDimitry Andric // A pair of default/requested minimum/maximum number of waves per execution 3650b57cec5SDimitry Andric // unit. Minimum - first, maximum - second. 3660b57cec5SDimitry Andric std::pair<unsigned, unsigned> WavesPerEU = {0, 0}; 3670b57cec5SDimitry Andric 3680b57cec5SDimitry Andric DenseMap<const Value *, 3690b57cec5SDimitry Andric std::unique_ptr<const AMDGPUBufferPseudoSourceValue>> BufferPSVs; 3700b57cec5SDimitry Andric DenseMap<const Value *, 3710b57cec5SDimitry Andric std::unique_ptr<const AMDGPUImagePseudoSourceValue>> ImagePSVs; 3720b57cec5SDimitry Andric std::unique_ptr<const AMDGPUGWSResourcePseudoSourceValue> GWSResourcePSV; 3730b57cec5SDimitry Andric 3740b57cec5SDimitry Andric private: 3750b57cec5SDimitry Andric unsigned LDSWaveSpillSize = 0; 3760b57cec5SDimitry Andric unsigned NumUserSGPRs = 0; 3770b57cec5SDimitry Andric unsigned NumSystemSGPRs = 0; 3780b57cec5SDimitry Andric 3790b57cec5SDimitry Andric bool HasSpilledSGPRs = false; 3800b57cec5SDimitry Andric bool HasSpilledVGPRs = false; 3810b57cec5SDimitry Andric bool HasNonSpillStackObjects = false; 3820b57cec5SDimitry Andric bool IsStackRealigned = false; 3830b57cec5SDimitry Andric 3840b57cec5SDimitry Andric unsigned NumSpilledSGPRs = 0; 3850b57cec5SDimitry Andric unsigned NumSpilledVGPRs = 0; 3860b57cec5SDimitry Andric 3870b57cec5SDimitry Andric // Feature bits required for inputs passed in user SGPRs. 3880b57cec5SDimitry Andric bool PrivateSegmentBuffer : 1; 3890b57cec5SDimitry Andric bool DispatchPtr : 1; 3900b57cec5SDimitry Andric bool QueuePtr : 1; 3910b57cec5SDimitry Andric bool KernargSegmentPtr : 1; 3920b57cec5SDimitry Andric bool DispatchID : 1; 3930b57cec5SDimitry Andric bool FlatScratchInit : 1; 3940b57cec5SDimitry Andric 3950b57cec5SDimitry Andric // Feature bits required for inputs passed in system SGPRs. 3960b57cec5SDimitry Andric bool WorkGroupIDX : 1; // Always initialized. 3970b57cec5SDimitry Andric bool WorkGroupIDY : 1; 3980b57cec5SDimitry Andric bool WorkGroupIDZ : 1; 3990b57cec5SDimitry Andric bool WorkGroupInfo : 1; 4000b57cec5SDimitry Andric bool PrivateSegmentWaveByteOffset : 1; 4010b57cec5SDimitry Andric 4020b57cec5SDimitry Andric bool WorkItemIDX : 1; // Always initialized. 4030b57cec5SDimitry Andric bool WorkItemIDY : 1; 4040b57cec5SDimitry Andric bool WorkItemIDZ : 1; 4050b57cec5SDimitry Andric 4060b57cec5SDimitry Andric // Private memory buffer 4070b57cec5SDimitry Andric // Compute directly in sgpr[0:1] 4080b57cec5SDimitry Andric // Other shaders indirect 64-bits at sgpr[0:1] 4090b57cec5SDimitry Andric bool ImplicitBufferPtr : 1; 4100b57cec5SDimitry Andric 4110b57cec5SDimitry Andric // Pointer to where the ABI inserts special kernel arguments separate from the 4120b57cec5SDimitry Andric // user arguments. This is an offset from the KernargSegmentPtr. 4130b57cec5SDimitry Andric bool ImplicitArgPtr : 1; 4140b57cec5SDimitry Andric 4150b57cec5SDimitry Andric // The hard-wired high half of the address of the global information table 4160b57cec5SDimitry Andric // for AMDPAL OS type. 0xffffffff represents no hard-wired high half, since 4170b57cec5SDimitry Andric // current hardware only allows a 16 bit value. 4180b57cec5SDimitry Andric unsigned GITPtrHigh; 4190b57cec5SDimitry Andric 4200b57cec5SDimitry Andric unsigned HighBitsOf32BitAddress; 4210b57cec5SDimitry Andric unsigned GDSSize; 4220b57cec5SDimitry Andric 4230b57cec5SDimitry Andric // Current recorded maximum possible occupancy. 4240b57cec5SDimitry Andric unsigned Occupancy; 4250b57cec5SDimitry Andric 4260b57cec5SDimitry Andric MCPhysReg getNextUserSGPR() const; 4270b57cec5SDimitry Andric 4280b57cec5SDimitry Andric MCPhysReg getNextSystemSGPR() const; 4290b57cec5SDimitry Andric 4300b57cec5SDimitry Andric public: 4310b57cec5SDimitry Andric struct SpilledReg { 4320b57cec5SDimitry Andric unsigned VGPR = 0; 4330b57cec5SDimitry Andric int Lane = -1; 4340b57cec5SDimitry Andric 4350b57cec5SDimitry Andric SpilledReg() = default; 4360b57cec5SDimitry Andric SpilledReg(unsigned R, int L) : VGPR (R), Lane (L) {} 4370b57cec5SDimitry Andric 4380b57cec5SDimitry Andric bool hasLane() { return Lane != -1;} 4390b57cec5SDimitry Andric bool hasReg() { return VGPR != 0;} 4400b57cec5SDimitry Andric }; 4410b57cec5SDimitry Andric 4420b57cec5SDimitry Andric struct SGPRSpillVGPRCSR { 4430b57cec5SDimitry Andric // VGPR used for SGPR spills 4440b57cec5SDimitry Andric unsigned VGPR; 4450b57cec5SDimitry Andric 4460b57cec5SDimitry Andric // If the VGPR is a CSR, the stack slot used to save/restore it in the 4470b57cec5SDimitry Andric // prolog/epilog. 4480b57cec5SDimitry Andric Optional<int> FI; 4490b57cec5SDimitry Andric 4500b57cec5SDimitry Andric SGPRSpillVGPRCSR(unsigned V, Optional<int> F) : VGPR(V), FI(F) {} 4510b57cec5SDimitry Andric }; 4520b57cec5SDimitry Andric 4530b57cec5SDimitry Andric struct VGPRSpillToAGPR { 4540b57cec5SDimitry Andric SmallVector<MCPhysReg, 32> Lanes; 4550b57cec5SDimitry Andric bool FullyAllocated = false; 4560b57cec5SDimitry Andric }; 4570b57cec5SDimitry Andric 4580b57cec5SDimitry Andric SparseBitVector<> WWMReservedRegs; 4590b57cec5SDimitry Andric 4600b57cec5SDimitry Andric void ReserveWWMRegister(unsigned reg) { WWMReservedRegs.set(reg); } 4610b57cec5SDimitry Andric 4620b57cec5SDimitry Andric private: 4630b57cec5SDimitry Andric // SGPR->VGPR spilling support. 4640b57cec5SDimitry Andric using SpillRegMask = std::pair<unsigned, unsigned>; 4650b57cec5SDimitry Andric 4660b57cec5SDimitry Andric // Track VGPR + wave index for each subregister of the SGPR spilled to 4670b57cec5SDimitry Andric // frameindex key. 4680b57cec5SDimitry Andric DenseMap<int, std::vector<SpilledReg>> SGPRToVGPRSpills; 4690b57cec5SDimitry Andric unsigned NumVGPRSpillLanes = 0; 4700b57cec5SDimitry Andric SmallVector<SGPRSpillVGPRCSR, 2> SpillVGPRs; 4710b57cec5SDimitry Andric 4720b57cec5SDimitry Andric DenseMap<int, VGPRSpillToAGPR> VGPRToAGPRSpills; 4730b57cec5SDimitry Andric 4740b57cec5SDimitry Andric // AGPRs used for VGPR spills. 4750b57cec5SDimitry Andric SmallVector<MCPhysReg, 32> SpillAGPR; 4760b57cec5SDimitry Andric 4770b57cec5SDimitry Andric // VGPRs used for AGPR spills. 4780b57cec5SDimitry Andric SmallVector<MCPhysReg, 32> SpillVGPR; 4790b57cec5SDimitry Andric 4800b57cec5SDimitry Andric public: // FIXME 4810b57cec5SDimitry Andric /// If this is set, an SGPR used for save/restore of the register used for the 4820b57cec5SDimitry Andric /// frame pointer. 4830b57cec5SDimitry Andric unsigned SGPRForFPSaveRestoreCopy = 0; 4840b57cec5SDimitry Andric Optional<int> FramePointerSaveIndex; 4850b57cec5SDimitry Andric 4860b57cec5SDimitry Andric public: 4870b57cec5SDimitry Andric SIMachineFunctionInfo(const MachineFunction &MF); 4880b57cec5SDimitry Andric 4890b57cec5SDimitry Andric bool initializeBaseYamlFields(const yaml::SIMachineFunctionInfo &YamlMFI); 4900b57cec5SDimitry Andric 4910b57cec5SDimitry Andric ArrayRef<SpilledReg> getSGPRToVGPRSpills(int FrameIndex) const { 4920b57cec5SDimitry Andric auto I = SGPRToVGPRSpills.find(FrameIndex); 4930b57cec5SDimitry Andric return (I == SGPRToVGPRSpills.end()) ? 4940b57cec5SDimitry Andric ArrayRef<SpilledReg>() : makeArrayRef(I->second); 4950b57cec5SDimitry Andric } 4960b57cec5SDimitry Andric 4970b57cec5SDimitry Andric ArrayRef<SGPRSpillVGPRCSR> getSGPRSpillVGPRs() const { 4980b57cec5SDimitry Andric return SpillVGPRs; 4990b57cec5SDimitry Andric } 5000b57cec5SDimitry Andric 5010b57cec5SDimitry Andric ArrayRef<MCPhysReg> getAGPRSpillVGPRs() const { 5020b57cec5SDimitry Andric return SpillAGPR; 5030b57cec5SDimitry Andric } 5040b57cec5SDimitry Andric 5050b57cec5SDimitry Andric ArrayRef<MCPhysReg> getVGPRSpillAGPRs() const { 5060b57cec5SDimitry Andric return SpillVGPR; 5070b57cec5SDimitry Andric } 5080b57cec5SDimitry Andric 5090b57cec5SDimitry Andric MCPhysReg getVGPRToAGPRSpill(int FrameIndex, unsigned Lane) const { 5100b57cec5SDimitry Andric auto I = VGPRToAGPRSpills.find(FrameIndex); 5110b57cec5SDimitry Andric return (I == VGPRToAGPRSpills.end()) ? (MCPhysReg)AMDGPU::NoRegister 5120b57cec5SDimitry Andric : I->second.Lanes[Lane]; 5130b57cec5SDimitry Andric } 5140b57cec5SDimitry Andric 5150b57cec5SDimitry Andric bool haveFreeLanesForSGPRSpill(const MachineFunction &MF, 5160b57cec5SDimitry Andric unsigned NumLane) const; 5170b57cec5SDimitry Andric bool allocateSGPRSpillToVGPR(MachineFunction &MF, int FI); 5180b57cec5SDimitry Andric bool allocateVGPRSpillToAGPR(MachineFunction &MF, int FI, bool isAGPRtoVGPR); 5190b57cec5SDimitry Andric void removeDeadFrameIndices(MachineFrameInfo &MFI); 5200b57cec5SDimitry Andric 5210b57cec5SDimitry Andric bool hasCalculatedTID() const { return TIDReg != 0; }; 5220b57cec5SDimitry Andric unsigned getTIDReg() const { return TIDReg; }; 5230b57cec5SDimitry Andric void setTIDReg(unsigned Reg) { TIDReg = Reg; } 5240b57cec5SDimitry Andric 5250b57cec5SDimitry Andric unsigned getBytesInStackArgArea() const { 5260b57cec5SDimitry Andric return BytesInStackArgArea; 5270b57cec5SDimitry Andric } 5280b57cec5SDimitry Andric 5290b57cec5SDimitry Andric void setBytesInStackArgArea(unsigned Bytes) { 5300b57cec5SDimitry Andric BytesInStackArgArea = Bytes; 5310b57cec5SDimitry Andric } 5320b57cec5SDimitry Andric 5330b57cec5SDimitry Andric // Add user SGPRs. 5340b57cec5SDimitry Andric unsigned addPrivateSegmentBuffer(const SIRegisterInfo &TRI); 5350b57cec5SDimitry Andric unsigned addDispatchPtr(const SIRegisterInfo &TRI); 5360b57cec5SDimitry Andric unsigned addQueuePtr(const SIRegisterInfo &TRI); 5370b57cec5SDimitry Andric unsigned addKernargSegmentPtr(const SIRegisterInfo &TRI); 5380b57cec5SDimitry Andric unsigned addDispatchID(const SIRegisterInfo &TRI); 5390b57cec5SDimitry Andric unsigned addFlatScratchInit(const SIRegisterInfo &TRI); 5400b57cec5SDimitry Andric unsigned addImplicitBufferPtr(const SIRegisterInfo &TRI); 5410b57cec5SDimitry Andric 5420b57cec5SDimitry Andric // Add system SGPRs. 5430b57cec5SDimitry Andric unsigned addWorkGroupIDX() { 5440b57cec5SDimitry Andric ArgInfo.WorkGroupIDX = ArgDescriptor::createRegister(getNextSystemSGPR()); 5450b57cec5SDimitry Andric NumSystemSGPRs += 1; 5460b57cec5SDimitry Andric return ArgInfo.WorkGroupIDX.getRegister(); 5470b57cec5SDimitry Andric } 5480b57cec5SDimitry Andric 5490b57cec5SDimitry Andric unsigned addWorkGroupIDY() { 5500b57cec5SDimitry Andric ArgInfo.WorkGroupIDY = ArgDescriptor::createRegister(getNextSystemSGPR()); 5510b57cec5SDimitry Andric NumSystemSGPRs += 1; 5520b57cec5SDimitry Andric return ArgInfo.WorkGroupIDY.getRegister(); 5530b57cec5SDimitry Andric } 5540b57cec5SDimitry Andric 5550b57cec5SDimitry Andric unsigned addWorkGroupIDZ() { 5560b57cec5SDimitry Andric ArgInfo.WorkGroupIDZ = ArgDescriptor::createRegister(getNextSystemSGPR()); 5570b57cec5SDimitry Andric NumSystemSGPRs += 1; 5580b57cec5SDimitry Andric return ArgInfo.WorkGroupIDZ.getRegister(); 5590b57cec5SDimitry Andric } 5600b57cec5SDimitry Andric 5610b57cec5SDimitry Andric unsigned addWorkGroupInfo() { 5620b57cec5SDimitry Andric ArgInfo.WorkGroupInfo = ArgDescriptor::createRegister(getNextSystemSGPR()); 5630b57cec5SDimitry Andric NumSystemSGPRs += 1; 5640b57cec5SDimitry Andric return ArgInfo.WorkGroupInfo.getRegister(); 5650b57cec5SDimitry Andric } 5660b57cec5SDimitry Andric 5670b57cec5SDimitry Andric // Add special VGPR inputs 5680b57cec5SDimitry Andric void setWorkItemIDX(ArgDescriptor Arg) { 5690b57cec5SDimitry Andric ArgInfo.WorkItemIDX = Arg; 5700b57cec5SDimitry Andric } 5710b57cec5SDimitry Andric 5720b57cec5SDimitry Andric void setWorkItemIDY(ArgDescriptor Arg) { 5730b57cec5SDimitry Andric ArgInfo.WorkItemIDY = Arg; 5740b57cec5SDimitry Andric } 5750b57cec5SDimitry Andric 5760b57cec5SDimitry Andric void setWorkItemIDZ(ArgDescriptor Arg) { 5770b57cec5SDimitry Andric ArgInfo.WorkItemIDZ = Arg; 5780b57cec5SDimitry Andric } 5790b57cec5SDimitry Andric 5800b57cec5SDimitry Andric unsigned addPrivateSegmentWaveByteOffset() { 5810b57cec5SDimitry Andric ArgInfo.PrivateSegmentWaveByteOffset 5820b57cec5SDimitry Andric = ArgDescriptor::createRegister(getNextSystemSGPR()); 5830b57cec5SDimitry Andric NumSystemSGPRs += 1; 5840b57cec5SDimitry Andric return ArgInfo.PrivateSegmentWaveByteOffset.getRegister(); 5850b57cec5SDimitry Andric } 5860b57cec5SDimitry Andric 5870b57cec5SDimitry Andric void setPrivateSegmentWaveByteOffset(unsigned Reg) { 5880b57cec5SDimitry Andric ArgInfo.PrivateSegmentWaveByteOffset = ArgDescriptor::createRegister(Reg); 5890b57cec5SDimitry Andric } 5900b57cec5SDimitry Andric 5910b57cec5SDimitry Andric bool hasPrivateSegmentBuffer() const { 5920b57cec5SDimitry Andric return PrivateSegmentBuffer; 5930b57cec5SDimitry Andric } 5940b57cec5SDimitry Andric 5950b57cec5SDimitry Andric bool hasDispatchPtr() const { 5960b57cec5SDimitry Andric return DispatchPtr; 5970b57cec5SDimitry Andric } 5980b57cec5SDimitry Andric 5990b57cec5SDimitry Andric bool hasQueuePtr() const { 6000b57cec5SDimitry Andric return QueuePtr; 6010b57cec5SDimitry Andric } 6020b57cec5SDimitry Andric 6030b57cec5SDimitry Andric bool hasKernargSegmentPtr() const { 6040b57cec5SDimitry Andric return KernargSegmentPtr; 6050b57cec5SDimitry Andric } 6060b57cec5SDimitry Andric 6070b57cec5SDimitry Andric bool hasDispatchID() const { 6080b57cec5SDimitry Andric return DispatchID; 6090b57cec5SDimitry Andric } 6100b57cec5SDimitry Andric 6110b57cec5SDimitry Andric bool hasFlatScratchInit() const { 6120b57cec5SDimitry Andric return FlatScratchInit; 6130b57cec5SDimitry Andric } 6140b57cec5SDimitry Andric 6150b57cec5SDimitry Andric bool hasWorkGroupIDX() const { 6160b57cec5SDimitry Andric return WorkGroupIDX; 6170b57cec5SDimitry Andric } 6180b57cec5SDimitry Andric 6190b57cec5SDimitry Andric bool hasWorkGroupIDY() const { 6200b57cec5SDimitry Andric return WorkGroupIDY; 6210b57cec5SDimitry Andric } 6220b57cec5SDimitry Andric 6230b57cec5SDimitry Andric bool hasWorkGroupIDZ() const { 6240b57cec5SDimitry Andric return WorkGroupIDZ; 6250b57cec5SDimitry Andric } 6260b57cec5SDimitry Andric 6270b57cec5SDimitry Andric bool hasWorkGroupInfo() const { 6280b57cec5SDimitry Andric return WorkGroupInfo; 6290b57cec5SDimitry Andric } 6300b57cec5SDimitry Andric 6310b57cec5SDimitry Andric bool hasPrivateSegmentWaveByteOffset() const { 6320b57cec5SDimitry Andric return PrivateSegmentWaveByteOffset; 6330b57cec5SDimitry Andric } 6340b57cec5SDimitry Andric 6350b57cec5SDimitry Andric bool hasWorkItemIDX() const { 6360b57cec5SDimitry Andric return WorkItemIDX; 6370b57cec5SDimitry Andric } 6380b57cec5SDimitry Andric 6390b57cec5SDimitry Andric bool hasWorkItemIDY() const { 6400b57cec5SDimitry Andric return WorkItemIDY; 6410b57cec5SDimitry Andric } 6420b57cec5SDimitry Andric 6430b57cec5SDimitry Andric bool hasWorkItemIDZ() const { 6440b57cec5SDimitry Andric return WorkItemIDZ; 6450b57cec5SDimitry Andric } 6460b57cec5SDimitry Andric 6470b57cec5SDimitry Andric bool hasImplicitArgPtr() const { 6480b57cec5SDimitry Andric return ImplicitArgPtr; 6490b57cec5SDimitry Andric } 6500b57cec5SDimitry Andric 6510b57cec5SDimitry Andric bool hasImplicitBufferPtr() const { 6520b57cec5SDimitry Andric return ImplicitBufferPtr; 6530b57cec5SDimitry Andric } 6540b57cec5SDimitry Andric 6550b57cec5SDimitry Andric AMDGPUFunctionArgInfo &getArgInfo() { 6560b57cec5SDimitry Andric return ArgInfo; 6570b57cec5SDimitry Andric } 6580b57cec5SDimitry Andric 6590b57cec5SDimitry Andric const AMDGPUFunctionArgInfo &getArgInfo() const { 6600b57cec5SDimitry Andric return ArgInfo; 6610b57cec5SDimitry Andric } 6620b57cec5SDimitry Andric 6630b57cec5SDimitry Andric std::pair<const ArgDescriptor *, const TargetRegisterClass *> 6640b57cec5SDimitry Andric getPreloadedValue(AMDGPUFunctionArgInfo::PreloadedValue Value) const { 6650b57cec5SDimitry Andric return ArgInfo.getPreloadedValue(Value); 6660b57cec5SDimitry Andric } 6670b57cec5SDimitry Andric 6680b57cec5SDimitry Andric Register getPreloadedReg(AMDGPUFunctionArgInfo::PreloadedValue Value) const { 6690b57cec5SDimitry Andric auto Arg = ArgInfo.getPreloadedValue(Value).first; 6700b57cec5SDimitry Andric return Arg ? Arg->getRegister() : Register(); 6710b57cec5SDimitry Andric } 6720b57cec5SDimitry Andric 6730b57cec5SDimitry Andric unsigned getGITPtrHigh() const { 6740b57cec5SDimitry Andric return GITPtrHigh; 6750b57cec5SDimitry Andric } 6760b57cec5SDimitry Andric 6778bcb0991SDimitry Andric uint32_t get32BitAddressHighBits() const { 6780b57cec5SDimitry Andric return HighBitsOf32BitAddress; 6790b57cec5SDimitry Andric } 6800b57cec5SDimitry Andric 6810b57cec5SDimitry Andric unsigned getGDSSize() const { 6820b57cec5SDimitry Andric return GDSSize; 6830b57cec5SDimitry Andric } 6840b57cec5SDimitry Andric 6850b57cec5SDimitry Andric unsigned getNumUserSGPRs() const { 6860b57cec5SDimitry Andric return NumUserSGPRs; 6870b57cec5SDimitry Andric } 6880b57cec5SDimitry Andric 6890b57cec5SDimitry Andric unsigned getNumPreloadedSGPRs() const { 6900b57cec5SDimitry Andric return NumUserSGPRs + NumSystemSGPRs; 6910b57cec5SDimitry Andric } 6920b57cec5SDimitry Andric 6930b57cec5SDimitry Andric unsigned getPrivateSegmentWaveByteOffsetSystemSGPR() const { 6940b57cec5SDimitry Andric return ArgInfo.PrivateSegmentWaveByteOffset.getRegister(); 6950b57cec5SDimitry Andric } 6960b57cec5SDimitry Andric 6970b57cec5SDimitry Andric /// Returns the physical register reserved for use as the resource 6980b57cec5SDimitry Andric /// descriptor for scratch accesses. 6990b57cec5SDimitry Andric unsigned getScratchRSrcReg() const { 7000b57cec5SDimitry Andric return ScratchRSrcReg; 7010b57cec5SDimitry Andric } 7020b57cec5SDimitry Andric 7030b57cec5SDimitry Andric void setScratchRSrcReg(unsigned Reg) { 7040b57cec5SDimitry Andric assert(Reg != 0 && "Should never be unset"); 7050b57cec5SDimitry Andric ScratchRSrcReg = Reg; 7060b57cec5SDimitry Andric } 7070b57cec5SDimitry Andric 7080b57cec5SDimitry Andric unsigned getScratchWaveOffsetReg() const { 7090b57cec5SDimitry Andric return ScratchWaveOffsetReg; 7100b57cec5SDimitry Andric } 7110b57cec5SDimitry Andric 7120b57cec5SDimitry Andric unsigned getFrameOffsetReg() const { 7130b57cec5SDimitry Andric return FrameOffsetReg; 7140b57cec5SDimitry Andric } 7150b57cec5SDimitry Andric 7160b57cec5SDimitry Andric void setFrameOffsetReg(unsigned Reg) { 7170b57cec5SDimitry Andric assert(Reg != 0 && "Should never be unset"); 7180b57cec5SDimitry Andric FrameOffsetReg = Reg; 7190b57cec5SDimitry Andric } 7200b57cec5SDimitry Andric 7210b57cec5SDimitry Andric void setStackPtrOffsetReg(unsigned Reg) { 7220b57cec5SDimitry Andric assert(Reg != 0 && "Should never be unset"); 7230b57cec5SDimitry Andric StackPtrOffsetReg = Reg; 7240b57cec5SDimitry Andric } 7250b57cec5SDimitry Andric 7260b57cec5SDimitry Andric // Note the unset value for this is AMDGPU::SP_REG rather than 7270b57cec5SDimitry Andric // NoRegister. This is mostly a workaround for MIR tests where state that 7280b57cec5SDimitry Andric // can't be directly computed from the function is not preserved in serialized 7290b57cec5SDimitry Andric // MIR. 7300b57cec5SDimitry Andric unsigned getStackPtrOffsetReg() const { 7310b57cec5SDimitry Andric return StackPtrOffsetReg; 7320b57cec5SDimitry Andric } 7330b57cec5SDimitry Andric 7340b57cec5SDimitry Andric void setScratchWaveOffsetReg(unsigned Reg) { 7350b57cec5SDimitry Andric assert(Reg != 0 && "Should never be unset"); 7360b57cec5SDimitry Andric ScratchWaveOffsetReg = Reg; 7370b57cec5SDimitry Andric } 7380b57cec5SDimitry Andric 7390b57cec5SDimitry Andric unsigned getQueuePtrUserSGPR() const { 7400b57cec5SDimitry Andric return ArgInfo.QueuePtr.getRegister(); 7410b57cec5SDimitry Andric } 7420b57cec5SDimitry Andric 7430b57cec5SDimitry Andric unsigned getImplicitBufferPtrUserSGPR() const { 7440b57cec5SDimitry Andric return ArgInfo.ImplicitBufferPtr.getRegister(); 7450b57cec5SDimitry Andric } 7460b57cec5SDimitry Andric 7470b57cec5SDimitry Andric bool hasSpilledSGPRs() const { 7480b57cec5SDimitry Andric return HasSpilledSGPRs; 7490b57cec5SDimitry Andric } 7500b57cec5SDimitry Andric 7510b57cec5SDimitry Andric void setHasSpilledSGPRs(bool Spill = true) { 7520b57cec5SDimitry Andric HasSpilledSGPRs = Spill; 7530b57cec5SDimitry Andric } 7540b57cec5SDimitry Andric 7550b57cec5SDimitry Andric bool hasSpilledVGPRs() const { 7560b57cec5SDimitry Andric return HasSpilledVGPRs; 7570b57cec5SDimitry Andric } 7580b57cec5SDimitry Andric 7590b57cec5SDimitry Andric void setHasSpilledVGPRs(bool Spill = true) { 7600b57cec5SDimitry Andric HasSpilledVGPRs = Spill; 7610b57cec5SDimitry Andric } 7620b57cec5SDimitry Andric 7630b57cec5SDimitry Andric bool hasNonSpillStackObjects() const { 7640b57cec5SDimitry Andric return HasNonSpillStackObjects; 7650b57cec5SDimitry Andric } 7660b57cec5SDimitry Andric 7670b57cec5SDimitry Andric void setHasNonSpillStackObjects(bool StackObject = true) { 7680b57cec5SDimitry Andric HasNonSpillStackObjects = StackObject; 7690b57cec5SDimitry Andric } 7700b57cec5SDimitry Andric 7710b57cec5SDimitry Andric bool isStackRealigned() const { 7720b57cec5SDimitry Andric return IsStackRealigned; 7730b57cec5SDimitry Andric } 7740b57cec5SDimitry Andric 7750b57cec5SDimitry Andric void setIsStackRealigned(bool Realigned = true) { 7760b57cec5SDimitry Andric IsStackRealigned = Realigned; 7770b57cec5SDimitry Andric } 7780b57cec5SDimitry Andric 7790b57cec5SDimitry Andric unsigned getNumSpilledSGPRs() const { 7800b57cec5SDimitry Andric return NumSpilledSGPRs; 7810b57cec5SDimitry Andric } 7820b57cec5SDimitry Andric 7830b57cec5SDimitry Andric unsigned getNumSpilledVGPRs() const { 7840b57cec5SDimitry Andric return NumSpilledVGPRs; 7850b57cec5SDimitry Andric } 7860b57cec5SDimitry Andric 7870b57cec5SDimitry Andric void addToSpilledSGPRs(unsigned num) { 7880b57cec5SDimitry Andric NumSpilledSGPRs += num; 7890b57cec5SDimitry Andric } 7900b57cec5SDimitry Andric 7910b57cec5SDimitry Andric void addToSpilledVGPRs(unsigned num) { 7920b57cec5SDimitry Andric NumSpilledVGPRs += num; 7930b57cec5SDimitry Andric } 7940b57cec5SDimitry Andric 7950b57cec5SDimitry Andric unsigned getPSInputAddr() const { 7960b57cec5SDimitry Andric return PSInputAddr; 7970b57cec5SDimitry Andric } 7980b57cec5SDimitry Andric 7990b57cec5SDimitry Andric unsigned getPSInputEnable() const { 8000b57cec5SDimitry Andric return PSInputEnable; 8010b57cec5SDimitry Andric } 8020b57cec5SDimitry Andric 8030b57cec5SDimitry Andric bool isPSInputAllocated(unsigned Index) const { 8040b57cec5SDimitry Andric return PSInputAddr & (1 << Index); 8050b57cec5SDimitry Andric } 8060b57cec5SDimitry Andric 8070b57cec5SDimitry Andric void markPSInputAllocated(unsigned Index) { 8080b57cec5SDimitry Andric PSInputAddr |= 1 << Index; 8090b57cec5SDimitry Andric } 8100b57cec5SDimitry Andric 8110b57cec5SDimitry Andric void markPSInputEnabled(unsigned Index) { 8120b57cec5SDimitry Andric PSInputEnable |= 1 << Index; 8130b57cec5SDimitry Andric } 8140b57cec5SDimitry Andric 8150b57cec5SDimitry Andric bool returnsVoid() const { 8160b57cec5SDimitry Andric return ReturnsVoid; 8170b57cec5SDimitry Andric } 8180b57cec5SDimitry Andric 8190b57cec5SDimitry Andric void setIfReturnsVoid(bool Value) { 8200b57cec5SDimitry Andric ReturnsVoid = Value; 8210b57cec5SDimitry Andric } 8220b57cec5SDimitry Andric 8230b57cec5SDimitry Andric /// \returns A pair of default/requested minimum/maximum flat work group sizes 8240b57cec5SDimitry Andric /// for this function. 8250b57cec5SDimitry Andric std::pair<unsigned, unsigned> getFlatWorkGroupSizes() const { 8260b57cec5SDimitry Andric return FlatWorkGroupSizes; 8270b57cec5SDimitry Andric } 8280b57cec5SDimitry Andric 8290b57cec5SDimitry Andric /// \returns Default/requested minimum flat work group size for this function. 8300b57cec5SDimitry Andric unsigned getMinFlatWorkGroupSize() const { 8310b57cec5SDimitry Andric return FlatWorkGroupSizes.first; 8320b57cec5SDimitry Andric } 8330b57cec5SDimitry Andric 8340b57cec5SDimitry Andric /// \returns Default/requested maximum flat work group size for this function. 8350b57cec5SDimitry Andric unsigned getMaxFlatWorkGroupSize() const { 8360b57cec5SDimitry Andric return FlatWorkGroupSizes.second; 8370b57cec5SDimitry Andric } 8380b57cec5SDimitry Andric 8390b57cec5SDimitry Andric /// \returns A pair of default/requested minimum/maximum number of waves per 8400b57cec5SDimitry Andric /// execution unit. 8410b57cec5SDimitry Andric std::pair<unsigned, unsigned> getWavesPerEU() const { 8420b57cec5SDimitry Andric return WavesPerEU; 8430b57cec5SDimitry Andric } 8440b57cec5SDimitry Andric 8450b57cec5SDimitry Andric /// \returns Default/requested minimum number of waves per execution unit. 8460b57cec5SDimitry Andric unsigned getMinWavesPerEU() const { 8470b57cec5SDimitry Andric return WavesPerEU.first; 8480b57cec5SDimitry Andric } 8490b57cec5SDimitry Andric 8500b57cec5SDimitry Andric /// \returns Default/requested maximum number of waves per execution unit. 8510b57cec5SDimitry Andric unsigned getMaxWavesPerEU() const { 8520b57cec5SDimitry Andric return WavesPerEU.second; 8530b57cec5SDimitry Andric } 8540b57cec5SDimitry Andric 8550b57cec5SDimitry Andric /// \returns SGPR used for \p Dim's work group ID. 8560b57cec5SDimitry Andric unsigned getWorkGroupIDSGPR(unsigned Dim) const { 8570b57cec5SDimitry Andric switch (Dim) { 8580b57cec5SDimitry Andric case 0: 8590b57cec5SDimitry Andric assert(hasWorkGroupIDX()); 8600b57cec5SDimitry Andric return ArgInfo.WorkGroupIDX.getRegister(); 8610b57cec5SDimitry Andric case 1: 8620b57cec5SDimitry Andric assert(hasWorkGroupIDY()); 8630b57cec5SDimitry Andric return ArgInfo.WorkGroupIDY.getRegister(); 8640b57cec5SDimitry Andric case 2: 8650b57cec5SDimitry Andric assert(hasWorkGroupIDZ()); 8660b57cec5SDimitry Andric return ArgInfo.WorkGroupIDZ.getRegister(); 8670b57cec5SDimitry Andric } 8680b57cec5SDimitry Andric llvm_unreachable("unexpected dimension"); 8690b57cec5SDimitry Andric } 8700b57cec5SDimitry Andric 8710b57cec5SDimitry Andric unsigned getLDSWaveSpillSize() const { 8720b57cec5SDimitry Andric return LDSWaveSpillSize; 8730b57cec5SDimitry Andric } 8740b57cec5SDimitry Andric 8750b57cec5SDimitry Andric const AMDGPUBufferPseudoSourceValue *getBufferPSV(const SIInstrInfo &TII, 8760b57cec5SDimitry Andric const Value *BufferRsrc) { 8770b57cec5SDimitry Andric assert(BufferRsrc); 8780b57cec5SDimitry Andric auto PSV = BufferPSVs.try_emplace( 8790b57cec5SDimitry Andric BufferRsrc, 8808bcb0991SDimitry Andric std::make_unique<AMDGPUBufferPseudoSourceValue>(TII)); 8810b57cec5SDimitry Andric return PSV.first->second.get(); 8820b57cec5SDimitry Andric } 8830b57cec5SDimitry Andric 8840b57cec5SDimitry Andric const AMDGPUImagePseudoSourceValue *getImagePSV(const SIInstrInfo &TII, 8850b57cec5SDimitry Andric const Value *ImgRsrc) { 8860b57cec5SDimitry Andric assert(ImgRsrc); 8870b57cec5SDimitry Andric auto PSV = ImagePSVs.try_emplace( 8880b57cec5SDimitry Andric ImgRsrc, 8898bcb0991SDimitry Andric std::make_unique<AMDGPUImagePseudoSourceValue>(TII)); 8900b57cec5SDimitry Andric return PSV.first->second.get(); 8910b57cec5SDimitry Andric } 8920b57cec5SDimitry Andric 8930b57cec5SDimitry Andric const AMDGPUGWSResourcePseudoSourceValue *getGWSPSV(const SIInstrInfo &TII) { 8940b57cec5SDimitry Andric if (!GWSResourcePSV) { 8950b57cec5SDimitry Andric GWSResourcePSV = 8968bcb0991SDimitry Andric std::make_unique<AMDGPUGWSResourcePseudoSourceValue>(TII); 8970b57cec5SDimitry Andric } 8980b57cec5SDimitry Andric 8990b57cec5SDimitry Andric return GWSResourcePSV.get(); 9000b57cec5SDimitry Andric } 9010b57cec5SDimitry Andric 9020b57cec5SDimitry Andric unsigned getOccupancy() const { 9030b57cec5SDimitry Andric return Occupancy; 9040b57cec5SDimitry Andric } 9050b57cec5SDimitry Andric 9060b57cec5SDimitry Andric unsigned getMinAllowedOccupancy() const { 9070b57cec5SDimitry Andric if (!isMemoryBound() && !needsWaveLimiter()) 9080b57cec5SDimitry Andric return Occupancy; 9090b57cec5SDimitry Andric return (Occupancy < 4) ? Occupancy : 4; 9100b57cec5SDimitry Andric } 9110b57cec5SDimitry Andric 9120b57cec5SDimitry Andric void limitOccupancy(const MachineFunction &MF); 9130b57cec5SDimitry Andric 9140b57cec5SDimitry Andric void limitOccupancy(unsigned Limit) { 9150b57cec5SDimitry Andric if (Occupancy > Limit) 9160b57cec5SDimitry Andric Occupancy = Limit; 9170b57cec5SDimitry Andric } 9180b57cec5SDimitry Andric 9190b57cec5SDimitry Andric void increaseOccupancy(const MachineFunction &MF, unsigned Limit) { 9200b57cec5SDimitry Andric if (Occupancy < Limit) 9210b57cec5SDimitry Andric Occupancy = Limit; 9220b57cec5SDimitry Andric limitOccupancy(MF); 9230b57cec5SDimitry Andric } 9240b57cec5SDimitry Andric }; 9250b57cec5SDimitry Andric 9260b57cec5SDimitry Andric } // end namespace llvm 9270b57cec5SDimitry Andric 9280b57cec5SDimitry Andric #endif // LLVM_LIB_TARGET_AMDGPU_SIMACHINEFUNCTIONINFO_H 929