[LLVMdev] Inserting an Intrinsic in LLVM IR

Philip Reames listmail at philipreames.com
Tue Jun 24 09:55:00 PDT 2014


On 06/23/2014 09:24 PM, pratik dand wrote:
> Dear,
>
> I have defined an intrinsic in IntrinsicsX86.td and want to insert 
> this intrinsic in a basic block of IR.
>
>  Module* mod = new Module("test", getGlobalContext());
>  BasicBlock* block = BasicBlock::Create(getGlobalContext(), "entry", 
> temp);
>  IRBuilder<> builder(block);
>  std::vector<Type *> arg_type;
>  arg_type.push_back(IntegerType::get(getGlobalContext(),32));
>  arg_type.push_back(IntegerType::get(getGlobalContext(),32));
>
>   Function *fun = Intrinsic::getDeclaration(mod, 
> Intrinsic::int_x86_addenc_32,arg_type);
You only need to specify the argument types if your intrinsic uses an 
"any" type in it's definition.  Given what you described, it doesn't 
sound like you need to.  You should drop the last argument.
>   Value *recurCall1 = builder.CreateCall2(fun,arg_type[0],arg_type[1]);
Your argument to CreateCall2 are wrong.  You need to pass the Values 
representing your arguments, not the Types representing the types of 
those arguments.
>
>
> The int_addenc_32 instrinsic takes in 2 i32 and returns 1 i32. There 
> is some problem in the last two lines of my code and I am able to 
> figure it out.
> Any help would be appreciated.
In general, providing the stack trace or error messages would help. 
Didn't need them in this case, but it will help you get better responses 
in the future.
>
> Thanks!
>
> -- 
> Pratik
>
>
>
> _______________________________________________
> 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/20140624/f2634503/attachment.html>


More information about the llvm-dev mailing list