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 16 #include "Views/DispatchStatistics.h" 17 #include "llvm/Support/Format.h" 18 19 namespace llvm { 20 namespace mca { 21 22 void DispatchStatistics::onEvent(const HWStallEvent &Event) { 23 if (Event.Type < HWStallEvent::LastGenericEvent) 24 HWStalls[Event.Type]++; 25 } 26 27 void DispatchStatistics::onEvent(const HWInstructionEvent &Event) { 28 if (Event.Type != HWInstructionEvent::Dispatched) 29 return; 30 31 const auto &DE = static_cast<const HWInstructionDispatchedEvent &>(Event); 32 NumDispatched += DE.MicroOpcodes; 33 } 34 35 void DispatchStatistics::printDispatchHistogram(raw_ostream &OS) const { 36 std::string Buffer; 37 raw_string_ostream TempStream(Buffer); 38 TempStream << "\n\nDispatch Logic - " 39 << "number of cycles where we saw N micro opcodes dispatched:\n"; 40 TempStream << "[# dispatched], [# cycles]\n"; 41 for (const std::pair<unsigned, unsigned> &Entry : DispatchGroupSizePerCycle) { 42 double Percentage = ((double)Entry.second / NumCycles) * 100.0; 43 TempStream << " " << Entry.first << ", " << Entry.second 44 << " (" << format("%.1f", floor((Percentage * 10) + 0.5) / 10) 45 << "%)\n"; 46 } 47 48 TempStream.flush(); 49 OS << Buffer; 50 } 51 52 static void printStalls(raw_ostream &OS, unsigned NumStalls, 53 unsigned NumCycles) { 54 if (!NumStalls) { 55 OS << NumStalls; 56 return; 57 } 58 59 double Percentage = ((double)NumStalls / NumCycles) * 100.0; 60 OS << NumStalls << " (" 61 << format("%.1f", floor((Percentage * 10) + 0.5) / 10) << "%)"; 62 } 63 64 void DispatchStatistics::printDispatchStalls(raw_ostream &OS) const { 65 std::string Buffer; 66 raw_string_ostream SS(Buffer); 67 SS << "\n\nDynamic Dispatch Stall Cycles:\n"; 68 SS << "RAT - Register unavailable: "; 69 printStalls(SS, HWStalls[HWStallEvent::RegisterFileStall], NumCycles); 70 SS << "\nRCU - Retire tokens unavailable: "; 71 printStalls(SS, HWStalls[HWStallEvent::RetireControlUnitStall], NumCycles); 72 SS << "\nSCHEDQ - Scheduler full: "; 73 printStalls(SS, HWStalls[HWStallEvent::SchedulerQueueFull], NumCycles); 74 SS << "\nLQ - Load queue full: "; 75 printStalls(SS, HWStalls[HWStallEvent::LoadQueueFull], NumCycles); 76 SS << "\nSQ - Store queue full: "; 77 printStalls(SS, HWStalls[HWStallEvent::StoreQueueFull], NumCycles); 78 SS << "\nGROUP - Static restrictions on the dispatch group: "; 79 printStalls(SS, HWStalls[HWStallEvent::DispatchGroupStall], NumCycles); 80 SS << '\n'; 81 SS.flush(); 82 OS << Buffer; 83 } 84 85 } // namespace mca 86 } // namespace llvm 87