]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Support clang options for compiling with sampled profiles (#589)
authorOlle Liljenzin <olle@liljenzin.se>
Fri, 8 May 2020 17:12:05 +0000 (19:12 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 8 May 2020 17:20:50 +0000 (19:20 +0200)
Add support for -fprofile-sample-use and -fprofile-sample-accurate.

(cherry picked from commit 4b1b7d4b36c036c190831d9283f8c1e22e640e24)

src/ccache.c
test/suites/profiling_clang.bash

index 8fe62aa55bccf8ebe1f736d6e9377781d302d635..54e8f21e08b8a8247115ce6c17c30deb2240efb1 100644 (file)
@@ -2025,9 +2025,9 @@ hash_profile_data_file(const char *path, struct hash *hash)
                format("%s/%s.gcda", path, base_name),
                // -fprofile-use[=dir]/-fbranch-probabilities (GCC >=9)
                format("%s/%s#%s.gcda", path, hashified_cwd, base_name),
-               // -fprofile(-instr)-use=file (Clang), -fauto-profile=file (GCC >=5)
+               // -fprofile(-instr|-sample)-use=file (Clang), -fauto-profile=file (GCC >=5)
                x_strdup(path),
-               // -fprofile(-instr)-use=dir (Clang)
+               // -fprofile(-instr|-sample)-use=dir (Clang)
                format("%s/default.profdata", path),
                // -fauto-profile (GCC >=5)
                x_strdup("fbdata.afdo"), // -fprofile-dir is not used
@@ -2222,11 +2222,12 @@ calculate_object_hash(struct args *args, struct args *preprocessor_args,
        // For profile generation (-fprofile(-instr)-generate[=path])
        // - hash profile path
        //
-       // For profile usage (-fprofile(-instr)-use, -fbranch-probabilities):
+       // For profile usage (-fprofile(-instr|-sample)-use, -fbranch-probabilities):
        // - hash profile data
        //
        // The profile directory can be specified as an argument to
-       // -fprofile(-instr)-generate=, -fprofile(-instr)-use= or -fprofile-dir=.
+       // -fprofile(-instr)-generate=, -fprofile(-instr|-sample)-use= or
+       // --fprofile-dir=.
        if (profile_generate) {
                assert(profile_path);
                cc_log("Adding profile directory %s to our hash", profile_path);
@@ -2581,6 +2582,7 @@ process_profiling_option(const char *arg)
                new_profile_path = x_strdup(strchr(arg, '=') + 1);
        } else if (str_eq(arg, "-fprofile-use")
                   || str_eq(arg, "-fprofile-instr-use")
+                  || str_eq(arg, "-fprofile-sample-use")
                   || str_eq(arg, "-fbranch-probabilities")
                   || str_eq(arg, "-fauto-profile")) {
                new_profile_use = true;
@@ -2589,9 +2591,12 @@ process_profiling_option(const char *arg)
                }
        } else if (str_startswith(arg, "-fprofile-use=")
                         || str_startswith(arg, "-fprofile-instr-use=")
+                        || str_startswith(arg, "-fprofile-sample-use=")
                         || str_startswith(arg, "-fauto-profile=")) {
                new_profile_use = true;
                new_profile_path = x_strdup(strchr(arg, '=') + 1);
+       } else if (str_eq(arg, "-fprofile-sample-accurate")) {
+               return true;
        } else {
                cc_log("Unknown profiling option: %s", arg);
                stats_update(STATS_UNSUPPORTED_OPTION);
index 4344f7d026abf52464f9e6c21c17c9116aa7208c..c6bb7ef7623553cd8bb92019306fc233255136e3 100644 (file)
@@ -95,4 +95,37 @@ SUITE_profiling_clang() {
     $CCACHE_COMPILE -fprofile-instr-use=foo.profdata -c test.c
     expect_stat 'cache hit (direct)' 1
     expect_stat 'cache miss' 3
+
+    # -------------------------------------------------------------------------
+    TEST "-fprofile-sample-use"
+
+    echo 'main:1:1' > sample.prof
+
+    $CCACHE_COMPILE -fprofile-sample-use=sample.prof -c test.c
+    expect_stat 'cache hit (direct)' 0
+    expect_stat 'cache miss' 1
+
+    $CCACHE_COMPILE -fprofile-sample-use=sample.prof -fprofile-sample-accurate -c test.c
+    expect_stat 'cache hit (direct)' 0
+    expect_stat 'cache miss' 2
+
+    $CCACHE_COMPILE -fprofile-sample-use=sample.prof -c test.c
+    expect_stat 'cache hit (direct)' 1
+    expect_stat 'cache miss' 2
+
+    $CCACHE_COMPILE -fprofile-sample-use=sample.prof -fprofile-sample-accurate -c test.c
+    expect_stat 'cache hit (direct)' 2
+    expect_stat 'cache miss' 2
+
+    echo 'main:2:2' > sample.prof
+
+    $CCACHE_COMPILE -fprofile-sample-use=sample.prof -c test.c
+    expect_stat 'cache hit (direct)' 2
+    expect_stat 'cache miss' 3
+
+     echo 'main:1:1' > sample.prof
+
+    $CCACHE_COMPILE -fprofile-sample-use=sample.prof -c test.c
+    expect_stat 'cache hit (direct)' 3
+    expect_stat 'cache miss' 3
 }