This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Merge ipa-profile pass from pretty-ipa


On Tue, Apr 27, 2010 at 3:09 PM, Jan Hubicka <hubicka@ucw.cz> wrote:
> Hi,
> this patch adds simple pass propagating node frequencies across callgraph. ?The
> pass is able to determine that functions called only from called once that are
> not called inside loop are called once and similar simple analysis. ?The
> savings are pretty small (about 1-4% on usual spec2000 benchmark, we get lucky
> in some cases but those tends to be the simple benchmarks, like gzip), but the
> pass is easy too and excercise the profile hot/cold infrastructure more
> On SPEC2000 GCC in whole program mode this affects about 300 functions.
>
> Bootstrapped/regtested x86_64-linux, will commit it later today if there
> are no complains.

Comments below (you need approval for this anyway).

> 2010-04-18 Jan Hubicka ?<jh@suse.cz>
>
> ? ? ? ?* doc/invoke.texi (-fipa-profile): Document.
> ? ? ? ?* opts.c (decode_options): Enable ipa-profile at -O1.
> ? ? ? ?* timevar.def (TV_IPA_PROFILE): Define.
> ? ? ? ?* common.opt (fipa-profile): Add.
> ? ? ? ?* cgraph.c (cgraph_clone_node): Set local flag and clear vtable method flag
> ? ? ? ?for clones.
> ? ? ? ?(cgraph_propagate_frequency): Handle only local ones.
> ? ? ? ?* tree-pass.h (pass_ipa_profile): Declare.
> ? ? ? ?* ipa-profile.c (gate_profile): Use flag_ipa_profile.
> ? ? ? ?(pass_ipa_profile): Use TV_IPA_PROFILE.
> ? ? ? ?* ipa.c (ipa_profile): New function.
> ? ? ? ?(gate_ipa_profile): Likewise.
> ? ? ? ?(pass_ipa_profile): New global variable.
> ? ? ? ?* passes.c (pass_ipa_profile): New.
> Index: doc/invoke.texi
> ===================================================================
> --- doc/invoke.texi ? ? (revision 158772)
> +++ doc/invoke.texi ? ? (working copy)
> @@ -344,7 +344,7 @@ Objective-C and Objective-C++ Dialects}.
> ?-fgcse-sm -fif-conversion -fif-conversion2 -findirect-inlining @gol
> ?-finline-functions -finline-functions-called-once -finline-limit=@var{n} @gol
> ?-finline-small-functions -fipa-cp -fipa-cp-clone -fipa-matrix-reorg -fipa-pta @gol
> --fipa-pure-const -fipa-reference -fipa-struct-reorg @gol
> +-fipa-profile -fipa-pure-const -fipa-reference -fipa-struct-reorg @gol
> ?-fipa-type-escape -fira-algorithm=@var{algorithm} @gol
> ?-fira-region=@var{region} -fira-coalesce @gol
> ?-fira-loop-pressure -fno-ira-share-save-slots @gol
> @@ -6601,6 +6601,17 @@ Perform interprocedural pointer analysis
> ?and reference analysis. ?This option can cause excessive memory and
> ?compile-time usage on large compilation units. ?It is not enabled by
> ?default at any optimization level.
> +Enabled by default at @option{-O} and higher.

Err - that's not true ;)

> +
> +@item -fipa-profile
> +@opindex fipa-profile
> +Perform interprocedural profile propagation. ?The functions called only from
> +cold functions are marked as cold. Also functions executed once (such as
> +@samp{cold}, @samp{noreturn}, static constructors or destructors)

use @code

are identified. Cold
> +functions and loop less parts of functions executed once are then optimized for
> +size.
> +
> +This flag is enabled by default at @option{-O1}.

Then you need to update the list of flags enabled at -O1 somewhere
up this file.

Ok with that changes.

Thanks,
Richard.

