I see. In the meantime, is there a suggested method to do actual finalization code (i.e. code that runs after *all* of the loops have been processed)?<br><br>Thanks,<br>Stephen<div class="gmail_extra"><br><br><div class="gmail_quote">
On 17 December 2012 12:57, Duncan Sands <span dir="ltr"><<a href="mailto:baldrick@free.fr" target="_blank">baldrick@free.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Chandler,<div class="im"><br>
<br>
On 17/12/12 13:47, Chandler Carruth wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
On Sun, Dec 16, 2012 at 7:23 AM, Duncan Sands <<a href="mailto:baldrick@free.fr" target="_blank">baldrick@free.fr</a><br></div><div class="im">
<mailto:<a href="mailto:baldrick@free.fr" target="_blank">baldrick@free.fr</a>>> wrote:<br>
<br>
Hi Stephen,<br>
<br>
<br>
On 13/12/12 18:58, Stephen McGruer wrote:<br>
<br>
I'm wondering if the documentation for LoopPass<br></div>
(<a href="http://llvm.org/docs/__WritingAnLLVMPass.html#__LoopPass" target="_blank">http://llvm.org/docs/__<u></u>WritingAnLLVMPass.html#__<u></u>LoopPass</a><br>
<<a href="http://llvm.org/docs/WritingAnLLVMPass.html#LoopPass" target="_blank">http://llvm.org/docs/<u></u>WritingAnLLVMPass.html#<u></u>LoopPass</a>>) is misleading or<div class="im"><br>
incorrect (or if I'm just missing something.) The documentation states:<br>
<br>
"The doFinalization method ... is called when the pass framework has<br>
finished<br>
calling runOnLoop<br></div>
<<a href="http://llvm.org/docs/__WritingAnLLVMPass.html#__runOnLoop" target="_blank">http://llvm.org/docs/__<u></u>WritingAnLLVMPass.html#__<u></u>runOnLoop</a><div class="im"><br>
<<a href="http://llvm.org/docs/WritingAnLLVMPass.html#runOnLoop" target="_blank">http://llvm.org/docs/<u></u>WritingAnLLVMPass.html#<u></u>runOnLoop</a>>> for<br>
<br>
every loop in the program being compiled."<br>
<br>
From this, I understood that for a single instance of a LoopPass<br>
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<br>
actually<br>
makes the calls to doFinalization() at the end of it's runOnFunction()<br>
method<br></div>
(<a href="http://llvm.org/docs/doxygen/__html/LoopPass_8cpp_source.__html#l00281" target="_blank">http://llvm.org/docs/doxygen/<u></u>__html/LoopPass_8cpp_source.__<u></u>html#l00281</a><br>
<<a href="http://llvm.org/docs/doxygen/html/LoopPass_8cpp_source.html#l00281" target="_blank">http://llvm.org/docs/doxygen/<u></u>html/LoopPass_8cpp_source.<u></u>html#l00281</a>>, at<div class="im"><br>
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<br>
file.<br>
<br>
<br>
my understanding is that this is the expected behaviour and the documentation<br>
should be improved (want to propose a patch?).<br>
<br>
<br>
I'm actually really hoping to change this behavior in the not-too-distant future.<br>
<br>
The goal that I and several others have worked out is that for *all* passes, the<br>
doInitialization and doFinalization are called once per module. All of the<br>
doInitialization methods should be called before the first pass's runOn***<br>
method is called, and all of the doFinalization calls should be after the last<br>
pass's runOn*** have finished.<br>
</div></blockquote>
<br>
would it still be possible to optimize and codegen functions as they are output<br>
(rather than waiting for the module to be completely output before doing this)?<br>
<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>
The goal of the initialization and finalization methods is to allow per-module<br>
caching, uniquing, setup, and teardown.<br>
<br>
I know that we are quite far from this goal in practice sadly, but I think the<br>
goal remains the same.<br>
<br>
<br>
Ciao, Duncan.<br>
<br>
<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<br>
FPPassManager does<br>
it calls to FunctionPass' doFinalization() in it's own doFinalization()<br>
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">LLVMdev@cs.uiuc.edu</a> <mailto:<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/__mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/__<u></u>mailman/listinfo/llvmdev</a><br>
<<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvmdev</a>><br>
<br>
<br>
______________________________<u></u>___________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <mailto:<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/__mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/__<u></u>mailman/listinfo/llvmdev</a><br>
<<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvmdev</a>><br>
<br>
<br>
</blockquote><div class="HOEnZb"><div class="h5">
<br>
______________________________<u></u>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvmdev</a><br>
</div></div></blockquote></div><br></div>