[PATCH] llvm-cov: Added -c option for branch counts.

Yuchen Wu yuchenericwu at hotmail.com
Mon Dec 16 13:33:11 PST 2013


>> @@ -538,17 +538,32 @@ void FileInfo::printBranchInfo(raw_fd_ostream &OS, const GCOVBlock &Block,
>>
>> for (SmallVectorImpl<uint64_t>::const_iterator I = BranchCounts.begin(),
>> E = BranchCounts.end(); I != E; ++I) {
>> - if (TotalCounts)
>> - OS << format("branch %2u taken %u%%\n", EdgeNo++,
>> - branchDiv(*I, TotalCounts));
>> - else
>> + if (TotalCounts) {
>> + if (Options.BranchCount) {
>> + // Print branch counts
>> + OS << format("branch %2u taken ", EdgeNo++) << *I << "\n";
>> + } else {
>> + // Print branch probabilities
>> + OS << format("branch %2u taken %u%%\n", EdgeNo++,
>> + branchDiv(*I, TotalCounts));
>> + }
>> + } else {
>> OS << format("branch %2u never executed\n", EdgeNo++);
>> + }
>> }
>> } else if (Options.UncondBranch && NumEdges == 1) {
>> // Print unconditional branch info.
>> - if ((*Block.dst_begin())->Count)
>> - OS << format("unconditional %2u taken 100%%\n", EdgeNo++);
>> - else
>> + uint64_t Count = (*Block.dst_begin())->Count;
>> + if (Count) {
>> + if (Options.BranchCount) {
>> + // Print branch counts
>> + OS << format("unconditional %2u taken ", EdgeNo++) << Count << "\n";
>> + } else {
>> + // Print branch probabilities
>> + OS << format("unconditional %2u taken 100%%\n", EdgeNo++);
>> + }
>> + } else {
>> OS << format("unconditional %2u never executed\n", EdgeNo++);
>> + }
>
> These two blocks are a bit redundant and they're starting to get a bit
> ugly with the chain of conditions. Would it be better if we hid the
> conditions and wrote something like these?
>
> OS << format("branch %2u ", EdgeNo++) <<
> formatBranchInfo(*I, TotalCounts) << "\n";
> // ...
> OS << format("unconditional %2u ", EdgeNo++) <<
> formatBranchInfo(Count, Count) << "\n";

Good idea, it's much cleaner this way. In addition to adding formatBranchInfo, I moved the other two helper functions into FileInfo as private member functions. 		 	   		  
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-llvm-cov-Moved-helper-functions-to-private-members.patch
Type: application/octet-stream
Size: 2977 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131216/36381548/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-llvm-cov-Added-c-option-for-branch-counts.patch
Type: application/octet-stream
Size: 12353 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131216/36381548/attachment-0001.obj>


More information about the llvm-commits mailing list