PandA-2024.02
StateTransitionGraph_constructor.cpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2004-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
49 
50 #include "hls_manager.hpp"
51 #include "op_graph.hpp"
54 
56  const StateTransitionGraphsCollectionRef _state_transition_graphs_collection, const HLS_managerConstRef _HLSMgr,
57  unsigned int _funId)
58  : state_index(0),
59  state_transition_graphs_collection(_state_transition_graphs_collection),
60  state_transition_graph(new StateTransitionGraph(state_transition_graphs_collection, -1)),
61  HLSMgr(_HLSMgr),
62  funId(_funId)
63 {
64 }
65 
67 {
68  const auto newVertex = state_transition_graphs_collection->AddVertex(NodeInfoRef(new StateInfo()));
69  const auto state_info = state_transition_graph->GetStateInfo(newVertex);
70  const auto cfg = HLSMgr.lock()->CGetFunctionBehavior(funId)->CGetOpGraph(FunctionBehavior::CFG);
71  const auto cfg_info = cfg->CGetOpGraphInfo();
72  state_info->HLSMgr = HLSMgr;
73  state_info->funId = funId;
74  state_info->name = "ENTRY";
75  state_info->executing_operations.push_back(cfg_info->entry_vertex);
76  state_info->starting_operations.push_back(cfg_info->entry_vertex);
77  state_info->ending_operations.push_back(cfg_info->entry_vertex);
78  state_info->BB_ids.insert(cfg->CGetOpNodeInfo(cfg_info->entry_vertex)->bb_index);
79  state_transition_graph->GetStateTransitionGraphInfo()->entry_node = newVertex;
80 }
81 
83 {
84  const auto newVertex = state_transition_graphs_collection->AddVertex(NodeInfoRef(new StateInfo()));
85  const auto state_info = state_transition_graph->GetStateInfo(newVertex);
86  const auto cfg = HLSMgr.lock()->CGetFunctionBehavior(funId)->CGetOpGraph(FunctionBehavior::CFG);
87  const auto cfg_info = cfg->CGetOpGraphInfo();
88  state_info->HLSMgr = HLSMgr;
89  state_info->funId = funId;
90  state_info->name = "EXIT";
91  state_info->executing_operations.push_back(cfg_info->exit_vertex);
92  state_info->starting_operations.push_back(cfg_info->exit_vertex);
93  state_info->ending_operations.push_back(cfg_info->exit_vertex);
94  state_info->BB_ids.insert(cfg->CGetOpNodeInfo(cfg_info->exit_vertex)->bb_index);
95  state_transition_graph->GetStateTransitionGraphInfo()->exit_node = newVertex;
96 }
97 
98 vertex StateTransitionGraph_constructor::create_state(const std::list<vertex>& exec_op,
99  const std::list<vertex>& start_op,
100  const std::list<vertex>& end_op,
101  const CustomOrderedSet<unsigned int>& BB_ids)
102 {
103  vertex newVertex = state_transition_graphs_collection->AddVertex(NodeInfoRef(new StateInfo()));
104  const StateInfoRef state_info = state_transition_graph->GetStateInfo(newVertex);
105  state_info->HLSMgr = HLSMgr;
106  state_info->funId = funId;
107  state_info->name = std::string(STATE_NAME_PREFIX + std::to_string(state_index));
108  state_transition_graph->GetStateTransitionGraphInfo()->state_id_to_vertex[state_index] = newVertex;
109  state_transition_graph->GetStateTransitionGraphInfo()->vertex_to_state_id[newVertex] = state_index;
110  state_info->executing_operations = exec_op;
111  state_info->starting_operations = start_op;
112  state_info->ending_operations = end_op;
113  state_info->BB_ids = BB_ids;
114 
115  state_index++;
116 
117  return newVertex;
118 }
119 
121 {
122  if(type == TransitionInfo::StateTransitionType::ST_EDGE_FEEDBACK)
123  {
124  state_transition_graph->GetStateTransitionGraphInfo()->is_a_dag = false;
125  }
126  // get the vertex iterator
127  VertexIterator vIterBeg, vIterEnd;
128  boost::tie(vIterBeg, vIterEnd) = boost::vertices(*state_transition_graph);
129  // check that source and target have been already added
130  THROW_ASSERT(std::find(vIterBeg, vIterEnd, src) != vIterEnd and std::find(vIterBeg, vIterEnd, tgt) != vIterEnd,
131  "Source vertex or target one is not present into graph");
132  EdgeDescriptor e;
133  bool exists;
134  boost::tie(e, exists) = boost::edge(src, tgt, *state_transition_graphs_collection);
135  THROW_ASSERT((not exists) or (not(state_transition_graph->GetSelector(e) & type)),
136  "transition already present with the same selector");
137  // edge creation
138  if(not exists)
139  {
140  const TransitionInfoRef eInfo = TransitionInfoRef(
141  new TransitionInfo(HLSMgr.lock()->CGetFunctionBehavior(funId)->CGetOpGraph(FunctionBehavior::CFG)));
142  e = state_transition_graphs_collection->AddEdge(src, tgt, type, eInfo);
143  }
144  else
145  {
146  state_transition_graphs_collection->AddSelector(e, type);
147  }
148  return e;
149 }
150 
152 {
153  state_transition_graph->GetTransitionInfo(e)->t = t;
154  state_transition_graph->GetTransitionInfo(e)->ops.insert(op);
155 }
156 
158  const CustomOrderedSet<vertex>& ops, vertex ref_state)
159 {
160  state_transition_graph->GetTransitionInfo(e)->t = t;
161  state_transition_graph->GetTransitionInfo(e)->ops = ops;
162  state_transition_graph->GetTransitionInfo(e)->ref_state = ref_state;
163 }
164 
166  const CustomOrderedSet<unsigned>& labels, bool has_default)
167 {
168  state_transition_graph->GetTransitionInfo(e)->t = CASE_COND;
169  state_transition_graph->GetTransitionInfo(e)->ops.insert(op);
170  state_transition_graph->GetTransitionInfo(e)->has_default = has_default;
171  state_transition_graph->GetTransitionInfo(e)->labels = labels;
172 }
173 
175 {
176  state_transition_graph->GetTransitionInfo(dest)->t = state_transition_graph->GetTransitionInfo(source)->t;
177  state_transition_graph->GetTransitionInfo(dest)->ops = state_transition_graph->GetTransitionInfo(source)->ops;
178  state_transition_graph->GetTransitionInfo(dest)->has_default =
179  state_transition_graph->GetTransitionInfo(source)->has_default;
180  state_transition_graph->GetTransitionInfo(dest)->labels = state_transition_graph->GetTransitionInfo(source)->labels;
181 }
182 
183 //*********************************************************************
184 
188 {
189  state_transition_graphs_collection->RemoveSelector(boost::edge(src, tgt, *state_transition_graphs_collection).first);
190 }
191 
195 {
196  std::map<unsigned int, vertex>& id_to_v = state_transition_graph->GetStateTransitionGraphInfo()->state_id_to_vertex;
197  std::map<vertex, unsigned int>& v_to_id = state_transition_graph->GetStateTransitionGraphInfo()->vertex_to_state_id;
198 
199  unsigned int id = v_to_id.at(src);
200  v_to_id.erase(src);
201  id_to_v.erase(id);
202  state_transition_graphs_collection->RemoveVertex(src);
203 }
void create_exit_state()
create the STG exit vertex
Data structure representing the entire HLS information.
This file contains the structures needed to manage a graph that will represent the state transition g...
const StateTransitionGraphsCollectionRef state_transition_graphs_collection
The bulk state transition graph.
vertex create_state(const std::list< vertex > &exec_op, const std::list< vertex > &start_op, const std::list< vertex > &end_op, const CustomOrderedSet< unsigned int > &BB_ids)
Adds a new state managing the operations given as parameters.
void set_unbounded_condition(const EdgeDescriptor &e, transition_type t, const CustomOrderedSet< vertex > &ops, vertex ref_state)
StateTransitionGraph_constructor(const StateTransitionGraphsCollectionRef state_transition_graphs_collection, const HLS_managerConstRef HLSMgr, unsigned int funId)
Constructor of the class.
void delete_edge(const vertex &src, const vertex &tgt)
Removes the specified edge from the graph.
void copy_condition(const EdgeDescriptor &dest, const EdgeDescriptor &source)
copy condition from one edge to another
const StateTransitionGraphRef state_transition_graph
The complete state transition graph.
Class used to describe a state transition graph.
Control flow graph.
File contanining the structures necessary to manage a graph that will represent a state transition gr...
EdgeDescriptor connect_state(const vertex &src, const vertex &tgt, int type)
Creates a connection between two vertices into the graph.
void set_condition(const EdgeDescriptor &e, transition_type t, vertex ops)
Changes the control condition associated to an edge.
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
This file contains the structures needed to manage a graph that will represent the state transition g...
boost::graph_traits< graph >::vertex_iterator VertexIterator
vertex_iterator definition.
Definition: graph.hpp:1307
void set_switch_condition(const EdgeDescriptor &e, vertex op, const CustomOrderedSet< unsigned > &labels, bool has_default)
function setting the condition on edge derived from switch statements
refcount< NodeInfo > NodeInfoRef
RefCount type definition of the NodeInfo class structure.
Definition: node_info.hpp:98
refcount< T > lock() const
Definition: refcount.hpp:212
void create_entry_state()
create the STG entry vertex
#define STATE_NAME_PREFIX
state name prefix
Structure holding information about a node into graph.
void delete_state(const vertex &src)
Removes the specified state from the graph.
const Wrefcount< const HLS_manager > HLSMgr
The HLSMgr.
Data structures used in operations graph.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
unsigned int state_index
Index of the next state to be created.
refcount< TransitionInfo > TransitionInfoRef
refcount about edge info
Structure holding the information about an edge into the graph.
boost::graph_traits< graph >::edge_descriptor EdgeDescriptor
edge definition.
Definition: graph.hpp:1316
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...
Definition: exceptions.hpp:289

Generated on Mon Feb 12 2024 13:02:54 for PandA-2024.02 by doxygen 1.8.13