[llvm-dev] JIT compiler and calls to existing functions

Caldarale, Charles R via llvm-dev llvm-dev at lists.llvm.org
Mon Mar 28 05:40:01 PDT 2016


> From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] 
> On Behalf Of Russell Wallace via llvm-dev
> Subject: [llvm-dev] JIT compiler and calls to existing functions

> In the context of a JIT compiler, what's the recommended way to generate a call to an 
> existing function, that is, not one that you are generating on-the-fly with LLVM, but 
> one that's already linked into your program? For example the cosine function (from the 
> standard math library); the Kaleidoscope tutorial recommends looking it up by name with 
> dlsym("cos"), but it seems to me that it should be possible to use a more efficient and 
> portable solution that takes advantage of the fact that you already have an actual pointer 
> to cos, even if you haven't linked with debugging symbols.

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.

 - Chuck



More information about the llvm-dev mailing list