mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 11:13:28 +01:00
convert LoopInfo.h and GraphWriter.h to use raw_ostream
llvm-svn: 79836
This commit is contained in:
parent
d8d0d40b2d
commit
f536c93134
@ -36,9 +36,8 @@
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/Analysis/Dominators.h"
|
||||
#include "llvm/Support/CFG.h"
|
||||
#include "llvm/Support/Streams.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include <algorithm>
|
||||
#include <ostream>
|
||||
|
||||
namespace llvm {
|
||||
|
||||
|
@ -235,7 +235,7 @@ inline typename cast_retty<X, Y>::ret_type dyn_cast_or_null(const Y &Val) {
|
||||
|
||||
|
||||
#ifdef DEBUG_CAST_OPERATORS
|
||||
#include "llvm/Support/Streams.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
struct bar {
|
||||
bar() {}
|
||||
@ -251,7 +251,7 @@ struct foo {
|
||||
};
|
||||
|
||||
template <> inline bool isa_impl<foo,bar>(const bar &Val) {
|
||||
cerr << "Classof: " << &Val << "\n";
|
||||
errs() << "Classof: " << &Val << "\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -24,47 +24,16 @@
|
||||
#define LLVM_SUPPORT_GRAPHWRITER_H
|
||||
|
||||
#include "llvm/Support/DOTGraphTraits.h"
|
||||
#include "llvm/Support/Streams.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/ADT/GraphTraits.h"
|
||||
#include "llvm/System/Path.h"
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
namespace llvm {
|
||||
|
||||
namespace DOT { // Private functions...
|
||||
inline std::string EscapeString(const std::string &Label) {
|
||||
std::string Str(Label);
|
||||
for (unsigned i = 0; i != Str.length(); ++i)
|
||||
switch (Str[i]) {
|
||||
case '\n':
|
||||
Str.insert(Str.begin()+i, '\\'); // Escape character...
|
||||
++i;
|
||||
Str[i] = 'n';
|
||||
break;
|
||||
case '\t':
|
||||
Str.insert(Str.begin()+i, ' '); // Convert to two spaces
|
||||
++i;
|
||||
Str[i] = ' ';
|
||||
break;
|
||||
case '\\':
|
||||
if (i+1 != Str.length())
|
||||
switch (Str[i+1]) {
|
||||
case 'l': continue; // don't disturb \l
|
||||
case '|': case '{': case '}':
|
||||
Str.erase(Str.begin()+i); continue;
|
||||
default: break;
|
||||
}
|
||||
case '{': case '}':
|
||||
case '<': case '>':
|
||||
case '|': case '"':
|
||||
Str.insert(Str.begin()+i, '\\'); // Escape character...
|
||||
++i; // don't infinite loop
|
||||
break;
|
||||
}
|
||||
return Str;
|
||||
}
|
||||
std::string EscapeString(const std::string &Label);
|
||||
}
|
||||
|
||||
namespace GraphProgram {
|
||||
@ -81,7 +50,7 @@ void DisplayGraph(const sys::Path& Filename, bool wait=true, GraphProgram::Name
|
||||
|
||||
template<typename GraphType>
|
||||
class GraphWriter {
|
||||
std::ostream &O;
|
||||
raw_ostream &O;
|
||||
const GraphType &G;
|
||||
bool ShortNames;
|
||||
|
||||
@ -91,7 +60,7 @@ class GraphWriter {
|
||||
typedef typename GTraits::nodes_iterator node_iterator;
|
||||
typedef typename GTraits::ChildIteratorType child_iterator;
|
||||
public:
|
||||
GraphWriter(std::ostream &o, const GraphType &g, bool SN) :
|
||||
GraphWriter(raw_ostream &o, const GraphType &g, bool SN) :
|
||||
O(o), G(g), ShortNames(SN) {}
|
||||
|
||||
void writeHeader(const std::string &Name) {
|
||||
@ -266,10 +235,10 @@ public:
|
||||
};
|
||||
|
||||
template<typename GraphType>
|
||||
std::ostream &WriteGraph(std::ostream &O, const GraphType &G,
|
||||
bool ShortNames = false,
|
||||
const std::string &Name = "",
|
||||
const std::string &Title = "") {
|
||||
raw_ostream &WriteGraph(raw_ostream &O, const GraphType &G,
|
||||
bool ShortNames = false,
|
||||
const std::string &Name = "",
|
||||
const std::string &Title = "") {
|
||||
// Start the graph emission process...
|
||||
GraphWriter<GraphType> W(O, G, ShortNames);
|
||||
|
||||
@ -295,26 +264,25 @@ sys::Path WriteGraph(const GraphType &G,
|
||||
std::string ErrMsg;
|
||||
sys::Path Filename = sys::Path::GetTemporaryDirectory(&ErrMsg);
|
||||
if (Filename.isEmpty()) {
|
||||
cerr << "Error: " << ErrMsg << "\n";
|
||||
errs() << "Error: " << ErrMsg << "\n";
|
||||
return Filename;
|
||||
}
|
||||
Filename.appendComponent(Name + ".dot");
|
||||
if (Filename.makeUnique(true,&ErrMsg)) {
|
||||
cerr << "Error: " << ErrMsg << "\n";
|
||||
errs() << "Error: " << ErrMsg << "\n";
|
||||
return sys::Path();
|
||||
}
|
||||
|
||||
cerr << "Writing '" << Filename << "'... ";
|
||||
errs() << "Writing '" << Filename << "'... ";
|
||||
|
||||
std::ofstream O(Filename.c_str());
|
||||
std::string ErrorInfo;
|
||||
raw_fd_ostream O(Filename.c_str(), ErrorInfo, raw_fd_ostream::F_Force);
|
||||
|
||||
if (O.good()) {
|
||||
if (ErrorInfo.empty()) {
|
||||
WriteGraph(O, G, ShortNames, Name, Title);
|
||||
cerr << " done. \n";
|
||||
|
||||
O.close();
|
||||
errs() << " done. \n";
|
||||
} else {
|
||||
cerr << "error opening file for writing!\n";
|
||||
errs() << "error opening file '" << Filename << "' for writing!\n";
|
||||
Filename.clear();
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "llvm/Support/CFG.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
#include "llvm/Support/GraphWriter.h"
|
||||
#include "llvm/Config/config.h"
|
||||
using namespace llvm;
|
||||
|
||||
namespace llvm {
|
||||
@ -136,14 +135,16 @@ namespace {
|
||||
|
||||
virtual bool runOnFunction(Function &F) {
|
||||
std::string Filename = "cfg." + F.getNameStr() + ".dot";
|
||||
cerr << "Writing '" << Filename << "'...";
|
||||
std::ofstream File(Filename.c_str());
|
||||
errs() << "Writing '" << Filename << "'...";
|
||||
|
||||
std::string ErrorInfo;
|
||||
raw_fd_ostream File(Filename.c_str(), ErrorInfo, raw_fd_ostream::F_Force);
|
||||
|
||||
if (File.good())
|
||||
if (ErrorInfo.empty())
|
||||
WriteGraph(File, (const Function*)&F);
|
||||
else
|
||||
cerr << " error opening file for writing!";
|
||||
cerr << "\n";
|
||||
errs() << " error opening file for writing!";
|
||||
errs() << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -166,14 +167,16 @@ namespace {
|
||||
explicit CFGOnlyPrinter(void *pid) : FunctionPass(pid) {}
|
||||
virtual bool runOnFunction(Function &F) {
|
||||
std::string Filename = "cfg." + F.getNameStr() + ".dot";
|
||||
cerr << "Writing '" << Filename << "'...";
|
||||
std::ofstream File(Filename.c_str());
|
||||
errs() << "Writing '" << Filename << "'...";
|
||||
|
||||
if (File.good())
|
||||
std::string ErrorInfo;
|
||||
raw_fd_ostream File(Filename.c_str(), ErrorInfo, raw_fd_ostream::F_Force);
|
||||
|
||||
if (ErrorInfo.empty())
|
||||
WriteGraph(File, (const Function*)&F, true);
|
||||
else
|
||||
cerr << " error opening file for writing!";
|
||||
cerr << "\n";
|
||||
errs() << " error opening file for writing!";
|
||||
errs() << "\n";
|
||||
return false;
|
||||
}
|
||||
void print(raw_ostream &OS, const Module* = 0) const {}
|
||||
|
@ -272,7 +272,7 @@ bool LPPassManager::runOnFunction(Function &F) {
|
||||
|
||||
/// Print passes managed by this manager
|
||||
void LPPassManager::dumpPassStructure(unsigned Offset) {
|
||||
llvm::cerr << std::string(Offset*2, ' ') << "Loop Pass Manager\n";
|
||||
errs().indent(Offset*2) << "Loop Pass Manager\n";
|
||||
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
|
||||
Pass *P = getContainedPass(Index);
|
||||
P->dumpPassStructure(Offset + 1);
|
||||
|
@ -1724,7 +1724,7 @@ GCMetadataPrinter *AsmPrinter::GetOrCreateGCPrinter(GCStrategy *S) {
|
||||
return GMP;
|
||||
}
|
||||
|
||||
cerr << "no GCMetadataPrinter registered for GC: " << Name << "\n";
|
||||
errs() << "no GCMetadataPrinter registered for GC: " << Name << "\n";
|
||||
llvm_unreachable(0);
|
||||
}
|
||||
|
||||
|
@ -765,9 +765,9 @@ void SchedulePostRATDList::ReleaseSucc(SUnit *SU, SDep *SuccEdge) {
|
||||
|
||||
#ifndef NDEBUG
|
||||
if (SuccSU->NumPredsLeft < 0) {
|
||||
cerr << "*** Scheduling failed! ***\n";
|
||||
errs() << "*** Scheduling failed! ***\n";
|
||||
SuccSU->dump(this);
|
||||
cerr << " has been released too many times!\n";
|
||||
errs() << " has been released too many times!\n";
|
||||
llvm_unreachable(0);
|
||||
}
|
||||
#endif
|
||||
|
@ -514,13 +514,13 @@ namespace llvm {
|
||||
}
|
||||
|
||||
void CompilationGraph::writeGraph(const std::string& OutputFilename) {
|
||||
std::ofstream O(OutputFilename.c_str());
|
||||
std::string ErrorInfo;
|
||||
raw_fd_ostream O(OutputFilename.c_str(), ErrorInfo);
|
||||
|
||||
if (O.good()) {
|
||||
if (ErrorInfo.empty()) {
|
||||
errs() << "Writing '"<< OutputFilename << "' file...";
|
||||
llvm::WriteGraph(O, this);
|
||||
errs() << "done.\n";
|
||||
O.close();
|
||||
}
|
||||
else {
|
||||
throw std::runtime_error("Error opening file '" + OutputFilename
|
||||
|
@ -12,12 +12,45 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Support/GraphWriter.h"
|
||||
#include "llvm/Support/Streams.h"
|
||||
#include "llvm/System/Path.h"
|
||||
#include "llvm/System/Program.h"
|
||||
#include "llvm/Config/config.h"
|
||||
using namespace llvm;
|
||||
|
||||
std::string llvm::DOT::EscapeString(const std::string &Label) {
|
||||
std::string Str(Label);
|
||||
for (unsigned i = 0; i != Str.length(); ++i)
|
||||
switch (Str[i]) {
|
||||
case '\n':
|
||||
Str.insert(Str.begin()+i, '\\'); // Escape character...
|
||||
++i;
|
||||
Str[i] = 'n';
|
||||
break;
|
||||
case '\t':
|
||||
Str.insert(Str.begin()+i, ' '); // Convert to two spaces
|
||||
++i;
|
||||
Str[i] = ' ';
|
||||
break;
|
||||
case '\\':
|
||||
if (i+1 != Str.length())
|
||||
switch (Str[i+1]) {
|
||||
case 'l': continue; // don't disturb \l
|
||||
case '|': case '{': case '}':
|
||||
Str.erase(Str.begin()+i); continue;
|
||||
default: break;
|
||||
}
|
||||
case '{': case '}':
|
||||
case '<': case '>':
|
||||
case '|': case '"':
|
||||
Str.insert(Str.begin()+i, '\\'); // Escape character...
|
||||
++i; // don't infinite loop
|
||||
break;
|
||||
}
|
||||
return Str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void llvm::DisplayGraph(const sys::Path &Filename, bool wait,
|
||||
GraphProgram::Name program) {
|
||||
std::string ErrMsg;
|
||||
@ -29,13 +62,11 @@ void llvm::DisplayGraph(const sys::Path &Filename, bool wait,
|
||||
args.push_back(Filename.c_str());
|
||||
args.push_back(0);
|
||||
|
||||
cerr << "Running 'Graphviz' program... ";
|
||||
if (sys::Program::ExecuteAndWait(Graphviz, &args[0],0,0,0,0,&ErrMsg)) {
|
||||
cerr << "Error viewing graph " << Filename << ": " << ErrMsg << "\n";
|
||||
}
|
||||
else {
|
||||
errs() << "Running 'Graphviz' program... ";
|
||||
if (sys::Program::ExecuteAndWait(Graphviz, &args[0],0,0,0,0,&ErrMsg))
|
||||
errs() << "Error viewing graph " << Filename << ": " << ErrMsg << "\n";
|
||||
else
|
||||
Filename.eraseFromDisk();
|
||||
}
|
||||
|
||||
#elif (HAVE_GV && (HAVE_DOT || HAVE_FDP || HAVE_NEATO || \
|
||||
HAVE_TWOPI || HAVE_CIRCO))
|
||||
@ -98,12 +129,12 @@ void llvm::DisplayGraph(const sys::Path &Filename, bool wait,
|
||||
args.push_back(PSFilename.c_str());
|
||||
args.push_back(0);
|
||||
|
||||
cerr << "Running '" << prog << "' program... ";
|
||||
errs() << "Running '" << prog << "' program... ";
|
||||
|
||||
if (sys::Program::ExecuteAndWait(prog, &args[0],0,0,0,0,&ErrMsg)) {
|
||||
cerr << "Error viewing graph " << Filename << ": '" << ErrMsg << "\n";
|
||||
errs() << "Error viewing graph " << Filename << ": '" << ErrMsg << "\n";
|
||||
} else {
|
||||
cerr << " done. \n";
|
||||
errs() << " done. \n";
|
||||
|
||||
sys::Path gv(LLVM_PATH_GV);
|
||||
args.clear();
|
||||
@ -114,15 +145,15 @@ void llvm::DisplayGraph(const sys::Path &Filename, bool wait,
|
||||
|
||||
ErrMsg.clear();
|
||||
if (wait) {
|
||||
if (sys::Program::ExecuteAndWait(gv, &args[0],0,0,0,0,&ErrMsg)) {
|
||||
cerr << "Error viewing graph: " << ErrMsg << "\n";
|
||||
}
|
||||
if (sys::Program::ExecuteAndWait(gv, &args[0],0,0,0,0,&ErrMsg))
|
||||
errs() << "Error viewing graph: " << ErrMsg << "\n";
|
||||
Filename.eraseFromDisk();
|
||||
PSFilename.eraseFromDisk();
|
||||
}
|
||||
else {
|
||||
sys::Program::ExecuteNoWait(gv, &args[0],0,0,0,&ErrMsg);
|
||||
cerr << "Remember to erase graph files: " << Filename << " " << PSFilename << "\n";
|
||||
errs() << "Remember to erase graph files: " << Filename << " "
|
||||
<< PSFilename << "\n";
|
||||
}
|
||||
}
|
||||
#elif HAVE_DOTTY
|
||||
@ -133,9 +164,9 @@ void llvm::DisplayGraph(const sys::Path &Filename, bool wait,
|
||||
args.push_back(Filename.c_str());
|
||||
args.push_back(0);
|
||||
|
||||
cerr << "Running 'dotty' program... ";
|
||||
errs() << "Running 'dotty' program... ";
|
||||
if (sys::Program::ExecuteAndWait(dotty, &args[0],0,0,0,0,&ErrMsg)) {
|
||||
cerr << "Error viewing graph " << Filename << ": " << ErrMsg << "\n";
|
||||
errs() << "Error viewing graph " << Filename << ": " << ErrMsg << "\n";
|
||||
} else {
|
||||
#ifdef __MINGW32__ // Dotty spawns another app and doesn't wait until it returns
|
||||
return;
|
||||
|
@ -193,8 +193,8 @@ void BlockExtractorPass::LoadFile(const char *Filename) {
|
||||
// Load the BlockFile...
|
||||
std::ifstream In(Filename);
|
||||
if (!In.good()) {
|
||||
cerr << "WARNING: BlockExtractor couldn't load file '" << Filename
|
||||
<< "'!\n";
|
||||
errs() << "WARNING: BlockExtractor couldn't load file '" << Filename
|
||||
<< "'!\n";
|
||||
return;
|
||||
}
|
||||
while (In) {
|
||||
|
Loading…
Reference in New Issue
Block a user