[llvm] r254261 - SamplePGO - Do not use std::to_string in diagnostics.

Diego Novillo via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 29 10:23:27 PST 2015


Author: dnovillo
Date: Sun Nov 29 12:23:26 2015
New Revision: 254261

URL: http://llvm.org/viewvc/llvm-project?rev=254261&view=rev
Log:
SamplePGO - Do not use std::to_string in diagnostics.

This fixes buildbots in systems that std::to_string is not present. It
also tidies the output of the diagnostic to render doubles a bit better
(thanks Ben Kramer for help with string streams and format).

Modified:
    llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp

Modified: llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp?rev=254261&r1=254260&r2=254261&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp Sun Nov 29 12:23:26 2015
@@ -44,6 +44,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorOr.h"
+#include "llvm/Support/Format.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Transforms/IPO.h"
 #include "llvm/Transforms/Utils/Cloning.h"
@@ -629,12 +630,14 @@ bool SampleProfileLoader::emitInlineHint
   // it globally hot.
   if (SamplesPercent >= SampleProfileGlobalHotThreshold) {
     F.addFnAttr(llvm::Attribute::InlineHint);
-    emitOptimizationRemark(
-        F.getContext(), DEBUG_TYPE, F, DebugLoc(),
-        Twine("Applied inline hint to globally hot function '" + F.getName() +
-              "' with " + Twine(std::to_string(SamplesPercent)) +
-              "% of samples (threshold: " +
-              Twine(std::to_string(SampleProfileGlobalHotThreshold)) + "%)"));
+    std::string Msg;
+    raw_string_ostream S(Msg);
+    S << "Applied inline hint to globally hot function '" << F.getName()
+      << "' with " << format("%.2f", SamplesPercent)
+      << "% of samples (threshold: "
+      << format("%.2f", SampleProfileGlobalHotThreshold.getValue()) << "%)";
+    S.flush();
+    emitOptimizationRemark(F.getContext(), DEBUG_TYPE, F, DebugLoc(), Msg);
     return true;
   }
 
@@ -642,12 +645,14 @@ bool SampleProfileLoader::emitInlineHint
   // it globally cold.
   if (SamplesPercent <= SampleProfileGlobalColdThreshold) {
     F.addFnAttr(llvm::Attribute::Cold);
-    emitOptimizationRemark(
-        F.getContext(), DEBUG_TYPE, F, DebugLoc(),
-        Twine("Applied cold hint to globally cold function '" + F.getName() +
-              "' with " + Twine(std::to_string(SamplesPercent)) +
-              "% of samples (threshold: " +
-              Twine(std::to_string(SampleProfileGlobalColdThreshold)) + "%)"));
+    std::string Msg;
+    raw_string_ostream S(Msg);
+    S << "Applied cold hint to globally cold function '" << F.getName()
+      << "' with " << format("%.2f", SamplesPercent)
+      << "% of samples (threshold: "
+      << format("%.2f", SampleProfileGlobalColdThreshold.getValue()) << "%)";
+    S.flush();
+    emitOptimizationRemark(F.getContext(), DEBUG_TYPE, F, DebugLoc(), Msg);
     return true;
   }
 




More information about the llvm-commits mailing list