diff --git a/compiler-rt/test/profile/gcc-flag-compatibility.test b/compiler-rt/test/profile/gcc-flag-compatibility.test --- 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 @@ # 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 --- 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 --- a/compiler-rt/test/profile/lit.cfg.py +++ b/compiler-rt/test/profile/lit.cfg.py @@ -65,22 +65,28 @@ # 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 --- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -832,8 +832,6 @@ 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* , i64 , i32 ,