[llvm-mca] use a formatted_raw_ostream to insert padding and get rid of tabs. NFC

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332381 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Andrea Di Biagio 2018-05-15 18:11:45 +00:00
parent d915812403
commit eebfacb84e
3 changed files with 76 additions and 92 deletions

View File

@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "ResourcePressureView.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/raw_ostream.h"
namespace mca {
@ -55,7 +56,9 @@ void ResourcePressureView::onInstructionEvent(const HWInstructionEvent &Event) {
}
}
static void printColumnNames(raw_string_ostream &OS, const MCSchedModel &SM) {
static void printColumnNames(formatted_raw_ostream &OS,
const MCSchedModel &SM) {
unsigned Column = OS.getColumn();
for (unsigned I = 1, ResourceIndex = 0, E = SM.getNumProcResourceKinds();
I < E; ++I) {
const MCProcResourceDesc &ProcResource = *SM.getProcResource(I);
@ -64,47 +67,37 @@ static void printColumnNames(raw_string_ostream &OS, const MCSchedModel &SM) {
if (ProcResource.SubUnitsIdxBegin || !NumUnits)
continue;
if (NumUnits == 1) {
OS << '[' << ResourceIndex << ']';
if (ResourceIndex < 10)
OS << " ";
else
OS << " ";
} else {
for (unsigned J = 0; J < NumUnits; ++J) {
OS << "[" << ResourceIndex << '.' << J << ']';
if (ResourceIndex < 10)
OS << " ";
else
OS << ' ';
}
for (unsigned J = 0; J < NumUnits; ++J) {
Column += 7;
OS << "[" << ResourceIndex;
if (NumUnits > 1)
OS << '.' << J;
OS << ']';
OS.PadToColumn(Column);
}
ResourceIndex++;
}
}
static void printResourcePressure(raw_string_ostream &OS, double Pressure) {
static void printResourcePressure(formatted_raw_ostream &OS, double Pressure,
unsigned Col) {
if (!Pressure || Pressure < 0.005) {
OS << " - ";
return;
OS << " - ";
} else {
// Round to the value to the nearest hundredth and then print it.
OS << format("%.2f", floor((Pressure * 100) + 0.5) / 100);
}
// Round to the value to the nearest hundredth and then print it.
OS << format("%.2f", floor((Pressure * 100) + 0.5)/100);
if (Pressure < 10.0)
OS << " ";
else if (Pressure < 100.0)
OS << " ";
else
OS << ' ';
OS.PadToColumn(Col);
}
void ResourcePressureView::printResourcePressurePerIteration(
raw_ostream &OS, unsigned Executions) const {
std::string Buffer;
raw_string_ostream TempStream(Buffer);
formatted_raw_ostream FOS(TempStream);
TempStream << "\n\nResources:\n";
FOS << "\n\nResources:\n";
const MCSchedModel &SM = STI.getSchedModel();
for (unsigned I = 1, ResourceIndex = 0, E = SM.getNumProcResourceKinds();
I < E; ++I) {
@ -115,25 +108,29 @@ void ResourcePressureView::printResourcePressurePerIteration(
continue;
for (unsigned J = 0; J < NumUnits; ++J) {
TempStream << '[' << ResourceIndex;
FOS << '[' << ResourceIndex;
if (NumUnits > 1)
TempStream << '.' << J;
TempStream << "] - " << ProcResource.Name << '\n';
FOS << '.' << J;
FOS << ']';
FOS.PadToColumn(6);
FOS << "- " << ProcResource.Name << '\n';
}
ResourceIndex++;
}
TempStream << "\n\nResource pressure per iteration:\n";
printColumnNames(TempStream, SM);
TempStream << '\n';
FOS << "\n\nResource pressure per iteration:\n";
FOS.flush();
printColumnNames(FOS, SM);
FOS << '\n';
FOS.flush();
for (unsigned I = 0, E = NumResourceUnits; I < E; ++I) {
double Usage = ResourceUsage[I + Source.size() * E];
printResourcePressure(TempStream, Usage / Executions);
printResourcePressure(FOS, Usage / Executions, (I + 1) * 7);
}
TempStream.flush();
FOS.flush();
OS << Buffer;
}
@ -141,10 +138,11 @@ void ResourcePressureView::printResourcePressurePerInstruction(
raw_ostream &OS, unsigned Executions) const {
std::string Buffer;
raw_string_ostream TempStream(Buffer);
formatted_raw_ostream FOS(TempStream);
TempStream << "\n\nResource pressure by instruction:\n";
printColumnNames(TempStream, STI.getSchedModel());
TempStream << "Instructions:\n";
FOS << "\n\nResource pressure by instruction:\n";
printColumnNames(FOS, STI.getSchedModel());
FOS << "Instructions:\n";
std::string Instruction;
raw_string_ostream InstrStream(Instruction);
@ -152,7 +150,7 @@ void ResourcePressureView::printResourcePressurePerInstruction(
for (unsigned I = 0, E = Source.size(); I < E; ++I) {
for (unsigned J = 0; J < NumResourceUnits; ++J) {
double Usage = ResourceUsage[J + I * NumResourceUnits];
printResourcePressure(TempStream, Usage / Executions);
printResourcePressure(FOS, Usage / Executions, (J + 1) * 7);
}
MCIP.printInst(&Source.getMCInstFromIndex(I), InstrStream, "", STI);
@ -162,10 +160,10 @@ void ResourcePressureView::printResourcePressurePerInstruction(
// Remove any tabs or spaces at the beginning of the instruction.
Str = Str.ltrim();
TempStream << Str << '\n';
FOS << Str << '\n';
Instruction = "";
TempStream.flush();
FOS.flush();
OS << Buffer;
Buffer = "";
}

View File

@ -73,48 +73,30 @@ void TimelineView::onInstructionEvent(const HWInstructionEvent &Event) {
LastCycle = std::max(LastCycle, CurrentCycle);
}
static void printAverageTime(raw_string_ostream &OS, double AverageTime) {
// Round to the nearest tenth.
OS << format("%.1f", floor((AverageTime * 10) + 0.5)/10);
if (AverageTime < 10.0)
OS << " ";
else if (AverageTime < 100.0)
OS << " ";
else
OS << " ";
}
void TimelineView::printWaitTimeEntry(raw_string_ostream &OS,
void TimelineView::printWaitTimeEntry(formatted_raw_ostream &OS,
const WaitTimeEntry &Entry,
unsigned SourceIndex) const {
OS << SourceIndex << '.';
if (SourceIndex < 10)
OS << " ";
else if (SourceIndex < 100)
OS << " ";
else if (SourceIndex < 1000)
OS << " ";
else
OS << ' ';
OS.PadToColumn(7);
if (Entry.Executions == 0) {
OS << " - - - - ";
OS << "- - - - ";
} else {
double AverageTime1, AverageTime2, AverageTime3;
unsigned Executions = Entry.Executions;
AverageTime1 = (double)Entry.CyclesSpentInSchedulerQueue / Executions;
AverageTime2 = (double)Entry.CyclesSpentInSQWhileReady / Executions;
AverageTime3 = (double)Entry.CyclesSpentAfterWBAndBeforeRetire / Executions;
if (Executions < 10)
OS << ' ' << Executions << " ";
else if (Executions < 100)
OS << ' ' << Executions << " ";
else
OS << Executions << " ";
printAverageTime(OS, AverageTime1);
printAverageTime(OS, AverageTime2);
printAverageTime(OS, AverageTime3);
OS << Executions;
OS.PadToColumn(13);
OS << format("%.1f", floor((AverageTime1 * 10) + 0.5) / 10);
OS.PadToColumn(20);
OS << format("%.1f", floor((AverageTime2 * 10) + 0.5) / 10);
OS.PadToColumn(27);
OS << format("%.1f", floor((AverageTime3 * 10) + 0.5) / 10);
OS.PadToColumn(34);
}
}
@ -124,21 +106,21 @@ void TimelineView::printAverageWaitTimes(raw_ostream &OS) const {
std::string Buffer;
raw_string_ostream TempStream(Buffer);
formatted_raw_ostream FOS(TempStream);
TempStream
<< "\n\nAverage Wait times (based on the timeline view):\n"
FOS << "\n\nAverage Wait times (based on the timeline view):\n"
<< "[0]: Executions\n"
<< "[1]: Average time spent waiting in a scheduler's queue\n"
<< "[2]: Average time spent waiting in a scheduler's queue while ready\n"
<< "[3]: Average time elapsed from WB until retire stage\n\n";
TempStream << " [0] [1] [2] [3]\n";
FOS << " [0] [1] [2] [3]\n";
// Use a different string stream for the instruction.
std::string Instruction;
raw_string_ostream InstrStream(Instruction);
for (unsigned I = 0, E = WaitTime.size(); I < E; ++I) {
printWaitTimeEntry(TempStream, WaitTime[I], I);
printWaitTimeEntry(FOS, WaitTime[I], I);
// Append the instruction info at the end of the line.
const MCInst &Inst = AsmSequence.getMCInstFromIndex(I);
@ -148,8 +130,8 @@ void TimelineView::printAverageWaitTimes(raw_ostream &OS) const {
// Consume any tabs or spaces at the beginning of the string.
StringRef Str(Instruction);
Str = Str.ltrim();
TempStream << " " << Str << '\n';
TempStream.flush();
FOS << " " << Str << '\n';
FOS.flush();
Instruction = "";
OS << Buffer;
@ -157,13 +139,14 @@ void TimelineView::printAverageWaitTimes(raw_ostream &OS) const {
}
}
void TimelineView::printTimelineViewEntry(raw_string_ostream &OS,
void TimelineView::printTimelineViewEntry(formatted_raw_ostream &OS,
const TimelineViewEntry &Entry,
unsigned Iteration,
unsigned SourceIndex) const {
if (Iteration == 0 && SourceIndex == 0)
OS << '\n';
OS << '[' << Iteration << ',' << SourceIndex << "]\t";
OS << '[' << Iteration << ',' << SourceIndex << ']';
OS.PadToColumn(10);
for (unsigned I = 0, E = Entry.CycleDispatched; I < E; ++I)
OS << ((I % 5 == 0) ? '.' : ' ');
OS << TimelineView::DisplayChar::Dispatched;
@ -194,9 +177,9 @@ void TimelineView::printTimelineViewEntry(raw_string_ostream &OS,
OS << ((I % 5 == 0 || I == LastCycle) ? '.' : ' ');
}
static void printTimelineHeader(raw_string_ostream &OS, unsigned Cycles) {
static void printTimelineHeader(formatted_raw_ostream &OS, unsigned Cycles) {
OS << "\n\nTimeline view:\n";
OS << " \t";
OS.PadToColumn(10);
for (unsigned I = 0; I <= Cycles; ++I) {
if (((I / 10) & 1) == 0)
OS << ' ';
@ -204,7 +187,8 @@ static void printTimelineHeader(raw_string_ostream &OS, unsigned Cycles) {
OS << I % 10;
}
OS << "\nIndex\t";
OS << "\nIndex";
OS.PadToColumn(10);
for (unsigned I = 0; I <= Cycles; ++I) {
if (((I / 10) & 1) == 0)
OS << I % 10;
@ -216,10 +200,11 @@ static void printTimelineHeader(raw_string_ostream &OS, unsigned Cycles) {
void TimelineView::printTimeline(raw_ostream &OS) const {
std::string Buffer;
raw_string_ostream TempStream(Buffer);
raw_string_ostream StringStream(Buffer);
formatted_raw_ostream FOS(StringStream);
printTimelineHeader(TempStream, LastCycle);
TempStream.flush();
printTimelineHeader(FOS, LastCycle);
FOS.flush();
OS << Buffer;
// Use a different string stream for the instruction.
@ -234,7 +219,7 @@ void TimelineView::printTimeline(raw_ostream &OS) const {
unsigned Iteration = I / AsmSequence.size();
unsigned SourceIndex = I % AsmSequence.size();
printTimelineViewEntry(TempStream, Entry, Iteration, SourceIndex);
printTimelineViewEntry(FOS, Entry, Iteration, SourceIndex);
// Append the instruction info at the end of the line.
const MCInst &Inst = AsmSequence.getMCInstFromIndex(I);
MCIP.printInst(&Inst, InstrStream, "", STI);
@ -243,8 +228,8 @@ void TimelineView::printTimeline(raw_ostream &OS) const {
// Consume any tabs or spaces at the beginning of the string.
StringRef Str(Instruction);
Str = Str.ltrim();
TempStream << " " << Str << '\n';
TempStream.flush();
FOS << " " << Str << '\n';
FOS.flush();
Instruction = "";
OS << Buffer;
}

View File

@ -104,6 +104,7 @@
#include "View.h"
#include "llvm/MC/MCInstPrinter.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/raw_ostream.h"
#include <map>
@ -142,11 +143,11 @@ class TimelineView : public View {
};
std::vector<WaitTimeEntry> WaitTime;
void printTimelineViewEntry(llvm::raw_string_ostream &OS,
void printTimelineViewEntry(llvm::formatted_raw_ostream &OS,
const TimelineViewEntry &E, unsigned Iteration,
unsigned SourceIndex) const;
void printWaitTimeEntry(llvm::raw_string_ostream &OS, const WaitTimeEntry &E,
unsigned Index) const;
void printWaitTimeEntry(llvm::formatted_raw_ostream &OS,
const WaitTimeEntry &E, unsigned Index) const;
const unsigned DEFAULT_ITERATIONS = 10;