21#ifndef GCC_PROFILE_COUNT_H
22#define GCC_PROFILE_COUNT_H
73#define REG_BR_PROB_BASE 10000
75#define RDIV(X,Y) (((X) + (Y) / 2) / (Y))
84#if (GCC_VERSION >= 5000)
86 if (!__builtin_mul_overflow (
a,
b, &tmp)
87 && !__builtin_add_overflow (tmp, c/2, &tmp))
98 if (
a < ((uint64_t)1 << 31)
99 &&
b < ((uint64_t)1 << 31)
100 && c < ((uint64_t)1 << 31))
102 *res = (
a *
b + (c / 2)) / c;
148 static const int n_bits = 29;
151 static const uint32_t max_probability = (uint32_t) 1 << (n_bits - 2);
152 static const uint32_t uninitialized_probability
153 = ((uint32_t) 1 << (n_bits - 1)) - 1;
165 m_val (val), m_quality (quality)
203 return guessed_always () / 2;
208 return always () - very_unlikely ();
213 return always () - unlikely ();
218 return initialized_p () && m_val != 0;
224 ret.
m_val = max_probability;
232 ret.
m_val = max_probability;
242 c.
m_val = uninitialized_probability;
250 return m_val != uninitialized_probability;
274 if (!initialized_p ())
290 ret.
m_val = ((
unsigned int)v) / 8;
298 int ret = m_val * 8 + m_quality;
310 ret.
m_val = max_probability;
330 if (other == never ())
332 if (*
this == never ())
335 return uninitialized ();
338 ret.
m_val =
MIN ((uint32_t)(m_val + other.
m_val), max_probability);
345 if (other == never ())
347 if (*
this == never ())
353 return *
this = uninitialized ();
356 m_val =
MIN ((uint32_t)(m_val + other.
m_val), max_probability);
364 if (*
this == never ()
365 || other == never ())
368 return uninitialized ();
377 if (*
this == never ()
378 || other == never ())
381 return *
this = uninitialized ();
384 m_val = m_val >= other.
m_val ? m_val - other.
m_val : 0;
392 if (*
this == never ()
393 || other == never ())
396 return uninitialized ();
398 ret.
m_val =
RDIV ((uint64_t)m_val * other.
m_val, max_probability);
405 if (*
this == never ()
406 || other == never ())
407 return *
this = never ();
409 return *
this = uninitialized ();
412 m_val =
RDIV ((uint64_t)m_val * other.
m_val, max_probability);
420 if (*
this == never ())
423 return uninitialized ();
426 if (m_val >= other.
m_val)
428 ret.
m_val = max_probability;
438 ret.
m_val =
MIN (
RDIV ((uint64_t)m_val * max_probability,
448 if (*
this == never ())
449 return *
this = never ();
451 return *
this = uninitialized ();
456 if (m_val > other.
m_val)
458 m_val = max_probability;
468 m_val =
MIN (
RDIV ((uint64_t)m_val * max_probability,
500 if (!(*
this == always ()))
501 *
this = (*
this - ret) / ret.
invert ();
507 if (*
this == uninitialized ())
509 return RDIV (val * m_val, max_probability);
515 return always() - *
this;
537 if (*
this == never ())
539 if (!initialized_p ())
540 return uninitialized ();
544 ret.
m_val =
MIN (tmp, max_probability);
553 if (*
this == never ())
558 return uninitialized ();
566 ret.
m_val =
MIN (val, max_probability);
592 if (!initialized_p ())
594 return m_val < max_probability / 100
595 || m_val > max_probability - max_probability / 100;
602 if (m_val == uninitialized_probability)
606 return m_val <= max_probability;
660 uint32_t
value ()
const {
return m_val; }
666 void dump (FILE *f)
const;
669 void dump (
char *buffer)
const;
688 sreal to_sreal ()
const;
756 static const int n_bits = 61;
757 static const uint64_t
max_count = ((uint64_t) 1 << n_bits) - 2;
759 static const uint64_t uninitialized_count = ((uint64_t) 1 << n_bits) - 1;
761#if defined (__arm__) && (__GNUC__ >= 6 && __GNUC__ <= 8)
766#define UINT64_BIT_FIELD_ALIGN __attribute__ ((aligned(8)))
768#define UINT64_BIT_FIELD_ALIGN
771#undef UINT64_BIT_FIELD_ALIGN
787 if (ipa ().nonzero_p ()
788 && !(other.
ipa () == other))
791 && !(ipa () == *
this))
794 return ipa_p () == other.
ipa_p ();
800 return from_gcov_type (0);
821 return from_gcov_type (1);
829 c.
m_val = uninitialized_count;
844 return m_val != uninitialized_count;
866 uint64_t
value ()
const {
return m_val; }
880 return !(other < *
this);
904 if (other == zero ())
906 if (*
this == zero ())
909 return uninitialized ();
913 uint64_t ret_val = m_val + other.
m_val;
921 if (other == zero ())
923 if (*
this == zero ())
929 return *
this = uninitialized ();
933 uint64_t ret_val = m_val + other.
m_val;
942 if (*
this == zero () || other == zero ())
945 return uninitialized ();
955 if (*
this == zero () || other == zero ())
958 return *
this = uninitialized ();
962 m_val = m_val >= other.
m_val ? m_val - other.
m_val : 0;
972 return m_val != uninitialized_count || m_quality ==
GUESSED_LOCAL;
981 if (*
this == zero ())
982 return !(other == zero ());
983 if (other == zero ())
986 return m_val < other.
m_val;
993 if (*
this == zero ())
995 if (other == zero ())
996 return !(*
this == zero ());
1005 return ipa ().initialized_p () && ipa ().m_val < (uint64_t) other;
1012 return ipa ().initialized_p () && ipa ().m_val > (uint64_t) other;
1019 if (*
this == zero ())
1021 if (other == zero ())
1022 return (*
this == zero ());
1024 return m_val <= other.
m_val;
1031 if (other == zero ())
1033 if (*
this == zero ())
1034 return (other == zero ());
1036 return m_val >= other.
m_val;
1043 return ipa ().initialized_p () && ipa ().m_val <= (uint64_t) other;
1050 return ipa ().initialized_p () && ipa ().m_val >= (uint64_t) other;
1080 return initialized_p () && m_val != 0;
1086 if (!initialized_p ())
1105 other = other.
ipa ();
1107 if (!initialized_p ())
1111 if (*
this == zero ())
1113 if (other == zero ())
1129 if (!initialized_p ())
1130 return uninitialized ();
1147 return uninitialized ();
1162 if (!initialized_p ())
1163 return uninitialized ();
1176 if (*
this == zero ())
1181 return uninitialized ();
1204 if (!initialized_p ())
1214 if (!initialized_p ())
1225 if (!initialized_p ())
1248 return adjusted_zero ();
1249 return uninitialized ();
1264 if (*
this == zero ()
1265 && !(overall == zero ()))
1270 if (*
this == overall && m_quality ==
PRECISE)
1275 if (overall.
m_val < m_val)
1294 if (!initialized_p ())
1299 int to_frequency (
struct function *fun)
const;
1300 int to_cgraph_frequency (
profile_count entry_bb_count)
const;
1304 void dump (FILE *f,
struct function *fun =
NULL)
const;
1307 void debug ()
const;
gcov_type apply_scale(gcov_type freq, gcov_type scale)
Definition basic-block.h:578
Definition profile-count.h:147
enum profile_quality quality() const
Definition profile-count.h:663
profile_probability sqrt() const
Definition profile-count.cc:469
profile_probability()
Definition profile-count.h:160
static const int n_bits
Definition profile-count.h:148
static profile_probability unlikely()
Definition profile-count.h:193
bool operator>(const profile_probability &other) const
Definition profile-count.h:616
profile_probability operator+(const profile_probability &other) const
Definition profile-count.h:328
bool reliable_p() const
Definition profile-count.h:254
profile_probability apply_scale(int64_t num, int64_t den) const
Definition profile-count.h:535
profile_probability split(const profile_probability &cprob)
Definition profile-count.h:492
static const uint32_t max_probability
Definition profile-count.h:151
profile_probability & operator/=(const profile_probability &other)
Definition profile-count.h:446
profile_probability operator*(const profile_probability &other) const
Definition profile-count.h:390
gcov_type apply(gcov_type val) const
Definition profile-count.h:505
enum profile_quality m_quality
Definition profile-count.h:156
profile_probability apply_scale(profile_probability num, profile_probability den) const
Definition profile-count.h:550
static profile_probability uninitialized()
Definition profile-count.h:239
static profile_probability very_unlikely()
Definition profile-count.h:185
profile_probability combine_with_count(profile_count count1, profile_probability other, profile_count count2) const
Definition profile-count.cc:437
uint32_t m_val
Definition profile-count.h:155
int to_reg_br_prob_base() const
Definition profile-count.h:280
static profile_probability guessed_never()
Definition profile-count.h:177
void debug() const
Definition profile-count.cc:202
void dump(FILE *f) const
Definition profile-count.cc:192
bool operator==(const profile_probability &other) const
Definition profile-count.h:323
bool initialized_p() const
Definition profile-count.h:248
profile_probability operator/(const profile_probability &other) const
Definition profile-count.h:418
profile_probability(uint32_t val, profile_quality quality)
Definition profile-count.h:164
profile_probability invert() const
Definition profile-count.h:513
sreal to_sreal() const
Definition profile-count.cc:460
static const uint32_t uninitialized_probability
Definition profile-count.h:153
uint32_t value() const
Definition profile-count.h:660
bool probably_reliable_p() const
Definition profile-count.h:588
static profile_probability from_reg_br_prob_base(int v)
Definition profile-count.h:261
bool differs_from_p(profile_probability other) const
Definition profile-count.cc:211
bool operator<(const profile_probability &other) const
Definition profile-count.h:611
bool operator<=(const profile_probability &other) const
Definition profile-count.h:621
int to_reg_br_prob_note() const
Definition profile-count.h:295
static profile_probability stream_in(class lto_input_block *)
Definition profile-count.cc:238
profile_probability afdo() const
Definition profile-count.h:527
profile_probability & operator+=(const profile_probability &other)
Definition profile-count.h:343
profile_probability adjusted() const
Definition profile-count.h:271
profile_probability operator-(const profile_probability &other) const
Definition profile-count.h:362
profile_probability pow(int) const
Definition profile-count.cc:499
profile_probability & operator*=(const profile_probability &other)
Definition profile-count.h:403
profile_probability guessed() const
Definition profile-count.h:519
profile_probability & operator-=(const profile_probability &other)
Definition profile-count.h:375
static profile_probability from_reg_br_prob_note(int v)
Definition profile-count.h:287
static profile_probability very_likely()
Definition profile-count.h:206
bool verify() const
Definition profile-count.h:599
static profile_probability probability_in_gcov_type(gcov_type val1, gcov_type val2)
Definition profile-count.h:305
static profile_probability likely()
Definition profile-count.h:211
static profile_probability guessed_always()
Definition profile-count.h:221
static profile_probability always()
Definition profile-count.h:229
bool nonzero_p() const
Definition profile-count.h:216
static profile_probability never()
Definition profile-count.h:169
static profile_probability even()
Definition profile-count.h:201
void stream_out(struct output_block *)
Definition profile-count.cc:249
bool operator>=(const profile_probability &other) const
Definition profile-count.h:626
bool differs_lot_from_p(profile_probability other) const
Definition profile-count.cc:227
bool debug
Definition collect-utils.cc:34
#define GTY(x)
Definition coretypes.h:41
int64_t gcov_type
Definition coretypes.h:46
bool operator==(const nowarn_spec_t &lhs, const nowarn_spec_t &rhs)
Definition diagnostic-spec.h:131
double pow(double, double)
bool operator<(const pattern_pos &e1, const pattern_pos &e2)
Definition genrecog.cc:3893
static profile_count max_count
Definition ipa-inline.cc:176
poly_int< N, C > r
Definition poly-int.h:774
Ca const poly_int< N, Cb > & b
Definition poly-int.h:771
Ca & a
Definition poly-int.h:770
profile_quality
Definition profile-count.h:30
@ ADJUSTED
Definition profile-count.h:61
@ GUESSED_LOCAL
Definition profile-count.h:38
@ UNINITIALIZED_PROFILE
Definition profile-count.h:32
@ GUESSED_GLOBAL0_ADJUSTED
Definition profile-count.h:46
@ GUESSED_GLOBAL0
Definition profile-count.h:43
@ AFDO
Definition profile-count.h:56
@ PRECISE
Definition profile-count.h:65
@ GUESSED
Definition profile-count.h:53
#define RDIV(X, Y)
Definition profile-count.h:75
#define REG_BR_PROB_BASE
Definition profile-count.h:73
bool parse_profile_quality(const char *value, profile_quality *quality)
Definition profile-count.cc:61
#define UINT64_BIT_FIELD_ALIGN
Definition profile-count.h:768
bool slow_safe_scale_64bit(uint64_t a, uint64_t b, uint64_t c, uint64_t *res)
Definition profile-count.cc:267
const char * profile_quality_as_string(enum profile_quality)
Definition profile-count.cc:53
bool safe_scale_64bit(uint64_t a, uint64_t b, uint64_t c, uint64_t *res)
Definition profile-count.h:82
sreal & operator/=(sreal &a, const sreal &b)
Definition sreal.h:157
bool operator<=(const sreal &a, const sreal &b)
Definition sreal.h:177
sreal & operator*=(sreal &a, const sreal &b)
Definition sreal.h:162
bool operator>(const sreal &a, const sreal &b)
Definition sreal.h:172
sreal & operator-=(sreal &a, const sreal &b)
Definition sreal.h:152
sreal & operator+=(sreal &a, const sreal &b)
Definition sreal.h:147
bool operator>=(const sreal &a, const sreal &b)
Definition sreal.h:182
Definition function.h:249
Definition lto-streamer.h:622
Definition lto-streamer.h:698
Definition profile-count.h:750
profile_count combine_with_ipa_count(profile_count ipa)
Definition profile-count.cc:383
profile_count apply_probability(profile_probability prob) const
Definition profile-count.h:1140
uint64_t value() const
Definition profile-count.h:866
sreal to_sreal_scale(profile_count in, bool *known=NULL) const
Definition profile-count.cc:323
static const uint64_t uninitialized_count
Definition profile-count.h:759
profile_count force_nonzero() const
Definition profile-count.h:1084
gcov_type to_gcov_type() const
Definition profile-count.h:835
bool operator<(const profile_count &other) const
Definition profile-count.h:977
profile_count global0adjusted() const
Definition profile-count.h:1222
static const int n_bits
Definition profile-count.h:756
profile_count max(profile_count other) const
Definition profile-count.h:1097
uint64_t UINT64_BIT_FIELD_ALIGN m_val
Definition profile-count.h:770
bool operator<=(const profile_count &other) const
Definition profile-count.h:1015
static profile_count stream_in(class lto_input_block *)
Definition profile-count.cc:135
static const uint64_t max_count
Definition profile-count.h:757
profile_count operator/(int64_t den) const
Definition profile-count.h:1064
profile_count combine_with_ipa_count_within(profile_count ipa, profile_count ipa2)
Definition profile-count.cc:400
profile_count operator+(const profile_count &other) const
Definition profile-count.h:902
bool initialized_p() const
Definition profile-count.h:842
enum profile_quality quality() const
Definition profile-count.h:869
void dump(FILE *f, struct function *fun=NULL) const
Definition profile-count.cc:90
int to_cgraph_frequency(profile_count entry_bb_count) const
Definition profile-count.cc:305
static profile_count uninitialized()
Definition profile-count.h:826
bool very_large_p()
Definition profile-count.h:1292
bool precise_p() const
Definition profile-count.h:860
static profile_count one()
Definition profile-count.h:819
enum profile_quality m_quality
Definition profile-count.h:772
static void adjust_for_ipa_scaling(profile_count *num, profile_count *den)
Definition profile-count.cc:358
static profile_count zero()
Definition profile-count.h:798
profile_count & operator+=(const profile_count &other)
Definition profile-count.h:919
bool reliable_p() const
Definition profile-count.h:848
profile_count guessed_local() const
Definition profile-count.h:1201
bool operator>(const profile_count &other) const
Definition profile-count.h:989
profile_count operator*=(int64_t num)
Definition profile-count.h:1058
profile_count apply_scale(profile_count num, profile_count den) const
Definition profile-count.h:1174
profile_count operator*(int64_t num) const
Definition profile-count.h:1053
bool ok_for_merging(profile_count other) const
Definition profile-count.h:875
profile_count merge(profile_count other) const
Definition profile-count.h:885
static profile_count guessed_zero()
Definition profile-count.h:811
profile_count ipa() const
Definition profile-count.h:1241
static profile_count from_gcov_type(gcov_type v, profile_quality quality=PRECISE)
Definition profile-count.cc:419
bool nonzero_p() const
Definition profile-count.h:1078
bool compatible_p(const profile_count other) const
Definition profile-count.h:778
bool differs_from_p(profile_count other) const
Definition profile-count.cc:117
bool operator==(const profile_count &other) const
Definition profile-count.h:897
bool operator>=(const profile_count &other) const
Definition profile-count.h:1027
profile_probability probability_in(const profile_count overall) const
Definition profile-count.h:1262
static profile_count adjusted_zero()
Definition profile-count.h:803
void stream_out(struct output_block *)
Definition profile-count.cc:146
profile_count global0() const
Definition profile-count.h:1211
profile_count apply_scale(int64_t num, int64_t den) const
Definition profile-count.h:1158
profile_count operator-(const profile_count &other) const
Definition profile-count.h:940
profile_count afdo() const
Definition profile-count.h:1253
profile_count & operator-=(const profile_count &other)
Definition profile-count.h:953
void debug() const
Definition profile-count.cc:108
int to_frequency(struct function *fun) const
Definition profile-count.cc:286
bool ipa_p() const
Definition profile-count.h:854
profile_count guessed() const
Definition profile-count.h:1232
bool verify() const
Definition profile-count.h:969
profile_count operator/=(int64_t den)
Definition profile-count.h:1069
profile_count apply_probability(int prob) const
Definition profile-count.h:1124
#define NULL
Definition system.h:50
#define MIN(X, Y)
Definition system.h:392
#define gcc_checking_assert(EXPR)
Definition system.h:828
#define MAX(X, Y)
Definition system.h:393
comp_cost operator+(comp_cost cost1, comp_cost cost2)
Definition tree-ssa-loop-ivopts.cc:270
comp_cost operator-(comp_cost cost1, comp_cost cost2)
Definition tree-ssa-loop-ivopts.cc:283