1 //===- AMDGPUPerfHintAnalysis.h - analysis of functions memory traffic ----===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 /// \file 11 /// \brief Analyzes if a function potentially memory bound and if a kernel 12 /// kernel may benefit from limiting number of waves to reduce cache thrashing. 13 /// 14 //===----------------------------------------------------------------------===// 15 16 #ifndef LLVM_LIB_TARGET_AMDGPU_MDGPUPERFHINTANALYSIS_H 17 #define LLVM_LIB_TARGET_AMDGPU_MDGPUPERFHINTANALYSIS_H 18 #include "llvm/IR/ValueMap.h" 19 #include "llvm/Pass.h" 20 21 namespace llvm { 22 23 struct AMDGPUPerfHintAnalysis : public FunctionPass { 24 static char ID; 25 26 public: AMDGPUPerfHintAnalysisAMDGPUPerfHintAnalysis27 AMDGPUPerfHintAnalysis() : FunctionPass(ID) {} 28 29 bool runOnFunction(Function &F) override; 30 getAnalysisUsageAMDGPUPerfHintAnalysis31 void getAnalysisUsage(AnalysisUsage &AU) const override { 32 AU.setPreservesAll(); 33 } 34 35 bool isMemoryBound(const Function *F) const; 36 37 bool needsWaveLimiter(const Function *F) const; 38 39 struct FuncInfo { 40 unsigned MemInstCount; 41 unsigned InstCount; 42 unsigned IAMInstCount; // Indirect access memory instruction count 43 unsigned LSMInstCount; // Large stride memory instruction count FuncInfoAMDGPUPerfHintAnalysis::FuncInfo44 FuncInfo() : MemInstCount(0), InstCount(0), IAMInstCount(0), 45 LSMInstCount(0) {} 46 }; 47 48 typedef ValueMap<const Function*, FuncInfo> FuncInfoMap; 49 50 private: 51 52 FuncInfoMap FIM; 53 }; 54 } // namespace llvm 55 #endif // LLVM_LIB_TARGET_AMDGPU_MDGPUPERFHINTANALYSIS_H 56