00001 /* Super Graph Region Dataflow Solver */ 00002 00003 /* Copyright (c) 1999 Stanford University 00004 00005 All rights reserved. 00006 00007 This software is provided under the terms described in 00008 the "suif_copyright.h" include file. */ 00009 00010 #include "common/suif_copyright.h" 00011 00012 #ifndef REGION_SOLVER_H 00013 #define REGION_SOLVER_H 00014 00015 00016 #include "super_graph/super_graph_forwarders.h" 00017 #include "sgraph/sgraph_forwarders.h" 00018 #include "ion/ion_forwarders.h" 00019 #include "dflowsolver_forwarders.h" 00020 00021 00022 00023 class SDWork { 00024 bool _is_changed; // only dependant on the exits. 00025 SuperGraphRegion *_region; 00026 SGraphNodeList *_worklist; // work list of non-entry, non exit 00027 list<SuperGraphRegion*> *_subregion_work; // sub-regions to do 00028 SGraphNodeList *_backedge_work; // list of backedges that need work. 00029 SGraphNodeList *_region_exit_work; // list of this regions exits that 00030 // need work 00031 public: 00032 SDWork(SuperGraphRegion *region); 00033 ~SDWork(); 00034 00035 bool empty_worklist() const; 00036 void add_work(SGraphNode node, bool is_back); 00037 SGraphNode pop_work(bool is_back); 00038 00039 // Add all of the successors to the worklist 00040 void add_successor_work(SGraphNode node, bool is_back); 00041 00042 bool empty_exit_work() const; 00043 void add_exit_work(SGraphNode node); 00044 SGraphNode pop_exit_work(); 00045 00046 bool empty_subregion_work() const; 00047 void add_subregion_work(SuperGraphRegion *region); 00048 SuperGraphRegion *pop_subregion_work(); 00049 00050 bool empty_backedge_work() const; 00051 void add_backedge_work(SGraphNode node); 00052 SGraphNode pop_backedge_work(); 00053 00054 private: 00055 /* override stupid defaults, don't implement these */ 00056 SDWork &operator=(const SDWork &); 00057 SDWork(const SDWork &); 00058 }; 00059 00060 00061 class SDSolver { 00062 SuperGraph *_graph; 00063 typedef suif_vector<SDValue *> sd_value_vector; 00064 00065 sd_value_vector *_node_in_value; // value at node input 00066 sd_value_vector *_node_out_value; // value at node output 00067 00068 // stuff for the workflow algorithm 00069 bool _is_changed; 00070 suif_vector<SDWork*> *_workstack; 00071 00072 public: 00073 00074 SDSolver(SuperGraph *graph); 00075 virtual ~SDSolver(); 00076 00077 SuperGraph *get_graph() const; 00078 // initialize the in and out values to the TOP value. 00079 // Frequently we use NULL for TOP. Saves space 00080 // but requires more complex solver functions. 00081 00082 void init_solver_to_top(); // all nodes set to top. 00083 void init_solver(const SDValue &top_value); 00084 00085 // initialize the entries to the specified region 00086 // to the init_value 00087 void init_region_entries(SuperGraphRegion *region, 00088 const SDValue &init_value); 00089 00090 // region with the given value. 00091 void init_entries(const SDValue &init_value); // Initialize entry to the top region 00092 00093 // iterate region and sub-regions until solved. 00094 // After iteration, we may need to iterate on the outer 00095 // Return true if the exit values have changed. 00096 virtual bool solve_region(SuperGraphRegion *region); 00097 00107 virtual bool merge_input_values(SGraphNode node); 00108 00109 virtual bool apply_transfer(SGraphNode) = 0; 00110 virtual bool apply_region_exit_transfer(SGraphNode) = 0; 00111 virtual bool apply_subregion_entry_transfer(SuperGraphRegion *) = 0; 00112 00113 virtual void print(ion *the_ion); 00114 00115 // Access to the data 00116 const SDValue &get_out_val(SGraphNode node) const; 00117 const SDValue &get_in_val(SGraphNode node) const; 00118 00119 // perform a lub meet on the current value and the new value 00120 bool lub_meet_out_val(SGraphNode node, const SDValue &val); 00121 bool lub_meet_in_val(SGraphNode node, const SDValue &val); 00122 00123 SDValue &get_mod_out_val(SGraphNode node); 00124 SDValue &get_mod_in_val(SGraphNode node); 00125 00126 bool is_in_val_top(SGraphNode node) const; 00127 bool is_out_val_top(SGraphNode node) const; 00128 00129 void set_in_val_top(SGraphNode node); 00130 void set_out_val_top(SGraphNode node); 00131 00132 // copy 00133 void set_in_val(SGraphNode node, const SDValue &val); 00134 void set_out_val(SGraphNode node, const SDValue &val); 00135 00136 private: 00137 // override stupid defaults, don't implement these 00138 SDSolver &operator=(const SDSolver &); 00139 SDSolver(const SDSolver &); 00140 }; 00141 00142 00143 #endif /* REGION_SOLVER_H */