This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Speed up for_each_rtx
- From: Ian Lance Taylor <ian at airs dot com>
- To: Paolo Bonzini <paolo dot bonzini at lu dot unisi dot ch>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Richard Henderson <rth at redhat dot com>
- Date: 20 Jan 2005 15:11:13 -0500
- Subject: Re: [PATCH] Speed up for_each_rtx
- References: <41EFAC3B.5050704@lu.unisi.ch>
Paolo Bonzini <paolo.bonzini@lu.unisi.ch> writes:
> +
> +void
> +init_rtlanal (void)
> +{
> + int i;
> + for (i = 0; i < NUM_RTX_CODE; i++)
> + {
> + const char *format = GET_RTX_FORMAT (i);
> + const char *first = strpbrk (format, "eEV");
> + non_rtx_starting_operands[i] = first ? first - format : -1;
> + }
> +}
Interesting approach. Since non_rtx_starting_operands is in fact a
compile time constant, this suggests the approach of writing a genrtl
program which writes out an optimized for_each_rtx function. The
optimized function would never call GET_RTX_FORMAT and would never
loop (except over vectors). Instead it would switch on GET_CODE and
have direct calls for the operands specific to that code.
For example, the generated code might look something like this:
tail_recurse:
result = (*f) (xp, data)
if (result == -1)
return 0;
else if (result != 0)
return result;
x = *xp;
switch (GET_CODE (x))
{
case REG:
etc.
return;
case PLUS:
case MINUS:
etc.
result = for_each_rtx (&XEXP (x, 0), data);
if (result == 0)
{
xp = &XEXP (x, 1);
goto tail_recurse;
}
break;
case ADDR_VEC:
// for_each_rtx_rtvec takes X, the operand number such that XVEC
// (x, i) gives us the vector, and F and DATA.
result = for_each_rtx_rtvec (x, 0, f, data);
break;
...
}
return result != -1 ? result : 0;
Ian