// Spiff up the output a little bit.
PassManager Passes;
// Make sure that the appropriate target data is always used...
- Passes.add(new TargetData("bugpoint", Result));
+ Passes.add(new TargetData(Result));
/// FIXME: If this used runPasses() like the methods below, we could get rid
/// of the -disable-* options!
I->setLinkage(GlobalValue::ExternalLinkage);
std::vector<const PassInfo*> CleanupPasses;
- CleanupPasses.push_back(getPI(createFunctionResolvingPass()));
CleanupPasses.push_back(getPI(createGlobalDCEPass()));
CleanupPasses.push_back(getPI(createDeadTypeEliminationPass()));
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
std::vector<Constant*> ArrayElts;
for (unsigned i = 0, e = TorList.size(); i != e; ++i) {
std::vector<Constant*> Elts;
- Elts.push_back(ConstantSInt::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));
}
/// 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;
if (CS->getOperand(1)->isNullValue())
break; // Found a null terminator, stop here.
- ConstantSInt *CI = dyn_cast<ConstantSInt>(CS->getOperand(0));
- int Priority = CI ? CI->getValue() : 0;
+ ConstantInt *CI = dyn_cast<ConstantInt>(CS->getOperand(0));
+ int Priority = CI ? CI->getSExtValue() : 0;
Constant *FP = CS->getOperand(1);
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(FP))
- if (CE->getOpcode() == Instruction::Cast)
+ 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));
}
}
}
}
+
/// SplitFunctionsOutOfModule - Given a module and a list of functions in the
/// module, split the functions OUT of the specified module, and place them in
/// the new module.
-///
-/// FIXME: this could be made DRAMATICALLY more efficient for large programs if
-/// we just MOVED functions from one module to the other, instead of cloning the
-/// whole module, then proceeding to delete an entire module's worth of stuff.
-///
Module *llvm::SplitFunctionsOutOfModule(Module *M,
const std::vector<Function*> &F) {
// Make sure functions & globals are all external so that linkage
// Remove the Test functions from the Safe module
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");
+ TestFunctions.insert(std::make_pair(F[i]->getName(), F[i]->getType()));
+ 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!
}
+
// Remove the Safe functions from the Test module
for (Module::iterator I = New->begin(), E = New->end(); I != E; ++I)
if (!TestFunctions.count(std::make_pair(I->getName(), I->getType())))
DeleteFunctionBody(I);
+
// Make sure that there is a global ctor/dtor array in both halves of the
// module if they both have static ctor/dtor functions.
SplitStaticCtorDtor("llvm.global_ctors", M, New);
/// BlocksToNotExtract list.
class BlockExtractorPass : public ModulePass {
bool runOnModule(Module &M);
+ public:
+ static char ID; // Pass ID, replacement for typeid
+ BlockExtractorPass() : ModulePass((intptr_t)&ID) {}
};
- RegisterOpt<BlockExtractorPass>
+ char BlockExtractorPass::ID = 0;
+ RegisterPass<BlockExtractorPass>
XX("extract-bbs", "Extract Basic Blocks From Module (for bugpoint use)");
}
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();