This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tree-ssa] memory usage vs tree-eh, take 2
- From: Richard Henderson <rth at twiddle dot net>
- To: gcc-patches at gcc dot gnu dot org
- Cc: law at redhat dot com
- Date: Thu, 18 Sep 2003 13:28:20 -0700
- Subject: [tree-ssa] memory usage vs tree-eh, take 2
This is what I committed. I was able to bootstrap on a 256M machine
in a not-unreasonable amount of time.
r~
* tree-eh.c: Include langhooks.h, remove errors.h.
(decide_copy_try_finally): Use estimate_num_insns to choose
between copy and switch implementations.
* c-common.c (c_estimate_num_insns): Take an expr, not a decl.
* tree-inline.c (limits_allow_inlining): Pass it the body of the decl.
* java/lang.c (java_estimate_num_insns): Take an expr, not a decl.
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.903.2.114
diff -u -p -r1.903.2.114 Makefile.in
--- Makefile.in 18 Sep 2003 14:14:58 -0000 1.903.2.114
+++ Makefile.in 18 Sep 2003 18:42:10 -0000
@@ -1557,7 +1557,7 @@ tree-dfa.o : tree-dfa.c $(TREE_FLOW_H) $
errors.h tree-inline.h $(HASHTAB_H) flags.h function.h $(TIMEVAR_H) \
tree-alias-common.h convert.h $(TM_H) coretypes.h langhooks.h
tree-eh.o : tree-eh.c $(TREE_FLOW_H) $(CONFIG_H) $(SYSTEM_H) \
- $(RTL_H) $(TREE_H) $(TM_H) flags.h function.h except.h errors.h
+ $(RTL_H) $(TREE_H) $(TM_H) flags.h function.h except.h langhooks.h
tree-optimize.o : tree-optimize.c $(TREE_FLOW_H) $(CONFIG_H) \
$(SYSTEM_H) $(RTL_H) $(TREE_H) $(TM_P_H) $(EXPR_H) \
$(GGC_H) output.h diagnostic.h ssa.h errors.h flags.h tree-alias-common.h \
Index: c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.344.2.35
diff -u -p -r1.344.2.35 c-common.c
--- c-common.c 13 Sep 2003 20:21:25 -0000 1.344.2.35
+++ c-common.c 18 Sep 2003 18:42:16 -0000
@@ -5789,12 +5789,12 @@ c_estimate_num_insns_1 (tree *tp, int *w
return NULL;
}
-/* Estimate number of instructions that will be created by expanding the body. */
+/* Estimate number of instructions that will be created by expanding EXPR. */
int
-c_estimate_num_insns (tree decl)
+c_estimate_num_insns (tree expr)
{
int num = 0;
- walk_tree_without_duplicates (&DECL_SAVED_TREE (decl), c_estimate_num_insns_1, &num);
+ walk_tree_without_duplicates (&expr, c_estimate_num_insns_1, &num);
return num;
}
Index: tree-eh.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-eh.c,v
retrieving revision 1.1.2.3
diff -u -p -r1.1.2.3 tree-eh.c
--- tree-eh.c 18 Sep 2003 14:14:59 -0000 1.1.2.3
+++ tree-eh.c 18 Sep 2003 18:42:17 -0000
@@ -32,7 +32,7 @@ Boston, MA 02111-1307, USA. */
#include "tree-dump.h"
#include "tree-inline.h"
#include "timevar.h"
-#include "errors.h"
+#include "langhooks.h"
/* HACK */
@@ -1160,17 +1160,29 @@ lower_try_finally_switch (struct leh_sta
the estimate of the size of the switch machinery we'd have to add. */
static bool
-decide_copy_try_finally (int ndests ATTRIBUTE_UNUSED,
- tree finally ATTRIBUTE_UNUSED)
+decide_copy_try_finally (int ndests, tree finally)
{
+ int f_estimate, sw_estimate;
+
if (!optimize)
return false;
- /* ??? Should actually estimate the size of the finally block here. */
-
- /* ??? Arbitrarily say -O1 does switch and -O2 does copy, so that both
- code paths get executed. */
- return optimize > 1;
+ /* Finally estimate N times, plus N gotos. */
+ f_estimate = (*lang_hooks.tree_inlining.estimate_num_insns) (finally);
+ f_estimate = (f_estimate + 1) * ndests;
+
+ /* Switch statement (cost 10), N variable assignments, N gotos. */
+ sw_estimate = 10 + 2 * ndests;
+
+ /* Optimize for size clearly wants our best guess. */
+ if (optimize_size)
+ return f_estimate < sw_estimate;
+
+ /* ??? These numbers are completely made up so far. */
+ if (optimize > 1)
+ return f_estimate < 100 || f_estimate * 2 < sw_estimate;
+ else
+ return f_estimate < 40 || f_estimate * 3 < sw_estimate * 2;
}
/* A subroutine of lower_eh_constructs_1. Lower a TRY_FINALLY_EXPR nodes
Index: tree-inline.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-inline.c,v
retrieving revision 1.26.2.44
diff -u -p -r1.26.2.44 tree-inline.c
--- tree-inline.c 17 Sep 2003 23:38:52 -0000 1.26.2.44
+++ tree-inline.c 18 Sep 2003 18:42:19 -0000
@@ -934,7 +934,8 @@ limits_allow_inlining (tree fn, inline_d
instructions that will be produces when expanding this function. */
if (!DECL_ESTIMATED_INSNS (fn))
DECL_ESTIMATED_INSNS (fn)
- = (*lang_hooks.tree_inlining.estimate_num_insns) (fn);
+ = (*lang_hooks.tree_inlining.estimate_num_insns)
+ (DECL_SAVED_TREE (fn));
estimated_insns = DECL_ESTIMATED_INSNS (fn);
/* We may be here either because fn is declared inline or because
Index: java/lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/lang.c,v
retrieving revision 1.103.2.17
diff -u -p -r1.103.2.17 lang.c
--- java/lang.c 23 Jul 2003 17:01:50 -0000 1.103.2.17
+++ java/lang.c 18 Sep 2003 18:42:36 -0000
@@ -1126,12 +1126,12 @@ java_estimate_num_insns_1 (tree *tp, int
return NULL;
}
-/* Estimate number of instructions that will be created by expanding the body. */
+/* Estimate number of instructions that will be created by expanding EXPR. */
static int
-java_estimate_num_insns (tree decl)
+java_estimate_num_insns (tree expr)
{
int num = 0;
- walk_tree (&DECL_SAVED_TREE (decl), java_estimate_num_insns_1, &num, NULL);
+ walk_tree_without_duplicates (&expr, java_estimate_num_insns_1, &num);
return num;
}