<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 26, 2015 at 1:12 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Tue, May 26, 2015 at 12:56 PM, Nat! <span dir="ltr"><<a href="mailto:nat@mulle-kybernetik.com" target="_blank">nat@mulle-kybernetik.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span><br>
> Am 26.05.2015 um 18:57 schrieb David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>>:<br>
><br>
><br>
><br>
> On Mon, May 25, 2015 at 11:05 AM, Nat! <<a href="mailto:nat@mulle-kybernetik.com" target="_blank">nat@mulle-kybernetik.com</a>> wrote:<br>
> Hi<br>
><br>
> I started hacking on clang itself and I have some questions, that I couldn't figure out with the help of the source code or the documentation.<br>
><br>
> Looking at the IR code generated by -O2 and -O0 it seems, that function inlining is done in clang already. But I haven't figured out, how that is actually done.<br>
><br>
> Here's some useful terminology for this discussion:<br>
><br>
> IRGen: Clang's generation of LLVM IR from Clang ASTs<br>
<br>
> CodeGen: LLVM's generation of machine code/assembly from LLVM IR<br>
</span>OK, clang unfortunately calls IR generation also code generation, which makes it a bit confusing for the newcomer.<br></blockquote></span><div><br>Yep, one day we'll rename it.<br> </div><span class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span><br>
> Clang: The Clang frontend, down to the point that it generates and passes LLVM IR to the LLVM libraries.<br>
> LLVM: Everything else. (the middle and backend)<br>
><br>
> Clang does not do inlining.<br>
> LLVM does inlining.<br>
> Clang produces code that can be/is encouraged to be/is required to be inlined by LLVM.<br>
><br>
> For example, if the user writes source code with the always_inline (or is it "alwaysinline", I forget) attribute, then Clang produces LLVM IR with the matching attribute and LLVM obeys the request (where possibly) and inlines all calls to that function during LLVM's optimization passes.<br>
<br>
</span>My mental model of what was happening was:<br>
<br>
<file.c> > cc1 > <<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__file.ir&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=usl_pfluUa3Zy0GitGJHl-JdhjyP1uBcTrsjo8EvnZU&s=2SggNcTDCt2lm44VNhQmocedA-X-iUZyyMRe7CRDS48&e=" target="_blank">file.ir</a>> and then llc < <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__file.ir&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=usl_pfluUa3Zy0GitGJHl-JdhjyP1uBcTrsjo8EvnZU&s=2SggNcTDCt2lm44VNhQmocedA-X-iUZyyMRe7CRDS48&e=" target="_blank">file.ir</a> > file.o<br>
<br>
and I expected all optimizations to be done after cc1 is complete. This is not the case. The inlining is done in the cc1 stage, during EmitBackendOutput. So that what you would call the "middle" and the code that does the inlining is linked in from the llvm project.</blockquote></span><div><br>That's sometimes called the "middle end" or "target independent optimizations" or "IR optimizers/optimizations", etc.<br> </div><span class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> The ir that I got from -cc1 -emit-llvm was therefore not created by "pure" clang as I expected but a mix of clang and llvm.<br></blockquote></span><div><br>Right. If you want literally the IR that Clang produced (& was going to give to LLVM) you need to pass -mllvm -disable-llvm-optzns. Without that, even at -O0, you'll get some LLVM optimizations running, including the AlwaysInliner (the version of teh inliner responsible for inlining always_inline functions - since that has to be done even at -O0).<br> </div><span class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I hope I can get substitute my debugging clang by doing cc1 -emit-llvm -O0 and then llc these with optimization on, as it would be a lot easier to debug, why my code does not get inlined.<br></blockquote></span></div></div></div></blockquote><div><br>& I'd suggest passing the .ll/.bc back to clang, rather than llc - as llc and Clang don't necessarily use precisely the same optimization pipeline.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Thanks for the helpful reply!<br>
<br>
Ciao<br>
<span><font color="#888888">   Nat!<br>
------------------------------------------------------<br>
Wir haben das Beste gewollt, aber es kam wie immer.<br>
                                    - W.Tschernomyrdin<br>
</font></span><div><div><br>
<br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">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>
</div></div></blockquote></span></div><br></div></div>
</blockquote></div><br></div></div>