How to produce a "Intrinsic Function" call instruction?

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.

For example, I can manually insert codes:

%res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
%sum = extractvalue {i32, i1} %res, 0
%obit = extractvalue {i32, i1} %res, 1
br i1 %obit, label %overflow, label %normal

into an assembly file, and it works OK.

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?

Anyone could help me? Thank you!

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

Olivier.

Hey,

?? wrote:

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.

Cheers,
Ralf