[llvm] r196856 - llvm-cov: Added -a option for block data.
NAKAMURA Takumi
geek4civic at gmail.com
Mon Dec 9 21:57:01 PST 2013
2013/12/10 Yuchen Wu <yuchenericwu at hotmail.com>:
> Author: ywu
> Date: Mon Dec 9 19:02:07 2013
> New Revision: 196856
>
> URL: http://llvm.org/viewvc/llvm-project?rev=196856&view=rev
> Log:
> llvm-cov: Added -a option for block data.
>
> Similar to gcov, llvm-cov will now print out the block count at the end
> of each block. Multiple blocks can end on the same line.
>
> One computational difference is by using -a, llvm-cov will no longer
> simply add the block counts together to form a line count. Instead, it
> will take the maximum of the block counts on that line. This has a
> similar effect to what gcov does, but generates more correct counts in
> certain scenarios.
>
> Also updated tests.
>
> Added:
> llvm/trunk/test/tools/llvm-cov/Inputs/test_-a.cpp.gcov
> - copied, changed from r196850, llvm/trunk/test/tools/llvm-cov/Inputs/test.cpp.orig_gcov
> llvm/trunk/test/tools/llvm-cov/Inputs/test_-a.h.gcov
> - copied, changed from r196850, llvm/trunk/test/tools/llvm-cov/Inputs/test.h.orig_gcov
> llvm/trunk/test/tools/llvm-cov/Inputs/test_no_options.cpp.gcov
> - copied, changed from r196850, llvm/trunk/test/tools/llvm-cov/Inputs/test.cpp.orig_gcov
> llvm/trunk/test/tools/llvm-cov/Inputs/test_no_options.h.gcov
> - copied, changed from r196850, llvm/trunk/test/tools/llvm-cov/Inputs/test.h.orig_gcov
> Removed:
> llvm/trunk/test/tools/llvm-cov/Inputs/test.cpp.orig_gcov
> llvm/trunk/test/tools/llvm-cov/Inputs/test.h.orig_gcov
> Modified:
> llvm/trunk/include/llvm/Support/GCOV.h
> llvm/trunk/lib/IR/GCOV.cpp
> llvm/trunk/test/tools/llvm-cov/llvm-cov.test
> llvm/trunk/tools/llvm-cov/llvm-cov.cpp
> Modified: llvm/trunk/lib/IR/GCOV.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/GCOV.cpp?rev=196856&r1=196855&r2=196856&view=diff
> ==============================================================================
> --- llvm/trunk/lib/IR/GCOV.cpp (original)
> +++ llvm/trunk/lib/IR/GCOV.cpp Mon Dec 9 19:02:07 2013
> @@ -358,7 +358,8 @@ void GCOVBlock::dump() const {
> // FileInfo implementation.
>
> /// print - Print source files with collected line count information.
> -void FileInfo::print(StringRef GCNOFile, StringRef GCDAFile) const {
> +void FileInfo::print(StringRef GCNOFile, StringRef GCDAFile,
> + const GCOVOptions &Options) const {
> for (StringMap<LineData>::const_iterator I = LineInfo.begin(),
> E = LineInfo.end(); I != E; ++I) {
> StringRef Filename = I->first();
> @@ -385,13 +386,21 @@ void FileInfo::print(StringRef GCNOFile,
> for (uint32_t i = 0; !AllLines.empty(); ++i) {
> LineData::const_iterator BlocksIt = Line.find(i);
>
> - // Add up the block counts to form line counts.
> if (BlocksIt != Line.end()) {
> + // Add up the block counts to form line counts.
> const BlockVector &Blocks = BlocksIt->second;
> uint64_t LineCount = 0;
> for (BlockVector::const_iterator I = Blocks.begin(), E = Blocks.end();
> I != E; ++I) {
> - LineCount += (*I)->getCount();
> + const GCOVBlock *Block = *I;
> + if (Options.AllBlocks) {
> + // Only take the highest block count for that line.
> + uint64_t BlockCount = Block->getCount();
> + LineCount = LineCount > BlockCount ? LineCount : BlockCount;
> + } else {
> + // Sum up all of the block counts.
> + LineCount += Block->getCount();
> + }
> }
> if (LineCount == 0)
> OS << " #####:";
> @@ -403,6 +412,24 @@ void FileInfo::print(StringRef GCNOFile,
> std::pair<StringRef, StringRef> P = AllLines.split('\n');
> OS << format("%5u:", i+1) << P.first << "\n";
> AllLines = P.second;
> +
> + if (Options.AllBlocks && BlocksIt != Line.end()) {
> + // Output the counts for each block at the last line of the block.
> + uint32_t BlockNo = 0;
> + const BlockVector &Blocks = BlocksIt->second;
> + for (BlockVector::const_iterator I = Blocks.begin(), E = Blocks.end();
> + I != E; ++I) {
> + const GCOVBlock *Block = *I;
> + if (Block->getLastLine() != i+1)
> + continue;
> +
> + if (Block->getCount() == 0)
> + OS << " $$$$$:";
> + else
> + OS << format("%9lu:", Block->getCount());
Don't use %lu with any assumptions. It broke i686 (and other bigendian
32bit hosts).
Fixed in r196882.
> + OS << format("%5u-block %u\n", i+1, BlockNo++);
> + }
> + }
> }
> }
> }
More information about the llvm-commits
mailing list