bugpoint doesn't need the mangler at all. DisambiguateGlobalSymbols
[oota-llvm.git] / tools / bugpoint / Miscompilation.cpp
index 57a4fc717fe641b59e4bad7231a7278e4c8f37d3..4c184d64a6392a6a9bb17cfc861a75f0e1721891 100644 (file)
@@ -22,7 +22,6 @@
 #include "llvm/Module.h"
 #include "llvm/Pass.h"
 #include "llvm/Analysis/Verifier.h"
-#include "llvm/Support/Mangler.h"
 #include "llvm/Transforms/Utils/Cloning.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileUtilities.h"
@@ -30,6 +29,7 @@
 using namespace llvm;
 
 namespace llvm {
+  extern cl::opt<std::string> OutputPrefix;
   extern cl::list<std::string> InputArgv;
 }
 
@@ -234,29 +234,18 @@ bool ReduceMiscompilingFunctions::TestFuncs(const std::vector<Function*>&Funcs){
   return TestFn(BD, ToOptimize, ToNotOptimize);
 }
 
-/// DisambiguateGlobalSymbols - Mangle symbols to guarantee uniqueness by
-/// modifying predominantly internal symbols rather than external ones.
+/// DisambiguateGlobalSymbols - Give anonymous global values names.
 ///
 static void DisambiguateGlobalSymbols(Module *M) {
-  // Try not to cause collisions by minimizing chances of renaming an
-  // already-external symbol, so take in external globals and functions as-is.
-  // The code should work correctly without disambiguation (assuming the same
-  // mangler is used by the two code generators), but having symbols with the
-  // same name causes warnings to be emitted by the code generator.
-  Mangler Mang(*M);
-  // Agree with the CBE on symbol naming
-  Mang.markCharUnacceptable('.');
   for (Module::global_iterator I = M->global_begin(), E = M->global_end();
        I != E; ++I) {
     // Don't mangle asm names.
-    if (!I->hasName() || I->getName()[0] != 1)
-      I->setName(Mang.getMangledName(I));
+    if (!I->hasName())
+      I->setName("anon_global");
   }
   for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) {
-    // Don't mangle asm names or intrinsics.
-    if ((!I->hasName() || I->getName()[0] != 1) &&
-        I->getIntrinsicID() == 0)
-      I->setName(Mang.getMangledName(I));
+    if (!I->hasName())
+      I->setName("anon_fn");
   }
 }
 
@@ -301,12 +290,15 @@ static bool ExtractLoops(BugDriver &BD,
              << " Please report a bug!\n";
       errs() << "      Continuing on with un-loop-extracted version.\n";
 
-      BD.writeProgramToFile("bugpoint-loop-extract-fail-tno.bc", ToNotOptimize);
-      BD.writeProgramToFile("bugpoint-loop-extract-fail-to.bc", ToOptimize);
-      BD.writeProgramToFile("bugpoint-loop-extract-fail-to-le.bc",
+      BD.writeProgramToFile(OutputPrefix + "-loop-extract-fail-tno.bc",
+                            ToNotOptimize);
+      BD.writeProgramToFile(OutputPrefix + "-loop-extract-fail-to.bc",
+                            ToOptimize);
+      BD.writeProgramToFile(OutputPrefix + "-loop-extract-fail-to-le.bc",
                             ToOptimizeLoopExtracted);
 
-      errs() << "Please submit the bugpoint-loop-extract-fail-*.bc files.\n";
+      errs() << "Please submit the " 
+             << OutputPrefix << "-loop-extract-fail-*.bc files.\n";
       delete ToOptimize;
       delete ToNotOptimize;
       delete ToOptimizeLoopExtracted;
@@ -544,10 +536,6 @@ DebugAMiscompilation(BugDriver &BD,
       ExtractLoops(BD, TestFn, MiscompiledFunctions)) {
     // Okay, we extracted some loops and the problem still appears.  See if we
     // can eliminate some of the created functions from being candidates.
-
-    // Loop extraction can introduce functions with the same name (foo_code).
-    // Make sure to disambiguate the symbols so that when the program is split
-    // apart that we can link it back together again.
     DisambiguateGlobalSymbols(BD.getProgram());
 
     // Do the reduction...
@@ -565,10 +553,6 @@ DebugAMiscompilation(BugDriver &BD,
       ExtractBlocks(BD, TestFn, MiscompiledFunctions)) {
     // Okay, we extracted some blocks and the problem still appears.  See if we
     // can eliminate some of the created functions from being candidates.
-
-    // Block extraction can introduce functions with the same name (foo_code).
-    // Make sure to disambiguate the symbols so that when the program is split
-    // apart that we can link it back together again.
     DisambiguateGlobalSymbols(BD.getProgram());
 
     // Do the reduction...
@@ -700,8 +684,8 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
   // Prototype: void *getPointerToNamedFunction(const char* Name)
   Constant *resolverFunc =
     Safe->getOrInsertFunction("getPointerToNamedFunction",
-                    PointerType::getUnqual(Type::getInt8Ty(Safe->getContext())),
-                    PointerType::getUnqual(Type::getInt8Ty(Safe->getContext())),
+                    Type::getInt8PtrTy(Safe->getContext()),
+                    Type::getInt8PtrTy(Safe->getContext()),
                        (Type *)0);
 
   // Use the function we just added to get addresses of functions we need.