From 5febe9cf8b7ccd37f33e2cf43e16707bd88c6197 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Mon, 9 Jul 2018 17:39:18 -0400 Subject: [PATCH 32/68] Add opt-problem.cc gcc/ChangeLog: * Makefile.in (OBJS): Add opt-problem.o. * opt-problem.cc: New file. --- gcc/Makefile.in | 1 + gcc/opt-problem.cc | 96 +++++++++++++++++++++++++++++++++++++++++ gcc/optinfo-emit-diagnostics.cc | 2 +- 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 gcc/opt-problem.cc diff --git a/gcc/Makefile.in b/gcc/Makefile.in index a53385c..472ef0e 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1424,6 +1424,7 @@ OBJS = \ omp-grid.o \ omp-low.o \ omp-simd-clone.o \ + opt-problem.o \ optabs.o \ optabs-libfuncs.o \ optabs-query.o \ diff --git a/gcc/opt-problem.cc b/gcc/opt-problem.cc new file mode 100644 index 0000000..f518b16 --- /dev/null +++ b/gcc/opt-problem.cc @@ -0,0 +1,96 @@ +/* Rich information on why an optimization wasn't possible. + Copyright (C) 2018 Free Software Foundation, Inc. + Contributed by David Malcolm . + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "backend.h" +#include "diagnostic.h" +#include "tree.h" +#include "gimple.h" +#include "pretty-print.h" +#include "gimple-pretty-print.h" +#include "opt-problem.h" + +/* Emit a remark about an optimization. */ + +bool +opt_report::remark (dump_location_t loc, const char *gmsgid, ...) +{ + if (!flag_remarks) + return false; + + va_list ap; + va_start (ap, gmsgid); + bool ret = emit_diagnostic_valist (DK_REMARK, loc.get_location_t (), -1, + gmsgid, &ap); + va_end (ap); + + // FIXME: how should this interact with optinfo? (we don't want a duplicate remark) + return ret; +} + +/* Emit a note about an optimization. */ + +bool +opt_report::note (dump_location_t loc, const char *gmsgid, ...) +{ + va_list ap; + va_start (ap, gmsgid); + bool ret = emit_diagnostic_valist (DK_NOTE, loc.get_location_t (), -1, + gmsgid, &ap); + va_end (ap); + + // FIXME: how should this interact with optinfo? (we don't want a duplicate note) + return ret; +} + +opt_problem *opt_problem::s_the_problem; + +// FIXME: some refactoring is needed, based on exactly where remarks land, +// and how this interacts with the optinfo stuff. For now, this decl: + +extern void +print_impl_location (pretty_printer *pp, const dump_impl_location_t &impl_loc); + +/* Emit a diagnostic note describing why an optimization wasn't possible. */ + +void +opt_problem::report_reason (opt_report &report) +{ + bool show_color = pp_show_color (global_dc->printer); + + pretty_printer pp; + pp_show_color (&pp) = pp_show_color (global_dc->printer); + pp_string (&pp, m_text); + if (m_stmt) + { + pp_string (&pp, ": "); + pp_begin_quote (&pp, show_color); + pp_gimple_stmt_1 (&pp, m_stmt, 0, TDF_SLIM); + pp_end_quote (&pp, show_color); + } + + print_impl_location (&pp, m_location.get_impl_location ()); + + const char *msg = pp_formatted_text (&pp); + + report.note (m_location, "%s", msg); +} diff --git a/gcc/optinfo-emit-diagnostics.cc b/gcc/optinfo-emit-diagnostics.cc index d8c29d3..786b2c7 100644 --- a/gcc/optinfo-emit-diagnostics.cc +++ b/gcc/optinfo-emit-diagnostics.cc @@ -148,7 +148,7 @@ print_count (pretty_printer *pp, profile_count count) /* Print IMPL_LOC to PP (as part of a remark). */ -static void +void print_impl_location (pretty_printer *pp, const dump_impl_location_t &impl_loc) { bool show_color = pp_show_color (pp); -- 1.8.5.3