Be a good little compiler and handle direct calls efficiently, even if there

are beastly ConstantPointerRefs in the way...


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11883 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2004-02-26 22:07:22 +00:00
parent 71e353ed35
commit cb582406dd

View File

@ -465,8 +465,12 @@ void GraphBuilder::visitInvokeInst(InvokeInst &II) {
} }
void GraphBuilder::visitCallSite(CallSite CS) { void GraphBuilder::visitCallSite(CallSite CS) {
Value *Callee = CS.getCalledValue();
if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(Callee))
Callee = CPR->getValue();
// Special case handling of certain libc allocation functions here. // Special case handling of certain libc allocation functions here.
if (Function *F = CS.getCalledFunction()) if (Function *F = dyn_cast<Function>(Callee))
if (F->isExternal()) if (F->isExternal())
switch (F->getIntrinsicID()) { switch (F->getIntrinsicID()) {
case Intrinsic::memmove: case Intrinsic::memmove:
@ -809,12 +813,11 @@ void GraphBuilder::visitCallSite(CallSite CS) {
if (isPointerType(I->getType())) if (isPointerType(I->getType()))
RetVal = getValueDest(*I); RetVal = getValueDest(*I);
DSNode *Callee = 0; DSNode *CalleeNode = 0;
if (DisableDirectCallOpt || !isa<Function>(CS.getCalledValue())) { if (DisableDirectCallOpt || !isa<Function>(Callee)) {
Callee = getValueDest(*CS.getCalledValue()).getNode(); CalleeNode = getValueDest(*Callee).getNode();
if (Callee == 0) { if (CalleeNode == 0) {
std::cerr << "WARNING: Program is calling through a null pointer?\n" std::cerr << "WARNING: Program is calling through a null pointer?\n"<< *I;
<< *I;
return; // Calling a null pointer? return; // Calling a null pointer?
} }
} }
@ -828,10 +831,10 @@ void GraphBuilder::visitCallSite(CallSite CS) {
Args.push_back(getValueDest(**I)); Args.push_back(getValueDest(**I));
// Add a new function call entry... // Add a new function call entry...
if (Callee) if (CalleeNode)
FunctionCalls->push_back(DSCallSite(CS, RetVal, Callee, Args)); FunctionCalls->push_back(DSCallSite(CS, RetVal, CalleeNode, Args));
else else
FunctionCalls->push_back(DSCallSite(CS, RetVal, CS.getCalledFunction(), FunctionCalls->push_back(DSCallSite(CS, RetVal, cast<Function>(Callee),
Args)); Args));
} }