[clang] 9fd9b5a - Don't emit coverage mapping for excluded functions
Petr Hosek via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 5 13:04:08 PST 2021
Author: Petr Hosek
Date: 2021-02-05T13:03:57-08:00
New Revision: 9fd9b5a9c9ece53ce36ec87e7dc8389d0f572476
URL: https://github.com/llvm/llvm-project/commit/9fd9b5a9c9ece53ce36ec87e7dc8389d0f572476
DIFF: https://github.com/llvm/llvm-project/commit/9fd9b5a9c9ece53ce36ec87e7dc8389d0f572476.diff
LOG: Don't emit coverage mapping for excluded functions
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.
Differential Revision: https://reviews.llvm.org/D96000
Added:
Modified:
clang/lib/CodeGen/CodeGenPGO.cpp
clang/test/CodeGen/profile-filter.c
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp
index 08ae87785065..49b38a404f5d 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -811,10 +811,10 @@ void CodeGenPGO::assignRegionCounters(GlobalDecl GD, llvm::Function *Fn) {
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);
diff --git a/clang/test/CodeGen/profile-filter.c b/clang/test/CodeGen/profile-filter.c
index dc5a31e872a1..d39097076fc9 100644
--- a/clang/test/CodeGen/profile-filter.c
+++ b/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 -dump-coverage-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 -dump-coverage-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 -dump-coverage-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 -dump-coverage-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 -dump-coverage-mapping -fprofile-list=%t-exclude-only.list -emit-llvm %s -o - | FileCheck %s --check-prefix=EXCLUDE
unsigned i;
+// CHECK: test1
+// CHECK: test2
+// FUNC: test1
+// FUNC-NOT: test2
+// FILE: test1
+// FILE: test2
+// EXCLUDE-NOT: test1
+// EXCLUDE: test2
+
// CHECK-NOT: noprofile
// CHECK: @test1
// FUNC-NOT: noprofile
More information about the cfe-commits
mailing list