<div dir="ltr">Hi ZhengXianLi,<div><br></div><div>The main entry point into the LTO LLVM code from lld is in <a href="https://github.com/llvm/llvm-project/blob/master/lld/ELF/LTO.cpp">https://github.com/llvm/llvm-project/blob/master/lld/ELF/LTO.cpp</a>. Specifically see the call to ltoObj->run which launches the main LTO handling after all of the setup here: <a href="https://github.com/llvm/llvm-project/blob/master/lld/ELF/LTO.cpp#L309">https://github.com/llvm/llvm-project/blob/master/lld/ELF/LTO.cpp#L309</a>. Most of the actual LTO handling is in the LLVM LTO code here: <a href="https://github.com/llvm/llvm-project/blob/master/llvm/lib/LTO/LTO.cpp">https://github.com/llvm/llvm-project/blob/master/llvm/lib/LTO/LTO.cpp</a></div><div>and here: <a href="https://github.com/llvm/llvm-project/blob/master/llvm/lib/LTO/LTOBackend.cpp">https://github.com/llvm/llvm-project/blob/master/llvm/lib/LTO/LTOBackend.cpp</a></div><div>Note there is an old LTO API implementation in LTOModule.cpp and *LTOCodeGenerator.cpp that is not used by lld, gold or bfd (just ld64 and some custom linkers nowadays that haven't yet migrated). The newer LTO API implementation in LTO.cpp and LTOBackend.cpp relies on linker resolutions passed by lld (or gold/bfd via gold-plugin.cpp) via that lld file I pointed to.</div><div><br></div><div>The following lld test contain some simple test cases for thinLTO:</div><div><a href="https://github.com/llvm/llvm-project/blob/master/lld/test/ELF/lto/thinlto.ll">https://github.com/llvm/llvm-project/blob/master/lld/test/ELF/lto/thinlto.ll</a><br></div><div><br></div><div>To run them with regular LTO instead of ThinLTO, just remove the -module-summary from the opt invocations.</div><div><br></div><div>There's clang documentation on ThinLTO here: <a href="https://clang.llvm.org/docs/ThinLTO.html">https://clang.llvm.org/docs/ThinLTO.html</a></div><div>and an old blog post on ThinLTO here: <a href="https://blog.llvm.org/posts/2016-06-21-thinlto-scalable-and-incremental-lto/">https://blog.llvm.org/posts/2016-06-21-thinlto-scalable-and-incremental-lto/</a></div><div>but they don't get into the details of the code implementation.</div><div><br></div><div>Hope that helps,</div><div>Teresa</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Sep 24, 2020 at 7:43 AM 半缘君 via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>Hi:</div><div>    I want to learn  how LTO and thinLTO work? But I'm confused how lld invoked either library. How can I find it in lld. Should i be familiar with lld source code? And i also think if there is some easy test case and with step-by- step debugging or some log messages can help me learn this? Is there some method can do stuff like this?</div><div>  Thank you very much.</div><div>   ZhengXianLi</div>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><span style="font-family:Times;font-size:medium"><table cellspacing="0" cellpadding="0"><tbody><tr style="color:rgb(85,85,85);font-family:sans-serif;font-size:small"><td nowrap style="border-top:2px solid rgb(213,15,37)">Teresa Johnson |</td><td nowrap style="border-top:2px solid rgb(51,105,232)"> Software Engineer |</td><td nowrap style="border-top:2px solid rgb(0,153,57)"> <a href="mailto:tejohnson@google.com" target="_blank">tejohnson@google.com</a> |</td><td nowrap style="border-top:2px solid rgb(238,178,17)"><br></td></tr></tbody></table></span></div></div></div>