> ?@item -fipa-cp
> ?@opindex fipa-cp
> Index: cgraph.c
> ===================================================================
> --- cgraph.c ? ?(revision 158775)
> +++ cgraph.c ? ?(working copy)
> @@ -1897,6 +1897,8 @@ cgraph_clone_node (struct cgraph_node *n
> ? new_node->analyzed = n->analyzed;
> ? new_node->local = n->local;
> ? new_node->local.externally_visible = false;
> + ?new_node->local.local = true;
> + ?new_node->local.vtable_method = false;
> ? new_node->global = n->global;
> ? new_node->rtl = n->rtl;
> ? new_node->count = count;
> @@ -2314,7 +2316,7 @@ cgraph_propagate_frequency (struct cgrap
> ?{
> ? bool maybe_unlikely_executed = true, maybe_executed_once = true;
> ? struct cgraph_edge *edge;
> - ?if (node->needed || node->local.externally_visible)
> + ?if (!node->local.local)
> ? ? return false;
> ? gcc_assert (node->analyzed);
> ? if (node->frequency == NODE_FREQUENCY_HOT)
> Index: tree-pass.h
> ===================================================================
> --- tree-pass.h (revision 158772)
> +++ tree-pass.h (working copy)
> @@ -459,6 +459,7 @@ extern struct simple_ipa_opt_pass pass_i
> ?extern struct simple_ipa_opt_pass pass_ipa_struct_reorg;
> ?extern struct ipa_opt_pass_d pass_ipa_lto_wpa_fixup;
> ?extern struct ipa_opt_pass_d pass_ipa_lto_finish_out;
> +extern struct ipa_opt_pass_d pass_ipa_profile;
>
> ?extern struct gimple_opt_pass pass_all_optimizations;
> ?extern struct gimple_opt_pass pass_cleanup_cfg_post_optimizing;
> Index: opts.c
> ===================================================================
> --- opts.c ? ? ?(revision 158772)
> +++ opts.c ? ? ?(working copy)
> @@ -858,6 +858,7 @@ decode_options (unsigned int argc, const
> ? flag_if_conversion2 = opt1;
> ? flag_ipa_pure_const = opt1;
> ? flag_ipa_reference = opt1;
> + ?flag_ipa_profile = opt1;
> ? flag_merge_constants = opt1;
> ? flag_split_wide_types = opt1;
> ? flag_tree_ccp = opt1;
> Index: timevar.def
> ===================================================================
> --- timevar.def (revision 158772)
> +++ timevar.def (working copy)
> @@ -59,6 +59,7 @@ DEFTIMEVAR (TV_WHOPR_WPA_IO ? ? ? ? ?, "
> ?DEFTIMEVAR (TV_WHOPR_LTRANS ? ? ? ? ?, "whopr ltrans")
> ?DEFTIMEVAR (TV_WHOPR_WPA_LTRANS_EXEC , "whopr wpa->ltrans")
> ?DEFTIMEVAR (TV_IPA_REFERENCE ? ? ? ? , "ipa reference")
> +DEFTIMEVAR (TV_IPA_PROFILE ? ? ? ? ? , "ipa profile")
> ?DEFTIMEVAR (TV_IPA_PURE_CONST ? ? ? ?, "ipa pure const")
> ?DEFTIMEVAR (TV_IPA_TYPE_ESCAPE ? ? ? , "ipa type escape")
> ?DEFTIMEVAR (TV_IPA_PTA ? ? ? ? ? ? ? , "ipa points-to")
> Index: ipa.c
> ===================================================================
> --- ipa.c ? ? ? (revision 158772)
> +++ ipa.c ? ? ? (working copy)
> @@ -741,3 +741,84 @@ debug_cgraph_node_set (cgraph_node_set s
> ? dump_cgraph_node_set (stderr, set);
> ?}
>
> +/* Simple ipa profile pass propagating frequencies across the callgraph. ?*/
> +
> +static unsigned int
> +ipa_profile (void)
> +{
> + ?struct cgraph_node **order = XCNEWVEC (struct cgraph_node *, cgraph_n_nodes);
> + ?struct cgraph_edge *e;
> + ?int order_pos;
> + ?bool something_changed = false;
> + ?int i;
> +
> + ?order_pos = cgraph_postorder (order);
> + ?for (i = order_pos - 1; i >= 0; i--)
> + ? ?{
> + ? ? ?if (order[i]->local.local && cgraph_propagate_frequency (order[i]))
> + ? ? ? {
> + ? ? ? ? for (e = order[i]->callees; e; e = e->next_callee)
> + ? ? ? ? ? if (e->callee->local.local && !e->callee->aux)
> + ? ? ? ? ? ? {
> + ? ? ? ? ? ? ? something_changed = true;
> + ? ? ? ? ? ? ? e->callee->aux = (void *)1;
> + ? ? ? ? ? ? }
> + ? ? ? }
> + ? ? ?order[i]->aux = NULL;
> + ? ?}
> +
> + ?while (something_changed)
> + ? ?{
> + ? ? ?something_changed = false;
> + ? ? ?for (i = order_pos - 1; i >= 0; i--)
> + ? ? ? {
> + ? ? ? ? if (order[i]->aux && cgraph_propagate_frequency (order[i]))
> + ? ? ? ? ? {
> + ? ? ? ? ? ? for (e = order[i]->callees; e; e = e->next_callee)
> + ? ? ? ? ? ? ? if (e->callee->local.local && !e->callee->aux)
> + ? ? ? ? ? ? ? ? {
> + ? ? ? ? ? ? ? ? ? something_changed = true;
> + ? ? ? ? ? ? ? ? ? e->callee->aux = (void *)1;
> + ? ? ? ? ? ? ? ? }
> + ? ? ? ? ? }
> + ? ? ? ? order[i]->aux = NULL;
> + ? ? ? }
> + ? ?}
> + ?free (order);
> + ?return 0;
> +}
> +
> +static bool
> +gate_ipa_profile (void)
> +{
> + ?return flag_ipa_profile;
> +}
> +
> +struct ipa_opt_pass_d pass_ipa_profile =
> +{
> + {
> + ?IPA_PASS,
> + ?"ipa-profile", ? ? ? ? ? ? ? ? ? ? ? /* name */
> + ?gate_ipa_profile, ? ? ? ? ? ? ? ? ? ?/* gate */
> + ?ipa_profile, ? ? ? ? ? ? ? ? ? ? ? ? /* execute */
> + ?NULL, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?/* sub */
> + ?NULL, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?/* next */
> + ?0, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* static_pass_number */
> + ?TV_IPA_PROFILE, ? ? ? ? ? ? ? ? ? ? ?/* tv_id */
> + ?0, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* properties_required */
> + ?0, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* properties_provided */
> + ?0, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* properties_destroyed */
> + ?0, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* todo_flags_start */
> + ?0 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* todo_flags_finish */
> + },
> + NULL, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* generate_summary */
> + NULL, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* write_summary */
> + NULL, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* read_summary */
> + NULL, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* write_optimization_summary */
> + NULL, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* read_optimization_summary */
> + NULL, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* stmt_fixup */
> + 0, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?/* TODOs */
> + NULL, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* function_transform */
> + NULL ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?/* variable_transform */
> +};
> Index: common.opt
> ===================================================================
> --- common.opt ?(revision 158772)
> +++ common.opt ?(working copy)
> @@ -693,14 +693,18 @@ fipa-cp-clone
> ?Common Report Var(flag_ipa_cp_clone) Optimization
> ?Perform cloning to make Interprocedural constant propagation stronger
>
> -fipa-pure-const
> -Common Report Var(flag_ipa_pure_const) Init(0) Optimization
> -Discover pure and const functions
> +fipa-profile
> +Common Report Var(flag_ipa_profile) Init(0) Optimization
> +Perform interprocedural profile propagation
>
> ?fipa-pta
> ?Common Report Var(flag_ipa_pta) Init(0) Optimization
> ?Perform interprocedural points-to analysis
>
> +fipa-pure-const
> +Common Report Var(flag_ipa_pure_const) Init(0) Optimization
> +Discover pure and const functions
> +
> ?fipa-reference
> ?Common Report Var(flag_ipa_reference) Init(0) Optimization
> ?Discover readonly and non addressable static variables
> Index: passes.c
> ===================================================================
> --- passes.c ? ?(revision 158772)
> +++ passes.c ? ?(working copy)
> @@ -803,6 +803,7 @@ init_optimization_passes (void)
>
> ? p = &all_regular_ipa_passes;
> ? NEXT_PASS (pass_ipa_whole_program_visibility);
> + ?NEXT_PASS (pass_ipa_profile);
> ? NEXT_PASS (pass_ipa_cp);
> ? NEXT_PASS (pass_ipa_inline);
> ? NEXT_PASS (pass_ipa_reference);
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]