Turn TODO_rebuild_frequencies to a pass
commitaa6741ef2e0c312af51825f6411380fe160a8222
authorJan Hubicka <jh@suse.cz>
Fri, 14 Jul 2023 15:14:15 +0000 (14 17:14 +0200)
committerJan Hubicka <jh@suse.cz>
Fri, 14 Jul 2023 15:14:15 +0000 (14 17:14 +0200)
tree69463ab8f0068daa77098600efe986020976aa3a
parent0d2673e995f0dd69f406a34d2e87d2a25cf3c285
Turn TODO_rebuild_frequencies to a pass

Currently we rebiuild profile_counts from profile_probability after inlining,
because there is a chance that producing large loop nests may get unrealistically
large profile_count values.  This is much less of concern when we switched to
new profile_count representation while back.

This propagation can also compensate for profile inconsistencies caused by
optimization passes.  Since inliner is followed by basic cleanup passes that
does not use profile, we get more realistic profile by delaying the recomputation
after basic optimizations exposed by inlininig are finished.

This does not fit into TODO machinery, so I turn rebuilding into stand alone
pass and schedule it before first consumer of profile in the optimization
queue.

I also added logic that avoids repropagating when CFG is good and not too close
to overflow.  Propagating visits very basic block loop_depth times, so it is
not linear and avoiding it may help a bit.

On tramp3d we get 14 functions repropagated and 916 are OK.  The repropagated
functions are RB tree ones where we produce crazy loop nests by recurisve inlining.
This is something to fix independently.

gcc/ChangeLog:

* passes.cc (execute_function_todo): Remove
TODO_rebuild_frequencies
* passes.def: Add rebuild_frequencies pass.
* predict.cc (estimate_bb_frequencies): Drop
force parameter.
(tree_estimate_probability): Update call of
estimate_bb_frequencies.
(rebuild_frequencies): Turn into a pass; verify CFG profile consistency
first and do not rebuild if not necessary.
(class pass_rebuild_frequencies): New.
(make_pass_rebuild_frequencies): New.
* profile-count.h: Add profile_count::very_large_p.
* tree-inline.cc (optimize_inline_calls): Do not return
TODO_rebuild_frequencies
* tree-pass.h (TODO_rebuild_frequencies): Remove.
(make_pass_rebuild_frequencies): Declare.
gcc/passes.cc
gcc/passes.def
gcc/predict.cc
gcc/profile-count.h
gcc/tree-inline.cc
gcc/tree-pass.h