<br><br>
<div><span class="gmail_quote">On 8/7/07, <b class="gmail_sendername">David Greene</b> <<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:dag@cray.com" target="_blank">dag@cray.com</a>> wrote:</span>
 
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">On Monday 06 August 2007 12:15, Anton Vayvod wrote:<br><br>> Spill intervals must be precolored because they can't be spilled once more. 
<br>> They are the shortest intervals precisely over each def/use of the original<br>> interval. That is why they also have their weights set to #INF.<br><br>Yes, that's true.  But I wonder if we shouldn't be smarter about which 
<br>register we pick to color it.  In Bill W's implementation, it was essentially<br>random.  What was your solution to this?</blockquote>
<div> </div>
<div>I allocated spill intervals at the beginning of each iteration so all the rest intervals (except of physreg intervals) were uncolored at the moment. So the only difference in allocating regs for spills was what end to choose: allocation_order_begin() or allocation_order_end(), I chose the former. I understand that sometimes you can prefer one register over another for spill so it won't conflict with as much intervals as it would being mapped to another phys, but the same can be said about every interval, right? 
<br> </div>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">> As for giving the best result. If assumed that each interval is spilled<br>> into the shortest spill intervals then precoloring won't do any harm to the 
<br>> quality of allocation (as shown above).<br><br>Wait, but aren't you implying then that it's impossible for an interval<br>corresponding to a spill to be uncolorable?  I don't think that's true.<br>
Therefore, precoloring most certainly can cause harm because a decision<br>is being made in local context without the global information that could<br>help make a better one.</blockquote>
<div> </div>
<div>At least this is the imply of LiveIntervals: try to call addIntervalsForSpills on a spill interval and you'll have an assertion (that was true at least for 1.9, probably it's true now). If spill interval has a length of 1 (and it has because of addIntervalsForSpills implementation) it can't be spilled again physically. Moreover if you were able to spill such intervals your iterations could become an infinite loop: algorithm could spill these intervals over and over again. Having spill intervals mapped to physregs garantees that your iterations will finish eventually. 
</div><br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">> But in theory you can spill intervals differently. For example, interval can<br>> be split into two  intervals - the shortest interval that cannot be colored 
<br>> right now and the  rest part that can be colored. That say if you have [10,<br>> 50) intervals that conflicts with [40, 45) and can't be colored it can be<br>> split into smth like  [10, 40) and [40, 50). The former part should not be 
<br>> precolored as it has  less conflicts (it doesn't intersects with [40, 45) )<br>> and can be colored entirely by one register on the next iteration.<br><br>Right.  Live range splitting would indeed be nice to have.  Bill's 
<br>implementation has a flavor of it.</blockquote>
<div> </div>
<div>In case live range splitting implemented spill intervals wouldn't have to be the shortest when some interval is spilled the first time. But during iterations uncolored spill intervals should become shorter and shorter until they are must-be-precolored. 
</div><br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">> Unfortunately, it seems that current implementation doesn't support such<br>> "clever" spilling. 
<br><br>True.  People have talked about adding it ever since I started getting<br>involved.<br><br>> Anyway, this precoloring doesn't force allocation algorithms to be<br>> non-iterative. In my implementation of optimistic register coloring I 
<br>> precolor spill intervals at the beginning of each iteration and thus don't<br>> have to spill their neghbours specifically. It was done automatically by<br>> Select phase of algorithm.<br><br>So how did you get around the requirement of the spillers that intervals 
<br>be mapped to physical registers?  Or did you not use the provided spillers?<br>That may be what I end up doing.  Loads and stores don't absolutely have to be<br>inserted into the actual instruction text on each iteration, though it is nice 
<br>for debugging purposes.</blockquote>
<div> </div>
<div>As far as I understand, you don't need to call spiller every iteration. LiveIntervals::addIntervalsForSpills does everything necessary for allocation to start next iteration. The idea is that when you spill some interval you only need to replace it with spill intervals for loads and stores and do the next iteration on new interval set but you don't need to insert actual instructions in code until the very end of your algorithm.
</div><br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">> As Fernando has mentioned while I was writing this after the last iteration<br>> of your algorithm before you call Spiller::runOnMachineFunction method 
<br>> every interval in VirtRegMap must be mapped to a physical register, both<br>> spill and others.<br><br>Right, which means the pre-defined spillers can't be called during iteration.</blockquote>
<div> </div>
<div>Exact.</div>
<div> </div>
<div>Anton.</div></div>