SummaryView.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //===--------------------- SummaryView.cpp -------------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. /// \file
  10. ///
  11. /// This file implements the functionalities used by the SummaryView to print
  12. /// the report information.
  13. ///
  14. //===----------------------------------------------------------------------===//
  15. #include "Views/SummaryView.h"
  16. #include "Support.h"
  17. #include "llvm/ADT/SmallVector.h"
  18. #include "llvm/Support/Format.h"
  19. namespace mca {
  20. #define DEBUG_TYPE "llvm-mca"
  21. using namespace llvm;
  22. SummaryView::SummaryView(const llvm::MCSchedModel &Model, const SourceMgr &S,
  23. unsigned Width)
  24. : SM(Model), Source(S), DispatchWidth(Width), TotalCycles(0),
  25. NumMicroOps(0), ProcResourceUsage(Model.getNumProcResourceKinds(), 0),
  26. ProcResourceMasks(Model.getNumProcResourceKinds(), 0) {
  27. computeProcResourceMasks(SM, ProcResourceMasks);
  28. }
  29. void SummaryView::onEvent(const HWInstructionEvent &Event) {
  30. // We are only interested in the "instruction retired" events generated by
  31. // the retire stage for instructions that are part of iteration #0.
  32. if (Event.Type != HWInstructionEvent::Retired ||
  33. Event.IR.getSourceIndex() >= Source.size())
  34. return;
  35. // Update the cumulative number of resource cycles based on the processor
  36. // resource usage information available from the instruction descriptor. We
  37. // need to compute the cumulative number of resource cycles for every
  38. // processor resource which is consumed by an instruction of the block.
  39. const Instruction &Inst = *Event.IR.getInstruction();
  40. const InstrDesc &Desc = Inst.getDesc();
  41. NumMicroOps += Desc.NumMicroOps;
  42. for (const std::pair<uint64_t, const ResourceUsage> &RU : Desc.Resources) {
  43. if (RU.second.size()) {
  44. const auto It = find(ProcResourceMasks, RU.first);
  45. assert(It != ProcResourceMasks.end() &&
  46. "Invalid processor resource mask!");
  47. ProcResourceUsage[std::distance(ProcResourceMasks.begin(), It)] +=
  48. RU.second.size();
  49. }
  50. }
  51. }
  52. void SummaryView::printView(raw_ostream &OS) const {
  53. unsigned Iterations = Source.getNumIterations();
  54. unsigned Instructions = Source.size();
  55. unsigned TotalInstructions = Instructions * Iterations;
  56. unsigned TotalUOps = NumMicroOps * Iterations;
  57. double IPC = (double)TotalInstructions / TotalCycles;
  58. double UOpsPerCycle = (double)TotalUOps / TotalCycles;
  59. double BlockRThroughput = computeBlockRThroughput(
  60. SM, DispatchWidth, NumMicroOps, ProcResourceUsage);
  61. std::string Buffer;
  62. raw_string_ostream TempStream(Buffer);
  63. TempStream << "Iterations: " << Iterations;
  64. TempStream << "\nInstructions: " << TotalInstructions;
  65. TempStream << "\nTotal Cycles: " << TotalCycles;
  66. TempStream << "\nTotal uOps: " << TotalUOps << '\n';
  67. TempStream << "\nDispatch Width: " << DispatchWidth;
  68. TempStream << "\nuOps Per Cycle: "
  69. << format("%.2f", floor((UOpsPerCycle * 100) + 0.5) / 100);
  70. TempStream << "\nIPC: "
  71. << format("%.2f", floor((IPC * 100) + 0.5) / 100);
  72. TempStream << "\nBlock RThroughput: "
  73. << format("%.1f", floor((BlockRThroughput * 10) + 0.5) / 10)
  74. << '\n';
  75. TempStream.flush();
  76. OS << Buffer;
  77. }
  78. } // namespace mca.