GCC Middle and Back End API Reference
optrecord_json_writer Class Reference

#include <optinfo-emit-json.h>

Collaboration diagram for optrecord_json_writer:

Public Member Functions

 optrecord_json_writer ()
void write () const
void add_record (const optinfo &optinfo)
void pop_scope ()
void add_record (std::unique_ptr< json::object > obj)
std::unique_ptr< json::objectimpl_location_to_json (dump_impl_location_t loc)
std::unique_ptr< json::objectlocation_to_json (location_t loc)
std::unique_ptr< json::objectprofile_count_to_json (profile_count count)
std::unique_ptr< json::stringget_id_value_for_pass (const opt_pass &pass)
std::unique_ptr< json::objectpass_to_json (const opt_pass &pass)
std::unique_ptr< json::arrayinlining_chain_to_json (location_t loc)
std::unique_ptr< json::objectoptinfo_to_json (const optinfo &optinfo)
void add_pass_list (json::array *arr, const opt_pass *pass)

Private Attributes

std::unique_ptr< json::arraym_root_tuple
auto_vec< json::array * > m_scopes

Detailed Description

A class for writing out optimization records in JSON format.   

Constructor & Destructor Documentation

◆ optrecord_json_writer()

optrecord_json_writer::optrecord_json_writer ( )
Emit optimization information as JSON files.
   Copyright (C) 2018-2026 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/>.   
optrecord_json_writer's ctor.  Populate the top-level parts of the
in-memory JSON representation.   

References GCC_PASS_LISTS, json::array::get(), m_root_tuple, m_scopes, and lang_hooks::name.

Member Function Documentation

◆ add_pass_list()

void optrecord_json_writer::add_pass_list ( json::array * arr,
const opt_pass * pass )
Add a json description of PASS and its siblings to ARR, recursing into
child passes (adding their descriptions within a "children" array).   

References add_pass_list(), json::array::append(), gcc_assert, opt_pass::next, pass_to_json(), and opt_pass::sub.

Referenced by add_pass_list().

◆ add_record() [1/2]

void optrecord_json_writer::add_record ( const optinfo & optinfo)
Add a record for OPTINFO to the queue of records to be written.   

References add_record(), optinfo::get_kind(), m_scopes, optinfo_to_json(), and optinfo::scope.

Referenced by add_record().

◆ add_record() [2/2]

void optrecord_json_writer::add_record ( std::unique_ptr< json::object > obj)
Private methods of optrecord_json_writer.   
Add record OBJ to the innermost scope.   

References gcc_assert, and m_scopes.

◆ get_id_value_for_pass()

std::unique_ptr< json::string > optrecord_json_writer::get_id_value_for_pass ( const opt_pass & pass)
Get a string for use when referring to PASS in the saved optimization
records.   

References pp_formatted_text(), and pp_pointer.

Referenced by optinfo_to_json(), and pass_to_json().

◆ impl_location_to_json()

std::unique_ptr< json::object > optrecord_json_writer::impl_location_to_json ( dump_impl_location_t loc)
Create a JSON object representing LOC.   

References dump_impl_location_t::m_file, dump_impl_location_t::m_function, and dump_impl_location_t::m_line.

Referenced by optinfo_to_json().

◆ inlining_chain_to_json()

std::unique_ptr< json::array > optrecord_json_writer::inlining_chain_to_json ( location_t loc)
Create a JSON array for LOC representing the chain of inlining
locations.
Compare with lhd_print_error_function and cp_print_error_function.   

References BLOCK_ABSTRACT_ORIGIN, BLOCK_SOURCE_LOCATION, BLOCK_SUPERCONTEXT, lang_hooks::decl_printable_name, LOCATION_BLOCK, LOCATION_LOCUS, location_to_json(), TREE_CODE, and UNKNOWN_LOCATION.

Referenced by optinfo_to_json().

◆ location_to_json()

std::unique_ptr< json::object > optrecord_json_writer::location_to_json ( location_t loc)
Create a JSON object representing LOC.   

References expand_location(), gcc_assert, LOCATION_LOCUS, and UNKNOWN_LOCATION.

Referenced by inlining_chain_to_json(), and optinfo_to_json().

◆ optinfo_to_json()

◆ pass_to_json()

std::unique_ptr< json::object > optrecord_json_writer::pass_to_json ( const opt_pass & pass)

◆ pop_scope()

void optrecord_json_writer::pop_scope ( )
Pop the innermost scope.   

References gcc_assert, and m_scopes.

◆ profile_count_to_json()

std::unique_ptr< json::object > optrecord_json_writer::profile_count_to_json ( profile_count count)
Create a JSON object representing COUNT.   

References count, and profile_quality_as_string().

Referenced by optinfo_to_json().

◆ write()

void optrecord_json_writer::write ( ) const
Choose an appropriate filename, and write the saved records to it.   

References error_at(), free(), m_root_tuple, pp_formatted_text(), and UNKNOWN_LOCATION.

Field Documentation

◆ m_root_tuple

std::unique_ptr<json::array> optrecord_json_writer::m_root_tuple
private

Referenced by optrecord_json_writer(), and write().

◆ m_scopes

auto_vec<json::array *> optrecord_json_writer::m_scopes
private

The documentation for this class was generated from the following files: