DispatchStatistics.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //===--------------------- DispatchStatistics.cpp ---------------------*- C++
  2. //-*-===//
  3. //
  4. // The LLVM Compiler Infrastructure
  5. //
  6. // This file is distributed under the University of Illinois Open Source
  7. // License. See LICENSE.TXT for details.
  8. //
  9. //===----------------------------------------------------------------------===//
  10. /// \file
  11. ///
  12. /// This file implements the DispatchStatistics interface.
  13. ///
  14. //===----------------------------------------------------------------------===//
  15. #include "Views/DispatchStatistics.h"
  16. #include "llvm/Support/Format.h"
  17. using namespace llvm;
  18. namespace mca {
  19. void DispatchStatistics::onEvent(const HWStallEvent &Event) {
  20. if (Event.Type < HWStallEvent::LastGenericEvent)
  21. HWStalls[Event.Type]++;
  22. }
  23. void DispatchStatistics::onEvent(const HWInstructionEvent &Event) {
  24. if (Event.Type != HWInstructionEvent::Dispatched)
  25. return;
  26. const auto &DE = static_cast<const HWInstructionDispatchedEvent &>(Event);
  27. NumDispatched += DE.MicroOpcodes;
  28. }
  29. void DispatchStatistics::printDispatchHistogram(llvm::raw_ostream &OS) const {
  30. std::string Buffer;
  31. raw_string_ostream TempStream(Buffer);
  32. TempStream << "\n\nDispatch Logic - "
  33. << "number of cycles where we saw N micro opcodes dispatched:\n";
  34. TempStream << "[# dispatched], [# cycles]\n";
  35. for (const std::pair<unsigned, unsigned> &Entry : DispatchGroupSizePerCycle) {
  36. double Percentage = ((double)Entry.second / NumCycles) * 100.0;
  37. TempStream << " " << Entry.first << ", " << Entry.second
  38. << " (" << format("%.1f", floor((Percentage * 10) + 0.5) / 10)
  39. << "%)\n";
  40. }
  41. TempStream.flush();
  42. OS << Buffer;
  43. }
  44. static void printStalls(raw_ostream &OS, unsigned NumStalls,
  45. unsigned NumCycles) {
  46. if (!NumStalls) {
  47. OS << NumStalls;
  48. return;
  49. }
  50. double Percentage = ((double)NumStalls / NumCycles) * 100.0;
  51. OS << NumStalls << " ("
  52. << format("%.1f", floor((Percentage * 10) + 0.5) / 10) << "%)";
  53. }
  54. void DispatchStatistics::printDispatchStalls(raw_ostream &OS) const {
  55. std::string Buffer;
  56. raw_string_ostream SS(Buffer);
  57. SS << "\n\nDynamic Dispatch Stall Cycles:\n";
  58. SS << "RAT - Register unavailable: ";
  59. printStalls(SS, HWStalls[HWStallEvent::RegisterFileStall], NumCycles);
  60. SS << "\nRCU - Retire tokens unavailable: ";
  61. printStalls(SS, HWStalls[HWStallEvent::RetireControlUnitStall], NumCycles);
  62. SS << "\nSCHEDQ - Scheduler full: ";
  63. printStalls(SS, HWStalls[HWStallEvent::SchedulerQueueFull], NumCycles);
  64. SS << "\nLQ - Load queue full: ";
  65. printStalls(SS, HWStalls[HWStallEvent::LoadQueueFull], NumCycles);
  66. SS << "\nSQ - Store queue full: ";
  67. printStalls(SS, HWStalls[HWStallEvent::StoreQueueFull], NumCycles);
  68. SS << "\nGROUP - Static restrictions on the dispatch group: ";
  69. printStalls(SS, HWStalls[HWStallEvent::DispatchGroupStall], NumCycles);
  70. SS << '\n';
  71. SS.flush();
  72. OS << Buffer;
  73. }
  74. } // namespace mca