<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 12, 2015 at 8:51 PM, Shen Liu <span dir="ltr"><<a href="mailto:shl413@lehigh.edu" target="_blank">shl413@lehigh.edu</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"><span class=""><span style="font-size:12.8px">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.</span></span><div style="font-size:12.8px">, which implies it is a callinst. Since it is not a CallInst, why does llvm add an opcode "call" before it? It looks a little weird here. </div></div></blockquote><div><br></div><div>It is a CallInst, hence whwy you can call getCalledFunction - but you just don't get an answer. It's a call, but not to a function. It's a call to a bitcast of a function. So the operand(0) is not a Function, but a BitCastInst (or a constant, I forget how they work).</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span class="HOEnZb"><font color="#888888"><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Shen</div></font></span></div><div class="gmail_extra"><br><div class="gmail_quote"><span class="">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></span><div><div class="h5"><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>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></div></div><br></div>
</blockquote></div><br></div></div>