[pretty-ipa] Enable IPA nothrow discovery
Jan Hubicka
hubicka@ucw.cz
Tue Apr 14 14:04:00 GMT 2009
> On Tue, Apr 14, 2009 at 10:54 AM, Jan Hubicka <hubicka@ucw.cz> wrote:
> >> Patch truncated?
> >
> > Indeed it is.
> > The patch caused quite noticeable improvements on pretty-ipa tramp3d
> > tonight. Â I will first re-check that there is nothing obviously wrong.
> > I would not expect it to help that much on largely acyclic control flow
> > so either there are more cycles in tramp3d that I tought, or local pure
> > const is unnecesarily conservative or IPA pure const produce wrong code.
> > I would expect last case to show in testsuite, we have plenty of
> > throwing tests there.
>
> I suggest to make loop_nest a unsigned short and swap
> inline_failed (4 bytes(!)) and count (8 bytes) and move uid right
> after count.
Good point :). Now when inline_failed is no longer a pointer, we can
sequeeze space out there. I will do that once other cgraph changes are
merged.
Thanks,
Honza
>
> Richard.
>
>
> > Honza
> >
> > Â Â Â Â * cgraph.c (cgraph_make_edge, dump_cgraph_node, cgraph_set_call_stmt):
> > Â Â Â Â Set nothrow flag.
> > Â Â Â Â * cgraph.h (struct function): Reduce loop_nest to 30 bits; add
> > Â Â Â Â can_throw_external flag.
> > Â Â Â Â * ipa-reference.c (ipa_utils_reduced_inorder): Update call.
> > Â Â Â Â * ipa-pure-const.c (ignore_edge): New function.
> > Â Â Â Â (propagate): Compute order for NOTHROW computation; set NOTHROWs
> > Â Â Â Â only over can_throw_external edges.
> > Â Â Â Â (local_pure_const): Add nothrow flag.
> > Â Â Â Â * ipa-utils.c (searchc): Add ignore_edge callback.
> > Â Â Â Â (ipa_utils_reduced_inorder): Add ignore_edge callback.
> > Â Â Â Â * ipa-utils.h (ipa_utils_reduced_inorder): Update prototype.
> > Â Â Â Â (set_nothrow_function_flags): Update cgraph.
> > Â Â Â Â * tree-cfg.c (verify_stmt): Relax nothrow checking when in IPA mode.
> > Index: cgraph.c
> > ===================================================================
> > --- cgraph.c   (revision 146003)
> > +++ cgraph.c   (working copy)
> > @@ -639,6 +639,7 @@
> > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â htab_hash_pointer (e->call_stmt));
> > Â Â }
> > Â e->call_stmt = new_stmt;
> > + Â e->can_throw_external = stmt_can_throw_external (new_stmt);
> > Â if (e->caller->call_site_hash)
> > Â Â {
> > Â Â Â void **slot;
> > @@ -667,7 +668,6 @@
> > Â Â for (node = orig->clones; node != orig;)
> > Â Â Â {
> > Â Â Â Â struct cgraph_edge *edge = cgraph_edge (node, old_stmt);
> > -
> > Â Â Â Â if (edge)
> > Â Â Â Â Â cgraph_set_call_stmt (edge, new_stmt);
> > Â Â Â Â if (node->clones)
> > @@ -774,6 +774,7 @@
> > Â edge->caller = caller;
> > Â edge->callee = callee;
> > Â edge->call_stmt = call_stmt;
> > + Â edge->can_throw_external = stmt_can_throw_external (call_stmt);
> > Â edge->prev_caller = NULL;
> > Â edge->next_caller = callee->callers;
> > Â if (callee->callers)
> > @@ -1386,6 +1387,8 @@
> > Â Â Â Â fprintf(f, "(inlined) ");
> > Â Â Â if (edge->indirect_call)
> > Â Â Â Â fprintf(f, "(indirect) ");
> > + Â Â Â if (edge->can_throw_external)
> > + Â Â Â fprintf(f, "(can throw external) ");
> > Â Â }
> >
> >  fprintf (f, "\n  calls: ");
> > Index: cgraph.h
> > ===================================================================
> > --- cgraph.h   (revision 146003)
> > +++ cgraph.h   (working copy)
> > @@ -248,9 +248,11 @@
> > Â Â Â per function call. Â The range is 0 to CGRAPH_FREQ_MAX. Â */
> > Â int frequency;
> > Â /* Depth of loop nest, 1 means no loop nest. Â */
> > - Â unsigned int loop_nest : 31;
> > + Â unsigned int loop_nest : 30;
> > Â /* Whether this edge describes a call that was originally indirect. Â */
> > Â unsigned int indirect_call : 1;
> > + Â /* Can this call throw externally? Â */
> > + Â unsigned int can_throw_external : 1;
> > Â /* Unique id of the edge. Â */
> > Â int uid;
> > Â };
> > Index: ipa-reference.c
> > ===================================================================
> > --- ipa-reference.c   (revision 146003)
> > +++ ipa-reference.c   (working copy)
> > @@ -1020,7 +1020,7 @@
> > Â struct cgraph_node *w;
> > Â struct cgraph_node **order =
> > Â Â XCNEWVEC (struct cgraph_node *, cgraph_n_nodes);
> > - Â int order_pos = ipa_utils_reduced_inorder (order, false, true);
> > + Â int order_pos = ipa_utils_reduced_inorder (order, false, true, NULL);
> > Â int i;
> >
> > Â cgraph_remove_function_insertion_hook (function_insertion_hook_holder);
> > @@ -1031,7 +1031,7 @@
> > Â Â Â the global information. Â All the nodes within a cycle will have
> > Â Â Â the same info so we collapse cycles first. Â Then we can do the
> > Â Â Â propagation in one pass from the leaves to the roots. Â */
> > - Â order_pos = ipa_utils_reduced_inorder (order, true, true);
> > + Â order_pos = ipa_utils_reduced_inorder (order, true, true, NULL);
> > Â if (dump_file)
> > Â Â ipa_utils_print_order(dump_file, "reduced", order, order_pos);
> >
> > Index: ipa-pure-const.c
> > ===================================================================
> > --- ipa-pure-const.c   (revision 146003)
> > +++ ipa-pure-const.c   (working copy)
> > @@ -671,6 +671,12 @@
> > Â visited_nodes = NULL;
> > Â }
> >
> > +static bool
> > +ignore_edge (struct cgraph_edge *e)
> > +{
> > + Â return (!e->can_throw_external);
> > +}
> > +
> > Â /* Produce the global information by preforming a transitive closure
> > Â Â on the local information that was produced by generate_summary.
> > Â Â Note that there is no function_transform pass since this only
> > @@ -690,7 +696,7 @@
> > Â cgraph_remove_function_insertion_hook (function_insertion_hook_holder);
> > Â cgraph_remove_node_duplication_hook (node_duplication_hook_holder);
> > Â cgraph_remove_node_removal_hook (node_removal_hook_holder);
> > - Â order_pos = ipa_utils_reduced_inorder (order, true, false);
> > + Â order_pos = ipa_utils_reduced_inorder (order, true, false, NULL);
> > Â if (dump_file)
> > Â Â {
> > Â Â Â dump_cgraph (dump_file);
> > @@ -705,7 +711,6 @@
> > Â Â {
> > Â Â Â enum pure_const_state_e pure_const_state = IPA_CONST;
> > Â Â Â bool looping = false;
> > - Â Â Â bool can_throw = false;
> > Â Â Â int count = 0;
> > Â Â Â node = order[i];
> >
> > @@ -718,13 +723,10 @@
> > Â Â Â Â Â if (pure_const_state < w_l->pure_const_state)
> > Â Â Â Â Â Â pure_const_state = w_l->pure_const_state;
> >
> > - Â Â Â Â if (w_l->can_throw)
> > - Â Â Â Â Â can_throw = true;
> > Â Â Â Â Â if (w_l->looping)
> > Â Â Â Â Â Â looping = true;
> >
> > - Â Â Â Â if (pure_const_state == IPA_NEITHER
> > - Â Â Â Â Â Â && can_throw)
> > + Â Â Â Â if (pure_const_state == IPA_NEITHER)
> > Â Â Â Â Â Â break;
> >
> > Â Â Â Â Â count++;
> > @@ -741,16 +743,10 @@
> > Â Â Â Â Â Â Â Â Â funct_state y_l = get_function_state (y);
> > Â Â Â Â Â Â Â Â Â if (pure_const_state < y_l->pure_const_state)
> > Â Â Â Â Â Â Â Â Â Â pure_const_state = y_l->pure_const_state;
> > - Â Â Â Â Â Â Â Â if (pure_const_state == IPA_NEITHER
> > - Â Â Â Â Â Â Â Â Â Â && can_throw)
> > + Â Â Â Â Â Â Â Â if (pure_const_state == IPA_NEITHER)
> > Â Â Â Â Â Â Â Â Â Â break;
> > Â Â Â Â Â Â Â Â Â if (y_l->looping)
> > Â Â Â Â Â Â Â Â Â Â looping = true;
> > - Â Â Â Â Â Â Â Â if (y_l->can_throw && !TREE_NOTHROW (w->decl)
> > - Â Â Â Â Â Â Â Â Â Â /* FIXME: We should check that the throw can get external.
> > - Â Â Â Â Â Â Â Â Â Â Â Â We also should handle only loops formed by can throw external
> > - Â Â Â Â Â Â Â Â Â Â Â Â edges. Â */)
> > - Â Â Â Â Â Â Â Â Â can_throw = true;
> > Â Â Â Â Â Â Â Â }
> > Â Â Â Â Â Â }
> > Â Â Â Â Â w_info = (struct ipa_dfs_info *) w->aux;
> > @@ -800,12 +796,80 @@
> > Â Â Â Â Â Â default:
> > Â Â Â Â Â Â Â break;
> > Â Â Â Â Â Â }
> > + Â Â Â Â w_info = (struct ipa_dfs_info *) w->aux;
> > + Â Â Â Â w = w_info->next_cycle;
> > + Â Â Â }
> > + Â Â }
> > +
> > + Â /* Cleanup. */
> > + Â for (node = cgraph_nodes; node; node = node->next)
> > + Â Â {
> > + Â Â Â /* Get rid of the aux information. Â */
> > + Â Â Â if (node->aux)
> > + Â Â Â {
> > + Â Â Â Â w_info = (struct ipa_dfs_info *) node->aux;
> > + Â Â Â Â free (node->aux);
> > + Â Â Â Â node->aux = NULL;
> > + Â Â Â }
> > + Â Â }
> > + Â order_pos = ipa_utils_reduced_inorder (order, true, false, ignore_edge);
> > + Â if (dump_file)
> > + Â Â {
> > + Â Â Â dump_cgraph (dump_file);
> > + Â Â Â ipa_utils_print_order(dump_file, "reduced for nothrow", order, order_pos);
> > + Â Â }
> > + Â /* Propagate the local information thru the call graph to produce
> > + Â Â the global information. Â All the nodes within a cycle will have
> > + Â Â the same info so we collapse cycles first. Â Then we can do the
> > + Â Â propagation in one pass from the leaves to the roots. Â */
> > + Â for (i = 0; i < order_pos; i++ )
> > + Â Â {
> > + Â Â Â bool can_throw = false;
> > + Â Â Â node = order[i];
> > +
> > + Â Â Â /* Find the worst state for any node in the cycle. Â */
> > + Â Â Â w = node;
> > + Â Â Â while (w)
> > + Â Â Â {
> > + Â Â Â Â struct cgraph_edge *e;
> > + Â Â Â Â funct_state w_l = get_function_state (w);
> > +
> > + Â Â Â Â if (w_l->can_throw)
> > + Â Â Â Â Â can_throw = true;
> > +
> > + Â Â Â Â if (can_throw)
> > + Â Â Â Â Â break;
> > +
> > + Â Â Â Â for (e = w->callees; e; e = e->next_callee)
> > + Â Â Â Â Â {
> > + Â Â Â Â Â Â struct cgraph_node *y = e->callee;
> > +
> > + Â Â Â Â Â Â if (cgraph_function_body_availability (y) > AVAIL_OVERWRITABLE)
> > + Â Â Â Â Â Â Â {
> > + Â Â Â Â Â Â Â Â funct_state y_l = get_function_state (y);
> > +
> > + Â Â Â Â Â Â Â Â if (can_throw)
> > + Â Â Â Â Â Â Â Â Â break;
> > + Â Â Â Â Â Â Â Â if (y_l->can_throw && !TREE_NOTHROW (w->decl)
> > + Â Â Â Â Â Â Â Â Â Â && e->can_throw_external)
> > + Â Â Â Â Â Â Â Â Â can_throw = true;
> > + Â Â Â Â Â Â Â }
> > + Â Â Â Â Â }
> > + Â Â Â Â w_info = (struct ipa_dfs_info *) w->aux;
> > + Â Â Â Â w = w_info->next_cycle;
> > + Â Â Â }
> > +
> > + Â Â Â /* Copy back the region's pure_const_state which is shared by
> > + Â Â Â Â all nodes in the region. Â */
> > + Â Â Â w = node;
> > + Â Â Â while (w)
> > + Â Â Â {
> > Â Â Â Â Â if (!can_throw && !TREE_NOTHROW (w->decl))
> > Â Â Â Â Â Â {
> > - Â Â Â Â Â Â /* FIXME: TREE_NOTHROW is not set because passmanager will execute
> > - Â Â Â Â Â Â Â Â verify_ssa and verify_cfg on every function. Â Before fixup_cfg is done,
> > - Â Â Â Â Â Â Â Â those functions are going to have NOTHROW calls in EH regions reulting
> > - Â Â Â Â Â Â Â Â in ICE. Â */
> > + Â Â Â Â Â Â struct cgraph_edge *e;
> > + Â Â Â Â Â Â TREE_NOTHROW (w->decl) = true;
> > + Â Â Â Â Â Â for (e = w->callers; e; e = e->next_caller)
> > + Â Â Â Â Â Â Â e->can_throw_external = false;
> > Â Â Â Â Â Â Â if (dump_file)
> > Â Â Â Â Â Â Â Â fprintf (dump_file, "Function found to be nothrow: %s\n",
> > Â Â Â Â Â Â Â Â Â Â Â Â cgraph_node_name (w));
> > @@ -952,7 +1016,12 @@
> > Â Â }
> > Â if (!l->can_throw && !TREE_NOTHROW (current_function_decl))
> > Â Â {
> > - Â Â Â TREE_NOTHROW (current_function_decl) = 1;
> > + Â Â Â struct cgraph_edge *e;
> > +
> > + Â Â Â TREE_NOTHROW (current_function_decl) = true;
> > + Â Â Â for (e = cgraph_node (current_function_decl)->callers;
> > + Â Â Â Â Â e; e = e->next_caller)
> > + Â Â Â e->can_throw_external = false;
> > Â Â Â changed = true;
> > Â Â Â if (dump_file)
> > Â Â Â Â fprintf (dump_file, "Function found to be nothrow: %s\n",
> > Index: ipa-utils.c
> > ===================================================================
> > --- ipa-utils.c (revision 146003)
> > +++ ipa-utils.c (working copy)
> > @@ -81,7 +81,8 @@
> > Â Â searching from. Â */
> >
> > Â static void
> > -searchc (struct searchc_env* env, struct cgraph_node *v)
> > +searchc (struct searchc_env* env, struct cgraph_node *v,
> > + Â Â Â Â bool (*ignore_edge) (struct cgraph_edge *))
> > Â {
> > Â struct cgraph_edge *edge;
> > Â struct ipa_dfs_info *v_info = (struct ipa_dfs_info *) v->aux;
> > @@ -101,12 +102,15 @@
> > Â Â Â struct ipa_dfs_info * w_info;
> > Â Â Â struct cgraph_node *w = edge->callee;
> >
> > + Â Â Â if (ignore_edge && ignore_edge (edge))
> > + Â Â Â Â continue;
> > +
> > Â Â Â if (w->aux && cgraph_function_body_availability (edge->callee) > AVAIL_OVERWRITABLE)
> > Â Â Â Â {
> > Â Â Â Â Â w_info = (struct ipa_dfs_info *) w->aux;
> > Â Â Â Â Â if (w_info->new_node)
> > Â Â Â Â Â Â {
> > - Â Â Â Â Â Â searchc (env, w);
> > + Â Â Â Â Â Â searchc (env, w, ignore_edge);
> > Â Â Â Â Â Â Â v_info->low_link =
> > Â Â Â Â Â Â Â Â (v_info->low_link < w_info->low_link) ?
> > Â Â Â Â Â Â Â Â v_info->low_link : w_info->low_link;
> > @@ -152,7 +156,8 @@
> >
> > Â int
> > Â ipa_utils_reduced_inorder (struct cgraph_node **order,
> > - Â Â Â Â Â Â Â Â Â Â Â Â Â bool reduce, bool allow_overwritable)
> > + Â Â Â Â Â Â Â Â Â Â Â Â Â bool reduce, bool allow_overwritable,
> > + Â Â Â Â Â Â Â Â Â Â Â Â Â bool (*ignore_edge) (struct cgraph_edge *))
> > Â {
> > Â struct cgraph_node *node;
> > Â struct searchc_env env;
> > @@ -193,7 +198,7 @@
> > Â while (result)
> > Â Â {
> > Â Â Â node = (struct cgraph_node *)result->value;
> > - Â Â Â searchc (&env, node);
> > + Â Â Â searchc (&env, node, ignore_edge);
> > Â Â Â result = splay_tree_min (env.nodes_marked_new);
> > Â Â }
> > Â splay_tree_delete (env.nodes_marked_new);
> > Index: ipa-utils.h
> > ===================================================================
> > --- ipa-utils.h (revision 146003)
> > +++ ipa-utils.h (working copy)
> > @@ -39,7 +39,8 @@
> >
> >  /* In ipa-utils.c  */
> > Â void ipa_utils_print_order (FILE*, const char *, struct cgraph_node**, int);
> > -int ipa_utils_reduced_inorder (struct cgraph_node **, bool, bool);
> > +int ipa_utils_reduced_inorder (struct cgraph_node **, bool, bool,
> > + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â bool (*ignore_edge) (struct cgraph_edge *));
> > Â tree get_base_var (tree);
> >
> >
> > Index: except.c
> > ===================================================================
> > --- except.c   (revision 146003)
> > +++ except.c   (working copy)
> > @@ -3548,7 +3550,13 @@
> > Â if (crtl->nothrow
> > Â Â Â && (cgraph_function_body_availability (cgraph_node (current_function_decl))
> > Â Â Â Â Â >= AVAIL_AVAILABLE))
> > - Â Â TREE_NOTHROW (current_function_decl) = 1;
> > + Â Â {
> > + Â Â Â struct cgraph_node *node = cgraph_node (current_function_decl);
> > + Â Â Â struct cgraph_edge *e;
> > + Â Â Â for (e = node->callers; e; e = e->next_caller)
> > + Â Â Â Â e->can_throw_external = false;
> > + Â Â Â TREE_NOTHROW (current_function_decl) = 1;
> > + Â Â }
> > Â return 0;
> > Â }
> >
> > Index: tree-cfg.c
> > ===================================================================
> > --- tree-cfg.c  (revision 146003)
> > +++ tree-cfg.c  (working copy)
> > @@ -4097,7 +4097,10 @@
> > Â Â Â to match. Â */
> > Â if (lookup_stmt_eh_region (stmt) >= 0)
> > Â Â {
> > - Â Â Â if (!stmt_could_throw_p (stmt))
> > + Â Â Â /* During IPA passes, ipa-pure-const sets nothrow flags on calls
> > + Â Â Â Â and they are updated on statements only after fixup_cfg
> > + Â Â Â Â is executed at beggining of expansion stage. Â */
> > + Â Â Â if (!stmt_could_throw_p (stmt) && cgraph_state != CGRAPH_STATE_IPA_SSA)
> > Â Â Â Â {
> > Â Â Â Â Â error ("statement marked for throw, but doesn%'t");
> > Â Â Â Â Â goto fail;
> >
More information about the Gcc-patches
mailing list