brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · a3be0f5 Raw
77 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8//9/// \file10/// \brief Analyzes if a function potentially memory bound and if a kernel11/// kernel may benefit from limiting number of waves to reduce cache thrashing.12///13//===----------------------------------------------------------------------===//14 15#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUPERFHINTANALYSIS_H16#define LLVM_LIB_TARGET_AMDGPU_AMDGPUPERFHINTANALYSIS_H17 18#include "llvm/IR/PassManager.h"19#include "llvm/IR/ValueMap.h"20 21#include "llvm/Analysis/CGSCCPassManager.h"22#include "llvm/Analysis/LazyCallGraph.h"23 24namespace llvm {25 26class AMDGPUPerfHintAnalysis;27class CallGraphSCC;28class GCNTargetMachine;29class LazyCallGraph;30 31class AMDGPUPerfHintAnalysis {32public:33  struct FuncInfo {34    unsigned MemInstCost;35    unsigned InstCost;36    unsigned IAMInstCost;      // Indirect access memory instruction count37    unsigned LSMInstCost;      // Large stride memory instruction count38    bool HasDenseGlobalMemAcc; // Set if at least 1 basic block has relatively39                               // high global memory access40    FuncInfo()41        : MemInstCost(0), InstCost(0), IAMInstCost(0), LSMInstCost(0),42          HasDenseGlobalMemAcc(false) {}43  };44 45  typedef ValueMap<const Function *, FuncInfo> FuncInfoMap;46 47private:48  FuncInfoMap FIM;49 50public:51  AMDGPUPerfHintAnalysis() = default;52 53  // OldPM54  bool runOnSCC(const GCNTargetMachine &TM, CallGraphSCC &SCC);55 56  // NewPM57  bool run(const GCNTargetMachine &TM, LazyCallGraph &CG);58 59  bool isMemoryBound(const Function *F) const;60 61  bool needsWaveLimiter(const Function *F) const;62};63 64struct AMDGPUPerfHintAnalysisPass65    : public PassInfoMixin<AMDGPUPerfHintAnalysisPass> {66  const GCNTargetMachine &TM;67  std::unique_ptr<AMDGPUPerfHintAnalysis> Impl;68 69  AMDGPUPerfHintAnalysisPass(const GCNTargetMachine &TM)70      : TM(TM), Impl(std::make_unique<AMDGPUPerfHintAnalysis>()) {}71 72  PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);73};74 75} // namespace llvm76#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUPERFHINTANALYSIS_H77