| 1 |
/* Definitions for transformations based on profile information for values. |
| 2 |
Copyright (C) 2003-2025 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is part of GCC. |
| 5 |
|
| 6 |
GCC is free software; you can redistribute it and/or modify it under |
| 7 |
the terms of the GNU General Public License as published by the Free |
| 8 |
Software Foundation; either version 3, or (at your option) any later |
| 9 |
version. |
| 10 |
|
| 11 |
GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 |
WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 |
for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with GCC; see the file COPYING3. If not see |
| 18 |
<http://www.gnu.org/licenses/>. */ |
| 19 |
|
| 20 |
#ifndef GCC_VALUE_PROF_H |
| 21 |
#define GCC_VALUE_PROF_H |
| 22 |
|
| 23 |
/* Supported histogram types. */ |
| 24 |
enum hist_type |
| 25 |
{ |
| 26 |
HIST_TYPE_INTERVAL, /* Measures histogram of values inside a specified |
| 27 |
interval. */ |
| 28 |
HIST_TYPE_POW2, /* Histogram of power of 2 values. */ |
| 29 |
HIST_TYPE_TOPN_VALUES, /* Tries to identify the N most common values. */ |
| 30 |
HIST_TYPE_INDIR_CALL, /* Tries to identify the function that is (almost) |
| 31 |
called in indirect call */ |
| 32 |
HIST_TYPE_AVERAGE, /* Compute average value (sum of all values). */ |
| 33 |
HIST_TYPE_IOR, /* Used to compute expected alignment. */ |
| 34 |
HIST_TYPE_TIME_PROFILE, /* Used for time profile */ |
| 35 |
HIST_TYPE_MAX |
| 36 |
}; |
| 37 |
|
| 38 |
#define COUNTER_FOR_HIST_TYPE(TYPE) ((int) (TYPE) + GCOV_FIRST_VALUE_COUNTER) |
| 39 |
#define HIST_TYPE_FOR_COUNTER(COUNTER) \ |
| 40 |
((enum hist_type) ((COUNTER) - GCOV_FIRST_VALUE_COUNTER)) |
| 41 |
|
| 42 |
|
| 43 |
/* The value to measure. */ |
| 44 |
struct histogram_value_t |
| 45 |
{ |
| 46 |
struct |
| 47 |
{ |
| 48 |
tree value; /* The value to profile. */ |
| 49 |
gimple *stmt; /* Insn containing the value. */ |
| 50 |
gcov_type *counters; /* Pointer to first counter. */ |
| 51 |
struct histogram_value_t *next; /* Linked list pointer. */ |
| 52 |
} hvalue; |
| 53 |
enum hist_type type; /* Type of information to measure. */ |
| 54 |
unsigned n_counters; /* Number of required counters. */ |
| 55 |
struct function *fun; |
| 56 |
union |
| 57 |
{ |
| 58 |
struct |
| 59 |
{ |
| 60 |
int int_start; /* First value in interval. */ |
| 61 |
unsigned int steps; /* Number of values in it. */ |
| 62 |
} intvl; /* Interval histogram data. */ |
| 63 |
} hdata; /* Profiled information specific data. */ |
| 64 |
}; |
| 65 |
|
| 66 |
typedef struct histogram_value_t *histogram_value; |
| 67 |
typedef const struct histogram_value_t *const_histogram_value; |
| 68 |
|
| 69 |
|
| 70 |
typedef vec<histogram_value> histogram_values; |
| 71 |
|
| 72 |
extern void gimple_find_values_to_profile (histogram_values *); |
| 73 |
extern bool gimple_value_profile_transformations (void); |
| 74 |
|
| 75 |
histogram_value gimple_alloc_histogram_value (struct function *, enum hist_type, |
| 76 |
gimple *stmt = NULL, |
| 77 |
tree value = NULL_TREE); |
| 78 |
histogram_value gimple_histogram_value (struct function *, gimple *); |
| 79 |
histogram_value gimple_histogram_value_of_type (struct function *, gimple *, |
| 80 |
enum hist_type); |
| 81 |
void gimple_add_histogram_value (struct function *, gimple *, histogram_value); |
| 82 |
void dump_histograms_for_stmt (struct function *, FILE *, gimple *); |
| 83 |
void gimple_remove_histogram_value (struct function *, gimple *, histogram_value); |
| 84 |
void gimple_remove_stmt_histograms (struct function *, gimple *); |
| 85 |
void gimple_duplicate_stmt_histograms (struct function *, gimple *, |
| 86 |
struct function *, gimple *); |
| 87 |
void gimple_move_stmt_histograms (struct function *, gimple *, gimple *); |
| 88 |
void verify_histograms (void); |
| 89 |
void free_histograms (function *); |
| 90 |
void stringop_block_profile (gimple *, unsigned int *, HOST_WIDE_INT *); |
| 91 |
gcall *gimple_ic (gcall *, struct cgraph_node *, profile_probability); |
| 92 |
bool get_nth_most_common_value (gimple *stmt, const char *counter_type, |
| 93 |
histogram_value hist, gcov_type *value, |
| 94 |
gcov_type *count, gcov_type *all, |
| 95 |
unsigned n = 0); |
| 96 |
|
| 97 |
/* In tree-profile.cc. */ |
| 98 |
extern void gimple_init_gcov_profiler (void); |
| 99 |
extern void gimple_gen_edge_profiler (int, edge); |
| 100 |
extern void gimple_gen_interval_profiler (histogram_value, unsigned); |
| 101 |
extern void gimple_gen_pow2_profiler (histogram_value, unsigned); |
| 102 |
extern void gimple_gen_topn_values_profiler (histogram_value, unsigned); |
| 103 |
extern void gimple_gen_ic_profiler (histogram_value, unsigned); |
| 104 |
extern void gimple_gen_ic_func_profiler (void); |
| 105 |
extern void gimple_gen_time_profiler (unsigned); |
| 106 |
extern void gimple_gen_average_profiler (histogram_value, unsigned); |
| 107 |
extern void gimple_gen_ior_profiler (histogram_value, unsigned); |
| 108 |
extern void stream_out_histogram_value (struct output_block *, histogram_value); |
| 109 |
extern void stream_in_histogram_value (class lto_input_block *, gimple *); |
| 110 |
extern struct cgraph_node* find_func_by_profile_id (int func_id); |
| 111 |
|
| 112 |
|
| 113 |
/* In profile.cc. */ |
| 114 |
extern void init_branch_prob (void); |
| 115 |
extern void branch_prob (bool); |
| 116 |
extern void read_thunk_profile (struct cgraph_node *); |
| 117 |
extern void end_branch_prob (void); |
| 118 |
|
| 119 |
/* Return true if any cfg coverage/profiling is enabled; -fprofile-arcs |
| 120 |
-fcondition-coverage -fpath-coverage. */ |
| 121 |
extern bool coverage_instrumentation_p (); |
| 122 |
|
| 123 |
#endif /* GCC_VALUE_PROF_H */ |
| 124 |
|