blob: 9599e09fbd962c41ff79efc0ed7403edbe300ab6 [file] [log] [blame]
Matt Arsenaulte7e23e32019-07-05 20:26:13 +00001//===- AMDGPUPerfHintAnalysis.h ---- analysis of memory traffic -*- C++ -*-===//
Stanislav Mekhanoshin1c538422018-05-25 17:25:12 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Stanislav Mekhanoshin1c538422018-05-25 17:25:12 +00006//
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
Matt Arsenaulte7e23e32019-07-05 20:26:13 +000017
18#include "llvm/Analysis/CallGraphSCCPass.h"
Stanislav Mekhanoshin1c538422018-05-25 17:25:12 +000019#include "llvm/IR/ValueMap.h"
20#include "llvm/Pass.h"
21
22namespace llvm {
23
Matt Arsenaulte7e23e32019-07-05 20:26:13 +000024struct AMDGPUPerfHintAnalysis : public CallGraphSCCPass {
Stanislav Mekhanoshin1c538422018-05-25 17:25:12 +000025 static char ID;
26
27public:
Matt Arsenaulte7e23e32019-07-05 20:26:13 +000028 AMDGPUPerfHintAnalysis() : CallGraphSCCPass(ID) {}
Stanislav Mekhanoshin1c538422018-05-25 17:25:12 +000029
Matt Arsenaulte7e23e32019-07-05 20:26:13 +000030 bool runOnSCC(CallGraphSCC &SCC) override;
Stanislav Mekhanoshin1c538422018-05-25 17:25:12 +000031
Reid Klecknercb48efd2018-05-25 17:46:24 +000032 void getAnalysisUsage(AnalysisUsage &AU) const override {
Stanislav Mekhanoshin1c538422018-05-25 17:25:12 +000033 AU.setPreservesAll();
34 }
35
36 bool isMemoryBound(const Function *F) const;
37
38 bool needsWaveLimiter(const Function *F) const;
39
40 struct FuncInfo {
41 unsigned MemInstCount;
42 unsigned InstCount;
43 unsigned IAMInstCount; // Indirect access memory instruction count
44 unsigned LSMInstCount; // Large stride memory instruction count
45 FuncInfo() : MemInstCount(0), InstCount(0), IAMInstCount(0),
46 LSMInstCount(0) {}
47 };
48
49 typedef ValueMap<const Function*, FuncInfo> FuncInfoMap;
50
51private:
52
53 FuncInfoMap FIM;
54};
55} // namespace llvm
56#endif // LLVM_LIB_TARGET_AMDGPU_MDGPUPERFHINTANALYSIS_H