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 :<br><br>Function fun = 0;<br>if ((fun=module->getFunction("llvm.sadd.with.overflow"))==0) {<br>
vector<Type*> fun_arguments;<br>fun_arguments.push_back(...); //depends on your type<br>fun_arguments.push_back(...); //depends on your type<br>FunctionType *fun_type = FunctionType::get(Type::VoidTy, fun_arguments, false);<br>
fun = llvm::Function::Create(fun_type, GlobalValue::ExternalLinkage, "llvm.sadd.with.overflow", module);<br>}<br>// insert your call to fun here<br><br><br>Olivier.<br><br><br><div class="gmail_quote">On Thu, Jul 30, 2009 at 10:38 AM, 张超 <span dir="ltr"><<a href="mailto:gausszhch@gmail.com">gausszhch@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div>Hi, all.</div>
<div>I have noticed that LLVM supports some Intrinsic Functions such as <i><b>"</b></i><font face="Courier New"><i><b>llvm.sadd.with.overflow"</b></i> described in <font face="Arial"><a href="http://llvm.org/docs/LangRef.html#int_sadd_overflow" target="_blank">http://llvm.org/docs/LangRef.html#int_sadd_overflow</a></font></font>. We can use these functions and needn't define the function bodies. </div>


<div> </div>
<div>For example, I can manually insert codes:</div>
<div> </div>
<div>    <i><b> %res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)<br>     %sum = extractvalue {i32, i1} %res, 0<br>     %obit = extractvalue {i32, i1} %res, 1<br>     br i1 %obit, label %overflow, label %normal</b></i></div>


<div> </div>
<div>into an assembly file, and it works OK.</div>
<div> </div>
<div>And now, my question is "How to produce such a call instruction using the LLVM classes?"</div>
<div> </div>
<div>I have also noticed that LLVM provides some classes like "<i><b>MemCpyInst"</b></i> to wrap the "<i><b>llvm.memcpy"</b></i> Intrinsic. But other intrinsic functions such as <i><b>"</b></i><font face="Courier New"><i><b>llvm.sadd.with.overflow"</b></i> I've mentioned above don't have the corresponding classes. How to deal with it?</font></div>


<div><font face="Courier New"></font> </div>
<div><font face="Courier New">Anyone could help me? Thank you!</font></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br>