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 KernArgSize(0), 21 MaxKernArgAlign(0), 22 LDSSize(0), 23 ABIArgOffset(0), 24 IsEntryFunction(AMDGPU::isEntryFunctionCC(MF.getFunction().getCallingConv())), 25 NoSignedZerosFPMath(MF.getTarget().Options.NoSignedZerosFPMath), 26 MemoryBound(false), 27 WaveLimiter(false) { 28 // FIXME: Should initialize KernArgSize based on ExplicitKernelArgOffset, 29 // except reserved size is not correctly aligned. 30 31 if (auto *Resolver = MF.getMMI().getResolver()) { 32 if (AMDGPUPerfHintAnalysis *PHA = static_cast<AMDGPUPerfHintAnalysis*>( 33 Resolver->getAnalysisIfAvailable(&AMDGPUPerfHintAnalysisID, true))) { 34 MemoryBound = PHA->isMemoryBound(&MF.getFunction()); 35 WaveLimiter = PHA->needsWaveLimiter(&MF.getFunction()); 36 } 37 } 38 } 39 40 unsigned AMDGPUMachineFunction::allocateLDSGlobal(const DataLayout &DL, 41 const GlobalValue &GV) { 42 auto Entry = LocalMemoryObjects.insert(std::make_pair(&GV, 0)); 43 if (!Entry.second) 44 return Entry.first->second; 45 46 unsigned Align = GV.getAlignment(); 47 if (Align == 0) 48 Align = DL.getABITypeAlignment(GV.getValueType()); 49 50 /// TODO: We should sort these to minimize wasted space due to alignment 51 /// padding. Currently the padding is decided by the first encountered use 52 /// during lowering. 53 unsigned Offset = LDSSize = alignTo(LDSSize, Align); 54 55 Entry.first->second = Offset; 56 LDSSize += DL.getTypeAllocSize(GV.getValueType()); 57 58 return Offset; 59 } 60