[compiler-rt] 3580daa - [InstrProf] Allow CSIRPGO function entry coverage

Ellis Hoag via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 18 15:10:20 PDT 2022


Author: Ellis Hoag
Date: 2022-07-18T15:10:11-07:00
New Revision: 3580daacf3ecb9bc628d05a4037266df6532ad6e

URL: https://github.com/llvm/llvm-project/commit/3580daacf3ecb9bc628d05a4037266df6532ad6e
DIFF: https://github.com/llvm/llvm-project/commit/3580daacf3ecb9bc628d05a4037266df6532ad6e.diff

LOG: [InstrProf] Allow CSIRPGO function entry coverage

The flag `-fcs-profile-generate` for enabling CSIRPGO moves the pass
`pgo-instrumentation` after inlining. Function entry coverage works fine
with this change, so remove the assert. I had originally left this
assert in because I had not tested this at the time.

Reviewed By: davidxl, MaskRay

Differential Revision: https://reviews.llvm.org/D129407

Added: 
    

Modified: 
    compiler-rt/test/profile/gcc-flag-compatibility.test
    compiler-rt/test/profile/instrprof-coverage.c
    compiler-rt/test/profile/lit.cfg.py
    llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/profile/gcc-flag-compatibility.test b/compiler-rt/test/profile/gcc-flag-compatibility.test
index 5b05e769cb145..c724aeb087a45 100644
--- a/compiler-rt/test/profile/gcc-flag-compatibility.test
+++ b/compiler-rt/test/profile/gcc-flag-compatibility.test
@@ -1,6 +1,6 @@
 RUN: rm -rf %t.d
 RUN: mkdir -p %t.d
-RUN: %clang_profgen_gcc=%t.d/d1/d2 -o %t.d/code %S/Inputs/gcc-flag-compatibility.c
+RUN: %clang_pgogen=%t.d/d1/d2 -o %t.d/code %S/Inputs/gcc-flag-compatibility.c
 
 # Test that the instrumented code writes to %t.d/d1/d2/
 RUN: %run %t.d/code
@@ -12,7 +12,7 @@ RUN: llvm-profdata merge -o %t.profdata %t.d/x1/
 
 # Test that we can specify a directory with -fprofile-use.
 RUN: llvm-profdata merge -o %t.d/default.profdata %t.d/x1/
-RUN: %clang_profuse_gcc=%t.d -o %t.d/code %S/Inputs/gcc-flag-compatibility.c
+RUN: %clang_pgouse=%t.d -o %t.d/code %S/Inputs/gcc-flag-compatibility.c
 
 # Test that we can specify a file with -fprofile-use.
-RUN: %clang_profuse_gcc=%t.profdata -o %t.d/code %S/Inputs/gcc-flag-compatibility.c
+RUN: %clang_pgouse=%t.profdata -o %t.d/code %S/Inputs/gcc-flag-compatibility.c

diff  --git a/compiler-rt/test/profile/instrprof-coverage.c b/compiler-rt/test/profile/instrprof-coverage.c
index 76e572c7e303b..88b46985e1143 100644
--- a/compiler-rt/test/profile/instrprof-coverage.c
+++ b/compiler-rt/test/profile/instrprof-coverage.c
@@ -2,15 +2,25 @@
 // RUN: %clang_pgogen -mllvm -pgo-function-entry-coverage %s -o %t.out
 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t.out
 // RUN: llvm-profdata merge -o %t.profdata %t.profraw
-// RUN: llvm-profdata show --covered %t.profdata | FileCheck %s --check-prefix CHECK --implicit-check-not goo
+// RUN: llvm-profdata show --covered %t.profdata | FileCheck %s --implicit-check-not goo
 
-int foo(int i) { return 4 * i + 1; }
-int bar(int i) { return 4 * i + 2; }
-int goo(int i) { return 4 * i + 3; }
+// RUN: %clang_cspgogen -O1 -mllvm -pgo-function-entry-coverage %s -o %t.cs.out
+// RUN: env LLVM_PROFILE_FILE=%t.csprofraw %run %t.cs.out
+// RUN: llvm-profdata merge -o %t.csprofdata %t.csprofraw
+// RUN: llvm-profdata show --covered %t.csprofdata --showcs | FileCheck %s --implicit-check-not goo
+
+void markUsed(int a) {
+  volatile int g;
+  g = a;
+}
+
+__attribute__((noinline)) int foo(int i) { return 4 * i + 1; }
+__attribute__((noinline)) int bar(int i) { return 4 * i + 2; }
+__attribute__((noinline)) int goo(int i) { return 4 * i + 3; }
 
 int main(int argc, char *argv[]) {
-  foo(5);
-  argc ? bar(6) : goo(7);
+  markUsed(foo(5));
+  markUsed(argc ? bar(6) : goo(7));
   return 0;
 }
 

