<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 2 February 2015 at 14:01, Russell Wallace <span dir="ltr"><<a href="mailto:russell.wallace@gmail.com" target="_blank">russell.wallace@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">As I understand it, clang currently has the -flto flag which activates some degree of whole program optimization. However, this requires clang to be presented with all the source files at the same time.</div></blockquote><div><br></div><div>Not at all. The -flto flag causes clang to emit a half-compiled .o file that is not at all a real object file. It contains no object code and is not elf, mach-o nor pe/coff. It's an llvm bitcode file.</div><div><br></div><div>The second half of this story is that you're going to ask the linker to compile a program with these non-object file .o files, and the linker needs to handle it. On darwin "ld" is linked against libLTO [ <a href="http://llvm.org/docs/LinkTimeOptimization.html">http://llvm.org/docs/LinkTimeOptimization.html</a> ]. On linux, you can use "gold" (the newer ld in binutils) with a plugin [ <a href="http://llvm.org/docs/GoldPlugin.html">http://llvm.org/docs/GoldPlugin.html</a> ]. I'm told the plan is to make lld support llvm lto when building windows/pecoff files, but this may not be ready yet.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"> This is easy enough to arrange in a greenfield project, but may be trickier with an existing program.<div><br></div><div>On Unix, C and C++ programs are usually compiled with makefiles (whether handwritten or auto generated), and these typically call the compiler on one source file at a time and then call the system linker only after compilation has proceeded to machine code object files. Thus, even with clang as a drop-in replacement for GCC, there is the challenge of obtaining exact compilation instructions from the makefile and then modifying these to allow clang to see all the files at once, no later than bitcode stage.</div></div></blockquote><div><br></div><div>The gold plugin webpage covers exactly this case, including a section on how to make llvm LTO work with autotools (configure+make) projects.</div><div><br></div><div>Nick</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>On Windows, it's common to have a Visual Studio project file that msbuild can use. This sometimes does call the compiler on multiple files at the same time; then there's the question of how to get clang-cl invoked with suitable options.<br></div><div><br></div><div>At least that's my thinking on this aspect of the problem so far; there are doubtless things I'm missing. What's currently being done in this area?</div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div></div>