[PATCH] D126826: [BOLT][NFC] Replace stdio with raw_ostream in CallGraph

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 8 15:38:15 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGdb313a00b615: [BOLT][NFC] Replace stdio with raw_ostream in CallGraph (authored by nhuhuan, committed by Amir).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126826/new/

https://reviews.llvm.org/D126826

Files:
  bolt/include/bolt/Passes/CallGraph.h


Index: bolt/include/bolt/Passes/CallGraph.h
===================================================================
--- bolt/include/bolt/Passes/CallGraph.h
+++ bolt/include/bolt/Passes/CallGraph.h
@@ -9,9 +9,10 @@
 #ifndef BOLT_PASSES_CALLGRAPH_H
 #define BOLT_PASSES_CALLGRAPH_H
 
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/raw_ostream.h"
 #include <cassert>
 #include <cstdint>
-#include <cstdio>
 #include <unordered_set>
 #include <vector>
 
@@ -160,31 +161,31 @@
 };
 
 template <class L> void CallGraph::printDot(char *FileName, L GetLabel) const {
-  FILE *File = fopen(FileName, "wt");
-  if (!File)
+  std::error_code EC;
+  raw_fd_ostream OS(std::string(FileName), EC, sys::fs::OF_None);
+  if (EC)
     return;
 
-  fprintf(File, "digraph g {\n");
+  OS << "digraph g {\n";
   for (NodeId F = 0; F < Nodes.size(); F++) {
     if (Nodes[F].samples() == 0)
       continue;
-    fprintf(File, "f%lu [label=\"%s\\nsamples=%u\\nsize=%u\"];\n", F,
-            GetLabel(F), Nodes[F].samples(), Nodes[F].size());
+    OS << "f" << F << " [label=\"" << GetLabel(F)
+       << "\\nsamples=" << Nodes[F].samples() << "\\nsize=" << Nodes[F].size()
+       << "\"];\n";
   }
   for (NodeId F = 0; F < Nodes.size(); F++) {
     if (Nodes[F].samples() == 0)
       continue;
     for (NodeId Dst : Nodes[F].successors()) {
       ArcConstIterator Arc = findArc(F, Dst);
-      fprintf(
-          File,
-          "f%lu -> f%u [label=\"normWgt=%.3lf,weight=%.0lf,callOffset=%.1lf\"];"
-          "\n",
-          F, Dst, Arc->normalizedWeight(), Arc->weight(), Arc->avgCallOffset());
+      OS << "f" << F << " -> f" << Dst
+         << " [label=\"normWgt=" << format("%.3lf", Arc->normalizedWeight())
+         << ",weight=" << format("%.0lf", Arc->weight())
+         << ",callOffset=" << format("%.1lf", Arc->avgCallOffset()) << "\"];\n";
     }
   }
-  fprintf(File, "}\n");
-  fclose(File);
+  OS << "}\n";
 }
 
 } // namespace bolt


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126826.435367.patch
Type: text/x-patch
Size: 1952 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220608/6f441a88/attachment.bin>


More information about the llvm-commits mailing list