By default -t is always on for mcc16 and it uses ./tmp-objs as the temp directory.
[oota-llvm.git] / tools / bugpoint / Miscompilation.cpp
index 8e677cbbb219f66315eb0dd18f650c5417b1b5da..a24ea7778118e3723526e0427c369ec9cf0a7a99 100644 (file)
@@ -112,7 +112,7 @@ ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
   // Ok, so now we know that the prefix passes work, try running the suffix
   // passes on the result of the prefix passes.
   //
-  Module *PrefixOutput = ParseInputFile(BitcodeResult);
+  Module *PrefixOutput = ParseInputFile(BitcodeResult, BD.getContext());
   if (PrefixOutput == 0) {
     std::cerr << BD.getToolName() << ": Error reading bitcode file '"
               << BitcodeResult << "'!\n";
@@ -220,8 +220,10 @@ bool ReduceMiscompilingFunctions::TestFuncs(const std::vector<Function*>&Funcs){
   std::cout << '\n';
 
   // Split the module into the two halves of the program we want.
-  Module *ToNotOptimize = CloneModule(BD.getProgram());
-  Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize, Funcs);
+  DenseMap<const Value*, Value*> ValueMap;
+  Module *ToNotOptimize = CloneModule(BD.getProgram(), ValueMap);
+  Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize, Funcs,
+                                                 ValueMap);
 
   // Run the predicate, note that the predicate will delete both input modules.
   return TestFn(BD, ToOptimize, ToNotOptimize);
@@ -258,9 +260,11 @@ static bool ExtractLoops(BugDriver &BD,
   while (1) {
     if (BugpointIsInterrupted) return MadeChange;
     
-    Module *ToNotOptimize = CloneModule(BD.getProgram());
+    DenseMap<const Value*, Value*> ValueMap;
+    Module *ToNotOptimize = CloneModule(BD.getProgram(), ValueMap);
     Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
-                                                   MiscompiledFunctions);
+                                                   MiscompiledFunctions,
+                                                   ValueMap);
     Module *ToOptimizeLoopExtracted = BD.ExtractLoop(ToOptimize);
     if (!ToOptimizeLoopExtracted) {
       // If the loop extractor crashed or if there were no extractible loops,
@@ -277,7 +281,7 @@ static bool ExtractLoops(BugDriver &BD,
     // we're going to test the newly loop extracted program to make sure nothing
     // has broken.  If something broke, then we'll inform the user and stop
     // extraction.
-    AbstractInterpreter *AI = BD.switchToCBE();
+    AbstractInterpreter *AI = BD.switchToSafeInterpreter();
     if (TestMergedProgram(BD, ToOptimizeLoopExtracted, ToNotOptimize, false)) {
       BD.switchToInterpreter(AI);
 
@@ -396,9 +400,11 @@ bool ReduceMiscompiledBlocks::TestFuncs(const std::vector<BasicBlock*> &BBs) {
   std::cout << '\n';
 
   // Split the module into the two halves of the program we want.
-  Module *ToNotOptimize = CloneModule(BD.getProgram());
+  DenseMap<const Value*, Value*> ValueMap;
+  Module *ToNotOptimize = CloneModule(BD.getProgram(), ValueMap);
   Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
-                                                 FunctionsBeingTested);
+                                                 FunctionsBeingTested,
+                                                 ValueMap);
 
   // Try the extraction.  If it doesn't work, then the block extractor crashed
   // or something, in which case bugpoint can't chase down this possibility.
@@ -443,9 +449,11 @@ static bool ExtractBlocks(BugDriver &BD,
       return false;
   }
 
-  Module *ProgClone = CloneModule(BD.getProgram());
+  DenseMap<const Value*, Value*> ValueMap;
+  Module *ProgClone = CloneModule(BD.getProgram(), ValueMap);
   Module *ToExtract = SplitFunctionsOutOfModule(ProgClone,
-                                                MiscompiledFunctions);
+                                                MiscompiledFunctions,
+                                                ValueMap);
   Module *Extracted = BD.ExtractMappedBlocksFromModule(Blocks, ToExtract);
   if (Extracted == 0) {
     // Weird, extraction should have worked.
@@ -608,9 +616,11 @@ bool BugDriver::debugMiscompilation() {
 
   // Output a bunch of bitcode files for the user...
   std::cout << "Outputting reduced bitcode files which expose the problem:\n";
-  Module *ToNotOptimize = CloneModule(getProgram());
+  DenseMap<const Value*, Value*> ValueMap;
+  Module *ToNotOptimize = CloneModule(getProgram(), ValueMap);
   Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
-                                                 MiscompiledFunctions);
+                                                 MiscompiledFunctions,
+                                                 ValueMap);
 
   std::cout << "  Non-optimized portion: ";
   ToNotOptimize = swapProgramIn(ToNotOptimize);
@@ -693,9 +703,9 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
         // 1. Add a string constant with its name to the global file
         Constant *InitArray = ConstantArray::get(F->getName());
         GlobalVariable *funcName =
-          new GlobalVariable(InitArray->getType(), true /*isConstant*/,
+          new GlobalVariable(*Safe, InitArray->getType(), true /*isConstant*/,
                              GlobalValue::InternalLinkage, InitArray,
-                             F->getName() + "_name", Safe);
+                             F->getName() + "_name");
 
         // 2. Use `GetElementPtr *funcName, 0, 0' to convert the string to an
         // sbyte* so it matches the signature of the resolver function.
@@ -712,8 +722,9 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
           // Create a new global to hold the cached function pointer.
           Constant *NullPtr = ConstantPointerNull::get(F->getType());
           GlobalVariable *Cache =
-            new GlobalVariable(F->getType(), false,GlobalValue::InternalLinkage,
-                               NullPtr,F->getName()+".fpcache", F->getParent());
+            new GlobalVariable(*F->getParent(), F->getType(), 
+                               false, GlobalValue::InternalLinkage,
+                               NullPtr,F->getName()+".fpcache");
 
           // Construct a new stub function that will re-route calls to F
           const FunctionType *FuncTy = F->getFunctionType();
@@ -838,13 +849,15 @@ static bool TestCodeGenerator(BugDriver &BD, Module *Test, Module *Safe) {
 /// debugCodeGenerator - debug errors in LLC, LLI, or CBE.
 ///
 bool BugDriver::debugCodeGenerator() {
-  if ((void*)cbe == (void*)Interpreter) {
-    std::string Result = executeProgramWithCBE("bugpoint.cbe.out");
-    std::cout << "\n*** The C backend cannot match the reference diff, but it "
-              << "is used as the 'known good'\n    code generator, so I can't"
-              << " debug it.  Perhaps you have a front-end problem?\n    As a"
-              << " sanity check, I left the result of executing the program "
-              << "with the C backend\n    in this file for you: '"
+  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";
     return true;
   }
@@ -854,8 +867,9 @@ bool BugDriver::debugCodeGenerator() {
   std::vector<Function*> Funcs = DebugAMiscompilation(*this, TestCodeGenerator);
 
   // Split the module into the two halves of the program we want.
-  Module *ToNotCodeGen = CloneModule(getProgram());
-  Module *ToCodeGen = SplitFunctionsOutOfModule(ToNotCodeGen, Funcs);
+  DenseMap<const Value*, Value*> ValueMap;
+  Module *ToNotCodeGen = CloneModule(getProgram(), ValueMap);
+  Module *ToCodeGen = SplitFunctionsOutOfModule(ToNotCodeGen, Funcs, ValueMap);
 
   // Condition the modules
   CleanupAndPrepareModules(*this, ToCodeGen, ToNotCodeGen);