[all-commits] [llvm/llvm-project] 4d7b19: [llvm-cov gcov] Refactor counting and reporting

Fangrui Song via All-commits all-commits at lists.llvm.org
Sun Sep 13 23:02:28 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 4d7b19454397103620394dcceaf29592ef195231
      https://github.com/llvm/llvm-project/commit/4d7b19454397103620394dcceaf29592ef195231
  Author: Fangrui Song <i at maskray.me>
  Date:   2020-09-13 (Sun, 13 Sep 2020)

  Changed paths:
    M llvm/include/llvm/ProfileData/GCOV.h
    M llvm/lib/ProfileData/GCOV.cpp
    M llvm/test/tools/llvm-cov/gcov-fake-4.2.c
    M llvm/test/tools/llvm-cov/llvm-cov.test
    M llvm/tools/llvm-cov/gcov.cpp

  Log Message:
  -----------
  [llvm-cov gcov] Refactor counting and reporting

The current organization of FileInfo and its referenced utility functions of
(GCOVFile, GCOVFunction, GCOVBlock) is messy. Some members of FileInfo are just
copied from GCOVFile. FileInfo::print (.gcov output and --intermediate output)
is interleaved with branch statistics and computation of line execution counts.
--intermediate has to do redundant .gcov output to gather branch statistics.

This patch deletes lots of code and introduces a clearer work flow:

```
fn collectFunction
  for each block b
    for each line lineNum
      let line be LineInfo of the file on lineNum
      line.exists = 1
      increment function's lines & linesExec if necessary
      increment line.count
      line.blocks.push_back(&b)

fn collectSourceLine
  compute cycle counts
  count = incoming_counts + cycle_counts
  if line.exists
    ++summary->lines
    if line.count
      ++summary->linesExec

fn collectSource
  for each line
    call collectSourceLine

fn main
  for each function
    call collectFunction
    print function summary
  for each source file
    call collectSource
    print file summary
    annotate the source file with line execution counts
  if -i
    print intermediate file
```

The output order of functions and files now follows the original order in
.gcno files.




More information about the All-commits mailing list