[phc-internals] [phc] r3383 committed - On revision 3316, the bug of having the same name for different storag...

phc at googlecode.com phc at googlecode.com
Sun Oct 10 22:55:48 IST 2010


Revision: 3383
Author: logytech
Date: Sun Oct 10 14:54:40 2010
Log: On revision 3316, the bug of having the same name for different  
storage node was addressed. Unfortunately, this introduced another problem  
when a basic block that uses arrays is processed more than once by the same  
wpa iteraction. This has been fixed now by keeping track of every storage  
node number generated for each context.
http://code.google.com/p/phc/source/detail?r=3383

Added:
  /trunk/test/subjects/optimization/array_loop.php
Modified:
  /trunk/src/optimize/wpa/Whole_program.cpp
  /trunk/src/optimize/wpa/Whole_program.h

=======================================
--- /dev/null
+++ /trunk/test/subjects/optimization/array_loop.php	Sun Oct 10 14:54:40  
2010
@@ -0,0 +1,21 @@
+<?php
+
+  // This example is intended to show an array use
+  // inside a loop that it is processed more than once
+  // by the same wpa iteraction.
+  //
+  // The patch that fixed the bug of having the same name for
+  // multiple storage nodes (rev 3316) introduced a bug leading
+  // phc to  never converge when a basic block is processed more
+  // than once on the same wpa iteraction. This new bug has
+  // been fixed by revision 3383.
+
+  // This is not supposed to be a real sql query, since its
+  // missing the mysql_connect.
+  $getCol = mysql_query("SELECT * FROM db");
+
+  // Print the rows.
+  while ($row = mysql_fetch_row($getCol))
+    echo $row;
+
+?>
=======================================
--- /trunk/src/optimize/wpa/Whole_program.cpp	Tue Sep 21 07:16:01 2010
+++ /trunk/src/optimize/wpa/Whole_program.cpp	Sun Oct 10 14:54:40 2010
@@ -261,9 +261,6 @@
  	// This will be here for a while.
  	create_empty_storage (outer_cx, "array", "FAKE");

-	// First empty storage node should be assigned with name "array0".
-	next_storage_count = 0;
-
  	// False until we see otherwise
  	this->skip_after_die = false;
  }
@@ -1869,9 +1866,13 @@
  	return result;
  }

-int Whole_program::storage_count() {
-  next_storage_count = storage_counts.top();
-  return next_storage_count++;
+int Whole_program::get_storage_count(Context *ctx) {
+	if (not storage_counts.has(ctx)) {
+		// Next storage count will be update on finish_block accordingly.
+		storage_counts[ctx] = (block_storage_count = next_storage_count);
+	}
+
+	return block_storage_count++;
  }

  Context*
@@ -1917,6 +1918,10 @@
  	saved_is_refs.push (false);
  	saved_lhss.push (NULL);
  	saved_plhss.push (NULL);
+
+	// First empty storage node should be assigned with name "array0".
+	next_storage_count = 0;
+	block_storage_count = 0;
  }

  void
@@ -1933,6 +1938,8 @@
  	saved_is_refs.pop ();
  	saved_lhss.pop ();
  	saved_plhss.pop ();
+
+	storage_counts.clear();
  }


@@ -1944,14 +1951,16 @@
  		destroy_fake_indices (cx);

  	block_cxs.push (cx);
-
  	unique_counts.push (0);
-	storage_counts.push(next_storage_count);

  	// Blocks which arent assign_var need to see correct results here.
  	saved_is_refs.push (false);
  	saved_lhss.push (NULL);
  	saved_plhss.push (NULL);
+
+	// If the block has a storage count, use it.
+	if (storage_counts.has(cx))
+		block_storage_count = storage_counts[cx];
  }


@@ -1973,12 +1982,15 @@

  	if (pop)
  	{
-	  block_cxs.pop ();
-	  unique_counts.pop ();
-	  storage_counts.pop();
-	  saved_is_refs.pop ();
-	  saved_lhss.pop ();
-	  saved_plhss.pop ();
+		block_cxs.pop ();
+		unique_counts.pop ();
+		saved_is_refs.pop ();
+		saved_lhss.pop ();
+		saved_plhss.pop ();
+
+		// Update next_storage if block storage count surpass it.
+		if (block_storage_count > next_storage_count)
+			next_storage_count = block_storage_count;
  	}

  	if (pm->args_info->verbose_flag)
@@ -2972,7 +2984,7 @@
  	if (name == "")
  	{
  		// Use a - so that the convert_context_name hack doesnt get confused.
-		name = cx->storage_name (type + lexical_cast<string>(storage_count()));
+		name = cx->storage_name (type +  
lexical_cast<string>(get_storage_count(cx)));
  	}

  	Storage_node* st = SN (name);
=======================================
--- /trunk/src/optimize/wpa/Whole_program.h	Fri Aug 20 14:49:06 2010
+++ /trunk/src/optimize/wpa/Whole_program.h	Sun Oct 10 14:54:40 2010
@@ -123,9 +123,12 @@
  	/*
  	 * Empty storage counts.
  	 */
-	int next_storage_count; // Keep track of newly created empty storage  
nodes.
-	Stack<int> storage_counts;
-	int storage_count();
+	CX_map<int> storage_counts;
+
+	// Keep track of newly created empty storage nodes
+	// for the whole system and for each basic block.
+	int next_storage_count, block_storage_count;
+	int get_storage_count(Context *ctx);

  	/*
  	 * Block contexts.


More information about the phc-internals mailing list