1//===- AMDGPUMemoryUtils.h - Memory related helper functions -*- C++ -*----===//
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#ifndef LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUMEMORYUTILS_H
10#define LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUMEMORYUTILS_H
11
12#include "llvm/ADT/ArrayRef.h"
13#include "llvm/ADT/DenseMap.h"
14#include "llvm/ADT/DenseSet.h"
15
16namespace llvm {
17
18struct Align;
19class AAResults;
20class DataLayout;
21class GlobalVariable;
22class LoadInst;
23class MemoryDef;
24class MemorySSA;
25class Value;
26class Function;
27class CallGraph;
28class Module;
29class TargetExtType;
30
31namespace AMDGPU {
32
33using FunctionVariableMap = DenseMap<Function *, DenseSet<GlobalVariable *>>;
34using VariableFunctionMap = DenseMap<GlobalVariable *, DenseSet<Function *>>;
35
36Align getAlign(const DataLayout &DL, const GlobalVariable *GV);
37
38// If GV is a named-barrier return its type. Otherwise return nullptr.
39TargetExtType *isNamedBarrier(const GlobalVariable &GV);
40
41bool isDynamicLDS(const GlobalVariable &GV);
42bool isLDSVariableToLower(const GlobalVariable &GV);
43
44struct LDSUsesInfoTy {
45 FunctionVariableMap direct_access;
46 FunctionVariableMap indirect_access;
47 bool HasSpecialGVs = false;
48};
49
50bool eliminateConstantExprUsesOfLDSFromAllInstructions(Module &M);
51
52void getUsesOfLDSByFunction(const CallGraph &CG, Module &M,
53 FunctionVariableMap &kernels,
54 FunctionVariableMap &functions);
55
56bool isKernelLDS(const Function *F);
57
58LDSUsesInfoTy getTransitiveUsesOfLDS(const CallGraph &CG, Module &M);
59
60/// Strip FnAttr attribute from any functions where we may have
61/// introduced its use.
62void removeFnAttrFromReachable(CallGraph &CG, Function *KernelRoot,
63 ArrayRef<StringRef> FnAttrs);
64
65/// Given a \p Def clobbering a load from \p Ptr according to the MSSA check
66/// if this is actually a memory update or an artificial clobber to facilitate
67/// ordering constraints.
68bool isReallyAClobber(const Value *Ptr, MemoryDef *Def, AAResults *AA);
69
70/// Check is a \p Load is clobbered in its function.
71bool isClobberedInFunction(const LoadInst *Load, MemorySSA *MSSA,
72 AAResults *AA);
73
74} // end namespace AMDGPU
75
76} // end namespace llvm
77
78#endif // LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUMEMORYUTILS_H
79