xref: /llvm-project/llvm/lib/Target/AMDGPU/AMDGPUMachineFunction.cpp (revision 75e7192ba321da26bd1867b496dc0bbac1bb7c64)
1 //===-- AMDGPUMachineFunctionInfo.cpp ---------------------------------------=//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "AMDGPUMachineFunction.h"
11 #include "AMDGPUSubtarget.h"
12 #include "AMDGPUPerfHintAnalysis.h"
13 #include "llvm/CodeGen/MachineModuleInfo.h"
14 
15 using namespace llvm;
16 
17 AMDGPUMachineFunction::AMDGPUMachineFunction(const MachineFunction &MF) :
18   MachineFunctionInfo(),
19   LocalMemoryObjects(),
20   ExplicitKernArgSize(0),
21   MaxKernArgAlign(0),
22   LDSSize(0),
23   IsEntryFunction(AMDGPU::isEntryFunctionCC(MF.getFunction().getCallingConv())),
24   NoSignedZerosFPMath(MF.getTarget().Options.NoSignedZerosFPMath),
25   MemoryBound(false),
26   WaveLimiter(false) {
27   // FIXME: Should initialize KernArgSize based on ExplicitKernelArgOffset,
28   // except reserved size is not correctly aligned.
29 
30   if (auto *Resolver = MF.getMMI().getResolver()) {
31     if (AMDGPUPerfHintAnalysis *PHA = static_cast<AMDGPUPerfHintAnalysis*>(
32           Resolver->getAnalysisIfAvailable(&AMDGPUPerfHintAnalysisID, true))) {
33       MemoryBound = PHA->isMemoryBound(&MF.getFunction());
34       WaveLimiter = PHA->needsWaveLimiter(&MF.getFunction());
35     }
36   }
37 }
38 
39 unsigned AMDGPUMachineFunction::allocateLDSGlobal(const DataLayout &DL,
40                                                   const GlobalValue &GV) {
41   auto Entry = LocalMemoryObjects.insert(std::make_pair(&GV, 0));
42   if (!Entry.second)
43     return Entry.first->second;
44 
45   unsigned Align = GV.getAlignment();
46   if (Align == 0)
47     Align = DL.getABITypeAlignment(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, Align);
53 
54   Entry.first->second = Offset;
55   LDSSize += DL.getTypeAllocSize(GV.getValueType());
56 
57   return Offset;
58 }
59