00001 #ifndef SEGMENT_GRAPH_H_INCLUDED_
00002 #define SEGMENT_GRAPH_H_INCLUDED_
00003
00004 #include<iostream>
00005 #include<map>
00006 #include<set>
00007 #include<utility>
00008
00009 #include "boost/graph/adjacency_list.hpp"
00010 #include "boost/graph/graphviz.hpp"
00011 #include "boost/algorithm/string.hpp"
00012 #include "../internal_representation/module.h"
00013
00014 #include "rose.h"
00015
00016 #include "edge.h"
00017 #include "function_annotation.h"
00018 #include "port_call_path.h"
00019 #include "segment.h"
00020
00021
00022 #define DBG_SHOW(name,id) std::cout<<"\n\ndebug id: "<< id<<" "<<#name<<" : \n"<<name->unparseToString()<<std::endl;
00023 namespace risc {
00024
00025 class Function;
00026
00027 namespace sg {
00028
00029 class SegmentGraph;
00030
00031 typedef boost::adjacency_list<boost::listS,
00032 boost::listS, boost::bidirectionalS, Segment, Edge,
00033 boost::property<boost::vertex_index_t, int> > Graph;
00034 typedef boost::graph_traits<Graph>::vertex_descriptor VertexDescriptor;
00035 typedef boost::graph_traits<Graph>::edge_descriptor EdgeDescriptor;
00036
00037 typedef boost::graph_traits<risc::sg::Graph>::vertex_iterator VertexIterator;
00038
00039 class FunctionAnnotationAttributes;
00040 class CachedFunctionAstAttributes;
00041
00047 class SegmentGraph {
00048
00049 public:
00050
00051 typedef std::set<SgFunctionDefinition*> FunctionCallBoundarySet;
00052 typedef std::set<VariantT> CCxxKeywordsBoundarySet;
00053
00054 SegmentGraph();
00055 SegmentGraph(FunctionCallBoundarySet function_boundaries);
00056 SegmentGraph(CCxxKeywordsBoundarySet keyword_boundaries);
00057 SegmentGraph(FunctionCallBoundarySet function_boundaries,
00058 CCxxKeywordsBoundarySet keyword_boundaries);
00059 typedef std::set<VertexDescriptor> SegmentSet;
00060
00061 void get_wait_and_notifying_events();
00062 void find_module_segments(std::vector<Module*>& module_definitions_);
00063 void print_psg_file(std::string file_name);
00064 void read_psg_from_file(std::string);
00065 void write_psg_attributes(std::string);
00066 void replace_function_call_vertex_with_its_psg();
00067 void remove_dangling_segments();
00068 void integrate_psg_into_sg(VertexDescriptor, SgSymbol *);
00069 void count_segments_that_belongs_to_certain_psg();
00070
00071
00072 std::vector<std::pair<VertexDescriptor, SgSymbol *> > function_call_segments;
00073 std::map< SgSymbol * , std::vector<VertexDescriptor> > map_of_function_name_and_starting_segments;
00074 std::map< SgSymbol * , std::vector<VertexDescriptor> > map_of_function_name_and_ending_segments;
00075 std::vector<SgExprStatement*> vector_of_statements_which_contain_non_defining_func_calls;
00076 std::map<std::string, SegmentSet> map_of_function_name_and_leaving_segments_id_to_be_stored_into_a_psg_file;
00077 std::map<std::string, VertexDescriptor> map_of_function_name_and_starting_segments_id_to_be_stored_into_a_psg_file;
00078 std::set<VertexDescriptor> first_segments;
00079 std::map<VertexDescriptor, int> is_psg_first_segment_touched;
00080 std::map<VertexDescriptor, std::vector<VertexDescriptor> > psg_segments;
00081 std::map<int,int> count_of_segments_that_belongs_to_certain_psg;
00082
00088 void clean_graph();
00089
00090
00097 void print_graph(std::string filename);
00098
00099
00106 void print_graph_read_write_access(std::string filename);
00107
00108
00118 void add_function(Function *function, bool duplicate_segments = false, bool is_simulation_process = true, std::string module_name = "");
00119
00120
00121
00127 void read_write_analysis_of_segments();
00128
00134 void set_all_segments_to_untouched();
00135
00136 private:
00137
00138 bool static_analysis_;
00139
00144 void handle_recursive_calls();
00145
00146
00159 void separate_variable_declaration_and_initializer_on_demand(
00160 SgBasicBlock *&bb, bool duplicate_segments, PortCallPath pcp);
00161
00162
00175 void decompose_expression_with_boundary_calls(SgExpression *expr,
00176 SgBasicBlock *&bb, bool duplicate_segments, PortCallPath pcp);
00177
00178
00185 void create_temp_variable_for_expression(SgExpression *expr,
00186 SgBasicBlock *&bb);
00187
00188
00194 std::string generate_unique_name(SgNode *node);
00195
00196
00203 bool is_boundary_stmt(SgStatement const * const current_stmt);
00204
00205
00211 SgFunctionCallExp* has_function_call_with_boundary(SgExpression *expr,
00212 bool duplicate_segments, PortCallPath pcp);
00213
00214
00224 bool should_decompose_function(SgExpression *expr, bool duplicate_segments,
00225 PortCallPath pcp);
00226
00227
00239 SgFunctionDeclaration* contains_function_call_expression(SgExpression *expr);
00240
00241
00250 SegmentSet build_graph(
00251 SgStatement *current_stmt,
00252 SegmentSet current_segments,
00253 SegmentSet &break_segments,
00254 SegmentSet &continue_segments,
00255 bool duplicate_segments,
00256 PortCallPath pcp);
00257
00258
00267 void add_expression_to_segment(SegmentSet segments, SgNode *expr,
00268 PortCallPath pcp);
00269
00270
00275 CachedFunctionAstAttributes*
00276 build_segment_graph_for_function(
00277 SgFunctionDefinition *func_def,
00278 bool duplicate_segments,
00279 PortCallPath pcp);
00280
00281
00287 void insert_loop_edges(VertexDescriptor &loop_vertex,
00288 SegmentSet ¤t_segments,
00289 SegmentSet &continue_segments,
00290 SegmentSet &leaf_segments_of_loop);
00291
00307 FunctionAnnotationAttributes* get_function_call_annotation(
00308 SgFunctionCallExp *func_call_exp);
00309
00315 CachedFunctionAstAttributes*
00316 create_cached_function_attribute_for_annotated_function(
00317 SgNode* boundary_node,
00318 WAIT_CONSTRUCT wait_type,
00319 SegmentSet incoming_segments,
00320 bool is_conflict_free,
00321 PortCallPath pcp);
00322
00332 void add_mapped_symbol_to_reference(SgFunctionCallExp *func_call,
00333 SgFunctionDefinition *func_def);
00334
00342 void forward_reference_function_parameters(SgFunctionCallExp *func_call_exp);
00343
00349 void mark_not_conflict_free_func_calls_in_segment(
00350 SgNode *stmt,
00351 SegmentSet segments);
00352
00353
00359 FunctionAnnotation*
00360 analyze_prepended_pragmas_for_annotation(SgFunctionDeclaration *func_decl);
00361
00362 SegmentSet duplicate_segments(SegmentSet segments);
00363 SegmentSet duplicate_empty_segments(SegmentSet segments);
00364
00365 FunctionCallBoundarySet function_boundaries_;
00366 CCxxKeywordsBoundarySet keyword_boundaries_;
00367
00368 std::set<VertexDescriptor> recursive_function_calls_;
00369
00374 static int counter;
00375
00380 bool follow_function_call(SgFunctionDeclaration *func_decl);
00381
00382 public:
00383
00388 bool has_transition(int seg_id_from, int seg_id_to);
00389
00394 VertexDescriptor id_to_vertex_descriptor(int seg_id);
00395
00399 Graph graph_;
00400
00405 std::set<VertexDescriptor> precached_function_segments_;
00406
00411 std::set<SgFunctionCallExp*> port_calls_;
00412
00413
00417 bool is_succesfully_created_;
00418 };
00419
00420 }
00421
00422 }
00423
00424 #endif
00425
00426