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