[LLVMdev] How to produce a "Intrinsic Function" call instruction?

Olivier Meurant meurant.olivier at gmail.com
Thu Jul 30 02:05:22 PDT 2009


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.


On Thu, Jul 30, 2009 at 10:38 AM, 张超 <gausszhch at gmail.com> wrote:

> 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!
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090730/29ec6d41/attachment.html>


More information about the llvm-dev mailing list