LLVM  12.0.0git
AMDGPUMachineFunction.cpp
Go to the documentation of this file.
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 
10 #include "AMDGPUPerfHintAnalysis.h"
11 #include "AMDGPUSubtarget.h"
14 
15 using namespace llvm;
16 
19  IsEntryFunction(
20  AMDGPU::isEntryFunctionCC(MF.getFunction().getCallingConv())),
21  IsModuleEntryFunction(
22  AMDGPU::isModuleEntryFunctionCC(MF.getFunction().getCallingConv())),
23  NoSignedZerosFPMath(MF.getTarget().Options.NoSignedZerosFPMath) {
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();
40  ExplicitKernArgSize = ST.getExplicitKernArgSize(F, MaxKernArgAlign);
41 }
42 
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.
63 
64  return Offset;
65 }
66 
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 }
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:111
AMDGPU specific subclass of TargetSubtarget.
SI Whole Quad Mode
This class represents lattice values for constants.
Definition: AllocatorList.h:23
AMDGPUMachineFunction(const MachineFunction &MF)
bool isModuleEntryFunctionCC(CallingConv::ID CC)
SPIR_KERNEL - Calling convention for SPIR kernel functions.
Definition: CallingConv.h:147
F(f)
Function & getFunction()
Return the LLVM function that this machine code represents.
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
static const AMDGPUSubtarget & get(const MachineFunction &MF)
bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
Definition: Attributes.cpp:246
unsigned StaticLDSSize
Number of bytes in the LDS allocated statically.
static Function * getFunction(Constant *C)
Definition: Evaluator.cpp:252
MaybeAlign getAlign() const
Returns the alignment of the given variable or function.
Definition: GlobalObject.h:82
bool isEntryFunctionCC(CallingConv::ID CC)
Align DynLDSAlign
Align for dynamic shared memory if any.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
uint64_t Offset
unsigned LDSSize
Number of bytes in the LDS that are being used.
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
Definition: Lint.cpp:517
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:158
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:275
Calling convention for AMDGPU code object kernels.
Definition: CallingConv.h:211
Type * getValueType() const
Definition: GlobalValue.h:273
void setDynLDSAlign(const DataLayout &DL, const GlobalVariable &GV)
unsigned allocateLDSGlobal(const DataLayout &DL, const GlobalVariable &GV)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Analyzes if a function potentially memory bound and if a kernel kernel may benefit from limiting numb...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL