[PATCH] Support for reading run counts in llvm-cov

Justin Bogner mail at justinbogner.com
Mon Nov 4 17:02:11 PST 2013


Yuchen Wu <yuchenericwu at hotmail.com> writes:
> From cefe0819c7dc0f6825655f8d5e6b15c10907c3e4 Mon Sep 17 00:00:00 2001
> From: Yuchen Wu <yuchen_wu at apple.com>
> Date: Thu, 24 Oct 2013 21:37:27 -0700
> Subject: [PATCH 12/12] Support for reading run counts in llvm-cov.
>
> Similar to the previous patch, this enables llvm-cov to correctly ouput
> the run count stored in the GCDA file. Again, GCOVProfiling currently
> does not generate this information, so the GCDA run data had to be
> hacked on from a GCDA file generated by gcc. With the run and program
> data included, both llvm-cov and gcov produced the same output.

This commit message is confusing - probably best to take out the
references to the other patches and just say what this one does, on its
own.

> ---
>  include/llvm/Support/GCOV.h | 21 +++++++++++++++++++--
>  lib/IR/GCOV.cpp             | 14 +++++++++++++-
>  2 files changed, 32 insertions(+), 3 deletions(-)
>
> diff --git a/include/llvm/Support/GCOV.h b/include/llvm/Support/GCOV.h
> index 77ce4d6..c4fbead 100644
> --- a/include/llvm/Support/GCOV.h
> +++ b/include/llvm/Support/GCOV.h
> @@ -126,6 +126,19 @@ public:
>      return true;
>    }
>  
> +  /// readObjectTag - If cursor points to an object summary tag then increment 
> +  /// the cursor and return true otherwise return false.
> +  bool readObjectTag() {
> +    StringRef Tag = Buffer->getBuffer().slice(Cursor, Cursor+4);
> +    if (Tag.empty() ||
> +        Tag[0] != '\0' || Tag[1] != '\0' ||
> +        Tag[2] != '\0' || Tag[3] != '\xa1') {
> +      return false;
> +    }
> +    Cursor += 4;
> +    return true;
> +  }
> +
>    /// readProgramTag - If cursor points to a program summary tag then increment 
>    /// the cursor and return true otherwise return false.
>    bool readProgramTag() {
> @@ -163,6 +176,7 @@ public:
>    }
>  
>    uint64_t getCursor() const { return Cursor; }
> +  void advanceCursor(uint32_t n) { Cursor += n*4; }
>  private:
>    MemoryBuffer *Buffer;
>    uint64_t Cursor;
> @@ -172,13 +186,14 @@ private:
>  /// (.gcno and .gcda).
>  class GCOVFile {
>  public:
> -  GCOVFile() : Functions(), ProgramCount(0) {}
> +  GCOVFile() : Functions(), RunCount(0), ProgramCount(0) {}
>    ~GCOVFile();
>    bool read(GCOVBuffer &Buffer);
>    void dump();
>    void collectLineCounts(FileInfo &FI);
>  private:
>    SmallVector<GCOVFunction *, 16> Functions;
> +  uint32_t RunCount;
>    uint32_t ProgramCount;
>  };
>  
> @@ -234,10 +249,12 @@ public:
>    void addLineCount(StringRef Filename, uint32_t Line, uint64_t Count) {
>      LineInfo[Filename][Line-1] += Count;
>    }
> -  void setProgramCount(uint32_t PC) { ProgramCount = PC; }
> +  void setRunCount(uint32_t Runs) { RunCount = Runs; }
> +  void setProgramCount(uint32_t Programs) { ProgramCount = Programs; }
>    void print(raw_fd_ostream &OS, StringRef gcnoFile, StringRef gcdaFile);
>  private:
>    StringMap<LineCounts> LineInfo;
> +  uint32_t RunCount;
>    uint32_t ProgramCount;
>  };
>  
> diff --git a/lib/IR/GCOV.cpp b/lib/IR/GCOV.cpp
> index 0fd1606..3aeddfb 100644
> --- a/lib/IR/GCOV.cpp
> +++ b/lib/IR/GCOV.cpp
> @@ -59,8 +59,18 @@ bool GCOVFile::read(GCOVBuffer &Buffer) {
>        (void)ReadGCDA;
>        assert(ReadGCDA && ".gcda data does not match .gcno data");
>      }
> -    while (Buffer.readProgramTag())
> +    if (Buffer.readObjectTag()) {
> +      uint32_t Length = Buffer.readInt();
> +      Buffer.readInt(); // checksum
> +      Buffer.readInt(); // num
> +      RunCount = Buffer.readInt();
> +      Buffer.advanceCursor(Length-3);
> +    }
> +    while (Buffer.readProgramTag()) {
> +      uint32_t Length = Buffer.readInt();
> +      Buffer.advanceCursor(Length);
>        ++ProgramCount;
> +    }

This changes the behaviour when reading program tags. Is this an
unrelated bug fix?

>    }
>  
>    return true;
> @@ -79,6 +89,7 @@ void GCOVFile::collectLineCounts(FileInfo &FI) {
>    for (SmallVectorImpl<GCOVFunction *>::iterator I = Functions.begin(),
>           E = Functions.end(); I != E; ++I) 
>      (*I)->collectLineCounts(FI);
> +  FI.setRunCount(RunCount);
>    FI.setProgramCount(ProgramCount);
>  }
>  
> @@ -258,6 +269,7 @@ void FileInfo::print(raw_fd_ostream &OS, StringRef gcnoFile,
>      OS << "        -:    0:Source:" << Filename << "\n";
>      OS << "        -:    0:Graph:" << gcnoFile << "\n";
>      OS << "        -:    0:Data:" << gcdaFile << "\n";
> +    OS << "        -:    0:Runs:" << RunCount << "\n";
>      OS << "        -:    0:Programs:" << ProgramCount << "\n";
>      LineCounts &L = LineInfo[Filename];
>      OwningPtr<MemoryBuffer> Buff;



More information about the llvm-commits mailing list