SummaryView.h 3.2 KB

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