Patch to detect constant functions.
Toon Moene
toon@moene.indiv.nluug.nl
Tue Aug 31 22:41:00 GMT 1999
[ cc'd to Craig ]
John Wehle wrote:
> This patch allows gcc to detect and mark functions as constant by using
> the information from the alias analysis to determine if the function
> references memory which isn't local. Knowing that a function is constant
> can help cse and loop. For example using -O2 on a x86 platform to compile:
> int
> subr(int a, int b, int c)
> {
>
> if (! c )
> return subr(a, b, 1);
>
> return a + b / c;
> }
>
> int
> func(int a, int b, int c)
> {
>
> return subr(a, b, c) + subr(a, b, c);
> }
>
Interesting - In Fortran this is *always* possible, because it is not
allowed to depend on side effects of part of an expression (see e.g. the
following interpretation w.r.t. to the FORTRAN 77 Standard:
http://www.fortran.com/fortran/F77_std/sideff.jpg ; for the Standard
itself see: http://www.fortran.com/fortran/F77_std/rjcnf.html ).
Indeed, the Fortran Frontend contains the following tantalizing comment
in f/com.c (finish_function):
/* TREE_READONLY (fndecl) = 1;
This caused &foo to be of type ptr-to-const-function
which then got a warning when stored in a ptr-to-function variable.
*/
Apparently, this is not used at the moment - Craig, how old is this
comment ? Is it still applicable ?
Another interesting "project" would be to "constify" Fortran intrinsics
- I lost track in f/intrin.c finding out whether this already happens.
--
Toon Moene (toon@moene.indiv.nluug.nl)
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
Phone: +31 346 214290; Fax: +31 346 214286
GNU Fortran: http://world.std.com/~burley/g77.html
More information about the Gcc-patches
mailing list