]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add coverage_instrumentation_p
authorJørgen Kvalsvik <j@lambda.is>
Wed, 26 Mar 2025 21:15:26 +0000 (22:15 +0100)
committerJørgen Kvalsvik <j@lambda.is>
Wed, 26 Mar 2025 23:01:15 +0000 (00:01 +0100)
Provide a helper for checking if any coverage (arc, conditions, paths)
is enabled, rather than manually checking all the flags. This should
make the intent clearer, and make it easier to maintain the checks when
more flags are added.

The function is forward declared in two header files as different passes
tend to include different headers (profile.h vs value-prof.h). This
could maybe be merged at some points, but profiling related symbols are
already a bit spread out and should probably be handled in a targeted
effort.

gcc/ChangeLog:

* builtins.cc (expand_builtin_fork_or_exec): Call
coverage_instrumentation_p.
* ipa-inline.cc (can_early_inline_edge_p): Likewise.
* passes.cc (finish_optimization_passes): Likewise.
* profile.cc (coverage_instrumentation_p): New function.
* profile.h (coverage_instrumentation_p): New declaration.
* tree-profile.cc (tree_profiling): Call
coverage_instrumentation_p.
(pass_ipa_tree_profile::gate): Likewise.
* value-prof.h (coverage_instrumentation_p): New declaration.

gcc/builtins.cc
gcc/ipa-inline.cc
gcc/passes.cc
gcc/profile.cc
gcc/profile.h
gcc/tree-profile.cc
gcc/value-prof.h

index ff48546eafd6cdd18874a4d2f4f2c3ce537e323c..a5f711a7b6a29d2e141eacb1d429e1eb4368536d 100644 (file)
@@ -6362,7 +6362,7 @@ expand_builtin_fork_or_exec (tree fn, tree exp, rtx target, int ignore)
   tree call;
 
   /* If we are not profiling, just call the function.  */
-  if (!profile_arc_flag && !condition_coverage_flag && !path_coverage_flag)
+  if (!coverage_instrumentation_p ())
     return NULL_RTX;
 
   /* Otherwise call the wrapper.  This should be equivalent for the rest of
index 38b4c9899012ab23d2b285b10417e2a7b50f8d21..d9fc111a9e76b85d69512552e3bd656dc52e3dc4 100644 (file)
@@ -701,7 +701,7 @@ can_early_inline_edge_p (struct cgraph_edge *e)
     }
   gcc_assert (gimple_in_ssa_p (DECL_STRUCT_FUNCTION (e->caller->decl))
              && gimple_in_ssa_p (DECL_STRUCT_FUNCTION (callee->decl)));
-  if ((profile_arc_flag || condition_coverage_flag || path_coverage_flag)
+  if (coverage_instrumentation_p ()
       && ((lookup_attribute ("no_profile_instrument_function",
                            DECL_ATTRIBUTES (caller->decl)) == NULL_TREE)
          != (lookup_attribute ("no_profile_instrument_function",
index a8c75520c8d9ff0ee62893911441656db90e57f5..3c28db78f095844fd76b6f259dbfd957ad348bcc 100644 (file)
@@ -352,8 +352,8 @@ finish_optimization_passes (void)
   gcc::dump_manager *dumps = m_ctxt->get_dumps ();
 
   timevar_push (TV_DUMP);
-  if (profile_arc_flag || condition_coverage_flag || path_coverage_flag
-      || flag_test_coverage || flag_branch_probabilities)
+  if (coverage_instrumentation_p () || flag_test_coverage
+      || flag_branch_probabilities)
     {
       dumps->dump_start (pass_profile_1->static_pass_number, NULL);
       end_branch_prob ();
index 8bba8b4398ff053af0ded92bd3e70aca57ba17bf..0b222cf3864083089093610b595a78f60f96546a 100644 (file)
@@ -1798,3 +1798,10 @@ end_branch_prob (void)
               total_num_conds);
     }
 }
+
+/* Return true if any cfg coverage/profiling is enabled; -fprofile-arcs
+   -fcondition-coverage -fpath-coverage.  */
+bool coverage_instrumentation_p ()
+{
+  return profile_arc_flag || condition_coverage_flag || path_coverage_flag;
+}
index 78d69f45ff271e3487c24b2e436a88cf26a507fc..a97445b8f6f3a3cd45547095f001dfd23f66a733 100644 (file)
@@ -77,4 +77,8 @@ extern void get_working_sets (void);
    profile.cc.  */
 extern struct gcov_summary *profile_info;
 
+/* Return true if any cfg coverage/profiling is enabled; -fprofile-arcs
+   -fcondition-coverage -fpath-coverage.  */
+extern bool coverage_instrumentation_p ();
+
 #endif /* PROFILE_H */
index 8aaed78e60c040fe63c31ec9473fec7ed5cd94a4..fed218eb60bcf3d0a17e5a0f08a3487d36a6e768 100644 (file)
@@ -1908,7 +1908,7 @@ tree_profiling (void)
          thunk = true;
          /* When generate profile, expand thunk to gimple so it can be
             instrumented same way as other functions.  */
-         if (profile_arc_flag || condition_coverage_flag || path_coverage_flag)
+         if (coverage_instrumentation_p ())
            expand_thunk (node, false, true);
          /* Read cgraph profile but keep function as thunk at profile-use
             time.  */
@@ -1953,8 +1953,7 @@ tree_profiling (void)
   release_profile_file_filtering ();
 
   /* Drop pure/const flags from instrumented functions.  */
-  if (profile_arc_flag || condition_coverage_flag || path_coverage_flag
-      || flag_test_coverage)
+  if (coverage_instrumentation_p () || flag_test_coverage)
     FOR_EACH_DEFINED_FUNCTION (node)
       {
        if (!gimple_has_body_p (node->decl)
@@ -1986,8 +1985,7 @@ tree_profiling (void)
 
       push_cfun (DECL_STRUCT_FUNCTION (node->decl));
 
-      if (profile_arc_flag || condition_coverage_flag || path_coverage_flag
-         || flag_test_coverage)
+      if (coverage_instrumentation_p () || flag_test_coverage)
        FOR_EACH_BB_FN (bb, cfun)
          {
            gimple_stmt_iterator gsi;
@@ -2072,8 +2070,7 @@ pass_ipa_tree_profile::gate (function *)
      disabled.  */
   return (!in_lto_p && !flag_auto_profile
          && (flag_branch_probabilities || flag_test_coverage
-             || profile_arc_flag || condition_coverage_flag
-             || path_coverage_flag)
+             || coverage_instrumentation_p ())
          && !seen_error ());
 }
 
index 5b1145a5aa2d66f1e172f5b32c0797badef5cb82..3d5395ecea70546d85ed345ea020ac94ec4a9c6b 100644 (file)
@@ -116,5 +116,9 @@ extern void branch_prob (bool);
 extern void read_thunk_profile (struct cgraph_node *);
 extern void end_branch_prob (void);
 
+/* Return true if any cfg coverage/profiling is enabled; -fprofile-arcs
+   -fcondition-coverage -fpath-coverage.  */
+extern bool coverage_instrumentation_p ();
+
 #endif /* GCC_VALUE_PROF_H */