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