1//===-- AMDGPUMachineFunctionInfo.cpp ---------------------------------------=// 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 7//===----------------------------------------------------------------------===// 26 KernelDynLDSName +=
F.getName();
27 KernelDynLDSName +=
".dynlds";
28return M->getNamedGlobal(KernelDynLDSName);
33Type *ArgTy = Arg.getType();
34if (
auto *PtrTy = dyn_cast<PointerType>(ArgTy)) {
44 : IsEntryFunction(AMDGPU::isEntryFunctionCC(
F.getCallingConv())),
45 IsModuleEntryFunction(
46 AMDGPU::isModuleEntryFunctionCC(
F.getCallingConv())),
47 IsChainFunction(AMDGPU::isChainCC(
F.getCallingConv())) {
49// FIXME: Should initialize KernArgSize based on ExplicitKernelArgOffset, 50// except reserved size is not correctly aligned. 52Attribute MemBoundAttr =
F.getFnAttribute(
"amdgpu-memory-bound");
55Attribute WaveLimitAttr =
F.getFnAttribute(
"amdgpu-wave-limiter");
58// FIXME: How is this attribute supposed to interact with statically known 60StringRef S =
F.getFnAttribute(
"amdgpu-gds-size").getValueAsString();
64// Assume the attribute allocates before any known GDS globals. 67// Second value, if present, is the maximum value that can be assigned. 68// Useful in PromoteAlloca or for LDS spills. Could be used for diagnostics 71F,
"amdgpu-lds-size", {0, UINT32_MAX},
true);
73// The two separate variables are only profitable when the LDS module lowering 74// pass is disabled. If graphics does not use dynamic LDS, this is never 75// profitable. Leaving cleanup for a later change. 83// FIXME: Shouldn't be target specific 84Attribute NSZAttr =
F.getFnAttribute(
"no-signed-zeros-fp-math");
96auto Entry = LocalMemoryObjects.insert(std::pair(&GV, 0));
98return Entry.first->second;
109 Entry.first->second = BarAddr.value();
110return BarAddr.value();
115// Absolute address LDS variables that exist prior to the LDS lowering 116// pass raise a fatal error in that pass. These failure modes are only 117// reachable if that lowering pass is disabled or broken. If/when adding 118// support for absolute addresses on user specified variables, the 119// alignment check moves to the lowering pass and the frame calculation 120// needs to take the user variables into consideration. 124if (ObjectStart !=
alignTo(ObjectStart, Alignment)) {
126"variable alignment");
130// If this is a module entry function, we can also sanity check against 131// the static frame. Strictly it would be better to check against the 132// attribute, i.e. that the variable is within the always-allocated 133// section, and not within some other non-absolute-address object 134// allocated here, but the extra error detection is minimal and we would 135// have to pass the Function around or cache the attribute value. 140"Absolute address LDS variable outside of static frame");
144 Entry.first->second = ObjectStart;
148 /// TODO: We should sort these to minimize wasted space due to alignment 149 /// padding. Currently the padding is decided by the first encountered use 155// Align LDS size to trailing, e.g. for aligning dynamic shared memory 159"expected region address space");
164// FIXME: Apply alignment of dynamic GDS 168 Entry.first->second =
Offset;
172std::optional<uint32_t>
174// TODO: Would be more consistent with the abs symbols to use a range 175MDNode *MD =
F.getMetadata(
"llvm.amdgcn.lds.kernel.id");
178 mdconst::extract<ConstantInt>(MD->
getOperand(0))) {
179uint64_t ZExt = KnownSize->getZExtValue();
180if (ZExt <= UINT32_MAX) {
188std::optional<uint32_t>
197if (
constAPInt *V = AbsSymRange->getSingleElement()) {
198 std::optional<uint64_t> ZExt = V->tryZExtValue();
199if (ZExt && (*ZExt <= UINT32_MAX)) {
221// If there is a dynamic LDS variable associated with this function F, every 222// further dynamic LDS instance (allocated by calling setDynLDSAlign) must 223// map to the same address. This holds because no LDS is allocated after the 224// lowering pass if there are dynamic LDS variables present. 229if (!Expect || (
Offset != *Expect)) {
static bool hasLDSKernelArgument(const Function &F)
static const GlobalVariable * getKernelDynLDSGlobalFromFunction(const Function &F)
Base class for AMDGPU specific classes of TargetSubtarget.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file contains the declarations for metadata subclasses.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
AMDGPUMachineFunction(const Function &F, const AMDGPUSubtarget &ST)
static std::optional< uint32_t > getLDSKernelIdMetadata(const Function &F)
Align DynLDSAlign
Align for dynamic shared memory if any.
bool isDynamicLDSUsed() const
void setUsesDynamicLDS(bool DynLDS)
uint32_t LDSSize
Number of bytes in the LDS that are being used.
void setDynLDSAlign(const Function &F, const GlobalVariable &GV)
static std::optional< uint32_t > getLDSAbsoluteAddress(const GlobalValue &GV)
uint64_t ExplicitKernArgSize
unsigned allocateLDSGlobal(const DataLayout &DL, const GlobalVariable &GV)
bool isModuleEntryFunction() const
uint32_t StaticLDSSize
Number of bytes in the LDS allocated statically.
Class for arbitrary precision integers.
This class represents an incoming formal argument to a Function.
bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
bool getValueAsBool() const
Return the attribute's value as a boolean.
StringRef getValueAsString() const
Return the attribute's value as a string.
This is the shared class of boolean and integer constants.
A parsed version of the target data layout string in and methods for querying it.
MaybeAlign getAlign() const
Returns the alignment of the given variable or function.
unsigned getAddressSpace() const
std::optional< ConstantRange > getAbsoluteSymbolRange() const
If this is an absolute symbol reference, returns the range of the symbol, otherwise returns std::null...
Type * getValueType() const
const MDOperand & getOperand(unsigned I) const
unsigned getNumOperands() const
Return number of MDNode operands.
A Module instance is used to store all the information related to an LLVM module.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef - Represent a constant reference to a string, i.e.
bool consumeInteger(unsigned Radix, T &Result)
Parse the current string as an integer of the specified radix.
constexpr bool empty() const
empty - Check if the string is empty.
The instances of the Type class are immutable: once they are created, they are never changed.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ REGION_ADDRESS
Address space for region memory. (GDS)
@ LOCAL_ADDRESS
Address space for local memory.
TargetExtType * isNamedBarrier(const GlobalVariable &GV)
std::pair< unsigned, unsigned > getIntegerPairAttribute(const Function &F, StringRef Name, std::pair< unsigned, unsigned > Default, bool OnlyFirstRequired)
@ AMDGPU_KERNEL
Used for AMDGPU code object kernels.
@ SPIR_KERNEL
Used for SPIR kernel functions.
This is an optimization pass for GlobalISel generic memory operations.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
This struct is a compact representation of a valid (non-zero power of two) alignment.