<div dir="ltr">Dear John and David,<div><br></div><div><br></div><div>Many thanks. It works this way.</div><div><br></div><div>Thanks a lot for the guidance.</div><div><br></div><div><br></div><div>Regards,</div><div>Kevin</div><div><img src="http://t.signauxdeux.com/e1t/o/5/f18dQhb0S1Ll8dDMPbW2n0x6l2B9gXrW7sKj5C56dQtgf3ZlND602?si=5235970534801408&pi=c9fea7e5-6c28-4f29-bc72-e81143be0711" width="1" height="1" style="display:none"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 13, 2015 at 4:52 AM, John Criswell <span dir="ltr"><<a href="mailto:jtcriswel@gmail.com" target="_blank">jtcriswel@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 bgcolor="#FFFFFF" text="#000000">
<div>Dear Kevin,<br>
<br>
In the LLVM IR, the function and the pointer to the function are
the same thing. Within an LLVM pass, if you have a pointer to a
Function object:<br>
<br>
Function * F = M.getOrInsertFunction(...)<br>
<br>
... then you can use F as a parameter to a call instruction:<br>
<br>
std::vector<Value *> args;<br>
args.push_back (F);<br>
CallInst * CI = CallInst::Create (AtExit, args, ...);<br>
<br>
Regards,<br>
<br>
John Criswell<div><div class="h5"><br>
<br>
On 3/12/15 11:24 PM, Kevin Hu wrote:<br>
</div></div></div><div><div class="h5">
<blockquote type="cite">
<div dir="ltr">Hi David,
<div><br>
</div>
<div><br>
</div>
<div>Thanks very much.</div>
<div><br>
</div>
<div>I tried and the IR it produces is:</div>
<div><br>
</div>
<div>%call = call i32 @atexit(void ()* foo)</div>
<div><br>
</div>
<div>The problem is this still doesn't give me any clues how to
produce the code inside my LLVM pass. How do I get the pointer
to this foo function?</div>
<div><br>
</div>
<div>Any hints?</div>
<div><br>
</div>
<div><br>
</div>
<div>Thank you.</div>
<div>Kevin Hu</div>
<img height="1" width="1"></div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Thu, Mar 12, 2015 at 6:09 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">
<div dir="ltr">Easiest thing to do would be to write the
equivalent C code, throw it through Clang, and look at the
IR it produces.<br>
<div class="gmail_extra"><br>
<div class="gmail_quote">
<div>
<div>On Thu, Mar 12, 2015 at 3:00 PM,
Kevin Hu <span dir="ltr"><<a href="mailto:hxy9243@gmail.com" target="_blank">hxy9243@gmail.com</a>></span>
wrote:<br>
</div>
</div>
<blockquote class="gmail_quote">
<div>
<div>
<div dir="ltr">Dear all,
<div><br>
</div>
<div><br>
</div>
<div>I'm writing an LLVM pass, and I want to
insert a call instruction that takes a
function pointer as a parameter. The effect
would be the same as following:</div>
<div><br>
</div>
<div>atexit(foo);</div>
<div><br>
</div>
<div>Where foo is a function I insert with
M.getOrInsertFunction(), which in LLVM is a
Function class.</div>
<div><br>
</div>
<div>I searched for a while and did not come
up with a satisfying answer. Should I create
a Value class of pointer type, or a Int64Ty
for a pointer? How do I get the pointer to
the function I create? I also tried passing
foo as Function* in LLVM as parameter to
create CallInst directly, and I doesn't seem
to work.</div>
<div>
<div><br>
</div>
<div>Any hints and enlightenment is
appreciated. Many thanks.</div>
<div><br>
</div>
<div><br>
</div>
Regards,<br>
<div>
<div dir="ltr">Yours,
<div>Kevin Hu</div>
</div>
</div>
</div>
</div>
<br>
</div>
</div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>
<a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br>
</blockquote>
</div>
<br>
</div>
</div>
</blockquote>
</div>
<br>
<br>
<div><br>
</div>
-- <br>
<div>
<div dir="ltr">Yours,
<div>X. Hu</div>
</div>
</div>
</div>
<br>
<fieldset></fieldset>
<br>
<pre>_______________________________________________
LLVM Developers mailing list
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a>
</pre>
</blockquote>
<br>
<br>
</div></div><span class="HOEnZb"><font color="#888888"><pre cols="72">--
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a href="http://www.cs.rochester.edu/u/criswell" target="_blank">http://www.cs.rochester.edu/u/criswell</a></pre>
</font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Yours,<div>X. Hu</div></div></div>
</div></div></div>