<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Tue, Jul 28, 2015 at 4:29 PM Cong Hou <<a href="mailto:congh@google.com">congh@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Tue, Jul 28, 2015 at 4:20 PM, Chandler Carruth <<a href="mailto:chandlerc@gmail.com" target="_blank">chandlerc@gmail.com</a>> wrote:<br>
> On Tue, Jul 28, 2015 at 3:58 PM Cong Hou <<a href="mailto:congh@google.com" target="_blank">congh@google.com</a>> wrote:<br>
>><br>
>> I found it not straightforward to normalize weights in MBPI. Note that<br>
>> MBPI reads weights from MBB, which provides the interface<br>
>> addSuccessor(MachineBasicBlock *succ, uint32_t weight) to let users indicate<br>
>> arbitrary weights for new added edges. Because we don't know how users use<br>
>> this interface, it can be difficult to adjust weights in MBB. I think there<br>
>> may be two solutions:<br>
>><br>
>> 1. We provide the interface normalizeWeights in MBB. Once we call this<br>
>> interface, the sum of weights is guaranteed to be less than UINT32_MAX.<br>
>> However, after the user add new successors with weights, we need to<br>
>> re-normalize it. This can still be useful when we want to calculate branch<br>
>> probabilities or do other adjustment after the weights are normalized.<br>
>><br>
>> 2. We maintained both normalized and original weights in MBB, so that once<br>
>> the original weights is modified, we also adjust the normalized weights.<br>
>> This solutions requires more space and more frequent calculations comparing<br>
>> to the first one, but the normalized weights are always guaranteed.<br>
>><br>
>> Do you have any other ideas? Or which one do you think is better?<br>
><br>
><br>
> First off, yuck, but thanks for digging into this.<br>
><br>
> 3. Another alternative might be to keep the sum stored, and when adding a<br>
> weight, we could simply check if that would overflow, if so, re-normalize<br>
> everything. It would require auditing code that adds a successor to ensure<br>
> it doesn't rely on the weights after adding a successor being the same, but<br>
> that seems unlikely to come up.<br>
><br>
> I'd particularly like to hear Duncan's thoughts on which of these options<br>
> would make most sense. I see pros and cons on all of these. I think I'd be<br>
> fine with either #1 or #3. I agree with your concern over the space<br>
> requirements of #2.<br>
<br>
Thanks for the suggestion! For #3 solution, what if the user first<br>
calculates weights for several successors and add them one by one? Do<br>
we need to notify the user how we normalize the weights so that the<br>
user can adjust the weights that are not added yet?<br></blockquote><div><br></div><div>Yuck, possibly.</div><div><br></div><div>Are there such callers of this API?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Cong<br>
<br>
><br>
>><br>
>><br>
>><br>
>> <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D10825&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=qwS0RpNdTZ35XHlMAtnJOJt2RmsaeQevH6NsZiMAomQ&s=QROhGfrpu_p1hJdDKU3aGa5kgmnUwfK8mKcOGFDHvKQ&e=" rel="noreferrer" target="_blank">http://reviews.llvm.org/D10825</a><br>
>><br>
>><br>
>><br>
>><br>
>> _______________________________________________<br>
>> llvm-commits mailing list<br>
>> <a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div>