<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: arial,helvetica,sans-serif; font-size: 10pt; color: #000000'><br><hr id="zwchr"><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><b>From: </b>"Pete Cooper" <peter_cooper@apple.com><br><b>To: </b>"Hal Finkel" <hfinkel@anl.gov><br><b>Cc: </b>"Chandler Carruth" <chandlerc@gmail.com>, "Duncan P. N. Exon Smith" <dexonsmith@apple.com>, "Philip Reames" <listmail@philipreames.com>, "Mehdi Amini" <mehdi.amini@apple.com>, "Rafael Espíndola" <rafael.espindola@gmail.com>, "llvm-dev" <llvm-dev@lists.llvm.org>, "Quentin Colombet" <qcolombet@apple.com>, "Eric Christopher" <echristo@gmail.com><br><b>Sent: </b>Thursday, May 12, 2016 6:39:25 PM<br><b>Subject: </b>Re: [llvm-dev] Deleting function IR after codegen<br><br>
<br class=""><div><blockquote class=""><div class="">On May 12, 2016, at 4:32 PM, Hal Finkel <<a href="mailto:hfinkel@anl.gov" class="" target="_blank">hfinkel@anl.gov</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br class="Apple-interchange-newline"><hr id="zwchr" style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><blockquote style="font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;" class=""><b class="">From:<span class="Apple-converted-space"> </span></b>"Chandler Carruth" <<a href="mailto:chandlerc@gmail.com" class="" target="_blank">chandlerc@gmail.com</a>><br class=""><b class="">To:<span class="Apple-converted-space"> </span></b>"Quentin Colombet" <<a href="mailto:qcolombet@apple.com" class="" target="_blank">qcolombet@apple.com</a>>, "Eric Christopher" <<a href="mailto:echristo@gmail.com" class="" target="_blank">echristo@gmail.com</a>><br class=""><b class="">Cc:<span class="Apple-converted-space"> </span></b>"Pete Cooper" <<a href="mailto:peter_cooper@apple.com" class="" target="_blank">peter_cooper@apple.com</a>>, "Duncan P. N. Exon Smith" <<a href="mailto:dexonsmith@apple.com" class="" target="_blank">dexonsmith@apple.com</a>>, "Hal Finkel" <<a href="mailto:hfinkel@anl.gov" class="" target="_blank">hfinkel@anl.gov</a>>, "Philip Reames" <<a href="mailto:listmail@philipreames.com" class="" target="_blank">listmail@philipreames.com</a>>, "Mehdi Amini" <<a href="mailto:mehdi.amini@apple.com" class="" target="_blank">mehdi.amini@apple.com</a>>, "Rafael Espíndola" <<a href="mailto:rafael.espindola@gmail.com" class="" target="_blank">rafael.espindola@gmail.com</a>>, "llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org" class="" target="_blank">llvm-dev@lists.llvm.org</a>><br class=""><b class="">Sent:<span class="Apple-converted-space"> </span></b>Thursday, May 12, 2016 6:11:34 PM<br class=""><b class="">Subject:<span class="Apple-converted-space"> </span></b>Re: [llvm-dev] Deleting function IR after codegen<br class=""><br class=""><div dir="ltr" class="">FWIW, +1 from me as well.<div class=""><br class=""></div><div id="DWT12188" class="">But I don't think you need to make this a module pass or anything else. I think you should leave the husks of the functions around and just nuke the IR out from under them. That way the module surface remains essentially identical. You can also probably nuke all the instructions from BBs with their addresses taken for jump tables, etc.</div></div></blockquote><span style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; float: none; display: inline ! important;" class="">I agree. We need to be careful about invalidating inter-procedural IR-level analysis results that we make use of using CodeGen (like AA). Consider, for example, the following situation:</span><br style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><br style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><span style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; float: none; display: inline ! important;" class=""> 1. We CodeGen a function foo(), and then remove its IR. During this process, we never used an AA query that reached CFL-AA</span><br style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><span style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; float: none; display: inline ! important;" class=""> 2. We CodeGen a function bar(), and bar() calls foo().</span><br style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><span style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; float: none; display: inline ! important;" class=""> 3. During (2), we make an AA query on instructions in bar(), which have MMOs with IR Values in bar()</span><br style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><span style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; float: none; display: inline ! important;" class=""> 4. CFL-AA is reached and does not have a cached graph for bar(), so it builds one</span><br style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><span style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; float: none; display: inline ! important;" class=""> 5. While building the graph for bar(), it reaches the call to foo(), and calls tryInterproceduralAnalysis</span><br style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><span style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; float: none; display: inline ! important;" class=""> 6. CFL-AA does not have a cached graph for foo(), so tryInterproceduralAnalysis triggers one to be constructed</span><br style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><span style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; float: none; display: inline ! important;" class=""> 7. But foo() is now empty, and so has trivial aliasing properties</span><br style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><span style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; float: none; display: inline ! important;" class=""> 8. We return an incorrect AA result when compiling bar()</span><br style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""></div></blockquote>Hmm. This is an interesting use case. Is this even legal in the current pass manager? Codegen is a FunctionPass which I thought could only look at global variables and its own function.</div><div><br class=""></div><div id="DWT12864">Or is the rule that a FunctionPass has read/write access to its own function, but read-only to other functions which is effectively what you’d need for the CFL-AA case above?</div></blockquote>I believe that, technically speaking, this is not legal. CFL-AA should really be a module pass if it wants to do IPA. I think that, at the time it was originally developed, it was made a function pass so that it could work without modifying every other function pass in the pipeline to mark it as preserved. Of course, we later did this anyway for GlobalsAA (a module-level analysis), so we should probably go back and do the same for CFL-AA.<br><br>I'm not sure that's the important distinction, however. GlobalsAA pre-computes all necessary data for the module up front (when runOnModule is called), so the scenario I described has no analogy there. If GlobalsAA computed information on Globals lazily (like CFL-AA builds function graphs lazily), it would have the same problem.<br><br>I'm not claiming that this is a good thing, I just wanted to point out that it can be a problem given code we have in-tree now.<br><br> -Hal<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><div></div><div><br class=""></div><div>Cheers,</div><div>Pete<br class=""><blockquote class=""><div class=""><br style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><span style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; float: none; display: inline ! important;" class=""> -Hal</span><br style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><blockquote style="font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;" class=""><div dir="ltr" class=""><div class=""></div><div class=""><br class=""></div><div class="">-Chandler<br class=""><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Tue, Mar 8, 2016 at 1:16 PM Quentin Colombet <<a href="mailto:qcolombet@apple.com" target="_blank" class="">qcolombet@apple.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><div class=""><blockquote class=""><div class="">On Mar 8, 2016, at 11:50 AM, Eric Christopher <<a href="mailto:echristo@gmail.com" target="_blank" class="">echristo@gmail.com</a>> wrote:</div><br class=""><div class=""><div dir="ltr" class=""><br class=""><br class=""><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><br class="">I could attach a patch, but first i’d really like to know if anyone is fundamentally opposed to this.<br class=""><br class=""></blockquote><div class=""><br class=""></div><div class="">Not necessarily. I think that any information that isn't being serialized in MI right now for a function could be as well. Definitely something for GlobalISel to keep in mind.</div></div></div></div></blockquote><div class=""><br class=""></div></div></div><div style="word-wrap: break-word;" class=""><div class=""><div class="">+1.</div><div class="">That’s basically where I would like to go with MachineModule/MachineModulePass.</div><div class=""><a href="http://lists.llvm.org/pipermail/llvm-dev/2016-January/094426.html" target="_blank" class="">http://lists.llvm.org/pipermail/llvm-dev/2016-January/094426.html</a></div><div class=""><br class=""></div>Cheers,</div><div class="">-Quentin</div></div><div style="word-wrap: break-word;" class=""><div class=""><br class=""><blockquote class=""><div class=""><div dir="ltr" class=""><div class="gmail_quote"><div class=""> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">I should note, a couple of issues have come up in the prototype.<br class="">- llvm::getDISubprogram was walking the function body to find the subprogram. This is trivial to fix as functions now have !dbg on them.<br class=""></blockquote><div class=""><br class=""></div><div class="">This is definitely worth it, please go ahead and do this.</div><div class=""> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">- The AsmPrinter is calling canBeOmittedFromSymbolTable on GlobalValue’s which then walks all their uses. I think this should be done earlier in codegen as an analysis whose results are available to the AsmPrinter.<br class=""></blockquote><div class=""><br class=""></div><div class="">I think this makes sense, but I worry about late added GlobalValues during code gen? How would we cope with that? Example: Let's say we start lowering a target specific construct as an MI pass etc and it constructs a global value, when do we run the analysis to make sure that all such things happen? Late as possible I'd assume. Maybe this isn't an issue, but thought I'd bring it up. At any rate, could you provide a bit more detail here?</div><div class=""><br class=""></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">- BB’s whose addresses are taken, i.e. jump tables, can’t be deleted. Those functions will just keep their IR around so no changes there.<br class=""><br class=""></blockquote><div class=""><br class=""></div><div class="">Oh well. Conveniently there aren't a lot of these.</div><div class=""><br class=""></div><div class="">-eric</div><div class=""><br class=""></div></div></div></div></blockquote></div></div></blockquote></div></div></div></blockquote><br style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><br style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><br style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><span style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; float: none; display: inline ! important;" class="">--<span class="Apple-converted-space"> </span></span><br style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><div style="font-family: arial,helvetica,sans-serif; font-size: 13px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><span class=""></span>Hal Finkel<br class="">Assistant Computational Scientist<br class="">Leadership Computing Facility<br class="">Argonne National Laboratory</div></div></blockquote></div><br class=""></blockquote><br><br><br>-- <br><div><span name="x"></span>Hal Finkel<br>Assistant Computational Scientist<br>Leadership Computing Facility<br>Argonne National Laboratory<span name="x"></span><br></div></div></body></html>