<div dir="ltr">Thanks for your helpful answer David! But one thing still makes me confused is when i use isa<CallInst> to check the original instruction the answser is yes.<div>, which implies it is a callinst. Since it is not a BitcastInst, why does llvm add an opcode "call" before it? It looks a little weird here.  </div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 12, 2015 at 10:48 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Thu, Nov 12, 2015 at 7:27 PM, Shen Liu via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi all,<div><br></div><div>Usually if we want to get the called Function we can directly use CallInst->getCalledFunction(), however, today i encounter an unusual CallInst as follows:</div><div><br></div><div> %call11 = call double (...)* bitcast (double ()* @quantum_frand to double (...)*)()<br></div><div><br></div><div>the original C source involve type cast:</div><div><br></div><div>float u,v;<br></div><div>extern double quantum_frand();<br></div><div><div><span style="white-space:pre-wrap">        </span>    u = 2 * quantum_frand() - 1;</div><div><span style="white-space:pre-wrap">       </span>    v = 2 * quantum_frand() - 1;</div></div><div><br></div><div>In this case, CallInst->getCalledFunction() returns a nullptr unusually, I printed out the getOperand(0) and found the operand is the whole thing of  "double (...)* bitcast (double ()* @quantum_frand to double (...)*)()". Any member function calling on that fails so i don't know whether there is an efficient way to exactly get the called function @quantum_frand(...) here?</div></div></blockquote><div><br></div></span><div>What you have is a BitCastInst, so you'd have to downcast the Value* to that, then look through the bitcast.<br><br>But realize you may never actually find a function in the end:<br><br>void func(void (*f)(void)) {<br>  f();<br>}<br><br>the f call is a call to a function pointer, so there is no statically knowable called function here. Your code will probably need to handle the case where this arises.<br><br>- David</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div> Thanks!</div><div><br></div><div><br></div><div>Best regards,</div><div><br></div><div>Shen</div><div><br></div><div><br></div><div><br></div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div></div>
</blockquote></div><br></div>