GCC Middle and Back End API Reference
coverage.cc File 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"
Include dependency graph for coverage.cc:

Data Structures

struct  coverage_data
 
struct  counts_entry
 

Macros

#define GCOV_LINKAGE
 
#define STR(str)   #str
 
#define DEF_GCOV_COUNTER(COUNTER, NAME, FN_TYPE)   STR(__gcov_merge ## FN_TYPE),
 
#define DEF_GCOV_COUNTER(COUNTER, NAME, FN_TYPE)   NAME,
 

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_typeget_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_datafunctions_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 charbbg_file_name
 
static unsigned bbg_file_stamp
 
static charda_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
 

Macro Definition Documentation

◆ DEF_GCOV_COUNTER [1/2]

#define DEF_GCOV_COUNTER ( COUNTER,
NAME,
FN_TYPE )   STR(__gcov_merge ## FN_TYPE),

◆ DEF_GCOV_COUNTER [2/2]

#define DEF_GCOV_COUNTER ( COUNTER,
NAME,
FN_TYPE )   NAME,

◆ GCOV_LINKAGE

#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/>.   

◆ STR

#define STR ( str)    #str
The names of merge functions for counters.   

Function Documentation

◆ build_fn_info()

static tree build_fn_info ( const struct coverage_data * data,
tree type,
tree key )
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(), ggc_alloc(), NULL, prg_ctr_mask, tree_to_shwi(), TREE_TYPE, TYPE_DOMAIN, TYPE_FIELDS, and TYPE_MAX_VALUE.

Referenced by coverage_obj_fn().

◆ build_fn_info_type()

◆ build_gcov_exit_decl()

◆ build_gcov_info_var_registration()

◆ build_info()

◆ build_info_type()

static void build_info_type ( tree type,
tree fn_info_ptr_type )
static
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(), ggc_alloc(), NULL_TREE, size_int, TYPE_QUAL_CONST, and void_type_node.

Referenced by coverage_obj_init().

◆ build_init_ctor()

◆ build_var()

static tree build_var ( tree fn_decl,
tree type,
int counter )
static
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(), ggc_alloc(), 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().

◆ coverage_begin_function()

◆ coverage_checksum_string()

static unsigned coverage_checksum_string ( unsigned chksum,
const char * string )
static
Generate a checksum for a string.  CHKSUM is the current
checksum.   

References crc32_string(), free(), ggc_alloc(), i, NULL, offset, startswith(), and y.

Referenced by coverage_compute_lineno_checksum(), and coverage_compute_profile_id().

◆ coverage_compute_cfg_checksum()

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, ggc_alloc(), basic_block_def::index, n_basic_blocks_for_fn, and basic_block_def::succs.

Referenced by branch_prob(), and ipa_icf::sem_function::init().

◆ coverage_compute_lineno_checksum()

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(), ggc_alloc(), and IDENTIFIER_POINTER.

Referenced by branch_prob().

◆ coverage_compute_profile_id()

◆ coverage_counter_alloc()

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().

◆ coverage_end_function()

◆ coverage_finish()

◆ coverage_init()

◆ coverage_obj_finish()

static void coverage_obj_finish ( vec< constructor_elt, va_gc > * ctor,
unsigned object_checksum )
static

◆ coverage_obj_fn()

static vec< constructor_elt, va_gc > * coverage_obj_fn ( vec< constructor_elt, va_gc > * ctor,
tree fn,
struct coverage_data const * data )
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, ggc_alloc(), and NULL.

Referenced by coverage_finish().

◆ coverage_obj_init()

◆ coverage_remove_note_file()

void coverage_remove_note_file ( void )
Remove coverage file if opened.   

References bbg_file_name, gcov_close(), and ggc_alloc().

Referenced by finalize().

◆ get_coverage_counts()

◆ get_gcov_type()

◆ get_gcov_unsigned_t()

static tree get_gcov_unsigned_t ( void )
static
Return the type node for gcov_unsigned_t.   

References 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().

◆ read_counts_file()

◆ tree_coverage_counter_addr()

◆ tree_coverage_counter_ref()

Variable Documentation

◆ bbg_file_name

char* bbg_file_name
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().

◆ bbg_file_stamp

unsigned bbg_file_stamp
static
File stamp for notes file.   

Referenced by build_info(), coverage_init(), and read_counts_file().

◆ counts_hash

hash_table<counts_entry>* counts_hash
static
Hash table of count data.   

Referenced by get_coverage_counts(), and read_counts_file().

◆ ctr_merge_functions

const char* const ctr_merge_functions[GCOV_COUNTERS]
static
Initial value:
= {
}

Referenced by build_info().

◆ ctr_names

const char* const ctr_names[GCOV_COUNTERS]
static
Initial value:
= {
}

Referenced by get_coverage_counts().

◆ da_file_name

char* da_file_name
static

◆ fn_b_ctrs

◆ fn_ctr_mask

unsigned fn_ctr_mask
static
Counter information for current function.   

Referenced by coverage_counter_alloc(), and coverage_end_function().

◆ fn_n_ctrs

◆ fn_v_ctrs

◆ functions_head

struct coverage_data* functions_head = 0
static

◆ functions_tail

struct coverage_data** functions_tail = &functions_head
static

Referenced by coverage_end_function().

◆ gcov_fn_info_ptr_type

tree gcov_fn_info_ptr_type
static

◆ gcov_fn_info_type

tree gcov_fn_info_type
static

◆ gcov_info_var

tree gcov_info_var
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().

◆ no_coverage

◆ prg_ctr_mask

unsigned prg_ctr_mask
static
Cumulative counter information for whole program.   

Referenced by build_fn_info(), build_info(), coverage_end_function(), and coverage_obj_init().