This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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]

[PATCH] Fix fortran creating a huge number of io transfer structs


Currently for code as simple as

       PROGRAM test
       WRITE(*,*) 'hello'
       WRITE(*,*) 'world'
       END

gfortran creates two struct __st_parameter_dt, one for each I/O operation.
This causes a _huge_ regression in compile time if we ever start to create
SFTs for those structs, as observed earlier and caused by the patch to 
enable SFTs for structures containing arrays.  This has been worked around
sofar, but there's no reason why gfortran cannot share one struct 
__st_parameter_dt per function or at least one per sequence of I/O 
operations.  In fact, the simple patch below cut's down compile time
for channel.f90 from 11s to 2s (if the workaround is disabled).

I'm sure the fortran guys know a better way of keeping track of a
struct __st_parameter_dt in a function, so this is a heads-up, the
patch doesn't work in general as it messes up the scopes for the variable.

Thanks,
Richard.


2006-02-22  Richard Guenther  <rguenther@suse.de>

	* trans-io.c (build_dt): Try to re-use older dt_parm created
	earlier for this function.

Index: trans-io.c
===================================================================
*** trans-io.c	(revision 111363)
--- trans-io.c	(working copy)
*************** Software Foundation, 51 Franklin Street,
*** 28,33 ****
--- 28,35 ----
  #include "ggc.h"
  #include "toplev.h"
  #include "real.h"
+ #include "target.h"
+ #include "function.h"
  #include "gfortran.h"
  #include "trans.h"
  #include "trans-stmt.h"
*************** build_dt (tree function, gfc_code * code
*** 1353,1366 ****
    gfc_namelist *nml;
    unsigned int mask = 0;
  
    gfc_start_block (&block);
    gfc_init_block (&post_block);
    gfc_init_block (&post_end_block);
  
-   var = gfc_create_var (st_parameter[IOPARM_ptype_dt].type, "dt_parm");
- 
-   set_error_locus (&block, var, &code->loc);
- 
    if (last_dt == IOLENGTH)
      {
        gfc_inquire *inq;
--- 1355,1374 ----
    gfc_namelist *nml;
    unsigned int mask = 0;
  
+   if (!dt_parm
+       || DECL_CONTEXT (dt_parm) != cfun->decl)
+     {
+       var = gfc_create_var (st_parameter[IOPARM_ptype_dt].type, "dt_parm");
+ 
+       set_error_locus (&block, var, &code->loc);
+     }
+   else
+     var = dt_parm;
+ 
    gfc_start_block (&block);
    gfc_init_block (&post_block);
    gfc_init_block (&post_end_block);
  
    if (last_dt == IOLENGTH)
      {
        gfc_inquire *inq;
*************** build_dt (tree function, gfc_code * code
*** 1477,1483 ****
  
    gfc_add_expr_to_block (&block, gfc_trans_code (code->block->next));
  
-   dt_parm = NULL;
    dt_post_end_block = NULL;
  
    return gfc_finish_block (&block);
--- 1485,1490 ----


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