Add a Program argument to diffProgram to avoid a use of swapProgramIn.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 30 Jul 2010 14:19:00 +0000 (14:19 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 30 Jul 2010 14:19:00 +0000 (14:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@109859 91177308-0d34-0410-b5e6-96231b3b80d8

tools/bugpoint/BugDriver.cpp
tools/bugpoint/BugDriver.h
tools/bugpoint/ExecutionDriver.cpp
tools/bugpoint/FindBugs.cpp
tools/bugpoint/Miscompilation.cpp

index 45a0d4dd17a31e0ae77c1f360a3318e453b7be46..d5b0656019d1722716e7e894cd34c86f9184fc4e 100644 (file)
@@ -211,7 +211,7 @@ bool BugDriver::run(std::string &ErrMsg) {
   // matches, then we assume there is a miscompilation bug and try to 
   // diagnose it.
   outs() << "*** Checking the code generator...\n";
-  bool Diff = diffProgram("", "", false, &Error);
+  bool Diff = diffProgram(Program, "", "", false, &Error);
   if (!Error.empty()) {
     errs() << Error;
     return debugCodeGeneratorCrash(ErrMsg);
index 6a7f47130a9189a7d7f5f920905205ff5a5b0cd3..4f345d613bb35bbc2ccffb1192df657147b31c50 100644 (file)
@@ -174,7 +174,8 @@ public:
   /// executeProgram - This method runs "Program", capturing the output of the
   /// 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,
                              const std::string &SharedObjects,
                              AbstractInterpreter *AI,
@@ -185,7 +186,8 @@ public:
   /// the code generator (e.g., llc crashes), this will return false and set
   /// 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
   /// 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
   /// 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 = "",
                    bool RemoveBitcode = false,
                    std::string *Error = 0);
index 57f12d5af8240d12716358aa1ebb829abdc47d72..01dd379f41b3ea27b7a9fd936251f89781e04214 100644 (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
 /// 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,
                                       const std::string &SharedObj,
                                       AbstractInterpreter *AI,
@@ -399,9 +400,10 @@ std::string BugDriver::executeProgram(std::string OutputFile,
 /// executeProgramSafely - Used to create reference output with the "safe"
 /// 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) {
-  return executeProgram(OutputFile, "", "", SafeInterpreter, Error);
+  return executeProgram(Program, OutputFile, "", "", SafeInterpreter, Error);
 }
 
 std::string BugDriver::compileSharedObject(const std::string &BitcodeFile,
@@ -440,7 +442,7 @@ bool BugDriver::createReferenceFile(Module *M, const std::string &Filename) {
   if (!Error.empty())
     return false;
 
-  ReferenceOutputFile = executeProgramSafely(Filename, &Error);
+  ReferenceOutputFile = executeProgramSafely(Program, Filename, &Error);
   if (!Error.empty()) {
     errs() << Error;
     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
 /// 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,
                             bool RemoveBitcode,
                             std::string *ErrMsg) {
   // 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())
     return false;
 
index 224c71747a6f5c8c4acaee0a42fcd987d3da8c5b..4fd597ee119ebe095a6eb472323c53dfce406483 100644 (file)
@@ -89,7 +89,7 @@ bool BugDriver::runManyPasses(const std::vector<const PassInfo*> &AllPasses,
     // output (created above).
     //
     outs() << "*** Checking if passes caused miscompliation:\n";
-    bool Diff = diffProgram(Filename, "", false, &Error);
+    bool Diff = diffProgram(Program, Filename, "", false, &Error);
     if (Error.empty() && Diff) {
       outs() << "\n*** diffProgram returned true!\n";
       debugMiscompilation(&Error);
index c17f2a9d00ff82d31bc50cdc698e730522637b1f..8cd3f387300b5f610f51d53c8e9fba80cf013b13 100644 (file)
@@ -76,8 +76,8 @@ ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
   }
   
   // Check to see if the finished program matches the reference output...
-  bool Diff = BD.diffProgram(BitcodeResult, "", true /*delete bitcode*/,
-                             &Error);
+  bool Diff = BD.diffProgram(BD.getProgram(), BitcodeResult, "",
+                             true /*delete bitcode*/, &Error);
   if (!Error.empty())
     return InternalError;
   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!
-  Diff = BD.diffProgram(BitcodeResult, "", false, &Error);
+  Diff = BD.diffProgram(BD.getProgram(), BitcodeResult, "", false, &Error);
   if (!Error.empty())
     return InternalError;
   if (Diff) {
@@ -153,7 +153,8 @@ ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
   }
 
   // Run the result...
-  Diff = BD.diffProgram(BitcodeResult, "", true /*delete bitcode*/, &Error);
+  Diff = BD.diffProgram(BD.getProgram(), BitcodeResult, "",
+                        true /*delete bitcode*/, &Error);
   if (!Error.empty())
     return InternalError;
   if (Diff) {
@@ -223,15 +224,15 @@ static bool TestMergedProgram(BugDriver &BD, Module *M1, Module *M2,
   }
   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
   // return true.
-  bool Broken = BD.diffProgram("", "", false, &Error);
+  bool Broken = BD.diffProgram(M1, "", "", false, &Error);
   if (!Error.empty()) {
-    // Delete the linked module & restore the original
-    delete BD.swapProgramIn(OldProgram.take());
+    // Delete the linked module
+    delete M1;
   }
+  // Delete the original and set the new program.
+  delete BD.swapProgramIn(M1);
   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.
   // 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())
     return false;
 
@@ -975,7 +977,8 @@ static bool TestCodeGenerator(BugDriver &BD, Module *Test, Module *Safe,
 ///
 bool BugDriver::debugCodeGenerator(std::string *Error) {
   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()) {
       outs() << "\n*** The \"safe\" i.e. 'known good' backend cannot match "
              << "the reference diff.  This may be due to a\n    front-end "