xref: /freebsd/contrib/llvm-project/llvm/tools/llvm-mca/Views/SummaryView.h (revision 77013d11e6483b970af25e13c9b892075742f7e5)
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 //===----------------------------------------------------------------------===//
27 
28 #ifndef LLVM_TOOLS_LLVM_MCA_SUMMARYVIEW_H
29 #define LLVM_TOOLS_LLVM_MCA_SUMMARYVIEW_H
30 
31 #include "Views/View.h"
32 #include "llvm/ADT/DenseMap.h"
33 #include "llvm/MC/MCSchedule.h"
34 #include "llvm/Support/raw_ostream.h"
35 
36 namespace llvm {
37 namespace mca {
38 
39 /// A view that collects and prints a few performance numbers.
40 class SummaryView : public View {
41   const llvm::MCSchedModel &SM;
42   llvm::ArrayRef<llvm::MCInst> Source;
43   const unsigned DispatchWidth;
44   unsigned LastInstructionIdx;
45   unsigned TotalCycles;
46   // The total number of micro opcodes contributed by a block of instructions.
47   unsigned NumMicroOps;
48 
49   struct DisplayValues {
50     unsigned Instructions;
51     unsigned Iterations;
52     unsigned TotalInstructions;
53     unsigned TotalCycles;
54     unsigned DispatchWidth;
55     unsigned TotalUOps;
56     double IPC;
57     double UOpsPerCycle;
58     double BlockRThroughput;
59   };
60 
61   // For each processor resource, this vector stores the cumulative number of
62   // resource cycles consumed by the analyzed code block.
63   llvm::SmallVector<unsigned, 8> ProcResourceUsage;
64 
65   // Each processor resource is associated with a so-called processor resource
66   // mask. This vector allows to correlate processor resource IDs with processor
67   // resource masks. There is exactly one element per each processor resource
68   // declared by the scheduling model.
69   llvm::SmallVector<uint64_t, 8> ProcResourceMasks;
70 
71   // Used to map resource indices to actual processor resource IDs.
72   llvm::SmallVector<unsigned, 8> ResIdx2ProcResID;
73 
74   // Compute the reciprocal throughput for the analyzed code block.
75   // The reciprocal block throughput is computed as the MAX between:
76   //   - NumMicroOps / DispatchWidth
77   //   - Total Resource Cycles / #Units   (for every resource consumed).
78   double getBlockRThroughput() const;
79 
80   /// Compute the data we want to print out in the object DV.
81   void collectData(DisplayValues &DV) const;
82 
83 public:
84   SummaryView(const llvm::MCSchedModel &Model, llvm::ArrayRef<llvm::MCInst> S,
85               unsigned Width);
86 
87   void onCycleEnd() override { ++TotalCycles; }
88   void onEvent(const HWInstructionEvent &Event) override;
89   void printView(llvm::raw_ostream &OS) const override;
90   StringRef getNameAsString() const override { return "SummaryView"; }
91   json::Value toJSON() const override;
92 };
93 } // namespace mca
94 } // namespace llvm
95 
96 #endif
97