Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 1 | //===--------------------- BackendStatistics.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 |
Andrea Di Biagio | 53e6ade | 2018-03-09 12:50:42 +0000 | [diff] [blame] | 10 | /// |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 11 | /// Functionalities used by the BackendPrinter to print out histograms |
| 12 | /// related to number of {dispatch/issue/retire} per number of cycles. |
| 13 | /// |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #include "BackendStatistics.h" |
| 17 | #include "llvm/Support/Format.h" |
| 18 | |
| 19 | using namespace llvm; |
| 20 | |
| 21 | namespace mca { |
| 22 | |
Clement Courbet | 844f22d | 2018-03-13 13:11:01 +0000 | [diff] [blame^] | 23 | void BackendStatistics::onInstructionEvent(const HWInstructionEvent &Event) { |
| 24 | switch (Event.Type) { |
| 25 | case HWInstructionEvent::Retired: |
| 26 | ++NumRetired; |
| 27 | break; |
| 28 | case HWInstructionEvent::Issued: |
| 29 | ++NumIssued; |
| 30 | break; |
| 31 | case HWInstructionEvent::Dispatched: |
| 32 | ++NumDispatched; |
| 33 | break; |
| 34 | default: |
| 35 | break; |
| 36 | } |
| 37 | } |
| 38 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 39 | void BackendStatistics::printRetireUnitStatistics(llvm::raw_ostream &OS) const { |
| 40 | std::string Buffer; |
| 41 | raw_string_ostream TempStream(Buffer); |
| 42 | TempStream << "\n\nRetire Control Unit - " |
| 43 | << "number of cycles where we saw N instructions retired:\n"; |
| 44 | TempStream << "[# retired], [# cycles]\n"; |
| 45 | |
| 46 | for (const std::pair<unsigned, unsigned> &Entry : RetiredPerCycle) { |
| 47 | TempStream << " " << Entry.first; |
| 48 | if (Entry.first < 10) |
| 49 | TempStream << ", "; |
| 50 | else |
| 51 | TempStream << ", "; |
| 52 | TempStream << Entry.second << " (" |
| 53 | << format("%.1f", ((double)Entry.second / NumCycles) * 100.0) |
| 54 | << "%)\n"; |
| 55 | } |
| 56 | |
| 57 | TempStream.flush(); |
| 58 | OS << Buffer; |
| 59 | } |
| 60 | |
Andrea Di Biagio | 53e6ade | 2018-03-09 12:50:42 +0000 | [diff] [blame] | 61 | void BackendStatistics::printDispatchUnitStatistics( |
| 62 | llvm::raw_ostream &OS) const { |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 63 | std::string Buffer; |
| 64 | raw_string_ostream TempStream(Buffer); |
| 65 | TempStream << "\n\nDispatch Logic - " |
| 66 | << "number of cycles where we saw N instructions dispatched:\n"; |
| 67 | TempStream << "[# dispatched], [# cycles]\n"; |
| 68 | for (const std::pair<unsigned, unsigned> &Entry : DispatchGroupSizePerCycle) { |
| 69 | TempStream << " " << Entry.first << ", " << Entry.second |
| 70 | << " (" |
| 71 | << format("%.1f", ((double)Entry.second / NumCycles) * 100.0) |
| 72 | << "%)\n"; |
| 73 | } |
| 74 | |
| 75 | TempStream.flush(); |
| 76 | OS << Buffer; |
| 77 | } |
| 78 | |
| 79 | void BackendStatistics::printSchedulerStatistics(llvm::raw_ostream &OS) const { |
| 80 | std::string Buffer; |
| 81 | raw_string_ostream TempStream(Buffer); |
| 82 | TempStream << "\n\nSchedulers - number of cycles where we saw N instructions " |
| 83 | "issued:\n"; |
| 84 | TempStream << "[# issued], [# cycles]\n"; |
| 85 | for (const std::pair<unsigned, unsigned> &Entry : IssuedPerCycle) { |
| 86 | TempStream << " " << Entry.first << ", " << Entry.second << " (" |
| 87 | << format("%.1f", ((double)Entry.second / NumCycles) * 100) |
| 88 | << "%)\n"; |
| 89 | } |
| 90 | |
| 91 | TempStream.flush(); |
| 92 | OS << Buffer; |
| 93 | } |
| 94 | |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 95 | void BackendStatistics::printRATStatistics(raw_ostream &OS, |
Andrea Di Biagio | 53e6ade | 2018-03-09 12:50:42 +0000 | [diff] [blame] | 96 | unsigned TotalMappings, |
| 97 | unsigned MaxUsedMappings) const { |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 98 | std::string Buffer; |
| 99 | raw_string_ostream TempStream(Buffer); |
| 100 | TempStream << "\n\nRegister Alias Table:"; |
| 101 | TempStream << "\nTotal number of mappings created: " << TotalMappings; |
| 102 | TempStream << "\nMax number of mappings used: " << MaxUsedMappings |
| 103 | << '\n'; |
| 104 | TempStream.flush(); |
| 105 | OS << Buffer; |
| 106 | } |
| 107 | |
Andrea Di Biagio | 53e6ade | 2018-03-09 12:50:42 +0000 | [diff] [blame] | 108 | void BackendStatistics::printDispatchStalls(raw_ostream &OS, unsigned RATStalls, |
| 109 | unsigned RCUStalls, |
| 110 | unsigned SCHEDQStalls, |
| 111 | unsigned LDQStalls, |
| 112 | unsigned STQStalls, |
| 113 | unsigned DGStalls) const { |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 114 | std::string Buffer; |
| 115 | raw_string_ostream TempStream(Buffer); |
| 116 | TempStream << "\n\nDynamic Dispatch Stall Cycles:\n"; |
| 117 | TempStream << "RAT - Register unavailable: " |
| 118 | << RATStalls; |
| 119 | TempStream << "\nRCU - Retire tokens unavailable: " |
| 120 | << RCUStalls; |
| 121 | TempStream << "\nSCHEDQ - Scheduler full: " |
| 122 | << SCHEDQStalls; |
| 123 | TempStream << "\nLQ - Load queue full: " |
| 124 | << LDQStalls; |
| 125 | TempStream << "\nSQ - Store queue full: " |
| 126 | << STQStalls; |
| 127 | TempStream << "\nGROUP - Static restrictions on the dispatch group: " |
| 128 | << DGStalls; |
| 129 | TempStream << '\n'; |
| 130 | TempStream.flush(); |
| 131 | OS << Buffer; |
| 132 | } |
| 133 | |
Andrea Di Biagio | 53e6ade | 2018-03-09 12:50:42 +0000 | [diff] [blame] | 134 | void BackendStatistics::printSchedulerUsage( |
| 135 | raw_ostream &OS, const MCSchedModel &SM, |
| 136 | const ArrayRef<BufferUsageEntry> &Usage) const { |
Andrea Di Biagio | 7948738 | 2018-03-10 17:40:25 +0000 | [diff] [blame] | 137 | |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 138 | std::string Buffer; |
| 139 | raw_string_ostream TempStream(Buffer); |
| 140 | TempStream << "\n\nScheduler's queue usage:\n"; |
Andrea Di Biagio | 7948738 | 2018-03-10 17:40:25 +0000 | [diff] [blame] | 141 | // Early exit if no buffered resources were consumed. |
| 142 | if (Usage.empty()) { |
| 143 | TempStream << "No scheduler resources used.\n"; |
| 144 | TempStream.flush(); |
| 145 | OS << Buffer; |
| 146 | return; |
| 147 | } |
| 148 | |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 149 | for (unsigned I = 0, E = SM.getNumProcResourceKinds(); I < E; ++I) { |
| 150 | const MCProcResourceDesc &ProcResource = *SM.getProcResource(I); |
| 151 | if (!ProcResource.BufferSize) |
| 152 | continue; |
| 153 | |
| 154 | for (const BufferUsageEntry &Entry : Usage) |
Andrea Di Biagio | 0c54129 | 2018-03-10 16:55:07 +0000 | [diff] [blame] | 155 | if (I == Entry.first) |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 156 | TempStream << ProcResource.Name << ", " << Entry.second << '/' |
| 157 | << ProcResource.BufferSize << '\n'; |
| 158 | } |
| 159 | |
| 160 | TempStream.flush(); |
| 161 | OS << Buffer; |
| 162 | } |
| 163 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 164 | } // namespace mca |