<div dir="ltr"><br><div>Hi David,</div><div><br></div><div class="gmail_extra"><div class="gmail_quote">On 14 September 2015 at 16:25, David Chisnall <span dir="ltr"><<a href="mailto:David.Chisnall@cl.cam.ac.uk" target="_blank">David.Chisnall@cl.cam.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 14 Sep 2015, at 06:58, Dipanjan Das via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
><br>
> Hi David,<br>
><br>
> I think you people can help me better if I explain what I am trying to achieve.<br>
>       • I have compiled gmp with LLVM 2.9<br>
>       • Linked the library statically with a stub program (gmp_demo.bc)<br>
>       • Transformed the bitcode to LLVM IR: llvm-dis gmp_demo.bc -o gmp_demo.ll<br>
>       • Trying to convert the IR to high-level C code: llc -march=c gmp_demo.ll<br>
> Though I know that llc C backend has many issues and has been removed from LLVM >=3.1, still I am desperate to make it work. The error I receive in the last step is the following: "LLVM ERROR: Code generator does not support intrinsic function 'llvm.uadd.with.overflow.i64'!"<br>
><br>
> I was planning to rewrite LLVM intrinsics not supported by llc to equivalent LLVM IR supported by llc. Is this approach feasible?<br>
<br>
It would still help to understand exactly why you’re trying to do this.  It sounds as if you’re using LLVM as a source-to-source translator, with C as the input and output language.  If this is the case, then the Clang rewriter infrastructure might be more useful to you.<br>
<br></blockquote><div><br></div><div>I have started working on automatic program repair where I need to work with a binary with source code unknown to us. May be using an in-house tool, I can lift off the binary to LLVM IR. I was planning to transform LLVM IR to equivalent high-level C code to try source code fixing approaches on the same.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The intrinsic that it is currently failing on is (as its name implies) an overflow-checked addition.  The reason that the C backed does not understand this builtin is simple: There is no way of (directly) expressing this in C, without extensions.<br>
<br>
You could potentially expand this in IR to a signed addition and a check that the sign bit had not changed, but it would be cleaner to simply modify the C backend to emit the Clang / GCC __builtin function that corresponds to the intrinsic.  You’re likely to find a number of other intrinsics that are not supported: the reason that the C backend was removed was that it never worked very well.  For example, anything involving exceptions can’t be implemented in C, so the C backend lowers it to setjmp / longjmp, which gives you a different ABI.<br></blockquote><div><br></div><div> </div></div>-- <br><div class="gmail_signature"><div dir="ltr"><span><div><div dir="ltr"><p>Thanks & Regards,</p>
<div>Dipanjan</div></div></div></span></div></div>
</div></div>