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
diff --git a/tools/bugpoint/BugDriver.cpp b/tools/bugpoint/BugDriver.cpp
index ac5de15..0934206 100644
--- a/tools/bugpoint/BugDriver.cpp
+++ b/tools/bugpoint/BugDriver.cpp
@@ -25,7 +25,6 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/raw_ostream.h"
-#include <iostream>
#include <memory>
using namespace llvm;
@@ -107,14 +106,14 @@
if (Program == 0) return true;
if (!run_as_child)
- std::cout << "Read input file : '" << Filenames[0] << "'\n";
+ outs() << "Read input file : '" << Filenames[0] << "'\n";
for (unsigned i = 1, e = Filenames.size(); i != e; ++i) {
std::auto_ptr<Module> M(ParseInputFile(Filenames[i], Context));
if (M.get() == 0) return true;
if (!run_as_child)
- std::cout << "Linking in input file: '" << Filenames[i] << "'\n";
+ outs() << "Linking in input file: '" << Filenames[i] << "'\n";
std::string ErrorMessage;
if (Linker::LinkModules(Program, M.get(), &ErrorMessage)) {
errs() << ToolName << ": error linking in '" << Filenames[i] << "': "
@@ -128,7 +127,7 @@
}
if (!run_as_child)
- std::cout << "*** All input ok\n";
+ outs() << "*** All input ok\n";
// All input files read successfully!
return false;
@@ -162,7 +161,7 @@
// file, then we know the compiler didn't crash, so try to diagnose a
// miscompilation.
if (!PassesToRun.empty()) {
- std::cout << "Running selected passes on program to test for crash: ";
+ outs() << "Running selected passes on program to test for crash: ";
if (runPasses(PassesToRun))
return debugOptimizerCrash();
}
@@ -171,12 +170,12 @@
if (initializeExecutionEnvironment()) return true;
// Test to see if we have a code generator crash.
- std::cout << "Running the code generator to test for a crash: ";
+ outs() << "Running the code generator to test for a crash: ";
try {
compileProgram(Program);
- std::cout << '\n';
+ outs() << '\n';
} catch (ToolExecutionError &TEE) {
- std::cout << TEE.what();
+ outs() << TEE.what();
return debugCodeGeneratorCrash();
}
@@ -187,7 +186,7 @@
//
bool CreatedOutput = false;
if (ReferenceOutputFile.empty()) {
- std::cout << "Generating reference output from raw program: ";
+ outs() << "Generating reference output from raw program: ";
if(!createReferenceFile(Program)){
return debugCodeGeneratorCrash();
}
@@ -202,10 +201,10 @@
// Diff the output of the raw program against the reference output. If it
// matches, then we assume there is a miscompilation bug and try to
// diagnose it.
- std::cout << "*** Checking the code generator...\n";
+ outs() << "*** Checking the code generator...\n";
try {
if (!diffProgram()) {
- std::cout << "\n*** Output matches: Debugging miscompilation!\n";
+ outs() << "\n*** Output matches: Debugging miscompilation!\n";
return debugMiscompilation();
}
} catch (ToolExecutionError &TEE) {
@@ -213,8 +212,8 @@
return debugCodeGeneratorCrash();
}
- std::cout << "\n*** Input program does not match reference diff!\n";
- std::cout << "Debugging code generator problem!\n";
+ outs() << "\n*** Input program does not match reference diff!\n";
+ outs() << "Debugging code generator problem!\n";
try {
return debugCodeGenerator();
} catch (ToolExecutionError &TEE) {
@@ -227,18 +226,18 @@
unsigned NumPrint = Funcs.size();
if (NumPrint > 10) NumPrint = 10;
for (unsigned i = 0; i != NumPrint; ++i)
- std::cout << " " << Funcs[i]->getName();
+ outs() << " " << Funcs[i]->getName();
if (NumPrint < Funcs.size())
- std::cout << "... <" << Funcs.size() << " total>";
- std::cout << std::flush;
+ outs() << "... <" << Funcs.size() << " total>";
+ outs().flush();
}
void llvm::PrintGlobalVariableList(const std::vector<GlobalVariable*> &GVs) {
unsigned NumPrint = GVs.size();
if (NumPrint > 10) NumPrint = 10;
for (unsigned i = 0; i != NumPrint; ++i)
- std::cout << " " << GVs[i]->getName();
+ outs() << " " << GVs[i]->getName();
if (NumPrint < GVs.size())
- std::cout << "... <" << GVs.size() << " total>";
- std::cout << std::flush;
+ outs() << "... <" << GVs.size() << " total>";
+ outs().flush();
}
diff --git a/tools/bugpoint/BugDriver.h b/tools/bugpoint/BugDriver.h
index d637c24..a462635 100644
--- a/tools/bugpoint/BugDriver.h
+++ b/tools/bugpoint/BugDriver.h
@@ -248,7 +248,7 @@
/// optimizations fail for some reason (optimizer crashes), return true,
/// otherwise return false. If DeleteOutput is set to true, the bitcode is
/// deleted on success, and the filename string is undefined. This prints to
- /// cout a single line message indicating whether compilation was successful
+ /// outs() a single line message indicating whether compilation was successful
/// or failed, unless Quiet is set. ExtraArgs specifies additional arguments
/// to pass to the child bugpoint instance.
///
diff --git a/tools/bugpoint/CrashDebugger.cpp b/tools/bugpoint/CrashDebugger.cpp
index 34efdc1..4e73b8f 100644
--- a/tools/bugpoint/CrashDebugger.cpp
+++ b/tools/bugpoint/CrashDebugger.cpp
@@ -28,8 +28,6 @@
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/CommandLine.h"
-#include <iostream>
-#include <fstream>
#include <set>
using namespace llvm;
@@ -65,8 +63,8 @@
sys::Path PrefixOutput;
Module *OrigProgram = 0;
if (!Prefix.empty()) {
- std::cout << "Checking to see if these passes crash: "
- << getPassesString(Prefix) << ": ";
+ outs() << "Checking to see if these passes crash: "
+ << getPassesString(Prefix) << ": ";
std::string PfxOutput;
if (BD.runPasses(Prefix, PfxOutput))
return KeepPrefix;
@@ -83,8 +81,8 @@
PrefixOutput.eraseFromDisk();
}
- std::cout << "Checking to see if these passes crash: "
- << getPassesString(Suffix) << ": ";
+ outs() << "Checking to see if these passes crash: "
+ << getPassesString(Suffix) << ": ";
if (BD.runPasses(Suffix)) {
delete OrigProgram; // The suffix crashes alone...
@@ -143,9 +141,9 @@
GVSet.insert(CMGV);
}
- std::cout << "Checking for crash with only these global variables: ";
+ outs() << "Checking for crash with only these global variables: ";
PrintGlobalVariableList(GVs);
- std::cout << ": ";
+ outs() << ": ";
// Loop over and delete any global variables which we aren't supposed to be
// playing with...
@@ -217,9 +215,9 @@
Functions.insert(CMF);
}
- std::cout << "Checking for crash with only these functions: ";
+ outs() << "Checking for crash with only these functions: ";
PrintFunctionList(Funcs);
- std::cout << ": ";
+ outs() << ": ";
// Loop over and delete any functions which we aren't supposed to be playing
// with...
@@ -277,14 +275,14 @@
for (unsigned i = 0, e = BBs.size(); i != e; ++i)
Blocks.insert(cast<BasicBlock>(ValueMap[BBs[i]]));
- std::cout << "Checking for crash with only these blocks:";
+ outs() << "Checking for crash with only these blocks:";
unsigned NumPrint = Blocks.size();
if (NumPrint > 10) NumPrint = 10;
for (unsigned i = 0, e = NumPrint; i != e; ++i)
- std::cout << " " << BBs[i]->getName();
+ outs() << " " << BBs[i]->getName();
if (NumPrint < Blocks.size())
- std::cout << "... <" << Blocks.size() << " total>";
- std::cout << ": ";
+ outs() << "... <" << Blocks.size() << " total>";
+ outs() << ": ";
// Loop over and delete any hack up any blocks that are not listed...
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
@@ -382,11 +380,11 @@
Instructions.insert(cast<Instruction>(ValueMap[Insts[i]]));
}
- std::cout << "Checking for crash with only " << Instructions.size();
+ outs() << "Checking for crash with only " << Instructions.size();
if (Instructions.size() == 1)
- std::cout << " instruction: ";
+ outs() << " instruction: ";
else
- std::cout << " instructions: ";
+ outs() << " instructions: ";
for (Module::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI)
for (Function::iterator FI = MI->begin(), FE = MI->end(); FI != FE; ++FI)
@@ -445,13 +443,13 @@
delete M; // No change made...
} else {
// See if the program still causes a crash...
- std::cout << "\nChecking to see if we can delete global inits: ";
+ outs() << "\nChecking to see if we can delete global inits: ";
if (TestFn(BD, M)) { // Still crashes?
BD.setNewProgram(M);
- std::cout << "\n*** Able to remove all global initializers!\n";
+ outs() << "\n*** Able to remove all global initializers!\n";
} else { // No longer crashes?
- std::cout << " - Removing all global inits hides problem!\n";
+ outs() << " - Removing all global inits hides problem!\n";
delete M;
std::vector<GlobalVariable*> GVs;
@@ -462,7 +460,7 @@
GVs.push_back(I);
if (GVs.size() > 1 && !BugpointIsInterrupted) {
- std::cout << "\n*** Attempting to reduce the number of global "
+ outs() << "\n*** Attempting to reduce the number of global "
<< "variables in the testcase\n";
unsigned OldSize = GVs.size();
@@ -483,7 +481,7 @@
Functions.push_back(I);
if (Functions.size() > 1 && !BugpointIsInterrupted) {
- std::cout << "\n*** Attempting to reduce the number of functions "
+ outs() << "\n*** Attempting to reduce the number of functions "
"in the testcase\n";
unsigned OldSize = Functions.size();
@@ -532,8 +530,8 @@
do {
if (BugpointIsInterrupted) break;
--Simplification;
- std::cout << "\n*** Attempting to reduce testcase by deleting instruc"
- << "tions: Simplification Level #" << Simplification << '\n';
+ outs() << "\n*** Attempting to reduce testcase by deleting instruc"
+ << "tions: Simplification Level #" << Simplification << '\n';
// Now that we have deleted the functions that are unnecessary for the
// program, try to remove instructions that are not necessary to cause the
@@ -561,7 +559,7 @@
} else {
if (BugpointIsInterrupted) goto ExitLoops;
- std::cout << "Checking instruction: " << *I;
+ outs() << "Checking instruction: " << *I;
Module *M = BD.deleteInstructionFromProgram(I, Simplification);
// Find out if the pass still crashes on this pass...
@@ -588,7 +586,7 @@
// Try to clean up the testcase by running funcresolve and globaldce...
if (!BugpointIsInterrupted) {
- std::cout << "\n*** Attempting to perform final cleanups: ";
+ outs() << "\n*** Attempting to perform final cleanups: ";
Module *M = CloneModule(BD.getProgram());
M = BD.performFinalCleanups(M, true);
@@ -614,15 +612,15 @@
/// out exactly which pass is crashing.
///
bool BugDriver::debugOptimizerCrash(const std::string &ID) {
- std::cout << "\n*** Debugging optimizer crash!\n";
+ outs() << "\n*** Debugging optimizer crash!\n";
// Reduce the list of passes which causes the optimizer to crash...
if (!BugpointIsInterrupted)
ReducePassList(*this).reduceList(PassesToRun);
- std::cout << "\n*** Found crashing pass"
- << (PassesToRun.size() == 1 ? ": " : "es: ")
- << getPassesString(PassesToRun) << '\n';
+ outs() << "\n*** Found crashing pass"
+ << (PassesToRun.size() == 1 ? ": " : "es: ")
+ << getPassesString(PassesToRun) << '\n';
EmitProgressBitcode(ID);
diff --git a/tools/bugpoint/ExecutionDriver.cpp b/tools/bugpoint/ExecutionDriver.cpp
index 6e5b7a0..7fd01ef 100644
--- a/tools/bugpoint/ExecutionDriver.cpp
+++ b/tools/bugpoint/ExecutionDriver.cpp
@@ -19,7 +19,6 @@
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/SystemUtils.h"
#include <fstream>
-#include <iostream>
using namespace llvm;
@@ -126,7 +125,7 @@
/// environment for executing LLVM programs.
///
bool BugDriver::initializeExecutionEnvironment() {
- std::cout << "Initializing execution environment: ";
+ outs() << "Initializing execution environment: ";
// Create an instance of the AbstractInterpreter interface as specified on
// the command line
@@ -188,7 +187,7 @@
if (!Interpreter)
errs() << Message;
else // Display informational messages on stdout instead of stderr
- std::cout << Message;
+ outs() << Message;
std::string Path = SafeInterpreterPath;
if (Path.empty())
@@ -260,10 +259,10 @@
"\"safe\" backend right now!\n";
break;
}
- if (!SafeInterpreter) { std::cout << Message << "\nExiting.\n"; exit(1); }
+ if (!SafeInterpreter) { outs() << Message << "\nExiting.\n"; exit(1); }
gcc = GCC::create(getToolName(), Message, &GCCToolArgv);
- if (!gcc) { std::cout << Message << "\nExiting.\n"; exit(1); }
+ if (!gcc) { outs() << Message << "\nExiting.\n"; exit(1); }
// If there was an error creating the selected interpreter, quit with error.
return Interpreter == 0;
@@ -355,7 +354,7 @@
errs() << "<timeout>";
static bool FirstTimeout = true;
if (FirstTimeout) {
- std::cout << "\n"
+ outs() << "\n"
"*** Program execution timed out! This mechanism is designed to handle\n"
" programs stuck in infinite loops gracefully. The -timeout option\n"
" can be used to change the timeout threshold or disable it completely\n"
@@ -418,7 +417,7 @@
}
try {
ReferenceOutputFile = executeProgramSafely(Filename);
- std::cout << "\nReference output is: " << ReferenceOutputFile << "\n\n";
+ outs() << "\nReference output is: " << ReferenceOutputFile << "\n\n";
} catch (ToolExecutionError &TEE) {
errs() << TEE.what();
if (Interpreter != SafeInterpreter) {
diff --git a/tools/bugpoint/ExtractFunction.cpp b/tools/bugpoint/ExtractFunction.cpp
index 7bdba50..a939f99 100644
--- a/tools/bugpoint/ExtractFunction.cpp
+++ b/tools/bugpoint/ExtractFunction.cpp
@@ -32,8 +32,6 @@
#include "llvm/System/Path.h"
#include "llvm/System/Signals.h"
#include <set>
-#include <fstream>
-#include <iostream>
using namespace llvm;
namespace llvm {
@@ -145,9 +143,9 @@
Module *NewM = runPassesOn(M, LoopExtractPasses);
if (NewM == 0) {
Module *Old = swapProgramIn(M);
- std::cout << "*** Loop extraction failed: ";
+ outs() << "*** Loop extraction failed: ";
EmitProgressBitcode("loopextraction", true);
- std::cout << "*** Sorry. :( Please report a bug!\n";
+ outs() << "*** Sorry. :( Please report a bug!\n";
swapProgramIn(Old);
return 0;
}
@@ -327,7 +325,7 @@
sys::Path uniqueFilename("bugpoint-extractblocks");
std::string ErrMsg;
if (uniqueFilename.createTemporaryFileOnDisk(true, &ErrMsg)) {
- std::cout << "*** Basic Block extraction failed!\n";
+ outs() << "*** Basic Block extraction failed!\n";
errs() << "Error creating temporary file: " << ErrMsg << "\n";
M = swapProgramIn(M);
EmitProgressBitcode("basicblockextractfail", true);
@@ -336,10 +334,13 @@
}
sys::RemoveFileOnSignal(uniqueFilename);
- std::ofstream BlocksToNotExtractFile(uniqueFilename.c_str());
- if (!BlocksToNotExtractFile) {
- std::cout << "*** Basic Block extraction failed!\n";
- errs() << "Error writing list of blocks to not extract: " << ErrMsg
+ std::string ErrorInfo;
+ raw_fd_ostream BlocksToNotExtractFile(uniqueFilename.c_str(),
+ /*Binary=*/false, /*Force=*/true,
+ ErrorInfo);
+ if (!ErrorInfo.empty()) {
+ outs() << "*** Basic Block extraction failed!\n";
+ errs() << "Error writing list of blocks to not extract: " << ErrorInfo
<< "\n";
M = swapProgramIn(M);
EmitProgressBitcode("basicblockextractfail", true);
@@ -371,7 +372,7 @@
free(ExtraArg);
if (Ret == 0) {
- std::cout << "*** Basic Block extraction failed, please report a bug!\n";
+ outs() << "*** Basic Block extraction failed, please report a bug!\n";
M = swapProgramIn(M);
EmitProgressBitcode("basicblockextractfail", true);
swapProgramIn(M);
diff --git a/tools/bugpoint/FindBugs.cpp b/tools/bugpoint/FindBugs.cpp
index a28c1b6..fd1f84b 100644
--- a/tools/bugpoint/FindBugs.cpp
+++ b/tools/bugpoint/FindBugs.cpp
@@ -19,7 +19,6 @@
#include "llvm/Pass.h"
#include <algorithm>
#include <ctime>
-#include <iostream>
using namespace llvm;
/// runManyPasses - Take the specified pass list and create different
@@ -31,14 +30,14 @@
///
bool BugDriver::runManyPasses(const std::vector<const PassInfo*> &AllPasses) {
setPassesToRun(AllPasses);
- std::cout << "Starting bug finding procedure...\n\n";
+ outs() << "Starting bug finding procedure...\n\n";
// Creating a reference output if necessary
if (initializeExecutionEnvironment()) return false;
- std::cout << "\n";
+ outs() << "\n";
if (ReferenceOutputFile.empty()) {
- std::cout << "Generating reference output from raw program: \n";
+ outs() << "Generating reference output from raw program: \n";
if (!createReferenceFile(Program))
return false;
}
@@ -55,31 +54,31 @@
//
// Step 2: Run optimizer passes on the program and check for success.
//
- std::cout << "Running selected passes on program to test for crash: ";
+ outs() << "Running selected passes on program to test for crash: ";
for(int i = 0, e = PassesToRun.size(); i != e; i++) {
- std::cout << "-" << PassesToRun[i]->getPassArgument( )<< " ";
+ outs() << "-" << PassesToRun[i]->getPassArgument( )<< " ";
}
std::string Filename;
if(runPasses(PassesToRun, Filename, false)) {
- std::cout << "\n";
- std::cout << "Optimizer passes caused failure!\n\n";
+ outs() << "\n";
+ outs() << "Optimizer passes caused failure!\n\n";
debugOptimizerCrash();
return true;
} else {
- std::cout << "Combination " << num << " optimized successfully!\n";
+ outs() << "Combination " << num << " optimized successfully!\n";
}
//
// Step 3: Compile the optimized code.
//
- std::cout << "Running the code generator to test for a crash: ";
+ outs() << "Running the code generator to test for a crash: ";
try {
compileProgram(Program);
- std::cout << '\n';
+ outs() << '\n';
} catch (ToolExecutionError &TEE) {
- std::cout << "\n*** compileProgram threw an exception: ";
- std::cout << TEE.what();
+ outs() << "\n*** compileProgram threw an exception: ";
+ outs() << TEE.what();
return debugCodeGeneratorCrash();
}
@@ -87,14 +86,14 @@
// Step 4: Run the program and compare its output to the reference
// output (created above).
//
- std::cout << "*** Checking if passes caused miscompliation:\n";
+ outs() << "*** Checking if passes caused miscompliation:\n";
try {
if (diffProgram(Filename, "", false)) {
- std::cout << "\n*** diffProgram returned true!\n";
+ outs() << "\n*** diffProgram returned true!\n";
debugMiscompilation();
return true;
} else {
- std::cout << "\n*** diff'd output matches!\n";
+ outs() << "\n*** diff'd output matches!\n";
}
} catch (ToolExecutionError &TEE) {
errs() << TEE.what();
@@ -104,7 +103,7 @@
sys::Path(Filename).eraseFromDisk();
- std::cout << "\n\n";
+ outs() << "\n\n";
num++;
} //end while
diff --git a/tools/bugpoint/Miscompilation.cpp b/tools/bugpoint/Miscompilation.cpp
index efa2538..83054f3 100644
--- a/tools/bugpoint/Miscompilation.cpp
+++ b/tools/bugpoint/Miscompilation.cpp
@@ -26,7 +26,6 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Config/config.h" // for HAVE_LINK_R
-#include <iostream>
using namespace llvm;
namespace llvm {
@@ -57,8 +56,8 @@
std::vector<const PassInfo*> &Suffix) {
// First, run the program with just the Suffix passes. If it is still broken
// with JUST the kept passes, discard the prefix passes.
- std::cout << "Checking to see if '" << getPassesString(Suffix)
- << "' compiles correctly: ";
+ outs() << "Checking to see if '" << getPassesString(Suffix)
+ << "' compiles correctly: ";
std::string BitcodeResult;
if (BD.runPasses(Suffix, BitcodeResult, false/*delete*/, true/*quiet*/)) {
@@ -71,7 +70,7 @@
// Check to see if the finished program matches the reference output...
if (BD.diffProgram(BitcodeResult, "", true /*delete bitcode*/)) {
- std::cout << " nope.\n";
+ outs() << " nope.\n";
if (Suffix.empty()) {
errs() << BD.getToolName() << ": I'm confused: the test fails when "
<< "no passes are run, nondeterministic program?\n";
@@ -79,14 +78,14 @@
}
return KeepSuffix; // Miscompilation detected!
}
- std::cout << " yup.\n"; // No miscompilation!
+ outs() << " yup.\n"; // No miscompilation!
if (Prefix.empty()) return NoFailure;
// Next, see if the program is broken if we run the "prefix" passes first,
// then separately run the "kept" passes.
- std::cout << "Checking to see if '" << getPassesString(Prefix)
- << "' compiles correctly: ";
+ outs() << "Checking to see if '" << getPassesString(Prefix)
+ << "' compiles correctly: ";
// If it is not broken with the kept passes, it's possible that the prefix
// passes must be run before the kept passes to break it. If the program
@@ -104,11 +103,11 @@
// If the prefix maintains the predicate by itself, only keep the prefix!
if (BD.diffProgram(BitcodeResult)) {
- std::cout << " nope.\n";
+ outs() << " nope.\n";
sys::Path(BitcodeResult).eraseFromDisk();
return KeepPrefix;
}
- std::cout << " yup.\n"; // No miscompilation!
+ outs() << " yup.\n"; // No miscompilation!
// Ok, so now we know that the prefix passes work, try running the suffix
// passes on the result of the prefix passes.
@@ -125,7 +124,7 @@
if (Suffix.empty())
return NoFailure;
- std::cout << "Checking to see if '" << getPassesString(Suffix)
+ outs() << "Checking to see if '" << getPassesString(Suffix)
<< "' passes compile correctly after the '"
<< getPassesString(Prefix) << "' passes: ";
@@ -140,13 +139,13 @@
// Run the result...
if (BD.diffProgram(BitcodeResult, "", true/*delete bitcode*/)) {
- std::cout << " nope.\n";
+ outs() << " nope.\n";
delete OriginalInput; // We pruned down the original input...
return KeepSuffix;
}
// Otherwise, we must not be running the bad pass anymore.
- std::cout << " yup.\n"; // No miscompilation!
+ outs() << " yup.\n"; // No miscompilation!
delete BD.swapProgramIn(OriginalInput); // Restore orig program & free test
return NoFailure;
}
@@ -213,12 +212,12 @@
bool ReduceMiscompilingFunctions::TestFuncs(const std::vector<Function*>&Funcs){
// Test to see if the function is misoptimized if we ONLY run it on the
// functions listed in Funcs.
- std::cout << "Checking to see if the program is misoptimized when "
- << (Funcs.size()==1 ? "this function is" : "these functions are")
- << " run through the pass"
- << (BD.getPassesToRun().size() == 1 ? "" : "es") << ":";
+ outs() << "Checking to see if the program is misoptimized when "
+ << (Funcs.size()==1 ? "this function is" : "these functions are")
+ << " run through the pass"
+ << (BD.getPassesToRun().size() == 1 ? "" : "es") << ":";
PrintFunctionList(Funcs);
- std::cout << '\n';
+ outs() << '\n';
// Split the module into the two halves of the program we want.
DenseMap<const Value*, Value*> ValueMap;
@@ -310,12 +309,12 @@
delete ToOptimize;
BD.switchToInterpreter(AI);
- std::cout << " Testing after loop extraction:\n";
+ outs() << " Testing after loop extraction:\n";
// Clone modules, the tester function will free them.
Module *TOLEBackup = CloneModule(ToOptimizeLoopExtracted);
Module *TNOBackup = CloneModule(ToNotOptimize);
if (!TestFn(BD, ToOptimizeLoopExtracted, ToNotOptimize)) {
- std::cout << "*** Loop extraction masked the problem. Undoing.\n";
+ outs() << "*** Loop extraction masked the problem. Undoing.\n";
// If the program is not still broken, then loop extraction did something
// that masked the error. Stop loop extraction now.
delete TOLEBackup;
@@ -325,7 +324,7 @@
ToOptimizeLoopExtracted = TOLEBackup;
ToNotOptimize = TNOBackup;
- std::cout << "*** Loop extraction successful!\n";
+ outs() << "*** Loop extraction successful!\n";
std::vector<std::pair<std::string, const FunctionType*> > MisCompFunctions;
for (Module::iterator I = ToOptimizeLoopExtracted->begin(),
@@ -394,16 +393,16 @@
bool ReduceMiscompiledBlocks::TestFuncs(const std::vector<BasicBlock*> &BBs) {
// Test to see if the function is misoptimized if we ONLY run it on the
// functions listed in Funcs.
- std::cout << "Checking to see if the program is misoptimized when all ";
+ outs() << "Checking to see if the program is misoptimized when all ";
if (!BBs.empty()) {
- std::cout << "but these " << BBs.size() << " blocks are extracted: ";
+ outs() << "but these " << BBs.size() << " blocks are extracted: ";
for (unsigned i = 0, e = BBs.size() < 10 ? BBs.size() : 10; i != e; ++i)
- std::cout << BBs[i]->getName() << " ";
- if (BBs.size() > 10) std::cout << "...";
+ outs() << BBs[i]->getName() << " ";
+ if (BBs.size() > 10) outs() << "...";
} else {
- std::cout << "blocks are extracted.";
+ outs() << "blocks are extracted.";
}
- std::cout << '\n';
+ outs() << '\n';
// Split the module into the two halves of the program we want.
DenseMap<const Value*, Value*> ValueMap;
@@ -526,11 +525,11 @@
if (!BugpointIsInterrupted)
ReduceMiscompilingFunctions(BD, TestFn).reduceList(MiscompiledFunctions);
- std::cout << "\n*** The following function"
- << (MiscompiledFunctions.size() == 1 ? " is" : "s are")
- << " being miscompiled: ";
+ outs() << "\n*** The following function"
+ << (MiscompiledFunctions.size() == 1 ? " is" : "s are")
+ << " being miscompiled: ";
PrintFunctionList(MiscompiledFunctions);
- std::cout << '\n';
+ outs() << '\n';
// See if we can rip any loops out of the miscompiled functions and still
// trigger the problem.
@@ -549,11 +548,11 @@
if (!BugpointIsInterrupted)
ReduceMiscompilingFunctions(BD, TestFn).reduceList(MiscompiledFunctions);
- std::cout << "\n*** The following function"
- << (MiscompiledFunctions.size() == 1 ? " is" : "s are")
- << " being miscompiled: ";
+ outs() << "\n*** The following function"
+ << (MiscompiledFunctions.size() == 1 ? " is" : "s are")
+ << " being miscompiled: ";
PrintFunctionList(MiscompiledFunctions);
- std::cout << '\n';
+ outs() << '\n';
}
if (!BugpointIsInterrupted &&
@@ -569,11 +568,11 @@
// Do the reduction...
ReduceMiscompilingFunctions(BD, TestFn).reduceList(MiscompiledFunctions);
- std::cout << "\n*** The following function"
- << (MiscompiledFunctions.size() == 1 ? " is" : "s are")
- << " being miscompiled: ";
+ outs() << "\n*** The following function"
+ << (MiscompiledFunctions.size() == 1 ? " is" : "s are")
+ << " being miscompiled: ";
PrintFunctionList(MiscompiledFunctions);
- std::cout << '\n';
+ outs() << '\n';
}
return MiscompiledFunctions;
@@ -586,15 +585,15 @@
static bool TestOptimizer(BugDriver &BD, Module *Test, Module *Safe) {
// Run the optimization passes on ToOptimize, producing a transformed version
// of the functions being tested.
- std::cout << " Optimizing functions being tested: ";
+ outs() << " Optimizing functions being tested: ";
Module *Optimized = BD.runPassesOn(Test, BD.getPassesToRun(),
/*AutoDebugCrashes*/true);
- std::cout << "done.\n";
+ outs() << "done.\n";
delete Test;
- std::cout << " Checking to see if the merged program executes correctly: ";
+ outs() << " Checking to see if the merged program executes correctly: ";
bool Broken = TestMergedProgram(BD, Optimized, Safe, true);
- std::cout << (Broken ? " nope.\n" : " yup.\n");
+ outs() << (Broken ? " nope.\n" : " yup.\n");
return Broken;
}
@@ -612,28 +611,28 @@
return false;
}
- std::cout << "\n*** Found miscompiling pass"
- << (getPassesToRun().size() == 1 ? "" : "es") << ": "
- << getPassesString(getPassesToRun()) << '\n';
+ outs() << "\n*** Found miscompiling pass"
+ << (getPassesToRun().size() == 1 ? "" : "es") << ": "
+ << getPassesString(getPassesToRun()) << '\n';
EmitProgressBitcode("passinput");
std::vector<Function*> MiscompiledFunctions =
DebugAMiscompilation(*this, TestOptimizer);
// Output a bunch of bitcode files for the user...
- std::cout << "Outputting reduced bitcode files which expose the problem:\n";
+ outs() << "Outputting reduced bitcode files which expose the problem:\n";
DenseMap<const Value*, Value*> ValueMap;
Module *ToNotOptimize = CloneModule(getProgram(), ValueMap);
Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
MiscompiledFunctions,
ValueMap);
- std::cout << " Non-optimized portion: ";
+ outs() << " Non-optimized portion: ";
ToNotOptimize = swapProgramIn(ToNotOptimize);
EmitProgressBitcode("tonotoptimize", true);
setNewProgram(ToNotOptimize); // Delete hacked module.
- std::cout << " Portion that is input to optimizer: ";
+ outs() << " Portion that is input to optimizer: ";
ToOptimize = swapProgramIn(ToOptimize);
EmitProgressBitcode("tooptimize");
setNewProgram(ToOptimize); // Delete hacked module.
@@ -860,14 +859,14 @@
bool BugDriver::debugCodeGenerator() {
if ((void*)SafeInterpreter == (void*)Interpreter) {
std::string Result = executeProgramSafely("bugpoint.safe.out");
- std::cout << "\n*** The \"safe\" i.e. 'known good' backend cannot match "
- << "the reference diff. This may be due to a\n front-end "
- << "bug or a bug in the original program, but this can also "
- << "happen if bugpoint isn't running the program with the "
- << "right flags or input.\n I left the result of executing "
- << "the program with the \"safe\" backend in this file for "
- << "you: '"
- << Result << "'.\n";
+ outs() << "\n*** The \"safe\" i.e. 'known good' backend cannot match "
+ << "the reference diff. This may be due to a\n front-end "
+ << "bug or a bug in the original program, but this can also "
+ << "happen if bugpoint isn't running the program with the "
+ << "right flags or input.\n I left the result of executing "
+ << "the program with the \"safe\" backend in this file for "
+ << "you: '"
+ << Result << "'.\n";
return true;
}
@@ -912,31 +911,31 @@
std::string SharedObject = compileSharedObject(SafeModuleBC.toString());
delete ToNotCodeGen;
- std::cout << "You can reproduce the problem with the command line: \n";
+ outs() << "You can reproduce the problem with the command line: \n";
if (isExecutingJIT()) {
- std::cout << " lli -load " << SharedObject << " " << TestModuleBC;
+ outs() << " lli -load " << SharedObject << " " << TestModuleBC;
} else {
- std::cout << " llc -f " << TestModuleBC << " -o " << TestModuleBC<< ".s\n";
- std::cout << " gcc " << SharedObject << " " << TestModuleBC
+ outs() << " llc -f " << TestModuleBC << " -o " << TestModuleBC<< ".s\n";
+ outs() << " gcc " << SharedObject << " " << TestModuleBC
<< ".s -o " << TestModuleBC << ".exe";
#if defined (HAVE_LINK_R)
- std::cout << " -Wl,-R.";
+ outs() << " -Wl,-R.";
#endif
- std::cout << "\n";
- std::cout << " " << TestModuleBC << ".exe";
+ outs() << "\n";
+ outs() << " " << TestModuleBC << ".exe";
}
for (unsigned i=0, e = InputArgv.size(); i != e; ++i)
- std::cout << " " << InputArgv[i];
- std::cout << '\n';
- std::cout << "The shared object was created with:\n llc -march=c "
- << SafeModuleBC << " -o temporary.c\n"
- << " gcc -xc temporary.c -O2 -o " << SharedObject
+ outs() << " " << InputArgv[i];
+ outs() << '\n';
+ outs() << "The shared object was created with:\n llc -march=c "
+ << SafeModuleBC << " -o temporary.c\n"
+ << " gcc -xc temporary.c -O2 -o " << SharedObject
#if defined(sparc) || defined(__sparc__) || defined(__sparcv9)
- << " -G" // Compile a shared library, `-G' for Sparc
+ << " -G" // Compile a shared library, `-G' for Sparc
#else
- << " -fPIC -shared" // `-shared' for Linux/X86, maybe others
+ << " -fPIC -shared" // `-shared' for Linux/X86, maybe others
#endif
- << " -fno-strict-aliasing\n";
+ << " -fno-strict-aliasing\n";
return false;
}
diff --git a/tools/bugpoint/OptimizerDriver.cpp b/tools/bugpoint/OptimizerDriver.cpp
index 741be24..da679cf 100644
--- a/tools/bugpoint/OptimizerDriver.cpp
+++ b/tools/bugpoint/OptimizerDriver.cpp
@@ -27,7 +27,6 @@
#include "llvm/Target/TargetData.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/CommandLine.h"
-#include "llvm/Support/Streams.h"
#include "llvm/System/Path.h"
#include "llvm/System/Program.h"
#include "llvm/Config/alloca.h"
@@ -71,15 +70,15 @@
//
std::string Filename = "bugpoint-" + ID + ".bc";
if (writeProgramToFile(Filename)) {
- cerr << "Error opening file '" << Filename << "' for writing!\n";
+ errs() << "Error opening file '" << Filename << "' for writing!\n";
return;
}
- cout << "Emitted bitcode to '" << Filename << "'\n";
+ outs() << "Emitted bitcode to '" << Filename << "'\n";
if (NoFlyer || PassesToRun.empty()) return;
- cout << "\n*** You can reproduce the problem with: ";
- cout << "opt " << Filename << " ";
- cout << getPassesString(PassesToRun) << "\n";
+ outs() << "\n*** You can reproduce the problem with: ";
+ outs() << "opt " << Filename << " ";
+ outs() << getPassesString(PassesToRun) << "\n";
}
int BugDriver::runPassesAsChild(const std::vector<const PassInfo*> &Passes) {
@@ -88,7 +87,7 @@
std::ios::binary;
std::ofstream OutFile(ChildOutput.c_str(), io_mode);
if (!OutFile.good()) {
- cerr << "Error opening bitcode file: " << ChildOutput << "\n";
+ errs() << "Error opening bitcode file: " << ChildOutput << "\n";
return 1;
}
@@ -100,7 +99,7 @@
if (Passes[i]->getNormalCtor())
PM.add(Passes[i]->getNormalCtor()());
else
- cerr << "Cannot create pass yet: " << Passes[i]->getPassName() << "\n";
+ errs() << "Cannot create pass yet: " << Passes[i]->getPassName() << "\n";
}
// Check that the module is well formed on completion of optimization
PM.add(createVerifierPass());
@@ -121,20 +120,20 @@
/// optimizations fail for some reason (optimizer crashes), return true,
/// otherwise return false. If DeleteOutput is set to true, the bitcode is
/// deleted on success, and the filename string is undefined. This prints to
-/// cout a single line message indicating whether compilation was successful or
-/// failed.
+/// outs() a single line message indicating whether compilation was successful
+/// or failed.
///
bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes,
std::string &OutputFilename, bool DeleteOutput,
bool Quiet, unsigned NumExtraArgs,
const char * const *ExtraArgs) const {
// setup the output file name
- cout << std::flush;
+ outs().flush();
sys::Path uniqueFilename("bugpoint-output.bc");
std::string ErrMsg;
if (uniqueFilename.makeUnique(true, &ErrMsg)) {
- cerr << getToolName() << ": Error making unique filename: "
- << ErrMsg << "\n";
+ errs() << getToolName() << ": Error making unique filename: "
+ << ErrMsg << "\n";
return(1);
}
OutputFilename = uniqueFilename.toString();
@@ -142,15 +141,15 @@
// set up the input file name
sys::Path inputFilename("bugpoint-input.bc");
if (inputFilename.makeUnique(true, &ErrMsg)) {
- cerr << getToolName() << ": Error making unique filename: "
- << ErrMsg << "\n";
+ errs() << getToolName() << ": Error making unique filename: "
+ << ErrMsg << "\n";
return(1);
}
std::ios::openmode io_mode = std::ios::out | std::ios::trunc |
std::ios::binary;
std::ofstream InFile(inputFilename.c_str(), io_mode);
if (!InFile.good()) {
- cerr << "Error opening bitcode file: " << inputFilename << "\n";
+ errs() << "Error opening bitcode file: " << inputFilename << "\n";
return(1);
}
WriteBitcodeToFile(Program, InFile);
@@ -212,17 +211,17 @@
if (!Quiet) {
if (result == 0)
- cout << "Success!\n";
+ outs() << "Success!\n";
else if (result > 0)
- cout << "Exited with error code '" << result << "'\n";
+ outs() << "Exited with error code '" << result << "'\n";
else if (result < 0) {
if (result == -1)
- cout << "Execute failed: " << ErrMsg << "\n";
+ outs() << "Execute failed: " << ErrMsg << "\n";
else
- cout << "Crashed with signal #" << abs(result) << "\n";
+ outs() << "Crashed with signal #" << abs(result) << "\n";
}
if (result & 0x01000000)
- cout << "Dumped core\n";
+ outs() << "Dumped core\n";
}
// Was the child successful?
@@ -242,8 +241,8 @@
if (runPasses(Passes, BitcodeResult, false/*delete*/, true/*quiet*/,
NumExtraArgs, ExtraArgs)) {
if (AutoDebugCrashes) {
- cerr << " Error running this sequence of passes"
- << " on the input program!\n";
+ errs() << " Error running this sequence of passes"
+ << " on the input program!\n";
delete OldProgram;
EmitProgressBitcode("pass-error", false);
exit(debugOptimizerCrash());
@@ -257,8 +256,8 @@
Module *Ret = ParseInputFile(BitcodeResult, Context);
if (Ret == 0) {
- cerr << getToolName() << ": Error reading bitcode file '"
- << BitcodeResult << "'!\n";
+ errs() << getToolName() << ": Error reading bitcode file '"
+ << BitcodeResult << "'!\n";
exit(1);
}
sys::Path(BitcodeResult).eraseFromDisk(); // No longer need the file on disk
diff --git a/tools/bugpoint/bugpoint.cpp b/tools/bugpoint/bugpoint.cpp
index 89ff7a6..9aedd7e 100644
--- a/tools/bugpoint/bugpoint.cpp
+++ b/tools/bugpoint/bugpoint.cpp
@@ -25,7 +25,6 @@
#include "llvm/System/Process.h"
#include "llvm/System/Signals.h"
#include "llvm/LinkAllVMCore.h"
-#include <iostream>
using namespace llvm;
// AsChild - Specifies that this invocation of bugpoint is being generated