GCC Middle and Back End API Reference
coverage.c File Reference
#include "gt-coverage.h"
Include dependency graph for coverage.c:

Data Structures

struct  coverage_data
struct  counts_entry

Typedefs

typedef struct counts_entry counts_entry_t

Functions

static void read_counts_file (void)
static tree build_var (tree, tree, int)
static void build_fn_info_type (tree, unsigned, tree)
static void build_info_type (tree, tree)
static tree build_fn_info (const struct coverage_data *, tree, tree)
static tree build_info (tree, tree)
static bool coverage_obj_init (void)
static vec< constructor_elt,
va_gc > * 
coverage_obj_fn (vec< constructor_elt, va_gc > *, tree, struct coverage_data const *)
static void coverage_obj_finish (vec< constructor_elt, va_gc > *)
tree get_gcov_type ()
static tree get_gcov_unsigned_t ()
gcov_typeget_coverage_counts (unsigned counter, unsigned expected, unsigned cfg_checksum, unsigned lineno_checksum, const struct gcov_ctr_summary **summary)
int coverage_counter_alloc ()
tree tree_coverage_counter_ref ()
tree tree_coverage_counter_addr ()
static unsigned coverage_checksum_string ()
unsigned coverage_compute_lineno_checksum ()
unsigned coverage_compute_profile_id ()
unsigned coverage_compute_cfg_checksum ()
int coverage_begin_function ()
void coverage_end_function ()
static tree build_var ()
static void build_fn_info_type ()
static tree build_fn_info ()
static void build_info_type ()
static tree build_info ()
static void build_init_ctor ()
static void coverage_obj_finish ()
void coverage_init ()
void coverage_finish ()

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 char * bbg_file_name
static unsigned bbg_file_stamp
static char * da_file_name
static const char *const ctr_merge_functions [GCOV_COUNTERS] = GCOV_MERGE_FUNCTIONS
static const char *const ctr_names [GCOV_COUNTERS] = GCOV_COUNTER_NAMES
static hash_table< counts_entrycounts_hash

Typedef Documentation

typedef struct counts_entry counts_entry_t
Counts information for a function.   

Function Documentation

static tree build_fn_info ( const struct coverage_data ,
tree  ,
tree   
)
static

Referenced by coverage_obj_fn().

static tree build_fn_info ( )
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 build_constructor(), build_int_cstu(), coverage_data::cfg_checksum, count, coverage_data::ctr_vars, get_gcov_unsigned_t(), coverage_data::ident, coverage_data::lineno_checksum, prg_ctr_mask, and tree_low_cst().

static void build_fn_info_type ( tree  ,
unsigned  ,
tree   
)
static

Referenced by coverage_obj_init().

static tree build_info ( tree  ,
tree   
)
static

Referenced by coverage_obj_finish().

static tree build_info ( )
static
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, build_array_type(), build_constructor(), build_index_type(), build_int_cstu(), build_string(), ctr_merge_functions, da_file_name, get_identifier(), prg_ctr_mask, and strlen().

static void build_info_type ( tree  ,
tree   
)
static

Referenced by coverage_obj_init().

static void build_info_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_function_type_list(), build_index_type(), build_pointer_type(), build_qualified_type(), finish_builtin_struct(), get_gcov_type(), get_gcov_unsigned_t(), and TYPE_QUAL_CONST.

static void build_init_ctor ( )
static
static tree build_var ( tree  ,
tree  ,
int   
)
static
static tree build_var ( )
static
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 get_identifier(), len, memcpy(), strlen(), and targetm.

int coverage_begin_function ( )
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, current_function_decl, expand_location(), gcov_is_error(), gcov_write_length(), gcov_write_string(), gcov_write_tag(), gcov_write_unsigned(), no_coverage, and offset.

Referenced by branch_prob().

static unsigned coverage_checksum_string ( )
static
Generate a checksum for a string.  CHKSUM is the current
   checksum.   

References crc32_string(), free(), and offset.

Referenced by coverage_compute_lineno_checksum(), and coverage_compute_profile_id().

unsigned coverage_compute_cfg_checksum ( void  )
Compute cfg checksum for the current function.
   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(), edge_def::dest, basic_block_def::index, and basic_block_def::succs.

Referenced by branch_prob().

unsigned coverage_compute_lineno_checksum ( void  )
Compute checksum for the current function.  We generate a CRC32.   

