[PATCH] llvm-cov: Added -b option for branch probabilities.

Yuchen Wu yuchenericwu at hotmail.com
Wed Dec 11 20:13:38 PST 2013


>> +// It is unlikely--but possible--for multiple functions to be on the same line.
>> +// But optimize for the common case.
> 
> What is this comment talking about?

The reason FunctionVector exists is because LineData needs to be able to store all of the functions that are on a single line. The comment is to explain that it's unlikely two functions will be on the same line, so optimize for the common case by setting the SmallVector typedef to contain a single element.

>> +typedef SmallVector<const GCOVFunction *, 1> FunctionVector;
>> +typedef DenseMap<uint32_t, FunctionVector> FunctionLines;
>> typedef SmallVector<const GCOVBlock *, 4> BlockVector;
>> -typedef DenseMap<uint32_t, BlockVector> LineData;
>> +typedef DenseMap<uint32_t, BlockVector> BlockLines;

>> +// Safe integer division, returns 0 if divisor is 0.
>> +static uint32_t safeDiv(uint64_t Numerator, uint64_t Divisor) {
>> + if (Divisor == 0)
>> + return 0;
>> + return Numerator/Divisor;
>> +}
> 
> Why do you need this?
> 
>> +
>> +// This custom division function mimics gcov's branch ouputs:
>> +// - Round to closest whole number
>> +// - Only output 0% or 100% if it's exactly that value
>> +static uint32_t branchDiv(uint64_t Numerator, uint64_t Divisor) {
>> + uint8_t Res = safeDiv(Numerator*100+Divisor/2, Divisor);
>> + if (Res == 0 && Numerator)
>> + return 1;
> 
> This seems like pretty strange behaviour if Divisor == 0.

The safeDiv and branchDiv functions need to return 0 if it's asked to divide 0 by 0, which actually happens quite often.

I've implemented all the other suggestions you made into this new patch. Enjoy! 		 	   		  
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-llvm-cov-Added-b-option-for-branch-probabilities.patch
Type: application/octet-stream
Size: 21816 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131211/3482a6f6/attachment.obj>


More information about the llvm-commits mailing list