This is the mail archive of the gcc@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: GCC gprof statistics


Aha. I am not sure how I got away with it in
the previous compilation, but
the posted versioon for_each_rtx.h produced warning(s) and
during the CVS source compilation,
-Werror option turns the warnings into error and stop the
compilation.

So this is a modified for_each_rtx.h and
this makes the CVS version compilation proceed.
(It is proceeding as of now.)

I modified the loop upper count a little bit.

*** /dev/null	1970-01-01 09:00:00.000000000 +0900
--- for_each_rtx.h	2003-07-01 18:09:21.000000000 +0900
***************
*** 0 ****
--- 1,133 ----
+ /***
+     for_each_rtx optimization.
+ 
+     Idea is to define a specialized for_each_rtx_xxxxx function
+     that uses a given function (the riginal second paramter f to 
+     for_each_rtx().)
+ 
+      And instead of calling the generic for_each_rtx(),
+      use the specialized version.
+ 
+      For each call to for_each_rtx thus replaced, we have one fewer 
+      argument to pass in the specialized version. 
+      (gprof analysis indicates that
+       for_each_rtx is called  so many times that this matters!)
+ 
+     Also, by inlining the called functions (adding inline)
+     before the definition of specialized for_each_rtx_func, the compiler
+     can have ample opportunities to optimize. (After a second look,
+     this is unlikely. But at least we can probably save the call/return
+     overhead.)
+     
+     Now instead of hard-coding the specialized function,
+     I decided to write a macro to write the specialized
+     definition for given function.
+ 
+     This makes it easy to propagate any change (optimization)
+     in for_each_rtx to the definitions. We only need to rewrite the
+     macro once. 
+ 
+     Is such optimizatin of for_each_rtx itself likely?
+     By looking at the current for_each_rtx and comment from
+     Andrew Pinski posted to gcc maling list, I think we can handle
+     some special cases of length=2 or 1 rtl tree, etc..
+     (for that matter, is GCC clever enough to figure that
+     XVECLEN(*x,i,j) is a constant in the nested loop?
+ 
+ 
+ DEFINE_FOR_EACH_RTX_ITERATOR(foobar) 
+ defines
+ int
+ for_each_rtx_foobar(x, data);
+      rtx *x;
+      void *data;  
+ 
+ CALL_FOR_EACH_RTX_ITERATOR(x, func, z)
+      is changed into
+      for_each_rtx_func(x, z)
+ 
+ cf. Use of DECLARE_FOR_EACH_RTX_ITERATOR is
+     to shut off warning in the CVS version of GCC source
+     compilation. -Werror turns any warning into an error.
+ 
+ ***/
+ 
+ #define DECLARE_FOR_EACH_RTX_ITERATOR(func) \
+ int  \
+ for_each_rtx_##func ( rtx *x, void * data)
+ 
+ 
+ #define DEFINE_FOR_EACH_RTX_ITERATOR(func) \
+ DECLARE_FOR_EACH_RTX_ITERATOR(func);  \
+ int \
+ for_each_rtx_##func (x, /*f, */ data) \
+      rtx *x;			      \
+      /***rtx_function f;***/	      \
+      void *data;		      \
+ { \
+   int result; \
+   int length; \
+   const char *format; \
+   int i;		\
+ 		\
+   /* Call F on X.  */		\
+   result = func (x, data);		\
+   if (result == -1)		\
+     /* Do not traverse sub-expressions.  */		\
+     return 0;		\
+   else if (result != 0)		\
+     /* Stop the traversal.  */		\
+     return result;		\
+ 		\
+   if (*x == NULL_RTX)		\
+     /* There are no sub-expressions.  */		\
+     return 0;		\
+ 		\
+   length = GET_RTX_LENGTH (GET_CODE (*x));		\
+   format = GET_RTX_FORMAT (GET_CODE (*x));		\
+ 		\
+   for (i = 0; i < length; ++i)		\
+     {		\
+       switch (format[i])		\
+ 	{		\
+ 	case 'e':		\
+ 	  result = for_each_rtx_##func (&XEXP (*x, i), /*f,*/ data);		\
+ 	  if (result != 0)		\
+ 	    return result;		\
+ 	  break;		\
+ 		\
+ 	case 'V':		\
+ 	case 'E':		\
+ 	  if (XVEC (*x, i) != 0)		\
+ 	    {		\
+ 	      int j;		\
+               int l = XVECLEN(*x, i);            \
+ 	      for (j = 0; j < l; ++j)		\
+ 		{		\
+ 		  result = for_each_rtx_##func (&XVECEXP (*x, i, j), /*f,*/ data);		\
+ 		  if (result != 0)		\
+ 		    return result;		\
+ 		}		\
+ 	    }		\
+ 	  break;		\
+ 		\
+ 	default:		\
+ 	  /* Nothing to do.  */		\
+ 	  break;		\
+ 	}		\
+ 		\
+     }		\
+ 		\
+   return 0;		\
+ }
+ 
+ #define CALL_FOR_EACH_RTX_ITERATOR(x, func, d) for_each_rtx_##func ((x),(d))
+ 
+ 
+ 
+ /* Usage Example
+     DEFINE_FOR_EACH_RTX_ITERATOR(gazonk)
+ 
+  CALL_FOR_EACH_RTX_ITERATOR(a, gazonk, c)
+ */
+ 

change to cse.c stands.

-- 
int main(void){int j=2003;/*(c)2003 cishikawa. */
char t[] ="<CI> @abcdefghijklmnopqrstuvwxyz.,\n\"";
char *i ="g>qtCIuqivb,gCwe\np@.ietCIuqi\"tqkvv is>dnamz";
while(*i)((j+=strchr(t,*i++)-(int)t),(j%=sizeof t-1),
(putchar(t[j])));return 0;}/* under GPL */


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