1 //===--------------------- RetireControlUnitStatistics.cpp ------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// This file implements the RetireControlUnitStatistics interface.
12 //===----------------------------------------------------------------------===//
14 #include "Views/RetireControlUnitStatistics.h"
15 #include "llvm/Support/Format.h"
20 RetireControlUnitStatistics::RetireControlUnitStatistics(const MCSchedModel
&SM
)
21 : NumRetired(0), NumCycles(0), EntriesInUse(0), MaxUsedEntries(0),
23 TotalROBEntries
= SM
.MicroOpBufferSize
;
24 if (SM
.hasExtraProcessorInfo()) {
25 const MCExtraProcessorInfo
&EPI
= SM
.getExtraProcessorInfo();
26 if (EPI
.ReorderBufferSize
)
27 TotalROBEntries
= EPI
.ReorderBufferSize
;
31 void RetireControlUnitStatistics::onEvent(const HWInstructionEvent
&Event
) {
32 if (Event
.Type
== HWInstructionEvent::Dispatched
) {
34 static_cast<const HWInstructionDispatchedEvent
&>(Event
).MicroOpcodes
;
35 EntriesInUse
+= NumEntries
;
38 if (Event
.Type
== HWInstructionEvent::Retired
) {
39 unsigned ReleasedEntries
= Event
.IR
.getInstruction()->getDesc().NumMicroOps
;
40 assert(EntriesInUse
>= ReleasedEntries
&& "Invalid internal state!");
41 EntriesInUse
-= ReleasedEntries
;
46 void RetireControlUnitStatistics::onCycleEnd() {
48 RetiredPerCycle
[NumRetired
]++;
51 MaxUsedEntries
= std::max(MaxUsedEntries
, EntriesInUse
);
52 SumOfUsedEntries
+= EntriesInUse
;
55 void RetireControlUnitStatistics::printView(raw_ostream
&OS
) const {
57 raw_string_ostream
TempStream(Buffer
);
58 TempStream
<< "\n\nRetire Control Unit - "
59 << "number of cycles where we saw N instructions retired:\n";
60 TempStream
<< "[# retired], [# cycles]\n";
62 for (const std::pair
<unsigned, unsigned> &Entry
: RetiredPerCycle
) {
63 TempStream
<< " " << Entry
.first
;
68 TempStream
<< Entry
.second
<< " ("
69 << format("%.1f", ((double)Entry
.second
/ NumCycles
) * 100.0)
73 unsigned AvgUsage
= (double)SumOfUsedEntries
/ NumCycles
;
74 double MaxUsagePercentage
= ((double)MaxUsedEntries
/ TotalROBEntries
) * 100.0;
75 double NormalizedMaxPercentage
= floor((MaxUsagePercentage
* 10) + 0.5) / 10;
76 double AvgUsagePercentage
= ((double)AvgUsage
/ TotalROBEntries
) * 100.0;
77 double NormalizedAvgPercentage
= floor((AvgUsagePercentage
* 10) + 0.5) / 10;
79 TempStream
<< "\nTotal ROB Entries: " << TotalROBEntries
80 << "\nMax Used ROB Entries: " << MaxUsedEntries
81 << format(" ( %.1f%% )", NormalizedMaxPercentage
)
82 << "\nAverage Used ROB Entries per cy: " << AvgUsage
83 << format(" ( %.1f%% )\n", NormalizedAvgPercentage
);