minor cleanups. Add provisions for a new standard BLOCKINFO_BLOCK
[oota-llvm.git] / tools / bugpoint / Miscompilation.cpp
index bdbd11ba1543cec28ab0c89869b0697110a5d1e4..534aa28533ed665df40f9bcdf1b7f36b7b7fe856 100644 (file)
@@ -341,9 +341,11 @@ static bool ExtractLoops(BugDriver &BD,
     // optimized and loop extracted module.
     MiscompiledFunctions.clear();
     for (unsigned i = 0, e = MisCompFunctions.size(); i != e; ++i) {
-      Function *NewF = ToNotOptimize->getFunction(MisCompFunctions[i].first,
-                                                  MisCompFunctions[i].second);
+      Function *NewF = ToNotOptimize->getFunction(MisCompFunctions[i].first);
+                                                  
       assert(NewF && "Function not found??");
+      assert(NewF->getFunctionType() == MisCompFunctions[i].second && 
+             "found wrong function type?");
       MiscompiledFunctions.push_back(NewF);
     }
 
@@ -479,9 +481,10 @@ static bool ExtractBlocks(BugDriver &BD,
   MiscompiledFunctions.clear();
 
   for (unsigned i = 0, e = MisCompFunctions.size(); i != e; ++i) {
-    Function *NewF = ProgClone->getFunction(MisCompFunctions[i].first,
-                                            MisCompFunctions[i].second);
+    Function *NewF = ProgClone->getFunction(MisCompFunctions[i].first);
     assert(NewF && "Function not found??");
+    assert(NewF->getFunctionType() == MisCompFunctions[i].second && 
+           "Function has wrong type??");
     MiscompiledFunctions.push_back(NewF);
   }
 
@@ -636,7 +639,7 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
   // First, if the main function is in the Safe module, we must add a stub to
   // the Test module to call into it.  Thus, we create a new function `main'
   // which just calls the old one.
-  if (Function *oldMain = Safe->getNamedFunction("main"))
+  if (Function *oldMain = Safe->getFunction("main"))
     if (!oldMain->isDeclaration()) {
       // Rename it
       oldMain->setName("llvm_bugpoint_old_main");
@@ -660,7 +663,8 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
 
       // Call the old main function and return its result
       BasicBlock *BB = new BasicBlock("entry", newMain);
-      CallInst *call = new CallInst(oldMainProto, args, "", BB);
+      CallInst *call = new CallInst(oldMainProto, &args[0], args.size(),
+                                    "", BB);
 
       // If the type of old function wasn't void, return value of call
       new ReturnInst(call, BB);
@@ -682,7 +686,7 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
   for (Module::iterator F = Safe->begin(), E = Safe->end(); F != E; ++F) {
     if (F->isDeclaration() && !F->use_empty() && &*F != resolverFunc &&
         F->getIntrinsicID() == 0 /* ignore intrinsics */) {
-      Function *TestFn = Test->getNamedFunction(F->getName());
+      Function *TestFn = Test->getFunction(F->getName());
 
       // Don't forward functions which are external in the test module too.
       if (TestFn && !TestFn->isDeclaration()) {
@@ -698,8 +702,7 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
 
         // GetElementPtr *funcName, ulong 0, ulong 0
         std::vector<Constant*> GEPargs(2,Constant::getNullValue(Type::Int32Ty));
-        Value *GEP =
-          ConstantExpr::getGetElementPtr(funcName, GEPargs);
+        Value *GEP = ConstantExpr::getGetElementPtr(funcName, &GEPargs[0], 2);
         std::vector<Value*> ResolverArgs;
         ResolverArgs.push_back(GEP);
 
@@ -731,7 +734,8 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
           // Resolve the call to function F via the JIT API:
           //
           // call resolver(GetElementPtr...)
-          CallInst *Resolver = new CallInst(resolverFunc, ResolverArgs,
+          CallInst *Resolver = new CallInst(resolverFunc, &ResolverArgs[0],
+                                            ResolverArgs.size(),
                                             "resolver", LookupBB);
           // cast the result from the resolver to correctly-typed function
           CastInst *CastedResolver = new BitCastInst(Resolver, 
@@ -753,10 +757,11 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
 
           // Pass on the arguments to the real function, return its result
           if (F->getReturnType() == Type::VoidTy) {
-            new CallInst(FuncPtr, Args, "", DoCallBB);
+            new CallInst(FuncPtr, &Args[0], Args.size(), "", DoCallBB);
             new ReturnInst(DoCallBB);
           } else {
-            CallInst *Call = new CallInst(FuncPtr, Args, "retval", DoCallBB);
+            CallInst *Call = new CallInst(FuncPtr, &Args[0], Args.size(),
+                                          "retval", DoCallBB);
             new ReturnInst(Call, DoCallBB);
           }