[PATCH] D96000: Don't emit coverage mapping for excluded functions

Petr Hosek via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 3 23:01:49 PST 2021


phosek created this revision.
phosek added reviewers: davidxl, vsk.
Herald added a subscriber: wenlei.
phosek requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When a function or a file is excluded using -fprofile-list= option,
don't emit coverage mapping as doing so confuses users since those
functions would always have zero count. This also reduces the binary
size considerably in cases where only a few functions or files are
being instrumented.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96000

Files:
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/test/CodeGen/profile-filter.c


Index: clang/test/CodeGen/profile-filter.c
===================================================================
--- clang/test/CodeGen/profile-filter.c
+++ clang/test/CodeGen/profile-filter.c
@@ -1,22 +1,31 @@
-// RUN: %clang_cc1 -fprofile-instrument=clang -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm %s -o - | FileCheck %s
 
 // RUN: echo "fun:test1" > %t-func.list
-// RUN: %clang_cc1 -fprofile-instrument=clang -fprofile-list=%t-func.list -emit-llvm %s -o - | FileCheck %s --check-prefix=FUNC
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -fprofile-list=%t-func.list -emit-llvm %s -o - | FileCheck %s --check-prefix=FUNC
 
 // RUN: echo "src:%s" | sed -e 's/\\/\\\\/g' > %t-file.list
-// RUN: %clang_cc1 -fprofile-instrument=clang -fprofile-list=%t-file.list -emit-llvm %s -o - | FileCheck %s --check-prefix=FILE
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -fprofile-list=%t-file.list -emit-llvm %s -o - | FileCheck %s --check-prefix=FILE
 
 // RUN: echo -e "[clang]\nfun:test1\n[llvm]\nfun:test2" > %t-section.list
 // RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t-section.list -emit-llvm %s -o - | FileCheck %s --check-prefix=SECTION
 
 // RUN: echo -e "fun:test*\n!fun:test1" > %t-exclude.list
-// RUN: %clang_cc1 -fprofile-instrument=clang -fprofile-list=%t-exclude.list -emit-llvm %s -o - | FileCheck %s --check-prefix=EXCLUDE
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -fprofile-list=%t-exclude.list -emit-llvm %s -o - | FileCheck %s --check-prefix=EXCLUDE
 
 // RUN: echo "!fun:test1" > %t-exclude-only.list
-// RUN: %clang_cc1 -fprofile-instrument=clang -fprofile-list=%t-exclude-only.list -emit-llvm %s -o - | FileCheck %s --check-prefix=EXCLUDE
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -fprofile-list=%t-exclude-only.list -emit-llvm %s -o - | FileCheck %s --check-prefix=EXCLUDE
 
 unsigned i;
 
+// CHECK: @__covrec_{{[0-9A-F]+}}u = linkonce_odr hidden constant <{ i64, i32, i64, i64, [{{.*}} x i8] }> <{ {{.*}} }>, section "__llvm_covfun"
+// CHECK: @__covrec_{{[0-9A-F]+}}u = linkonce_odr hidden constant <{ i64, i32, i64, i64, [{{.*}} x i8] }> <{ {{.*}} }>, section "__llvm_covfun"
+// FUNC: @__covrec_{{[0-9A-F]+}}u = linkonce_odr hidden constant <{ i64, i32, i64, i64, [{{.*}} x i8] }> <{ {{.*}} }>, section "__llvm_covfun"
+// FUNC-NOT: @__covrec_{{[0-9A-F]+}}u = linkonce_odr hidden constant <{ i64, i32, i64, i64, [{{.*}} x i8] }> <{ {{.*}} }>, section "__llvm_covfun"
+// FILE: @__covrec_{{[0-9A-F]+}}u = linkonce_odr hidden constant <{ i64, i32, i64, i64, [{{.*}} x i8] }> <{ {{.*}} }>, section "__llvm_covfun"
+// FILE: @__covrec_{{[0-9A-F]+}}u = linkonce_odr hidden constant <{ i64, i32, i64, i64, [{{.*}} x i8] }> <{ {{.*}} }>, section "__llvm_covfun"
+// EXCLUDE: @__covrec_{{[0-9A-F]+}}u = linkonce_odr hidden constant <{ i64, i32, i64, i64, [{{.*}} x i8] }> <{ {{.*}} }>, section "__llvm_covfun"
+// EXCLUDE-NOT: @__covrec_{{[0-9A-F]+}}u = linkonce_odr hidden constant <{ i64, i32, i64, i64, [{{.*}} x i8] }> <{ {{.*}} }>, section "__llvm_covfun"
+
 // CHECK-NOT: noprofile
 // CHECK: @test1
 // FUNC-NOT: noprofile
Index: clang/lib/CodeGen/CodeGenPGO.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenPGO.cpp
+++ clang/lib/CodeGen/CodeGenPGO.cpp
@@ -811,10 +811,10 @@
   if (isa<CXXDestructorDecl>(D) && GD.getDtorType() != Dtor_Base)
     return;
 
+  CGM.ClearUnusedCoverageMapping(D);
   if (Fn->hasFnAttribute(llvm::Attribute::NoProfile))
     return;
 
-  CGM.ClearUnusedCoverageMapping(D);
   setFuncName(Fn);
 
   mapRegionCounters(D);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96000.321320.patch
Type: text/x-patch
Size: 3695 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210204/86832b1e/attachment.bin>


More information about the cfe-commits mailing list