<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2017-07-29 2:50 GMT-07:00 Alex Denisov via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Hi Mackenzie,<br>
<br>
The trick is to use LTO.<br>
Here is a set of commands you need to run in order to prepare build system:<br>
<br>
$ mkdir build<br>
$ cd build<br>
$ export CFLAGS="-flto -g "<br>
$ export CXXFLAGS="-flto -g "<br>
$ export CPPFLAGS="-flto -g "<br>
$ cmake ../llvm<br></blockquote><div><br></div><div>Shorter:</div><div><br></div><div>```cmake ../llvm -DLLVM_ENABLE_LTO=YES```</div><div><br></div><div>Note that LTO implies a different optimization pipeline. If you just want IR without changing anything else, the exact command line flag is `-emit-llvm` I believe.</div><div><br></div><div>Best,</div><div><br></div><div>-- </div><div>Mehdi</div><div><br></div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<br>
Now you can build any target you want, for instance:<br>
<br>
$ make LLVMSupport -j8<br>
<br>
When it's done you will have bunch of .o files, which are actually LLVM bitcode files:<br>
<br>
$ find ./ -name "*.o" | xargs file<br>
.//CMakeFiles/test.o: LLVM bitcode, wrapper x86_64<br>
.//lib/Support/CMakeFiles/<wbr>LLVMSupport.dir/Allocator.cpp.<wbr>o: LLVM bitcode, wrapper x86_64<br>
.//lib/Support/CMakeFiles/<wbr>LLVMSupport.dir/APFloat.cpp.o: LLVM bitcode, wrapper x86_64<br>
.//lib/Support/CMakeFiles/<wbr>LLVMSupport.dir/APInt.cpp.o: LLVM bitcode, wrapper x86_64<br>
.//lib/Support/CMakeFiles/<wbr>LLVMSupport.dir/APSInt.cpp.o: LLVM bitcode, wrapper x86_64<br>
.//lib/Support/CMakeFiles/<wbr>LLVMSupport.dir/<wbr>ARMAttributeParser.cpp.o: LLVM bitcode, wrapper x86_64<br>
....<br>
<br>
If you need a human readable IR, then you can convert them into .ll using llvm-dis:<br>
<br>
$ llvm-dis .//lib/Support/CMakeFiles/<wbr>LLVMSupport.dir/Allocator.cpp.<wbr>o<br>
$ file .//lib/Support/CMakeFiles/<wbr>LLVMSupport.dir/Allocator.cpp.<wbr>o.ll<br>
.//lib/Support/CMakeFiles/<wbr>LLVMSupport.dir/Allocator.cpp.<wbr>o.ll: ASCII text, with very long lines<br>
<br>
I hope that helps.<br>
<br>
Cheers,<br>
Alex.<br>
<div><div class="gmail-h5"><br>
> On 29. Jul 2017, at 10:32, Mackenzie Moore via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
> Hello everyone,<br>
><br>
> I'm trying to compile LLVM and Clang into LLVM IR with debug info. I know that clang++ -g2 -S -emit-llvm <filename> does this, but I'm unfamiliar with CMake.<br>
><br>
> I tried changing CMAKE_CXX_FLAGS in CMakeCache.txt to "clang++ -g2 -S -emit-llvm," "-g2 -S -emit-llvm," and "-emit-llvm," but everything I tried resulted in a failed build, and/or .o files that didn't look like LLVM IR files when I opened them up. Where is the right place to pass these flags in?<br>
><br>
> Thanks,<br>
> Mackenzie<br>
> ______________________________<wbr>_________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br>
</div></div>--<br>
AlexDenisov<br>
Software Engineer, <a href="https://lowlevelbits.org" rel="noreferrer" target="_blank">https://lowlevelbits.org</a><br>
<br>
<br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div></div>