annotated->insert (bb);
}
-/* Update profile_count by known autofdo count. */
-void
+/* Update COUNT by known autofdo count C. */
+static void
update_count_by_afdo_count (profile_count *count, gcov_type c)
{
if (c)
*count = profile_count::zero ().afdo ();
}
+/* Update COUNT by known autofdo count C. */
+static void
+update_count_by_afdo_count (profile_count *count, profile_count c)
+{
+ if (c.nonzero_p ())
+ *count = c;
+ /* In case we have guessed profile which is already zero, preserve
+ quality info. */
+ else if (count->nonzero_p ()
+ || count->quality () < c.quality ())
+ *count = c;
+}
+
/* For a given BB, set its execution count. Attach value profile if a stmt
is not in PROMOTED, because we only want to promote an indirect call once.
Return TRUE if BB is annotated. */
bb1->count.dump (dump_file);
fprintf (dump_file, "\n");
}
- bb->count = bb1->count;
+ update_count_by_afdo_count (&bb->count, bb1->count);
set_bb_annotated (bb, annotated_bb);
}
}
bb1->count.dump (dump_file);
fprintf (dump_file, "\n");
}
- bb->count = bb1->count;
+ update_count_by_afdo_count (&bb->count, bb1->count);
set_bb_annotated (bb, annotated_bb);
}
}
total_known_count.dump (dump_file);
fprintf (dump_file, "\n");
}
- bb->count = total_known_count;
+ update_count_by_afdo_count (&bb->count, total_known_count);
set_bb_annotated (bb, annotated_bb);
changed = true;
}
}
else if (num_unknown_edges > 1
&& is_bb_annotated (bb, *annotated_bb)
- && total_known_count >= bb->count)
+ && (total_known_count >= bb->count || !bb->count.nonzero_p ()))
{
FOR_EACH_EDGE (e, ei, is_succ ? bb->succs : bb->preds)
{
if (!is_bb_annotated (bb, *annotated_bb)
&& is_bb_annotated ((basic_block)bb->aux, *annotated_bb))
{
- bb->count = ((basic_block)bb->aux)->count;
+ update_count_by_afdo_count (&bb->count, ((basic_block)bb->aux)->count);
set_bb_annotated (bb, annotated_bb);
if (dump_file)
{
FOR_EACH_BB_FN (bb, cfun)
if (is_bb_annotated (bb, *annotated_bb))
{
- bool all_known = false;
+ bool all_known = true;
profile_count total_count = profile_count::zero ().afdo ();
FOR_EACH_EDGE (e, ei, bb->succs)
still propagate the rest. */
if (e->probability.nonzero_p ())
{
- all_known = true;
+ all_known = false;
break;
}
}
set_bb_annotated (bb, &annotated_bb);
}
}
+ /* We try to preserve static profile for BBs with 0
+ afdo samples, but if even static profile agrees with 0,
+ consider it final so propagation works better. */
+ for (basic_block bb : zero_bbs)
+ if (bb->count.nonzero_p ())
+ {
+ update_count_by_afdo_count (&bb->count, 0);
+ set_bb_annotated (bb, &annotated_bb);
+ if (dump_file)
+ {
+ fprintf (dump_file, " Annotating bb %i with count ", bb->index);
+ bb->count.dump (dump_file);
+ fprintf (dump_file,
+ " (has 0 count in both static and afdo profile)\n");
+ }
+ }
/* Exit without clobbering static profile if there was no
non-zero count. */
if (!profile_found)