[llvm] r194637 - llvm-cov: Removed StringMap holding GCOVLines.

Yuchen Wu yuchenericwu at hotmail.com
Wed Nov 13 16:32:00 PST 2013


Author: ywu
Date: Wed Nov 13 18:32:00 2013
New Revision: 194637

URL: http://llvm.org/viewvc/llvm-project?rev=194637&view=rev
Log:
llvm-cov: Removed StringMap holding GCOVLines.

According to the hazy gcov documentation, it appeared to be technically
possible for lines within a block to belong to different source files.
However, upon further investigation, gcov does not actually support
multiple source files for a single block.

This change removes a level of separation between blocks and lines by
replacing the StringMap of GCOVLines with a SmallVector of ints
representing line numbers. This also means that the GCOVLines class is
no longer needed.

This paves the way for supporting the "-a" option, which will output
block information.

Added:
    llvm/trunk/test/tools/llvm-cov/Inputs/test_read_fail.gcno
Modified:
    llvm/trunk/include/llvm/Support/GCOV.h
    llvm/trunk/lib/IR/GCOV.cpp

Modified: llvm/trunk/include/llvm/Support/GCOV.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/GCOV.h?rev=194637&r1=194636&r2=194637&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/GCOV.h (original)
+++ llvm/trunk/include/llvm/Support/GCOV.h Wed Nov 13 18:32:00 2013
@@ -25,7 +25,6 @@ namespace llvm {
 
 class GCOVFunction;
 class GCOVBlock;
-class GCOVLines;
 class FileInfo;
 
 namespace GCOV {
@@ -211,6 +210,7 @@ public:
   GCOVFunction() : Ident(0), LineNumber(0) {}
   ~GCOVFunction();
   bool read(GCOVBuffer &Buffer, GCOV::GCOVFormat Format);
+  StringRef getFilename() const { return Filename; }
   void dump();
   void collectLineCounts(FileInfo &FI);
 private:
@@ -224,31 +224,21 @@ private:
 /// GCOVBlock - Collects block information.
 class GCOVBlock {
 public:
-  GCOVBlock(uint32_t N) : Number(N), Counter(0) {}
+  GCOVBlock(GCOVFunction &P, uint32_t N) :
+    Parent(P), Number(N), Counter(0), Edges(), Lines() {}
   ~GCOVBlock();
   void addEdge(uint32_t N) { Edges.push_back(N); }
-  void addLine(StringRef Filename, uint32_t LineNo);
+  void addLine(uint32_t N) { Lines.push_back(N); }
   void addCount(uint64_t N) { Counter += N; }
   size_t getNumEdges() { return Edges.size(); }
   void dump();
   void collectLineCounts(FileInfo &FI);
 private:
+  GCOVFunction &Parent;
   uint32_t Number;
   uint64_t Counter;
   SmallVector<uint32_t, 16> Edges;
-  StringMap<GCOVLines *> Lines;
-};
-
-/// GCOVLines - A wrapper around a vector of int to keep track of line nos.
-class GCOVLines {
-public:
-  ~GCOVLines() { Lines.clear(); }
-  void add(uint32_t N) { Lines.push_back(N); }
-  void collectLineCounts(FileInfo &FI, StringRef Filename, uint64_t Count);
-  void dump();
-
-private:
-  SmallVector<uint32_t, 4> Lines;
+  SmallVector<uint32_t, 16> Lines;
 };
 
 typedef DenseMap<uint32_t, uint64_t> LineCounts;

Modified: llvm/trunk/lib/IR/GCOV.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/GCOV.cpp?rev=194637&r1=194636&r2=194637&view=diff
==============================================================================
--- llvm/trunk/lib/IR/GCOV.cpp (original)
+++ llvm/trunk/lib/IR/GCOV.cpp Wed Nov 13 18:32:00 2013
@@ -161,7 +161,7 @@ bool GCOVFunction::read(GCOVBuffer &Buff
   if (!Buff.readInt(BlockCount)) return false;
   for (uint32_t i = 0, e = BlockCount; i != e; ++i) {
     if (!Buff.readInt(Dummy)) return false; // Block flags;
-    Blocks.push_back(new GCOVBlock(i));
+    Blocks.push_back(new GCOVBlock(*this, i));
   }
 
   // read edges.
@@ -197,14 +197,18 @@ bool GCOVFunction::read(GCOVBuffer &Buff
     GCOVBlock *Block = Blocks[BlockNo];
     if (!Buff.readInt(Dummy)) return false; // flag
     while (Buff.getCursor() != (EndPos - 4)) {
-      StringRef Filename;
-      if (!Buff.readString(Filename)) return false;
+      StringRef F;
+      if (!Buff.readString(F)) return false;
+      if (F != Filename) {
+        errs() << "Multiple sources for a single basic block.\n";
+        return false;
+      }
       if (Buff.getCursor() == (EndPos - 4)) break;
       while (true) {
         uint32_t Line;
         if (!Buff.readInt(Line)) return false;
         if (!Line) break;
-        Block->addLine(Filename, Line);
+        Block->addLine(Line);
       }
     }
     if (!Buff.readInt(Dummy)) return false; // flag
@@ -234,22 +238,15 @@ void GCOVFunction::collectLineCounts(Fil
 /// ~GCOVBlock - Delete GCOVBlock and its content.
 GCOVBlock::~GCOVBlock() {
   Edges.clear();
-  DeleteContainerSeconds(Lines);
-}
-
-void GCOVBlock::addLine(StringRef Filename, uint32_t LineNo) {
-  GCOVLines *&LinesForFile = Lines[Filename];
-  if (!LinesForFile)
-    LinesForFile = new GCOVLines();
-  LinesForFile->add(LineNo);
+  Lines.clear();
 }
 
 /// collectLineCounts - Collect line counts. This must be used after
 /// reading .gcno and .gcda files.
 void GCOVBlock::collectLineCounts(FileInfo &FI) {
-  for (StringMap<GCOVLines *>::iterator I = Lines.begin(),
+  for (SmallVectorImpl<uint32_t>::iterator I = Lines.begin(),
          E = Lines.end(); I != E; ++I)
-    I->second->collectLineCounts(FI, I->first(), Counter);
+    FI.addLineCount(Parent.getFilename(), *I, Counter);
 }
 
 /// dump - Dump GCOVBlock content to dbgs() for debugging purposes.
@@ -264,35 +261,14 @@ void GCOVBlock::dump() {
   }
   if (!Lines.empty()) {
     dbgs() << "\tLines : ";
-    for (StringMap<GCOVLines *>::iterator LI = Lines.begin(),
-           LE = Lines.end(); LI != LE; ++LI) {
-      dbgs() << LI->first() << " -> ";
-      LI->second->dump();
-      dbgs() << "\n";
-    }
+    for (SmallVectorImpl<uint32_t>::iterator I = Lines.begin(),
+           E = Lines.end(); I != E; ++I)
+      dbgs() << (*I) << ",";
+    dbgs() << "\n";
   }
 }
 
 //===----------------------------------------------------------------------===//
-// GCOVLines implementation.
-
-/// collectLineCounts - Collect line counts. This must be used after
-/// reading .gcno and .gcda files.
-void GCOVLines::collectLineCounts(FileInfo &FI, StringRef Filename, 
-                                  uint64_t Count) {
-  for (SmallVectorImpl<uint32_t>::iterator I = Lines.begin(),
-         E = Lines.end(); I != E; ++I)
-    FI.addLineCount(Filename, *I, Count);
-}
-
-/// dump - Dump GCOVLines content to dbgs() for debugging purposes.
-void GCOVLines::dump() {
-  for (SmallVectorImpl<uint32_t>::iterator I = Lines.begin(),
-         E = Lines.end(); I != E; ++I)
-    dbgs() << (*I) << ",";
-}
-
-//===----------------------------------------------------------------------===//
 // FileInfo implementation.
 
 /// print -  Print source files with collected line count information.

Added: llvm/trunk/test/tools/llvm-cov/Inputs/test_read_fail.gcno
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/test_read_fail.gcno?rev=194637&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/llvm-cov/Inputs/test_read_fail.gcno (added) and llvm/trunk/test/tools/llvm-cov/Inputs/test_read_fail.gcno Wed Nov 13 18:32:00 2013 differ





More information about the llvm-commits mailing list