SamplePGO - Do not use std::to_string in diagnostics.
authorDiego Novillo <dnovillo@google.com>
Sun, 29 Nov 2015 18:23:26 +0000 (18:23 +0000)
committerDiego Novillo <dnovillo@google.com>
Sun, 29 Nov 2015 18:23:26 +0000 (18:23 +0000)
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).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254261 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/SampleProfile.cpp

index 5cb71f71e707d0897f696f8b9ed244f81fbd8a8d..2ce1fcece41f089005a4fe42e8886f81e0fa10f0 100644 (file)
@@ -44,6 +44,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorOr.h"
 #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"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Transforms/IPO.h"
 #include "llvm/Transforms/Utils/Cloning.h"
@@ -629,12 +630,14 @@ bool SampleProfileLoader::emitInlineHints(Function &F) {
   // it globally hot.
   if (SamplesPercent >= SampleProfileGlobalHotThreshold) {
     F.addFnAttr(llvm::Attribute::InlineHint);
   // 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;
   }
 
     return true;
   }
 
@@ -642,12 +645,14 @@ bool SampleProfileLoader::emitInlineHints(Function &F) {
   // it globally cold.
   if (SamplesPercent <= SampleProfileGlobalColdThreshold) {
     F.addFnAttr(llvm::Attribute::Cold);
   // 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;
   }
 
     return true;
   }