From 4cb66a6a355e07d9ecf5322f048b934ceaae898f Mon Sep 17 00:00:00 2001 From: Raihaan Shouhell Date: Sat, 2 Mar 2024 16:37:14 +0800 Subject: [PATCH] feat: Add -fprofile-update support (#1408) --- src/argprocessing.cpp | 4 +++ test/suites/profiling_clang.bash | 46 ++++++++++++++++++++++++++++++++ test/suites/profiling_gcc.bash | 41 ++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+) diff --git a/src/argprocessing.cpp b/src/argprocessing.cpp index 3066ff37e..0a156a683 100644 --- a/src/argprocessing.cpp +++ b/src/argprocessing.cpp @@ -238,6 +238,10 @@ process_profiling_option(const Context& ctx, return true; } + if (util::starts_with(arg, "-fprofile-update")) { + return true; + } + std::string new_profile_path; bool new_profile_use = false; diff --git a/test/suites/profiling_clang.bash b/test/suites/profiling_clang.bash index a6ac5c972..1f848f7e3 100644 --- a/test/suites/profiling_clang.bash +++ b/test/suites/profiling_clang.bash @@ -131,4 +131,50 @@ SUITE_profiling_clang() { $CCACHE_COMPILE -fprofile-sample-use=sample.prof -c test.c expect_stat direct_cache_hit 3 expect_stat cache_miss 3 + + # ------------------------------------------------------------------------- + TEST "-fprofile-update=single" + + if $COMPILER -fprofile-update=single -fprofile-generate -c test.c 2>/dev/null; then + + $CCACHE_COMPILE -fprofile-update=single -fprofile-generate -c test.c + expect_stat direct_cache_hit 0 + expect_stat cache_miss 1 + + $COMPILER -fprofile-generate -fprofile-update=single test.o -o test + + ./test + + $CCACHE_COMPILE -fprofile-update=single -fprofile-generate -c test.c + expect_stat direct_cache_hit 1 + expect_stat cache_miss 1 + + $CCACHE_COMPILE -fprofile-use -c test.c + expect_stat direct_cache_hit 1 + expect_stat cache_miss 2 + fi + + # ------------------------------------------------------------------------- + TEST "-fprofile-update=atomic" + + if $COMPILER -fprofile-update=atomic -fprofile-generate -c test.c 2>/dev/null; then + + $CCACHE_COMPILE -fprofile-update=atomic -fprofile-generate -c test.c + expect_stat direct_cache_hit 0 + expect_stat cache_miss 1 + + $COMPILER -fprofile-generate -fprofile-update=atomic test.o -o test + + ./test + + $CCACHE_COMPILE -fprofile-update=atomic -fprofile-generate -c test.c + expect_stat direct_cache_hit 1 + expect_stat cache_miss 1 + + $CCACHE_COMPILE -fprofile-use -c test.c + expect_stat direct_cache_hit 1 + expect_stat cache_miss 2 + + # ------------------------------------------------------------------------- + fi } diff --git a/test/suites/profiling_gcc.bash b/test/suites/profiling_gcc.bash index f83aeaf1a..89f901377 100644 --- a/test/suites/profiling_gcc.bash +++ b/test/suites/profiling_gcc.bash @@ -163,4 +163,45 @@ SUITE_profiling_gcc() { expect_stat direct_cache_hit 4 expect_stat cache_miss 3 fi + + # ------------------------------------------------------------------------- + TEST "-fprofile-update=single" + + $CCACHE_COMPILE -fprofile-update=single -fprofile-generate -c test.c + expect_stat direct_cache_hit 0 + expect_stat cache_miss 1 + + $COMPILER -fprofile-generate -fprofile-update=single test.o -o test + + ./test + + $CCACHE_COMPILE -fprofile-update=single -fprofile-generate -c test.c + expect_stat direct_cache_hit 1 + expect_stat cache_miss 1 + + $CCACHE_COMPILE -fprofile-use -c test.c + expect_stat direct_cache_hit 1 + expect_stat cache_miss 2 + + # ------------------------------------------------------------------------- + + TEST "-fprofile-update=atomic" + + $CCACHE_COMPILE -fprofile-update=atomic -fprofile-generate -c test.c + expect_stat direct_cache_hit 0 + expect_stat cache_miss 1 + + $COMPILER -fprofile-generate -fprofile-update=atomic test.o -o test + + ./test + + $CCACHE_COMPILE -fprofile-update=atomic -fprofile-generate -c test.c + expect_stat direct_cache_hit 1 + expect_stat cache_miss 1 + + $CCACHE_COMPILE -fprofile-use -c test.c + expect_stat direct_cache_hit 1 + expect_stat cache_miss 2 + + # ------------------------------------------------------------------------- } -- 2.47.2