<div dir="ltr">Btw, I forgot to add this piece of information: I ended up dividing the work of my pass into two parts -- I created a module pass that had all the transformation instructions that didn't have anything to do with dominance, and I kept the dominance-dependent code inside a function pass. Then, I just had to force a dependence between them (the function pass requiring the module one), and this way I could apply my transformations.<div><br></div><div>Anyways, I still think doFinalization is wrongly defined or, at least, implemented, as I tried to discuss on my previous email =)</div><div><br></div><div>Thanks a lot,</div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><br>--<br>Cristianno Martins<br>PhD Student of Computer Science<br>University of Campinas<br><a href="mailto:cmartins@ic.unicamp.br" target="_blank">cmartins@ic.unicamp.br</a><br><a href="mailto:cristiannomartins@hotmail.com" target="_blank"></a></div></div>
<br><div class="gmail_quote">On Wed, May 6, 2015 at 1:11 PM, Cristianno Martins <span dir="ltr"><<a href="mailto:cristiannomartins@gmail.com" target="_blank">cristiannomartins@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">Hello again,<div><br></div><div>First of all, thanks for all the answers =) they really helped a lot =D</div><span class=""><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="font-size:13px"><i>Have you verified that some other pass is not adding the function declarations back in after your pass is executed (e.g., by using the -debug-pass=Executions argument to see what passes run after your pass)?</i></span></div><div><span style="font-size:13px"><i><br></i></span></div></blockquote></span>I considered that for a moment, but I realized that wouldn't be possible for two reasons: I specifically ran my pass with opt level zero; and one of the tasks I was doing was removing unused prototypes from the Module -- so, why would any other doFinalization pass reintroduce those prototypes if those functions were not being invoked anywhere? (PS: since this clean-up happened inside my doFinalization, I'm assuming only other doFinalization would be able to change the module after this point)<span class=""><br><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="font-size:13px"><i><br></i></span></div><div><span style="font-size:13px"><i>Also, does your doFinalization() method make other changes that are persistent?</i></span></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><p class="MsoNormal" style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><br></p></div></blockquote></span><div><div>The main reason why I chose to use doFinalization was to check if any of the functions I'm replacing still had any uses: since my pass replaced every function call with my respective function calls, if any uses could still be listed, that meant that some instruction must be taking the address of that function, and I should treat those instructions at this point. At the end, since I was already checking for uses, I ended up removing the extra prototypes at this point, if they were still there.</div><div><br></div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><span class=""><div><p class="MsoNormal" style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">I don’t think doFinalization() is really meant to be used this way.</span></p></div></span><div><p class="MsoNormal" style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Its purpose is to allow clean-up of internal data-structures used by the pass itself, not to make additional changes to the module.</span></p></div></blockquote> <div>Then, I have a question: why should doFinalization need a Module& as argument? I mean, since I shouldn't be able to modify it, and all data structures I created to work my pass are known and (mostly) directly accessible from within doFinalization, its argument would never be useful, right?</div><div><br><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><span class=""><p class="MsoNormal" style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">One option would be to rewrite your pass as a ModulePass instead of a FunctionPass, then iterating over the functions manually, and doing the final clean-up once that’s done.</span></p></span><div><div><span style="font-size:13px"><i><br></i></span></div><span class=""><div><span style="font-size:13px"><i>That said, I agree with the suggestion of writing a ModulePass. Since the PassManager does not run FunctionPasses in parallel yet, there's little benefit to using them. I have often found the limitations on FunctionPasses to not be worth the hassle.</i></span></div></span></div><div><span style="font-size:13px"><i><br></i></span></div></blockquote></div></div><div><div>Well, I actually wouldn't mind using a ModulePass to begin with, but unfortunately I had to rewrite my pass as a FunctionPass because part of the job it does involve accessing the DominatorTree -- and, unfortunately, I couldn't find a way to access it from inside a ModulePass. Even when I try to force a dependence between my module pass and DominatorTree, I can't get it to work because (if I'm not mistaken) module passes are hard-coded to run before function passes =/</div></div><div><br></div></div><span class=""><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><span style="font-size:13px"><i>My understanding is that doInitialization() and doFinalization() are designed specifically for modifying the LLVM IR (otherwise, why would a mutable reference to the Function be provided)?</i></span></div></div></blockquote><br><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><span style="font-size:13px"><i>If that is not the case, then there is either a bug in the code or a bug in the documentation.</i></span></div></div><div><span style="font-size:13px"><i><br></i></span></div></blockquote></span>Exactly like I thought =)<span class=""><br><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><i><br style="font-size:13px"></i></div></div><div><p class="MsoNormal" style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif;color:black"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">I’ve always thought that the only guarantee is that doFinalization(Module &M) runs after runOnFunction() was executed for all functions in M, and there’s no guarantee it runs *immediately* after. <u></u><u></u></span></p><p class="MsoNormal" style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif;color:black"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">That is, a PM may run a bunch of function passes over each function, and only then call doFinazliation() for each pass. That means that, even though you get a mutable reference to the module, the module you’ll see is quite different from what you may expect.<u></u><u></u></span></p><p class="MsoNormal" style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif;color:black"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p><p class="MsoNormal" style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif;color:black"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">People more familiar with the pass managers – please correct me if I’m wrong.</span></p></div></blockquote><font color="#1f497d" face="Calibri, sans-serif"><span style="font-size:15px"><div><font color="#1f497d" face="Calibri, sans-serif"><span style="font-size:15px"><br></span></font></div></span></font></span>I don't really mind at all if other passes run or even had their doFinalization passes running in any order in relation to mine: the point here is doFinalization is running (I know that because module.dump() is being called from inside that function, and I can see the module containing the modifications I do during the execution of that method), but the final bc file (written by opt) does have the exactly same code that I get if I dumped module at the beginning of my doFinalization (and they have differences between them btw =)).<span class=""><font color="#1f497d" face="Calibri, sans-serif"><span style="font-size:15px"><br></span></font><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><span style="color:rgb(80,0,80)"> </span></div></div><div><span style="color:rgb(80,0,80)"><br></span></div><div><span style="color:rgb(80,0,80)"><br></span></div></blockquote><div><div class="gmail_extra"><div><div>--<br>Cristianno Martins<br>PhD Student of Computer Science<br>University of Campinas<br><a href="mailto:cmartins@ic.unicamp.br" target="_blank">cmartins@ic.unicamp.br</a><br><a href="mailto:cristiannomartins@hotmail.com" target="_blank"></a></div></div><div><br></div></div></div></span></div>
</blockquote></div><br></div>