<div style="font-family: arial, helvetica, sans-serif; font-size: 10pt"><div dir="ltr">On Sun, Dec 16, 2012 at 7:23 AM, Duncan Sands <span dir="ltr"><<a href="mailto:baldrick@free.fr" target="_blank" class="cremed">baldrick@free.fr</a>></span> wrote:<br>
<div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Stephen,<div class="im"><br>
<br>
On 13/12/12 18:58, Stephen McGruer wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
I'm wondering if the documentation for LoopPass<br>
(<a href="http://llvm.org/docs/WritingAnLLVMPass.html#LoopPass" target="_blank" class="cremed">http://llvm.org/docs/<u></u>WritingAnLLVMPass.html#<u></u>LoopPass</a>) is misleading or<br>
incorrect (or if I'm just missing something.) The documentation states:<br>
<br>
"The doFinalization method ... is called when the pass framework has finished<br></div>
calling runOnLoop <<a href="http://llvm.org/docs/WritingAnLLVMPass.html#runOnLoop" target="_blank" class="cremed">http://llvm.org/docs/<u></u>WritingAnLLVMPass.html#<u></u>runOnLoop</a>> for<div class="im"><br>
every loop in the program being compiled."<br>
<br>
 From this, I understood that for a single instance of a LoopPass sub-class, the<br>
doFinalization method would be called exactly once, after all loops had been<br>
seen. However in practice I am seeing doFinalization() being called multiple<br>
times per program. Digging into the code, it appears that LPPassManager actually<br>
makes the calls to doFinalization() at the end of it's runOnFunction() method<br>
(<a href="http://llvm.org/docs/doxygen/html/LoopPass_8cpp_source.html#l00281" target="_blank" class="cremed">http://llvm.org/docs/doxygen/<u></u>html/LoopPass_8cpp_source.<u></u>html#l00281</a>, at time of<br>
writing). This therefore means that doFinalization() can be called multiple<br>
times per LoopPass; as many as there are functions defined in the input file.<br>
</div></blockquote>
<br>
my understanding is that this is the expected behaviour and the documentation<br>
should be improved (want to propose a patch?).<br></blockquote><div><br></div><div style>I'm actually really hoping to change this behavior in the not-too-distant future.</div><div style><br></div><div style>The goal that I and several others have worked out is that for *all* passes, the doInitialization and doFinalization are called once per module. All of the doInitialization methods should be called before the first pass's runOn***  method is called, and all of the doFinalization calls should be after the last pass's runOn*** have finished.</div>
<div style><br></div><div style>The goal of the initialization and finalization methods is to allow per-module caching, uniquing, setup, and teardown.</div><div style><br></div><div style>I know that we are quite far from this goal in practice sadly, but I think the goal remains the same.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Ciao, Duncan.<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
<br>
Assuming I have made no mistakes here, is this a case of poorly written<br>
documentation, or an error in the implementation? I note that FPPassManager does<br>
it calls to FunctionPass' doFinalization() in it's own doFinalization() method,<br>
which seems the correct behaviour to me.<br>
<br>
Thanks,<br>
Stephen<br>
<br>
<br></div>
______________________________<u></u>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank" class="cremed">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank" class="cremed">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank" class="cremed">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvmdev</a><br>
<br>
</blockquote>
<br>
______________________________<u></u>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank" class="cremed">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank" class="cremed">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank" class="cremed">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvmdev</a><br>
</blockquote></div><br></div></div></div>