Patchwork [fortran] PR 40628, optimize TRIM on assignment

login
register
mail settings
Submitter Thomas Koenig
Date June 18, 2010, 9:45 p.m.
Message ID <1276897515.8491.8.camel@linux-fd1f.site>
Download mbox | patch
Permalink /patch/56226/
State New
Headers show

Comments

Thomas Koenig - June 18, 2010, 9:45 p.m.
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  <tkoenig@gcc.gnu.org>

	* 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.
Thomas Koenig - June 19, 2010, 9:27 p.m.
I wrote:

> OK in principle for the idea?  OK for trunk?

Not OK, even if I have to say it for myself :-)

In that patch, traversing the namespace isn't complete, because
it didn't handle blocks at all.

I'll submit a new patch, which also optimizes a few more cases.

	Thomas

Patch

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.  */