From patchwork Fri Jun 18 21:45:15 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [fortran] PR 40628, optimize TRIM on assignment Date: Fri, 18 Jun 2010 11:45:15 -0000 From: Thomas Koenig X-Patchwork-Id: 56226 Message-Id: <1276897515.8491.8.camel@linux-fd1f.site> To: fortran@gcc.gnu.org Cc: gcc-patches@gcc.gnu.org Hello world, this patch fixes one part of PR 40628 by optimizing away an unneeded TRIM on string assignment. I have created a new file for this, optimize.c. This is supposed to contain optimizations with gfc_expr, before translations into TREEs. Chances are this file will grow a bit later :-) right now it only contains this single optimization. At a later stage, it might be a good idea to add a -fdump-optimized-tree to see what the optimization has done. Regression-tested on x86_64-unknown-linux-gnu. OK in principle for the idea? OK for trunk? Thomas 2010-06-18 Thomas Koenig * Make-lang.in: Add fortran/optimize.o. * gfortran.h: Add prototype for gfc_optimize_namespace. * trans-decl.c (gfc_generate_function_code): If optimizing, call gfc_optimize_namespace. * optimize.c: New file. Index: Make-lang.in =================================================================== --- Make-lang.in (Revision 160943) +++ Make-lang.in (Arbeitskopie) @@ -66,7 +66,7 @@ F95_OBJS = $(F95_PARSER_OBJS) $(FORTRAN_TARGET_OBJ fortran/trans.o fortran/trans-array.o fortran/trans-common.o \ fortran/trans-const.o fortran/trans-decl.o fortran/trans-expr.o \ fortran/trans-intrinsic.o fortran/trans-io.o fortran/trans-openmp.o \ - fortran/trans-stmt.o fortran/trans-types.o + fortran/trans-stmt.o fortran/trans-types.o fortran/optimize.o fortran_OBJS = $(F95_OBJS) gfortranspec.o Index: gfortran.h =================================================================== --- gfortran.h (Revision 160943) +++ gfortran.h (Arbeitskopie) @@ -2825,4 +2825,8 @@ gfc_symtree* gfc_get_tbp_symtree (gfc_symtree**, c #define CLASS_DATA(sym) sym->ts.u.derived->components +/* optimize.c */ + +void gfc_optimize_namespace (gfc_namespace *); + #endif /* GCC_GFORTRAN_H */ Index: trans-decl.c =================================================================== --- trans-decl.c (Revision 160943) +++ trans-decl.c (Arbeitskopie) @@ -4371,6 +4371,9 @@ gfc_generate_function_code (gfc_namespace * ns) int rank; bool is_recursive; + if (optimize) + gfc_optimize_namespace (ns); + sym = ns->proc_name; /* Check that the frontend isn't still using this. */