<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">How about<div><br></div><div>startUp()</div><div><br></div><div>cleanUp()</div><div><br></div><div>would that avoid the confusion with doInitialization/doFinalization?</div><div><br></div><div>Pedro</div><div><br><div><div>On Dec 6, 2012, at 3:59 PM, Chandler Carruth <<a href="mailto:chandlerc@google.com">chandlerc@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-family: arial, helvetica, sans-serif; font-size: 10pt"><div dir="ltr">On Thu, Dec 6, 2012 at 3:53 PM, Jim Grosbach <span dir="ltr"><<a href="mailto:grosbach@apple.com" target="_blank">grosbach@apple.com</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"><div style="word-wrap:break-word"><br><div><div class="im"><div>On Dec 6, 2012, at 3:44 PM, Pedro Artigas <<a href="mailto:partigas@apple.com" target="_blank">partigas@apple.com</a>> wrote:</div>
<br><blockquote type="cite"><div style="word-wrap:break-word">There is not really any MCContext today that is a "pass", an MCContext is embedded inside MachineModuleInfo which is a pass. One solution would be to have:</div>
</blockquote><div><br></div></div>Ah, right. That does simplify things.</div><div><div class="im"><br><blockquote type="cite"><div style="word-wrap:break-word"><div><br></div><div>class MCContextManual</div><div><br></div>
<div>and </div><div><br></div><div>class MCContext : public MCContextManual</div><div><br></div><div>Regular users can continue using MCContext as they do today. MachineModuleInfo would, inside it's doInitialization / doFinalization call MCContextManual's doInitialization and doFinalization. Other users would have the doInitialization and doFinalization called automatically in the constructor/destructor.</div>
<div><br></div><div>This would prevent any multiple inheritance and would reduce code changes as users of MCContext can continue to use MCContext as they do today.</div><div><br></div><div>Is this ok?</div><div><br></div>
</div></blockquote><div><br></div></div><div>Sounds totally reasonable to me. Chandler?</div></div></div></blockquote><div><br></div><div style="">I don't think we should use the names doInitialization and doFinalization unless the thing is a pass.</div>
<div style=""><br></div><div style="">Instead, MCContext should just expose a 'reset' or 'clear' method that MachineModuleInfo can call at the appropriate time.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-Jim</div></font></span><div><div class="h5"><div><br></div><br><blockquote type="cite"><div style="word-wrap:break-word">
<div>Pedro</div><div><div><br></div><div><br><div><div>On Dec 6, 2012, at 3:26 PM, Jim Grosbach <<a href="mailto:grosbach@apple.com" target="_blank">grosbach@apple.com</a>> wrote:</div><br><blockquote type="cite"><div style="word-wrap:break-word">
<br><div><div>On Dec 6, 2012, at 3:24 PM, Chandler Carruth <<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>> wrote:</div><br><blockquote type="cite"><div style="font-family:arial,helvetica,sans-serif;font-size:10pt">
<div dir="ltr">On Thu, Dec 6, 2012 at 3:11 PM, Pedro Artigas <span dir="ltr"><<a href="mailto:partigas@apple.com" target="_blank">partigas@apple.com</a>></span> wrote:<br>
<div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word">
<div><br></div><div>Answer inline.</div>
<br><div><div><div>On Dec 6, 2012, at 2:51 PM, Chandler Carruth <<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>> wrote:</div><br><blockquote type="cite"><div style="font-family:arial,helvetica,sans-serif;font-size:10pt">

<div dir="ltr">On Thu, Dec 6, 2012 at 2:46 PM, Pedro Artigas <span dir="ltr"><<a href="mailto:partigas@apple.com" target="_blank">partigas@apple.com</a>></span> wrote:<br>
<div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Sure, no problem.<br>


<br>
The MCContext is used inside MachineModuleInfo which is a ImmutablePass under the pass manager model, it can also be used standalone. the change added a boolean that indicates if someone will call doInitialization / doFinalization to reuse the MCContext data structure across multiple modules or not, today only MachineModuleInfo does that, and, since it is a Pass it gets it's doInitialization/doFinalization called automagically by the pass manager and calls the MCContext doInitialization / doFinalization methods there.<br>



<br>
The issue was that since there are some uses of the MCContext that are outside of the PassManager, those need to have doInitialization and doFinalization called automatically by constructor/destructor as otherwise nobody would call doInitialization/doFinalization (which were the root cause of valgrind bugs in my prior check in)<br>



<br>
Is that sufficient context?<br></blockquote><div><br></div><div>This is a fantastic explanation. In the future, I would love to see this type of explanation in the commit log, it helps when reviewing the patch.</div>
<div><br></div><div>As a side-note, I feel it might be a slightly better design to have an MCContext, and an MCContextPass, where the MCContext doesn't have doInitialization / doFinalization (and in fact, doesn't derive from the Pass machinery), but the latter does. The latter can then construct and destroy the MCContext for each module. This design would make the bool flag unnecessary by encoding the two interfaces in the type system itself.</div>


<div><br></div><div>Would that make sense? Or is it really important performance wise to just clear the data structures inside MCContext rather than destroying and recreating them?</div></div></div></div></div></blockquote>

<div><br></div></div><div>It does make sense to have a MCContextManual and MCContextPass or some other name like this (the non Manual/Pass version, being the more specialized, should derive from the regular/Manual  one). </div>

<div><br></div><div>This would save the bool inside the class, (which is insignificant as it is a single bool in a class that has just a single instanced object) but I believe would make the code a little cleaner. Both approaches achieve pretty much the same thing with regards to compile time savings.</div>

<div><br></div><div>It is important to just clear the data structures, that is the source of compile time savings as there is no extra allocate/deallocate.</div></div></div></blockquote><div><br></div><div>I would structure this as:</div>

<div><br></div><div>MCContextImpl which exposes non-virtual 'clear' or 'reset' method to clean up the datastructures.</div><div><br></div><div>MCContext, derived from MCContextImpl, which just provides a normal, non-pass instance interface.</div>

<div><br></div><div>MCContextPass, derived from MCContextImpl and ImmutablePass, and redirects the virtual ImmutablePass interface into the MCContextImpl's reset.</div><div><br></div><div><br></div>
<div>If for some reason the multiple inheritance is problematic (which would be reasonable) I might go for:</div><div><br></div><div>MCContext, which works much like it used to, but adds a 'reset' method which resets the datastructures.</div>

<div><br></div><div>MCContextPass, which *contains* an MCContext, exposes it via a 'get' method, and resets it on the doInitialization / doFinalization call (whichever is more appropriate).</div><div>
<br></div><div><br></div><div>Thoughts Jim? Other parties interested in the MC design here?</div></div></div></div></div>
</blockquote><br></div><div><br></div><div>I like the second construction (an MCContextPass which contains an MCContext). It feels more intuitively correct to me. Plus I have an allergy to multiple inheritance.</div><div>
<br></div><div>-Jim</div><br></div></blockquote></div><br></div></div></div></blockquote></div></div></div><br></div></blockquote></div><br></div></div></div>
</blockquote></div><br></div></body></html>