1343171Sdim//===--------------------- SummaryView.h ---------------------*- C++ -*-===//
2343171Sdim//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6343171Sdim//
7343171Sdim//===----------------------------------------------------------------------===//
8343171Sdim/// \file
9343171Sdim///
10343171Sdim/// This file implements the summary view.
11343171Sdim///
12343171Sdim/// The goal of the summary view is to give a very quick overview of the
13343171Sdim/// performance throughput. Below is an example of summary view:
14343171Sdim///
15343171Sdim///
16343171Sdim/// Iterations:        300
17343171Sdim/// Instructions:      900
18343171Sdim/// Total Cycles:      610
19343171Sdim/// Dispatch Width:    2
20343171Sdim/// IPC:               1.48
21343171Sdim/// Block RThroughput: 2.0
22343171Sdim///
23343171Sdim/// The summary view collects a few performance numbers. The two main
24343171Sdim/// performance indicators are 'Total Cycles' and IPC (Instructions Per Cycle).
25343171Sdim///
26343171Sdim//===----------------------------------------------------------------------===//
27343171Sdim
28343171Sdim#ifndef LLVM_TOOLS_LLVM_MCA_SUMMARYVIEW_H
29343171Sdim#define LLVM_TOOLS_LLVM_MCA_SUMMARYVIEW_H
30343171Sdim
31343171Sdim#include "Views/View.h"
32343171Sdim#include "llvm/ADT/DenseMap.h"
33343171Sdim#include "llvm/MC/MCSchedule.h"
34343171Sdim#include "llvm/Support/raw_ostream.h"
35343171Sdim
36343171Sdimnamespace llvm {
37343171Sdimnamespace mca {
38343171Sdim
39343171Sdim/// A view that collects and prints a few performance numbers.
40343171Sdimclass SummaryView : public View {
41343171Sdim  const llvm::MCSchedModel &SM;
42343171Sdim  llvm::ArrayRef<llvm::MCInst> Source;
43343171Sdim  const unsigned DispatchWidth;
44343171Sdim  unsigned LastInstructionIdx;
45343171Sdim  unsigned TotalCycles;
46343171Sdim  // The total number of micro opcodes contributed by a block of instructions.
47343171Sdim  unsigned NumMicroOps;
48353358Sdim
49343171Sdim  // For each processor resource, this vector stores the cumulative number of
50343171Sdim  // resource cycles consumed by the analyzed code block.
51343171Sdim  llvm::SmallVector<unsigned, 8> ProcResourceUsage;
52343171Sdim
53343171Sdim  // Each processor resource is associated with a so-called processor resource
54343171Sdim  // mask. This vector allows to correlate processor resource IDs with processor
55343171Sdim  // resource masks. There is exactly one element per each processor resource
56343171Sdim  // declared by the scheduling model.
57343171Sdim  llvm::SmallVector<uint64_t, 8> ProcResourceMasks;
58343171Sdim
59353358Sdim  // Used to map resource indices to actual processor resource IDs.
60353358Sdim  llvm::SmallVector<unsigned, 8> ResIdx2ProcResID;
61353358Sdim
62343171Sdim  // Compute the reciprocal throughput for the analyzed code block.
63343171Sdim  // The reciprocal block throughput is computed as the MAX between:
64343171Sdim  //   - NumMicroOps / DispatchWidth
65343171Sdim  //   - Total Resource Cycles / #Units   (for every resource consumed).
66343171Sdim  double getBlockRThroughput() const;
67343171Sdim
68343171Sdimpublic:
69343171Sdim  SummaryView(const llvm::MCSchedModel &Model, llvm::ArrayRef<llvm::MCInst> S,
70343171Sdim              unsigned Width);
71343171Sdim
72343171Sdim  void onCycleEnd() override { ++TotalCycles; }
73343171Sdim  void onEvent(const HWInstructionEvent &Event) override;
74343171Sdim  void printView(llvm::raw_ostream &OS) const override;
75343171Sdim};
76353358Sdim
77343171Sdim} // namespace mca
78343171Sdim} // namespace llvm
79343171Sdim
80343171Sdim#endif
81