<div dir="ltr">Yup - thanks for the correction!</div><br><div class="gmail_quote"><div dir="ltr">On Thu, Nov 29, 2018 at 11:37 AM <<a href="mailto:paul.robinson@sony.com">paul.robinson@sony.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div class="m_-6830808465200381808WordSection1">
<p class="MsoNormal" style="margin-left:4.8pt">most notably, at -O0, all the functions in the IR will be attributed with 'nodebug',<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
</div></div><div lang="EN-US" link="blue" vlink="purple"><div class="m_-6830808465200381808WordSection1"><p class="MsoNormal"><a name="m_-6830808465200381808__MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Dave means 'optnone' here. This prevents (most) optimization.<u></u><u></u></span></a></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">--paulr<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> cfe-dev [mailto:<a href="mailto:cfe-dev-bounces@lists.llvm.org" target="_blank">cfe-dev-bounces@lists.llvm.org</a>]
<b>On Behalf Of </b>David Blaikie via cfe-dev<br>
<b>Sent:</b> Thursday, November 29, 2018 2:33 PM<br>
<b>To:</b> Alex Denisov<br>
<b>Cc:</b> David Greene; <a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a></span></p></div></div></div></div></div><div lang="EN-US" link="blue" vlink="purple"><div class="m_-6830808465200381808WordSection1"><div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt"><div><div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""><br>
<b>Subject:</b> Re: [cfe-dev] Getting LLVM IR from clang<u></u><u></u></span></p></div></div></div></div></div><div lang="EN-US" link="blue" vlink="purple"><div class="m_-6830808465200381808WordSection1"><div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt"><div><div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""></span></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">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).</p></div></div></div></div><div lang="EN-US" link="blue" vlink="purple"><div class="m_-6830808465200381808WordSection1"><div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt"><div><p class="MsoNormal"><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.<u></u><u></u></p></div></div></div></div><div lang="EN-US" link="blue" vlink="purple"><div class="m_-6830808465200381808WordSection1"><div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">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:<u></u><u></u></p>
</div>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">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" 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" 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" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><u></u><u></u></p>
</blockquote>
</div>
</div></div></div></blockquote></div>