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