Files
clang-p2996/llvm/tools/llvm-mca/Views/RetireControlUnitStatistics.cpp
Chandler Carruth 2946cd7010 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

llvm-svn: 351636
2019-01-19 08:50:56 +00:00

91 lines
3.2 KiB
C++

//===--------------------- RetireControlUnitStatistics.cpp ------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
/// \file
///
/// This file implements the RetireControlUnitStatistics interface.
///
//===----------------------------------------------------------------------===//
#include "Views/RetireControlUnitStatistics.h"
#include "llvm/Support/Format.h"
namespace llvm {
namespace mca {
RetireControlUnitStatistics::RetireControlUnitStatistics(const MCSchedModel &SM)
: NumRetired(0), NumCycles(0), EntriesInUse(0), MaxUsedEntries(0),
SumOfUsedEntries(0) {
TotalROBEntries = SM.MicroOpBufferSize;
if (SM.hasExtraProcessorInfo()) {
const MCExtraProcessorInfo &EPI = SM.getExtraProcessorInfo();
if (EPI.ReorderBufferSize)
TotalROBEntries = EPI.ReorderBufferSize;
}
}
void RetireControlUnitStatistics::onEvent(const HWInstructionEvent &Event) {
if (Event.Type == HWInstructionEvent::Dispatched) {
unsigned NumEntries =
static_cast<const HWInstructionDispatchedEvent &>(Event).MicroOpcodes;
EntriesInUse += NumEntries;
}
if (Event.Type == HWInstructionEvent::Retired) {
unsigned ReleasedEntries = Event.IR.getInstruction()->getDesc().NumMicroOps;
assert(EntriesInUse >= ReleasedEntries && "Invalid internal state!");
EntriesInUse -= ReleasedEntries;
++NumRetired;
}
}
void RetireControlUnitStatistics::onCycleEnd() {
// Update histogram
RetiredPerCycle[NumRetired]++;
NumRetired = 0;
++NumCycles;
MaxUsedEntries = std::max(MaxUsedEntries, EntriesInUse);
SumOfUsedEntries += EntriesInUse;
}
void RetireControlUnitStatistics::printView(raw_ostream &OS) const {
std::string Buffer;
raw_string_ostream TempStream(Buffer);
TempStream << "\n\nRetire Control Unit - "
<< "number of cycles where we saw N instructions retired:\n";
TempStream << "[# retired], [# cycles]\n";
for (const std::pair<unsigned, unsigned> &Entry : RetiredPerCycle) {
TempStream << " " << Entry.first;
if (Entry.first < 10)
TempStream << ", ";
else
TempStream << ", ";
TempStream << Entry.second << " ("
<< format("%.1f", ((double)Entry.second / NumCycles) * 100.0)
<< "%)\n";
}
unsigned AvgUsage = (double)SumOfUsedEntries / NumCycles;
double MaxUsagePercentage = ((double)MaxUsedEntries / TotalROBEntries) * 100.0;
double NormalizedMaxPercentage = floor((MaxUsagePercentage * 10) + 0.5) / 10;
double AvgUsagePercentage = ((double)AvgUsage / TotalROBEntries) * 100.0;
double NormalizedAvgPercentage = floor((AvgUsagePercentage * 10) + 0.5) / 10;
TempStream << "\nTotal ROB Entries: " << TotalROBEntries
<< "\nMax Used ROB Entries: " << MaxUsedEntries
<< format(" ( %.1f%% )", NormalizedMaxPercentage)
<< "\nAverage Used ROB Entries per cy: " << AvgUsage
<< format(" ( %.1f%% )\n", NormalizedAvgPercentage);
TempStream.flush();
OS << Buffer;
}
} // namespace mca
} // namespace llvm