<div dir="ltr">That seems to work, thanks! The specific code I ended up with to call int64_t print(int64_t) looks like:<div><br></div><div><div>        auto f = builder.CreateIntToPtr(</div><div>            ConstantInt::get(builder.getInt64Ty(), uintptr_t(print)),</div><div>            PointerType::getUnqual(FunctionType::get(</div><div>                builder.getInt64Ty(), {builder.getInt64Ty()}, false)));</div><div>        return builder.CreateCall(f, args);</div></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 28, 2016 at 1:40 PM, Caldarale, Charles R <span dir="ltr"><<a href="mailto:Chuck.Caldarale@unisys.com" target="_blank">Chuck.Caldarale@unisys.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">> From: llvm-dev [mailto:<a href="mailto:llvm-dev-bounces@lists.llvm.org">llvm-dev-bounces@lists.llvm.org</a>]<br>
> On Behalf Of Russell Wallace via llvm-dev<br>
> Subject: [llvm-dev] JIT compiler and calls to existing functions<br>
<div><div class="h5"><br>
> In the context of a JIT compiler, what's the recommended way to generate a call to an<br>
> existing function, that is, not one that you are generating on-the-fly with LLVM, but<br>
> one that's already linked into your program? For example the cosine function (from the<br>
> standard math library); the Kaleidoscope tutorial recommends looking it up by name with<br>
> dlsym("cos"), but it seems to me that it should be possible to use a more efficient and<br>
> portable solution that takes advantage of the fact that you already have an actual pointer<br>
> to cos, even if you haven't linked with debugging symbols.<br>
<br>
</div></div>Perhaps not the most elegant, but we simply use the IRBuilder.CreateIntToPtr() method to construct the Callee argument for IRBuilder.CreateCall().  The first argument for CreateIntToPtr() comes from ConstantInt::get(I64, uintptr_t(ptr)), while the second is a function type pointer defined by using PointerType::get() on the result of FunctionType::get() with the appropriate function signature.<br>
<br>
 - Chuck<br>
<br>
</blockquote></div><br></div>