aboutsummaryrefslogtreecommitdiff
path: root/gcc/optinfo-emit-json.cc
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2018-11-19 16:31:03 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2018-11-19 16:31:03 +0000
commit8d1af516844f94784d9a3a7ffc59f9ab3daa1f5d (patch)
treec32e504ef3de3abf09e0126e75c2712a7de83e6e /gcc/optinfo-emit-json.cc
parent4fea820523334138d7165f20333ef30ba8e01c1d (diff)
downloadgcc-8d1af516844f94784d9a3a7ffc59f9ab3daa1f5d.zip
gcc-8d1af516844f94784d9a3a7ffc59f9ab3daa1f5d.tar.gz
gcc-8d1af516844f94784d9a3a7ffc59f9ab3daa1f5d.tar.bz2
Eliminate global state from -fsave-optimization-record
As work towards fixing PR tree-optimization/87025, this patch eliminates global state from optinfo-emit-json.cc in favor of adding an optional m_json_writer field to dump_context, replacing the m_forcibly_enable_optinfo flag. This allows for writing selftests for the interaction of the JSON-building code with the dumpfile.c code. In particular, the existing selftest that created optinfo instances now exercise the JSON-building code (although no JSON is actually written out). The patch also simplifies the layering by replacing optinfo::emit () with dump_context::emit_optinfo, so that dump_context has responsibility for keeping track of dump destinations. gcc/ChangeLog: PR tree-optimization/87025 * dump-context.h: Include "optinfo.h". (class optrecord_json_writer): New forward decl. (dump_context::forcibly_enable_optinfo_p): Delete. (dump_context::optinfo_enabled_p): New member function. (dump_context::optimization_records_enabled_p): New member function. (dump_context::set_json_writer): New member function. (dump_context::emit_optinfo): New member function. (dump_context::m_forcibly_enable_optinfo): Delete. (dump_context::m_json_writer): New member data. * dumpfile.c (dump_context::set_json_writer): New member function. (dump_context::finish_any_json_writer): New member function. (dump_context::end_scope): Replace call to optimization_records_maybe_pop_dump_scope with call to m_json_writer->pop_scope. (dump_context::optinfo_enabled_p): New member function. (dump_context::end_any_optinfo): Replace call to optinfo::emit with call to dump_context::emit_optinfo. (dump_context::emit_optinfo): New member function. (temp_dump_context::temp_dump_context): Replace m_forcibly_enable_optinfo with call to set_json_writer. (temp_dump_context::~temp_dump_context): Clean up any json writer. * optinfo-emit-json.cc (class optrecord_json_writer): Move to optinfo-emit-json.h (the_json_writer): Delete. (optimization_records_start): Delete. (optimization_records_finish): Delete. (optimization_records_enabled_p): Delete, in favor of dump_context::optimization_records_enabled_p. (optimization_records_maybe_record_optinfo): Delete. (optimization_records_maybe_pop_dump_scope): Delete. * optinfo-emit-json.h: Include "json.h". Delete forward decl of opt_pass. (optimization_records_start): Delete. (optimization_records_finish): Delete. (optimization_records_enabled_p): Delete. (optimization_records_maybe_record_optinfo): Delete. (optimization_records_maybe_pop_dump_scope): Delete. (class optrecord_json_writer): Move here from optinfo-emit-json.cc. * optinfo.cc (optinfo::emit_for_opt_problem): Replace call to optinfo::emit with call to dump_context::emit_optinfo. (optinfo::emit): Delete, in favor of dump_context::emit_optinfo. (optinfo_enabled_p): Delete, in favor of dump_context::optinfo_enabled_p. (optinfo_wants_inlining_info_p): Update for conversion o optimization_records_enabled_p to a member function of dump_context. * optinfo.h (optinfo_enabled_p): Delete, in favor of dump_context::optinfo_enabled_p. (optinfo::emit): Delete, in favor of dump_context::emit_optinfo. * toplev.c: Include "dump-context.h". (compile_file): Replace call to optimization_records_finish with dump_context::finish_any_json_writer. (do_compile): Replace call to optimization_records_start with conditionally creating a optrecord_json_writer for the dump_context. From-SVN: r266279
Diffstat (limited to 'gcc/optinfo-emit-json.cc')
-rw-r--r--gcc/optinfo-emit-json.cc101
1 files changed, 0 insertions, 101 deletions
diff --git a/gcc/optinfo-emit-json.cc b/gcc/optinfo-emit-json.cc
index 6d4502c..4fa6708 100644
--- a/gcc/optinfo-emit-json.cc
+++ b/gcc/optinfo-emit-json.cc
@@ -47,38 +47,6 @@ along with GCC; see the file COPYING3. If not see
#include "dump-context.h"
#include <zlib.h>
-/* A class for writing out optimization records in JSON format. */
-
-class optrecord_json_writer
-{
-public:
- optrecord_json_writer ();
- ~optrecord_json_writer ();
- void write () const;
- void add_record (const optinfo *optinfo);
- void pop_scope ();
-
- void add_record (json::object *obj);
- json::object *impl_location_to_json (dump_impl_location_t loc);
- json::object *location_to_json (location_t loc);
- json::object *profile_count_to_json (profile_count count);
- json::string *get_id_value_for_pass (opt_pass *pass);
- json::object *pass_to_json (opt_pass *pass);
- json::value *inlining_chain_to_json (location_t loc);
- json::object *optinfo_to_json (const optinfo *optinfo);
- void add_pass_list (json::array *arr, opt_pass *pass);
-
-private:
- /* The root value for the JSON file.
- Currently the JSON values are stored in memory, and flushed when the
- compiler exits. It would probably be better to simply write out
- the JSON as we go. */
- json::array *m_root_tuple;
-
- /* The currently open scopes, for expressing nested optimization records. */
- auto_vec<json::array *> m_scopes;
-};
-
/* optrecord_json_writer's ctor. Populate the top-level parts of the
in-memory JSON representation. */
@@ -471,75 +439,6 @@ optrecord_json_writer::add_pass_list (json::array *arr, opt_pass *pass)
while (pass);
}
-/* File-level interface to rest of compiler (to avoid exposing
- class optrecord_json_writer outside of this file). */
-
-static optrecord_json_writer *the_json_writer;
-
-/* Perform startup activity for -fsave-optimization-record. */
-
-void
-optimization_records_start ()
-{
- /* Bail if recording not enabled. */
- if (!flag_save_optimization_record)
- return;
-
- the_json_writer = new optrecord_json_writer ();
-}
-
-/* Perform cleanup activity for -fsave-optimization-record.
-
- Currently, the file is written out here in one go, before cleaning
- up. */
-
-void
-optimization_records_finish ()
-{
- /* Bail if recording not enabled. */
- if (!the_json_writer)
- return;
-
- the_json_writer->write ();
-
- delete the_json_writer;
- the_json_writer = NULL;
-}
-
-/* Did the user request optimization records to be written out? */
-
-bool
-optimization_records_enabled_p ()
-{
- return the_json_writer != NULL;
-}
-
-/* If optimization records were requested, then add a record for OPTINFO
- to the queue of records to be written. */
-
-void
-optimization_records_maybe_record_optinfo (const optinfo *optinfo)
-{
- /* Bail if recording not enabled. */
- if (!the_json_writer)
- return;
-
- the_json_writer->add_record (optinfo);
-}
-
-/* Handling for the end of a dump scope for the
- optimization records sink. */
-
-void
-optimization_records_maybe_pop_dump_scope ()
-{
- /* Bail if recording not enabled. */
- if (!the_json_writer)
- return;
-
- the_json_writer->pop_scope ();
-}
-
#if CHECKING_P
namespace selftest {