References coverage_checksum_string(), current_function_decl, and expand_location().

Referenced by branch_prob().

unsigned coverage_compute_profile_id ( )
Compute profile ID.  This is better to be unique in whole program.   

References coverage_checksum_string(), symtab_node_base::decl, expand_location(), first_global_object_name, and cgraph_node::symbol.

Referenced by init_node_map().

int coverage_counter_alloc ( )
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(), and no_coverage.

Referenced by branch_prob(), and instrument_values().

void coverage_finish ( void  )
Performs file-level cleanup.  Close notes file, generate coverage
   variables and constructor.   

References bbg_file_name, coverage_obj_finish(), coverage_obj_fn(), coverage_obj_init(), da_file_name, coverage_data::fn_decl, functions_head, gcov_close(), local_tick, and coverage_data::next.

Referenced by ipa_passes().

void coverage_init ( )
Perform file-level initialization. Read in data file, generate name
   of notes file.   

References bbg_file_name, bbg_file_stamp, da_file_name, error(), gcov_open(), gcov_write_unsigned(), len, local_tick, memcpy(), read_counts_file(), and strlen().

Referenced by do_compile().

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

Referenced by coverage_finish().

static void coverage_obj_finish ( )
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_index_type(), build_info(), build_qualified_type(), gcov_fn_info_ptr_type, gcov_info_var, get_identifier(), TYPE_QUAL_CONST, varpool_finalize_decl(), and vec_safe_length().

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 build_fn_info(), build_var(), gcov_fn_info_ptr_type, gcov_fn_info_type, gcov_info_var, and varpool_finalize_decl().

Referenced by coverage_finish().

static bool coverage_obj_init ( )
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_fn_info_type(), build_info_type(), build_init_ctor(), build_pointer_type(), build_qualified_type(), cgraph_dump_file, da_file_name, coverage_data::fn_decl, functions_head, 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, prg_ctr_mask, TYPE_QUAL_CONST, and lang_hooks::types.

Referenced by coverage_finish().

gcov_type* get_coverage_counts ( unsigned  counter,
unsigned  expected,
unsigned  cfg_checksum,
unsigned  lineno_checksum,
const struct gcov_ctr_summary **  summary 
)
static tree get_gcov_unsigned_t ( )
static
Return the type node for gcov_unsigned_t.   

Referenced by build_fn_info(), build_fn_info_type(), and build_info_type().

static void read_counts_file ( void  )
static
Forward declarations.   
Read in the counts file, if available.   

References counts_hash, and error().

Referenced by coverage_init().

tree tree_coverage_counter_addr ( )
tree tree_coverage_counter_ref ( )
Generate a tree to access COUNTER NO.   

References build_int_cst(), fn_b_ctrs, fn_n_ctrs, fn_v_ctrs, gcov_type_node, and get_gcov_type().

Referenced by gimple_gen_edge_profiler(), and gimple_gen_interval_profiler().


Variable Documentation

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

unsigned bbg_file_stamp
static
File stamp for notes file.   

Referenced by build_info(), and coverage_init().

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

Referenced by get_coverage_counts(), and read_counts_file().

const char* const ctr_merge_functions[GCOV_COUNTERS] = GCOV_MERGE_FUNCTIONS
static
The names of merge functions for counters.   

Referenced by build_info().

const char* const ctr_names[GCOV_COUNTERS] = GCOV_COUNTER_NAMES
static

Referenced by get_coverage_counts().

char* da_file_name
static
Name of the count data (gcda) file.   

Referenced by build_info(), coverage_finish(), coverage_init(), coverage_obj_init(), and get_coverage_counts().

unsigned fn_b_ctrs[GCOV_COUNTERS]
static
unsigned fn_ctr_mask
static
Counter information for current function.   

Referenced by coverage_counter_alloc(), and coverage_end_function().

unsigned fn_n_ctrs[GCOV_COUNTERS]
static
struct coverage_data* functions_head = 0
static
struct coverage_data** functions_tail = &functions_head
static

Referenced by coverage_end_function().

tree gcov_fn_info_ptr_type
static
tree gcov_fn_info_type
static
tree gcov_info_var
static
Coverage info VAR_DECL and function info type nodes.   

Referenced by build_init_ctor(), coverage_obj_finish(), coverage_obj_fn(), and coverage_obj_init().

unsigned no_coverage = 0
static
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().