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, fortran] Reduce memory usage for intrinsic masks


:ADDPATCH fortran:

Hello world,

this rather straightforward patch converts masks for different 
intrinsics to logical(kind=1) if they are expressions.  This means that,
for code like "pack(a,a>0.4)", we generate a logical1 instead of a
logical4 array.  This is a fairly big save in memory footprint.  In the
library, we now access all masks as kind=1 anyway.

For once, there isn't a PR associated with this.  No new test case as
this is tested extensively throughout the testsuite anyway. 
Regression-tested on i686-pc-linux-gnu.

OK for trunk?

	Thomas

2007-09-07  Thomas Koenig  <tkoenig@gcc.gnu.org>

	* iresolve.c (resolve_mask_arg): If a mask is an array
	expression, convert it to kind=1.
Index: iresolve.c
===================================================================
--- iresolve.c	(revision 128136)
+++ iresolve.c	(working copy)
@@ -78,18 +78,32 @@ static void
 resolve_mask_arg (gfc_expr *mask)
 {
 
-  /* The mask can be any kind for an array.
-     For the scalar case, coerce it to kind=4 unconditionally
-     (because this is the only kind we have a library function
-     for).  */
+  gfc_typespec ts;
 
-  if (mask->rank == 0 && mask->ts.kind != 4)
+  if (mask->rank == 0)
     {
-      gfc_typespec ts;
+      /* For the scalar case, coerce the mask to kind=4 unconditionally
+	 (because this is the only kind we have a library function
+	 for).  */
 
-      ts.type = BT_LOGICAL;
-      ts.kind = 4;
-      gfc_convert_type (mask, &ts, 2);
+      if (mask->ts.kind != 4)
+	{
+	  ts.type = BT_LOGICAL;
+	  ts.kind = 4;
+	  gfc_convert_type (mask, &ts, 2);
+	}
+    }
+  else
+    {
+      /* In the library, we access the mask with a GFC_LOGICAL_1
+	 argument.  No need to waste memory if we are about to create
+	 a temporary array.  */
+      if (mask->expr_type == EXPR_OP)
+	{
+	  ts.type = BT_LOGICAL;
+	  ts.kind = 1;
+	  gfc_convert_type (mask, &ts, 2);
+	}
     }
 }
 

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