<div dir="ltr"><div>cc-ed llvm-dev back so others can hopefully help. I don't load passes via plugins so this is outside my area of expertise. But I have seen some recent patches fly by that are working on this.</div><div><br></div>I saw from an earlier question you posted that you are using gold. There is a patch under development/review to get pass plugins to work for LTO through gold. See <a href="https://reviews.llvm.org/D77704" target="_blank">https://reviews.llvm.org/D77704</a>.<div><br></div><div>Eli (added) was working on adding support as well, here are a couple of patches he recently landed for this in LTO and lld:</div><div><a href="https://reviews.llvm.org/D75879" target="_blank">https://reviews.llvm.org/D75879</a> (lld)<br></div><div><a href="https://reviews.llvm.org/D76866">https://reviews.llvm.org/D76866</a> (LTO)</div><div><br></div><div>I'm not completely sure what the status is at this point though. Eli is probably the best person to answer.</div><div><br></div><div>Teresa</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Apr 22, 2020 at 7:50 PM y liu <<a href="mailto:ly820nha@gmail.com">ly820nha@gmail.com</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 dir="ltr"><div>I‘m using LLVM 10, and register my pass by following code:</div><div><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:Consolas,"Courier New",monospace;font-size:18px;line-height:24px;white-space:pre-wrap"><div style="line-height:24px"><div><span style="color:rgb(86,156,214)">char</span> <span style="color:rgb(78,201,176)">MyModulePass</span>::ID = <span style="color:rgb(181,206,168)">0</span>;</div><div><span style="color:rgb(86,156,214)">static</span> <span style="color:rgb(78,201,176)">RegisterPass</span><<span style="color:rgb(78,201,176)">MyModulePass</span>> <span style="color:rgb(220,220,170)">X</span>(<span style="color:rgb(206,145,120)">"MyModule"</span>, <span style="color:rgb(206,145,120)">"MyModule pass"</span>);</div><div><span style="color:rgb(86,156,214)">static</span> <span style="color:rgb(86,156,214)">void</span> <span style="color:rgb(220,220,170)">registerMyModulePass</span>(<span style="color:rgb(86,156,214)">const</span> <span style="color:rgb(78,201,176)">PassManagerBuilder</span> <span style="color:rgb(86,156,214)">&</span>,</div><div>                         <span style="color:rgb(78,201,176)">legacy</span>::<span style="color:rgb(78,201,176)">PassManagerBase</span> <span style="color:rgb(86,156,214)">&</span><span style="color:rgb(156,220,254)">PM</span>) {</div><div>  <span style="color:rgb(156,220,254)">PM</span>.<span style="color:rgb(220,220,170)">add</span>(<span style="color:rgb(197,134,192)">new</span> <span style="color:rgb(220,220,170)">MyModulePass</span>());</div><div>}</div><div><span style="color:rgb(86,156,214)">static</span> RegisterStandardPasses</div><div>  <span style="color:rgb(220,220,170)">RegisterMyPass</span>(<span style="color:rgb(78,201,176)">PassManagerBuilder</span>::EP_FullLinkTimeOptimizationLast,</div><div>                 registerMyModulePass);</div></div></div></div><div><div class="gmail_quote"><div class="gmail_attr">MyModulePass reles on helper.c.</div><div class="gmail_attr">I want to use it for optimization after the link is compelte.</div><div class="gmail_attr">Now, I compile it manually with opt.</div><div class="gmail_attr">For example:</div><div class="gmail_attr"><br></div><div class="gmail_attr">Target: fun1.c fun2.c fun3.c main.c<br>Pass: Mypass.so<br>Dependency: helper.c</div><div class="gmail_attr"><br>fun1.c fun2.c fun3.c main.c ---> target.bc<br>                   helper.c ---> helper.o<br><br>target.bc helper.o ---> target-link.bc ----> opt Mypass.so  ---> target-opt.bc ---> target<br></div><div class="gmail_attr"><br></div><div class="gmail_attr">I want to achieve my goals by LTO.</div><div class="gmail_attr"><br></div><div dir="ltr" class="gmail_attr">Teresa Johnson <<a href="mailto:tejohnson@google.com" target="_blank">tejohnson@google.com</a>>于2020年4月22日 周三23:11写道:<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 dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Apr 22, 2020 at 5:12 AM y liu via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">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 dir="ltr">Hi,<div>I have a module pass and I hope to use it to optimize a real-world program.</div><div>I need LTO,and I have got LTO plugin.</div></div></blockquote><div><br></div><div>Do you mean the LLVM gold plugin (relevant when doing LTO links with gold or gnu ld), or are you trying to load your new pass via a pass plugin?</div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div></div><div> Yes, it’s gold plugin, I need it to link .bc and .o files. I want to optimize the target after linking. </div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div></div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>But How can I add my passes to LTO Pass. I can't find solution. </div><div>What should I do?</div></div></blockquote><div><br></div><div>This depends on whether you are trying to add via a pass plugin dynamically via the command line (I believe the support for this is work in progress), or by manually modifying the pass pipeline within LLVM.</div><div>Have you implemented as an old pass manager pass (the current default) or the new pass manager or both?</div><div>Is it an LTO specific pass, or do you also want to run for non-LTO optimizing compiles (most optimizing passes should run in all cases).</div><div><br></div><div>Assuming the latter, and also assuming you are using the default old pass manager, you would want to look at the following places in PassManagerBuilder.cpp:</div><div><br></div><div>regular (full) LTO: PassManagerBuilder::addLTOOptimizationPasses</div><div><br></div><div>ThinLTO: PassManagerBuilder::populateModulePassManager, which is used both by the pre-LTO compile and by the LTO linking ThinLTO compiles. If you want to insert your pass for both, just put it in the relevant place in this file, if you want to only do during the LTO link portion of the ThinLTO compile, then guard it with a check for "PerformThinLTO".</div><div><br></div><div>For the new pass manager, it would be added to PassBuilder.cpp (that is structured a bit differently so let me know and I can point you in the right direction). If you are planning to send upstream it should be supported by both pass managers.</div><div><br></div><div>HTH,</div><div>Teresa</div><div><br></div><div>_______________________________________________</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
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></blockquote></div></div><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><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></div>
</blockquote></div></div>
</div>
</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>