LLVM  17.0.0git
AMDGPUMachineFunction.h
Go to the documentation of this file.
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"
15 #include "llvm/IR/DataLayout.h"
16 #include "llvm/IR/Function.h"
17 #include "llvm/IR/GlobalValue.h"
18 #include "llvm/IR/GlobalVariable.h"
19 
20 namespace llvm {
21 
22 class AMDGPUSubtarget;
23 class GCNSubtarget;
24 
26  /// A map to keep track of local memory objects and their offsets within the
27  /// local memory space.
29 
30 protected:
31  uint64_t ExplicitKernArgSize = 0; // Cache for this.
32  Align MaxKernArgAlign; // Cache for this.
33 
34  /// Number of bytes in the LDS that are being used.
37 
38  /// Number of bytes in the LDS allocated statically. This field is only used
39  /// in the instruction selector and not part of the machine function info.
42 
43  /// Align for dynamic shared memory if any. Dynamic shared memory is
44  /// allocated directly after the static one, i.e., LDSSize. Need to pad
45  /// LDSSize to ensure that dynamic one is aligned accordingly.
46  /// The maximal alignment is updated during IR translation or lowering
47  /// stages.
49 
50  // Kernels + shaders. i.e. functions called by the hardware and not called
51  // by other functions.
52  bool IsEntryFunction = false;
53 
54  // Entry points called by other functions instead of directly by the hardware.
55  bool IsModuleEntryFunction = false;
56 
57  bool NoSignedZerosFPMath = false;
58 
59  // Function may be memory bound.
60  bool MemoryBound = false;
61 
62  // Kernel may need limited waves per EU for better performance.
63  bool WaveLimiter = false;
64 
65 public:
67 
69  return ExplicitKernArgSize;
70  }
71 
73 
74  uint32_t getLDSSize() const {
75  return LDSSize;
76  }
77 
78  uint32_t getGDSSize() const {
79  return GDSSize;
80  }
81 
82  bool isEntryFunction() const {
83  return IsEntryFunction;
84  }
85 
87 
88  bool hasNoSignedZerosFPMath() const {
89  return NoSignedZerosFPMath;
90  }
91 
92  bool isMemoryBound() const {
93  return MemoryBound;
94  }
95 
96  bool needsWaveLimiter() const {
97  return WaveLimiter;
98  }
99 
100  unsigned allocateLDSGlobal(const DataLayout &DL, const GlobalVariable &GV) {
101  return allocateLDSGlobal(DL, GV, DynLDSAlign);
102  }
103 
104  unsigned allocateLDSGlobal(const DataLayout &DL, const GlobalVariable &GV,
105  Align Trailing);
106 
108 
109  // A kernel function may have an associated LDS allocation, and a kernel-scope
110  // LDS allocation must have an associated kernel function
111 
112  // LDS allocation should have an associated kernel function
113  static const Function *
115  static const GlobalVariable *
117 
118  // Module or kernel scope LDS variable
119  static bool isKnownAddressLDSGlobal(const GlobalVariable &GV);
120  static unsigned calculateKnownAddressOfLDSGlobal(const GlobalVariable &GV);
121 
122  static std::optional<uint32_t> getLDSKernelIdMetadata(const Function &F);
123 
124  Align getDynLDSAlign() const { return DynLDSAlign; }
125 
126  void setDynLDSAlign(const DataLayout &DL, const GlobalVariable &GV);
127 };
128 
129 }
130 #endif
llvm::AMDGPUMachineFunction::getMaxKernArgAlign
Align getMaxKernArgAlign() const
Definition: AMDGPUMachineFunction.h:72
llvm::AMDGPUMachineFunction::getLDSKernelIdMetadata
static std::optional< uint32_t > getLDSKernelIdMetadata(const Function &F)
Definition: AMDGPUMachineFunction.cpp:203
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::AMDGPUMachineFunction::ExplicitKernArgSize
uint64_t ExplicitKernArgSize
Definition: AMDGPUMachineFunction.h:31
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:114
llvm::Function
Definition: Function.h:59
llvm::AMDGPUMachineFunction::getDynLDSAlign
Align getDynLDSAlign() const
Definition: AMDGPUMachineFunction.h:124
llvm::GlobalVariable
Definition: GlobalVariable.h:39
llvm::SmallDenseMap
Definition: DenseMap.h:880
llvm::AMDGPUMachineFunction::LDSSize
uint32_t LDSSize
Number of bytes in the LDS that are being used.
Definition: AMDGPUMachineFunction.h:35
llvm::AMDGPUMachineFunction::getLDSSize
uint32_t getLDSSize() const
Definition: AMDGPUMachineFunction.h:74
DenseMap.h
AMDGPUSubtarget
#define AMDGPUSubtarget
Definition: AMDGPUInstructionSelector.cpp:43
llvm::AMDGPUMachineFunction::WaveLimiter
bool WaveLimiter
Definition: AMDGPUMachineFunction.h:63
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::AMDGPUMachineFunction::getKernelLDSGlobalFromFunction
static const GlobalVariable * getKernelLDSGlobalFromFunction(const Function &F)
Definition: AMDGPUMachineFunction.cpp:109
llvm::AMDGPUMachineFunction::needsWaveLimiter
bool needsWaveLimiter() const
Definition: AMDGPUMachineFunction.h:96
GlobalValue.h
llvm::AMDGPUMachineFunction::NoSignedZerosFPMath
bool NoSignedZerosFPMath
Definition: AMDGPUMachineFunction.h:57
llvm::AMDGPUMachineFunction::allocateLDSGlobal
unsigned allocateLDSGlobal(const DataLayout &DL, const GlobalVariable &GV)
Definition: AMDGPUMachineFunction.h:100
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::AMDGPUMachineFunction::MemoryBound
bool MemoryBound
Definition: AMDGPUMachineFunction.h:60
llvm::AMDGPUMachineFunction::allocateKnownAddressLDSGlobal
void allocateKnownAddressLDSGlobal(const Function &F)
Definition: AMDGPUMachineFunction.cpp:153
llvm::AMDGPUSubtarget
Definition: AMDGPUSubtarget.h:29
uint64_t
llvm::ARM_MB::ST
@ ST
Definition: ARMBaseInfo.h:73
llvm::AMDGPUMachineFunction::isEntryFunction
bool isEntryFunction() const
Definition: AMDGPUMachineFunction.h:82
llvm::AMDGPUMachineFunction::IsModuleEntryFunction
bool IsModuleEntryFunction
Definition: AMDGPUMachineFunction.h:55
llvm::AMDGPUMachineFunction::getExplicitKernArgSize
uint64_t getExplicitKernArgSize() const
Definition: AMDGPUMachineFunction.h:68
llvm::AMDGPUMachineFunction::getGDSSize
uint32_t getGDSSize() const
Definition: AMDGPUMachineFunction.h:78
llvm::AMDGPUMachineFunction::isMemoryBound
bool isMemoryBound() const
Definition: AMDGPUMachineFunction.h:92
DataLayout.h
uint32_t
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::AMDGPUMachineFunction::StaticLDSSize
uint32_t StaticLDSSize
Number of bytes in the LDS allocated statically.
Definition: AMDGPUMachineFunction.h:40
llvm::AMDGPUMachineFunction::calculateKnownAddressOfLDSGlobal
static unsigned calculateKnownAddressOfLDSGlobal(const GlobalVariable &GV)
Definition: AMDGPUMachineFunction.cpp:122
llvm::AMDGPUMachineFunction::isModuleEntryFunction
bool isModuleEntryFunction() const
Definition: AMDGPUMachineFunction.h:86
GlobalVariable.h
Function.h
llvm::AMDGPUMachineFunction::hasNoSignedZerosFPMath
bool hasNoSignedZerosFPMath() const
Definition: AMDGPUMachineFunction.h:88
llvm::AMDGPUMachineFunction::IsEntryFunction
bool IsEntryFunction
Definition: AMDGPUMachineFunction.h:52
llvm::AMDGPUMachineFunction::getKernelLDSFunctionFromGlobal
static const Function * getKernelLDSFunctionFromGlobal(const GlobalVariable &GV)
Definition: AMDGPUMachineFunction.cpp:98
llvm::AMDGPUMachineFunction::StaticGDSSize
uint32_t StaticGDSSize
Definition: AMDGPUMachineFunction.h:41
llvm::AMDGPUMachineFunction::AMDGPUMachineFunction
AMDGPUMachineFunction(const Function &F, const AMDGPUSubtarget &ST)
Definition: AMDGPUMachineFunction.cpp:19
MachineFunction.h
llvm::AMDGPUMachineFunction
Definition: AMDGPUMachineFunction.h:25
llvm::MachineFunctionInfo
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
Definition: MachineFunction.h:95
llvm::AMDGPUMachineFunction::MaxKernArgAlign
Align MaxKernArgAlign
Definition: AMDGPUMachineFunction.h:32
llvm::AMDGPUMachineFunction::GDSSize
uint32_t GDSSize
Definition: AMDGPUMachineFunction.h:36
llvm::AMDGPUMachineFunction::DynLDSAlign
Align DynLDSAlign
Align for dynamic shared memory if any.
Definition: AMDGPUMachineFunction.h:48
llvm::AMDGPUMachineFunction::isKnownAddressLDSGlobal
static bool isKnownAddressLDSGlobal(const GlobalVariable &GV)
Definition: AMDGPUMachineFunction.cpp:92
AMDGPUBaseInfo.h
llvm::AMDGPUMachineFunction::setDynLDSAlign
void setDynLDSAlign(const DataLayout &DL, const GlobalVariable &GV)
Definition: AMDGPUMachineFunction.cpp:217