diff mbox

[fortran,34/66] inline sum and product: Update the scalarizer: gfc_ss_info refcounting

Message ID 20111027233208.18581.37924@gimli.local
State New
Headers show

Commit Message

Mikael Morin Oct. 27, 2011, 11:32 p.m. UTC
As there will be more than one gfc_ss struct pointing to a single gfc_ss_info,
it needs to be reference counted. This introduces reference counting.
OK?
2011-10-19  Mikael Morin  <mikael@gcc.gnu.org>

	* trans.h (struct gfc_ss_info): New field refcount.
	* trans-array.c (free_ss_info): Decrement refcount. Return early if
	still non-zero.
	(gfc_get_array_ss, gfc_get_temp_ss, gfc_get_scalar_ss): Increment
	refcount.
diff mbox

Patch

diff --git a/trans-array.c b/trans-array.c
index 663d12e..abb6db2 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -489,6 +489,11 @@  gfc_free_ss_chain (gfc_ss * ss)
 static void
 free_ss_info (gfc_ss_info *ss_info)
 {
+  ss_info->refcount--;
+  if (ss_info->refcount > 0)
+    return;
+
+  gcc_assert (ss_info->refcount == 0);
   free (ss_info);
 }
 
@@ -532,6 +537,7 @@  gfc_get_array_ss (gfc_ss *next, gfc_expr *expr, int dimen, gfc_ss_type type)
   int i;
 
   ss_info = gfc_get_ss_info ();
+  ss_info->refcount++;
   ss_info->type = type;
   ss_info->expr = expr;
 
@@ -556,6 +562,7 @@  gfc_get_temp_ss (tree type, tree string_length, int dimen)
   int i;
 
   ss_info = gfc_get_ss_info ();
+  ss_info->refcount++;
   ss_info->type = GFC_SS_TEMP;
   ss_info->string_length = string_length;
   ss_info->data.temp.type = type;
@@ -580,6 +587,7 @@  gfc_get_scalar_ss (gfc_ss *next, gfc_expr *expr)
   gfc_ss_info *ss_info;
 
   ss_info = gfc_get_ss_info ();
+  ss_info->refcount++;
   ss_info->type = GFC_SS_SCALAR;
   ss_info->expr = expr;
 
diff --git a/trans.h b/trans.h
index c35b1ae..02f2b42 100644
--- a/trans.h
+++ b/trans.h
@@ -185,6 +185,7 @@  gfc_ss_type;
 
 typedef struct gfc_ss_info
 {
+  int refcount;
   gfc_ss_type type;
   gfc_expr *expr;
   tree string_length;