Inserting an Intrinsic in LLVM IR

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);
Value *recurCall1 = builder.CreateCall2(fun,arg_type[0],arg_type[1]);

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.

Thanks!

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. Your argument to CreateCall2 are wrong. You need to pass the Values representing your arguments, not the Types representing the types of those arguments. 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.