From 3dcc1b8616b87f44c1231beba9281e3c35cfca16 Mon Sep 17 00:00:00 2001 From: Andrea Di Biagio Date: Tue, 10 Apr 2018 15:14:15 +0000 Subject: [PATCH] [llvm-mca] Simplify code. NFC llvm-svn: 329711 --- tools/llvm-mca/ResourcePressureView.cpp | 48 ++++++++++--------------- 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/tools/llvm-mca/ResourcePressureView.cpp b/tools/llvm-mca/ResourcePressureView.cpp index 0a458836102..18f208f8e23 100644 --- a/tools/llvm-mca/ResourcePressureView.cpp +++ b/tools/llvm-mca/ResourcePressureView.cpp @@ -83,6 +83,22 @@ static void printColumnNames(raw_string_ostream &OS, const MCSchedModel &SM) { } } +static void printResourcePressure(raw_string_ostream &OS, double Pressure) { + if (!Pressure) { + OS << " - "; + return; + } + + // 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 << ' '; +} + void ResourcePressureView::printResourcePressurePerIteration( raw_ostream &OS, unsigned Executions) const { std::string Buffer; @@ -114,20 +130,7 @@ void ResourcePressureView::printResourcePressurePerIteration( for (unsigned I = 0, E = NumResourceUnits; I < E; ++I) { double Usage = ResourceUsage[I + Source.size() * E]; - if (!Usage) { - TempStream << " - "; - continue; - } - - double Pressure = Usage / Executions; - // Round to the value to the nearest hundredth and then print it. - TempStream << format("%.2f", floor((Pressure * 100) + 0.5)/100); - if (Pressure < 10.0) - TempStream << " "; - else if (Pressure < 100.0) - TempStream << " "; - else - TempStream << ' '; + printResourcePressure(TempStream, Usage / Executions); } TempStream.flush(); @@ -146,22 +149,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]; - if (!Usage) { - TempStream << " - "; - } else { - double Pressure = Usage / Executions; - if (Pressure < 0.005) { - TempStream << " - "; - } else { - TempStream << format("%.2f", Pressure); - if (Pressure < 10.0) - TempStream << " "; - else if (Pressure < 100.0) - TempStream << " "; - else - TempStream << ' '; - } - } + printResourcePressure(TempStream, Usage / Executions); } MCIP.printInst(&Source.getMCInstFromIndex(I), TempStream, "", STI);