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
00066 void get_wait_and_notifying_events();
00067
00074 void find_module_segments();
00075
00082 void print_psg_file(std::string file_name);
00083
00091 void read_psg_from_file(std::string);
00092
00093
00102 void replace_partial_function_call_nodes();
00103
00116 void integrate_psg_into_sg(VertexDescriptor, SgSymbol *);
00117
00123 void remove_dangling_segments();
00124
00134 std::vector<std::string> channel_seg_id_array_names_;
00135
00140 std::set<VertexDescriptor> port_call_seg_vertexs_;
00141
00148 std::vector<std::pair<VertexDescriptor, SgSymbol *> >
00149 vertexID_symbol_pairs_of_partialFuncCallNodes_;
00150
00155 std::map< SgSymbol * , std::vector<VertexDescriptor> >
00156 func_symbols_and_entrance_segVertex_;
00157
00162 std::map< SgSymbol * , std::vector<VertexDescriptor> >
00163 func_symbols_and_exit_segVertex_;
00164
00169 int total_segment_nodes_;
00170
00176 void clean_graph();
00177
00178
00185 void print_graph(std::string filename);
00186
00187
00194 void print_graph_read_write_access(std::string filename);
00195
00196
00206 void add_function(
00207 Thread *originating_thread,
00208 Function *function,
00209 bool duplicate_segments = false,
00210 bool is_simulation_process = true,
00211 std::string module_name = "");
00212
00218 void read_write_analysis_of_segments();
00219
00225 void set_all_segments_to_untouched();
00226
00227 private:
00228
00229 bool static_analysis_;
00230
00235 void handle_recursive_calls();
00236
00237
00250 void separate_variable_declaration_and_initializer_on_demand(
00251 SgBasicBlock *&bb, bool duplicate_segments, PortCallPath pcp);
00252
00253
00266 void decompose_expression_with_boundary_calls(SgExpression *expr,
00267 SgBasicBlock *&bb, bool duplicate_segments, PortCallPath pcp);
00268
00269
00276 void create_temp_variable_for_expression(SgExpression *expr,
00277 SgBasicBlock *&bb);
00278
00279
00285 std::string generate_unique_name(SgNode *node);
00286
00292 std::string generate_unique_name(std::string);
00293
00294
00301 bool is_boundary_stmt(SgStatement const * const current_stmt);
00302
00303
00309 SgFunctionCallExp* has_function_call_with_boundary(SgExpression *expr,
00310 bool duplicate_segments, PortCallPath pcp);
00311
00312
00322 bool should_decompose_function(SgExpression *expr, bool duplicate_segments,
00323 PortCallPath pcp);
00324
00325
00337 SgFunctionDeclaration* contains_function_call_expression(SgExpression *expr);
00338
00339
00348 SegmentSet build_graph(
00349 SgStatement *current_stmt,
00350 SegmentSet current_segments,
00351 SegmentSet &break_segments,
00352 SegmentSet &continue_segments,
00353 bool duplicate_segments,
00354 PortCallPath pcp);
00355
00356
00365 void add_expression_to_segment(SegmentSet segments, SgNode *expr,
00366 PortCallPath pcp);
00367
00368
00373 CachedFunctionAstAttributes*
00374 build_segment_graph_for_function(
00375 SgFunctionDefinition *func_def,
00376 bool duplicate_segments,
00377 PortCallPath pcp);
00378
00379
00385 void insert_loop_edges(VertexDescriptor &loop_vertex,
00386 SegmentSet ¤t_segments,
00387 SegmentSet &continue_segments,
00388 SegmentSet &leaf_segments_of_loop);
00389
00405 FunctionAnnotationAttributes* get_function_call_annotation(
00406 SgFunctionCallExp *func_call_exp);
00407
00413 CachedFunctionAstAttributes*
00414 create_cached_function_attribute_for_annotated_function(
00415 SgNode* boundary_node,
00416 WAIT_CONSTRUCT wait_type,
00417 SegmentSet incoming_segments,
00418 bool is_conflict_free,
00419 PortCallPath pcp);
00420
00430 void add_mapped_symbol_to_reference(SgFunctionCallExp *func_call,
00431 SgFunctionDefinition *func_def);
00432
00440 void forward_reference_function_parameters(SgFunctionCallExp *func_call_exp);
00441
00447 void mark_not_conflict_free_func_calls_in_segment(
00448 SgNode *stmt,
00449 SegmentSet segments);
00450
00451
00457 FunctionAnnotation*
00458 analyze_prepended_pragmas_for_annotation(SgFunctionDeclaration *func_decl);
00459
00460 SegmentSet duplicate_segments(SegmentSet segments);
00461 SegmentSet duplicate_empty_segments(SegmentSet segments);
00462
00463 FunctionCallBoundarySet function_boundaries_;
00464 CCxxKeywordsBoundarySet keyword_boundaries_;
00465
00466 std::set<VertexDescriptor> recursive_function_calls_;
00467
00472 static int counter;
00473
00478 bool follow_function_call(SgFunctionDeclaration *func_decl);
00479
00480 public:
00481
00486 bool has_transition(int seg_id_from, int seg_id_to);
00487
00492 VertexDescriptor id_to_vertex_descriptor(int seg_id);
00493
00497 Graph graph_;
00498
00503 std::set<VertexDescriptor> precached_function_segments_;
00504
00509 std::set<SgFunctionCallExp*> port_calls_;
00510
00511
00515 bool is_succesfully_created_;
00516 };
00517
00518 }
00519
00520 }
00521
00522 #endif
00523
00524