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]

[PATCH]: RTL iterators


Only supports RTL that is 20 levels deep, but i've never seen one more
than 3 levels deep, so i don't think this is a problem.

The get_next_CODE functions are generated by the preprocessor.
It might make sense to have an rtliter.h.in, and preprocess it once to
generate the functions, rather than have them generated each time
something includes it.


Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/egcs/gcc/ChangeLog,v
retrieving revision 1.10951
diff -c -3 -p -w -B -b -r1.10951 ChangeLog
*** ChangeLog	2001/08/08 15:40:55	1.10951
--- ChangeLog	2001/08/09 21:35:52
***************
*** 1,3 ****
--- 1,7 ----
+ 2001-08-09  Daniel Berlin  <dan@cgsoftware.com>
+ 
+ 	* rtliter.h: New file. RTL Iterators.
+ 
  2001-08-08  H.J. Lu <hjl@gnu.org>
  
  	* config/mips/mips.c (mips_unique_section): New. Copied from
Index: rtliter.h
===================================================================
RCS file: rtliter.h
diff -N rtliter.h
*** /dev/null	Tue May  5 13:32:27 1998
--- rtliter.h	Thu Aug  9 14:35:52 2001
***************
*** 0 ****
--- 1,113 ----
+ /* Register Transfer Language (RTL) iterator definitions for GNU C-Compiler
+    Copyright (C) 2001 Free Software Foundation, Inc.
+    Contributed by Daniel Berlin (dan@cgsoftware.com).
+ 
+ This file is part of GNU CC.
+ 
+ GNU CC is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+ 
+ GNU CC is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+ 
+ You should have received a copy of the GNU General Public License
+ along with GNU CC; see the file COPYING.  If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.  */
+ 
+ #ifndef RTLITER_H_
+ #define RTLITER_H_
+ #include "ggc.h"
+ /* Cookie used to keep track of where the iterator is. */
+ typedef struct rtx_iter_cookie
+ {
+   rtx stack[20];
+   unsigned char stackplace;
+   unsigned char top[20];
+   unsigned char topplace;
+   unsigned char length[20];
+   unsigned char lengthplace;
+ }
+  *rtx_iter;
+ static inline rtx get_next_rtx PARAMS ((rtx, rtx_iter *));
+ /* Get the next rtx, given the cookie. Returns NULL when
+    there is no next RTX.
+    The first time you call this, curr should be non-NULL, and
+    *cookie should be 0.
+    After that, there is no need to pass a valid curr.  */
+ static inline rtx
+ get_next_rtx (curr, cookie)
+      rtx curr;
+      rtx_iter *cookie;
+ {
+   register RTX_CODE code;
+   register int i;
+   register const char *fmt;
+   register int length;
+   if (*cookie == 0)
+     {
+       *cookie = (rtx_iter) ggc_alloc (sizeof (struct rtx_iter_cookie));
+       (*cookie)->stackplace = 0;
+       (*cookie)->stack[0] = curr;
+       (*cookie)->top[0] = 0;
+       (*cookie)->topplace = 0;
+       (*cookie)->lengthplace = 0;
+       (*cookie)->length[0] = GET_RTX_LENGTH (GET_CODE (curr));
+     }
+ top:
+   curr = (*cookie)->stack[(*cookie)->stackplace];
+   code = GET_CODE (curr);
+   fmt = GET_RTX_FORMAT (code);
+   length = (*cookie)->length[(*cookie)->lengthplace];
+   for (; (*cookie)->top[(*cookie)->topplace] < length;
+        (*cookie)->top[(*cookie)->topplace]++)
+     {
+       register int i;
+       i = (*cookie)->top[(*cookie)->topplace];
+       switch (fmt[i])
+ 	{
+ 	case 'e':
+ 	  (*cookie)->stack[++(*cookie)->stackplace] = XEXP (curr, i);
+ 	  (*cookie)->top[(*cookie)->topplace]++;
+ 	  (*cookie)->top[++(*cookie)->topplace] = 0;
+ 	  (*cookie)->length[++(*cookie)->lengthplace] =
+ 	    GET_RTX_LENGTH (GET_CODE (XEXP (curr, i)));
+ 	  return (XEXP (curr, i));
+ 	case 'V':
+ 	case 'E':
+ 	  (*cookie)->stack[++(*cookie)->stackplace] = XVECEXP (curr, 0, i);
+ 	  (*cookie)->top[(*cookie)->topplace]++;
+ 	  (*cookie)->top[++(*cookie)->topplace] = 0;
+ 	  (*cookie)->length[++(*cookie)->lengthplace] = XVECLEN (curr, i);
+ 	  return (XVECEXP (curr, 0, i));
+ 	}
+     }
+   if ((*cookie)->stackplace == 0)
+     return NULL;
+   (*cookie)->stackplace--;
+   (*cookie)->lengthplace--;
+   (*cookie)->topplace--;
+   goto top;
+ }
+ /* Generic iteration template, used in generating get_next functions. */
+ #define GENERIC_ITER_TEMPLATE(ENUM) \
+ rtx get_next_ ## ENUM PARAMS ((rtx, rtx_iter *)); \
+ rtx get_next_ ## ENUM (curr, cookie) \
+   rtx curr; \
+   rtx_iter *cookie; \
+ { \
+   rtx temp; \
+   while (( temp = get_next_rtx (curr, cookie)) != NULL) \
+       if (GET_CODE (temp) == ENUM) \
+ 	return temp; \
+   return NULL; \
+ } \
+ /* Generate a get_next function for each possible RTX */
+ #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) GENERIC_ITER_TEMPLATE (ENUM)
+ #include "rtl.def"
+ #undef DEF_RTL_EXPR
+ #endif

-- 
"In my house there's this light switch that doesn't do anything.
Every so often I would flick it on and off just to check.
Yesterday, I got a call from a woman in Germany.  She said, "Cut
it out."
"-Steven Wright


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