[phc-internals] [phc commit] r1474 - in branches/dataflow: . src/optimize

codesite-noreply at google.com codesite-noreply at google.com
Thu Jul 31 18:31:52 IST 2008


Author: paul.biggar
Date: Fri Jul 25 07:16:37 2008
New Revision: 1474

Added:
   branches/dataflow/src/optimize/Dead_code_elimination.cpp
   branches/dataflow/src/optimize/Dead_code_elimination.h
   branches/dataflow/src/optimize/Flow_visitor.h
      - copied, changed from r1467, /branches/dataflow/src/optimize/Backwards_flow_visitor.h
Removed:
   branches/dataflow/src/optimize/Backwards_flow_visitor.cpp
   branches/dataflow/src/optimize/Backwards_flow_visitor.h
Modified:
   branches/dataflow/Makefile.am
   branches/dataflow/Makefile.in
   branches/dataflow/src/optimize/Basic_block.cpp
   branches/dataflow/src/optimize/Basic_block.h
   branches/dataflow/src/optimize/Live_variable_analysis.cpp
   branches/dataflow/src/optimize/Live_variable_analysis.h

Log:
Forwards and backwards control flow are only slightly different, so 
this provides the direction as a template parameter. While its simple 
enough to stick with the inheritence model, it blows up when I try to 
have different classes with different behaviour (I wanted to add a 
sparse version, with empty default functions).

This reduces the amount of code, classes and files, and handles both 
forward and backwards analyses. It also adds a placeholder for DCE.


Modified: branches/dataflow/Makefile.am
==============================================================================
--- branches/dataflow/Makefile.am	(original)
+++ branches/dataflow/Makefile.am	Fri Jul 25 07:16:37 2008
@@ -146,16 +146,17 @@
 	src/lib/Object.h											\
 	src/lib/String.cpp										\
 	src/lib/String.h											\
-	src/optimize/Backwards_flow_visitor.cpp			\
-	src/optimize/Backwards_flow_visitor.h				\
 	src/optimize/Basic_block.cpp							\
 	src/optimize/Basic_block.h								\
 	src/optimize/CFG.cpp										\
 	src/optimize/CFG.h										\
 	src/optimize/Copy_propagation.cpp					\
 	src/optimize/Copy_propagation.h						\
+	src/optimize/Dead_code_elimination.cpp				\
+	src/optimize/Dead_code_elimination.h				\
 	src/optimize/Fix_point.cpp								\
 	src/optimize/Fix_point.h								\
+	src/optimize/Flow_visitor.h							\
 	src/optimize/Live_variable_analysis.cpp			\
 	src/optimize/Live_variable_analysis.h				\
 	src/optimize/Prune_symbol_table.cpp					\

Modified: branches/dataflow/Makefile.in
==============================================================================
--- branches/dataflow/Makefile.in	(original)
+++ branches/dataflow/Makefile.in	Fri Jul 25 07:16:37 2008
@@ -98,11 +98,11 @@
 	MIR_transform.lo MIR_visitor.lo php_parser.tab.lo \
 	HIR_lower_expr.lo Lower_control_flow.lo AttrMap.lo base64.lo \
 	Boolean.lo demangle.lo error.lo Integer.lo Object.lo String.lo \
-	Backwards_flow_visitor.lo Basic_block.lo CFG.lo \
-	Copy_propagation.lo Fix_point.lo Live_variable_analysis.lo \
-	Prune_symbol_table.lo Set.lo Use_def_counter.lo \
-	Parse_buffer.lo parse.lo PHP_context.lo XML_parser.lo \
-	Pass_manager.lo Plugin_pass.lo AST_unparser.lo \
+	Basic_block.lo CFG.lo Copy_propagation.lo \
+	Dead_code_elimination.lo Fix_point.lo \
+	Live_variable_analysis.lo Prune_symbol_table.lo Set.lo \
+	Use_def_counter.lo Parse_buffer.lo parse.lo PHP_context.lo \
+	XML_parser.lo Pass_manager.lo Plugin_pass.lo AST_unparser.lo \
 	Constant_folding.lo DOT_unparser.lo Invalid_check.lo \
 	Note_top_level_declarations.lo Process_includes.lo \
 	Remove_concat_null.lo Remove_parser_temporaries.lo \
@@ -676,16 +676,17 @@
 	src/lib/Object.h											\
 	src/lib/String.cpp										\
 	src/lib/String.h											\
-	src/optimize/Backwards_flow_visitor.cpp			\
-	src/optimize/Backwards_flow_visitor.h				\
 	src/optimize/Basic_block.cpp							\
 	src/optimize/Basic_block.h								\
 	src/optimize/CFG.cpp										\
 	src/optimize/CFG.h										\
 	src/optimize/Copy_propagation.cpp					\
 	src/optimize/Copy_propagation.h						\
+	src/optimize/Dead_code_elimination.cpp				\
+	src/optimize/Dead_code_elimination.h				\
 	src/optimize/Fix_point.cpp								\
 	src/optimize/Fix_point.h								\
+	src/optimize/Flow_visitor.h							\
 	src/optimize/Live_variable_analysis.cpp			\
 	src/optimize/Live_variable_analysis.h				\
 	src/optimize/Prune_symbol_table.cpp					\
@@ -1199,7 +1200,6 @@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/AST_unparser.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/AST_visitor.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/AttrMap.Plo at am__quote@
- at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/Backwards_flow_visitor.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/Basic_block.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/Boolean.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/CFG.Plo at am__quote@
@@ -1209,6 +1209,7 @@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/Constant_folding.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/Copy_propagation.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/DOT_unparser.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/Dead_code_elimination.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/Desugar.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/Early_lower_control_flow.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/Echo_split.Plo at am__quote@
@@ -1659,13 +1660,6 @@
  @AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) 
$(depcomp) @AMDEPBACKSLASH@
  @am__fastdepCXX_FALSE@	$(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) 
