summaryrefslogtreecommitdiff
path: root/gcc/dumpfile.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2018-06-26 13:34:59 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2018-06-26 13:34:59 +0000
commit4f5b9c803ac4edc639d8bf4a827ba40e4dab4db0 (patch)
treeda6d4a4811016c1d51edbe927f601eb11d9c3835 /gcc/dumpfile.c
parent3da2f26ca45060ddd8514010090353a2adec334a (diff)
downloadgcc-4f5b9c803ac4edc639d8bf4a827ba40e4dab4db0.tar.gz
Introduce dump_location_t
gcc/ChangeLog: * cfgloop.c (get_loop_location): Convert return type from location_t to dump_user_location_t, replacing INSN_LOCATION lookups by implicit construction from rtx_insn *, and using dump_user_location_t::from_function_decl for the fallback case. * cfgloop.h (get_loop_location): Convert return type from location_t to dump_user_location_t. * cgraphunit.c (walk_polymorphic_call_targets): Update call to dump_printf_loc to pass in a dump_location_t rather than a location_t, via the gimple stmt. * coverage.c (get_coverage_counts): Update calls to dump_printf_loc to pass in dump_location_t rather than a location_t. * doc/optinfo.texi (Dump types): Convert example of dump_printf_loc from taking "locus" to taking "insn". Update description of the "_loc" calls to cover dump_location_t. * dumpfile.c: Include "backend.h", "gimple.h", "rtl.h", and "selftest.h". (dump_user_location_t::dump_user_location_t): New constructors, from gimple *stmt and rtx_insn *. (dump_user_location_t::from_function_decl): New function. (dump_loc): Make static. (dump_gimple_stmt_loc): Convert param "loc" from location_t to const dump_location_t &. (dump_generic_expr_loc): Delete. (dump_printf_loc): Convert param "loc" from location_t to const dump_location_t &. (selftest::test_impl_location): New function. (selftest::dumpfile_c_tests): New function. * dumpfile.h: Include "profile-count.h". (class dump_user_location_t): New class. (struct dump_impl_location_t): New struct. (class dump_location_t): New class. (dump_printf_loc): Convert 2nd param from source_location to const dump_location_t &. (dump_generic_expr_loc): Delete. (dump_gimple_stmt_loc): Convert 2nd param from source_location to const dump_location_t &. * gimple-fold.c (fold_gimple_assign): Update call to dump_printf_loc to pass in a dump_location_t rather than a location_t, via the gimple stmt. (gimple_fold_call): Likewise. * gimple-loop-interchange.cc (loop_cand::analyze_iloop_reduction_var): Update for change to check_reduction_path. (tree_loop_interchange::interchange): Update for change to find_loop_location. * graphite-isl-ast-to-gimple.c (scop_to_isl_ast): Update for change in return-type of find_loop_location. (graphite_regenerate_ast_isl): Likewise. * graphite-optimize-isl.c (optimize_isl): Likewise. * graphite.c (graphite_transform_loops): Likewise. * ipa-devirt.c (ipa_devirt): Update call to dump_printf_loc to pass in a dump_location_t rather than a location_t, via the gimple stmt. * ipa-prop.c (ipa_make_edge_direct_to_target): Likewise. * ipa.c (walk_polymorphic_call_targets): Likewise. * loop-unroll.c (report_unroll): Convert "locus" param from location_t to dump_location_t. (decide_unrolling): Update for change to get_loop_location's return type. * omp-grid.c (struct grid_prop): Convert field "target_loc" from location_t to dump_user_location_t. (grid_find_single_omp_among_assignments_1): Updates calls to dump_printf_loc to pass in a dump_location_t rather than a location_t, via the gimple stmt. (grid_parallel_clauses_gridifiable): Convert "tloc" from location_t to dump_location_t. Updates calls to dump_printf_loc to pass in a dump_location_t rather than a location_t, via the gimple stmt. (grid_inner_loop_gridifiable_p): Likewise. (grid_dist_follows_simple_pattern): Likewise. (grid_gfor_follows_tiling_pattern): Likewise. (grid_target_follows_gridifiable_pattern): Likewise. (grid_attempt_target_gridification): Convert initialization of local "grid" from memset to zero-initialization; FIXME: does this require C++11? Update call to dump_printf_loc to pass in a optinfo_location rather than a location_t, via the gimple stmt. * profile.c (read_profile_edge_counts): Updates call to dump_printf_loc to pass in a dump_location_t rather than a location_t (compute_branch_probabilities): Likewise. * selftest-run-tests.c (selftest::run_tests): Call dumpfile_c_tests. * selftest.h (dumpfile_c_tests): New decl. * tree-loop-distribution.c (pass_loop_distribution::execute): Update for change in return type of find_loop_location. * tree-parloops.c (parallelize_loops): Likewise. * tree-ssa-loop-ivcanon.c (try_unroll_loop_completely): Convert "locus" from location_t to dump_user_location_t. (canonicalize_loop_induction_variables): Likewise. * tree-ssa-loop-ivopts.c (tree_ssa_iv_optimize_loop): Update for change in return type of find_loop_location. * tree-ssa-loop-niter.c (number_of_iterations_exit): Update call to dump_printf_loc to pass in a dump_location_t rather than a location_t, via the stmt. * tree-ssa-sccvn.c (eliminate_dom_walker::before_dom_children): Likewise. * tree-vect-loop-manip.c (find_loop_location): Convert return type from source_location to dump_user_location_t. (vect_do_peeling): Update for above change. (vect_loop_versioning): Update for change in type of vect_location. * tree-vect-loop.c (check_reduction_path): Convert "loc" param from location_t to dump_user_location_t. (vect_estimate_min_profitable_iters): Update for change in type of vect_location. * tree-vect-slp.c (vect_print_slp_tree): Convert param "loc" from location_t to dump_location_t. (vect_slp_bb): Update for change in type of vect_location. * tree-vectorizer.c (vect_location): Convert from source_location to dump_user_location_t. (try_vectorize_loop_1): Update for change in vect_location's type. (vectorize_loops): Likewise. (increase_alignment): Likewise. * tree-vectorizer.h (vect_location): Convert from source_location to dump_user_location_t. (find_loop_location): Convert return type from source_location to dump_user_location_t. (check_reduction_path): Convert 1st param from location_t to dump_user_location_t. * value-prof.c (check_counter): Update call to dump_printf_loc to pass in a dump_user_location_t rather than a location_t; update call to error_at for change in type of "locus". (check_ic_target): Update call to dump_printf_loc to pass in a dump_user_location_t rather than a location_t, via the call_stmt. From-SVN: r262149
Diffstat (limited to 'gcc/dumpfile.c')
-rw-r--r--gcc/dumpfile.c133
1 files changed, 105 insertions, 28 deletions
diff --git a/gcc/dumpfile.c b/gcc/dumpfile.c
index 2f11284d488..d4e1477cfb9 100644
--- a/gcc/dumpfile.c
+++ b/gcc/dumpfile.c
@@ -29,6 +29,10 @@ along with GCC; see the file COPYING3. If not see
#include "profile-count.h"
#include "tree-cfg.h"
#include "langhooks.h"
+#include "backend.h" /* for gimple.h. */
+#include "gimple.h" /* for dump_user_location_t ctor. */
+#include "rtl.h" /* for dump_user_location_t ctor. */
+#include "selftest.h"
/* If non-NULL, return one past-the-end of the matching SUBPART of
the WHOLE string. */
@@ -358,9 +362,51 @@ dump_open_alternate_stream (struct dump_file_info *dfi)
return stream;
}
+/* Construct a dump_user_location_t from STMT (using its location and
+ hotness). */
+
+dump_user_location_t::dump_user_location_t (gimple *stmt)
+: m_count (), m_loc (UNKNOWN_LOCATION)
+{
+ if (stmt)
+ {
+ if (stmt->bb)
+ m_count = stmt->bb->count;
+ m_loc = gimple_location (stmt);
+ }
+}
+
+/* Construct a dump_user_location_t from an RTL instruction (using its
+ location and hotness). */
+
+dump_user_location_t::dump_user_location_t (rtx_insn *insn)
+: m_count (), m_loc (UNKNOWN_LOCATION)
+{
+ if (insn)
+ {
+ basic_block bb = BLOCK_FOR_INSN (insn);
+ if (bb)
+ m_count = bb->count;
+ m_loc = INSN_LOCATION (insn);
+ }
+}
+
+/* Construct from a function declaration. This one requires spelling out
+ to avoid accidentally constructing from other kinds of tree. */
+
+dump_user_location_t
+dump_user_location_t::from_function_decl (tree fndecl)
+{
+ gcc_assert (fndecl);
+
+ // FIXME: profile count for function?
+ return dump_user_location_t (profile_count (),
+ DECL_SOURCE_LOCATION (fndecl));
+}
+
/* Print source location on DFILE if enabled. */
-void
+static void
dump_loc (dump_flags_t dump_kind, FILE *dfile, source_location loc)
{
if (dump_kind)
@@ -393,18 +439,19 @@ dump_gimple_stmt (dump_flags_t dump_kind, dump_flags_t extra_dump_flags,
/* Similar to dump_gimple_stmt, except additionally print source location. */
void
-dump_gimple_stmt_loc (dump_flags_t dump_kind, source_location loc,
+dump_gimple_stmt_loc (dump_flags_t dump_kind, const dump_location_t &loc,
dump_flags_t extra_dump_flags, gimple *gs, int spc)
{
+ location_t srcloc = loc.get_location_t ();
if (dump_file && (dump_kind & pflags))
{
- dump_loc (dump_kind, dump_file, loc);
+ dump_loc (dump_kind, dump_file, srcloc);
print_gimple_stmt (dump_file, gs, spc, dump_flags | extra_dump_flags);
}
if (alt_dump_file && (dump_kind & alt_flags))
{
- dump_loc (dump_kind, alt_dump_file, loc);
+ dump_loc (dump_kind, alt_dump_file, srcloc);
print_gimple_stmt (alt_dump_file, gs, spc, dump_flags | extra_dump_flags);
}
}
@@ -423,27 +470,6 @@ dump_generic_expr (dump_flags_t dump_kind, dump_flags_t extra_dump_flags,
print_generic_expr (alt_dump_file, t, dump_flags | extra_dump_flags);
}
-
-/* Similar to dump_generic_expr, except additionally print the source
- location. */
-
-void
-dump_generic_expr_loc (dump_flags_t dump_kind, source_location loc,
- dump_flags_t extra_dump_flags, tree t)
-{
- if (dump_file && (dump_kind & pflags))
- {
- dump_loc (dump_kind, dump_file, loc);
- print_generic_expr (dump_file, t, dump_flags | extra_dump_flags);
- }
-
- if (alt_dump_file && (dump_kind & alt_flags))
- {
- dump_loc (dump_kind, alt_dump_file, loc);
- print_generic_expr (alt_dump_file, t, dump_flags | extra_dump_flags);
- }
-}
-
/* Output a formatted message using FORMAT on appropriate dump streams. */
void
@@ -469,13 +495,14 @@ dump_printf (dump_flags_t dump_kind, const char *format, ...)
/* Similar to dump_printf, except source location is also printed. */
void
-dump_printf_loc (dump_flags_t dump_kind, source_location loc,
+dump_printf_loc (dump_flags_t dump_kind, const dump_location_t &loc,
const char *format, ...)
{
+ location_t srcloc = loc.get_location_t ();
if (dump_file && (dump_kind & pflags))
{
va_list ap;
- dump_loc (dump_kind, dump_file, loc);
+ dump_loc (dump_kind, dump_file, srcloc);
va_start (ap, format);
vfprintf (dump_file, format, ap);
va_end (ap);
@@ -484,7 +511,7 @@ dump_printf_loc (dump_flags_t dump_kind, source_location loc,
if (alt_dump_file && (dump_kind & alt_flags))
{
va_list ap;
- dump_loc (dump_kind, alt_dump_file, loc);
+ dump_loc (dump_kind, alt_dump_file, srcloc);
va_start (ap, format);
vfprintf (alt_dump_file, format, ap);
va_end (ap);
@@ -1059,3 +1086,53 @@ enable_rtl_dump_file (void)
NULL);
return num_enabled > 0;
}
+
+#if CHECKING_P
+
+namespace selftest {
+
+/* Verify that the dump_location_t constructors capture the source location
+ at which they were called (provided that the build compiler is sufficiently
+ recent). */
+
+static void
+test_impl_location ()
+{
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
+ /* Default ctor. */
+ {
+ dump_location_t loc;
+ const int expected_line = __LINE__ - 1;
+ ASSERT_STR_CONTAINS (loc.get_impl_location ().m_file, "dumpfile.c");
+ ASSERT_EQ (loc.get_impl_location ().m_line, expected_line);
+ }
+
+ /* Constructing from a gimple. */
+ {
+ dump_location_t loc ((gimple *)NULL);
+ const int expected_line = __LINE__ - 1;
+ ASSERT_STR_CONTAINS (loc.get_impl_location ().m_file, "dumpfile.c");
+ ASSERT_EQ (loc.get_impl_location ().m_line, expected_line);
+ }
+
+ /* Constructing from an rtx_insn. */
+ {
+ dump_location_t loc ((rtx_insn *)NULL);
+ const int expected_line = __LINE__ - 1;
+ ASSERT_STR_CONTAINS (loc.get_impl_location ().m_file, "dumpfile.c");
+ ASSERT_EQ (loc.get_impl_location ().m_line, expected_line);
+ }
+#endif
+}
+
+/* Run all of the selftests within this file. */
+
+void
+dumpfile_c_tests ()
+{
+ test_impl_location ();
+}
+
+} // namespace selftest
+
+#endif /* CHECKING_P */