GCC Middle and Back End API Reference
|
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "target.h"
#include "rtl.h"
#include "tree.h"
#include "tree-pass.h"
#include "memmodel.h"
#include "tm_p.h"
#include "stringpool.h"
#include "cgraph.h"
#include "coverage.h"
#include "diagnostic-core.h"
#include "fold-const.h"
#include "stor-layout.h"
#include "output.h"
#include "toplev.h"
#include "langhooks.h"
#include "tree-iterator.h"
#include "context.h"
#include "pass_manager.h"
#include "intl.h"
#include "auto-profile.h"
#include "profile.h"
#include "diagnostic.h"
#include "varasm.h"
#include "file-prefix-map.h"
#include "gcov-io.cc"
#include "gcov-counter.def"
#include "gt-coverage.h"
Data Structures | |
struct | coverage_data |
struct | counts_entry |
Macros | |
#define | GCOV_LINKAGE |
#define | STR(str) |
#define | DEF_GCOV_COUNTER(COUNTER, NAME, FN_TYPE) |
#define | DEF_GCOV_COUNTER(COUNTER, NAME, FN_TYPE) |
Functions | |
static tree | build_var (tree, tree, int) |
tree | get_gcov_type (void) |
static tree | get_gcov_unsigned_t (void) |
static void | read_counts_file (void) |
gcov_type * | get_coverage_counts (unsigned counter, unsigned cfg_checksum, unsigned lineno_checksum, unsigned int n_counts) |
int | coverage_counter_alloc (unsigned counter, unsigned num) |
tree | tree_coverage_counter_ref (unsigned counter, unsigned no) |
tree | tree_coverage_counter_addr (unsigned counter, unsigned no) |
static unsigned | coverage_checksum_string (unsigned chksum, const char *string) |
unsigned | coverage_compute_lineno_checksum (void) |
unsigned | coverage_compute_profile_id (struct cgraph_node *n) |
unsigned | coverage_compute_cfg_checksum (struct function *fn) |
int | coverage_begin_function (unsigned lineno_checksum, unsigned cfg_checksum) |
void | coverage_end_function (unsigned lineno_checksum, unsigned cfg_checksum) |
void | coverage_remove_note_file (void) |
static void | build_fn_info_type (tree type, unsigned counters, tree gcov_info_type) |
static tree | build_fn_info (const struct coverage_data *data, tree type, tree key) |
static void | build_info_type (tree type, tree fn_info_ptr_type) |
static tree | build_info (tree info_type, tree fn_ary, unsigned object_checksum) |
static void | build_init_ctor (tree gcov_info_type) |
static void | build_gcov_exit_decl (void) |
static void | build_gcov_info_var_registration (tree gcov_info_type) |
static bool | coverage_obj_init (void) |
static vec< constructor_elt, va_gc > * | coverage_obj_fn (vec< constructor_elt, va_gc > *ctor, tree fn, struct coverage_data const *data) |
static void | coverage_obj_finish (vec< constructor_elt, va_gc > *ctor, unsigned object_checksum) |
void | coverage_init (const char *filename) |
void | coverage_finish (void) |
Variables | |
static struct coverage_data * | functions_head = 0 |
static struct coverage_data ** | functions_tail = &functions_head |
static unsigned | no_coverage = 0 |
static unsigned | prg_ctr_mask |
static unsigned | fn_ctr_mask |
static tree | fn_v_ctrs [GCOV_COUNTERS] |
static unsigned | fn_n_ctrs [GCOV_COUNTERS] |
static unsigned | fn_b_ctrs [GCOV_COUNTERS] |
static tree | gcov_info_var |
static tree | gcov_fn_info_type |
static tree | gcov_fn_info_ptr_type |
static char * | bbg_file_name |
static unsigned | bbg_file_stamp |
static char * | da_file_name |
static const char *const | ctr_merge_functions [GCOV_COUNTERS] |
static const char *const | ctr_names [GCOV_COUNTERS] |
static hash_table< counts_entry > * | counts_hash |
#define DEF_GCOV_COUNTER | ( | COUNTER, | |
NAME, | |||
FN_TYPE ) |
#define DEF_GCOV_COUNTER | ( | COUNTER, | |
NAME, | |||
FN_TYPE ) |
#define GCOV_LINKAGE |
Read and write coverage files, and associated functionality. Copyright (C) 1990-2024 Free Software Foundation, Inc. Contributed by James E. Wilson, UC Berkeley/Cygnus Support; based on some ideas from Dain Samples of UC Berkeley. Further mangling by Bob Manson, Cygnus Support. Further mangled by Nathan Sidwell, CodeSourcery 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/>.
#define STR | ( | str | ) |
The names of merge functions for counters.
|
static |
Returns a CONSTRUCTOR for a gcov_fn_info. DATA is the coverage data for the function and TYPE is the gcov_fn_info RECORD_TYPE. KEY is the object file key.
References build1(), build_constructor(), build_fold_addr_expr, build_int_cstu(), CONSTRUCTOR_APPEND_ELT, count, DECL_CHAIN, fields, GCOV_COUNTERS, get_gcov_unsigned_t(), NULL, prg_ctr_mask, tree_to_shwi(), TREE_TYPE, TYPE_DOMAIN, TYPE_FIELDS, and TYPE_MAX_VALUE.
Referenced by coverage_obj_fn().
Creates the gcov_fn_info RECORD_TYPE.
References build_array_type(), build_decl(), build_index_type(), build_pointer_type(), build_qualified_type(), BUILTINS_LOCATION, DECL_CHAIN, fields, finish_builtin_struct(), gcc_assert, get_gcov_type(), get_gcov_unsigned_t(), lang_hooks_for_types::make_type, NULL_TREE, size_int, TYPE_QUAL_CONST, and lang_hooks::types.
Referenced by coverage_obj_init().
|
static |
Generate the destructor function to call __gcov_exit.
References append_to_statement_list(), build_call_expr(), build_decl(), build_function_type_list(), BUILTINS_LOCATION, cgraph_build_static_cdtor(), DECL_ASSEMBLER_NAME, DECL_EXTERNAL, DEFAULT_INIT_PRIORITY, get_identifier(), MAX_RESERVED_INIT_PRIORITY, NULL, SUPPORTS_INIT_PRIORITY, TREE_PUBLIC, and void_type_node.
Referenced by coverage_obj_init().
|
static |
Generate the pointer to the gcov_info_var in a dedicated section.
References build_decl(), build_fold_addr_expr, build_pointer_type(), BUILTINS_LOCATION, DECL_INITIAL, DECL_NAME, varpool_node::finalize_decl(), gcov_info_var, get_identifier(), get_section(), mark_decl_referenced(), NULL, NULL_TREE, SECTION_UNNAMED, set_decl_section_name(), TREE_READONLY, and TREE_STATIC.
Referenced by coverage_obj_init().
Returns a CONSTRUCTOR for the gcov_info object. INFO_TYPE is the gcov_info structure type, FN_ARY is the array of pointers to function info objects.
References bbg_file_stamp, build1(), build_array_type(), build_constructor(), build_decl(), build_index_type(), build_int_cstu(), build_string(), BUILTINS_LOCATION, char_type_node, CONSTRUCTOR_APPEND_ELT, ctr_merge_functions, da_file_name, DECL_ARTIFICIAL, DECL_ASSEMBLER_NAME, DECL_CHAIN, DECL_EXTERNAL, fold_build2, gcc_assert, GCOV_COUNTERS, get_identifier(), NULL, null_pointer_node, prg_ctr_mask, size_int, size_one_node, TREE_NOTHROW, TREE_PUBLIC, TREE_TYPE, TYPE_DOMAIN, TYPE_FIELDS, and TYPE_MAX_VALUE.
Referenced by coverage_obj_finish().
Create gcov_info struct. TYPE is the incomplete RECORD_TYPE to be completed, and FN_INFO_PTR_TYPE is a pointer to the function info type.
References build_array_type(), build_decl(), build_function_type_list(), build_index_type(), build_pointer_type(), build_qualified_type(), BUILTINS_LOCATION, char_type_node, DECL_CHAIN, fields, finish_builtin_struct(), GCOV_COUNTERS, get_gcov_type(), get_gcov_unsigned_t(), NULL_TREE, size_int, TYPE_QUAL_CONST, and void_type_node.
Referenced by coverage_obj_init().
|
static |
Generate the constructor function to call __gcov_init.
References append_to_statement_list(), build_call_expr(), build_decl(), build_fold_addr_expr, build_function_type_list(), build_pointer_type(), BUILTINS_LOCATION, cgraph_build_static_cdtor(), DECL_ASSEMBLER_NAME, DECL_EXTERNAL, DEFAULT_INIT_PRIORITY, gcov_info_var, get_identifier(), MAX_RESERVED_INIT_PRIORITY, NULL, SUPPORTS_INIT_PRIORITY, TREE_PUBLIC, and void_type_node.
Referenced by coverage_obj_init().
Forward declarations.
Build a coverage variable of TYPE for function FN_DECL. If COUNTER >= 0 it is a counter array, otherwise it is the function structure.
References build_decl(), BUILTINS_LOCATION, DECL_ASSEMBLER_NAME, DECL_NAME, DECL_NONALIASED, coverage_data::fn_decl, get_identifier(), IDENTIFIER_POINTER, NULL_TREE, SET_DECL_ALIGN, symbol_table::symbol_suffix_separator(), targetm, TREE_ADDRESSABLE, TREE_STATIC, and TYPE_ALIGN.
Referenced by coverage_counter_alloc(), and coverage_obj_fn().
int coverage_begin_function | ( | unsigned | lineno_checksum, |
unsigned | cfg_checksum ) |
Begin output to the notes file for the current function. Writes the function header. Returns nonzero if data should be output.
References bbg_file_name, cfun, coverage_node_map_initialized_p(), current_function_decl, current_function_funcdef_no, DECL_ARTIFICIAL, DECL_ASSEMBLER_NAME, DECL_FUNCTION_VERSIONED, DECL_LAMBDA_FUNCTION_P, DECL_SOURCE_LOCATION, expand_location(), gcc_assert, gcov_is_error(), GCOV_TAG_FUNCTION, gcov_write_filename(), gcov_write_length(), gcov_write_string(), gcov_write_tag(), gcov_write_unsigned(), cgraph_node::get(), IDENTIFIER_POINTER, no_coverage, offset, remap_profile_filename(), and warning_at().
Referenced by branch_prob().
|
static |
Generate a checksum for a string. CHKSUM is the current checksum.
References crc32_string(), free(), i, NULL, offset, startswith(), and y.
Referenced by coverage_compute_lineno_checksum(), and coverage_compute_profile_id().
unsigned coverage_compute_cfg_checksum | ( | struct function * | fn | ) |
Compute cfg checksum for the function FN given as argument. The checksum is calculated carefully so that source code changes that doesn't affect the control flow graph won't change the checksum. This is to make the profile data useable across source code change. The downside of this is that the compiler may use potentially wrong profile data - that the source code change has non-trivial impact on the validity of profile data (e.g. the reversed condition) but the compiler won't detect the change and use the wrong profile data.
References crc32_byte(), FOR_EACH_BB_FN, FOR_EACH_EDGE, basic_block_def::index, n_basic_blocks_for_fn, and basic_block_def::succs.
Referenced by branch_prob(), and ipa_icf::sem_function::init().
unsigned coverage_compute_lineno_checksum | ( | void | ) |
Compute checksum for the current function. We generate a CRC32.
References coverage_checksum_string(), current_function_decl, DECL_ASSEMBLER_NAME, DECL_SOURCE_LOCATION, expand_location(), and IDENTIFIER_POINTER.
Referenced by branch_prob().
unsigned coverage_compute_profile_id | ( | struct cgraph_node * | n | ) |
Compute profile ID. This is better to be unique in whole program.
References coverage_checksum_string(), symtab_node::decl, DECL_ASSEMBLER_NAME, DECL_EXTERNAL, DECL_SOURCE_LOCATION, endswith(), expand_location(), first_global_object_name, free(), IDENTIFIER_POINTER, TREE_PUBLIC, and symtab_node::unique_name.
Referenced by init_node_map().
int coverage_counter_alloc | ( | unsigned | counter, |
unsigned | num ) |
Allocate NUM counters of type COUNTER. Returns nonzero if the allocation succeeded.
References build_array_type(), build_var(), current_function_decl, fn_b_ctrs, fn_ctr_mask, fn_n_ctrs, fn_v_ctrs, get_gcov_type(), no_coverage, and NULL_TREE.
Referenced by branch_prob(), and instrument_values().
void coverage_end_function | ( | unsigned | lineno_checksum, |
unsigned | cfg_checksum ) |
Finish coverage data for the current function. Verify no output error has occurred. Save function coverage counts.
References bbg_file_name, build_array_type(), build_index_type(), coverage_data::cfg_checksum, cfun, coverage_node_map_initialized_p(), coverage_data::ctr_vars, current_function_decl, current_function_funcdef_no, DECL_SIZE, DECL_SIZE_UNIT, varpool_node::finalize_decl(), fn_b_ctrs, fn_ctr_mask, coverage_data::fn_decl, fn_n_ctrs, fn_v_ctrs, functions_tail, gcc_assert, GCOV_COUNTERS, gcov_is_error(), cgraph_node::get(), get_gcov_type(), ggc_alloc(), i, coverage_data::ident, coverage_data::lineno_checksum, coverage_data::next, NULL, NULL_TREE, prg_ctr_mask, cgraph_node::profile_id, size_int, TREE_TYPE, TYPE_SIZE, TYPE_SIZE_UNIT, and warning().
Referenced by branch_prob().
void coverage_finish | ( | void | ) |
Performs file-level cleanup. Close notes file, generate coverage variables and constructor.
References bbg_file_name, coverage_data::cfg_checksum, coverage_obj_finish(), coverage_obj_fn(), coverage_obj_init(), crc32_unsigned(), da_file_name, coverage_data::fn_decl, functions_head, gcov_close(), coverage_data::ident, coverage_data::lineno_checksum, local_tick, coverage_data::next, and NULL.
Referenced by ipa_passes().
void coverage_init | ( | const char * | filename | ) |
Perform file-level initialization. Read in data file, generate name of notes file.
References bbg_file_name, bbg_file_stamp, da_file_name, gcc::dump_manager::dump_finish(), gcc::dump_manager::dump_start(), error(), g, GCOV_DATA_SUFFIX, GCOV_NOTE_MAGIC, GCOV_NOTE_SUFFIX, gcov_open(), gcov_write_string(), gcov_write_unsigned(), gcc::context::get_dumps(), gcc::pass_manager::get_pass_profile(), gcc::context::get_passes(), local_tick, mangle_path(), lang_hooks::name, NULL, read_autofdo_file(), read_counts_file(), startswith(), opt_pass::static_pass_number, and warning().
Referenced by do_compile().
|
static |
Finalize the coverage data. Generates the array of pointers to function objects from CTOR. Generate the gcov_info initializer.
References build_array_type(), build_constructor(), build_decl(), build_index_type(), build_info(), build_qualified_type(), BUILTINS_LOCATION, DECL_INITIAL, DECL_NAME, varpool_node::finalize_decl(), gcov_fn_info_ptr_type, gcov_info_var, get_identifier(), NULL_TREE, size_int, TREE_STATIC, TREE_TYPE, TYPE_QUAL_CONST, and vec_safe_length().
Referenced by coverage_finish().
|
static |
Generate the coverage function info for FN and DATA. Append a pointer to that object to CTOR and return the appended CTOR.
References build1(), build_fn_info(), build_var(), CONSTRUCTOR_APPEND_ELT, DECL_INITIAL, varpool_node::finalize_decl(), gcov_fn_info_ptr_type, gcov_fn_info_type, gcov_info_var, and NULL.
Referenced by coverage_finish().
|
static |
Create the gcov_info types and object. Generate the constructor function to call __gcov_init. Does not generate the initializer for the object. Returns TRUE if coverage data is being emitted.
References build_decl(), build_fn_info_type(), build_gcov_exit_decl(), build_gcov_info_var_registration(), build_info_type(), build_init_ctor(), build_pointer_type(), build_qualified_type(), BUILTINS_LOCATION, da_file_name, DECL_NAME, DECL_STRUCT_FUNCTION, symbol_table::dump_file, coverage_data::fn_decl, functions_head, GCOV_COUNTERS, gcov_fn_info_ptr_type, gcov_fn_info_type, gcov_info_var, get_identifier(), lang_hooks_for_types::make_type, coverage_data::next, no_coverage, NULL, NULL_TREE, prg_ctr_mask, symtab, TREE_STATIC, TYPE_QUAL_CONST, and lang_hooks::types.
Referenced by coverage_finish().
void coverage_remove_note_file | ( | void | ) |
Remove coverage file if opened.
References bbg_file_name, and gcov_close().
Referenced by finalize().
gcov_type * get_coverage_counts | ( | unsigned | counter, |
unsigned | cfg_checksum, | ||
unsigned | lineno_checksum, | ||
unsigned int | n_counts ) |
Returns the counters for a particular tag.
References counts_entry::cfg_checksum, counts_entry::counts, counts_hash, coverage_node_map_initialized_p(), counts_entry::ctr, ctr_names, current_function_decl, current_function_funcdef_no, da_file_name, DECL_SOURCE_LOCATION, dump_enabled_p(), dump_printf(), dump_printf_loc(), dump_user_location_t::from_function_decl(), dump_user_location_t::from_location_t(), G_, gcc_assert, cgraph_node::get(), counts_entry::ident, input_location, counts_entry::lineno_checksum, MSG_MISSED_OPTIMIZATION, counts_entry::n_counts, NULL, cgraph_node::profile_id, seen_error(), warning(), and warning_at().
Referenced by compute_value_histograms(), get_exec_counts(), and read_thunk_profile().
tree get_gcov_type | ( | void | ) |
Return the type node for gcov_type.
References LONG_LONG_TYPE_SIZE, opt_mode< T >::require(), smallest_int_mode_for_size(), lang_hooks_for_types::type_for_mode, and lang_hooks::types.
Referenced by build_fn_info_type(), build_info_type(), coverage_counter_alloc(), coverage_end_function(), gimple_divmod_fixed_value_transform(), gimple_gen_ic_profiler(), gimple_gen_time_profiler(), gimple_init_gcov_profiler(), gimple_stringops_transform(), init_ic_make_global_vars(), tree_coverage_counter_addr(), tree_coverage_counter_ref(), and tree_profiling().
|
static |
Return the type node for gcov_unsigned_t.
References opt_mode< T >::require(), smallest_int_mode_for_size(), lang_hooks_for_types::type_for_mode, and lang_hooks::types.
Referenced by build_fn_info(), build_fn_info_type(), and build_info_type().
|
static |
Read in the counts file, if available.
References bbg_file_stamp, counts_entry::cfg_checksum, counts_entry::counts, counts_hash, crc32_unsigned(), counts_entry::ctr, da_file_name, error(), G_, gcov_close(), GCOV_COUNTER_FOR_TAG, GCOV_DATA_MAGIC, gcov_is_error(), gcov_magic(), gcov_open(), gcov_position(), gcov_read_counter(), gcov_read_unsigned(), gcov_sync(), GCOV_TAG_COUNTER_NUM, GCOV_TAG_FUNCTION, GCOV_TAG_IS_COUNTER, GCOV_TAG_OBJECT_SUMMARY, GCOV_UNSIGNED2STRING, counts_entry::ident, counts_entry::lineno_checksum, counts_entry::n_counts, NULL, offset, profile_info, gcov_summary::runs, gcov_summary::sum_max, and warning().
Referenced by coverage_init().
tree tree_coverage_counter_addr | ( | unsigned | counter, |
unsigned | no ) |
Generate a tree to access the address of COUNTER NO.
References build4(), build_fold_addr_expr, build_int_cst(), fn_b_ctrs, fn_n_ctrs, fn_v_ctrs, gcc_assert, gcov_type_node, get_gcov_type(), integer_type_node, and NULL.
Referenced by gimple_gen_average_profiler(), gimple_gen_ic_profiler(), gimple_gen_ior_profiler(), gimple_gen_pow2_profiler(), and gimple_gen_topn_values_profiler().
tree tree_coverage_counter_ref | ( | unsigned | counter, |
unsigned | no ) |
Generate a tree to access COUNTER NO.
References build4(), build_int_cst(), fn_b_ctrs, fn_n_ctrs, fn_v_ctrs, gcc_assert, gcov_type_node, get_gcov_type(), integer_type_node, and NULL.
Referenced by gimple_gen_edge_profiler(), gimple_gen_interval_profiler(), gimple_gen_time_profiler(), and instrument_decisions().
|
static |
Name of the notes (gcno) output file. The "bbg" prefix is for historical reasons, when the notes file contained only the basic block graph notes. If this is NULL we're not writing to the notes file.
Referenced by coverage_begin_function(), coverage_end_function(), coverage_finish(), coverage_init(), and coverage_remove_note_file().
|
static |
File stamp for notes file.
Referenced by build_info(), coverage_init(), and read_counts_file().
|
static |
Hash table of count data.
Referenced by get_coverage_counts(), and read_counts_file().
|
static |
Referenced by build_info().
|
static |
Referenced by get_coverage_counts().
|
static |
Name of the count data (gcda) file.
Referenced by build_info(), coverage_finish(), coverage_init(), coverage_obj_init(), get_coverage_counts(), and read_counts_file().
|
static |
|
static |
Counter information for current function.
Referenced by coverage_counter_alloc(), and coverage_end_function().
|
static |
|
static |
|
static |
Referenced by coverage_finish(), and coverage_obj_init().
|
static |
Referenced by coverage_end_function().
|
static |
Referenced by coverage_obj_finish(), coverage_obj_fn(), and coverage_obj_init().
|
static |
Referenced by coverage_obj_fn(), and coverage_obj_init().
|
static |
Coverage info VAR_DECL and function info type nodes.
Referenced by build_gcov_info_var_registration(), build_init_ctor(), coverage_obj_finish(), coverage_obj_fn(), and coverage_obj_init().
|
static |
Referenced by coverage_begin_function(), coverage_counter_alloc(), and coverage_obj_init().
|
static |
Cumulative counter information for whole program.
Referenced by build_fn_info(), build_info(), coverage_end_function(), and coverage_obj_init().