[llvm-commits] [llvm] r79836 - in /llvm/trunk: include/llvm/Analysis/LoopInfo.h include/llvm/Support/Casting.h include/llvm/Support/GraphWriter.h lib/Analysis/CFGPrinter.cpp lib/Analysis/LoopPass.cpp lib/CodeGen/AsmPrinter/AsmPrinter.cpp lib/CodeGen/PostRASchedulerList.cpp lib/CompilerDriver/CompilationGraph.cpp lib/Support/GraphWriter.cpp lib/Transforms/IPO/LoopExtractor.cpp
Chris Lattner
sabre at nondot.org
Sun Aug 23 00:19:13 PDT 2009
Author: lattner
Date: Sun Aug 23 02:19:13 2009
New Revision: 79836
URL: http://llvm.org/viewvc/llvm-project?rev=79836&view=rev
Log:
convert LoopInfo.h and GraphWriter.h to use raw_ostream
Modified:
llvm/trunk/include/llvm/Analysis/LoopInfo.h
llvm/trunk/include/llvm/Support/Casting.h
llvm/trunk/include/llvm/Support/GraphWriter.h
llvm/trunk/lib/Analysis/CFGPrinter.cpp
llvm/trunk/lib/Analysis/LoopPass.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/trunk/lib/CodeGen/PostRASchedulerList.cpp
llvm/trunk/lib/CompilerDriver/CompilationGraph.cpp
llvm/trunk/lib/Support/GraphWriter.cpp
llvm/trunk/lib/Transforms/IPO/LoopExtractor.cpp
Modified: llvm/trunk/include/llvm/Analysis/LoopInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopInfo.h?rev=79836&r1=79835&r2=79836&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/LoopInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/LoopInfo.h Sun Aug 23 02:19:13 2009
@@ -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 {
Modified: llvm/trunk/include/llvm/Support/Casting.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Casting.h?rev=79836&r1=79835&r2=79836&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Casting.h (original)
+++ llvm/trunk/include/llvm/Support/Casting.h Sun Aug 23 02:19:13 2009
@@ -235,7 +235,7 @@
#ifdef DEBUG_CAST_OPERATORS
-#include "llvm/Support/Streams.h"
+#include "llvm/Support/raw_ostream.h"
struct bar {
bar() {}
@@ -251,7 +251,7 @@
};
template <> inline bool isa_impl<foo,bar>(const bar &Val) {
- cerr << "Classof: " << &Val << "\n";
+ errs() << "Classof: " << &Val << "\n";
return true;
}
Modified: llvm/trunk/include/llvm/Support/GraphWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/GraphWriter.h?rev=79836&r1=79835&r2=79836&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/GraphWriter.h (original)
+++ llvm/trunk/include/llvm/Support/GraphWriter.h Sun Aug 23 02:19:13 2009
@@ -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 @@
template<typename GraphType>
class GraphWriter {
- std::ostream &O;
+ raw_ostream &O;
const GraphType &G;
bool ShortNames;
@@ -91,7 +60,7 @@
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 @@
};
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 @@
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();
}
Modified: llvm/trunk/lib/Analysis/CFGPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/CFGPrinter.cpp?rev=79836&r1=79835&r2=79836&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/CFGPrinter.cpp (original)
+++ llvm/trunk/lib/Analysis/CFGPrinter.cpp Sun Aug 23 02:19:13 2009
@@ -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 @@
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 @@
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 {}
Modified: llvm/trunk/lib/Analysis/LoopPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopPass.cpp?rev=79836&r1=79835&r2=79836&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LoopPass.cpp (original)
+++ llvm/trunk/lib/Analysis/LoopPass.cpp Sun Aug 23 02:19:13 2009
@@ -272,7 +272,7 @@
/// 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);
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=79836&r1=79835&r2=79836&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Sun Aug 23 02:19:13 2009
@@ -1724,7 +1724,7 @@
return GMP;
}
- cerr << "no GCMetadataPrinter registered for GC: " << Name << "\n";
+ errs() << "no GCMetadataPrinter registered for GC: " << Name << "\n";
llvm_unreachable(0);
}
Modified: llvm/trunk/lib/CodeGen/PostRASchedulerList.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/PostRASchedulerList.cpp?rev=79836&r1=79835&r2=79836&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/PostRASchedulerList.cpp (original)
+++ llvm/trunk/lib/CodeGen/PostRASchedulerList.cpp Sun Aug 23 02:19:13 2009
@@ -765,9 +765,9 @@
#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
Modified: llvm/trunk/lib/CompilerDriver/CompilationGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CompilerDriver/CompilationGraph.cpp?rev=79836&r1=79835&r2=79836&view=diff
==============================================================================
--- llvm/trunk/lib/CompilerDriver/CompilationGraph.cpp (original)
+++ llvm/trunk/lib/CompilerDriver/CompilationGraph.cpp Sun Aug 23 02:19:13 2009
@@ -514,13 +514,13 @@
}
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
Modified: llvm/trunk/lib/Support/GraphWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/GraphWriter.cpp?rev=79836&r1=79835&r2=79836&view=diff
==============================================================================
--- llvm/trunk/lib/Support/GraphWriter.cpp (original)
+++ llvm/trunk/lib/Support/GraphWriter.cpp Sun Aug 23 02:19:13 2009
@@ -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 @@
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 @@
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 @@
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 @@
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;
Modified: llvm/trunk/lib/Transforms/IPO/LoopExtractor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/LoopExtractor.cpp?rev=79836&r1=79835&r2=79836&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/LoopExtractor.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/LoopExtractor.cpp Sun Aug 23 02:19:13 2009
@@ -193,8 +193,8 @@
// 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) {
More information about the llvm-commits
mailing list