I am doing inter-procedural static analysis, so I need to do DFS of call graph. llvm-gcc sometimes generates this kind of call instruction, which cause the call graph to be incomplete. <br><br>But thanks for your information, instcombine really solves the problem.
<br><br><div><span class="gmail_quote">On 7/17/07, <b class="gmail_sendername">Chris Lattner</b> <<a href="mailto:sabre@nondot.org">sabre@nondot.org</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Thu, 12 Jul 2007, Zhongxing Xu wrote:<br>> The current BasicCallGraph will miss call sites like this:<br>> %tmp86 = call i8* (...)* bitcast (i8* ()* @find_ispell to i8* (...)*)( )<br>> ; <i8*> [#uses=1]
<br>><br>> Here the direct user of @find_ispell is a ConstantExpr.<br>> I added several lines of code to address this case.<br>> Below is the output of command: svn diff lib/Analysis/IPA/CallGraph.cpp<br>> Attached is LLVM asm files with such function calls.
<br><br>This is problematic, because it's not checking for the type of constant<br>expr (i.e. is it a bitcast, etc). That can easily be fixed, but here's a<br>basic question: when is this important? The instcombine pass should fix
<br>up these bitcasts, so they shouldn't occur frequently in practice. When<br>have you found this to be important?<br><br>Thanks,<br><br>-Chris<br><br>> Index: lib/Analysis/IPA/CallGraph.cpp<br>> ===================================================================
<br>> --- lib/Analysis/IPA/CallGraph.cpp (revision 39771)<br>> +++ lib/Analysis/IPA/CallGraph.cpp (working copy)<br>> @@ -13,6 +13,7 @@<br>> //===----------------------------------------------------------------------===//
<br>><br>><br>> #include "llvm/Analysis/CallGraph.h"<br>> +#include "llvm/Constants.h"<br>> # include "llvm/Module.h"<br>> # include "llvm/Instructions.h"<br>> # include "llvm/Support/CallSite.h"
<br>> @@ -150,6 +151,19 @@<br>> -> addCalledFunction(CS, Node);<br>> else<br>> isUsedExternally = true;<br>> + } else if (ConstantExpr* CE = dyn_cast<ConstantExpr>(*I)) {
<br>> + for (Value::use_iterator I = CE->use_begin(), E = CE->use_end();<br>> + I != E; ++I)<br>> + if (Instruction* Inst = dyn_cast<Instruction>(*I)) {<br>> + CallSite CS = CallSite::get(Inst);
<br>> + if (isOnlyADirectCall(F, CS))<br>> + getOrInsertFunction(Inst->getParent()->getParent())<br>> + ->addCalledFunction(CS, Node);<br>> + else<br>
> + isUsedExternally = true;<br>> + } else {<br>> + isUsedExternally = true;<br>> + }<br>> } else if (GlobalValue *GV = dyn_cast<GlobalValue>(*I)) {<br>
> for (Value::use_iterator I = GV->use_begin(), E = GV->use_end();<br>> I != E; ++I)<br>><br>><br><br>-Chris<br><br>--<br><a href="http://nondot.org/sabre/">http://nondot.org/sabre/
</a><br><a href="http://llvm.org/">http://llvm.org/</a><br>_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu">
http://llvm.cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br></blockquote></div><br>