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