Andrea Di Biagio | 0cc66c7 | 2018-03-09 13:52:03 +0000 | [diff] [blame] | 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 | |
Matt Davis | 10aa09f | 2018-08-24 20:24:53 +0000 | [diff] [blame] | 16 | #include "Views/SummaryView.h" |
Andrea Di Biagio | 3fc20c9 | 2018-05-23 15:59:27 +0000 | [diff] [blame] | 17 | #include "Support.h" |
| 18 | #include "llvm/ADT/SmallVector.h" |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 19 | #include "llvm/Support/Format.h" |
Andrea Di Biagio | 0cc66c7 | 2018-03-09 13:52:03 +0000 | [diff] [blame] | 20 | |
| 21 | namespace mca { |
| 22 | |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 23 | #define DEBUG_TYPE "llvm-mca" |
| 24 | |
Andrea Di Biagio | 0cc66c7 | 2018-03-09 13:52:03 +0000 | [diff] [blame] | 25 | using namespace llvm; |
| 26 | |
Andrea Di Biagio | db158be | 2018-10-22 16:28:07 +0000 | [diff] [blame] | 27 | SummaryView::SummaryView(const MCSchedModel &Model, const SourceMgr &S, |
Andrea Di Biagio | bdc6706 | 2018-06-01 14:35:21 +0000 | [diff] [blame] | 28 | unsigned Width) |
| 29 | : SM(Model), Source(S), DispatchWidth(Width), TotalCycles(0), |
Andrea Di Biagio | 65c77d7 | 2018-10-24 16:56:43 +0000 | [diff] [blame^] | 30 | NumMicroOps(0), ProcResourceUsage(Model.getNumProcResourceKinds(), 0) { |
Andrea Di Biagio | bdc6706 | 2018-06-01 14:35:21 +0000 | [diff] [blame] | 31 | computeProcResourceMasks(SM, ProcResourceMasks); |
| 32 | } |
| 33 | |
Matt Davis | 0906a7f | 2018-07-12 16:56:17 +0000 | [diff] [blame] | 34 | void SummaryView::onEvent(const HWInstructionEvent &Event) { |
Andrea Di Biagio | 8b647dc | 2018-08-30 10:50:20 +0000 | [diff] [blame] | 35 | // We are only interested in the "instruction retired" events generated by |
| 36 | // the retire stage for instructions that are part of iteration #0. |
| 37 | if (Event.Type != HWInstructionEvent::Retired || |
| 38 | Event.IR.getSourceIndex() >= Source.size()) |
Andrea Di Biagio | 3fc20c9 | 2018-05-23 15:59:27 +0000 | [diff] [blame] | 39 | return; |
| 40 | |
| 41 | // Update the cumulative number of resource cycles based on the processor |
Andrea Di Biagio | 0af8115 | 2018-05-24 17:22:14 +0000 | [diff] [blame] | 42 | // resource usage information available from the instruction descriptor. We |
| 43 | // need to compute the cumulative number of resource cycles for every |
| 44 | // processor resource which is consumed by an instruction of the block. |
Andrea Di Biagio | 3fc20c9 | 2018-05-23 15:59:27 +0000 | [diff] [blame] | 45 | const Instruction &Inst = *Event.IR.getInstruction(); |
| 46 | const InstrDesc &Desc = Inst.getDesc(); |
| 47 | NumMicroOps += Desc.NumMicroOps; |
| 48 | for (const std::pair<uint64_t, const ResourceUsage> &RU : Desc.Resources) { |
Andrea Di Biagio | bdc6706 | 2018-06-01 14:35:21 +0000 | [diff] [blame] | 49 | if (RU.second.size()) { |
| 50 | const auto It = find(ProcResourceMasks, RU.first); |
| 51 | assert(It != ProcResourceMasks.end() && |
| 52 | "Invalid processor resource mask!"); |
| 53 | ProcResourceUsage[std::distance(ProcResourceMasks.begin(), It)] += |
| 54 | RU.second.size(); |
Andrea Di Biagio | 3fc20c9 | 2018-05-23 15:59:27 +0000 | [diff] [blame] | 55 | } |
| 56 | } |
Andrea Di Biagio | 3fc20c9 | 2018-05-23 15:59:27 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 59 | void SummaryView::printView(raw_ostream &OS) const { |
Andrea Di Biagio | b522975 | 2018-03-13 17:24:32 +0000 | [diff] [blame] | 60 | unsigned Iterations = Source.getNumIterations(); |
| 61 | unsigned Instructions = Source.size(); |
Andrea Di Biagio | 0cc66c7 | 2018-03-09 13:52:03 +0000 | [diff] [blame] | 62 | unsigned TotalInstructions = Instructions * Iterations; |
Andrea Di Biagio | a2eee47 | 2018-08-29 17:56:39 +0000 | [diff] [blame] | 63 | unsigned TotalUOps = NumMicroOps * Iterations; |
Andrea Di Biagio | 0cc66c7 | 2018-03-09 13:52:03 +0000 | [diff] [blame] | 64 | double IPC = (double)TotalInstructions / TotalCycles; |
Andrea Di Biagio | a2eee47 | 2018-08-29 17:56:39 +0000 | [diff] [blame] | 65 | double UOpsPerCycle = (double)TotalUOps / TotalCycles; |
Andrea Di Biagio | bdc6706 | 2018-06-01 14:35:21 +0000 | [diff] [blame] | 66 | double BlockRThroughput = computeBlockRThroughput( |
| 67 | SM, DispatchWidth, NumMicroOps, ProcResourceUsage); |
Andrea Di Biagio | 0cc66c7 | 2018-03-09 13:52:03 +0000 | [diff] [blame] | 68 | |
| 69 | std::string Buffer; |
| 70 | raw_string_ostream TempStream(Buffer); |
Andrea Di Biagio | 3fc20c9 | 2018-05-23 15:59:27 +0000 | [diff] [blame] | 71 | TempStream << "Iterations: " << Iterations; |
| 72 | TempStream << "\nInstructions: " << TotalInstructions; |
| 73 | TempStream << "\nTotal Cycles: " << TotalCycles; |
Andrea Di Biagio | a2eee47 | 2018-08-29 17:56:39 +0000 | [diff] [blame] | 74 | TempStream << "\nTotal uOps: " << TotalUOps << '\n'; |
Andrea Di Biagio | 3fc20c9 | 2018-05-23 15:59:27 +0000 | [diff] [blame] | 75 | TempStream << "\nDispatch Width: " << DispatchWidth; |
Andrea Di Biagio | a2eee47 | 2018-08-29 17:56:39 +0000 | [diff] [blame] | 76 | TempStream << "\nuOps Per Cycle: " |
| 77 | << format("%.2f", floor((UOpsPerCycle * 100) + 0.5) / 100); |
| 78 | TempStream << "\nIPC: " |
| 79 | << format("%.2f", floor((IPC * 100) + 0.5) / 100); |
Andrea Di Biagio | 0af8115 | 2018-05-24 17:22:14 +0000 | [diff] [blame] | 80 | TempStream << "\nBlock RThroughput: " |
| 81 | << format("%.1f", floor((BlockRThroughput * 10) + 0.5) / 10) |
Andrea Di Biagio | 3fc20c9 | 2018-05-23 15:59:27 +0000 | [diff] [blame] | 82 | << '\n'; |
Andrea Di Biagio | 0cc66c7 | 2018-03-09 13:52:03 +0000 | [diff] [blame] | 83 | TempStream.flush(); |
| 84 | OS << Buffer; |
| 85 | } |
Andrea Di Biagio | 0cc66c7 | 2018-03-09 13:52:03 +0000 | [diff] [blame] | 86 | } // namespace mca. |