Bob Floyd
2014-Mar-31 16:30 UTC
[LLVMdev] Request for guidance calling math routines, e.g. log, tan
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. Is it as simple as a call to `Module::getFunction( "llvm.log.f128" )` for the `Value*` required by `IRBuilder::CreateCall(Value*,..)` ? Then, where is the definition of "llvm.log.f128"? Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140331/d33032a2/attachment.html>
Tim Northover
2014-Mar-31 17:27 UTC
[LLVMdev] Request for guidance calling math routines, e.g. log, tan
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.