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 //===----------------------------------------------------------------------===//
9 #include "AMDGPUMachineFunction.h"
10 #include "AMDGPUSubtarget.h"
11 #include "AMDGPUPerfHintAnalysis.h"
12 #include "llvm/CodeGen/MachineModuleInfo.h"
16 AMDGPUMachineFunction::AMDGPUMachineFunction(const MachineFunction &MF) :
17 MachineFunctionInfo(),
19 ExplicitKernArgSize(0),
21 IsEntryFunction(AMDGPU::isEntryFunctionCC(MF.getFunction().getCallingConv())),
22 NoSignedZerosFPMath(MF.getTarget().Options.NoSignedZerosFPMath),
25 const AMDGPUSubtarget &ST = AMDGPUSubtarget::get(MF);
27 // FIXME: Should initialize KernArgSize based on ExplicitKernelArgOffset,
28 // except reserved size is not correctly aligned.
29 const Function &F = MF.getFunction();
31 Attribute MemBoundAttr = F.getFnAttribute("amdgpu-memory-bound");
32 MemoryBound = MemBoundAttr.isStringAttribute() &&
33 MemBoundAttr.getValueAsString() == "true";
35 Attribute WaveLimitAttr = F.getFnAttribute("amdgpu-wave-limiter");
36 WaveLimiter = WaveLimitAttr.isStringAttribute() &&
37 WaveLimitAttr.getValueAsString() == "true";
39 CallingConv::ID CC = F.getCallingConv();
40 if (CC == CallingConv::AMDGPU_KERNEL || CC == CallingConv::SPIR_KERNEL)
41 ExplicitKernArgSize = ST.getExplicitKernArgSize(F, MaxKernArgAlign);
44 unsigned AMDGPUMachineFunction::allocateLDSGlobal(const DataLayout &DL,
45 const GlobalValue &GV) {
46 auto Entry = LocalMemoryObjects.insert(std::make_pair(&GV, 0));
48 return Entry.first->second;
50 unsigned Align = GV.getAlignment();
52 Align = DL.getABITypeAlignment(GV.getValueType());
54 /// TODO: We should sort these to minimize wasted space due to alignment
55 /// padding. Currently the padding is decided by the first encountered use
57 unsigned Offset = LDSSize = alignTo(LDSSize, Align);
59 Entry.first->second = Offset;
60 LDSSize += DL.getTypeAllocSize(GV.getValueType());