[phc-internals] [phc commit] r1802 - branches/dataflow/src/optimize

codesite-noreply at google.com codesite-noreply at google.com
Tue Oct 21 13:23:41 IST 2008


Author: paul.biggar
Date: Tue Oct 21 05:22:50 2008
New Revision: 1802

Modified:
    branches/dataflow/src/optimize/Basic_block.cpp
    branches/dataflow/src/optimize/CFG.cpp

Log:
The CFG graphs were difficult to read, so:

- standardize line breaks
- add breaks between PHIs, MUs and CHIs
- move the statement to the top of the block
- dont break the line for short properties (esp CHIs)
- adds the word CHI, MU and PHI for the properties
- move the block the PHI comes from to the end of the line (much more  
readable)


Modified: branches/dataflow/src/optimize/Basic_block.cpp
==============================================================================
--- branches/dataflow/src/optimize/Basic_block.cpp	(original)
+++ branches/dataflow/src/optimize/Basic_block.cpp	Tue Oct 21 05:22:50 2008
@@ -138,7 +138,6 @@
  			Rvalue* arg = edge->pm[phi_lhs]; // avoid assertion.

  			stringstream ss;
-			ss << "(" << cfg->index[edge->get_source()->vertex] << "): ";
  			if (arg)
  			{
  				if (isa<VARIABLE_NAME> (arg))
@@ -148,27 +147,33 @@
  			}
  			else
  				ss << "XXX"; // missing value.
+
+			ss << " (" << cfg->index[edge->get_source()->vertex] << ")";
  			

  			list.push_back (s (ss.str()));
  		}

-		result->push_back (make_pair (phi_lhs->get_ssa_var_name (), list));
+		stringstream name;
+		name << "PHI (" << *phi_lhs->get_ssa_var_name () << ")";
+		result->push_back (make_pair (s(name.str()), list));
  	}

-// Add muis:
-	
+	// XXX HACK: add a line break
+	if (mus->size() && result->size())
+		result->push_back (make_pair (s(""), *(new String_list)));
+
+	// Add mus:
  	foreach (VARIABLE_NAME* mu, *mus)
  	{
+		stringstream name;
+		name << "MU (" << *mu->get_ssa_var_name () << ")";
  		result->push_back (
  			make_pair (
-				s("MU"),
-				*(new List<String*> (
-					mu->get_ssa_var_name ()))));
+				s(name.str()),
+				*(new String_list)));
  	}

-//	if (live_in)
-//		result->push_back (make_pair (s("IN"), live_in));
  	return result;
  }

