<div dir="ltr">Hi Vedant,<div><br></div><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(<wbr>createDebugifyPass());</div><div> PassManager::add(P);</div><div> PassManager::add(<wbr>createCheckDebugifyPass());</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. But what about <b>Call Graph SCC Pass</b> and <b>Loop Pass</b>?</div><div><br></div><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><br></div><div>I'm currently trying to strip debug info after each CheckDebugify. 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><br></div><div>Thank you for your help</div><div><br></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_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="HOEnZb"><font color="#888888"><br clear="all"><div><div class="m_1955841791358062680gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Son Tuan Vu</div></div></div></font></span><div><div class="h5">
<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_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_1955841791358062680HOEnZb"><font color="#888888"><div><br></div><div>vedant</div></font></span><div><div class="m_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_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_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_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_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>