[phc-internals] [phc commit] r2586 - Fix crash in def_use.

codesite-noreply at google.com codesite-noreply at google.com
Tue May 5 17:39:26 IST 2009


Author: paul.biggar
Date: Tue May  5 09:38:06 2009
New Revision: 2586

Modified:
    branches/dataflow/src/optimize/wpa/Context.cpp
    branches/dataflow/src/optimize/wpa/Def_use.cpp
    branches/dataflow/src/optimize/wpa/Optimization_transformer.cpp
    branches/dataflow/src/optimize/wpa/WPA_lattice.cpp
    branches/dataflow/src/optimize/wpa/Whole_program.cpp

Log:
Fix crash in def_use.
Record uses in bin_ops.
Check that results are actually folded.
The regexes used to fix up contexts were, predicatably, fragile. This  
handles names like mandel_/0/4/2::ABV
Handle merging of WPA_lattice names.


Modified: branches/dataflow/src/optimize/wpa/Context.cpp
==============================================================================
--- branches/dataflow/src/optimize/wpa/Context.cpp	(original)
+++ branches/dataflow/src/optimize/wpa/Context.cpp	Tue May  5 09:38:06 2009
@@ -176,29 +176,35 @@
  string
  Context::convert_context_name (string name)
  {
-	// If it starts with "array_" or "object_", we want the last BB ID, its a
-	// heap allocation, and we want its last BB ID.
  	string BB_ID = "/\\d+";
  	string all_IDs = "(" + BB_ID + ")+";
  	string all_but_one = all_IDs + "(" + BB_ID + ")";

-   boost::regex re1 ("(array|object)_" + all_but_one);
+
+	// If it starts with "array_" or "object_", we want the last BB ID, its a
+	// heap allocation, and we want its last BB ID.
+   boost::regex re1 ("(array|object)_" + all_but_one + "(.*)");
     if (boost::regex_match (name, re1))
  	{
-		return boost::regex_replace (name, re1, "\\1\\3");
+		string result = boost::regex_replace (name, re1, "\\1\\3\\4");
+//		cdebug << "RE1 matches: " << name << " -> " << result << "\n";
+		return result;
  	}


  	// Remove other BB IDs
-   boost::regex re2("([^/]+)" + all_IDs);
+   boost::regex re2("([^/]+)" + all_IDs + "(.*)");
     if (boost::regex_match (name, re2))
  	{
-		return boost::regex_replace (name, re2, "\\1");
+		string result = boost::regex_replace (name, re2, "\\1\\3");
+//		cdebug << "RE2 matches: " << name << " -> " << result << "\n";
+		return result;
  	}

-
  	
  	// Otherwise, just leave it
+
+//	cdebug << "No matches: " << name << "\n";
  	return name;
  }


Modified: branches/dataflow/src/optimize/wpa/Def_use.cpp
==============================================================================
--- branches/dataflow/src/optimize/wpa/Def_use.cpp	(original)
+++ branches/dataflow/src/optimize/wpa/Def_use.cpp	Tue May  5 09:38:06 2009
@@ -83,7 +83,7 @@
  	Set<Context> all_contexts;

  	typedef Map<Context, Set<Alias_name> > x; // fool foreach
-	x* all_sets[12] =
+	x* all_sets[6] =
  	{
  		&ref_defs, &ref_uses, &ref_may_defs, &val_defs, &val_uses, &val_may_defs,
  	};

Modified: branches/dataflow/src/optimize/wpa/Optimization_transformer.cpp
==============================================================================
--- branches/dataflow/src/optimize/wpa/Optimization_transformer.cpp	 
(original)
+++ branches/dataflow/src/optimize/wpa/Optimization_transformer.cpp	Tue  
May  5 09:38:06 2009
@@ -133,7 +133,11 @@
  {
  	Literal* lit = dynamic_cast <Literal*> (get_literal (bb,  
in->variable_name));
  	if (lit)
-		bb->statement = new Assign_var (in->variable_name, PHP::fold_pre_op  
(lit, in->op));
+	{
+		Literal* folded = PHP::fold_pre_op (lit, in->op);
+		assert (folded);
+		dyc<Assign_var> (bb->statement)->rhs = folded;
+	}
  }

  void
