1 //===--------------------- SummaryView.cpp -------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// This file implements the functionalities used by the SummaryView to print
12 /// the report information.
14 //===----------------------------------------------------------------------===//
16 #include "Views/SummaryView.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/MCA/Support.h"
19 #include "llvm/Support/Format.h"
24 #define DEBUG_TYPE "llvm-mca"
26 SummaryView::SummaryView(const MCSchedModel &Model, ArrayRef<MCInst> S,
28 : SM(Model), Source(S), DispatchWidth(Width), LastInstructionIdx(0),
29 TotalCycles(0), NumMicroOps(0),
30 ProcResourceUsage(Model.getNumProcResourceKinds(), 0),
31 ProcResourceMasks(Model.getNumProcResourceKinds()) {
32 computeProcResourceMasks(SM, ProcResourceMasks);
35 void SummaryView::onEvent(const HWInstructionEvent &Event) {
36 if (Event.Type == HWInstructionEvent::Dispatched)
37 LastInstructionIdx = Event.IR.getSourceIndex();
39 // We are only interested in the "instruction retired" events generated by
40 // the retire stage for instructions that are part of iteration #0.
41 if (Event.Type != HWInstructionEvent::Retired ||
42 Event.IR.getSourceIndex() >= Source.size())
45 // Update the cumulative number of resource cycles based on the processor
46 // resource usage information available from the instruction descriptor. We
47 // need to compute the cumulative number of resource cycles for every
48 // processor resource which is consumed by an instruction of the block.
49 const Instruction &Inst = *Event.IR.getInstruction();
50 const InstrDesc &Desc = Inst.getDesc();
51 NumMicroOps += Desc.NumMicroOps;
52 for (const std::pair<uint64_t, const ResourceUsage> &RU : Desc.Resources) {
53 if (RU.second.size()) {
54 const auto It = find(ProcResourceMasks, RU.first);
55 assert(It != ProcResourceMasks.end() &&
56 "Invalid processor resource mask!");
57 ProcResourceUsage[std::distance(ProcResourceMasks.begin(), It)] +=
63 void SummaryView::printView(raw_ostream &OS) const {
64 unsigned Instructions = Source.size();
65 unsigned Iterations = (LastInstructionIdx / Instructions) + 1;
66 unsigned TotalInstructions = Instructions * Iterations;
67 unsigned TotalUOps = NumMicroOps * Iterations;
68 double IPC = (double)TotalInstructions / TotalCycles;
69 double UOpsPerCycle = (double)TotalUOps / TotalCycles;
70 double BlockRThroughput = computeBlockRThroughput(
71 SM, DispatchWidth, NumMicroOps, ProcResourceUsage);
74 raw_string_ostream TempStream(Buffer);
75 TempStream << "Iterations: " << Iterations;
76 TempStream << "\nInstructions: " << TotalInstructions;
77 TempStream << "\nTotal Cycles: " << TotalCycles;
78 TempStream << "\nTotal uOps: " << TotalUOps << '\n';
79 TempStream << "\nDispatch Width: " << DispatchWidth;
80 TempStream << "\nuOps Per Cycle: "
81 << format("%.2f", floor((UOpsPerCycle * 100) + 0.5) / 100);
82 TempStream << "\nIPC: "
83 << format("%.2f", floor((IPC * 100) + 0.5) / 100);
84 TempStream << "\nBlock RThroughput: "
85 << format("%.1f", floor((BlockRThroughput * 10) + 0.5) / 10)