This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] Repost: genattrtab speedup/memory reduction
> On Tue, Aug 07, 2001 at 01:54:16PM +0200, Jan van Male#84776 wrote:
> > /* Loop until nothing changes for one iteration. */
> > ! something_changed = 1;
> > ! while (something_changed)
> > {
> > ! something_changed = 0;
> > ! for (iv = insn_code_values[i]; iv; iv = iv->next)
> ----
> > /* Loop until nothing changes for one iteration. */
> > ! for (iv = insn_code_values[i]; iv; iv = iv->next)
>
> How is it that we're "looping until nothing changes",
> if the while statement has been removed?
Yes, Daniel is correct, the while loop inside does the job.
I am sending updated patch with removed missleading comment and unneeded
variable.
2001-08-07 Jan Hubicka <jh@suse.cz>
* genattrtab.c (simplify_test_exp_in_temp): New function.
(simplify_test_exp): Avoid explicit use of temporary obstack.
(simplify_cond, insert_right_side, evaluate_eq_attr,
simplify_and_tree, simplify_or_tree, eliminate_known_true):
Use simplify_test_exp_in_temp.
(optimize_attrs): Iterate until expression stabilizes.
Index: genattrtab.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/genattrtab.c,v
retrieving revision 1.90
diff -c -3 -p -r1.90 genattrtab.c
*** genattrtab.c 2001/04/13 21:10:14 1.90
--- genattrtab.c 2001/08/08 18:13:04
*************** static rtx evaluate_eq_attr PARAMS ((rtx
*** 417,422 ****
--- 417,423 ----
static rtx simplify_and_tree PARAMS ((rtx, rtx *, int, int));
static rtx simplify_or_tree PARAMS ((rtx, rtx *, int, int));
static rtx simplify_test_exp PARAMS ((rtx, int, int));
+ static rtx simplify_test_exp_in_temp PARAMS ((rtx, int, int));
static void optimize_attrs PARAMS ((void));
static void gen_attr PARAMS ((rtx, int));
static int count_alternatives PARAMS ((rtx));
*************** simplify_cond (exp, insn_code, insn_inde
*** 2593,2599 ****
rtx newtest, newval;
/* Simplify this test. */
! newtest = SIMPLIFY_TEST_EXP (tests[i], insn_code, insn_index);
tests[i] = newtest;
newval = tests[i + 1];
--- 2594,2600 ----
rtx newtest, newval;
/* Simplify this test. */
! newtest = simplify_test_exp_in_temp (tests[i], insn_code, insn_index);
tests[i] = newtest;
newval = tests[i + 1];
*************** insert_right_side (code, exp, term, insn
*** 2782,2788 ****
newexp = attr_rtx (code, exp, term);
}
! return SIMPLIFY_TEST_EXP (newexp, insn_code, insn_index);
}
/* If we have an expression which AND's a bunch of
--- 2783,2789 ----
newexp = attr_rtx (code, exp, term);
}
! return simplify_test_exp_in_temp (newexp, insn_code, insn_index);
}
/* If we have an expression which AND's a bunch of
*************** evaluate_eq_attr (exp, value, insn_code,
*** 2910,2917 ****
for (i = 0; i < XVECLEN (value, 0); i += 2)
{
! rtx this = SIMPLIFY_TEST_EXP (XVECEXP (value, 0, i),
! insn_code, insn_index);
SIMPLIFY_ALTERNATIVE (this);
--- 2911,2918 ----
for (i = 0; i < XVECLEN (value, 0); i += 2)
{
! rtx this = simplify_test_exp_in_temp (XVECEXP (value, 0, i),
! insn_code, insn_index);
SIMPLIFY_ALTERNATIVE (this);
*************** simplify_and_tree (exp, pterm, insn_code
*** 2992,2998 ****
{
newexp = attr_rtx (GET_CODE (exp), left, right);
! exp = SIMPLIFY_TEST_EXP (newexp, insn_code, insn_index);
}
}
--- 2993,2999 ----
{
newexp = attr_rtx (GET_CODE (exp), left, right);
! exp = simplify_test_exp_in_temp (newexp, insn_code, insn_index);
}
}
*************** simplify_and_tree (exp, pterm, insn_code
*** 3015,3021 ****
{
newexp = attr_rtx (GET_CODE (exp), left, right);
! exp = SIMPLIFY_TEST_EXP (newexp, insn_code, insn_index);
}
}
--- 3016,3022 ----
{
newexp = attr_rtx (GET_CODE (exp), left, right);
! exp = simplify_test_exp_in_temp (newexp, insn_code, insn_index);
}
}
*************** simplify_or_tree (exp, pterm, insn_code,
*** 3111,3117 ****
{
newexp = attr_rtx (GET_CODE (exp), left, right);
! exp = SIMPLIFY_TEST_EXP (newexp, insn_code, insn_index);
}
}
--- 3112,3118 ----
{
newexp = attr_rtx (GET_CODE (exp), left, right);
! exp = simplify_test_exp_in_temp (newexp, insn_code, insn_index);
}
}
*************** simplify_or_tree (exp, pterm, insn_code,
*** 3134,3140 ****
{
newexp = attr_rtx (GET_CODE (exp), left, right);
! exp = SIMPLIFY_TEST_EXP (newexp, insn_code, insn_index);
}
}
--- 3135,3141 ----
{
newexp = attr_rtx (GET_CODE (exp), left, right);
! exp = simplify_test_exp_in_temp (newexp, insn_code, insn_index);
}
}
*************** attr_rtx_cost (x)
*** 3207,3212 ****
--- 3208,3236 ----
return cost;
}
+
+ /* Simplify test expression and use temporary obstack in order to avoid
+ memory bloat. Use RTX_UNCHANGING_P to avoid unnecesary simplifications
+ and avoid unnecesary copying if possible. */
+
+ static rtx
+ simplify_test_exp_in_temp (exp, insn_code, insn_index)
+ rtx exp;
+ int insn_code, insn_index;
+ {
+ rtx x;
+ struct obstack *old;
+ if (RTX_UNCHANGING_P (exp))
+ return exp;
+ old = rtl_obstack;
+ rtl_obstack = temp_obstack;
+ x = simplify_test_exp (exp, insn_code, insn_index);
+ rtl_obstack = old;
+ if (x == exp || rtl_obstack == temp_obstack)
+ return x;
+ return attr_copy_rtx (x);
+ }
+
/* Given an expression, see if it can be simplified for a particular insn
code based on the values of other attributes being tested. This can
eliminate nested get_attr_... calls.
*************** simplify_test_exp (exp, insn_code, insn_
*** 3464,3476 ****
if (ie->insn_code == insn_code)
{
rtx x;
- struct obstack *old = rtl_obstack;
- rtl_obstack = temp_obstack;
x = evaluate_eq_attr (exp, av->value, insn_code, insn_index);
x = SIMPLIFY_TEST_EXP (x, insn_code, insn_index);
- rtl_obstack = old;
if (attr_rtx_cost(x) < 20)
! return attr_copy_rtx (x);
}
break;
--- 3488,3497 ----
if (ie->insn_code == insn_code)
{
rtx x;
x = evaluate_eq_attr (exp, av->value, insn_code, insn_index);
x = SIMPLIFY_TEST_EXP (x, insn_code, insn_index);
if (attr_rtx_cost(x) < 20)
! return x;
}
break;
*************** optimize_attrs ()
*** 3499,3505 ****
struct attr_value *av;
struct insn_ent *ie;
rtx newexp;
- int something_changed = 1;
int i;
struct attr_value_list
{
--- 3520,3525 ----
*************** optimize_attrs ()
*** 3557,3597 ****
clear_struct_flag (iv->av->value);
/* Loop until nothing changes for one iteration. */
! something_changed = 1;
! while (something_changed)
{
! something_changed = 0;
! for (iv = insn_code_values[i]; iv; iv = iv->next)
! {
! struct obstack *old = rtl_obstack;
! attr = iv->attr;
! av = iv->av;
! ie = iv->ie;
! if (GET_CODE (av->value) != COND)
! continue;
! rtl_obstack = temp_obstack;
#if 0 /* This was intended as a speed up, but it was slower. */
! if (insn_n_alternatives[ie->insn_code] > 6
! && count_sub_rtxs (av->value, 200) >= 200)
! newexp = simplify_by_alternatives (av->value, ie->insn_code,
! ie->insn_index);
! else
#endif
! newexp = simplify_cond (av->value, ie->insn_code,
! ie->insn_index);
! rtl_obstack = old;
! if (newexp != av->value)
! {
! newexp = attr_copy_rtx (newexp);
! remove_insn_ent (av, ie);
! av = get_attr_value (newexp, attr, ie->insn_code);
! iv->av = av;
! insert_insn_ent (av, ie);
! something_changed = 1;
! }
}
}
}
--- 3577,3618 ----
clear_struct_flag (iv->av->value);
/* Loop until nothing changes for one iteration. */
! for (iv = insn_code_values[i]; iv; iv = iv->next)
{
! struct obstack *old = rtl_obstack;
! attr = iv->attr;
! av = iv->av;
! ie = iv->ie;
! if (GET_CODE (av->value) != COND)
! continue;
! rtl_obstack = temp_obstack;
#if 0 /* This was intended as a speed up, but it was slower. */
! if (insn_n_alternatives[ie->insn_code] > 6
! && count_sub_rtxs (av->value, 200) >= 200)
! newexp = simplify_by_alternatives (av->value, ie->insn_code,
! ie->insn_index);
! else
#endif
! newexp = av->value;
! while (GET_CODE (newexp) == COND)
! {
! rtx newexp2 = simplify_cond (newexp, ie->insn_code,
! ie->insn_index);
! if (newexp2 == newexp)
! break;
! newexp = newexp2;
! }
! rtl_obstack = old;
! if (newexp != av->value)
! {
! newexp = attr_copy_rtx (newexp);
! remove_insn_ent (av, ie);
! av = get_attr_value (newexp, attr, ie->insn_code);
! iv->av = av;
! insert_insn_ent (av, ie);
}
}
}