summaryrefslogtreecommitdiff
path: root/tools/opt
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-07-16 15:30:09 +0000
committerDan Gohman <gohman@apple.com>2009-07-16 15:30:09 +0000
commitac95cc79ac0b899d566cc29c0f646f39c2fa35c0 (patch)
treea56cfb3fae390064970714d26d13dca84545c1fc /tools/opt
parentad60f660c6fd1999a3e21823128d37aca62e9285 (diff)
downloadllvm-ac95cc79ac0b899d566cc29c0f646f39c2fa35c0.tar.gz
llvm-ac95cc79ac0b899d566cc29c0f646f39c2fa35c0.tar.bz2
llvm-ac95cc79ac0b899d566cc29c0f646f39c2fa35c0.tar.xz
Convert more tools code from cerr and cout to errs() and outs().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76070 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/opt')
-rw-r--r--tools/opt/PrintSCC.cpp24
-rw-r--r--tools/opt/opt.cpp50
2 files changed, 42 insertions, 32 deletions
diff --git a/tools/opt/PrintSCC.cpp b/tools/opt/PrintSCC.cpp
index be652644a6..2d678ed0be 100644
--- a/tools/opt/PrintSCC.cpp
+++ b/tools/opt/PrintSCC.cpp
@@ -29,8 +29,8 @@
#include "llvm/Module.h"
#include "llvm/Analysis/CallGraph.h"
#include "llvm/Support/CFG.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/ADT/SCCIterator.h"
-#include <iostream>
using namespace llvm;
namespace {
@@ -73,18 +73,18 @@ namespace {
bool CFGSCC::runOnFunction(Function &F) {
unsigned sccNum = 0;
- std::cout << "SCCs for Function " << F.getName() << " in PostOrder:";
+ outs() << "SCCs for Function " << F.getName() << " in PostOrder:";
for (scc_iterator<Function*> SCCI = scc_begin(&F),
E = scc_end(&F); SCCI != E; ++SCCI) {
std::vector<BasicBlock*> &nextSCC = *SCCI;
- std::cout << "\nSCC #" << ++sccNum << " : ";
+ outs() << "\nSCC #" << ++sccNum << " : ";
for (std::vector<BasicBlock*>::const_iterator I = nextSCC.begin(),
E = nextSCC.end(); I != E; ++I)
- std::cout << (*I)->getName() << ", ";
+ outs() << (*I)->getName() << ", ";
if (nextSCC.size() == 1 && SCCI.hasLoop())
- std::cout << " (Has self-loop).";
+ outs() << " (Has self-loop).";
}
- std::cout << "\n";
+ outs() << "\n";
return true;
}
@@ -94,19 +94,19 @@ bool CFGSCC::runOnFunction(Function &F) {
bool CallGraphSCC::runOnModule(Module &M) {
CallGraphNode* rootNode = getAnalysis<CallGraph>().getRoot();
unsigned sccNum = 0;
- std::cout << "SCCs for the program in PostOrder:";
+ outs() << "SCCs for the program in PostOrder:";
for (scc_iterator<CallGraphNode*> SCCI = scc_begin(rootNode),
E = scc_end(rootNode); SCCI != E; ++SCCI) {
const std::vector<CallGraphNode*> &nextSCC = *SCCI;
- std::cout << "\nSCC #" << ++sccNum << " : ";
+ outs() << "\nSCC #" << ++sccNum << " : ";
for (std::vector<CallGraphNode*>::const_iterator I = nextSCC.begin(),
E = nextSCC.end(); I != E; ++I)
- std::cout << ((*I)->getFunction() ? (*I)->getFunction()->getName()
- : std::string("Indirect CallGraph node")) << ", ";
+ outs() << ((*I)->getFunction() ? (*I)->getFunction()->getName()
+ : std::string("Indirect CallGraph node")) << ", ";
if (nextSCC.size() == 1 && SCCI.hasLoop())
- std::cout << " (Has self-loop).";
+ outs() << " (Has self-loop).";
}
- std::cout << "\n";
+ outs() << "\n";
return true;
}
diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp
index fd86d0dffb..abfeace376 100644
--- a/tools/opt/opt.cpp
+++ b/tools/opt/opt.cpp
@@ -30,7 +30,6 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PluginLoader.h"
#include "llvm/Support/StandardPasses.h"
-#include "llvm/Support/Streams.h"
#include "llvm/Support/SystemUtils.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/LinkAllPasses.h"
@@ -126,12 +125,15 @@ struct CallGraphSCCPassPrinter : public CallGraphSCCPass {
virtual bool runOnSCC(const std::vector<CallGraphNode *>&SCC) {
if (!Quiet) {
- cout << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
+ outs() << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
for (unsigned i = 0, e = SCC.size(); i != e; ++i) {
Function *F = SCC[i]->getFunction();
- if (F)
+ if (F) {
+ outs().flush();
getAnalysisID<Pass>(PassToPrint).print(cout, F->getParent());
+ cout << std::flush;
+ }
}
}
// Get and print pass...
@@ -156,8 +158,10 @@ struct ModulePassPrinter : public ModulePass {
virtual bool runOnModule(Module &M) {
if (!Quiet) {
- cout << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
+ outs() << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
+ outs().flush();
getAnalysisID<Pass>(PassToPrint).print(cout, &M);
+ cout << std::flush;
}
// Get and print pass...
@@ -181,11 +185,13 @@ struct FunctionPassPrinter : public FunctionPass {
virtual bool runOnFunction(Function &F) {
if (!Quiet) {
- cout << "Printing analysis '" << PassToPrint->getPassName()
- << "' for function '" << F.getName() << "':\n";
+ outs() << "Printing analysis '" << PassToPrint->getPassName()
+ << "' for function '" << F.getName() << "':\n";
}
// Get and print pass...
+ outs().flush();
getAnalysisID<Pass>(PassToPrint).print(cout, F.getParent());
+ cout << std::flush;
return false;
}
@@ -207,9 +213,11 @@ struct LoopPassPrinter : public LoopPass {
virtual bool runOnLoop(Loop *L, LPPassManager &LPM) {
if (!Quiet) {
- cout << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
- getAnalysisID<Pass>(PassToPrint).print(cout,
+ outs() << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
+ outs().flush();
+ getAnalysisID<Pass>(PassToPrint).print(cout,
L->getHeader()->getParent()->getParent());
+ cout << std::flush;
}
// Get and print pass...
return false;
@@ -233,12 +241,14 @@ struct BasicBlockPassPrinter : public BasicBlockPass {
virtual bool runOnBasicBlock(BasicBlock &BB) {
if (!Quiet) {
- cout << "Printing Analysis info for BasicBlock '" << BB.getName()
- << "': Pass " << PassToPrint->getPassName() << ":\n";
+ outs() << "Printing Analysis info for BasicBlock '" << BB.getName()
+ << "': Pass " << PassToPrint->getPassName() << ":\n";
}
// Get and print pass...
+ outs().flush();
getAnalysisID<Pass>(PassToPrint).print(cout, BB.getParent()->getParent());
+ cout << std::flush;
return false;
}
@@ -330,16 +340,16 @@ int main(int argc, char **argv) {
}
if (M.get() == 0) {
- cerr << argv[0] << ": ";
+ errs() << argv[0] << ": ";
if (ErrorMessage.size())
- cerr << ErrorMessage << "\n";
+ errs() << ErrorMessage << "\n";
else
- cerr << "bitcode didn't read correctly.\n";
+ errs() << "bitcode didn't read correctly.\n";
return 1;
}
// Figure out what stream we are supposed to write to...
- // FIXME: cout is not binary!
+ // FIXME: outs() is not binary!
raw_ostream *Out = &outs(); // Default to printing to stdout...
if (OutputFilename != "-") {
std::string ErrorInfo;
@@ -414,8 +424,8 @@ int main(int argc, char **argv) {
if (PassInf->getNormalCtor())
P = PassInf->getNormalCtor()();
else
- cerr << argv[0] << ": cannot create pass: "
- << PassInf->getPassName() << "\n";
+ errs() << argv[0] << ": cannot create pass: "
+ << PassInf->getPassName() << "\n";
if (P) {
bool isBBPass = dynamic_cast<BasicBlockPass*>(P) != 0;
bool isLPass = !isBBPass && dynamic_cast<LoopPass*>(P) != 0;
@@ -470,22 +480,22 @@ int main(int argc, char **argv) {
if (!NoVerify && !VerifyEach)
Passes.add(createVerifierPass());
- // Write bitcode out to disk or cout as the last step...
+ // Write bitcode out to disk or outs() as the last step...
if (!NoOutput && !AnalyzeOnly)
Passes.add(createBitcodeWriterPass(*Out));
// Now that we have all of the passes ready, run them.
Passes.run(*M.get());
- // Delete the ofstream.
+ // Delete the raw_fd_ostream.
if (Out != &outs())
delete Out;
return 0;
} catch (const std::string& msg) {
- cerr << argv[0] << ": " << msg << "\n";
+ errs() << argv[0] << ": " << msg << "\n";
} catch (...) {
- cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
+ errs() << argv[0] << ": Unexpected unknown exception occurred.\n";
}
llvm_shutdown();
return 1;