Skip to content

Commit

Permalink
[gcov] Add spanning tree optimization
Browse files Browse the repository at this point in the history
gcov is an "Edge Profiling with Edge Counters" application according to
Optimally Profiling and Tracing Programs (1994).

The minimum number of counters necessary is |E|-(|V|-1). The unmeasured edges
form a spanning tree. Both GCC --coverage and clang -fprofile-generate leverage
this optimization. This patch implements the optimization for clang --coverage.
The produced .gcda files are much smaller now.
  • Loading branch information
MaskRay committed Sep 13, 2020
1 parent f086e85 commit 63182c2
Show file tree
Hide file tree
Showing 6 changed files with 326 additions and 151 deletions.
1 change: 0 additions & 1 deletion clang/test/CodeGen/code-coverage-tsan.c
Expand Up @@ -5,7 +5,6 @@
// CHECK-LABEL: void @foo()
/// Two counters are incremented by __tsan_atomic64_fetch_add.
// CHECK: call i64 @__tsan_atomic64_fetch_add
// CHECK-NEXT: call i64 @__tsan_atomic64_fetch_add
// CHECK-NEXT: call i32 @__tsan_atomic32_fetch_sub

_Atomic(int) cnt;
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/test/profile/Posix/gcov-fork.c
Expand Up @@ -17,7 +17,7 @@ int main(void) { // CHECK-NEXT: 1: [[#@LINE]]:
int status; // CHECK-NEXT: -: [[#@LINE]]:
func1(); // CHECK-NEXT: 1: [[#@LINE]]:
pid_t pid = fork(); // CHECK-NEXT: 1: [[#@LINE]]:
if (pid == -1) return 1; // CHECK-NEXT: 2: [[#@LINE]]:
if (pid == -1) return 1; // CHECK-NEXT: 1: [[#@LINE]]:
if (pid) // CHECK-NEXT: 2: [[#@LINE]]:
wait(&status); // CHECK-NEXT: 1: [[#@LINE]]:
func2(); // CHECK-NEXT: 2: [[#@LINE]]:
Expand Down
8 changes: 4 additions & 4 deletions compiler-rt/test/profile/gcov-dump-and-remove.c
Expand Up @@ -11,10 +11,10 @@
extern void __gcov_dump(void);
extern void __gcov_reset(void);
extern int remove(const char *); // CHECK: -: [[#@LINE]]:extern int remove
int main(void) { // CHECK-NEXT: #####: [[#@LINE]]:
__gcov_dump(); // CHECK-NEXT: #####: [[#@LINE]]:
__gcov_reset(); // CHECK-NEXT: #####: [[#@LINE]]:
if (remove("gcov-dump-and-remove.gcda") != 0) // CHECK-NEXT: #####: [[#@LINE]]:
int main(void) { // CHECK-NEXT: 1: [[#@LINE]]:
__gcov_dump(); // CHECK-NEXT: 1: [[#@LINE]]:
__gcov_reset(); // CHECK-NEXT: 1: [[#@LINE]]:
if (remove("gcov-dump-and-remove.gcda") != 0) // CHECK-NEXT: 1: [[#@LINE]]:
return 1; // CHECK-NEXT: #####: [[#@LINE]]: return 1;
// CHECK-NEXT: -: [[#@LINE]]:
__gcov_dump(); // CHECK-NEXT: 1: [[#@LINE]]:
Expand Down

0 comments on commit 63182c2

Please sign in to comment.