{
profile_count cnt = bb->count;
bbs.safe_push (bb);
- max_count = max_count.max (bb->count);
+ max_count = profile_count::max_prefer_initialized (max_count, cnt);
if (afdo_set_bb_count (bb, zero_bbs))
{
std::swap (cnt, bb->count);
- max_count_in_fn = max_count_in_fn.max (cnt);
+ max_count_in_fn
+ = profile_count::max_prefer_initialized (max_count_in_fn, cnt);
add_scale (&scales, cnt, bb->count);
}
}
if (is_bb_annotated (seed_bb, *annotated_bb))
{
component[seed_bb->index] = 1;
- max_count_in_fn = max_count_in_fn.max (seed_bb->count);
+ max_count_in_fn
+ = profile_count::max_prefer_initialized (max_count_in_fn, seed_bb->count);
}
else
component[seed_bb->index] = 0;
basic_block b = stack.pop ();
bbs.quick_push (b);
- max_count = max_count.max (b->count);
+ max_count = profile_count::max_prefer_initialized (max_count, b->count);
for (edge e: b->preds)
if (!component[e->src->index])
/* Since profile_count::operator< does not establish a strict weak order
in presence of uninitialized counts, use 'max': this makes them appear
as if having execution frequency less than any initialized count. */
- profile_count m = c1.max (c2);
- return (m == c2) - (m == c1);
+ gcov_type gc1 = c1.initialized_p () ? c1.to_gcov_type () : 0;
+ gcov_type gc2 = c2.initialized_p () ? c2.to_gcov_type () : 0;
+ gcov_type m = MAX (gc1, gc2);
+ return (m == gc1) - (m == gc2);
}
/* Reorder basic blocks using the "simple" algorithm. This tries to
else if (a->count.quality () < b->count.quality ())
a->count = b->count;
else if (a->count.quality () == b->count.quality ())
- a->count = a->count.max (b->count);
+ a->count = profile_count::max_prefer_initialized (a->count, b->count);
cfg_hooks->merge_blocks (a, b);
/* Lookup the most frequent update of the value and believe that
it dominates all the other; precise analysis here is difficult. */
EXECUTE_IF_SET_IN_BITMAP (info.bb_set, 0, index, bi)
- max = max.max (BASIC_BLOCK_FOR_FN (cfun, index)->count);
+ max = profile_count::max_prefer_initialized
+ (max, BASIC_BLOCK_FOR_FN (cfun, index)->count);
if (dump_file)
{
fprintf (dump_file, " Set with count ");
FOR_ALL_BB_FN (bb, cfun)
{
bb->count = bb->count.apply_scale (num, den);
- cfun->cfg->count_max = cfun->cfg->count_max.max (bb->count);
+ cfun->cfg->count_max = profile_count::max_prefer_initialized
+ (cfun->cfg->count_max, bb->count);
}
ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = node->count;
}
basic_block bb;
FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)
- true_count_max = true_count_max.max (bb->count);
+ true_count_max = profile_count::max_prefer_initialized (true_count_max, bb->count);
cfun->cfg->count_max = true_count_max;
executed, then preserve this info. */
if (!(bb->count == profile_count::zero ()))
bb->count = count.guessed_local ().combine_with_ipa_count (ipa_count);
- cfun->cfg->count_max = cfun->cfg->count_max.max (bb->count);
+ cfun->cfg->count_max
+ = profile_count::max_prefer_initialized (cfun->cfg->count_max,
+ bb->count);
}
free_aux_for_blocks ();
cfun->cfg->count_max = profile_count::uninitialized ();
FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)
{
- cfun->cfg->count_max = cfun->cfg->count_max.max (bb->count);
+ cfun->cfg->count_max
+ = profile_count::max_prefer_initialized (cfun->cfg->count_max,
+ bb->count);
if (bb->count.nonzero_p () && bb->count.quality () >= AFDO)
feedback_found = true;
/* Uninitialized count may be result of inlining or an omision in an
/* Make counter forcibly nonzero. */
profile_count force_nonzero () const;
- profile_count max (profile_count other) const
- {
- profile_count val = *this;
- /* Always prefer nonzero IPA counts over local counts. */
- if (ipa ().nonzero_p () || other.ipa ().nonzero_p ())
- {
- val = ipa ();
- other = other.ipa ();
- }
- if (!initialized_p ())
- return other;
- if (!other.initialized_p ())
- return *this;
- if (*this == zero ())
- return other;
- if (other == zero ())
- return *this;
- gcc_checking_assert (compatible_p (other));
- if (val.m_val < other.m_val || (m_val == other.m_val
- && val.m_quality < other.m_quality))
- return other;
- return *this;
- }
+ /* Return maximum of A and B. If one of values is uninitialized return the
+ other. */
+
+ static profile_count
+ max_prefer_initialized (const profile_count a, const profile_count b)
+ {
+ if (!a.initialized_p ())
+ return b;
+ if (!b.initialized_p ())
+ return a;
+ profile_count ret;
+ gcc_checking_assert (a.compatible_p (b));
+ ret.m_val = MAX (a.m_val, b.m_val);
+ ret.m_quality = MIN (a.m_quality, b.m_quality);
+ return ret;
+ }
/* PROB is a probability in scale 0...REG_BR_PROB_BASE. Scale counter
accordingly. */
tree rhs = gimple_cond_rhs (stmt);
enum tree_code code = gimple_cond_code (stmt);
condition = build2 (code, boolean_type_node, lhs, rhs);
- count = EDGE_SUCC (bb, 0)->count ().max (EDGE_SUCC (bb, 1)->count ());
+ count = profile_count::max_prefer_initialized (EDGE_SUCC (bb, 0)->count (),
+ EDGE_SUCC (bb, 1)->count ());
if (irange::supports_p (TREE_TYPE (lhs)))
{
auto range_op = range_op_handler (code);