1*0b57cec5SDimitry Andric //===-- AMDGPUMachineFunctionInfo.cpp ---------------------------------------=// 2*0b57cec5SDimitry Andric // 3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0b57cec5SDimitry Andric // 7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 8*0b57cec5SDimitry Andric 9*0b57cec5SDimitry Andric #include "AMDGPUMachineFunction.h" 10*0b57cec5SDimitry Andric #include "AMDGPUSubtarget.h" 11*0b57cec5SDimitry Andric #include "AMDGPUPerfHintAnalysis.h" 12*0b57cec5SDimitry Andric #include "llvm/CodeGen/MachineModuleInfo.h" 13*0b57cec5SDimitry Andric 14*0b57cec5SDimitry Andric using namespace llvm; 15*0b57cec5SDimitry Andric 16*0b57cec5SDimitry Andric AMDGPUMachineFunction::AMDGPUMachineFunction(const MachineFunction &MF) : 17*0b57cec5SDimitry Andric MachineFunctionInfo(), 185ffd83dbSDimitry Andric Mode(MF.getFunction()), 19*0b57cec5SDimitry Andric IsEntryFunction(AMDGPU::isEntryFunctionCC(MF.getFunction().getCallingConv())), 205ffd83dbSDimitry Andric NoSignedZerosFPMath(MF.getTarget().Options.NoSignedZerosFPMath) { 21*0b57cec5SDimitry Andric const AMDGPUSubtarget &ST = AMDGPUSubtarget::get(MF); 22*0b57cec5SDimitry Andric 23*0b57cec5SDimitry Andric // FIXME: Should initialize KernArgSize based on ExplicitKernelArgOffset, 24*0b57cec5SDimitry Andric // except reserved size is not correctly aligned. 25*0b57cec5SDimitry Andric const Function &F = MF.getFunction(); 26*0b57cec5SDimitry Andric 27*0b57cec5SDimitry Andric Attribute MemBoundAttr = F.getFnAttribute("amdgpu-memory-bound"); 28*0b57cec5SDimitry Andric MemoryBound = MemBoundAttr.isStringAttribute() && 29*0b57cec5SDimitry Andric MemBoundAttr.getValueAsString() == "true"; 30*0b57cec5SDimitry Andric 31*0b57cec5SDimitry Andric Attribute WaveLimitAttr = F.getFnAttribute("amdgpu-wave-limiter"); 32*0b57cec5SDimitry Andric WaveLimiter = WaveLimitAttr.isStringAttribute() && 33*0b57cec5SDimitry Andric WaveLimitAttr.getValueAsString() == "true"; 34*0b57cec5SDimitry Andric 35*0b57cec5SDimitry Andric CallingConv::ID CC = F.getCallingConv(); 36*0b57cec5SDimitry Andric if (CC == CallingConv::AMDGPU_KERNEL || CC == CallingConv::SPIR_KERNEL) 37*0b57cec5SDimitry Andric ExplicitKernArgSize = ST.getExplicitKernArgSize(F, MaxKernArgAlign); 38*0b57cec5SDimitry Andric } 39*0b57cec5SDimitry Andric 40*0b57cec5SDimitry Andric unsigned AMDGPUMachineFunction::allocateLDSGlobal(const DataLayout &DL, 415ffd83dbSDimitry Andric const GlobalVariable &GV) { 42*0b57cec5SDimitry Andric auto Entry = LocalMemoryObjects.insert(std::make_pair(&GV, 0)); 43*0b57cec5SDimitry Andric if (!Entry.second) 44*0b57cec5SDimitry Andric return Entry.first->second; 45*0b57cec5SDimitry Andric 465ffd83dbSDimitry Andric Align Alignment = 475ffd83dbSDimitry Andric DL.getValueOrABITypeAlignment(GV.getAlign(), GV.getValueType()); 48*0b57cec5SDimitry Andric 49*0b57cec5SDimitry Andric /// TODO: We should sort these to minimize wasted space due to alignment 50*0b57cec5SDimitry Andric /// padding. Currently the padding is decided by the first encountered use 51*0b57cec5SDimitry Andric /// during lowering. 525ffd83dbSDimitry Andric unsigned Offset = LDSSize = alignTo(LDSSize, Alignment); 53*0b57cec5SDimitry Andric 54*0b57cec5SDimitry Andric Entry.first->second = Offset; 55*0b57cec5SDimitry Andric LDSSize += DL.getTypeAllocSize(GV.getValueType()); 56*0b57cec5SDimitry Andric 57*0b57cec5SDimitry Andric return Offset; 58*0b57cec5SDimitry Andric } 59