Hi, all.
I have noticed that LLVM supports some Intrinsic Functions such as "__llvm.sadd.with.overflow" described in http://llvm.org/docs/LangRef.html#int_sadd_overflow. We can use these functions and needn’t define the function bodies.
And now, my question is “How to produce such a call instruction using the LLVM classes?”
I have also noticed that LLVM provides some classes like "MemCpyInst" to wrap the "llvm.memcpy" Intrinsic. But other intrinsic functions such as "__llvm.sadd.with.overflow" I’ve mentioned above don’t have the corresponding classes. How to deal with it?
You can use your module to get the function or if not available create the function and use it like any other functions you may have. This how I do :
Function fun = 0;
if ((fun=module->getFunction(“llvm.sadd.with.overflow”))==0) {
vector<Type*> fun_arguments;
fun_arguments.push_back(…); //depends on your type
fun_arguments.push_back(…); //depends on your type
FunctionType *fun_type = FunctionType::get(Type::VoidTy, fun_arguments, false);
fun = llvm::Function::Create(fun_type, GlobalValue::ExternalLinkage, “llvm.sadd.with.overflow”, module);
}
// insert your call to fun here
I have also noticed that LLVM provides some classes like
"/*MemCpyInst"*/ to wrap the "/*llvm.memcpy"*/ Intrinsic. But other
intrinsic functions such as /*"*//*llvm.sadd.with.overflow"*/ I've
mentioned above don't have the corresponding classes. How to deal with it?
For special instruction set intrinsics like SSE, you can use
Intrinsic::getDeclaration() which returns an llvm::Function* :
Intrinsic::getDeclaration(module, Intrinsic::sadd_with_overflow);
Have a look at include/llvm/Intrinsics.gen for the exact names.