<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">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<br>
<br>
On 3/12/15 11:24 PM, Kevin Hu wrote:<br>
</div>
<blockquote
cite="mid:CAH_2Da38unemsiyexR7Acc5+aJMOwA_8mS1yXb1Bc5-Cfc8m2w@mail.gmail.com"
type="cite">
<meta http-equiv="Context-Type" content="text/html; charset=UTF-8">
<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 moz-do-not-send="true" 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 moz-do-not-send="true"
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 class="h5">On Thu, Mar 12, 2015 at 3:00 PM,
Kevin Hu <span dir="ltr"><<a
moz-do-not-send="true"
href="mailto:hxy9243@gmail.com"
target="_blank">hxy9243@gmail.com</a>></span>
wrote:<br>
</div>
</div>
<blockquote class="gmail_quote">
<div>
<div class="h5">
<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 moz-do-not-send="true"
href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>
<a moz-do-not-send="true"
href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a moz-do-not-send="true"
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 class="gmail_signature">
<div dir="ltr">Yours,
<div>X. Hu</div>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a class="moz-txt-link-freetext" href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a>
<a class="moz-txt-link-freetext" href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a>
</pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a class="moz-txt-link-freetext" href="http://www.cs.rochester.edu/u/criswell">http://www.cs.rochester.edu/u/criswell</a></pre>
</body>
</html>