GCC Middle and Back End API Reference
optinfo-emit-json.h
Go to the documentation of this file.
1/* Emit optimization information as JSON files.
2 Copyright (C) 2018-2026 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 3, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21#ifndef GCC_OPTINFO_EMIT_JSON_H
22#define GCC_OPTINFO_EMIT_JSON_H
23
24#include "json.h"
25
26class optinfo;
27
28/* A class for writing out optimization records in JSON format. */
29
31{
32public:
34
35 void write () const;
36 void add_record (const optinfo &optinfo);
37 void pop_scope ();
38
39 void add_record (std::unique_ptr<json::object> obj);
40
41 std::unique_ptr<json::object>
43
44 std::unique_ptr<json::object>
45 location_to_json (location_t loc);
46
47 std::unique_ptr<json::object>
49
50 std::unique_ptr<json::string>
51 get_id_value_for_pass (const opt_pass &pass);
52
53 std::unique_ptr<json::object>
54 pass_to_json (const opt_pass &pass);
55
56 std::unique_ptr<json::array>
57 inlining_chain_to_json (location_t loc);
58
59 std::unique_ptr<json::object>
61
62 void
63 add_pass_list (json::array *arr, const opt_pass *pass);
64
65 private:
66 /* The root value for the JSON file.
67 Currently the JSON values are stored in memory, and flushed when the
68 compiler exits. It would probably be better to simply write out
69 the JSON as we go. */
70 std::unique_ptr<json::array> m_root_tuple;
71
72 /* The currently open scopes, for expressing nested optimization records. */
74};
75
76#endif /* #ifndef GCC_OPTINFO_EMIT_JSON_H */
Definition vec.h:1667
Definition dumpfile.h:381
Definition json.h:263
Definition tree-pass.h:74
Definition optinfo.h:82
std::unique_ptr< json::object > location_to_json(location_t loc)
Definition optinfo-emit-json.cc:186
std::unique_ptr< json::object > profile_count_to_json(profile_count count)
Definition optinfo-emit-json.cc:200
std::unique_ptr< json::array > inlining_chain_to_json(location_t loc)
Definition optinfo-emit-json.cc:266
optrecord_json_writer()
Definition optinfo-emit-json.cc:54
void add_record(const optinfo &optinfo)
Definition optinfo-emit-json.cc:131
std::unique_ptr< json::object > optinfo_to_json(const optinfo &optinfo)
Definition optinfo-emit-json.cc:323
std::unique_ptr< json::string > get_id_value_for_pass(const opt_pass &pass)
Definition optinfo-emit-json.cc:212
std::unique_ptr< json::object > impl_location_to_json(dump_impl_location_t loc)
Definition optinfo-emit-json.cc:173
std::unique_ptr< json::array > m_root_tuple
Definition optinfo-emit-json.h:70
void add_pass_list(json::array *arr, const opt_pass *pass)
Definition optinfo-emit-json.cc:426
std::unique_ptr< json::object > pass_to_json(const opt_pass &pass)
Definition optinfo-emit-json.cc:223
auto_vec< json::array * > m_scopes
Definition optinfo-emit-json.h:73
void write() const
Definition optinfo-emit-json.cc:95
void pop_scope()
Definition optinfo-emit-json.cc:162
Definition profile-count.h:789