xref: /freebsd-src/contrib/llvm-project/llvm/tools/llvm-mca/Views/SummaryView.h (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
1fe6060f1SDimitry Andric //===--------------------- SummaryView.h ------------------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric /// \file
90b57cec5SDimitry Andric ///
100b57cec5SDimitry Andric /// This file implements the summary view.
110b57cec5SDimitry Andric ///
120b57cec5SDimitry Andric /// The goal of the summary view is to give a very quick overview of the
130b57cec5SDimitry Andric /// performance throughput. Below is an example of summary view:
140b57cec5SDimitry Andric ///
150b57cec5SDimitry Andric ///
160b57cec5SDimitry Andric /// Iterations:        300
170b57cec5SDimitry Andric /// Instructions:      900
180b57cec5SDimitry Andric /// Total Cycles:      610
190b57cec5SDimitry Andric /// Dispatch Width:    2
200b57cec5SDimitry Andric /// IPC:               1.48
210b57cec5SDimitry Andric /// Block RThroughput: 2.0
220b57cec5SDimitry Andric ///
230b57cec5SDimitry Andric /// The summary view collects a few performance numbers. The two main
240b57cec5SDimitry Andric /// performance indicators are 'Total Cycles' and IPC (Instructions Per Cycle).
250b57cec5SDimitry Andric ///
260b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
270b57cec5SDimitry Andric 
280b57cec5SDimitry Andric #ifndef LLVM_TOOLS_LLVM_MCA_SUMMARYVIEW_H
290b57cec5SDimitry Andric #define LLVM_TOOLS_LLVM_MCA_SUMMARYVIEW_H
300b57cec5SDimitry Andric 
310b57cec5SDimitry Andric #include "llvm/MC/MCSchedule.h"
32*349cc55cSDimitry Andric #include "llvm/MCA/View.h"
330b57cec5SDimitry Andric #include "llvm/Support/raw_ostream.h"
340b57cec5SDimitry Andric 
350b57cec5SDimitry Andric namespace llvm {
360b57cec5SDimitry Andric namespace mca {
370b57cec5SDimitry Andric 
380b57cec5SDimitry Andric /// A view that collects and prints a few performance numbers.
390b57cec5SDimitry Andric class SummaryView : public View {
400b57cec5SDimitry Andric   const llvm::MCSchedModel &SM;
410b57cec5SDimitry Andric   llvm::ArrayRef<llvm::MCInst> Source;
420b57cec5SDimitry Andric   const unsigned DispatchWidth;
430b57cec5SDimitry Andric   unsigned LastInstructionIdx;
440b57cec5SDimitry Andric   unsigned TotalCycles;
450b57cec5SDimitry Andric   // The total number of micro opcodes contributed by a block of instructions.
460b57cec5SDimitry Andric   unsigned NumMicroOps;
470b57cec5SDimitry Andric 
48e8d8bef9SDimitry Andric   struct DisplayValues {
49e8d8bef9SDimitry Andric     unsigned Instructions;
50e8d8bef9SDimitry Andric     unsigned Iterations;
51e8d8bef9SDimitry Andric     unsigned TotalInstructions;
52e8d8bef9SDimitry Andric     unsigned TotalCycles;
53e8d8bef9SDimitry Andric     unsigned DispatchWidth;
54e8d8bef9SDimitry Andric     unsigned TotalUOps;
55e8d8bef9SDimitry Andric     double IPC;
56e8d8bef9SDimitry Andric     double UOpsPerCycle;
57e8d8bef9SDimitry Andric     double BlockRThroughput;
58e8d8bef9SDimitry Andric   };
59e8d8bef9SDimitry Andric 
600b57cec5SDimitry Andric   // For each processor resource, this vector stores the cumulative number of
610b57cec5SDimitry Andric   // resource cycles consumed by the analyzed code block.
620b57cec5SDimitry Andric   llvm::SmallVector<unsigned, 8> ProcResourceUsage;
630b57cec5SDimitry Andric 
640b57cec5SDimitry Andric   // Each processor resource is associated with a so-called processor resource
650b57cec5SDimitry Andric   // mask. This vector allows to correlate processor resource IDs with processor
660b57cec5SDimitry Andric   // resource masks. There is exactly one element per each processor resource
670b57cec5SDimitry Andric   // declared by the scheduling model.
680b57cec5SDimitry Andric   llvm::SmallVector<uint64_t, 8> ProcResourceMasks;
690b57cec5SDimitry Andric 
700b57cec5SDimitry Andric   // Used to map resource indices to actual processor resource IDs.
710b57cec5SDimitry Andric   llvm::SmallVector<unsigned, 8> ResIdx2ProcResID;
720b57cec5SDimitry Andric 
73e8d8bef9SDimitry Andric   /// Compute the data we want to print out in the object DV.
74e8d8bef9SDimitry Andric   void collectData(DisplayValues &DV) const;
75e8d8bef9SDimitry Andric 
760b57cec5SDimitry Andric public:
770b57cec5SDimitry Andric   SummaryView(const llvm::MCSchedModel &Model, llvm::ArrayRef<llvm::MCInst> S,
780b57cec5SDimitry Andric               unsigned Width);
790b57cec5SDimitry Andric 
onCycleEnd()800b57cec5SDimitry Andric   void onCycleEnd() override { ++TotalCycles; }
810b57cec5SDimitry Andric   void onEvent(const HWInstructionEvent &Event) override;
820b57cec5SDimitry Andric   void printView(llvm::raw_ostream &OS) const override;
getNameAsString()83e8d8bef9SDimitry Andric   StringRef getNameAsString() const override { return "SummaryView"; }
84e8d8bef9SDimitry Andric   json::Value toJSON() const override;
850b57cec5SDimitry Andric };
860b57cec5SDimitry Andric } // namespace mca
870b57cec5SDimitry Andric } // namespace llvm
880b57cec5SDimitry Andric 
890b57cec5SDimitry Andric #endif
90