Add a Program argument to diffProgram to avoid a use of swapProgramIn.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@109859 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2010-07-30 14:19:00 +00:00
parent e099eba206
commit 10757dd8e1
5 changed files with 32 additions and 22 deletions

View File

@ -211,7 +211,7 @@ bool BugDriver::run(std::string &ErrMsg) {
// matches, then we assume there is a miscompilation bug and try to // matches, then we assume there is a miscompilation bug and try to
// diagnose it. // diagnose it.
outs() << "*** Checking the code generator...\n"; outs() << "*** Checking the code generator...\n";
bool Diff = diffProgram("", "", false, &Error); bool Diff = diffProgram(Program, "", "", false, &Error);
if (!Error.empty()) { if (!Error.empty()) {
errs() << Error; errs() << Error;
return debugCodeGeneratorCrash(ErrMsg); return debugCodeGeneratorCrash(ErrMsg);

View File

@ -174,7 +174,8 @@ public:
/// executeProgram - This method runs "Program", capturing the output of the /// executeProgram - This method runs "Program", capturing the output of the
/// program to a file. A recommended filename may be optionally specified. /// program to a file. A recommended filename may be optionally specified.
/// ///
std::string executeProgram(std::string OutputFilename, std::string executeProgram(const Module *Program,
std::string OutputFilename,
std::string Bitcode, std::string Bitcode,
const std::string &SharedObjects, const std::string &SharedObjects,
AbstractInterpreter *AI, AbstractInterpreter *AI,
@ -185,7 +186,8 @@ public:
/// the code generator (e.g., llc crashes), this will return false and set /// the code generator (e.g., llc crashes), this will return false and set
/// Error. /// Error.
/// ///
std::string executeProgramSafely(std::string OutputFile, std::string *Error); std::string executeProgramSafely(const Module *Program,
std::string OutputFile, std::string *Error);
/// createReferenceFile - calls compileProgram and then records the output /// createReferenceFile - calls compileProgram and then records the output
/// into ReferenceOutputFile. Returns true if reference file created, false /// into ReferenceOutputFile. Returns true if reference file created, false
@ -200,7 +202,8 @@ public:
/// is different, 1 is returned. If there is a problem with the code /// is different, 1 is returned. If there is a problem with the code
/// generator (e.g., llc crashes), this will return -1 and set Error. /// generator (e.g., llc crashes), this will return -1 and set Error.
/// ///
bool diffProgram(const std::string &BitcodeFile = "", bool diffProgram(const Module *Program,
const std::string &BitcodeFile = "",
const std::string &SharedObj = "", const std::string &SharedObj = "",
bool RemoveBitcode = false, bool RemoveBitcode = false,
std::string *Error = 0); std::string *Error = 0);

View File

@ -320,7 +320,8 @@ void BugDriver::compileProgram(Module *M, std::string *Error) {
/// program to a file, returning the filename of the file. A recommended /// program to a file, returning the filename of the file. A recommended
/// filename may be optionally specified. /// filename may be optionally specified.
/// ///
std::string BugDriver::executeProgram(std::string OutputFile, std::string BugDriver::executeProgram(const Module *Program,
std::string OutputFile,
std::string BitcodeFile, std::string BitcodeFile,
const std::string &SharedObj, const std::string &SharedObj,
AbstractInterpreter *AI, AbstractInterpreter *AI,
@ -399,9 +400,10 @@ std::string BugDriver::executeProgram(std::string OutputFile,
/// executeProgramSafely - Used to create reference output with the "safe" /// executeProgramSafely - Used to create reference output with the "safe"
/// backend, if reference output is not provided. /// backend, if reference output is not provided.
/// ///
std::string BugDriver::executeProgramSafely(std::string OutputFile, std::string BugDriver::executeProgramSafely(const Module *Program,
std::string OutputFile,
std::string *Error) { std::string *Error) {
return executeProgram(OutputFile, "", "", SafeInterpreter, Error); return executeProgram(Program, OutputFile, "", "", SafeInterpreter, Error);
} }
std::string BugDriver::compileSharedObject(const std::string &BitcodeFile, std::string BugDriver::compileSharedObject(const std::string &BitcodeFile,
@ -440,7 +442,7 @@ bool BugDriver::createReferenceFile(Module *M, const std::string &Filename) {
if (!Error.empty()) if (!Error.empty())
return false; return false;
ReferenceOutputFile = executeProgramSafely(Filename, &Error); ReferenceOutputFile = executeProgramSafely(Program, Filename, &Error);
if (!Error.empty()) { if (!Error.empty()) {
errs() << Error; errs() << Error;
if (Interpreter != SafeInterpreter) { if (Interpreter != SafeInterpreter) {
@ -460,12 +462,14 @@ bool BugDriver::createReferenceFile(Module *M, const std::string &Filename) {
/// is different, 1 is returned. If there is a problem with the code /// is different, 1 is returned. If there is a problem with the code
/// generator (e.g., llc crashes), this will return -1 and set Error. /// generator (e.g., llc crashes), this will return -1 and set Error.
/// ///
bool BugDriver::diffProgram(const std::string &BitcodeFile, bool BugDriver::diffProgram(const Module *Program,
const std::string &BitcodeFile,
const std::string &SharedObject, const std::string &SharedObject,
bool RemoveBitcode, bool RemoveBitcode,
std::string *ErrMsg) { std::string *ErrMsg) {
// Execute the program, generating an output file... // Execute the program, generating an output file...
sys::Path Output(executeProgram("", BitcodeFile, SharedObject, 0, ErrMsg)); sys::Path Output(executeProgram(Program, "", BitcodeFile, SharedObject, 0,
ErrMsg));
if (!ErrMsg->empty()) if (!ErrMsg->empty())
return false; return false;

View File

@ -89,7 +89,7 @@ bool BugDriver::runManyPasses(const std::vector<const PassInfo*> &AllPasses,
// output (created above). // output (created above).
// //
outs() << "*** Checking if passes caused miscompliation:\n"; outs() << "*** Checking if passes caused miscompliation:\n";
bool Diff = diffProgram(Filename, "", false, &Error); bool Diff = diffProgram(Program, Filename, "", false, &Error);
if (Error.empty() && Diff) { if (Error.empty() && Diff) {
outs() << "\n*** diffProgram returned true!\n"; outs() << "\n*** diffProgram returned true!\n";
debugMiscompilation(&Error); debugMiscompilation(&Error);

View File

@ -76,8 +76,8 @@ ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
} }
// Check to see if the finished program matches the reference output... // Check to see if the finished program matches the reference output...
bool Diff = BD.diffProgram(BitcodeResult, "", true /*delete bitcode*/, bool Diff = BD.diffProgram(BD.getProgram(), BitcodeResult, "",
&Error); true /*delete bitcode*/, &Error);
if (!Error.empty()) if (!Error.empty())
return InternalError; return InternalError;
if (Diff) { if (Diff) {
@ -113,7 +113,7 @@ ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
} }
// If the prefix maintains the predicate by itself, only keep the prefix! // If the prefix maintains the predicate by itself, only keep the prefix!
Diff = BD.diffProgram(BitcodeResult, "", false, &Error); Diff = BD.diffProgram(BD.getProgram(), BitcodeResult, "", false, &Error);
if (!Error.empty()) if (!Error.empty())
return InternalError; return InternalError;
if (Diff) { if (Diff) {
@ -153,7 +153,8 @@ ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
} }
// Run the result... // Run the result...
Diff = BD.diffProgram(BitcodeResult, "", true /*delete bitcode*/, &Error); Diff = BD.diffProgram(BD.getProgram(), BitcodeResult, "",
true /*delete bitcode*/, &Error);
if (!Error.empty()) if (!Error.empty())
return InternalError; return InternalError;
if (Diff) { if (Diff) {
@ -223,15 +224,15 @@ static bool TestMergedProgram(BugDriver &BD, Module *M1, Module *M2,
} }
delete M2; // We are done with this module. delete M2; // We are done with this module.
OwningPtr<Module> OldProgram(BD.swapProgramIn(M1));
// Execute the program. If it does not match the expected output, we must // Execute the program. If it does not match the expected output, we must
// return true. // return true.
bool Broken = BD.diffProgram("", "", false, &Error); bool Broken = BD.diffProgram(M1, "", "", false, &Error);
if (!Error.empty()) { if (!Error.empty()) {
// Delete the linked module & restore the original // Delete the linked module
delete BD.swapProgramIn(OldProgram.take()); delete M1;
} }
// Delete the original and set the new program.
delete BD.swapProgramIn(M1);
return Broken; return Broken;
} }
@ -958,7 +959,8 @@ static bool TestCodeGenerator(BugDriver &BD, Module *Test, Module *Safe,
// Run the code generator on the `Test' code, loading the shared library. // Run the code generator on the `Test' code, loading the shared library.
// The function returns whether or not the new output differs from reference. // The function returns whether or not the new output differs from reference.
bool Result = BD.diffProgram(TestModuleBC.str(), SharedObject, false, &Error); bool Result = BD.diffProgram(BD.getProgram(), TestModuleBC.str(),
SharedObject, false, &Error);
if (!Error.empty()) if (!Error.empty())
return false; return false;
@ -975,7 +977,8 @@ static bool TestCodeGenerator(BugDriver &BD, Module *Test, Module *Safe,
/// ///
bool BugDriver::debugCodeGenerator(std::string *Error) { bool BugDriver::debugCodeGenerator(std::string *Error) {
if ((void*)SafeInterpreter == (void*)Interpreter) { if ((void*)SafeInterpreter == (void*)Interpreter) {
std::string Result = executeProgramSafely("bugpoint.safe.out", Error); std::string Result = executeProgramSafely(Program, "bugpoint.safe.out",
Error);
if (Error->empty()) { if (Error->empty()) {
outs() << "\n*** The \"safe\" i.e. 'known good' backend cannot match " outs() << "\n*** The \"safe\" i.e. 'known good' backend cannot match "
<< "the reference diff. This may be due to a\n front-end " << "the reference diff. This may be due to a\n front-end "