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;
29
30namespace AMDGPU {
31
32using FunctionVariableMap = DenseMap<Function *, DenseSet<GlobalVariable *>>;
33using VariableFunctionMap = DenseMap<GlobalVariable *, DenseSet<Function *>>;
34
35Align getAlign(const DataLayout &DL, const GlobalVariable *GV);
36
37bool isDynamicLDS(const GlobalVariable &GV);
38bool isLDSVariableToLower(const GlobalVariable &GV);
39
40struct LDSUsesInfoTy {
41 FunctionVariableMap direct_access;
42 FunctionVariableMap indirect_access;
43};
44
45bool eliminateConstantExprUsesOfLDSFromAllInstructions(Module &M);
46
47void getUsesOfLDSByFunction(const CallGraph &CG, Module &M,
48 FunctionVariableMap &kernels,
49 FunctionVariableMap &functions);
50
51bool isKernelLDS(const Function *F);
52
53LDSUsesInfoTy getTransitiveUsesOfLDS(const CallGraph &CG, Module &M);
54
55/// Strip FnAttr attribute from any functions where we may have
56/// introduced its use.
57void removeFnAttrFromReachable(CallGraph &CG, Function *KernelRoot,
58 ArrayRef<StringRef> FnAttrs);
59
60/// Given a \p Def clobbering a load from \p Ptr according to the MSSA check
61/// if this is actually a memory update or an artificial clobber to facilitate
62/// ordering constraints.
63bool isReallyAClobber(const Value *Ptr, MemoryDef *Def, AAResults *AA);
64
65/// Check is a \p Load is clobbered in its function.
66bool isClobberedInFunction(const LoadInst *Load, MemorySSA *MSSA,
67 AAResults *AA);
68
69} // end namespace AMDGPU
70
71} // end namespace llvm
72
73#endif // LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUMEMORYUTILS_H
74