/// general code.
Function *ExecutionEngine::FindFunctionNamed(const char *FnName) {
for (unsigned i = 0, e = Modules.size(); i != e; ++i) {
- if (Function *F = Modules[i]->getModule()->getNamedFunction(FnName))
+ if (Function *F = Modules[i]->getModule()->getFunction(FnName))
return F;
}
return 0;
// If the program doesn't define a main, try pulling one in from a .a file.
// This is needed for programs where the main function is defined in an
// archive, such f2c'd programs.
- Function *Main = M->getMainFunction();
+ Function *Main = M->getFunction("main");
if (Main == 0 || Main->isDeclaration())
UndefinedSymbols.insert("main");
bool runOnModule(Module &M) {
if (Named == 0) {
- Named = M.getMainFunction();
+ Named = M.getFunction("main");
if (Named == 0) return false; // No function to extract
}
//functions, ensuring that all malloc and free that might happen
//happen through intrinsics.
bool changed = false;
- if (Function* F = M.getNamedFunction("free")) {
+ if (Function* F = M.getFunction("free")) {
assert(F->isDeclaration() && "free not external?");
if (!F->use_empty()) {
Function* FN = new Function(F->getFunctionType(),
changed = true;
}
}
- if (Function* F = M.getNamedFunction("malloc")) {
+ if (Function* F = M.getFunction("malloc")) {
assert(F->isDeclaration() && "malloc not external?");
if (!F->use_empty()) {
Function* FN = new Function(F->getFunctionType(),
// internalize the module, it must be a library or something.
//
if (ExternalNames.empty()) {
- Function *MainFunc = M.getMainFunction();
+ Function *MainFunc = M.getFunction("main");
if (MainFunc == 0 || MainFunc->isDeclaration())
return false; // No main found, must be a library...
bool Changed = false;
// These are what the functions are called.
- Function* SetJmp = M.getNamedFunction("llvm.setjmp");
- Function* LongJmp = M.getNamedFunction("llvm.longjmp");
+ Function* SetJmp = M.getFunction("llvm.setjmp");
+ Function* LongJmp = M.getFunction("llvm.longjmp");
// This program doesn't have longjmp and setjmp calls.
if ((!LongJmp || LongJmp->use_empty()) &&
// Strip debug info in the module if it exists. To do this, we remove
// llvm.dbg.func.start, llvm.dbg.stoppoint, and llvm.dbg.region.end calls, and
// any globals they point to if now dead.
- Function *FuncStart = M.getNamedFunction("llvm.dbg.func.start");
- Function *StopPoint = M.getNamedFunction("llvm.dbg.stoppoint");
- Function *RegionStart = M.getNamedFunction("llvm.dbg.region.start");
- Function *RegionEnd = M.getNamedFunction("llvm.dbg.region.end");
- Function *Declare = M.getNamedFunction("llvm.dbg.declare");
+ Function *FuncStart = M.getFunction("llvm.dbg.func.start");
+ Function *StopPoint = M.getFunction("llvm.dbg.stoppoint");
+ Function *RegionStart = M.getFunction("llvm.dbg.region.start");
+ Function *RegionEnd = M.getFunction("llvm.dbg.region.end");
+ Function *Declare = M.getFunction("llvm.dbg.declare");
if (!FuncStart && !StopPoint && !RegionStart && !RegionEnd && !Declare)
return true;
}
bool FunctionProfiler::runOnModule(Module &M) {
- Function *Main = M.getMainFunction();
+ Function *Main = M.getFunction("main");
if (Main == 0) {
cerr << "WARNING: cannot insert function profiling into a module"
<< " with no main function!\n";
ModulePass *llvm::createBlockProfilerPass() { return new BlockProfiler(); }
bool BlockProfiler::runOnModule(Module &M) {
- Function *Main = M.getMainFunction();
+ Function *Main = M.getFunction("main");
if (Main == 0) {
cerr << "WARNING: cannot insert block profiling into a module"
<< " with no main function!\n";
ModulePass *llvm::createEdgeProfilerPass() { return new EdgeProfiler(); }
bool EdgeProfiler::runOnModule(Module &M) {
- Function *Main = M.getMainFunction();
+ Function *Main = M.getFunction("main");
if (Main == 0) {
cerr << "WARNING: cannot insert edge profiling into a module"
<< " with no main function!\n";
}
bool TraceBasicBlocks::runOnModule(Module &M) {
- Function *Main = M.getMainFunction();
+ Function *Main = M.getFunction("main");
if (Main == 0) {
cerr << "WARNING: cannot insert basic-block trace instrumentation"
<< " into a module with no main function!\n";
/// doInitialization - If this module uses the GC intrinsics, find them now. If
/// not, this pass does not do anything.
bool LowerGC::doInitialization(Module &M) {
- GCRootInt = M.getNamedFunction("llvm.gcroot");
- GCReadInt = M.getNamedFunction("llvm.gcread");
- GCWriteInt = M.getNamedFunction("llvm.gcwrite");
+ GCRootInt = M.getFunction("llvm.gcroot");
+ GCReadInt = M.getFunction("llvm.gcread");
+ GCWriteInt = M.getFunction("llvm.gcwrite");
if (!GCRootInt && !GCReadInt && !GCWriteInt) return false;
PointerType *VoidPtr = PointerType::get(Type::Int8Ty);
ValueSymbolTable &SymTab = getValueSymbolTable();
// See if we have a definition for the specified function already.
- Function *F = dyn_cast_or_null<Function>(SymTab.lookup(Name));
+ GlobalValue *F = dyn_cast_or_null<GlobalValue>(SymTab.lookup(Name));
if (F == 0) {
// Nope, add it
Function *New = new Function(Ty, GlobalVariable::ExternalLinkage, Name);
// If the function exists but has the wrong type, return a bitcast to the
// right type.
- if (F->getFunctionType() != Ty)
+ if (F->getType() != PointerType::get(Ty))
return ConstantExpr::getBitCast(F, PointerType::get(Ty));
// Otherwise, we just found the existing function or a prototype.
//if main isn't present, claim there is no problem
if (KeepMain && find(Funcs.begin(), Funcs.end(),
- BD.getProgram()->getMainFunction()) == Funcs.end())
+ BD.getProgram()->getFunction("main")) == Funcs.end())
return false;
// Clone the program to try hacking it apart...
// 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");
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()) {
// using the contents of Args to determine argc & argv, and the contents of
// EnvVars to determine envp.
//
- Function *Fn = MP->getModule()->getMainFunction();
+ Function *Fn = MP->getModule()->getFunction("main");
if (!Fn) {
std::cerr << "'main' function not found in module.\n";
return -1;
if (const FunctionType *FTy =
dyn_cast<FunctionType>(PTy->getElementType()))
if (Function *OtherF =
- CurModule.CurrentModule->getNamedFunction(DID.getName()))
+ CurModule.CurrentModule->getFunction(DID.getName()))
if (FuncTysDifferOnlyBySRet(FTy,OtherF->getFunctionType())) {
V->replaceAllUsesWith(ConstantExpr::getBitCast(OtherF, PTy));
fixed = true;
//Not all functions use vaarg, so make a second check for ObsoleteVarArgs
{
Function* F;
- if ((F = Result->getNamedFunction("llvm.va_start"))
+ if ((F = Result->getFunction("llvm.va_start"))
&& F->getFunctionType()->getNumParams() == 0)
ObsoleteVarArgs = true;
- if((F = Result->getNamedFunction("llvm.va_copy"))
+ if((F = Result->getFunction("llvm.va_copy"))
&& F->getFunctionType()->getNumParams() == 1)
ObsoleteVarArgs = true;
}
}
if(ObsoleteVarArgs) {
- if(Function* F = Result->getNamedFunction("llvm.va_start")) {
+ if(Function* F = Result->getFunction("llvm.va_start")) {
if (F->arg_size() != 0) {
error("Obsolete va_start takes 0 argument");
return 0;
Result->getFunctionList().erase(F);
}
- if(Function* F = Result->getNamedFunction("llvm.va_end")) {
+ if(Function* F = Result->getFunction("llvm.va_end")) {
if(F->arg_size() != 1) {
error("Obsolete va_end takes 1 argument");
return 0;
Result->getFunctionList().erase(F);
}
- if(Function* F = Result->getNamedFunction("llvm.va_copy")) {
+ if(Function* F = Result->getFunction("llvm.va_copy")) {
if(F->arg_size() != 1) {
error("Obsolete va_copy takes 1 argument");
return 0;
if (const FunctionType *FTy =
dyn_cast<FunctionType>(PTy->getElementType()))
if (Function *OtherF =
- CurModule.CurrentModule->getNamedFunction(DID.getName()))
+ CurModule.CurrentModule->getFunction(DID.getName()))
if (FuncTysDifferOnlyBySRet(FTy,OtherF->getFunctionType())) {
V->replaceAllUsesWith(ConstantExpr::getBitCast(OtherF, PTy));
fixed = true;
//Not all functions use vaarg, so make a second check for ObsoleteVarArgs
{
Function* F;
- if ((F = Result->getNamedFunction("llvm.va_start"))
+ if ((F = Result->getFunction("llvm.va_start"))
&& F->getFunctionType()->getNumParams() == 0)
ObsoleteVarArgs = true;
- if((F = Result->getNamedFunction("llvm.va_copy"))
+ if((F = Result->getFunction("llvm.va_copy"))
&& F->getFunctionType()->getNumParams() == 1)
ObsoleteVarArgs = true;
}
}
if(ObsoleteVarArgs) {
- if(Function* F = Result->getNamedFunction("llvm.va_start")) {
+ if(Function* F = Result->getFunction("llvm.va_start")) {
if (F->arg_size() != 0) {
error("Obsolete va_start takes 0 argument");
return 0;
Result->getFunctionList().erase(F);
}
- if(Function* F = Result->getNamedFunction("llvm.va_end")) {
+ if(Function* F = Result->getFunction("llvm.va_end")) {
if(F->arg_size() != 1) {
error("Obsolete va_end takes 1 argument");
return 0;
Result->getFunctionList().erase(F);
}
- if(Function* F = Result->getNamedFunction("llvm.va_copy")) {
+ if(Function* F = Result->getFunction("llvm.va_copy")) {
if(F->arg_size() != 1) {
error("Obsolete va_copy takes 1 argument");
return 0;
if (const FunctionType *FTy =
dyn_cast<FunctionType>(PTy->getElementType()))
if (Function *OtherF =
- CurModule.CurrentModule->getNamedFunction(DID.getName()))
+ CurModule.CurrentModule->getFunction(DID.getName()))
if (FuncTysDifferOnlyBySRet(FTy,OtherF->getFunctionType())) {
V->replaceAllUsesWith(ConstantExpr::getBitCast(OtherF, PTy));
fixed = true;
//Not all functions use vaarg, so make a second check for ObsoleteVarArgs
{
Function* F;
- if ((F = Result->getNamedFunction("llvm.va_start"))
+ if ((F = Result->getFunction("llvm.va_start"))
&& F->getFunctionType()->getNumParams() == 0)
ObsoleteVarArgs = true;
- if((F = Result->getNamedFunction("llvm.va_copy"))
+ if((F = Result->getFunction("llvm.va_copy"))
&& F->getFunctionType()->getNumParams() == 1)
ObsoleteVarArgs = true;
}
}
if(ObsoleteVarArgs) {
- if(Function* F = Result->getNamedFunction("llvm.va_start")) {
+ if(Function* F = Result->getFunction("llvm.va_start")) {
if (F->arg_size() != 0) {
error("Obsolete va_start takes 0 argument");
return 0;
Result->getFunctionList().erase(F);
}
- if(Function* F = Result->getNamedFunction("llvm.va_end")) {
+ if(Function* F = Result->getFunction("llvm.va_end")) {
if(F->arg_size() != 1) {
error("Obsolete va_end takes 1 argument");
return 0;
Result->getFunctionList().erase(F);
}
- if(Function* F = Result->getNamedFunction("llvm.va_copy")) {
+ if(Function* F = Result->getFunction("llvm.va_copy")) {
if(F->arg_size() != 1) {
error("Obsolete va_copy takes 1 argument");
return 0;
}
void CppWriter::printInline(const std::string& fname, const std::string& func) {
- const Function* F = TheModule->getNamedFunction(func);
+ const Function* F = TheModule->getFunction(func);
if (!F) {
error(std::string("Function '") + func + "' not found in input module");
return;
const std::string& fname, // Name of generated function
const std::string& funcName // Name of function to generate
) {
- const Function* F = TheModule->getNamedFunction(funcName);
+ const Function* F = TheModule->getFunction(funcName);
if (!F) {
error(std::string("Function '") + funcName + "' not found in input module");
return;