<div dir="ltr"><div class="gmail_extra">Hello,</div><div class="gmail_extra"><br></div><div class="gmail_extra">@Anastasis: what do you think about this? Do you mind if I implement the debugify-each mode and refactor the code to have DebugifyFunctionPass and DebugifyLoopPass? I am sorry if it bothers you, I should have done this earlier, so you could focus on fixing the optimization passes. FYI, my <span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">debugify-each is quite ready, I am having Debugify and CheckDebugify before and after each ModulePass, then</span> I just need to implement the FunctionPass and LoopPass.</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 26, 2018 at 8:53 PM, Vedant Kumar <span dir="ltr"><<a href="mailto:vsk@apple.com" target="_blank">vsk@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">Hello,<br><div><br><blockquote type="cite"><span class=""><div>On Apr 26, 2018, at 6:44 AM, Son Tuan VU <<a href="mailto:sontuan.vu119@gmail.com" target="_blank">sontuan.vu119@gmail.com</a>> wrote:</div><br class="m_4281711852896340249Apple-interchange-newline"></span><div><div dir="ltr">Hi Vedant,<div><br></div><span class=""><div>I have tried to implement the fix you proposed, but it didn't work as expected. I created a new <b>Module</b> Pass Manager (not Function Pass Manager) and override the <b>add()</b> method like this:</div><div><br></div><div><div>class DebugifyEachPassManager : public legacy::PassManager {</div><div> public:</div><div>   void add(Pass *P) override {</div><div>     PassManager::add(createDebugi<wbr>fyPass());</div><div>     PassManager::add(P);</div><div>     PassManager::add(createCheckD<wbr>ebugifyPass());</div><div>   }    </div><div>        </div><div>   bool run(Module &M) {</div><div>     return PassManager::run(M);</div><div>   }            </div><div>};     </div><div><br></div>However, we can't apply and check debugify of <b>FunctionPass</b>es since these passes are managed by Function Pass Managers created on the fly during <b>schedulePass()</b>. I guess we'd have to implement the FunctionPass version of Debugify and CheckDebugify.</div></span></div></div></blockquote><div><br></div><div>Yes, Anastasis (CC'd) has started exploring this idea: <a href="https://gramanas.github.io/posts/community-bonding/" target="_blank">https://gramanas.github.io/<wbr>posts/community-bonding/</a>. Please sync up with him before you start hacking, so you can collaborate on the design and split up work :). Now that GSoC has officially started, Anastasis needs to plan work ahead of time, so we need to find a way to avoid duplicating work.</div><div><br></div><div>If you find that it's difficult to split up work on this, consider working on enhancing opt's -verify-each mode so that it runs after each pass in -O1/-O2/etc. This would help address use-before-def scenarios with debug info intrinsics. There's an ongoing discussion about this here: <a href="https://reviews.llvm.org/D46100" target="_blank">https://reviews.llvm.<wbr>org/D46100</a>.</div><span class=""><div><br></div></span></div></div></blockquote><div><br></div><div>Yes I am still waiting for Chandler's thoughts on verify-each mode of LegacyPassManager (because it works if we use the new PassManager) and on what would be the best way to tackle it.</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><div><span class=""><blockquote type="cite"><div><div dir="ltr"><div> But what about <b>Call Graph SCC Pass</b> and <b>Loop Pass</b>?</div></div></div></blockquote><div><br></div></span><div>Great question! It might not be worthwhile to shoehorn what debugify does onto cgscc passes. The major cgscc pass I know of is the inliner, and its handling of debug info can be tested in a more targeted way. I think it would be worth adding a debugify wrapper for loop passes, however.</div><span class=""><div><br></div><br><blockquote type="cite"><div><div dir="ltr"><div>Do we have a way to know whether a pass is an analysis or a transformation at the moment of adding the pass to the manager? I want to try to debugify only transformation passes because analysis passes do not modify the IR, hence do not modify the DI. But I'm not sure if there's a way to achieve this.</div></div></div></blockquote><div><br></div></span>I'm not sure if there's a way to do this, but I see it as an optimization that can be deferred for now.</div><div><br></div><div><span class=""><br><blockquote type="cite"><div><div dir="ltr"><div>I'm currently trying to strip debug info after each CheckDebugify.</div></div></div></blockquote><div><br></div></span>There's a function called StripDebugInfo which does this.</div></div></blockquote><div><br></div><div>Wow thanks, I was reimplementing that function.... </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><span class="HOEnZb"><font color="#888888"><div><br></div><div>vedant</div></font></span><div><div class="h5"><div><br></div><div><br><blockquote type="cite"><div><div dir="ltr"><div> I have been searching everywhere but can't seem to find an API to remove MDNodes. I have seen a <b>MDNode::deleteAsSubclass() </b>method, unfortunately it is private.I guess nobody has ever needed to remove MDNodes/Metadata before. Can you give me some advice on how to do this please?</div></div></div></blockquote><blockquote type="cite"><div dir="ltr"><div><br></div><div>Thank you for your help</div><div><br></div></div><div class="gmail_extra"><br clear="all"><div><div class="m_4281711852896340249gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Son Tuan Vu</div></div></div>
<br><div class="gmail_quote">On Fri, Mar 16, 2018 at 11:54 PM, Son Tuan VU <span dir="ltr"><<a href="mailto:sontuan.vu119@gmail.com" target="_blank">sontuan.vu119@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Mhm I see now, thanks for your explanation! </div><div class="gmail_extra"><span class="m_4281711852896340249HOEnZb"><font color="#888888"><br clear="all"><div><div class="m_4281711852896340249m_1955841791358062680gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Son Tuan Vu</div></div></div></font></span><div><div class="m_4281711852896340249h5">
<br><div class="gmail_quote">On Fri, Mar 16, 2018 at 10:58 PM, Vedant Kumar <span dir="ltr"><<a href="mailto:vsk@apple.com" target="_blank">vsk@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><blockquote type="cite"><span><div>On Mar 16, 2018, at 2:30 PM, Son Tuan VU <<a href="mailto:sontuan.vu119@gmail.com" target="_blank">sontuan.vu119@gmail.com</a>> wrote:</div><br class="m_4281711852896340249m_1955841791358062680m_-3786410432644066664Apple-interchange-newline"></span><div><div dir="ltr">Hi Vedant,<div><br></div><span><div>Thank you for your reply. I think I can make this debugify-each mode, but I guess this is reserved for your GSoC project ?</div></span></div></div></blockquote><div><br></div><div>No, there's no reserved work. If you'd like to work on this I encourage you to do so. There's plenty of other work slated for the GSoC project. That said, let's make sure to sync up on the mailing lists to make sure work isn't being duplicated.</div><span><div><br></div><br><blockquote type="cite"><div><div dir="ltr"><div>However, if I understand correctly, we do not want to take the output of the first check-debugify (I mean the .ll file with potentially all the WARNINGs and ERRORs after the first pass) as input for the second debugify. What we need is to take the fresh output of <b>clang -Xclang -emit-llvm -disable-O0-optnone -S </b>and iteratively test each optimization. Am I right?</div></div></div></blockquote><div><br></div></span><div>The intermediate textual output is all irrelevant. And clang isn't in the picture here. Opt's regular mode of operation is to run pass1, then run pass2, etc. In the debugify-each mode, this instead looks like: debugify, pass1, check-debugify, strip debug info, debugify, pass2, etc. etc.</div><span class="m_4281711852896340249m_1955841791358062680HOEnZb"><font color="#888888"><div><br></div><div>vedant</div></font></span><div><div class="m_4281711852896340249m_1955841791358062680h5"><div><br></div><br><blockquote type="cite"><div><div dir="ltr"><div><br></div><div>Cheers,</div><div><br></div></div><div class="gmail_extra"><br clear="all"><div><div class="m_4281711852896340249m_1955841791358062680m_-3786410432644066664gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Son Tuan Vu</div></div></div>
<br><div class="gmail_quote">On Thu, Mar 15, 2018 at 4:05 AM, Vedant Kumar <span dir="ltr"><<a href="mailto:vsk@apple.com" target="_blank">vsk@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi Son Tuan,<div><br></div><div>Thanks for taking a look at this :). Responses inline --</div><div><br></div><div><div><span><blockquote type="cite"><div>On Mar 14, 2018, at 8:11 AM, Son Tuan VU <<a href="mailto:sontuan.vu119@gmail.com" target="_blank">sontuan.vu119@gmail.com</a>> wrote:</div><br class="m_4281711852896340249m_1955841791358062680m_-3786410432644066664m_251843486385049358Apple-interchange-newline"><div><div dir="ltr">Hi Vedant, hi all,<div><br></div><div>My goal is to measure debug info loss of <i>each</i><b> </b>optimization pass in LLVM. I am trying to create a debugify-each mode in opt, inspired by verify-each mode which is supposed to already work.</div></div></div></blockquote><div><br></div></span>+ Anastasis, who's interested in working on this as well. There's definitely enough work to go around: once we can measure debug info loss after each pass, we'll need a testing harness.</div><div><br></div><div><span><br><blockquote type="cite"><div><div dir="ltr"><div>However, if I understand correctly, the verify-each mode (triggered by -verify-each option in opt) only works when we provide a pass list or a pass pipeline.</div></div></div></blockquote><div><br></div></span><div>Yes, you're correct.</div><span><div><br></div><br><blockquote type="cite"><div><div dir="ltr"><div> Is this intended? I mean, why do not let people verify each pass in -O{1,2,3} pipeline?</div></div></div></blockquote><div><br></div></span><div>That's a good question! Like you, I assumed -verify-each "does the right thing" when you pass -O1/-O2/etc. to opt.</div><div><br></div><div>I'm not sure if the current behavior is intended (hopefully others will chime in about this :). If no one does, please file a bug.</div><div><br></div><div>I imagine this is pretty simple to fix. You can just define and use custom pass managers within opt which inject debugify passes as needed:</div><div><br></div><div><div></div><blockquote type="cite"><blockquote type="cite"><div>// In opt.cpp:</div></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><div>class DebugifyEachFunctionPassManage<wbr>r : public legacy::FunctionPassManager {</div><div>public:</div><div>  explicit DebugifyEachFunctionPassManage<wbr>r(Module *M)</div><div>      : FunctionPassManager(M) {}</div><div><br></div><div>  void add(Pass *P) override {</div><div>    // FunctionPassManager::add(<debu<wbr>gify>)</div><div>    FunctionPassManager::add(P);</div><div>  }</div><div>};</div></blockquote></blockquote><div><br></div></div><span><div><br></div><blockquote type="cite"><div><div dir="ltr"><div>My second question is more about debugify: what should be the best way to debugify each pass? Adding a debugify-each mode would make the output unreadable!</div></div></div></blockquote><div><br></div></span><div>The intermediate output is all irrelevant. I think it'd be best to simply throw it away. What really matters are the debug info loss statistics: we should capture these stats after each pass and dump them as JSON, at the end of the pipeline.</div><span class="m_4281711852896340249m_1955841791358062680m_-3786410432644066664HOEnZb"><font color="#888888"><div><br></div><div>vedant</div></font></span><span><div><br></div><br><blockquote type="cite"><div><div dir="ltr"><div> Maybe writing a script that collects all optimization options (like -mem2reg or -constmerge), then pass each one of them to opt with -enable-debugify so that we have 1 output file for each debugified pass?</div><div><br></div><div>Thank you for your help,</div><div><br clear="all"><div><div class="m_4281711852896340249m_1955841791358062680m_-3786410432644066664m_251843486385049358gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Son Tuan Vu</div></div></div>
</div></div>
</div></blockquote></span></div><br></div></div></blockquote></div><br></div>
</div></blockquote></div></div></div><br></div></blockquote></div><br></div></div></div>
</blockquote></div><br></div>
</blockquote></div><br></div></div></div></blockquote></div><br></div></div>