This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix ipa-pure-const with same_body aliases (take 2)
Hi!
On Mon, Dec 14, 2009 at 12:56:54PM +0100, Richard Guenther wrote:
> Hm, indeed not very much prettier. I'll let Honza break the tie here
> (I'm ok with either variant, some people might argue abstraction is
> always better - I'm not so strict here).
Based on IRC feedback from Honza, here is what I'm bootstrapping/regtesting
ATM:
2009-12-14 Jakub Jelinek <jakub@redhat.com>
* cgraph.h (cgraph_set_nothrow_flag, cgraph_set_readonly_flag,
cgraph_set_pure_flag, cgraph_set_looping_const_or_pure_flag): New
prototypes.
* cgraph.c (cgraph_set_nothrow_flag, cgraph_set_readonly_flag,
cgraph_set_pure_flag, cgraph_set_looping_const_or_pure_flag): New
functions.
* except.h (set_nothrow_function_flags): Remove prototype.
* except.c (set_nothrow_function_flags): Use cgraph_set_nothrow_flag.
Make static.
* ipa-pure-const.c (propagate): Use cgraph_set_nothrow_flag,
cgraph_set_readonly_flag, cgraph_set_pure_flag
and cgraph_set_looping_const_or_pure_flag.
(local_pure_const): Likewise.
--- gcc/cgraph.h.jj 2009-12-10 22:54:27.000000000 +0100
+++ gcc/cgraph.h 2009-12-14 13:48:09.000000000 +0100
@@ -475,6 +475,11 @@ struct cgraph_node * cgraph_create_virtu
VEC(ipa_replace_map_p,gc)* tree_map,
bitmap args_to_skip);
+void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
+void cgraph_set_readonly_flag (struct cgraph_node *, bool);
+void cgraph_set_pure_flag (struct cgraph_node *, bool);
+void cgraph_set_looping_const_or_pure_flag (struct cgraph_node *, bool);
+
/* In cgraphunit.c */
void cgraph_finalize_function (tree, bool);
void cgraph_mark_if_needed (tree);
--- gcc/cgraph.c.jj 2009-12-10 22:54:27.000000000 +0100
+++ gcc/cgraph.c 2009-12-14 13:46:44.000000000 +0100
@@ -2208,4 +2208,53 @@ cgraph_make_node_local (struct cgraph_no
}
}
+/* Set TREE_NOTHROW on NODE's decl and on same_body aliases of NODE
+ if any to NOTHROW. */
+
+void
+cgraph_set_nothrow_flag (struct cgraph_node *node, bool nothrow)
+{
+ struct cgraph_node *alias;
+ TREE_NOTHROW (node->decl) = nothrow;
+ for (alias = node->same_body; alias; alias = alias->next)
+ TREE_NOTHROW (alias->decl) = nothrow;
+}
+
+/* Set TREE_READONLY on NODE's decl and on same_body aliases of NODE
+ if any to READONLY. */
+
+void
+cgraph_set_readonly_flag (struct cgraph_node *node, bool readonly)
+{
+ struct cgraph_node *alias;
+ TREE_READONLY (node->decl) = readonly;
+ for (alias = node->same_body; alias; alias = alias->next)
+ TREE_READONLY (alias->decl) = readonly;
+}
+
+/* Set DECL_PURE_P on NODE's decl and on same_body aliases of NODE
+ if any to PURE. */
+
+void
+cgraph_set_pure_flag (struct cgraph_node *node, bool pure)
+{
+ struct cgraph_node *alias;
+ DECL_PURE_P (node->decl) = pure;
+ for (alias = node->same_body; alias; alias = alias->next)
+ DECL_PURE_P (alias->decl) = pure;
+}
+
+/* Set DECL_LOOPING_CONST_OR_PURE_P on NODE's decl and on
+ same_body aliases of NODE if any to LOOPING_CONST_OR_PURE. */
+
+void
+cgraph_set_looping_const_or_pure_flag (struct cgraph_node *node,
+ bool looping_const_or_pure)
+{
+ struct cgraph_node *alias;
+ DECL_LOOPING_CONST_OR_PURE_P (node->decl) = looping_const_or_pure;
+ for (alias = node->same_body; alias; alias = alias->next)
+ DECL_LOOPING_CONST_OR_PURE_P (alias->decl) = looping_const_or_pure;
+}
+
#include "gt-cgraph.h"
--- gcc/except.h.jj 2009-11-25 16:47:36.000000000 +0100
+++ gcc/except.h 2009-12-14 13:49:57.000000000 +0100
@@ -228,9 +228,6 @@ extern int doing_eh (int);
loop hackery; should not be used by new code. */
extern void for_each_eh_label (void (*) (rtx));
-/* Set TREE_NOTHROW and cfun->all_throwers_are_sibcalls. */
-extern unsigned int set_nothrow_function_flags (void);
-
extern void init_eh (void);
extern void init_eh_for_function (void);
--- gcc/except.c.jj 2009-11-25 16:47:36.000000000 +0100
+++ gcc/except.c 2009-12-14 13:50:34.000000000 +0100
@@ -1835,7 +1835,7 @@ can_nonlocal_goto (const_rtx insn)
/* Set TREE_NOTHROW and crtl->all_throwers_are_sibcalls. */
-unsigned int
+static unsigned int
set_nothrow_function_flags (void)
{
rtx insn;
@@ -1892,7 +1892,7 @@ set_nothrow_function_flags (void)
struct cgraph_edge *e;
for (e = node->callers; e; e = e->next_caller)
e->can_throw_external = false;
- TREE_NOTHROW (current_function_decl) = 1;
+ cgraph_set_nothrow_flag (node, true);
if (dump_file)
fprintf (dump_file, "Marking function nothrow: %s\n\n",
--- gcc/ipa-pure-const.c.jj 2009-11-28 17:16:14.000000000 +0100
+++ gcc/ipa-pure-const.c 2009-12-14 12:28:00.000000000 +0100
@@ -941,8 +941,8 @@ propagate (void)
fprintf (dump_file, "Function found to be %sconst: %s\n",
this_looping ? "looping " : "",
cgraph_node_name (w));
- TREE_READONLY (w->decl) = 1;
- DECL_LOOPING_CONST_OR_PURE_P (w->decl) = this_looping;
+ cgraph_set_readonly_flag (w, true);
+ cgraph_set_looping_const_or_pure_flag (w, this_looping);
break;
case IPA_PURE:
@@ -950,8 +950,8 @@ propagate (void)
fprintf (dump_file, "Function found to be %spure: %s\n",
this_looping ? "looping " : "",
cgraph_node_name (w));
- DECL_PURE_P (w->decl) = 1;
- DECL_LOOPING_CONST_OR_PURE_P (w->decl) = this_looping;
+ cgraph_set_pure_flag (w, true);
+ cgraph_set_looping_const_or_pure_flag (w, this_looping);
break;
default:
@@ -1032,7 +1032,7 @@ propagate (void)
if (!can_throw && !TREE_NOTHROW (w->decl))
{
struct cgraph_edge *e;
- TREE_NOTHROW (w->decl) = true;
+ cgraph_set_nothrow_flag (w, true);
for (e = w->callers; e; e = e->next_caller)
e->can_throw_external = false;
if (dump_file)
@@ -1110,6 +1110,7 @@ local_pure_const (void)
{
bool changed = false;
funct_state l;
+ struct cgraph_node *node;
/* Because we do not schedule pass_fixup_cfg over whole program after early optimizations
we must not promote functions that are called by already processed functions. */
@@ -1120,23 +1121,23 @@ local_pure_const (void)
fprintf (dump_file, "Function called in recursive cycle; ignoring\n");
return 0;
}
- if (cgraph_function_body_availability (cgraph_node (current_function_decl))
- <= AVAIL_OVERWRITABLE)
+ node = cgraph_node (current_function_decl);
+ if (cgraph_function_body_availability (node) <= AVAIL_OVERWRITABLE)
{
if (dump_file)
fprintf (dump_file, "Function has wrong visibility; ignoring\n");
return 0;
}
- l = analyze_function (cgraph_node (current_function_decl), false);
+ l = analyze_function (node, false);
switch (l->pure_const_state)
{
case IPA_CONST:
if (!TREE_READONLY (current_function_decl))
{
- TREE_READONLY (current_function_decl) = 1;
- DECL_LOOPING_CONST_OR_PURE_P (current_function_decl) = l->looping;
+ cgraph_set_readonly_flag (node, true);
+ cgraph_set_looping_const_or_pure_flag (node, l->looping);
changed = true;
if (dump_file)
fprintf (dump_file, "Function found to be %sconst: %s\n",
@@ -1147,7 +1148,7 @@ local_pure_const (void)
else if (DECL_LOOPING_CONST_OR_PURE_P (current_function_decl)
&& !l->looping)
{
- DECL_LOOPING_CONST_OR_PURE_P (current_function_decl) = false;
+ cgraph_set_looping_const_or_pure_flag (node, false);
changed = true;
if (dump_file)
fprintf (dump_file, "Function found to be non-looping: %s\n",
@@ -1159,8 +1160,8 @@ local_pure_const (void)
case IPA_PURE:
if (!TREE_READONLY (current_function_decl))
{
- DECL_PURE_P (current_function_decl) = 1;
- DECL_LOOPING_CONST_OR_PURE_P (current_function_decl) = l->looping;
+ cgraph_set_pure_flag (node, true);
+ cgraph_set_looping_const_or_pure_flag (node, l->looping);
changed = true;
if (dump_file)
fprintf (dump_file, "Function found to be %spure: %s\n",
@@ -1171,7 +1172,7 @@ local_pure_const (void)
else if (DECL_LOOPING_CONST_OR_PURE_P (current_function_decl)
&& !l->looping)
{
- DECL_LOOPING_CONST_OR_PURE_P (current_function_decl) = false;
+ cgraph_set_looping_const_or_pure_flag (node, false);
changed = true;
if (dump_file)
fprintf (dump_file, "Function found to be non-looping: %s\n",
@@ -1187,9 +1188,8 @@ local_pure_const (void)
{
struct cgraph_edge *e;
- TREE_NOTHROW (current_function_decl) = true;
- for (e = cgraph_node (current_function_decl)->callers;
- e; e = e->next_caller)
+ cgraph_set_nothrow_flag (node, true);
+ for (e = node->callers; e; e = e->next_caller)
e->can_throw_external = false;
changed = true;
if (dump_file)
Jakub