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(), Mode(MF.getFunction()), 18 IsEntryFunction( 19 AMDGPU::isEntryFunctionCC(MF.getFunction().getCallingConv())), 20 IsModuleEntryFunction( 21 AMDGPU::isModuleEntryFunctionCC(MF.getFunction().getCallingConv())), 22 NoSignedZerosFPMath(MF.getTarget().Options.NoSignedZerosFPMath) { 23 const AMDGPUSubtarget &ST = AMDGPUSubtarget::get(MF); 24 25 // FIXME: Should initialize KernArgSize based on ExplicitKernelArgOffset, 26 // except reserved size is not correctly aligned. 27 const Function &F = MF.getFunction(); 28 29 Attribute MemBoundAttr = F.getFnAttribute("amdgpu-memory-bound"); 30 MemoryBound = MemBoundAttr.isStringAttribute() && 31 MemBoundAttr.getValueAsString() == "true"; 32 33 Attribute WaveLimitAttr = F.getFnAttribute("amdgpu-wave-limiter"); 34 WaveLimiter = WaveLimitAttr.isStringAttribute() && 35 WaveLimitAttr.getValueAsString() == "true"; 36 37 CallingConv::ID CC = F.getCallingConv(); 38 if (CC == CallingConv::AMDGPU_KERNEL || CC == CallingConv::SPIR_KERNEL) 39 ExplicitKernArgSize = ST.getExplicitKernArgSize(F, MaxKernArgAlign); 40 } 41 42 unsigned AMDGPUMachineFunction::allocateLDSGlobal(const DataLayout &DL, 43 const GlobalVariable &GV) { 44 auto Entry = LocalMemoryObjects.insert(std::make_pair(&GV, 0)); 45 if (!Entry.second) 46 return Entry.first->second; 47 48 Align Alignment = 49 DL.getValueOrABITypeAlignment(GV.getAlign(), GV.getValueType()); 50 51 /// TODO: We should sort these to minimize wasted space due to alignment 52 /// padding. Currently the padding is decided by the first encountered use 53 /// during lowering. 54 unsigned Offset = StaticLDSSize = alignTo(StaticLDSSize, Alignment); 55 56 Entry.first->second = Offset; 57 StaticLDSSize += DL.getTypeAllocSize(GV.getValueType()); 58 59 // Update the LDS size considering the padding to align the dynamic shared 60 // memory. 61 LDSSize = alignTo(StaticLDSSize, DynLDSAlign); 62 63 return Offset; 64 } 65 66 void AMDGPUMachineFunction::setDynLDSAlign(const DataLayout &DL, 67 const GlobalVariable &GV) { 68 assert(DL.getTypeAllocSize(GV.getValueType()).isZero()); 69 70 Align Alignment = 71 DL.getValueOrABITypeAlignment(GV.getAlign(), GV.getValueType()); 72 if (Alignment <= DynLDSAlign) 73 return; 74 75 LDSSize = alignTo(StaticLDSSize, Alignment); 76 DynLDSAlign = Alignment; 77 } 78