$(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) 
$(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o 
String.lo `test -f 'src/lib/String.cpp' || echo '$(srcdir)/'`src/lib/String.cpp

-Backwards_flow_visitor.lo: src/optimize/Backwards_flow_visitor.cpp
- at am__fastdepCXX_TRUE@	$(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) 
$(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) 
$(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT 
Backwards_flow_visitor.lo -MD -MP -MF 
$(DEPDIR)/Backwards_flow_visitor.Tpo -c -o Backwards_flow_visitor.lo 
`test -f 'src/optimize/Backwards_flow_visitor.cpp' || echo '$(srcdir)/'`src/optimize/Backwards_flow_visitor.cpp
- at am__fastdepCXX_TRUE@	mv -f $(DEPDIR)/Backwards_flow_visitor.Tpo $(DEPDIR)/Backwards_flow_visitor.Plo
- at AMDEP_TRUE@@am__fastdepCXX_FALSE@	
source='src/optimize/Backwards_flow_visitor.cpp' 
object='Backwards_flow_visitor.lo' libtool=yes @AMDEPBACKSLASH@
- at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) 
$(depcomp) @AMDEPBACKSLASH@
- at am__fastdepCXX_FALSE@	$(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) 
$(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) 
$(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o 
Backwards_flow_visitor.lo `test 
-f 'src/optimize/Backwards_flow_visitor.cpp' || echo '$(srcdir)/'`src/optimize/Backwards_flow_visitor.cpp
-
 Basic_block.lo: src/optimize/Basic_block.cpp
  @am__fastdepCXX_TRUE@	$(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) 
$(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) 
$(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT 
Basic_block.lo -MD -MP -MF $(DEPDIR)/Basic_block.Tpo -c -o 
Basic_block.lo `test -f 'src/optimize/Basic_block.cpp' || echo '$(srcdir)/'`src/optimize/Basic_block.cpp
 @am__fastdepCXX_TRUE@	mv -f $(DEPDIR)/Basic_block.Tpo $(DEPDIR)/Basic_block.Plo
@@ -1686,6 +1680,13 @@
  @AMDEP_TRUE@@am__fastdepCXX_FALSE@	
source='src/optimize/Copy_propagation.cpp' object='Copy_propagation.lo' 
libtool=yes @AMDEPBACKSLASH@
  @AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) 
$(depcomp) @AMDEPBACKSLASH@
  @am__fastdepCXX_FALSE@	$(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) 
$(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) 
$(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o 
Copy_propagation.lo `test -f 'src/optimize/Copy_propagation.cpp' || echo '$(srcdir)/'`src/optimize/Copy_propagation.cpp
+
+Dead_code_elimination.lo: src/optimize/Dead_code_elimination.cpp
+ at am__fastdepCXX_TRUE@	$(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) 
$(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) 
$(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT 
Dead_code_elimination.lo -MD -MP -MF 
$(DEPDIR)/Dead_code_elimination.Tpo -c -o Dead_code_elimination.lo 
`test -f 'src/optimize/Dead_code_elimination.cpp' || echo '$(srcdir)/'`src/optimize/Dead_code_elimination.cpp
+ at am__fastdepCXX_TRUE@	mv -f $(DEPDIR)/Dead_code_elimination.Tpo $(DEPDIR)/Dead_code_elimination.Plo
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	
source='src/optimize/Dead_code_elimination.cpp' 
object='Dead_code_elimination.lo' libtool=yes @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) 
$(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@	$(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) 
$(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) 
$(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o 
Dead_code_elimination.lo `test 
-f 'src/optimize/Dead_code_elimination.cpp' || echo '$(srcdir)/'`src/optimize/Dead_code_elimination.cpp

 Fix_point.lo: src/optimize/Fix_point.cpp
  @am__fastdepCXX_TRUE@	$(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) 
$(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) 
$(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT 
Fix_point.lo -MD -MP -MF $(DEPDIR)/Fix_point.Tpo -c -o Fix_point.lo 
`test -f 'src/optimize/Fix_point.cpp' || echo '$(srcdir)/'`src/optimize/Fix_point.cpp

Modified: branches/dataflow/src/optimize/Basic_block.cpp
==============================================================================
--- branches/dataflow/src/optimize/Basic_block.cpp	(original)
+++ branches/dataflow/src/optimize/Basic_block.cpp	Fri Jul 25 07:16:37 2008
@@ -1,5 +1,4 @@
 #include "Basic_block.h"
-#include "Backwards_flow_visitor.h"
 #include "process_ir/General.h"

 using namespace std;

Modified: branches/dataflow/src/optimize/Basic_block.h
==============================================================================
--- branches/dataflow/src/optimize/Basic_block.h	(original)
+++ branches/dataflow/src/optimize/Basic_block.h	Fri Jul 25 07:16:37 2008
@@ -2,13 +2,12 @@
 #define PHC_BASIC_BLOCK

 #include <boost/graph/properties.hpp>
+
 #include "MIR.h"
 #include "CFG.h"
 #include "Set.h"


-class Backwards_flow_visitor;
-
 /* Basic blocks */
 class Basic_block
 {
@@ -30,9 +29,6 @@
 	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*);

 public:
  	// TODO: these should be moved into a solution class, so that we can 
have 1 per analysis.

Added: branches/dataflow/src/optimize/Dead_code_elimination.cpp
==============================================================================

Added: branches/dataflow/src/optimize/Dead_code_elimination.h
==============================================================================
--- (empty file)
+++ branches/dataflow/src/optimize/Dead_code_elimination.h	Fri Jul 25 
07:16:37 2008
@@ -0,0 +1,56 @@
+/*
+ * phc -- the open source PHP compiler
+ * See doc/license/README.license for licensing information
+ *
+ * Dead-code elimination
+ */
+
+#include "pass_manager/Pass_manager.h"
+#include "Flow_visitor.h"
+
+#ifndef PHC_DEAD_CODE_ELIMINATION
+#define PHC_DEAD_CODE_ELIMINATION
+
+class Dead_code_elimination : public Pass, public Forwards_flow_visitor
+{
+public:
+	bool pass_is_enabled (Pass_manager* pm);
+	void run (IR::PHP_script* ir_script, Pass_manager* pm);
+	void run (CFG*);
+public:
+
+	void process_assign_var (Statement_block* sb, MIR::Assign_var*);
+
+	// TODO
+	// I dont want to have to overwrite these every time I write a pass.
+	// Define a "sparse_visitor", which odesn't require this.
+
+	// Transfer functions
+	void transfer_in (Basic_block* bb, list<Basic_block*>* preds);
+	void transfer_out (Basic_block* bb, list<Basic_block*>* succs);
+
+	// Local solution
+	void process_entry_block (Entry_block*) {}
+	void process_empty_block (Empty_block*) {}
+	void process_exit_block (Exit_block*) {}
+	void process_branch_block (Branch_block*);
+
+	void process_assign_array (Statement_block* sb, MIR::Assign_array*);
+	void process_assign_target (Statement_block* sb, MIR::Assign_target*);
+	void process_assign_var_var (Statement_block* sb, MIR::Assign_var_var*);
+	void process_eval_expr (Statement_block* sb, MIR::Eval_expr*);
+	void process_foreach_end (Statement_block* sb, MIR::Foreach_end*);
+	void process_foreach_next (Statement_block* sb, MIR::Foreach_next*);
+	void process_foreach_reset (Statement_block* sb, MIR::Foreach_reset*);
+	void process_global (Statement_block* sb, MIR::Global*);
+	void process_pre_op (Statement_block* sb, MIR::Pre_op*);
+	void process_push_array (Statement_block* sb, MIR::Push_array*);
+	void process_return (Statement_block* sb, MIR::Return*);
+	void process_static_declaration (Statement_block* sb, MIR::Static_declaration*);
+	void process_try (Statement_block* sb, MIR::Try*);
+	void process_throw (Statement_block* sb, MIR::Throw*);
+
+
+};
+
+#endif // PHC_DEAD_CODE_ELIMINATION

Copied: branches/dataflow/src/optimize/Flow_visitor.h (from r1467, /branches/dataflow/src/optimize/Backwards_flow_visitor.h)
==============================================================================
--- /branches/dataflow/src/optimize/Backwards_flow_visitor.h	(original)
+++ branches/dataflow/src/optimize/Flow_visitor.h	Fri Jul 25 07:16:37 2008
@@ -1,17 +1,55 @@
-#ifndef PHC_BACKWARDS_FLOW_VISITOR
-#define PHC_BACKWARDS_FLOW_VISITOR
+#ifndef PHC_FLOW_VISITOR
+#define PHC_FLOW_VISITOR

 #include "CFG.h"
 #include "Basic_block.h"
+#include "process_ir/General.h"

-class Backwards_flow_visitor
+enum Flow_visitor_direction { FORWARD_FLOW, BACKWARD_FLOW };
+template <Flow_visitor_direction Direction> class Flow_visitor;
+typedef class Flow_visitor<FORWARD_FLOW> Forwards_flow_visitor;
+typedef class Flow_visitor<BACKWARD_FLOW> Backwards_flow_visitor;
+
+
+template <Flow_visitor_direction Direction>
+class Flow_visitor
 {
 public:
-	void run (CFG* cfg);

-/* Public interface for analyses */
+	virtual void run (CFG* cfg)
+	{
+		foreach (Basic_block* bb, *cfg->get_all_bbs ())
+		{
+			bb->init_df ();
+			process_bb_local (bb);
+		}
+
+		// Add the exit block the worklist
+		list<Basic_block*> worklist;
+		worklist.push_back (cfg->get_exit_bb ());
+
+		// iterate until the worklist is no more
+		while (not worklist.empty ())
+		{
+			// Process the front block
+			Basic_block* bb = worklist.front ();
+			worklist.pop_front ();
+
+			cdebug << "process BB " << bb->vertex << endl;
+			process_transfer_functions (bb, cfg);
+
+			foreach (Basic_block* pred, *get_next_cfg_nodes (bb, cfg))
+				worklist.push_back (pred);
+
+			if (bb->should_reiterate ())
+				worklist.push_back (bb);
+		}
+	}
+
 public:

+	/* Public interface for analyses */
+
 	/* Transfer functions */
  	virtual void transfer_in (Basic_block* bb, list<Basic_block*>* preds) 
= 0;
  	virtual void transfer_out (Basic_block* bb, list<Basic_block*>* 
succs) = 0;
@@ -24,26 +62,131 @@
 	// TODO: any need for a process_statement_block?
 	
 	// Local solution - statements
-	virtual void process_assign_array (Statement_block* sb, 
MIR::Assign_array*) = 0;
-	virtual void process_assign_target (Statement_block* sb, 
MIR::Assign_target*) = 0;
-	virtual void process_assign_var (Statement_block* sb, 
MIR::Assign_var*) = 0;
-	virtual void process_assign_var_var (Statement_block* sb, 
MIR::Assign_var_var*) = 0;
-	virtual void process_eval_expr (Statement_block* sb, MIR::Eval_expr*) 
= 0;
-	virtual void process_foreach_end (Statement_block* sb, 
MIR::Foreach_end*) = 0;
-	virtual void process_foreach_next (Statement_block* sb, 
MIR::Foreach_next*) = 0;
-	virtual void process_foreach_reset (Statement_block* sb, 
MIR::Foreach_reset*) = 0;
-	virtual void process_global (Statement_block* sb, MIR::Global*) = 0;
-	virtual void process_pre_op (Statement_block* sb, MIR::Pre_op*) = 0;
-	virtual void process_push_array (Statement_block* sb, 
MIR::Push_array*) = 0;
-	virtual void process_return (Statement_block* sb, MIR::Return*) = 0;
-	virtual void process_static_declaration (Statement_block* sb, 
MIR::Static_declaration*) = 0;
-	virtual void process_throw (Statement_block* sb, MIR::Throw*) = 0;
-	virtual void process_try (Statement_block* sb, MIR::Try*) = 0;
+	virtual void process_assign_array (Statement_block*, 
MIR::Assign_array*) = 0;
+	virtual void process_assign_target (Statement_block*, 
MIR::Assign_target*) = 0;
+	virtual void process_assign_var (Statement_block*, MIR::Assign_var*) 
= 0;
+	virtual void process_assign_var_var (Statement_block*, 
MIR::Assign_var_var*) = 0;
+	virtual void process_eval_expr (Statement_block*, MIR::Eval_expr*) = 0;
+	virtual void process_foreach_end (Statement_block*, 
MIR::Foreach_end*) = 0;
+	virtual void process_foreach_next (Statement_block*, 
MIR::Foreach_next*) = 0;
+	virtual void process_foreach_reset (Statement_block*, 
MIR::Foreach_reset*) = 0;
+	virtual void process_global (Statement_block*, MIR::Global*) = 0;
+	virtual void process_pre_op (Statement_block*, MIR::Pre_op*) = 0;
+	virtual void process_push_array (Statement_block*, MIR::Push_array*) 
= 0;
+	virtual void process_return (Statement_block*, MIR::Return*) = 0;
+	virtual void process_static_declaration (Statement_block*, 
MIR::Static_declaration*) = 0;
+	virtual void process_throw (Statement_block*, MIR::Throw*) = 0;
+	virtual void process_try (Statement_block*, MIR::Try*) = 0;

 private:
 	/* Dispatcher for BBs */
-	void process_bb (Basic_block* bb, CFG* cfg);
+	void process_bb_local (Basic_block* bb)
+	{
+		/* Calculate the local solution */
+		if (Entry_block* eb = dynamic_cast<Entry_block*> (bb))
+			process_entry_block (eb);
+
+		else if (Empty_block* eb = dynamic_cast<Empty_block*> (bb))
+			process_empty_block (eb);
+
+		else if (Exit_block* eb = dynamic_cast<Exit_block*> (bb))
+			process_exit_block (eb);
+
+		else if (Branch_block* brb = dynamic_cast<Branch_block*> (bb))
+			process_branch_block (brb);
+
+		else if (Statement_block* sb = dynamic_cast<Statement_block*> (bb))
+		{
+			switch (sb->statement->classid ())
+			{
+				case MIR::Assign_array::ID:
+					process_assign_array(sb, dyc<MIR::Assign_array>(sb->statement));
+					break;
+				case MIR::Assign_target::ID:
+					process_assign_target(sb, dyc<MIR::Assign_target>(sb->statement));
+					break;
+				case MIR::Assign_var::ID:
+					process_assign_var(sb, dyc<MIR::Assign_var>(sb->statement));
+					break;
+				case MIR::Assign_var_var::ID:
+					process_assign_var_var(sb, dyc<MIR::Assign_var_var>(sb->statement));
+					break;
+				case MIR::Eval_expr::ID:
+					process_eval_expr(sb, dyc<MIR::Eval_expr>(sb->statement));
+					break;
+				case MIR::Foreach_end::ID:
+					process_foreach_end(sb, dyc<MIR::Foreach_end>(sb->statement));
+					break;
+				case MIR::Foreach_next::ID:
+					process_foreach_next(sb, dyc<MIR::Foreach_next>(sb->statement));
+					break;
+				case MIR::Foreach_reset::ID:
+					process_foreach_reset(sb, dyc<MIR::Foreach_reset>(sb->statement));
+					break;
+				case MIR::Global::ID:
+					process_global(sb, dyc<MIR::Global>(sb->statement));
+					break;
+				case MIR::Pre_op::ID:
+					process_pre_op(sb, dyc<MIR::Pre_op>(sb->statement));
+					break;
+				case MIR::Push_array::ID:
+					process_push_array(sb, dyc<MIR::Push_array>(sb->statement));
+					break;
+				case MIR::Return::ID:
+					process_return(sb, dyc<MIR::Return>(sb->statement));
+					break;
+				case MIR::Static_declaration::ID:
+					process_static_declaration(sb, dyc<MIR::Static_declaration>(sb->statement));
+					break;
+				case MIR::Throw::ID:
+					process_throw(sb, dyc<MIR::Throw>(sb->statement));
+					break;
+				case MIR::Try::ID:
+					process_try(sb, dyc<MIR::Try>(sb->statement));
+					break;
+				default:
+					assert (0);
+			}
+		}
+	}
+
+	/* Directional analyses */
+
+	virtual void process_transfer_functions (Basic_block* bb, CFG* cfg);
+	virtual list<Basic_block*>* get_next_cfg_nodes (Basic_block* bb, CFG* cfg);;
+
+
+};
+
+template<>
+class Flow_visitor<FORWARD_FLOW>
+{
+	list<Basic_block*>* get_next_cfg_nodes (Basic_block* bb, CFG* cfg)
+	{
+		return cfg->get_successors (bb);
+	}
+
+	void process_transfer_functions (Basic_block* bb, CFG* cfg)
+	{
+//		transfer_in (bb, cfg->get_predecessors (bb));
+//		transfer_out (bb, cfg->get_successors (bb));
+	}
+};
+
+template<>
+class Flow_visitor<BACKWARD_FLOW>
+{
+	list<Basic_block*>* get_next_cfg_nodes (Basic_block* bb, CFG* cfg)
+	{
+		return cfg->get_predecessors (bb);
+	}
+
+	void process_transfer_functions (Basic_block* bb, CFG* cfg)
+	{
+//		transfer_out (bb, cfg->get_successors (bb));
+//		transfer_in (bb, cfg->get_predecessors (bb));
+	}
 };


-#endif // PHC_BACKWARDS_FLOW_VISITOR
+#endif // PHC_FLOW_VISITOR

Modified: branches/dataflow/src/optimize/Live_variable_analysis.cpp
==============================================================================
--- branches/dataflow/src/optimize/Live_variable_analysis.cpp	(original)
+++ branches/dataflow/src/optimize/Live_variable_analysis.cpp	Fri Jul 
25 07:16:37 2008
@@ -6,6 +6,7 @@
  */

 #include "Live_variable_analysis.h"
+#include "Dead_code_elimination.h"
 #include "CFG.h"
 #include "process_ir/General.h"
 #include "cmdline.h"
@@ -36,10 +37,10 @@
 		CFG* cfg = new CFG ();
 		cfg->add_statements (method->statements);
 		cfg->dump_graphviz (s("BEFORE DCE"));
-		Backwards_flow_visitor::run (cfg);
+		run (cfg);
 		cfg->dump_graphviz (s("AFTER DCE"));
-//		Dead_code_elimination* dce = new Dead_code_elimination;
-//		dce->run (cfg);
+		Dead_code_elimination* dce = new Dead_code_elimination;
+		dce->run (cfg);
 	}
 }


Modified: branches/dataflow/src/optimize/Live_variable_analysis.h
==============================================================================
--- branches/dataflow/src/optimize/Live_variable_analysis.h	(original)
+++ branches/dataflow/src/optimize/Live_variable_analysis.h	Fri Jul 25 
07:16:37 2008
@@ -6,10 +6,10 @@
  */

 #include "pass_manager/Pass_manager.h"
-#include "Backwards_flow_visitor.h"
+#include "Flow_visitor.h"

-#ifndef LIVE_VARIABLE_ANALYSIS
-#define LIVE_VARIABLE_ANALYSIS
+#ifndef PHC_LIVE_VARIABLE_ANALYSIS
+#define PHC_LIVE_VARIABLE_ANALYSIS

 class Live_variable_analysis : public Pass, public Backwards_flow_visitor
 {
@@ -17,6 +17,7 @@
 	Live_variable_analysis ();
 	bool pass_is_enabled (Pass_manager* pm);
 	void run (IR::PHP_script* ir_script, Pass_manager* pm);
+	void run (CFG*);
 public:

 	// Transfer functions
@@ -47,4 +48,4 @@

 };

-#endif // LIVE_VARIABLE_ANALYSIS
+#endif // PHC_LIVE_VARIABLE_ANALYSIS


More information about the phc-internals mailing list