| 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 | |
| 16 | namespace llvm { |
| 17 | |
| 18 | struct Align; |
| 19 | class AAResults; |
| 20 | class DataLayout; |
| 21 | class GlobalVariable; |
| 22 | class LoadInst; |
| 23 | class MemoryDef; |
| 24 | class MemorySSA; |
| 25 | class Value; |
| 26 | class Function; |
| 27 | class CallGraph; |
| 28 | class Module; |
| 29 | class TargetExtType; |
| 30 | |
| 31 | namespace AMDGPU { |
| 32 | |
| 33 | using FunctionVariableMap = DenseMap<Function *, DenseSet<GlobalVariable *>>; |
| 34 | using VariableFunctionMap = DenseMap<GlobalVariable *, DenseSet<Function *>>; |
| 35 | |
| 36 | Align getAlign(const DataLayout &DL, const GlobalVariable *GV); |
| 37 | |
| 38 | // If GV is a named-barrier return its type. Otherwise return nullptr. |
| 39 | TargetExtType *isNamedBarrier(const GlobalVariable &GV); |
| 40 | |
| 41 | bool isDynamicLDS(const GlobalVariable &GV); |
| 42 | bool isLDSVariableToLower(const GlobalVariable &GV); |
| 43 | |
| 44 | struct LDSUsesInfoTy { |
| 45 | FunctionVariableMap direct_access; |
| 46 | FunctionVariableMap indirect_access; |
| 47 | bool HasSpecialGVs = false; |
| 48 | }; |
| 49 | |
| 50 | bool eliminateConstantExprUsesOfLDSFromAllInstructions(Module &M); |
| 51 | |
| 52 | void getUsesOfLDSByFunction(const CallGraph &CG, Module &M, |
| 53 | FunctionVariableMap &kernels, |
| 54 | FunctionVariableMap &functions); |
| 55 | |
| 56 | bool isKernelLDS(const Function *F); |
| 57 | |
| 58 | LDSUsesInfoTy getTransitiveUsesOfLDS(const CallGraph &CG, Module &M); |
| 59 | |
| 60 | /// Strip FnAttr attribute from any functions where we may have |
| 61 | /// introduced its use. |
| 62 | void 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. |
| 68 | bool isReallyAClobber(const Value *Ptr, MemoryDef *Def, AAResults *AA); |
| 69 | |
| 70 | /// Check is a \p Load is clobbered in its function. |
| 71 | bool 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 | |