xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AMDGPU/AMDGPUMachineFunction.cpp (revision cfd6422a5217410fbd66f7a7a8a64d9d85e61229)
1 //===-- AMDGPUMachineFunctionInfo.cpp ---------------------------------------=//
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 #include "AMDGPUMachineFunction.h"
10 #include "AMDGPUSubtarget.h"
11 #include "AMDGPUPerfHintAnalysis.h"
12 #include "llvm/CodeGen/MachineModuleInfo.h"
13 
14 using namespace llvm;
15 
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);
22 
23   // FIXME: Should initialize KernArgSize based on ExplicitKernelArgOffset,
24   // except reserved size is not correctly aligned.
25   const Function &F = MF.getFunction();
26 
27   Attribute MemBoundAttr = F.getFnAttribute("amdgpu-memory-bound");
28   MemoryBound = MemBoundAttr.isStringAttribute() &&
29                 MemBoundAttr.getValueAsString() == "true";
30 
31   Attribute WaveLimitAttr = F.getFnAttribute("amdgpu-wave-limiter");
32   WaveLimiter = WaveLimitAttr.isStringAttribute() &&
33                 WaveLimitAttr.getValueAsString() == "true";
34 
35   CallingConv::ID CC = F.getCallingConv();
36   if (CC == CallingConv::AMDGPU_KERNEL || CC == CallingConv::SPIR_KERNEL)
37     ExplicitKernArgSize = ST.getExplicitKernArgSize(F, MaxKernArgAlign);
38 }
39 
40 unsigned AMDGPUMachineFunction::allocateLDSGlobal(const DataLayout &DL,
41                                                   const GlobalVariable &GV) {
42   auto Entry = LocalMemoryObjects.insert(std::make_pair(&GV, 0));
43   if (!Entry.second)
44     return Entry.first->second;
45 
46   Align Alignment =
47       DL.getValueOrABITypeAlignment(GV.getAlign(), GV.getValueType());
48 
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
51   /// during lowering.
52   unsigned Offset = LDSSize = alignTo(LDSSize, Alignment);
53 
54   Entry.first->second = Offset;
55   LDSSize += DL.getTypeAllocSize(GV.getValueType());
56 
57   return Offset;
58 }
59