<div dir="ltr"><div><div>You may want to copy the list on your replies (Reply All or similar), as I'm by far no expert on how the analysis at AST level would work. <br><br></div>As they saying goes "The devil is in the detail", so a large part of the actual answer to your question depends on "what optimisatons you plan to do". I know there are people who work on/have worked on "source to source" conversions, and (parts of) Clang can absolutely be used for this purpose. Whether anyone has already done something that you can use, whether it does exactly what you want or something similar is a further question, that I haven't got the answer to.<br><br>--<br></div>Mats<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 1 May 2015 at 11:39, Hayden Livingston <span dir="ltr"><<a href="mailto:halivingston@gmail.com" target="_blank">halivingston@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Yes, the point is to go over the C source code to generate optimized code.<br>
<br>
I'm using the CFG from Clang, but it's painful to generate SSA form. I<br>
don't have an algorithm, so I was hoping there would be a paper or<br>
well code that would be show me how to do it.<br>
<div class="HOEnZb"><div class="h5"><br>
On Fri, May 1, 2015 at 3:27 AM, mats petersson <<a href="mailto:mats@planetcatfish.com">mats@planetcatfish.com</a>> wrote:<br>
> Someone will come along and correct me if I'm wrong, but my understanding is<br>
> that Clang does indeed rely very on LLVM to produce optimised code, and very<br>
> little, if any, optimisation is done in Clang. Clang produces LLVM IR<br>
> directly from the AST (or at least "nearly directly", it does some<br>
> transformations in Sema for example, that introduces explicit casts from<br>
> implicit casts in the original source - such as converting integers to float<br>
> or float to integer in arguments or assignments).<br>
><br>
> This is kind of the beauty of LLVM IR, and certainly helps the approach I've<br>
> taken in my Pascal compiler - of course, you still need to produce<br>
> "sensible" LLVM IR, as the optimisation will not remove all forms of<br>
> useless/stupid code that the user could create (as I've found out at times).<br>
><br>
> I have a hard time understanding why you couldn't use LLVM IR to make the<br>
> optimisations you want (by adding suitable passes to the compiler) - or was<br>
> the point to output C source code that is "optimised"? If so, you may want<br>
> to work at the AST level in Clang instead - there are tools for (recusively)<br>
> iterating over that too.<br>
><br>
> --<br>
> Mats<br>
><br>
> On 1 May 2015 at 10:58, Hayden Livingston <<a href="mailto:halivingston@gmail.com">halivingston@gmail.com</a>> wrote:<br>
>><br>
>> For my project (a subset of C) I'm trying to do optimizations at the<br>
>> source level language and wondering why Clang doesn't have an SSA form<br>
>> representation.<br>
>><br>
>> Is it not useful, since LLVM does almost all the optimizations?<br>
>> _______________________________________________<br>
>> cfe-dev mailing list<br>
>> <a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
><br>
><br>
</div></div></blockquote></div><br></div>