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