xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AMDGPU/AMDGPUMachineFunction.cpp (revision a7dea1671b87c07d2d266f836bfa8b58efc7c134)
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   LocalMemoryObjects(),
19   ExplicitKernArgSize(0),
20   LDSSize(0),
21   IsEntryFunction(AMDGPU::isEntryFunctionCC(MF.getFunction().getCallingConv())),
22   NoSignedZerosFPMath(MF.getTarget().Options.NoSignedZerosFPMath),
23   MemoryBound(false),
24   WaveLimiter(false) {
25   const AMDGPUSubtarget &ST = AMDGPUSubtarget::get(MF);
26 
27   // FIXME: Should initialize KernArgSize based on ExplicitKernelArgOffset,
28   // except reserved size is not correctly aligned.
29   const Function &F = MF.getFunction();
30 
31   Attribute MemBoundAttr = F.getFnAttribute("amdgpu-memory-bound");
32   MemoryBound = MemBoundAttr.isStringAttribute() &&
33                 MemBoundAttr.getValueAsString() == "true";
34 
35   Attribute WaveLimitAttr = F.getFnAttribute("amdgpu-wave-limiter");
36   WaveLimiter = WaveLimitAttr.isStringAttribute() &&
37                 WaveLimitAttr.getValueAsString() == "true";
38 
39   CallingConv::ID CC = F.getCallingConv();
40   if (CC == CallingConv::AMDGPU_KERNEL || CC == CallingConv::SPIR_KERNEL)
41     ExplicitKernArgSize = ST.getExplicitKernArgSize(F, MaxKernArgAlign);
42 }
43 
44 unsigned AMDGPUMachineFunction::allocateLDSGlobal(const DataLayout &DL,
45                                                   const GlobalValue &GV) {
46   auto Entry = LocalMemoryObjects.insert(std::make_pair(&GV, 0));
47   if (!Entry.second)
48     return Entry.first->second;
49 
50   unsigned Align = GV.getAlignment();
51   if (Align == 0)
52     Align = DL.getABITypeAlignment(GV.getValueType());
53 
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
56   /// during lowering.
57   unsigned Offset = LDSSize = alignTo(LDSSize, Align);
58 
59   Entry.first->second = Offset;
60   LDSSize += DL.getTypeAllocSize(GV.getValueType());
61 
62   return Offset;
63 }
64