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 "rose.h"
00013
00014 #include "edge.h"
00015 #include "function_annotation.h"
00016 #include "segment.h"
00017
00018
00019 namespace risc {
00020
00021 class Function;
00022
00023 namespace sg {
00024
00025 class SegmentGraph;
00026
00027 typedef boost::adjacency_list<boost::listS,
00028 boost::listS, boost::bidirectionalS, Segment, Edge,
00029 boost::property<boost::vertex_index_t, int> > Graph;
00030 typedef boost::graph_traits<Graph>::vertex_descriptor VertexDescriptor;
00031 typedef boost::graph_traits<Graph>::edge_descriptor EdgeDescriptor;
00032
00033 typedef boost::graph_traits<risc::sg::Graph>::vertex_iterator VertexIterator;
00034
00035 class FunctionAnnotationAttributes;
00036 class CachedFunctionAstAttributes;
00037
00043 class SegmentGraph {
00044
00045 public:
00046 typedef std::set<SgFunctionDefinition*> FunctionCallBoundarySet;
00047 typedef std::set<VariantT> CCxxKeywordsBoundarySet;
00048
00049 SegmentGraph(FunctionCallBoundarySet function_boundaries);
00050 SegmentGraph(CCxxKeywordsBoundarySet keyword_boundaries);
00051 SegmentGraph(FunctionCallBoundarySet function_boundaries,
00052 CCxxKeywordsBoundarySet keyword_boundaries);
00053
00059 void clean_graph();
00060
00061
00068 void print_graph(std::string filename);
00069
00070
00077 void print_graph_read_write_access(std::string filename);
00078
00079
00087 void add_function(Function *function, bool duplicate_segments = false);
00088
00089 typedef std::set<VertexDescriptor> SegmentSet;
00090
00096 void read_write_analysis_of_segments();
00097
00103 void set_all_segments_to_untouched();
00104
00105 private:
00106
00107 bool static_analysis_;
00108
00113 void handle_recursive_calls();
00114
00115
00128 void separate_variable_declaration_and_initializer_on_demand(
00129 SgBasicBlock *&bb, bool duplicate_segments);
00130
00131
00144 void decompose_expression_with_boundary_calls(SgExpression *expr,
00145 SgBasicBlock *&bb, bool duplicate_segments);
00146
00147
00154 void create_temp_variable_for_expression(SgExpression *expr,
00155 SgBasicBlock *&bb);
00156
00157
00163 std::string generate_unique_name(SgNode *node);
00164
00165
00172 bool is_boundary_stmt(SgStatement const * const current_stmt);
00173
00174
00180 SgFunctionCallExp* has_function_call_with_boundary(SgExpression *expr,
00181 bool duplicate_segments);
00182
00183
00193 bool should_decompose_function(SgExpression *expr, bool duplicate_segments);
00194
00195
00207 SgFunctionDeclaration* contains_function_call_expression(SgExpression *expr);
00208
00209
00218 SegmentSet build_graph(
00219 SgStatement *current_stmt,
00220 SegmentSet current_segments,
00221 SegmentSet &break_segments,
00222 SegmentSet &continue_segments,
00223 bool duplicate_segments);
00224
00225
00234 void add_expression_to_segment(SegmentSet segments, SgNode *expr);
00235
00236
00241 CachedFunctionAstAttributes* build_segment_graph_for_function(
00242 SgFunctionDefinition *func_def, bool duplicate_segments);
00243
00244
00250 void insert_loop_edges(VertexDescriptor &loop_vertex,
00251 SegmentSet ¤t_segments,
00252 SegmentSet &continue_segments,
00253 SegmentSet &leaf_segments_of_loop);
00254
00270 FunctionAnnotationAttributes* get_function_call_annotation(
00271 SgFunctionCallExp *func_call_exp);
00272
00278 CachedFunctionAstAttributes*
00279 create_cached_function_attribute_for_annotated_function(
00280 SgNode* boundary_node,
00281 WAIT_CONSTRUCT wait_type,
00282 SegmentSet incoming_segments);
00283
00293 void add_mapped_symbol_to_reference(SgFunctionCallExp *func_call,
00294 SgFunctionDefinition *func_def);
00295
00303 void forward_reference_function_parameters(SgFunctionCallExp *func_call_exp);
00304
00305 FunctionAnnotation*
00306 analyze_prepended_pragmas_for_annotation(SgFunctionDeclaration *func_decl);
00307
00308 SegmentSet duplicate_segments(SegmentSet segments);
00309 SegmentSet duplicate_empty_segments(SegmentSet segments);
00310
00311 FunctionCallBoundarySet function_boundaries_;
00312 CCxxKeywordsBoundarySet keyword_boundaries_;
00313
00314 std::set<VertexDescriptor> recursive_function_calls_;
00315
00320 static int counter;
00321
00322 public:
00323
00324 Graph graph_;
00325
00326 std::set<VertexDescriptor> precached_function_segments_;
00327 };
00328
00329 }
00330
00331 }
00332
00333 #endif
00334
00335