blob: 3a7eb827c478e1b37152a3c3328cbc03113e2a2e [file] [log] [blame]
Andrea Di Biagio0cc66c72018-03-09 13:52:03 +00001//===--------------------- 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 Davis10aa09f2018-08-24 20:24:53 +000016#include "Views/SummaryView.h"
Andrea Di Biagio3fc20c92018-05-23 15:59:27 +000017#include "llvm/ADT/SmallVector.h"
Clement Courbetcc5e6a72018-12-17 08:08:31 +000018#include "llvm/MCA/Support.h"
Andrea Di Biagiodf5d9482018-03-23 19:40:04 +000019#include "llvm/Support/Format.h"
Andrea Di Biagio0cc66c72018-03-09 13:52:03 +000020
Fangrui Song5a8fd652018-10-30 15:56:08 +000021namespace llvm {
Andrea Di Biagio0cc66c72018-03-09 13:52:03 +000022namespace mca {
23
Andrea Di Biagiodf5d9482018-03-23 19:40:04 +000024#define DEBUG_TYPE "llvm-mca"
25
Andrea Di Biagio84d00512018-10-26 10:48:04 +000026SummaryView::SummaryView(const MCSchedModel &Model, ArrayRef<MCInst> S,
Andrea Di Biagiobdc67062018-06-01 14:35:21 +000027 unsigned Width)
Sam McCall0739ffc2018-10-26 12:19:48 +000028 : SM(Model), Source(S), DispatchWidth(Width), LastInstructionIdx(0),
29 TotalCycles(0), NumMicroOps(0),
Andrea Di Biagio84d00512018-10-26 10:48:04 +000030 ProcResourceUsage(Model.getNumProcResourceKinds(), 0) {
Andrea Di Biagiobdc67062018-06-01 14:35:21 +000031 computeProcResourceMasks(SM, ProcResourceMasks);
32}
33
Matt Davis0906a7f2018-07-12 16:56:17 +000034void SummaryView::onEvent(const HWInstructionEvent &Event) {
Andrea Di Biagio84d00512018-10-26 10:48:04 +000035 if (Event.Type == HWInstructionEvent::Dispatched)
36 LastInstructionIdx = Event.IR.getSourceIndex();
37
Andrea Di Biagio8b647dc2018-08-30 10:50:20 +000038 // 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 Biagio3fc20c92018-05-23 15:59:27 +000042 return;
43
44 // Update the cumulative number of resource cycles based on the processor
Andrea Di Biagio0af81152018-05-24 17:22:14 +000045 // 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 Biagio3fc20c92018-05-23 15:59:27 +000048 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 Biagiobdc67062018-06-01 14:35:21 +000052 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 Biagio3fc20c92018-05-23 15:59:27 +000058 }
59 }
Andrea Di Biagio3fc20c92018-05-23 15:59:27 +000060}
61
Andrea Di Biagiodf5d9482018-03-23 19:40:04 +000062void SummaryView::printView(raw_ostream &OS) const {
Andrea Di Biagiob5229752018-03-13 17:24:32 +000063 unsigned Instructions = Source.size();
Andrea Di Biagio84d00512018-10-26 10:48:04 +000064 unsigned Iterations = (LastInstructionIdx / Instructions) + 1;
Andrea Di Biagio0cc66c72018-03-09 13:52:03 +000065 unsigned TotalInstructions = Instructions * Iterations;
Andrea Di Biagioa2eee472018-08-29 17:56:39 +000066 unsigned TotalUOps = NumMicroOps * Iterations;
Andrea Di Biagio0cc66c72018-03-09 13:52:03 +000067 double IPC = (double)TotalInstructions / TotalCycles;
Andrea Di Biagioa2eee472018-08-29 17:56:39 +000068 double UOpsPerCycle = (double)TotalUOps / TotalCycles;
Andrea Di Biagiobdc67062018-06-01 14:35:21 +000069 double BlockRThroughput = computeBlockRThroughput(
70 SM, DispatchWidth, NumMicroOps, ProcResourceUsage);
Andrea Di Biagio0cc66c72018-03-09 13:52:03 +000071
72 std::string Buffer;
73 raw_string_ostream TempStream(Buffer);
Andrea Di Biagio3fc20c92018-05-23 15:59:27 +000074 TempStream << "Iterations: " << Iterations;
75 TempStream << "\nInstructions: " << TotalInstructions;
76 TempStream << "\nTotal Cycles: " << TotalCycles;
Andrea Di Biagioa2eee472018-08-29 17:56:39 +000077 TempStream << "\nTotal uOps: " << TotalUOps << '\n';
Andrea Di Biagio3fc20c92018-05-23 15:59:27 +000078 TempStream << "\nDispatch Width: " << DispatchWidth;
Andrea Di Biagioa2eee472018-08-29 17:56:39 +000079 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 Biagio0af81152018-05-24 17:22:14 +000083 TempStream << "\nBlock RThroughput: "
84 << format("%.1f", floor((BlockRThroughput * 10) + 0.5) / 10)
Andrea Di Biagio3fc20c92018-05-23 15:59:27 +000085 << '\n';
Andrea Di Biagio0cc66c72018-03-09 13:52:03 +000086 TempStream.flush();
87 OS << Buffer;
88}
Andrea Di Biagio0cc66c72018-03-09 13:52:03 +000089} // namespace mca.
Fangrui Song5a8fd652018-10-30 15:56:08 +000090} // namespace llvm