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),
22 IsEntryFunction(AMDGPU::isEntryFunctionCC(MF
.getFunction().getCallingConv())),
23 NoSignedZerosFPMath(MF
.getTarget().Options
.NoSignedZerosFPMath
),
26 const AMDGPUSubtarget
&ST
= AMDGPUSubtarget::get(MF
);
28 // FIXME: Should initialize KernArgSize based on ExplicitKernelArgOffset,
29 // except reserved size is not correctly aligned.
30 const Function
&F
= MF
.getFunction();
32 Attribute MemBoundAttr
= F
.getFnAttribute("amdgpu-memory-bound");
33 MemoryBound
= MemBoundAttr
.isStringAttribute() &&
34 MemBoundAttr
.getValueAsString() == "true";
36 Attribute WaveLimitAttr
= F
.getFnAttribute("amdgpu-wave-limiter");
37 WaveLimiter
= WaveLimitAttr
.isStringAttribute() &&
38 WaveLimitAttr
.getValueAsString() == "true";
40 CallingConv::ID CC
= F
.getCallingConv();
41 if (CC
== CallingConv::AMDGPU_KERNEL
|| CC
== CallingConv::SPIR_KERNEL
)
42 ExplicitKernArgSize
= ST
.getExplicitKernArgSize(F
, MaxKernArgAlign
);
45 unsigned AMDGPUMachineFunction::allocateLDSGlobal(const DataLayout
&DL
,
46 const GlobalValue
&GV
) {
47 auto Entry
= LocalMemoryObjects
.insert(std::make_pair(&GV
, 0));
49 return Entry
.first
->second
;
51 unsigned Align
= GV
.getAlignment();
53 Align
= DL
.getABITypeAlignment(GV
.getValueType());
55 /// TODO: We should sort these to minimize wasted space due to alignment
56 /// padding. Currently the padding is decided by the first encountered use
58 unsigned Offset
= LDSSize
= alignTo(LDSSize
, Align
);
60 Entry
.first
->second
= Offset
;
61 LDSSize
+= DL
.getTypeAllocSize(GV
.getValueType());