optinfo-emit-json.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Emit optimization information as JSON files.
  2. Copyright (C) 2018-2019 Free Software Foundation, Inc.
  3. Contributed by David Malcolm <dmalcolm@redhat.com>.
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #ifndef GCC_OPTINFO_EMIT_JSON_H
  17. #define GCC_OPTINFO_EMIT_JSON_H
  18. #include "json.h"
  19. class optinfo;
  20. /* A class for writing out optimization records in JSON format. */
  21. class optrecord_json_writer
  22. {
  23. public:
  24. optrecord_json_writer ();
  25. ~optrecord_json_writer ();
  26. void write () const;
  27. void add_record (const optinfo *optinfo);
  28. void pop_scope ();
  29. void add_record (json::object *obj);
  30. json::object *impl_location_to_json (dump_impl_location_t loc);
  31. json::object *location_to_json (location_t loc);
  32. json::object *profile_count_to_json (profile_count count);
  33. json::string *get_id_value_for_pass (opt_pass *pass);
  34. json::object *pass_to_json (opt_pass *pass);
  35. json::value *inlining_chain_to_json (location_t loc);
  36. json::object *optinfo_to_json (const optinfo *optinfo);
  37. void add_pass_list (json::array *arr, opt_pass *pass);
  38. private:
  39. /* The root value for the JSON file.
  40. Currently the JSON values are stored in memory, and flushed when the
  41. compiler exits. It would probably be better to simply write out
  42. the JSON as we go. */
  43. json::array *m_root_tuple;
  44. /* The currently open scopes, for expressing nested optimization records. */
  45. auto_vec<json::array *> m_scopes;
  46. };
  47. #endif /* #ifndef GCC_OPTINFO_EMIT_JSON_H */