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

Hi Bob,

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.