xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AMDGPU/AMDGPUPerfHintAnalysis.h (revision 1323ec571215a77ddd21294f0871979d5ad6b992)
1 //===- AMDGPUPerfHintAnalysis.h ---- analysis of memory traffic -*- 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 /// \file
10 /// \brief Analyzes if a function potentially memory bound and if a kernel
11 /// kernel may benefit from limiting number of waves to reduce cache thrashing.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_LIB_TARGET_AMDGPU_MDGPUPERFHINTANALYSIS_H
16 #define LLVM_LIB_TARGET_AMDGPU_MDGPUPERFHINTANALYSIS_H
17 
18 #include "llvm/Analysis/CallGraphSCCPass.h"
19 #include "llvm/IR/ValueMap.h"
20 
21 namespace llvm {
22 
23 struct AMDGPUPerfHintAnalysis : public CallGraphSCCPass {
24   static char ID;
25 
26 public:
27   AMDGPUPerfHintAnalysis() : CallGraphSCCPass(ID) {}
28 
29   bool runOnSCC(CallGraphSCC &SCC) override;
30 
31   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 MemInstCost;
41     unsigned InstCost;
42     unsigned IAMInstCost; // Indirect access memory instruction count
43     unsigned LSMInstCost; // Large stride memory instruction count
44     FuncInfo() : MemInstCost(0), InstCost(0), IAMInstCost(0), LSMInstCost(0) {}
45   };
46 
47   typedef ValueMap<const Function*, FuncInfo> FuncInfoMap;
48 
49 private:
50 
51   FuncInfoMap FIM;
52 };
53 } // namespace llvm
54 #endif // LLVM_LIB_TARGET_AMDGPU_MDGPUPERFHINTANALYSIS_H
55