diff options
author | David Malcolm <dmalcolm@redhat.com> | 2018-07-20 15:37:23 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2018-07-20 15:37:23 +0000 |
commit | 4a4412b9de23b153481a60cd69abcee71c3e34fb (patch) | |
tree | bfca81ed27910bef95adb2304ad0b3e69af27dd2 /gcc/json.h | |
parent | bf0086f1c8ff9998fb55a27f6606bccbba873e09 (diff) | |
download | gcc-4a4412b9de23b153481a60cd69abcee71c3e34fb.zip gcc-4a4412b9de23b153481a60cd69abcee71c3e34fb.tar.gz gcc-4a4412b9de23b153481a60cd69abcee71c3e34fb.tar.bz2 |
Add "-fsave-optimization-record"
This patch implements a -fsave-optimization-record option, which
leads to a JSON file being written out, recording the dump_* calls
made (via the optinfo infrastructure).
The patch includes a minimal version of the JSON patch I posted last
year, with just enough support needed for optimization records (I
removed all of the parser code, leaving just the code for building
in-memory JSON trees and writing them to a pretty_printer).
gcc/ChangeLog:
* Makefile.in (OBJS): Add json.o and optinfo-emit-json.o.
(CFLAGS-optinfo-emit-json.o): Define TARGET_NAME.
* common.opt (fsave-optimization-record): New option.
* coretypes.h (struct kv_pair): Move here from dumpfile.c.
* doc/invoke.texi (-fsave-optimization-record): New option.
* dumpfile.c: Include "optinfo-emit-json.h".
(struct kv_pair): Move to coretypes.h.
(optgroup_options): Make non-static.
(dump_context::end_scope): Call
optimization_records_maybe_pop_dump_scope.
* dumpfile.h (optgroup_options): New decl.
* json.cc: New file.
* json.h: New file.
* optinfo-emit-json.cc: New file.
* optinfo-emit-json.h: New file.
* optinfo.cc: Include "optinfo-emit-json.h".
(optinfo::emit): Call optimization_records_maybe_record_optinfo.
(optinfo_enabled_p): Check optimization_records_enabled_p.
(optinfo_wants_inlining_info_p): Likewise.
* optinfo.h: Update comment.
* profile-count.c (profile_quality_as_string): New function.
* profile-count.h (profile_quality_as_string): New decl.
(profile_count::quality): New accessor.
* selftest-run-tests.c (selftest::run_tests): Call json_cc_tests
and optinfo_emit_json_cc_tests.
* selftest.h (selftest::json_cc_tests): New decl.
(selftest::optinfo_emit_json_cc_tests): New decl.
* toplev.c: Include "optinfo-emit-json.h".
(compile_file): Call optimization_records_finish.
(do_compile): Call optimization_records_start.
* tree-ssa-live.c: Include optinfo.h.
(remove_unused_scope_block_p): Retain inlining information if
optinfo_wants_inlining_info_p returns true.
From-SVN: r262905
Diffstat (limited to 'gcc/json.h')
-rw-r--r-- | gcc/json.h | 166 |
1 files changed, 166 insertions, 0 deletions
diff --git a/gcc/json.h b/gcc/json.h new file mode 100644 index 0000000..5c3274c --- /dev/null +++ b/gcc/json.h @@ -0,0 +1,166 @@ +/* JSON trees + Copyright (C) 2017-2018 Free Software Foundation, Inc. + Contributed by David Malcolm <dmalcolm@redhat.com>. + +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 +<http://www.gnu.org/licenses/>. */ + +#ifndef GCC_JSON_H +#define GCC_JSON_H + +/* Implementation of JSON, a lightweight data-interchange format. + + See http://www.json.org/ + and http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf + and https://tools.ietf.org/html/rfc7159 + + Supports creating a DOM-like tree of json::value *, and then dumping + json::value * to text. */ + +namespace json +{ + +/* Forward decls of json::value and its subclasses (using indentation + to denote inheritance. */ + +class value; + class object; + class array; + class number; + class string; + class literal; + +/* An enum for discriminating the subclasses of json::value. */ + +enum kind +{ + /* class json::object. */ + JSON_OBJECT, + + /* class json::array. */ + JSON_ARRAY, + + /* class json::number. */ + JSON_NUMBER, + + /* class json::string. */ + JSON_STRING, + + /* class json::literal uses these three values to identify the + particular literal. */ + JSON_TRUE, + JSON_FALSE, + JSON_NULL +}; + +/* Base class of JSON value. */ + +class value +{ + public: + virtual ~value () {} + virtual enum kind get_kind () const = 0; + virtual void print (pretty_printer *pp) const = 0; + + void dump (FILE *) const; +}; + +/* Subclass of value for objects: an unordered collection of + key/value pairs. */ + +class object : public value +{ + public: + ~object (); + + enum kind get_kind () const FINAL OVERRIDE { return JSON_OBJECT; } + void print (pretty_printer *pp) const FINAL OVERRIDE; + + void set (const char *key, value *v); + + private: + typedef hash_map <char *, value *, + simple_hashmap_traits<nofree_string_hash, value *> > map_t; + map_t m_map; +}; + +/* Subclass of value for arrays. */ + +class array : public value +{ + public: + ~array (); + + enum kind get_kind () const FINAL OVERRIDE { return JSON_ARRAY; } + void print (pretty_printer *pp) const FINAL OVERRIDE; + + void append (value *v) { m_elements.safe_push (v); } + + private: + auto_vec<value *> m_elements; +}; + +/* Subclass of value for numbers. */ + +class number : public value +{ + public: + number (double value) : m_value (value) {} + + enum kind get_kind () const FINAL OVERRIDE { return JSON_NUMBER; } + void print (pretty_printer *pp) const FINAL OVERRIDE; + + double get () const { return m_value; } + + private: + double m_value; +}; + +/* Subclass of value for strings. */ + +class string : public value +{ + public: + string (const char *utf8) : m_utf8 (xstrdup (utf8)) {} + ~string () { free (m_utf8); } + + enum kind get_kind () const FINAL OVERRIDE { return JSON_STRING; } + void print (pretty_printer *pp) const FINAL OVERRIDE; + + const char *get_string () const { return m_utf8; } + + private: + char *m_utf8; +}; + +/* Subclass of value for the three JSON literals "true", "false", + and "null". */ + +class literal : public value +{ + public: + literal (enum kind kind) : m_kind (kind) {} + + enum kind get_kind () const FINAL OVERRIDE { return m_kind; } + void print (pretty_printer *pp) const FINAL OVERRIDE; + + private: + enum kind m_kind; +}; + +} // namespace json + +#endif /* GCC_JSON_H */ |