MCPcopy Create free account
hub / github.com/GANGE666/xVMP / getOrInsertFunction

Method getOrInsertFunction

src/lib/IR/Module.cpp:144–166  ·  view source on GitHub ↗

getOrInsertFunction - Look up the specified function in the module symbol 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.

Source from the content-addressed store, hash-verified

142// the symbol table directly for this common task.
143//
144Constant *Module::getOrInsertFunction(StringRef Name, FunctionType *Ty,
145 AttributeList AttributeList) {
146 // See if we have a definition for the specified function already.
147 GlobalValue *F = getNamedValue(Name);
148 if (!F) {
149 // Nope, add it
150 Function *New = Function::Create(Ty, GlobalVariable::ExternalLinkage,
151 DL.getProgramAddressSpace(), Name);
152 if (!New->isIntrinsic()) // Intrinsics get attrs set on construction
153 New->setAttributes(AttributeList);
154 FunctionList.push_back(New);
155 return New; // Return the new prototype.
156 }
157
158 // If the function exists but has the wrong type, return a bitcast to the
159 // right type.
160 auto *PTy = PointerType::get(Ty, F->getAddressSpace());
161 if (F->getType() != PTy)
162 return ConstantExpr::getBitCast(F, PTy);
163
164 // Otherwise, we just found the existing function or a prototype.
165 return F;
166}
167
168Constant *Module::getOrInsertFunction(StringRef Name,
169 FunctionType *Ty) {

Callers 15

EmitCfiSlowPathCheckMethod · 0.45
CleanupAndPrepareModulesFunction · 0.45
mainFunction · 0.45
getDeclarationMethod · 0.45
createMallocFunction · 0.45
createFreeFunction · 0.45
runOnFunctionMethod · 0.45
checkStackGuardMethod · 0.45
runMethod · 0.45
CreateFailBBMethod · 0.45
prepareEHPadsMethod · 0.45

Calls 8

getFunction · 0.50
AttributeListClass · 0.50
isIntrinsicMethod · 0.45
setAttributesMethod · 0.45
push_backMethod · 0.45
getAddressSpaceMethod · 0.45
getTypeMethod · 0.45

Tested by 10

TESTFunction · 0.36
getFunctionMethod · 0.36
testRoundTripMethod · 0.36
TEST_FFunction · 0.36
TEST_FFunction · 0.36
TEST_FFunction · 0.36
TESTFunction · 0.36
TESTFunction · 0.36
TEST_FFunction · 0.36