mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-21 18:24:23 +00:00
Change the interface to Module::getOrInsertFunction to be easier to use,
to resolve PR1088, and to help PR411. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32988 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -166,15 +166,21 @@ public:
|
|||||||
/// @{
|
/// @{
|
||||||
public:
|
public:
|
||||||
/// getOrInsertFunction - Look up the specified function in the module symbol
|
/// getOrInsertFunction - Look up the specified function in the module symbol
|
||||||
/// table. If it does not exist, add a prototype for the function and return
|
/// table. Four possibilities:
|
||||||
/// it.
|
/// 1. If it does not exist, add a prototype for the function and return it.
|
||||||
Function *getOrInsertFunction(const std::string &Name, const FunctionType *T);
|
/// 2. If it exists, and has internal linkage, the existing function is
|
||||||
|
/// renamed and a new one is inserted.
|
||||||
|
/// 3. Otherwise, if the existing function has the correct prototype, return
|
||||||
|
/// the existing function.
|
||||||
|
/// 4. Finally, the function exists but has the wrong prototype: return the
|
||||||
|
/// function with a constantexpr cast to the right prototype.
|
||||||
|
Constant *getOrInsertFunction(const std::string &Name, const FunctionType *T);
|
||||||
|
|
||||||
/// getOrInsertFunction - Look up the specified function in the module symbol
|
/// getOrInsertFunction - Look up the specified function in the module symbol
|
||||||
/// table. If it does not exist, add a prototype for the function and return
|
/// table. If it does not exist, add a prototype for the function and return
|
||||||
/// it. This version of the method takes a null terminated list of function
|
/// it. This version of the method takes a null terminated list of function
|
||||||
/// arguments, which makes it easier for clients to use.
|
/// arguments, which makes it easier for clients to use.
|
||||||
Function *getOrInsertFunction(const std::string &Name, const Type *RetTy,...)
|
Constant *getOrInsertFunction(const std::string &Name, const Type *RetTy,...)
|
||||||
END_WITH_NULL;
|
END_WITH_NULL;
|
||||||
|
|
||||||
/// getFunction - Look up the specified function in the module symbol table.
|
/// getFunction - Look up the specified function in the module symbol table.
|
||||||
|
@ -152,23 +152,35 @@ void Module::setPointerSize(PointerSize PS) {
|
|||||||
// Methods for easy access to the functions in the module.
|
// Methods for easy access to the functions in the module.
|
||||||
//
|
//
|
||||||
|
|
||||||
// getOrInsertFunction - Look up the specified function in the module symbol
|
Constant *Module::getOrInsertFunction(const std::string &Name,
|
||||||
// table. If it does not exist, add a prototype for the function and return
|
|
||||||
// it. This is nice because it allows most passes to get away with not handling
|
|
||||||
// the symbol table directly for this common task.
|
|
||||||
//
|
|
||||||
Function *Module::getOrInsertFunction(const std::string &Name,
|
|
||||||
const FunctionType *Ty) {
|
const FunctionType *Ty) {
|
||||||
SymbolTable &SymTab = getValueSymbolTable();
|
SymbolTable &SymTab = getValueSymbolTable();
|
||||||
|
|
||||||
// See if we have a definitions for the specified function already...
|
// See if we have a definitions for the specified function already.
|
||||||
if (Value *V = SymTab.lookup(PointerType::get(Ty), Name)) {
|
Function *F =
|
||||||
return cast<Function>(V); // Yup, got it
|
dyn_cast_or_null<Function>(SymTab.lookup(PointerType::get(Ty), Name));
|
||||||
} else { // Nope, add one
|
if (F == 0) {
|
||||||
|
// Nope, add it.
|
||||||
Function *New = new Function(Ty, GlobalVariable::ExternalLinkage, Name);
|
Function *New = new Function(Ty, GlobalVariable::ExternalLinkage, Name);
|
||||||
FunctionList.push_back(New);
|
FunctionList.push_back(New);
|
||||||
return New; // Return the new prototype...
|
return New; // Return the new prototype.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Okay, the function exists. Does it have externally visible linkage?
|
||||||
|
if (F->hasInternalLinkage()) {
|
||||||
|
// Rename the function.
|
||||||
|
F->setName(SymTab.getUniqueName(F->getType(), F->getName()));
|
||||||
|
// Retry, now there won't be a conflict.
|
||||||
|
return getOrInsertFunction(Name, Ty);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the function exists but has the wrong type, return a bitcast to the
|
||||||
|
// right type.
|
||||||
|
if (F->getFunctionType() != Ty)
|
||||||
|
return ConstantExpr::getBitCast(F, PointerType::get(Ty));
|
||||||
|
|
||||||
|
// Otherwise, we just found the existing function or a prototype.
|
||||||
|
return F;
|
||||||
}
|
}
|
||||||
|
|
||||||
// getOrInsertFunction - Look up the specified function in the module symbol
|
// getOrInsertFunction - Look up the specified function in the module symbol
|
||||||
@ -176,7 +188,7 @@ Function *Module::getOrInsertFunction(const std::string &Name,
|
|||||||
// This version of the method takes a null terminated list of function
|
// This version of the method takes a null terminated list of function
|
||||||
// arguments, which makes it easier for clients to use.
|
// arguments, which makes it easier for clients to use.
|
||||||
//
|
//
|
||||||
Function *Module::getOrInsertFunction(const std::string &Name,
|
Constant *Module::getOrInsertFunction(const std::string &Name,
|
||||||
const Type *RetTy, ...) {
|
const Type *RetTy, ...) {
|
||||||
va_list Args;
|
va_list Args;
|
||||||
va_start(Args, RetTy);
|
va_start(Args, RetTy);
|
||||||
|
Reference in New Issue
Block a user