<div dir="ltr">-O0 -flto would still run the always-inliner, for example (& would skip any frontend (clang IR generation-level) optimizations you might be interested in), and would add the "optnone" attribute to the functions which may not be what you want if you're trying to investigate the -O3 pipeline</div><br><div class="gmail_quote"><div dir="ltr">On Fri, Nov 30, 2018 at 12:12 AM Alex Denisov <<a href="mailto:1101.debian@gmail.com">1101.debian@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">> Collecting IR from LTO probably isn't what's desired - since that'll be already optimized in the individual compilation stage (to then be further optimized in the LTO stage).<br>
<br>
Hm, I'm a bit surprised now. So even if I call "clang -flto -O0 -c main.c" the actual bitcode will be optimized? Then which optimizations will be applied?<br>
Does it also affect -fembed-bitcode?<br>
<br>
> On 29. Nov 2018, at 20:33, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:<br>
> <br>
> Collecting IR from LTO probably isn't what's desired - since that'll be already optimized in the individual compilation stage (to then be further optimized in the LTO stage).<br>
> <br>
> As others mentioned, -Xclang -disable-llvm-optzns. Also note that changing optimization flags (-O0 versus -O3, etc) will change the IR that's generated - most notably, at -O0, all the functions in the IR will be attributed with 'nodebug', so running this IR through opt -O3 will be basically a no-op. This catches folks by surprise sometimes. So use the -O flag you want, but pass disable-llvm-optzns to get that 'optimized' IR (as far as Clang's codegen is concerned) prior to the LLVM optimizations running on it.<br>
> <br>
> On Thu, Nov 29, 2018 at 12:49 AM Alex Denisov via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br>
> Hi David,<br>
> <br>
> There are at least two robust ways to get the Bitcode/IR:<br>
> <br>
> 1. LTO. You can enable link-time optimization by adding -flto compiler flags, in the end all object files (*.o) will in fact be bitcode files. I.e.:<br>
> <br>
> > file gmock.dir/gmock-gtest-all.cc.o<br>
> gmock.dir/gmock-gtest-all.cc.o: LLVM bitcode, wrapper x86_6<br>
> <br>
> 2. Embedded bitcode. Clang 3.9 and higher has an option -fembed-bitcode. When enabled, the resulting executable will contain additional section containing bitcode.<br>
> You can use this great tool[1] to extract the bitcode from an executable.<br>
> <br>
> Both approaches produce bitcode (binary format), if you need IR (human-readable format), then you can post-process the bitcode by running llvm-dis against each bitcode file.<br>
> <br>
> I hope it helps.<br>
> <br>
> [1] <a href="https://github.com/JDevlieghere/LibEBC" rel="noreferrer" target="_blank">https://github.com/JDevlieghere/LibEBC</a><br>
> <br>
> > On 28. Nov 2018, at 23:22, David Greene via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br>
> > <br>
> > How do I get the LLVM IR produced by clang? I know that -emit-llvm<br>
> > produces IR but it seems to be after processing by LLVM (things are<br>
> > optimized out, for example). Is there an "official" way to get the IR<br>
> > coming right out of clang's codegen? I can do a hack with -mllvm<br>
> > -print-before-all but that's icky.<br>
> > <br>
> > Thanks!<br>
> > <br>
> > -David<br>
> > _______________________________________________<br>
> > cfe-dev mailing list<br>
> > <a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
> > <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
> <br>
> _______________________________________________<br>
> cfe-dev mailing list<br>
> <a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
<br>
</blockquote></div>