@@ -182,11 +187,13 @@
  	VARIABLE_NAME* rhs;
  	foreach (tie (lhs, rhs), *chis)
  	{
+		stringstream name;
+		name << "CHI (" << *lhs->get_ssa_var_name () << ")";
+
  		result->push_back (
  			make_pair (
-				s("CHI"),
-				*(new List<String*> (
-					lhs->get_ssa_var_name (),
+				s(name.str ()),
+				*(new String_list (
  					rhs->get_ssa_var_name ()))));
  	}


Modified: branches/dataflow/src/optimize/CFG.cpp
==============================================================================
--- branches/dataflow/src/optimize/CFG.cpp	(original)
+++ branches/dataflow/src/optimize/CFG.cpp	Tue Oct 21 05:22:50 2008
@@ -254,7 +254,6 @@
  		// headlabel and taillabel attributes dont expand the area they are
  		// in, and so are frequently unreadable.
  	}
-#define LINE_LENGTH 20
  	void operator()(std::ostream& out, const vertex_t& v) const
  	{
  		out << "[";
@@ -265,90 +264,80 @@

  		out << "label=\"";

-		// IN annotations
-		stringstream ss1;
-		pair<String*, list<String*> > props;
-		foreach (props, *vb[v]->get_graphviz_head_properties ())
-		{
-			if (props.second.size ())
-			{
-				ss1 << *props.first << " = [";
-				unsigned int line_count = 1;
-				foreach (String* str, props.second)
-				{
-					ss1 << *DOT_unparser::escape (str) << ", ";
-					if (ss1.str().size() > (LINE_LENGTH * line_count))
-					{
-						line_count++;
-						ss1 << "\\n";
-					}
-				}
-				ss1 << "]\\n";
-			}
-		}

  		// BB source
-		stringstream ss2;
-		ss2
+		out	
  			<< "(" << index[v] << ") "
  			<< *DOT_unparser::escape (vb[v]->get_graphviz_label ());

-		// BB properties
-		stringstream ss3;
-		foreach (props, *vb[v]->get_graphviz_bb_properties ())
+		// Annotations
+		String* head = unparse_properties (vb[v]->get_graphviz_head_properties  
());
+		String* main = unparse_properties (vb[v]->get_graphviz_bb_properties ());
+		String* tail = unparse_properties (vb[v]->get_graphviz_tail_properties  
());
+
+		// Blank line after source, if theres anything else
+
+		if (head->size()) out << "\\n\\n";
+		out << *head;
+
+		if (main->size()) out << "\\n\\n";
+		out << *main;
+
+		if (tail->size()) out << "\\n\\n";
+		out << *tail;
+		
+		out << "\"]";
+	}
+
+#define LINE_LENGTH 30
+	static String* unparse_properties (list<pair<String*, list<String*> > >*  
properties)
+	{
+		stringstream ss;
+		pair<String*, list<String*> > props;
+		foreach (props, *properties)
  		{
+			append (ss, *props.first);
  			if (props.second.size ())
  			{
-				ss3 << *props.first << " = [";
-				unsigned int line_count = 1;
+				append (ss, " = [");
  				foreach (String* str, props.second)
  				{
-					ss3 << *DOT_unparser::escape (str) << ", ";
-					if (ss3.str().size() > (LINE_LENGTH * line_count))
-					{
-						line_count++;
-						ss3 << "\\n";
-					}
+					append (ss, *DOT_unparser::escape (str));
+					if (str != props.second.back())
+						append (ss, ", ", false);
  				}
-				ss3 << "]\\n";
+				append (ss, "]", false);
  			}
+			append (ss, "\\n", false);
  		}

-		// OUT annotations
-		stringstream ss4;
-		foreach (props, *vb[v]->get_graphviz_tail_properties ())
+		return s(ss.str());
+	}
+
+	// Append STR to SS, adding a newline before it if the result will be too
+	// long.
+	static void append (stringstream& ss, string str, bool can_break = true)
+	{
+		// Add the \n at the start, or the next 'can_break' might start a line.
+		if (can_break)
  		{
-			if (props.second.size ())
-			{
-				ss4 << *props.first << " = [";
-				unsigned int line_count = 1;
-				foreach (String* str, props.second)
-				{
-					ss4 << *DOT_unparser::escape (str) << ", ";
-					if (ss4.str().size() > (LINE_LENGTH * line_count))
-					{
-						line_count++;
-						ss4 << "\\n";
-					}
-				}
-				ss4 << "]\\n";
-			}
-		}
+			// The only length that concerns us is between the lat newline in SS,
+			// and the first one in STR.
+			int newline_pos1 = ss.str().rfind ("\\n") + sizeof ("\\n");
+			if (newline_pos1 == string::npos)
+				newline_pos1 = ss.str().size();
+
+			int newline_pos2 = str.find ("\\n");
+			if (newline_pos2 == string::npos)
+				newline_pos2 = str.size();

-		// Print out all 4 stringstreams, with line-break;
-		out << ss1.str();
-		if (ss1.str().size())
-			out << "\\n"; // blank line before source
-		out << ss2.str();
-		if (ss3.str().size() || ss4.str().size())
-			out << "\\n\\n"; // blank line after source
-		out << ss3.str();
-		out << ss4.str();
-		if (ss3.str().size() || ss4.str().size())
-			out << "\b\b";
+			if ((ss.str().size() - newline_pos1) + newline_pos2 > LINE_LENGTH

-		
-		out << "\"]";
+				&& (newline_pos1 != ss.str().size())) // no point adding a \n to a \n  
just cause STR is too long
+				ss << "\\n";
+		}
+
+		ss << str;
  	}
  };



More information about the phc-internals mailing list