aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJørgen Kvalsvik <j@lambda.is>2025-03-26 22:15:26 +0100
committerJørgen Kvalsvik <j@lambda.is>2025-03-27 00:01:15 +0100
commitdc9ca4b2701f91b1efb82ea605f0ec7254e80974 (patch)
tree7675a78d4ee26f15a9012e9745137763e948ebea
parent8ed2d5d219e999aee42015a0db38612011c2c507 (diff)
downloadgcc-dc9ca4b2701f91b1efb82ea605f0ec7254e80974.zip
gcc-dc9ca4b2701f91b1efb82ea605f0ec7254e80974.tar.gz
gcc-dc9ca4b2701f91b1efb82ea605f0ec7254e80974.tar.bz2
Add coverage_instrumentation_p
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.
-rw-r--r--gcc/builtins.cc2
-rw-r--r--gcc/ipa-inline.cc2
-rw-r--r--gcc/passes.cc4
-rw-r--r--gcc/profile.cc7
-rw-r--r--gcc/profile.h4
-rw-r--r--gcc/tree-profile.cc11
-rw-r--r--gcc/value-prof.h4
7 files changed, 23 insertions, 11 deletions
diff --git a/gcc/builtins.cc b/gcc/builtins.cc
index ff48546..a5f711a 100644
--- a/gcc/builtins.cc
+++ b/gcc/builtins.cc
@@ -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
diff --git a/gcc/ipa-inline.cc b/gcc/ipa-inline.cc
index 38b4c98..d9fc111 100644
--- a/gcc/ipa-inline.cc
+++ b/gcc/ipa-inline.cc
@@ -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",
diff --git a/gcc/passes.cc b/gcc/passes.cc
index a8c7552..3c28db7 100644
--- a/gcc/passes.cc
+++ b/gcc/passes.cc
@@ -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 ();
diff --git a/gcc/profile.cc b/gcc/profile.cc
index 8bba8b4..0b222cf 100644
--- a/gcc/profile.cc
+++ b/gcc/profile.cc
@@ -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;
+}
diff --git a/gcc/profile.h b/gcc/profile.h
index 78d69f4..a97445b 100644
--- a/gcc/profile.h
+++ b/gcc/profile.h
@@ -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 */
diff --git a/gcc/tree-profile.cc b/gcc/tree-profile.cc
index 8aaed78..fed218e 100644
--- a/gcc/tree-profile.cc
+++ b/gcc/tree-profile.cc
@@ -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 ());
}
diff --git a/gcc/value-prof.h b/gcc/value-prof.h
index 5b1145a..3d5395e 100644
--- a/gcc/value-prof.h
+++ b/gcc/value-prof.h
@@ -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 */