diff  --git a/compiler-rt/test/profile/lit.cfg.py b/compiler-rt/test/profile/lit.cfg.py
index 5ef4ca0dd05d1..bdcc9f4e5dace 100644
--- a/compiler-rt/test/profile/lit.cfg.py
+++ b/compiler-rt/test/profile/lit.cfg.py
@@ -65,22 +65,28 @@ def exclude_unsupported_files_for_aix(dirname):
 # Add clang substitutions.
 config.substitutions.append( ("%clang ", build_invocation(clang_cflags)) )
 config.substitutions.append( ("%clangxx ", build_invocation(clang_cxxflags)) )
+
 config.substitutions.append( ("%clang_profgen ", build_invocation(clang_cflags) + " -fprofile-instr-generate ") )
 config.substitutions.append( ("%clang_profgen=", build_invocation(clang_cflags) + " -fprofile-instr-generate=") )
-config.substitutions.append( ("%clang_pgogen ", build_invocation(clang_cflags) + " -fprofile-generate ") )
-config.substitutions.append( ("%clang_pgogen=", build_invocation(clang_cflags) + " -fprofile-generate=") )
-
 config.substitutions.append( ("%clangxx_profgen ", build_invocation(clang_cxxflags) + " -fprofile-instr-generate ") )
 config.substitutions.append( ("%clangxx_profgen=", build_invocation(clang_cxxflags) + " -fprofile-instr-generate=") )
+
+config.substitutions.append( ("%clang_pgogen ", build_invocation(clang_cflags) + " -fprofile-generate ") )
+config.substitutions.append( ("%clang_pgogen=", build_invocation(clang_cflags) + " -fprofile-generate=") )
 config.substitutions.append( ("%clangxx_pgogen ", build_invocation(clang_cxxflags) + " -fprofile-generate ") )
 config.substitutions.append( ("%clangxx_pgogen=", build_invocation(clang_cxxflags) + " -fprofile-generate=") )
 
-config.substitutions.append( ("%clang_profgen_gcc=", build_invocation(clang_cflags) + " -fprofile-generate=") )
-config.substitutions.append( ("%clang_profuse_gcc=", build_invocation(clang_cflags) + " -fprofile-use=") )
+config.substitutions.append( ("%clang_cspgogen ", build_invocation(clang_cflags) + " -fcs-profile-generate ") )
+config.substitutions.append( ("%clang_cspgogen=", build_invocation(clang_cflags) + " -fcs-profile-generate=") )
+config.substitutions.append( ("%clangxx_cspgogen ", build_invocation(clang_cxxflags) + " -fcs-profile-generate ") )
+config.substitutions.append( ("%clangxx_cspgogen=", build_invocation(clang_cxxflags) + " -fcs-profile-generate=") )
 
 config.substitutions.append( ("%clang_profuse=", build_invocation(clang_cflags) + " -fprofile-instr-use=") )
 config.substitutions.append( ("%clangxx_profuse=", build_invocation(clang_cxxflags) + " -fprofile-instr-use=") )
 
+config.substitutions.append( ("%clang_pgouse=", build_invocation(clang_cflags) + " -fprofile-use=") )
+config.substitutions.append( ("%clangxx_profuse=", build_invocation(clang_cxxflags) + " -fprofile-instr-use=") )
+
 config.substitutions.append( ("%clang_lto_profgen=", build_invocation(clang_cflags, True) + " -fprofile-instr-generate=") )
 
 if config.host_os not in ['Windows', 'Darwin', 'FreeBSD', 'Linux', 'NetBSD', 'SunOS', 'AIX']:

diff  --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
index 12da42da0b62e..c4512d0222cde 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -840,8 +840,6 @@ static void instrumentOneFunc(
   auto CFGHash = ConstantInt::get(Type::getInt64Ty(M->getContext()),
                                   FuncInfo.FunctionHash);
   if (PGOFunctionEntryCoverage) {
-    assert(!IsCS &&
-           "entry coverge does not support context-sensitive instrumentation");
     auto &EntryBB = F.getEntryBlock();
     IRBuilder<> Builder(&EntryBB, EntryBB.getFirstInsertionPt());
     // llvm.instrprof.cover(i8* <name>, i64 <hash>, i32 <num-counters>,


        


More information about the llvm-commits mailing list