All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
segment_graph.h
Go to the documentation of this file.
1 #ifndef SEGMENT_GRAPH_H_INCLUDED_
2 #define SEGMENT_GRAPH_H_INCLUDED_
3 
4 #include<iostream>
5 #include<map>
6 #include<set>
7 #include<utility>
8 
9 #include "boost/graph/adjacency_list.hpp"
10 #include "boost/graph/graphviz.hpp"
11 #include "boost/algorithm/string.hpp"
12 #include "../internal_representation/module.h"
13 
14 #include "rose.h"
15 
16 #include "edge.h"
17 #include "function_annotation.h"
18 #include "port_call_path.h"
19 #include "segment.h"
20 
21 
22 #define DBG_SHOW(name,id) std::cout<<"\n\ndebug id: "<< id<<" "<<#name<<" : \n"<<name->unparseToString()<<std::endl;
23 namespace risc {
24 
25 class Function;
26 
27 namespace sg {
28 
30 
31 typedef boost::adjacency_list<boost::listS, // list (not vector!) of vertices (RD)
32  boost::listS, boost::bidirectionalS, Segment, Edge,
33  boost::property<boost::vertex_index_t, int> > Graph;
34 typedef boost::graph_traits<Graph>::vertex_descriptor VertexDescriptor; // ends up as 'void*' (RD)
35 typedef boost::graph_traits<Graph>::vertex_iterator VertexIterator; // ends up as 'void*' (RD)
36 typedef boost::graph_traits<Graph>::edge_descriptor EdgeDescriptor;
37 
40 
46 struct SegmentCmp {
47  bool operator()( // comparison of two VertexDescriptors
48  const VertexDescriptor lhs,
49  const VertexDescriptor rhs) const
50  {
51 // return lhs < rhs; // this would be the default behavior, comparing 2 pointers;
52  // because that's non-deterministic over multiple program runs,
53  // we compare instead the segment IDs (12/15/18, RD)
54 
55  Graph *FakeGraphHandle = NULL; // we only need this type, not the value!
56  // (the VertexDescriptors are 'void*' pointers,
57  // allowing direct access to the vertices
58  // without knowing the specific Graph object;
59  // this works only for a _list_ of vertices)
60 
61 // printf("DEBUG: SegmentCmp(lhs=%p, rhs=%p) lhs.id=%d, rhs.id=%d, lhs.node_id=%d, rhs.node_id=%d\n",
62 // lhs, rhs,
63 // (*FakeGraphHandle)[lhs].id_, (*FakeGraphHandle)[rhs].id_,
64 // (*FakeGraphHandle)[lhs].node_id_, (*FakeGraphHandle)[rhs].node_id_);
65 // assert((*FakeGraphHandle)[lhs].id_ == (*FakeGraphHandle)[rhs].id_ ?
66 // lhs == rhs : true); // this fails in PSG cases
67  assert((*FakeGraphHandle)[lhs].node_id_ == (*FakeGraphHandle)[rhs].node_id_ ?
68  lhs == rhs : true); // this holds true even for PSG segments
69 
70  return (*FakeGraphHandle)[lhs].node_id_ < (*FakeGraphHandle)[rhs].node_id_;
71  }
72 };
73 
79 class SegmentGraph {
80 
81 public:
82 
83  typedef std::set<SgFunctionDefinition*> FunctionCallBoundarySet;
84  typedef std::set<VariantT> CCxxKeywordsBoundarySet;
85 
86  SegmentGraph();
87  SegmentGraph(FunctionCallBoundarySet function_boundaries);
88  SegmentGraph(CCxxKeywordsBoundarySet keyword_boundaries);
89  SegmentGraph(FunctionCallBoundarySet function_boundaries,
90  CCxxKeywordsBoundarySet keyword_boundaries);
91 
92  typedef std::set<VertexDescriptor, // RD's new one (deterministic order by segment IDs)
93  SegmentCmp> SegmentSet; // (comparison performed by SegmentCmp above)
94 
101 
108  void find_module_segments();
109 
116  void print_psg_file(std::string file_name);
117 
125  void read_psg_from_file(std::string file_name);
126 
127 
136 
149  void integrate_psg_into_sg(VertexDescriptor func_call_vertex_id, SgSymbol * func_sym);
150 
157 
167  std::vector<std::string> channel_seg_id_array_names_;
168 
173  std::set<VertexDescriptor> port_call_seg_vertexs_;
174 
181  std::vector<std::pair<VertexDescriptor, SgSymbol *> >
183 
188  std::map< SgSymbol * , std::vector<VertexDescriptor> >
190 
195  std::map< SgSymbol * , std::vector<VertexDescriptor> >
197 
203 
209  void clean_graph();
210 
211 
218  void print_graph(std::string filename);
219 
220 
227  void print_graph_read_write_access(std::string filename);
228 
229 
244  void add_function(
245  Thread *originating_thread,
246  Function *function,
247  bool duplicate_segments = false,
248  bool is_simulation_process = true,
249  std::string module_name = "");
250 
251  //DM 05/20/2019 same as add_function with extra functionality for sc_method
266  void add_function_method(
267  Thread *originating_thread,
268  Function *function,
269  bool duplicate_segments = false,
270  bool is_simulation_process = true,
271  std::string module_name = "");
272 
279 
286 
287 private:
288 
294 
299  void handle_recursive_calls();
300 
301 
316  SgBasicBlock *&bb, bool duplicate_segments, PortCallPath pcp);
317 
318 
335  void decompose_expression_with_boundary_calls(SgExpression *expr,
336  SgBasicBlock *&bb, bool duplicate_segments, PortCallPath pcp,
337  int stmt_type = 0, SgStatement* parent = NULL,
338  SgBasicBlock* body = NULL);
339 
349  void create_temp_variable_for_expression(SgExpression *expr,
350  SgBasicBlock *&bb,
351  int stmt_type = 0, SgStatement* parent = NULL,
352  SgBasicBlock* body = NULL);
353 
359  std::string generate_unique_name(SgNode *node);
360 
366  std::string generate_unique_name(std::string);
367 
368 
375  bool is_boundary_stmt(SgStatement const * const current_stmt);
376 
377 
384  SgFunctionCallExp* has_function_call_with_boundary(SgExpression *expr,
385  bool duplicate_segments, PortCallPath pcp);
386 
387 
398  bool should_decompose_function(SgExpression *expr, bool duplicate_segments,
399  PortCallPath pcp, bool is_condition= false);
400 
401 
413  SgFunctionDeclaration* contains_function_call_expression(SgExpression *expr);
414 
415 
435  SgStatement *current_stmt,
436  SegmentSet current_segments,
437  SegmentSet &break_segments,
438  SegmentSet &continue_segments,
439  bool duplicate_segments,
440  PortCallPath pcp);
441 
442 
453  void add_expression_to_segment(SegmentSet segments, SgNode *expr,
454  PortCallPath pcp);
455 
456 
467  SgFunctionDefinition *func_def,
468  bool duplicate_segments,
469  PortCallPath pcp,
470  bool is_registered_b_transport = false);
471 
472 
481  void insert_loop_edges(VertexDescriptor &loop_vertex,
482  SegmentSet &current_segments,
483  SegmentSet &continue_segments,
484  SegmentSet &leaf_segments_of_loop);
485 
503  SgFunctionCallExp *func_call_exp);
504 
517  SgNode* boundary_node,
518  WAIT_CONSTRUCT wait_type,
519  SegmentSet incoming_segments,
520  bool is_conflict_free,
521  PortCallPath pcp);
522 
533  void add_mapped_symbol_to_reference(SgFunctionCallExp *func_call,
534  SgFunctionDefinition *func_def);
535 
543  SgFunctionCallExp *func_call,
544  SgVariableDefinition* socket);
545 
557  SgFunctionCallExp *func_call,
558  SgFunctionDefinition *func_def,
559  SgVariableDefinition *socket);
560 
561 
570  SgFunctionCallExp *func_call,
571  SgFunctionDefinition *func_def,
572  SgVariableDefinition *socket);
573 
582  SgFunctionCallExp *func_call,
583  SgFunctionDefinition *func_def,
584  SgVariableDefinition *socket);
585 
586 
594  void forward_reference_function_parameters(SgFunctionCallExp *func_call_exp);
595 
604  SgNode *stmt,
605  SegmentSet segments);
606 
607 
614  analyze_prepended_pragmas_for_annotation(SgFunctionDeclaration *func_decl);
615 
623 
632 
637 
642 
646  std::set<VertexDescriptor> recursive_function_calls_;
647 
652  static int counter;
653 
658  bool follow_function_call(SgFunctionDeclaration *func_decl);
659 
669  SgFunctionDeclaration *func_decl,
670  bool duplicate_segments,
671  PortCallPath pcp
672  );
673 
674 
675 
676 public:
684 
689  bool has_transition(int seg_id_from, int seg_id_to);
690 
696 
701 
706  std::set<VertexDescriptor> precached_function_segments_;
707 
712  std::set<SgFunctionCallExp*> port_calls_;
713 
714 
719 
724  std::unordered_map<SgFunctionDeclaration*,
725  std::vector<int> >
727 
732  std::unordered_map<SgFunctionCallExp*, //socket_x->b_transport(..)
733  std::vector<int> > // <socket id, offset to be instrumented before the bt>
735 
736  std::unordered_set<SgFunctionCallExp*> b_transport_calls_;
737 
741  std::unordered_set<SgVariableSymbol*> Tlm2_containers_;
742 };
743 
744 } // end of namespace sg
745 
746 } // end of namespace risc
747 
748 #endif /* SEGMENT_GRAPH_H_INCLUDED_ */
749 
750 /* ex: set softtabstop=2 tabstop=2 shiftwidth=2 expandtab: */
void print_graph_read_write_access(std::string filename)
This function prints all variables which have read or written in this segment.
Definition: segment_graph.cpp:142
Definition: function_annotation.h:53
This class represents a segment graph for a process.
Definition: segment_graph.h:79
void get_wait_and_notifying_events()
set the wait_events_ and notify_events_ for psg nodes under psg mode
Definition: segment_graph.cpp:195
void separate_variable_declaration_and_initializer_on_demand(SgBasicBlock *&bb, bool duplicate_segments, PortCallPath pcp)
This function checks if a direct or indirect boundary call is in the initializer expression of the va...
Definition: segment_graph.cpp:5360
Definition: thread.h:21
boost::graph_traits< Graph >::vertex_iterator VertexIterator
Definition: segment_graph.h:35
SgFunctionDeclaration * contains_function_call_expression(SgExpression *expr)
In this function we look for expressions which contain a function call in the following style: foo();...
Definition: segment_graph.cpp:5128
void replace_partial_function_call_nodes()
for each partial function call node, calls integrate_psg_into_sg to replace the node with correspondi...
Definition: segment_graph.cpp:612
std::unordered_set< SgVariableSymbol * > Tlm2_containers_
including generic payload and dmi
Definition: segment_graph.h:741
boost::graph_traits< Graph >::vertex_descriptor VertexDescriptor
Definition: segment_graph.h:34
std::set< VertexDescriptor, SegmentCmp > SegmentSet
Definition: segment_graph.h:93
bool has_transition(int seg_id_from, int seg_id_to)
true, if there is a transition from &#39;from&#39; to &#39;to&#39;
Definition: segment_graph.cpp:7296
void add_expression_to_segment(SegmentSet segments, SgNode *expr, PortCallPath pcp)
This function adds to each segment the given expression.
Definition: segment_graph.cpp:1493
void print_graph(std::string filename)
This function prints the graph in a dot file. The name of the file is user defined by argument...
Definition: segment_graph.cpp:123
std::unordered_map< SgFunctionDeclaration *, std::vector< int > > func_socket_offset_mapping_
used for instrumenting seg id offset in b_transport implementation functions.
Definition: segment_graph.h:726
std::set< VertexDescriptor > precached_function_segments_
This set stores segments from precached functions. These segments will be deleted later...
Definition: segment_graph.h:706
void read_psg_from_file(std::string file_name)
load the .psg file from disk reconstructs nodes and connections
Definition: segment_graph.cpp:677
Definition: edge.h:11
bool operator()(const VertexDescriptor lhs, const VertexDescriptor rhs) const
Definition: segment_graph.h:47
bool is_boundary_stmt(SgStatement const *const current_stmt)
This function checks if a given statement is a potential boundary statement.
Definition: segment_graph.cpp:4750
int total_segment_nodes_
for redaction of psg, we need to store the total number of segment nodes. The value is set in the mai...
Definition: segment_graph.h:202
bool should_decompose_function(SgExpression *expr, bool duplicate_segments, PortCallPath pcp, bool is_condition=false)
This function determines if a expression should be decomposed. This is the case if expression has the...
Definition: segment_graph.cpp:4979
std::set< SgFunctionCallExp * > port_calls_
This set stores all function calls which belong to a port. These segments will be deleted later...
Definition: segment_graph.h:712
void reference_analysis_hack_for_dmi_get_ptr(SgFunctionCallExp *func_call, SgFunctionDefinition *func_def, SgVariableDefinition *socket)
get_dmi_ptr is a special case. In this case, the 2nd parameter is a reference referring to a dmi obje...
Definition: segment_graph.cpp:6851
std::map< SgSymbol *, std::vector< VertexDescriptor > > func_symbols_and_exit_segVertex_
mapping of function symbol and its exit segment vertexes reconstructed after loading ...
Definition: segment_graph.h:196
WAIT_CONSTRUCT
Definition: function_annotation.h:7
void create_temp_variable_for_expression(SgExpression *expr, SgBasicBlock *&bb, int stmt_type=0, SgStatement *parent=NULL, SgBasicBlock *body=NULL)
This function creates a variable declaration of the type of the given expression. The variable will b...
Definition: segment_graph.cpp:5674
void clean_graph()
This function deletes all duplicated nodes in each vertex of the graph.
Definition: segment_graph.cpp:77
static int counter
This counter is used for generating variables names with unique names.
Definition: segment_graph.h:652
bool is_succesfully_created_
Is true if the segment graph is successfully created.
Definition: segment_graph.h:718
SegmentGraph()
Definition: segment_graph.cpp:50
CachedFunctionAstAttributes * build_segment_graph_for_function(SgFunctionDefinition *func_def, bool duplicate_segments, PortCallPath pcp, bool is_registered_b_transport=false)
This function generates a segment graph for a function.
Definition: segment_graph.cpp:6430
bool static_analysis_
determine if the compiler should perform static analysis or dynamic analysis
Definition: segment_graph.h:293
CachedFunctionAstAttributes * create_cached_function_attribute_for_annotated_function(SgNode *boundary_node, WAIT_CONSTRUCT wait_type, SegmentSet incoming_segments, bool is_conflict_free, PortCallPath pcp)
This function creates a cached function annotation information for based on the cached function infor...
Definition: segment_graph.cpp:6679
Definition: port_call_path.h:10
Function object (functor!?) for SegmentSet (12/15/18, RD)
Definition: segment_graph.h:46
void integrate_psg_into_sg(VertexDescriptor func_call_vertex_id, SgSymbol *func_sym)
replace a partial function call node with its psg. If the partial function call is a port call...
Definition: segment_graph.cpp:285
void mark_not_conflict_free_func_calls_in_segment(SgNode *stmt, SegmentSet segments)
This function checks if there is a not-conflict-free function call in the expression. If so, all segments marked as in conflict.
Definition: segment_graph.cpp:7245
std::set< SgFunctionDefinition * > FunctionCallBoundarySet
Definition: segment_graph.h:83
void set_all_segments_to_untouched()
This function sets the status of the flag helper_for_graph_algorithms for all nodes to &#39;Untouched&#39;...
Definition: segment_graph.cpp:6501
FunctionAnnotation * analyze_prepended_pragmas_for_annotation(SgFunctionDeclaration *func_decl)
This function checks if the function has any pragma. The results are in the return value...
Definition: segment_graph.cpp:7135
void add_function(Thread *originating_thread, Function *function, bool duplicate_segments=false, bool is_simulation_process=true, std::string module_name="")
This function analyzes the given function and creates a segment graph for it. The graph will be autom...
Definition: segment_graph.cpp:1166
CCxxKeywordsBoundarySet keyword_boundaries_
Currently not used.
Definition: segment_graph.h:641
void print_psg_file(std::string file_name)
store the psg as .psg file on disk
Definition: segment_graph.cpp:162
void remove_dangling_segments()
after integration of all the psgs, the segments that does not belong to simulation processes are remo...
Definition: segment_graph.cpp:553
SegmentSet duplicate_empty_segments(SegmentSet segments)
This function dupilcates a SegmentSet. The dulicated segments will have also incoming edges...
Definition: segment_graph.cpp:1508
void insert_loop_edges(VertexDescriptor &loop_vertex, SegmentSet &current_segments, SegmentSet &continue_segments, SegmentSet &leaf_segments_of_loop)
This is a helper function for loop handling.
Definition: segment_graph.cpp:4793
Graph graph_
Internal data structure of the segment graph.
Definition: segment_graph.h:700
std::map< SgSymbol *, std::vector< VertexDescriptor > > func_symbols_and_entrance_segVertex_
mapping of function symbol and its entrance segment vertexes, reconstructed after loading ...
Definition: segment_graph.h:189
std::vector< std::string > channel_seg_id_array_names_
we need to instrument set_upcoming_segment_id(var_array) before port calls var_array is defined in th...
Definition: segment_graph.h:167
void forward_reference_function_parameters(SgFunctionCallExp *func_call_exp)
This function forwards the arguments which are passed by reference to the function parameters of the ...
Definition: segment_graph.cpp:7080
void reference_analysis_hack_for_nb_transport(SgFunctionCallExp *func_call, SgFunctionDefinition *func_def, SgVariableDefinition *socket)
we now also keep the pcp
Definition: segment_graph.cpp:6983
std::set< VertexDescriptor > port_call_seg_vertexs_
stores the partial function call nodes that hold port calls. are used in PSG mode.
Definition: segment_graph.h:173
std::string generate_unique_name(SgNode *node)
Generates an unique name for a varible based on the given node.
Definition: segment_graph.cpp:6409
This class stores precached information of a analyzed function. Each function definition has an assoc...
Definition: cached_function_ast_attributes.h:18
void read_write_analysis_of_segments()
The function determines which variables are read and written in the individual segments.
Definition: segment_graph.cpp:4887
void analyze_TLM2_container_final_mapping()
there may be nested b_transports, so, a reference typed gp (gp0) may refer to another reference typed...
Definition: segment_graph.cpp:7362
FunctionAnnotationAttributes * get_function_call_annotation(SgFunctionCallExp *func_call_exp)
This function takes a function call expression and checks if there is any function annotation at the ...
Definition: segment_graph.cpp:6515
std::set< VariantT > CCxxKeywordsBoundarySet
Definition: segment_graph.h:84
std::unordered_set< SgFunctionCallExp * > b_transport_calls_
Definition: segment_graph.h:736
std::set< VertexDescriptor > recursive_function_calls_
Contains the entrance vertexes of recursive function calls.
Definition: segment_graph.h:646
void add_function_method(Thread *originating_thread, Function *function, bool duplicate_segments=false, bool is_simulation_process=true, std::string module_name="")
This function analyzes the given function and creates a segment graph for it. The graph will be autom...
Definition: segment_graph.cpp:1302
SegmentSet build_graph(SgStatement *current_stmt, SegmentSet current_segments, SegmentSet &break_segments, SegmentSet &continue_segments, bool duplicate_segments, PortCallPath pcp)
This function creates the segment graph.
Definition: segment_graph.cpp:1574
void find_module_segments()
for loading PSG It adds simulation threads to module_definitions, and sets the corresponding starting...
Definition: segment_graph.cpp:628
void set_socket_call_CachedFunctionAstAttributes(SgFunctionDeclaration *func_decl, bool duplicate_segments, PortCallPath pcp)
set the CachedFunctionAstAttributes for registered b_transport functions
Definition: segment_graph.cpp:7328
bool follow_function_call(SgFunctionDeclaration *func_decl)
true, if the function be followed.
Definition: segment_graph.cpp:7287
FunctionCallBoundarySet function_boundaries_
Contains all boudaries (currently, wait statemens)
Definition: segment_graph.h:636
boost::adjacency_list< boost::listS, boost::listS, boost::bidirectionalS, Segment, Edge, boost::property< boost::vertex_index_t, int > > Graph
Definition: segment_graph.h:29
void handle_recursive_calls()
This function integrates the recursive function calls.
Definition: segment_graph.cpp:5160
Definition: function.h:14
This class provides attributes for function anotations.
Definition: function_annotation_attributes.h:17
void decompose_expression_with_boundary_calls(SgExpression *expr, SgBasicBlock *&bb, bool duplicate_segments, PortCallPath pcp, int stmt_type=0, SgStatement *parent=NULL, SgBasicBlock *body=NULL)
This function decomposes an expression into multiple statements. Functions which call directly or ind...
Definition: segment_graph.cpp:6066
void set_socket_attribute_for_dmi_object(SgFunctionCallExp *func_call, SgVariableDefinition *socket)
we need to know which module instance this dmi object connects to
Definition: segment_graph.cpp:7049
SegmentSet duplicate_segments(SegmentSet segments)
This function dupilcates a SegmentSet. the dulicated segments will have also incoming edges...
Definition: segment_graph.cpp:1541
boost::graph_traits< Graph >::edge_descriptor EdgeDescriptor
Definition: segment_graph.h:36
SgFunctionCallExp * has_function_call_with_boundary(SgExpression *expr, bool duplicate_segments, PortCallPath pcp)
This function checks if in the given expression a function call occurs which calls a functon with a b...
Definition: segment_graph.cpp:4899
Definition: segment.h:22
std::unordered_map< SgFunctionCallExp *, std::vector< int > > bt_socket_offset_mapping_
used for instrumenting seg id offset in b_transport implementation functions.
Definition: segment_graph.h:734
VertexDescriptor id_to_vertex_descriptor(int seg_id)
Returns a vertex descriptor of the segment with the id &#39;seg_id&#39;.
Definition: segment_graph.cpp:7312
void add_mapped_symbol_to_reference(SgFunctionCallExp *func_call, SgFunctionDefinition *func_def)
Let&#39;s take a look at this example: void foo(int &amp;ref, int value, in &amp;ref2); foo(var, some_var, other_var); This function adds the symbol of &quot;var&quot; to the attribute &quot;references&quot; of the symbol &quot;ref&quot;. The same happens for &quot;ref2&quot; and &quot;other_var&quot;.
Definition: segment_graph.cpp:6749
std::vector< std::pair< VertexDescriptor, SgSymbol * > > vertexID_symbol_pairs_of_partialFuncCallNodes_
pairs of VertexDescriptor of partial function call node and the function&#39;s symbol. used for replacing partial function call nodes with its subpsg
Definition: segment_graph.h:182
void reference_analysis_hack_for_b_transport(SgFunctionCallExp *func_call, SgFunctionDefinition *func_def, SgVariableDefinition *socket)
we now also keep the pcp
Definition: segment_graph.cpp:6916