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]

Re: [PATCH] RTL Iterators


Also, you could pretty easily rewrite for_each_rtx to use a little less than
half the code (22 vs 57 lines), no recursion,  and not directly depend on the internal
structure of RTL, as follows:

int
for_each_rtx_two (x, f, data)
        rtx *x;
        rtx_function f;
        void *data;
{
  rtx_iter cookie;
  rtx temp;
  int result;

  result = (*f) (x, data);
  if (result  == -1)
    temp = get_next_rtx_nopush (*x, cookie);
  else if (result != 0)
    return result;
  else
    temp = get_next_rtx (*x, cookie);

  while (temp != NULL)
    {
      result = (*f) (&temp, data);
      if (result  == -1)
        temp = get_next_rtx_nopush (*x, cookie);
      else if (result != 0)
        return result;
      else
        temp = get_next_rtx (*x, cookie);
    }
  return 0;
}

(The semantics of for_each_rtx are a little tricky, hence, the nopush
function. It doesn't push the current subexpression onto the cookie's stack, so
we can avoid going through the subtrees if the user asks us to).

I already rewrote the macro so it generates a one line function,
rather than a 6 line function, for each rtx code.
If i write a seperate generate program, or script,  i can make the
get_next_(RTX_CODE) functions into defines, and only have 3 real
functions.
I don't know if it's possible to have macros that recursively define
macros (I don't think it is, having spent about 20 minutes
with cpp.texi, and trying various things).
We really want to be able to say:

#define GENERATE_ITERATOR_MACRO(ENUM) \
#define get_next_ ## ENUM(curr,cookie) get_next_rtx_of_code(ENUM,curr,cookie)

Which would let us get rid of all the one line functions.
If it's really that important to not generate that many one line
functions, i'll just make a seperate program or something to generate
the iterator code.
--Dan
-- 
"I went to the eye doctor and found out I needed glasses for
reading.  So, I got some flip-up contact lenses.
"-Steven Wright


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