181ad6265SDimitry Andric //===- AMDGPUMemoryUtils.h - Memory related helper functions -*- C++ -*----===// 281ad6265SDimitry Andric // 381ad6265SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 481ad6265SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 581ad6265SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 681ad6265SDimitry Andric // 781ad6265SDimitry Andric //===----------------------------------------------------------------------===// 881ad6265SDimitry Andric 981ad6265SDimitry Andric #ifndef LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUMEMORYUTILS_H 1081ad6265SDimitry Andric #define LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUMEMORYUTILS_H 1181ad6265SDimitry Andric 12*0fca6ea1SDimitry Andric #include "llvm/ADT/ArrayRef.h" 13*0fca6ea1SDimitry Andric #include "llvm/ADT/DenseMap.h" 14*0fca6ea1SDimitry Andric #include "llvm/ADT/DenseSet.h" 15*0fca6ea1SDimitry Andric 1681ad6265SDimitry Andric namespace llvm { 1781ad6265SDimitry Andric 1881ad6265SDimitry Andric struct Align; 1981ad6265SDimitry Andric class AAResults; 2081ad6265SDimitry Andric class DataLayout; 2181ad6265SDimitry Andric class GlobalVariable; 2281ad6265SDimitry Andric class LoadInst; 2381ad6265SDimitry Andric class MemoryDef; 2481ad6265SDimitry Andric class MemorySSA; 2581ad6265SDimitry Andric class Value; 26*0fca6ea1SDimitry Andric class Function; 27*0fca6ea1SDimitry Andric class CallGraph; 28*0fca6ea1SDimitry Andric class Module; 2981ad6265SDimitry Andric 3081ad6265SDimitry Andric namespace AMDGPU { 3181ad6265SDimitry Andric 32*0fca6ea1SDimitry Andric using FunctionVariableMap = DenseMap<Function *, DenseSet<GlobalVariable *>>; 33*0fca6ea1SDimitry Andric using VariableFunctionMap = DenseMap<GlobalVariable *, DenseSet<Function *>>; 34*0fca6ea1SDimitry Andric 35*0fca6ea1SDimitry Andric Align getAlign(const DataLayout &DL, const GlobalVariable *GV); 3681ad6265SDimitry Andric 3706c3fb27SDimitry Andric bool isDynamicLDS(const GlobalVariable &GV); 38bdd1243dSDimitry Andric bool isLDSVariableToLower(const GlobalVariable &GV); 3981ad6265SDimitry Andric 40*0fca6ea1SDimitry Andric struct LDSUsesInfoTy { 41*0fca6ea1SDimitry Andric FunctionVariableMap direct_access; 42*0fca6ea1SDimitry Andric FunctionVariableMap indirect_access; 43*0fca6ea1SDimitry Andric }; 44*0fca6ea1SDimitry Andric 45*0fca6ea1SDimitry Andric bool eliminateConstantExprUsesOfLDSFromAllInstructions(Module &M); 46*0fca6ea1SDimitry Andric 47*0fca6ea1SDimitry Andric void getUsesOfLDSByFunction(const CallGraph &CG, Module &M, 48*0fca6ea1SDimitry Andric FunctionVariableMap &kernels, 49*0fca6ea1SDimitry Andric FunctionVariableMap &functions); 50*0fca6ea1SDimitry Andric 51*0fca6ea1SDimitry Andric bool isKernelLDS(const Function *F); 52*0fca6ea1SDimitry Andric 53*0fca6ea1SDimitry Andric LDSUsesInfoTy getTransitiveUsesOfLDS(const CallGraph &CG, Module &M); 54*0fca6ea1SDimitry Andric 55*0fca6ea1SDimitry Andric /// Strip FnAttr attribute from any functions where we may have 56*0fca6ea1SDimitry Andric /// introduced its use. 57*0fca6ea1SDimitry Andric void removeFnAttrFromReachable(CallGraph &CG, Function *KernelRoot, 58*0fca6ea1SDimitry Andric ArrayRef<StringRef> FnAttrs); 59*0fca6ea1SDimitry Andric 6081ad6265SDimitry Andric /// Given a \p Def clobbering a load from \p Ptr according to the MSSA check 6181ad6265SDimitry Andric /// if this is actually a memory update or an artificial clobber to facilitate 6281ad6265SDimitry Andric /// ordering constraints. 6381ad6265SDimitry Andric bool isReallyAClobber(const Value *Ptr, MemoryDef *Def, AAResults *AA); 6481ad6265SDimitry Andric 6581ad6265SDimitry Andric /// Check is a \p Load is clobbered in its function. 6681ad6265SDimitry Andric bool isClobberedInFunction(const LoadInst *Load, MemorySSA *MSSA, 6781ad6265SDimitry Andric AAResults *AA); 6881ad6265SDimitry Andric 6981ad6265SDimitry Andric } // end namespace AMDGPU 7081ad6265SDimitry Andric 7181ad6265SDimitry Andric } // end namespace llvm 7281ad6265SDimitry Andric 7381ad6265SDimitry Andric #endif // LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUMEMORYUTILS_H 74