Skip to content

Commit

Permalink
llvm-cov: Store blocks rather than counts per line.
Browse files Browse the repository at this point in the history
Each line stores all the blocks that execute on that line, instead of
only storing the line counts previously accumulated. This provides more
information for each line, and will be useful for options in enabling
block and branch information.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@196177 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
yuchenericwu committed Dec 3, 2013
1 parent 2331c9f commit 357fcf9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
10 changes: 6 additions & 4 deletions include/llvm/Support/GCOV.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ class GCOVBlock {
}
void addLine(uint32_t N) { Lines.push_back(N); }
void addCount(size_t DstEdgeNo, uint64_t N);
uint64_t getCount() const { return Counter; }
size_t getNumSrcEdges() const { return SrcEdges.size(); }
size_t getNumDstEdges() const { return DstEdges.size(); }

Expand All @@ -269,17 +270,18 @@ class GCOVBlock {
SmallVector<uint32_t, 16> Lines;
};

typedef DenseMap<uint32_t, uint64_t> LineCounts;
typedef SmallVector<const GCOVBlock *, 4> BlockVector;
typedef DenseMap<uint32_t, BlockVector> LineData;
class FileInfo {
public:
void addLineCount(StringRef Filename, uint32_t Line, uint64_t Count) {
LineInfo[Filename][Line-1] += Count;
void addBlockLine(StringRef Filename, uint32_t Line, const GCOVBlock *Block) {
LineInfo[Filename][Line-1].push_back(Block);
}
void setRunCount(uint32_t Runs) { RunCount = Runs; }
void setProgramCount(uint32_t Programs) { ProgramCount = Programs; }
void print(raw_fd_ostream &OS, StringRef gcnoFile, StringRef gcdaFile) const;
private:
StringMap<LineCounts> LineInfo;
StringMap<LineData> LineInfo;
uint32_t RunCount;
uint32_t ProgramCount;
};
Expand Down
20 changes: 13 additions & 7 deletions lib/IR/GCOV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ void GCOVBlock::addCount(size_t DstEdgeNo, uint64_t N) {
void GCOVBlock::collectLineCounts(FileInfo &FI) {
for (SmallVectorImpl<uint32_t>::iterator I = Lines.begin(),
E = Lines.end(); I != E; ++I)
FI.addLineCount(Parent.getFilename(), *I, Counter);
FI.addBlockLine(Parent.getFilename(), *I, this);
}

/// dump - Dump GCOVBlock content to dbgs() for debugging purposes.
Expand Down Expand Up @@ -319,7 +319,7 @@ void GCOVBlock::dump() const {
/// print - Print source files with collected line count information.
void FileInfo::print(raw_fd_ostream &OS, StringRef gcnoFile,
StringRef gcdaFile) const {
for (StringMap<LineCounts>::const_iterator I = LineInfo.begin(),
for (StringMap<LineData>::const_iterator I = LineInfo.begin(),
E = LineInfo.end(); I != E; ++I) {
StringRef Filename = I->first();
OwningPtr<MemoryBuffer> Buff;
Expand All @@ -335,15 +335,21 @@ void FileInfo::print(raw_fd_ostream &OS, StringRef gcnoFile,
OS << " -: 0:Runs:" << RunCount << "\n";
OS << " -: 0:Programs:" << ProgramCount << "\n";

const LineCounts &L = I->second;
const LineData &L = I->second;
uint32_t i = 0;
while (!AllLines.empty()) {
LineCounts::const_iterator CountIt = L.find(i);
if (CountIt != L.end()) {
if (CountIt->second == 0)
LineData::const_iterator BlocksIt = L.find(i);
if (BlocksIt != L.end()) {
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();
}
if (LineCount == 0)
OS << " #####:";
else
OS << format("%9" PRIu64 ":", CountIt->second);
OS << format("%9" PRIu64 ":", LineCount);
} else {
OS << " -:";
}
Expand Down

0 comments on commit 357fcf9

Please sign in to comment.