[phc-internals] [phc commit] r1471 - branches/dataflow/src/optimize
codesite-noreply at google.com
codesite-noreply at google.com
Thu Jul 31 18:27:39 IST 2008
Author: paul.biggar
Date: Thu Jul 24 14:28:00 2008
New Revision: 1471
Modified:
branches/dataflow/src/optimize/Basic_block.cpp
branches/dataflow/src/optimize/Basic_block.h
branches/dataflow/src/optimize/CFG.cpp
branches/dataflow/src/optimize/Set.cpp
branches/dataflow/src/optimize/Set.h
Log:
Add the contents of the sets to the CFG print-out.
Modified: branches/dataflow/src/optimize/Basic_block.cpp
==============================================================================
--- branches/dataflow/src/optimize/Basic_block.cpp (original)
+++ branches/dataflow/src/optimize/Basic_block.cpp Thu Jul 24 14:28:00 2008
@@ -2,10 +2,22 @@
#include "Backwards_flow_visitor.h"
#include "process_ir/General.h"
+using namespace std;
+
/* Constructors */
+
+Basic_block::Basic_block()
+{
+ defs = new Set();
+ uses = new Set();
+ live_in = new Set();
+ live_out = new Set();
+}
+
Branch_block::Branch_block (MIR::Branch* b)
: branch (b)
{
+
}
Statement_block::Statement_block (MIR::Statement* s)
@@ -13,10 +25,12 @@
{
}
-String*
+list<pair<String*,String*> >*
Basic_block::get_graphviz_properties ()
{
- return NULL;
+ list<pair<String*,String*> >* result = new list<pair<String*,String*> >;
+ assert (0);
+ return result;
}
/* Labels for graphviz */
@@ -50,10 +64,15 @@
return s(ss.str());
}
-String*
+list<pair<String*,String*> >*
Branch_block::get_graphviz_properties ()
{
- return s("shape=\"rectangle\"");
+ list<pair<String*,String*> >* result =
+ Basic_block::get_graphviz_properties ();
+
+ result->push_back (pair<String*,String*> (s("shape"), s("rectangle")));
+
+ return result;
}
@@ -74,4 +93,34 @@
uses = new Set;
live_in = new Set;
live_out = new Set;
+}
+
+
+list<std::pair<String*,Set*> >*
+Basic_block::get_graphviz_bb_properties ()
+{
+ list<pair<String*,Set*> >* result = new list<std::pair<String*,Set*> >;
+ if (defs)
+ result->push_back (pair<String*, Set*> (s("defs"), defs));
+ if (uses)
+ result->push_back (pair<String*, Set*> (s("uses"), uses));
+ return result;
+}
+
+list<std::pair<String*,Set*> >*
+Basic_block::get_graphviz_head_properties ()
+{
+ list<std::pair<String*,Set*> >* result = new
list<std::pair<String*,Set*> >;
+ if (live_out)
+ result->push_back (pair<String*, Set*> (s("OUT"), live_out));
+ return result;
+}
+
+list<std::pair<String*,Set*> >*
+Basic_block::get_graphviz_tail_properties ()
+{
+ list<std::pair<String*,Set*> >* result = new
list<std::pair<String*,Set*> >;
+ if (live_in)
+ result->push_back (pair<String*, Set*> (s("IN"), live_in));
+ return result;
}
Modified: branches/dataflow/src/optimize/Basic_block.h
==============================================================================
--- branches/dataflow/src/optimize/Basic_block.h (original)
+++ branches/dataflow/src/optimize/Basic_block.h Thu Jul 24 14:28:00 2008
@@ -13,6 +13,8 @@
class Basic_block
{
public:
+ Basic_block();
+
// Indicate to BGL that this represents a vertex internal property.
typedef boost::vertex_property_tag kind;
vertex_t vertex;
@@ -21,7 +23,13 @@
virtual String* get_graphviz_label () = 0;
// Override if there are extra properties for this block.
- virtual String* get_graphviz_properties ();
+ // Returns a list of (name,value) pairs
+ virtual list<std::pair<String*,String*> >* get_graphviz_properties ();
+
+ // Returns a list of (name, list[values]) pairs
+ virtual list<std::pair<String*,Set*> >* get_graphviz_bb_properties ();
+ virtual list<std::pair<String*,Set*> >* get_graphviz_head_properties ();
+ virtual list<std::pair<String*,Set*> >* get_graphviz_tail_properties ();
// Process this block using the passed analysis
bool process (Backwards_flow_visitor*);
@@ -60,8 +68,8 @@
public:
MIR::Branch* branch;
Branch_block (MIR::Branch* b);
- virtual String* get_graphviz_label ();
- virtual String* get_graphviz_properties ();
+ String* get_graphviz_label ();
+ list<std::pair<String*,String*> >* get_graphviz_properties ();
};
Modified: branches/dataflow/src/optimize/CFG.cpp
==============================================================================
--- branches/dataflow/src/optimize/CFG.cpp (original)
+++ branches/dataflow/src/optimize/CFG.cpp Thu Jul 24 14:28:00 2008
@@ -189,18 +189,81 @@
}
void operator()(std::ostream& out, const edge_t& v) const
{
- // No edges properties
// TODO add true and false for Branches
+
+ // Head and tail annotatations are done in the vertex, because the
+ // headlabel and taillabel attributes dont expand the area they are
+ // in, and so are frequently unreadable.
}
void operator()(std::ostream& out, const vertex_t& v) const
{
- out << " [label=\"" << *DOT_unparser::escape
(vb[v]->get_graphviz_label ()) << "\"";
- String* prop = vb[v]->get_graphviz_properties ();
- if (prop)
- out << ", " << *prop << " ";
+ out << "[label=\"";
+
+ // IN annotations
+ pair<String*, Set*> props;
+ stringstream ss1;
+ foreach (props, *vb[v]->get_graphviz_head_properties ())
+ {
+ if (props.second->bs.size ())
+ {
+ ss1 << *props.first << " = [";
+ foreach (string str, props.second->bs)
+ {
+ ss1 << str << ", ";
+ }
+ ss1 << "]\\n";
+ }
+ }
+
+ // BB source
+ stringstream ss2;
+ ss2 << *DOT_unparser::escape (vb[v]->get_graphviz_label ());
+
+ // BB properties
+ stringstream ss3;
+ foreach (props, *vb[v]->get_graphviz_bb_properties ())
+ {
+ if (props.second->bs.size ())
+ {
+ ss3 << *props.first << " = [";
+ foreach (string str, props.second->bs)
+ {
+ ss3 << str << ", ";
+ }
+ ss3 << "]\\n";
+ }
+ }
+
+ // OUT annotations
+ stringstream ss4;
+ foreach (props, *vb[v]->get_graphviz_tail_properties ())
+ {
+ if (props.second->bs.size ())
+ {
+ ss4 << *props.first << " = [";
+ foreach (string str, props.second->bs)
+ {
+ ss4 << str << ", ";
+ }
+ ss4 << "]\\n";
+ }
+ }
+
+ // 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";
+
- out << "]";
+ out << "\"]";
}
};
Modified: branches/dataflow/src/optimize/Set.cpp
==============================================================================
--- branches/dataflow/src/optimize/Set.cpp (original)
+++ branches/dataflow/src/optimize/Set.cpp Thu Jul 24 14:28:00 2008
@@ -5,6 +5,7 @@
#include "Set.h"
Set::Set()
+: bs()
{
}
Modified: branches/dataflow/src/optimize/Set.h
==============================================================================
--- branches/dataflow/src/optimize/Set.h (original)
+++ branches/dataflow/src/optimize/Set.h Thu Jul 24 14:28:00 2008
@@ -6,7 +6,7 @@
class Set
{
-private:
+public:
// Backing store
set<string> bs;
More information about the phc-internals
mailing list