This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Speed up for_each_rtx


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]