1 //===-- AMDGPUMachineFunctionInfo.h -------------------------------*- C++ -*-=// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEFUNCTION_H 10 #define LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEFUNCTION_H 11 12 #include "Utils/AMDGPUBaseInfo.h" 13 #include "llvm/ADT/DenseMap.h" 14 #include "llvm/ADT/Optional.h" 15 #include "llvm/CodeGen/MachineFunction.h" 16 #include "llvm/IR/DataLayout.h" 17 #include "llvm/IR/Function.h" 18 #include "llvm/IR/GlobalValue.h" 19 #include "llvm/IR/GlobalVariable.h" 20 21 namespace llvm { 22 23 class AMDGPUMachineFunction : public MachineFunctionInfo { 24 /// A map to keep track of local memory objects and their offsets within the 25 /// local memory space. 26 SmallDenseMap<const GlobalValue *, unsigned, 4> LocalMemoryObjects; 27 28 protected: 29 uint64_t ExplicitKernArgSize = 0; // Cache for this. 30 Align MaxKernArgAlign; // Cache for this. 31 32 /// Number of bytes in the LDS that are being used. 33 uint32_t LDSSize = 0; 34 uint32_t GDSSize = 0; 35 36 /// Number of bytes in the LDS allocated statically. This field is only used 37 /// in the instruction selector and not part of the machine function info. 38 uint32_t StaticLDSSize = 0; 39 uint32_t StaticGDSSize = 0; 40 41 /// Align for dynamic shared memory if any. Dynamic shared memory is 42 /// allocated directly after the static one, i.e., LDSSize. Need to pad 43 /// LDSSize to ensure that dynamic one is aligned accordingly. 44 /// The maximal alignment is updated during IR translation or lowering 45 /// stages. 46 Align DynLDSAlign; 47 48 // State of MODE register, assumed FP mode. 49 AMDGPU::SIModeRegisterDefaults Mode; 50 51 // Kernels + shaders. i.e. functions called by the hardware and not called 52 // by other functions. 53 bool IsEntryFunction = false; 54 55 // Entry points called by other functions instead of directly by the hardware. 56 bool IsModuleEntryFunction = false; 57 58 bool NoSignedZerosFPMath = false; 59 60 // Function may be memory bound. 61 bool MemoryBound = false; 62 63 // Kernel may need limited waves per EU for better performance. 64 bool WaveLimiter = false; 65 66 public: 67 AMDGPUMachineFunction(const MachineFunction &MF); 68 69 uint64_t getExplicitKernArgSize() const { 70 return ExplicitKernArgSize; 71 } 72 73 Align getMaxKernArgAlign() const { return MaxKernArgAlign; } 74 75 uint32_t getLDSSize() const { 76 return LDSSize; 77 } 78 79 uint32_t getGDSSize() const { 80 return GDSSize; 81 } 82 83 AMDGPU::SIModeRegisterDefaults getMode() const { 84 return Mode; 85 } 86 87 bool isEntryFunction() const { 88 return IsEntryFunction; 89 } 90 91 bool isModuleEntryFunction() const { return IsModuleEntryFunction; } 92 93 bool hasNoSignedZerosFPMath() const { 94 return NoSignedZerosFPMath; 95 } 96 97 bool isMemoryBound() const { 98 return MemoryBound; 99 } 100 101 bool needsWaveLimiter() const { 102 return WaveLimiter; 103 } 104 105 unsigned allocateLDSGlobal(const DataLayout &DL, const GlobalVariable &GV); 106 void allocateModuleLDSGlobal(const Function &F); 107 108 static Optional<uint32_t> getLDSKernelIdMetadata(const Function &F); 109 110 Align getDynLDSAlign() const { return DynLDSAlign; } 111 112 void setDynLDSAlign(const DataLayout &DL, const GlobalVariable &GV); 113 }; 114 115 } 116 #endif 117