minor cleanups. Add provisions for a new standard BLOCKINFO_BLOCK
[oota-llvm.git] / tools / bugpoint / ExtractFunction.cpp
index 43e68404cb24d6f4d4e6664ed5cde5d4b2b071b3..85da9294285e0bd1221755687a6c2485e8cd22b0 100644 (file)
@@ -110,7 +110,6 @@ Module *BugDriver::performFinalCleanups(Module *M, bool MayModifySemantics) {
     I->setLinkage(GlobalValue::ExternalLinkage);
 
   std::vector<const PassInfo*> CleanupPasses;
-  CleanupPasses.push_back(getPI(createFunctionResolvingPass()));
   CleanupPasses.push_back(getPI(createGlobalDCEPass()));
   CleanupPasses.push_back(getPI(createDeadTypeEliminationPass()));
 
@@ -170,7 +169,7 @@ Module *BugDriver::ExtractLoop(Module *M) {
 void llvm::DeleteFunctionBody(Function *F) {
   // delete the body of the function...
   F->deleteBody();
-  assert(F->isExternal() && "This didn't make the function external!");
+  assert(F->isDeclaration() && "This didn't make the function external!");
 }
 
 /// GetTorInit - Given a list of entries for static ctors/dtors, return them
@@ -180,7 +179,7 @@ static Constant *GetTorInit(std::vector<std::pair<Function*, int> > &TorList) {
   std::vector<Constant*> ArrayElts;
   for (unsigned i = 0, e = TorList.size(); i != e; ++i) {
     std::vector<Constant*> Elts;
-    Elts.push_back(ConstantInt::get(Type::IntTy, TorList[i].second));
+    Elts.push_back(ConstantInt::get(Type::Int32Ty, TorList[i].second));
     Elts.push_back(TorList[i].first);
     ArrayElts.push_back(ConstantStruct::get(Elts));
   }
@@ -195,7 +194,7 @@ static Constant *GetTorInit(std::vector<std::pair<Function*, int> > &TorList) {
 /// prune appropriate entries out of M1s list.
 static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2){
   GlobalVariable *GV = M1->getNamedGlobal(GlobalName);
-  if (!GV || GV->isExternal() || GV->hasInternalLinkage() ||
+  if (!GV || GV->isDeclaration() || GV->hasInternalLinkage() ||
       !GV->use_empty()) return;
   
   std::vector<std::pair<Function*, int> > M1Tors, M2Tors;
@@ -217,11 +216,11 @@ static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2){
         if (CE->isCast())
           FP = CE->getOperand(0);
       if (Function *F = dyn_cast<Function>(FP)) {
-        if (!F->isExternal())
+        if (!F->isDeclaration())
           M1Tors.push_back(std::make_pair(F, Priority));
         else {
           // Map to M2's version of the function.
-          F = M2->getFunction(F->getName(), F->getFunctionType());
+          F = M2->getFunction(F->getName());
           M2Tors.push_back(std::make_pair(F, Priority));
         }
       }
@@ -272,9 +271,10 @@ Module *llvm::SplitFunctionsOutOfModule(Module *M,
   std::set<std::pair<std::string, const PointerType*> > TestFunctions;
   for (unsigned i = 0, e = F.size(); i != e; ++i) {
     TestFunctions.insert(std::make_pair(F[i]->getName(), F[i]->getType()));  
-    Function *TNOF = M->getFunction(F[i]->getName(), F[i]->getFunctionType());
-    DEBUG(std::cerr << "Removing function " << F[i]->getName() << "\n");
+    Function *TNOF = M->getFunction(F[i]->getName());
     assert(TNOF && "Function doesn't exist in module!");
+    assert(TNOF->getFunctionType() == F[i]->getFunctionType() && "wrong type?");
+    DEBUG(std::cerr << "Removing function " << F[i]->getName() << "\n");
     DeleteFunctionBody(TNOF);       // Function is now external in this module!
   }
 
@@ -305,7 +305,11 @@ namespace {
   /// BlocksToNotExtract list.
   class BlockExtractorPass : public ModulePass {
     bool runOnModule(Module &M);
+  public:
+    static char ID; // Pass ID, replacement for typeid
+    BlockExtractorPass() : ModulePass((intptr_t)&ID) {}
   };
+  char BlockExtractorPass::ID = 0;
   RegisterPass<BlockExtractorPass>
   XX("extract-bbs", "Extract Basic Blocks From Module (for bugpoint use)");
 }
@@ -317,7 +321,7 @@ bool BlockExtractorPass::runOnModule(Module &M) {
     Function *F = BB->getParent();
 
     // Map the corresponding function in this module.
-    Function *MF = M.getFunction(F->getName(), F->getFunctionType());
+    Function *MF = M.getFunction(F->getName());
 
     // Figure out which index the basic block is in its function.
     Function::iterator BBI = MF->begin();