[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / llvm / tools / llvm-mca / Views / SummaryView.h
blobc99905dd3e8b5244270640d101ea16688e1aac0f
1 //===--------------------- SummaryView.h ------------------------*- 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 /// \file
9 ///
10 /// This file implements the summary view.
11 ///
12 /// The goal of the summary view is to give a very quick overview of the
13 /// performance throughput. Below is an example of summary view:
14 ///
15 ///
16 /// Iterations: 300
17 /// Instructions: 900
18 /// Total Cycles: 610
19 /// Dispatch Width: 2
20 /// IPC: 1.48
21 /// Block RThroughput: 2.0
22 ///
23 /// The summary view collects a few performance numbers. The two main
24 /// performance indicators are 'Total Cycles' and IPC (Instructions Per Cycle).
25 ///
26 //===----------------------------------------------------------------------===//
28 #ifndef LLVM_TOOLS_LLVM_MCA_SUMMARYVIEW_H
29 #define LLVM_TOOLS_LLVM_MCA_SUMMARYVIEW_H
31 #include "llvm/MC/MCSchedule.h"
32 #include "llvm/MCA/View.h"
33 #include "llvm/Support/raw_ostream.h"
35 namespace llvm {
36 namespace mca {
38 /// A view that collects and prints a few performance numbers.
39 class SummaryView : public View {
40 const llvm::MCSchedModel &SM;
41 llvm::ArrayRef<llvm::MCInst> Source;
42 const unsigned DispatchWidth;
43 unsigned LastInstructionIdx;
44 unsigned TotalCycles;
45 // The total number of micro opcodes contributed by a block of instructions.
46 unsigned NumMicroOps;
48 struct DisplayValues {
49 unsigned Instructions;
50 unsigned Iterations;
51 unsigned TotalInstructions;
52 unsigned TotalCycles;
53 unsigned DispatchWidth;
54 unsigned TotalUOps;
55 double IPC;
56 double UOpsPerCycle;
57 double BlockRThroughput;
60 // For each processor resource, this vector stores the cumulative number of
61 // resource cycles consumed by the analyzed code block.
62 llvm::SmallVector<unsigned, 8> ProcResourceUsage;
64 // Each processor resource is associated with a so-called processor resource
65 // mask. This vector allows to correlate processor resource IDs with processor
66 // resource masks. There is exactly one element per each processor resource
67 // declared by the scheduling model.
68 llvm::SmallVector<uint64_t, 8> ProcResourceMasks;
70 // Used to map resource indices to actual processor resource IDs.
71 llvm::SmallVector<unsigned, 8> ResIdx2ProcResID;
73 /// Compute the data we want to print out in the object DV.
74 void collectData(DisplayValues &DV) const;
76 public:
77 SummaryView(const llvm::MCSchedModel &Model, llvm::ArrayRef<llvm::MCInst> S,
78 unsigned Width);
80 void onCycleEnd() override { ++TotalCycles; }
81 void onEvent(const HWInstructionEvent &Event) override;
82 void printView(llvm::raw_ostream &OS) const override;
83 StringRef getNameAsString() const override { return "SummaryView"; }
84 json::Value toJSON() const override;
86 } // namespace mca
87 } // namespace llvm
89 #endif