From ff79fe55cef79902385eec2969253e2ca6a91b18 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Mon, 9 Jul 2018 17:39:18 -0400 Subject: [PATCH 45/46] 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 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 gcc/opt-problem.cc diff --git a/gcc/Makefile.in b/gcc/Makefile.in index c5c3d3c..fb262da 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1425,6 +1425,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); +} -- 1.8.5.3