mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-14 11:39:35 +00:00
[BOLT][NFC] Replace stdio with raw_ostream in CallGraph
Replacing stdio functions, e.g., fopen, fprintf, with raw_ostream. Test Plan: ``` ninja check-bolt ``` Reviewed By: Amir Differential Revision: https://reviews.llvm.org/D126826
This commit is contained in:
parent
c9b55eb807
commit
db313a00b6
@ -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 @@ private:
|
||||
};
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user