@@ -196,10 +200,13 @@
  	// If they're both literals, we can replace them with the new value.
  	if (isa<Literal> (in->left) && isa<Literal> (in->right))
  	{
-		dyc<Assign_var> (bb->statement)->rhs = PHP::fold_bin_op (
+		Literal* folded = PHP::fold_bin_op (
  				dyc<Literal> (in->left),
  				in->op,
  				dyc<Literal> (in->right));
+
+		if (folded)
+			dyc<Assign_var> (bb->statement)->rhs = folded;
  	}
  }

@@ -216,7 +223,9 @@
  		&& *in->cast->value != "array"
  		&& *in->cast->value != "object")
  	{
-		dyc<Assign_var> (bb->statement)->rhs = PHP::cast_to (in->cast,  
dyc<Literal> (rhs));
+		Literal* folded = PHP::cast_to (in->cast, dyc<Literal> (rhs));
+		if (folded)
+			dyc<Assign_var> (bb->statement)->rhs = folded;
  	}
  }

@@ -335,9 +344,9 @@
  	// If they're both literals, we can replace them with the new value.
  	if (isa<Literal> (rval))
  	{
-		dyc<Assign_var> (bb->statement)->rhs = PHP::fold_unary_op (
-				in->op,
-				dyc<Literal> (rval));
+		Literal* folded = PHP::fold_unary_op (in->op, dyc<Literal> (rval));
+		if (folded)
+			dyc<Assign_var> (bb->statement)->rhs = folded;
  	}
  }


Modified: branches/dataflow/src/optimize/wpa/WPA_lattice.cpp
==============================================================================
--- branches/dataflow/src/optimize/wpa/WPA_lattice.cpp	(original)
+++ branches/dataflow/src/optimize/wpa/WPA_lattice.cpp	Tue May  5 09:38:06  
2009
@@ -180,22 +180,45 @@
  	CX_lattices new_ins;
  	foreach (tie (cx, map), ins)
  	{
-		new_ins[cx.get_non_contextual ()].merge (&map);
+		// Each map needs its key's names changed.
+		Lattice_map newmap;
+
+		string str;
+		Lattice_cell* cell;
+		foreach (tie (str, cell), map)
+		{
+			str = Context::convert_context_name (str);
+
+			// There may be multiple cells for the same name.
+			newmap[str] = meet (newmap[str], cell);
+		}
+
+		// The context needs to change names too.
+		new_ins[cx.get_non_contextual ()].merge (&newmap);
  	}
-	ins.clear ();
  	ins = new_ins;

-
+	// TODO: remove code duplication
  	CX_lattices new_outs;
  	foreach (tie (cx, map), outs)
  	{
-		new_outs[cx.get_non_contextual ()].merge (&map);
-	}
-	outs.clear ();
-	outs = new_outs;
+		// Each map needs its key's names changed.
+		Lattice_map newmap;
+
+		string str;
+		Lattice_cell* cell;
+		foreach (tie (str, cell), map)
+		{
+			str = Context::convert_context_name (str);

+			// There may be multiple cells for the same name.
+			newmap[str] = meet (newmap[str], cell);
+		}

-	// TODO ST contexts still arent merged!
+		// The context needs to change names too.
+		new_outs[cx.get_non_contextual ()].merge (&newmap);
+	}
+	outs = new_outs;
  }



Modified: branches/dataflow/src/optimize/wpa/Whole_program.cpp
==============================================================================
--- branches/dataflow/src/optimize/wpa/Whole_program.cpp	(original)
+++ branches/dataflow/src/optimize/wpa/Whole_program.cpp	Tue May  5  
09:38:06 2009
@@ -1865,7 +1865,15 @@
  		return;
  	}

-	// TODO: record uses
+	// Record uses
+	if (not isa<Literal_cell> (left->lit))
+		record_use (block_cx, VN (ns, dyc<VARIABLE_NAME> (in->left)));
+
+	if (not isa<Literal_cell> (right->lit))
+		record_use (block_cx, VN (ns, dyc<VARIABLE_NAME> (in->right)));
+
+
+

  	Types types = type_inf->get_bin_op_types (block_cx, left, right,  
*in->op->value);



More information about the phc-internals mailing list