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(),
18 Mode(MF.getFunction()),
19 IsEntryFunction(AMDGPU::isEntryFunctionCC(MF.getFunction().getCallingConv())),
20 NoSignedZerosFPMath(MF.getTarget().Options.NoSignedZerosFPMath) {
21 const AMDGPUSubtarget &ST = AMDGPUSubtarget::get(MF);
23 // FIXME: Should initialize KernArgSize based on ExplicitKernelArgOffset,
24 // except reserved size is not correctly aligned.
25 const Function &F = MF.getFunction();
27 Attribute MemBoundAttr = F.getFnAttribute("amdgpu-memory-bound");
28 MemoryBound = MemBoundAttr.isStringAttribute() &&
29 MemBoundAttr.getValueAsString() == "true";
31 Attribute WaveLimitAttr = F.getFnAttribute("amdgpu-wave-limiter");
32 WaveLimiter = WaveLimitAttr.isStringAttribute() &&
33 WaveLimitAttr.getValueAsString() == "true";
35 CallingConv::ID CC = F.getCallingConv();
36 if (CC == CallingConv::AMDGPU_KERNEL || CC == CallingConv::SPIR_KERNEL)
37 ExplicitKernArgSize = ST.getExplicitKernArgSize(F, MaxKernArgAlign);
40 unsigned AMDGPUMachineFunction::allocateLDSGlobal(const DataLayout &DL,
41 const GlobalVariable &GV) {
42 auto Entry = LocalMemoryObjects.insert(std::make_pair(&GV, 0));
44 return Entry.first->second;
47 DL.getValueOrABITypeAlignment(GV.getAlign(), GV.getValueType());
49 /// TODO: We should sort these to minimize wasted space due to alignment
50 /// padding. Currently the padding is decided by the first encountered use
52 unsigned Offset = LDSSize = alignTo(LDSSize, Alignment);
54 Entry.first->second = Offset;
55 LDSSize += DL.getTypeAllocSize(GV.getValueType());