00001 #ifndef SEGMENT_GRAPH_H_INCLUDED_
00002 #define SEGMENT_GRAPH_H_INCLUDED_
00003
00004 #include<iostream>
00005 #include<set>
00006 #include<utility>
00007
00008 #include<boost/graph/adjacency_list.hpp>
00009 #include<boost/graph/graphviz.hpp>
00010 #include<boost/algorithm/string.hpp>
00011
00012 #include "../internal_representation/function.h"
00013 #include "segment.h"
00014 #include "edge.h"
00015
00016 namespace risc {
00017
00018 namespace sg {
00019
00020 class SegmentGraph;
00021
00022 typedef boost::adjacency_list<boost::listS,
00023 boost::listS, boost::bidirectionalS, Segment, Edge,
00024 boost::property<boost::vertex_index_t, int> > Graph;
00025 typedef boost::graph_traits<Graph>::vertex_descriptor VertexDescriptor;
00026 typedef boost::graph_traits<Graph>::edge_descriptor EdgeDescriptor;
00027
00028 typedef boost::graph_traits<risc::sg::Graph>::vertex_iterator VertexIterator;
00029
00030 class CachedFunctionAstAttributes;
00031
00037 class SegmentGraph {
00038
00039 public:
00040 typedef std::set<SgFunctionDefinition*> FunctionCallBoundarySet;
00041 typedef std::set<VariantT> CCxxKeywordsBoundarySet;
00042
00043 SegmentGraph(FunctionCallBoundarySet function_boundaries);
00044 SegmentGraph(CCxxKeywordsBoundarySet keyword_boundaries);
00045 SegmentGraph(FunctionCallBoundarySet function_boundaries,
00046 CCxxKeywordsBoundarySet keyword_boundaries);
00047
00053 void clean_graph();
00054
00055
00062 void print_graph(std::string filename);
00063
00064
00071 void print_graph_read_write_access(std::string filename);
00072
00073
00081 void add_function(Function *function, bool duplicate_segments = false);
00082
00083 typedef std::set<VertexDescriptor> SegmentSet;
00084
00090 void read_write_analysis_of_segments();
00091
00097 void set_all_segments_to_untouched();
00098
00099 private:
00100
00105 void handle_recursive_calls();
00106
00107
00120 void separate_variable_declaration_and_initializer_on_demand(
00121 SgBasicBlock *&bb, bool duplicate_segments);
00122
00123
00136 void decompose_expression_with_boundary_calls(SgExpression *expr,
00137 SgBasicBlock *&bb, bool duplicate_segments);
00138
00139
00146 void create_temp_variable_for_expression(SgExpression *expr,
00147 SgBasicBlock *&bb);
00148
00149
00163 SgExpression* decompose_member_function_calls(SgFunctionCallExp *func_call,
00164 SgBasicBlock *&bb);
00165
00166
00172 std::string generate_unique_name(SgNode *node);
00173
00174
00181 bool is_boundary_stmt(SgStatement const * const current_stmt);
00182
00183
00189 SgFunctionCallExp* has_function_call_with_boundary(SgExpression *expr,
00190 bool duplicate_segments);
00191
00192
00202 bool should_decompose_function(SgExpression *expr);
00203
00204
00216 SgFunctionDeclaration* contains_function_call_expression(SgExpression *expr);
00217
00218
00227 SegmentSet build_graph(
00228 SgStatement *current_stmt,
00229 SegmentSet current_segments,
00230 SegmentSet &break_segments,
00231 SegmentSet &continue_segments,
00232 bool duplicate_segments);
00233
00234
00243 void add_expression_to_segment(SegmentSet segments, SgNode *expr);
00244
00245
00250 CachedFunctionAstAttributes* build_segment_graph_for_function(
00251 SgFunctionDefinition *func_def, bool duplicate_segments);
00252
00253
00259 void insert_loop_edges(VertexDescriptor &loop_vertex,
00260 SegmentSet ¤t_segments,
00261 SegmentSet &continue_segments,
00262 SegmentSet &leaf_segments_of_loop);
00263
00264 SegmentSet duplicate_segments(SegmentSet segments);
00265 SegmentSet duplicate_empty_segments(SegmentSet segments);
00266
00267 FunctionCallBoundarySet function_boundaries_;
00268 CCxxKeywordsBoundarySet keyword_boundaries_;
00269
00270 std::set<VertexDescriptor> recursive_function_calls_;
00271
00272 static int counter;
00273 public:
00274 Graph graph_;
00275
00276 std::set<VertexDescriptor> precached_function_segments_;
00277 };
00278
00279 }
00280
00281 }
00282
00283 #endif
00284
00285