xref: /openbsd-src/gnu/llvm/llvm/tools/llvm-mca/Views/SummaryView.h (revision d415bd752c734aee168c4ee86ff32e8cc249eb16)
173471bf0Spatrick //===--------------------- SummaryView.h ------------------------*- C++ -*-===//
209467b48Spatrick //
309467b48Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
409467b48Spatrick // See https://llvm.org/LICENSE.txt for license information.
509467b48Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
609467b48Spatrick //
709467b48Spatrick //===----------------------------------------------------------------------===//
809467b48Spatrick /// \file
909467b48Spatrick ///
1009467b48Spatrick /// This file implements the summary view.
1109467b48Spatrick ///
1209467b48Spatrick /// The goal of the summary view is to give a very quick overview of the
1309467b48Spatrick /// performance throughput. Below is an example of summary view:
1409467b48Spatrick ///
1509467b48Spatrick ///
1609467b48Spatrick /// Iterations:        300
1709467b48Spatrick /// Instructions:      900
1809467b48Spatrick /// Total Cycles:      610
1909467b48Spatrick /// Dispatch Width:    2
2009467b48Spatrick /// IPC:               1.48
2109467b48Spatrick /// Block RThroughput: 2.0
2209467b48Spatrick ///
2309467b48Spatrick /// The summary view collects a few performance numbers. The two main
2409467b48Spatrick /// performance indicators are 'Total Cycles' and IPC (Instructions Per Cycle).
2509467b48Spatrick ///
2609467b48Spatrick //===----------------------------------------------------------------------===//
2709467b48Spatrick 
2809467b48Spatrick #ifndef LLVM_TOOLS_LLVM_MCA_SUMMARYVIEW_H
2909467b48Spatrick #define LLVM_TOOLS_LLVM_MCA_SUMMARYVIEW_H
3009467b48Spatrick 
3109467b48Spatrick #include "llvm/ADT/DenseMap.h"
3209467b48Spatrick #include "llvm/MC/MCSchedule.h"
33*d415bd75Srobert #include "llvm/MCA/View.h"
3409467b48Spatrick #include "llvm/Support/raw_ostream.h"
3509467b48Spatrick 
3609467b48Spatrick namespace llvm {
3709467b48Spatrick namespace mca {
3809467b48Spatrick 
3909467b48Spatrick /// A view that collects and prints a few performance numbers.
4009467b48Spatrick class SummaryView : public View {
4109467b48Spatrick   const llvm::MCSchedModel &SM;
4209467b48Spatrick   llvm::ArrayRef<llvm::MCInst> Source;
4309467b48Spatrick   const unsigned DispatchWidth;
4409467b48Spatrick   unsigned LastInstructionIdx;
4509467b48Spatrick   unsigned TotalCycles;
4609467b48Spatrick   // The total number of micro opcodes contributed by a block of instructions.
4709467b48Spatrick   unsigned NumMicroOps;
4809467b48Spatrick 
4973471bf0Spatrick   struct DisplayValues {
5073471bf0Spatrick     unsigned Instructions;
5173471bf0Spatrick     unsigned Iterations;
5273471bf0Spatrick     unsigned TotalInstructions;
5373471bf0Spatrick     unsigned TotalCycles;
5473471bf0Spatrick     unsigned DispatchWidth;
5573471bf0Spatrick     unsigned TotalUOps;
5673471bf0Spatrick     double IPC;
5773471bf0Spatrick     double UOpsPerCycle;
5873471bf0Spatrick     double BlockRThroughput;
5973471bf0Spatrick   };
6073471bf0Spatrick 
6109467b48Spatrick   // For each processor resource, this vector stores the cumulative number of
6209467b48Spatrick   // resource cycles consumed by the analyzed code block.
6309467b48Spatrick   llvm::SmallVector<unsigned, 8> ProcResourceUsage;
6409467b48Spatrick 
6509467b48Spatrick   // Each processor resource is associated with a so-called processor resource
6609467b48Spatrick   // mask. This vector allows to correlate processor resource IDs with processor
6709467b48Spatrick   // resource masks. There is exactly one element per each processor resource
6809467b48Spatrick   // declared by the scheduling model.
6909467b48Spatrick   llvm::SmallVector<uint64_t, 8> ProcResourceMasks;
7009467b48Spatrick 
7109467b48Spatrick   // Used to map resource indices to actual processor resource IDs.
7209467b48Spatrick   llvm::SmallVector<unsigned, 8> ResIdx2ProcResID;
7309467b48Spatrick 
7473471bf0Spatrick   /// Compute the data we want to print out in the object DV.
7573471bf0Spatrick   void collectData(DisplayValues &DV) const;
7673471bf0Spatrick 
7709467b48Spatrick public:
7809467b48Spatrick   SummaryView(const llvm::MCSchedModel &Model, llvm::ArrayRef<llvm::MCInst> S,
7909467b48Spatrick               unsigned Width);
8009467b48Spatrick 
onCycleEnd()8109467b48Spatrick   void onCycleEnd() override { ++TotalCycles; }
8209467b48Spatrick   void onEvent(const HWInstructionEvent &Event) override;
8309467b48Spatrick   void printView(llvm::raw_ostream &OS) const override;
getNameAsString()8473471bf0Spatrick   StringRef getNameAsString() const override { return "SummaryView"; }
8573471bf0Spatrick   json::Value toJSON() const override;
8609467b48Spatrick };
8709467b48Spatrick } // namespace mca
8809467b48Spatrick } // namespace llvm
8909467b48Spatrick 
9009467b48Spatrick #endif
91