PandA-2024.02
operations_graph_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  */
47 #include "custom_map.hpp" // for CustomMap
48 #include "custom_set.hpp" // for CustomSet
49 #include "exceptions.hpp" // for THROW_ASSERT
50 #include "function_behavior.hpp" // for tree_nodeRef, Funct...
51 #include "op_graph.hpp"
52 #include "string_manipulation.hpp"
53 #include "tree_manager.hpp"
54 #include "tree_node.hpp"
55 #include "typed_node_info.hpp" // for GET_NAME, ENTRY, EXIT
56 #include <boost/tuple/tuple.hpp> // for tie
57 #include <list> // for list
58 #include <utility> // for pair
59 
61  : og(std::move(_og)), op_graph(new OpGraph(og, -1))
62 {
63 }
64 
66 
68 {
69  og->Clear();
70  index_map.clear();
71 }
72 
74 {
75  if(index_map.find(source) != index_map.end())
76  {
77  return index_map.find(source)->second;
78  }
79  NodeInfoRef node_info(new OpNodeInfo());
80  GetPointer<OpNodeInfo>(node_info)->vertex_name = source;
81  const vertex v_og = og->AddVertex(node_info);
82  index_map[source] = v_og;
83  return index_map[source];
84 }
85 
86 vertex operations_graph_constructor::CgetIndex(const std::string& source) const
87 {
88  THROW_ASSERT(index_map.find(source) != index_map.end(), "Index with name " + source + " doesn't exist");
89  return index_map.find(source)->second;
90 }
91 
92 EdgeDescriptor operations_graph_constructor::AddEdge(const vertex source, const vertex dest, int selector)
93 {
94  return og->AddEdge(source, dest, selector);
95 }
96 
97 void operations_graph_constructor::RemoveEdge(const vertex source, const vertex dest, int selector)
98 {
99  og->RemoveSelector(source, dest, selector);
100 }
101 
103 {
104  og->RemoveSelector(edge, selector);
105 }
106 
108 {
109  og->CompressEdges();
110 }
111 
112 void operations_graph_constructor::add_edge_info(const vertex src, const vertex tgt, const int selector,
113  unsigned int NodeID)
114 {
115  EdgeDescriptor e;
116  bool inserted;
117  boost::tie(e, inserted) = boost::edge(src, tgt, *og);
118  THROW_ASSERT(inserted, "Edge from " + GET_NAME(og, src) + " to " + GET_NAME(og, tgt) + " doesn't exists");
119  get_edge_info<OpEdgeInfo>(e, *(og))->add_nodeID(NodeID, selector);
120 }
121 
123  const std::string& operation_t, unsigned int bb_index,
124  const unsigned int node_id)
125 {
126  THROW_ASSERT(src != "", "Vertex name empty");
127  THROW_ASSERT(operation_t != "", "Operation empty");
128  vertex current = getIndex(src);
129  THROW_ASSERT(!op_graph->CGetOpNodeInfo(current)->node || node_id == 0 ||
130  node_id == op_graph->CGetOpNodeInfo(current)->GetNodeId(),
131  "Trying to set node_id " + STR(node_id) + " to vertex " + src + " that has already node_id " +
132  STR(op_graph->CGetOpNodeInfo(current)->GetNodeId()));
133  if(node_id > 0 && node_id != ENTRY_ID && node_id != EXIT_ID)
134  {
135  op_graph->GetOpNodeInfo(current)->node = TM->CGetTreeReindex(node_id);
136  }
137  const unsigned int updated_node_id = op_graph->GetOpNodeInfo(current)->GetNodeId();
138  if(updated_node_id != 0 && updated_node_id != ENTRY_ID && updated_node_id != EXIT_ID)
139  {
140  GetPointer<gimple_node>(TM->get_tree_node_const(updated_node_id))->operation = operation_t;
141  }
142  GET_NODE_INFO(og, OpNodeInfo, current)->bb_index = bb_index;
143  if(src == ENTRY)
144  {
145  op_graph->GetOpGraphInfo()->entry_vertex = current;
146  }
147  if(src == EXIT)
148  {
149  op_graph->GetOpGraphInfo()->exit_vertex = current;
150  }
151  op_graph->GetOpGraphInfo()->tree_node_to_operation[node_id] = current;
152 }
153 
154 void operations_graph_constructor::add_type(const std::string& src, unsigned int type_t)
155 {
156  THROW_ASSERT(src != "", "Vertex name empty");
157  THROW_ASSERT(type_t != 0, "Type of vertex " + src + " is zero");
158  vertex src_index = getIndex(src);
159  if(GET_NODE_INFO(og, OpNodeInfo, src_index)->node_type != TYPE_GENERIC)
160  {
161  GET_NODE_INFO(og, OpNodeInfo, src_index)->node_type |= type_t;
162  }
163  else
164  {
165  GET_NODE_INFO(og, OpNodeInfo, src_index)->node_type = type_t;
166  }
167 }
168 
169 void operations_graph_constructor::AddVariable(const vertex op_vertex, const unsigned int variable,
170  const FunctionBehavior_VariableType variable_type,
171  const FunctionBehavior_VariableAccessType access_type)
172 {
173  op_graph->GetOpNodeInfo(op_vertex)->variables[variable_type][access_type].insert(variable);
174 }
175 
176 void operations_graph_constructor::add_parameter(const vertex& Ver, unsigned int Var)
177 {
178  op_graph->GetOpNodeInfo(Ver)->actual_parameters.push_back(Var);
179 }
180 
181 void operations_graph_constructor::add_called_function(const std::string& source, unsigned int called_function)
182 {
183  op_graph->GetOpNodeInfo(getIndex(source))->called.insert(called_function);
184 }
185 
187 {
188  op_graph->GetOpNodeInfo(Ver)->cited_variables.insert(Vargc);
189 }
#define EXIT
Definition: global.h:46
OpGraphConstRef op_graph
The operation graph (for scheduling purpose) (cannot be const because of = operator) ...
Definition: schedule.hpp:172
const OpGraphRef op_graph
The graph with all the edges.
const OpGraphsCollectionRef og
reference to the bulk operations graph
void add_called_function(const std::string &source, unsigned int called_function)
Adds a call to the vertex.
const tree_nodeRef CGetTreeReindex(const unsigned int i) const
Return a tree_reindex wrapping the i-th tree_node.
#define GET_NODE_INFO(data, NodeInfo, vertex_index)
Definition: graph.hpp:601
void CompressEdges()
Remove all redundant edges.
#define GET_NAME(data, vertex_index)
Helper macro returning the name associated with a node.
Information associated with a generic operation node.
Definition: op_graph.hpp:363
tree_managerRef TM
The tree manager.
Definition: schedule.hpp:128
void add_edge_info(const vertex src, const vertex tgt, const int selector, unsigned int NodeID)
Add edge info to the graph.
exceptions managed by PandA
FunctionBehavior_VariableType
The possible type of a variable.
Definition of hash function for EdgeDescriptor.
Definition: graph.hpp:1321
void Clear()
Remove all vertices and edges.
void add_type(const std::string &src, unsigned int type)
Add the type associated with a vertex.
Base class description of data information associated with each node of a graph.
redefinition of map to manage ordered/unordered structures
#define STR(s)
Macro which performs a lexical_cast to a string.
Auxiliary methods for manipulating string.
const tree_nodeRef get_tree_node_const(unsigned int i) const
Return the reference to the i-th tree_node Constant version of get_tree_node.
#define EXIT_ID
constant used to represent tree node index of exit operation
Definition: op_graph.hpp:81
This class specifies the characteristic of a particular operation working on a given functional unit...
#define ENTRY
Superclass include.
void AddVariable(const vertex op_vertex, const unsigned int variable, const FunctionBehavior_VariableType variable_type, const FunctionBehavior_VariableAccessType access_type)
Adds an access to a variable to an operation vertex.
void AddOperation(const tree_managerRef TM, const std::string &src, const std::string &oper, unsigned int bb_index, const unsigned int node_id)
Add the operation associated with a vertex.
redefinition of set to manage ordered/unordered structures
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
FunctionBehavior_VariableAccessType
The access type to a variable.
Classes specification of the tree_node data structures.
void RemoveEdge(const vertex source, const vertex dest, int selector)
remove a selector between two vertices
void add_parameter(const vertex &Ver, unsigned int Vargc)
Adds a parameter to the vertex.
operations_graph_constructor(OpGraphsCollectionRef _og)
Constructor.
vertex CgetIndex(const std::string &source) const
Return the vertex index given the id of the vertex node.
~operations_graph_constructor()
Destructor.
void AddSourceCodeVariable(const vertex &Ver, unsigned int Vargc)
Adds a (ssa-)variable to the set of variables referred by the operation vertex.
#define ENTRY_ID
constant used to represent tree node index of entry operation
Definition: op_graph.hpp:79
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
EdgeDescriptor AddEdge(const vertex source, const vertex dest, int selector)
add an edge between vertex source and vertex dest
vertex getIndex(const std::string &source)
Return the vertex index given the id of the vertex node.
Class used to describe a particular graph with operations as nodes.
Definition: op_graph.hpp:783
This class provides methods to build an operations graph.
#define TYPE_GENERIC
constant identifying the node type of a GENERIC operation.
void RemoveSelector(const EdgeDescriptor edge, const int selector)
set the selector of an edge between vertex source and vertex dest
std::map< std::string, vertex > index_map
Mapping between id to index.
Class specification of the manager of the tree structures extracted from the raw file.
A brief description of the C++ Header File.
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:50 for PandA-2024.02 by doxygen 1.8.13