xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AMDGPU/AMDGPUMachineFunction.cpp (revision 5ffd83dbcc34f10e07f6d3e968ae6365869615f4)
10b57cec5SDimitry Andric //===-- AMDGPUMachineFunctionInfo.cpp ---------------------------------------=//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #include "AMDGPUMachineFunction.h"
100b57cec5SDimitry Andric #include "AMDGPUSubtarget.h"
110b57cec5SDimitry Andric #include "AMDGPUPerfHintAnalysis.h"
120b57cec5SDimitry Andric #include "llvm/CodeGen/MachineModuleInfo.h"
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric using namespace llvm;
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric AMDGPUMachineFunction::AMDGPUMachineFunction(const MachineFunction &MF) :
170b57cec5SDimitry Andric   MachineFunctionInfo(),
18*5ffd83dbSDimitry Andric   Mode(MF.getFunction()),
190b57cec5SDimitry Andric   IsEntryFunction(AMDGPU::isEntryFunctionCC(MF.getFunction().getCallingConv())),
20*5ffd83dbSDimitry Andric   NoSignedZerosFPMath(MF.getTarget().Options.NoSignedZerosFPMath) {
210b57cec5SDimitry Andric   const AMDGPUSubtarget &ST = AMDGPUSubtarget::get(MF);
220b57cec5SDimitry Andric 
230b57cec5SDimitry Andric   // FIXME: Should initialize KernArgSize based on ExplicitKernelArgOffset,
240b57cec5SDimitry Andric   // except reserved size is not correctly aligned.
250b57cec5SDimitry Andric   const Function &F = MF.getFunction();
260b57cec5SDimitry Andric 
270b57cec5SDimitry Andric   Attribute MemBoundAttr = F.getFnAttribute("amdgpu-memory-bound");
280b57cec5SDimitry Andric   MemoryBound = MemBoundAttr.isStringAttribute() &&
290b57cec5SDimitry Andric                 MemBoundAttr.getValueAsString() == "true";
300b57cec5SDimitry Andric 
310b57cec5SDimitry Andric   Attribute WaveLimitAttr = F.getFnAttribute("amdgpu-wave-limiter");
320b57cec5SDimitry Andric   WaveLimiter = WaveLimitAttr.isStringAttribute() &&
330b57cec5SDimitry Andric                 WaveLimitAttr.getValueAsString() == "true";
340b57cec5SDimitry Andric 
350b57cec5SDimitry Andric   CallingConv::ID CC = F.getCallingConv();
360b57cec5SDimitry Andric   if (CC == CallingConv::AMDGPU_KERNEL || CC == CallingConv::SPIR_KERNEL)
370b57cec5SDimitry Andric     ExplicitKernArgSize = ST.getExplicitKernArgSize(F, MaxKernArgAlign);
380b57cec5SDimitry Andric }
390b57cec5SDimitry Andric 
400b57cec5SDimitry Andric unsigned AMDGPUMachineFunction::allocateLDSGlobal(const DataLayout &DL,
41*5ffd83dbSDimitry Andric                                                   const GlobalVariable &GV) {
420b57cec5SDimitry Andric   auto Entry = LocalMemoryObjects.insert(std::make_pair(&GV, 0));
430b57cec5SDimitry Andric   if (!Entry.second)
440b57cec5SDimitry Andric     return Entry.first->second;
450b57cec5SDimitry Andric 
46*5ffd83dbSDimitry Andric   Align Alignment =
47*5ffd83dbSDimitry Andric       DL.getValueOrABITypeAlignment(GV.getAlign(), GV.getValueType());
480b57cec5SDimitry Andric 
490b57cec5SDimitry Andric   /// TODO: We should sort these to minimize wasted space due to alignment
500b57cec5SDimitry Andric   /// padding. Currently the padding is decided by the first encountered use
510b57cec5SDimitry Andric   /// during lowering.
52*5ffd83dbSDimitry Andric   unsigned Offset = LDSSize = alignTo(LDSSize, Alignment);
530b57cec5SDimitry Andric 
540b57cec5SDimitry Andric   Entry.first->second = Offset;
550b57cec5SDimitry Andric   LDSSize += DL.getTypeAllocSize(GV.getValueType());
560b57cec5SDimitry Andric 
570b57cec5SDimitry Andric   return Offset;
580b57cec5SDimitry Andric }
59