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 
00047   typedef std::set<SgFunctionDefinition*> FunctionCallBoundarySet;
00048   typedef std::set<VariantT> CCxxKeywordsBoundarySet;
00049 
00050   SegmentGraph(FunctionCallBoundarySet function_boundaries);
00051   SegmentGraph(CCxxKeywordsBoundarySet keyword_boundaries);
00052   SegmentGraph(FunctionCallBoundarySet function_boundaries,
00053       CCxxKeywordsBoundarySet keyword_boundaries);
00054 
00060   void clean_graph();
00061 
00062 
00069   void print_graph(std::string filename);
00070 
00071 
00078   void print_graph_read_write_access(std::string filename);
00079 
00080 
00088   void add_function(Function *function, bool duplicate_segments = false);
00089 
00090   typedef std::set<VertexDescriptor> SegmentSet;
00091 
00097   void read_write_analysis_of_segments();
00098 
00104   void set_all_segments_to_untouched();
00105 
00106 private:
00107 
00108   bool static_analysis_;
00109 
00114   void handle_recursive_calls();
00115 
00116 
00129   void separate_variable_declaration_and_initializer_on_demand(
00130            SgBasicBlock *&bb, bool duplicate_segments);
00131 
00132 
00145   void decompose_expression_with_boundary_calls(SgExpression *expr,
00146            SgBasicBlock *&bb, bool duplicate_segments);
00147 
00148 
00155   void create_temp_variable_for_expression(SgExpression *expr,
00156            SgBasicBlock *&bb);
00157 
00158 
00164   std::string generate_unique_name(SgNode *node);
00165 
00166 
00173   bool is_boundary_stmt(SgStatement const * const current_stmt);
00174 
00175 
00181   SgFunctionCallExp* has_function_call_with_boundary(SgExpression *expr,
00182                          bool duplicate_segments);
00183 
00184 
00194   bool should_decompose_function(SgExpression *expr, bool duplicate_segments);
00195 
00196 
00208   SgFunctionDeclaration* contains_function_call_expression(SgExpression *expr);
00209 
00210 
00219   SegmentSet build_graph(
00220       SgStatement *current_stmt,
00221       SegmentSet current_segments,
00222       SegmentSet &break_segments,
00223       SegmentSet &continue_segments,
00224       bool duplicate_segments);
00225 
00226 
00235   void add_expression_to_segment(SegmentSet segments, SgNode *expr);
00236 
00237 
00242   CachedFunctionAstAttributes* build_segment_graph_for_function(
00243       SgFunctionDefinition *func_def, bool duplicate_segments);
00244 
00245 
00251   void insert_loop_edges(VertexDescriptor &loop_vertex,
00252            SegmentSet ¤t_segments,
00253            SegmentSet &continue_segments,
00254            SegmentSet &leaf_segments_of_loop);
00255 
00271   FunctionAnnotationAttributes* get_function_call_annotation(
00272       SgFunctionCallExp *func_call_exp);
00273 
00279   CachedFunctionAstAttributes*
00280   create_cached_function_attribute_for_annotated_function(
00281       SgNode* boundary_node,
00282       WAIT_CONSTRUCT wait_type,
00283       SegmentSet incoming_segments,
00284       bool is_conflict_free);
00285 
00295   void add_mapped_symbol_to_reference(SgFunctionCallExp *func_call,
00296            SgFunctionDefinition *func_def);
00297 
00305   void forward_reference_function_parameters(SgFunctionCallExp *func_call_exp);
00306 
00312   void mark_not_conflict_free_func_calls_in_segment(
00313            SgNode *stmt,
00314            SegmentSet segments);
00315 
00316 
00322   FunctionAnnotation*
00323   analyze_prepended_pragmas_for_annotation(SgFunctionDeclaration *func_decl);
00324 
00325   SegmentSet duplicate_segments(SegmentSet segments);
00326   SegmentSet duplicate_empty_segments(SegmentSet segments);
00327 
00328   FunctionCallBoundarySet function_boundaries_;
00329   CCxxKeywordsBoundarySet keyword_boundaries_;
00330 
00331   std::set<VertexDescriptor> recursive_function_calls_;
00332 
00337   static int counter;
00338 
00343   bool follow_function_call(SgFunctionDeclaration *func_decl);
00344 
00345 public:
00346 
00351   bool has_transition(int seg_id_from, int seg_id_to);
00352 
00357   VertexDescriptor id_to_vertex_descriptor(int seg_id);
00358 
00362   Graph graph_;
00363 
00368   std::set<VertexDescriptor> precached_function_segments_;
00369 
00374   std::set<SgFunctionCallExp*> port_calls_;
00375 
00376 
00380   bool is_succesfully_created_;
00381 };
00382 
00383 } 
00384 
00385 } 
00386 
00387 #endif 
00388 
00389