[LLVMdev] Request for guidance calling math routines, e.g. log, tan
Tim Northover
t.p.northover at gmail.com
Mon Mar 31 10:27:37 PDT 2014
Hi Bob,
On 31 March 2014 17:30, Bob Floyd <bobfloyd at comcast.net> wrote:
> I am populating llvm via. IRBuilder followed by JIT, and need to call math
> functions, e.g. log, tan, but seem to be in outer space on how this is done
> in llvm.
There are two ways to do it (differing in how you get the "Function *"
that you use in Builder.CreateCall). If LLVM knows about that
function, you can call Intrinsic::getDeclaration. In this case,
something like:
Type *F128Ty = Type::getFP128Ty(Ctx);
Function *Log = Intrinsic::getDeclaration(Intrinsic::log, F128Ty);
That probably covers most of the maths function, but if LLVM doesn't
know about something you'd have to use Module::getOrInsertFunction,
describing the entire prototype. In this case perhaps:
Function *Log = M->GetOrInsertFunction("logl", F128Ty, F128Ty, NULL);
> Is it as simple as a call to `Module::getFunction( "llvm.log.f128" )` for
> the `Value*` required by `IRBuilder::CreateCall(Value*,..)` ?
What you get back from getFunction (assuming it's valid and not
nullptr) will be suitable for use in CreateCall.
Cheers.
Tim.
More information about the llvm-dev
mailing list