PandA-2024.02
basic_block.hpp
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  */
50 #ifndef BASIC_BLOCK_HPP
51 #define BASIC_BLOCK_HPP
52 
53 #include "config_HAVE_UNORDERED.hpp"
54 
55 #include "cdfg_edge_info.hpp" // for CdfgEdgeInfo
56 #include "edge_info.hpp" // for EdgeInfoRef
57 #include "graph.hpp" // for vertex, EdgeDesc...
58 #include "graph_info.hpp" // for GraphInfo
59 #include "node_info.hpp" // for NodeInfo
60 #include "refcount.hpp" // for refcount, Refcou...
61 #include <cstddef> // for size_t
62 #include <functional> // for binary_function
63 #include <list> // for list
64 #include <string> // for string
65 #include <utility> // for pair
66 
67 #include "custom_map.hpp"
68 #include "custom_set.hpp"
69 
77 class FunctionBehavior;
80 
84 #define D_SELECTOR (1 << 7)
86 
88 #define PD_SELECTOR (1 << 8)
89 
91 #define J_SELECTOR (1 << 9)
92 
94 #define PP_SELECTOR (1 << 10)
95 
100 struct BBNodeInfo : public NodeInfo
101 {
102  public:
104  unsigned int loop_id;
105 
107  unsigned int cer;
108 
110  blocRef block;
111 
113  std::list<vertex> statements_list;
114 
118  BBNodeInfo();
119 
124  explicit BBNodeInfo(blocRef _block);
125 
130  void add_operation_node(const vertex op);
131 
136  vertex get_first_operation() const;
137 
142  vertex get_last_operation() const;
143 
148  bool empty() const;
149 
156  size_t size() const;
157 
161  unsigned int get_bb_index() const;
162 
167 
172 };
176 
180 struct BBEdgeInfo : public CdfgEdgeInfo
181 {
182  private:
184  friend class FunctionBehavior;
185 
187  unsigned long long epp_value;
188 
189  public:
193  BBEdgeInfo();
194 
198  ~BBEdgeInfo() override;
199 
203  bool cdg_edge_T() const;
204 
208  bool cdg_edge_F() const;
209 
213  bool cfg_edge_T() const;
214 
218  bool cfg_edge_F() const;
219 
223  bool switch_p() const;
224 
228  const CustomOrderedSet<unsigned int> get_labels(const int selector) const;
229 
233  void set_epp_value(unsigned long long _epp_value);
234 
238  unsigned long long get_epp_value() const;
239 };
243 
247 struct BBGraphInfo : public GraphInfo
248 {
251 
253  const unsigned int function_index;
254 
256 
259 
262 
268  BBGraphInfo(const application_managerConstRef AppM, const unsigned int function_index);
269 };
273 
281 {
282  private:
284 
285  public:
292 
296  ~BBGraphsCollection() override;
297 
305  inline EdgeDescriptor AddEdge(const vertex source, const vertex target, const int selector)
306  {
307  if(ExistsEdge(source, target))
308  {
309  return AddSelector(source, target, selector);
310  }
311  else
312  {
313  return InternalAddEdge(source, target, selector, EdgeInfoRef(new BBEdgeInfo()));
314  }
315  }
316 };
320 
324 struct BBGraph : public graph
325 {
326  public:
332  BBGraph(const BBGraphsCollectionRef _g, int selector);
333 
340  BBGraph(const BBGraphsCollectionRef _g, int selector, CustomUnorderedSet<vertex>& sub);
341 
345  ~BBGraph() override = default;
346 
352  void WriteDot(const std::string& file_name, const int detail_level = 0) const;
353 
360  void WriteDot(const std::string& file_name, const CustomUnorderedSet<vertex>& annotated,
361  const int detail_level = 0) const;
362 
366  size_t num_bblocks() const;
367 
373  inline BBNodeInfoRef GetBBNodeInfo(const vertex node)
374  {
375  return RefcountCast<BBNodeInfo>(graph::GetNodeInfo(node));
376  }
377 
383  inline const BBNodeInfoConstRef CGetBBNodeInfo(const vertex node) const
384  {
385  return RefcountCast<const BBNodeInfo>(graph::CGetNodeInfo(node));
386  }
387 
392  {
393  return RefcountCast<BBEdgeInfo>(graph::GetEdgeInfo(e));
394  }
395 
400  {
401  return RefcountCast<const BBEdgeInfo>(graph::CGetEdgeInfo(e));
402  }
403 
409  {
410  return RefcountCast<BBGraphInfo>(graph::GetGraphInfo());
411  }
412 
418  {
419  return RefcountCast<const BBGraphInfo>(graph::CGetGraphInfo());
420  }
421 };
425 
426 #if !HAVE_UNORDERED
427 class BBVertexSorter : std::binary_function<vertex, vertex, bool>
428 {
429  private:
433 
434  public:
439  explicit BBVertexSorter(const BBGraphConstRef bb_graph);
440 
447  bool operator()(const vertex x, const vertex y) const;
448 };
449 
450 class BBEdgeSorter : std::binary_function<EdgeDescriptor, EdgeDescriptor, bool>
451 {
452  private:
456 
459 
460  public:
465  explicit BBEdgeSorter(const BBGraphConstRef bb_graph);
466 
473  bool operator()(const EdgeDescriptor x, const EdgeDescriptor y) const;
474 };
475 #endif
476 
480 class bb_vertex_order_by_map : std::binary_function<vertex, vertex, bool>
481 {
482  private:
484  const std::map<vertex, unsigned int>& ref;
485 
486  public:
491  explicit bb_vertex_order_by_map(const std::map<vertex, unsigned int>& _ref) : ref(_ref)
492  {
493  }
494 
501  bool operator()(const vertex x, const vertex y) const
502  {
503  return ref.find(x)->second < ref.find(y)->second;
504  }
505 };
506 #endif
BBVertexSorter bb_sorter
The vertex sorter.
This struct specifies the field bloc (basic block).
BBEdgeInfoRef GetBBEdgeInfo(const EdgeDescriptor e)
Returns the info associated with an edge.
const CustomOrderedSet< unsigned int > & get_live_in() const
Returns the live in of the basic block.
const unsigned int function_index
The index of the function.
Base class storing user data information to the whole graph.
Definition: graph_info.hpp:60
Definition of the node_info object for the basic_block graph.
string target
Definition: lenet_tvm.py:16
Information associated with a basic block edge.
BBGraphInfoRef GetBBGraphInfo()
Returns the property associated with the graph.
EdgeInfoRef GetEdgeInfo(typename boost::graph_traits< graphs_collection >::vertex_descriptor source, typename boost::graph_traits< graphs_collection >::vertex_descriptor target)
Get the edge property.
Definition: graph.hpp:794
const BBGraphInfoConstRef CGetBBGraphInfo() const
Returns the property associated with the graph.
CONSTREF_FORWARD_DECL(application_manager)
Class specification of the graph structures.
Information associated with an operation or basic block graph.
const EdgeInfoConstRef CGetEdgeInfo(typename boost::graph_traits< graphs_collection >::vertex_descriptor source, typename boost::graph_traits< graphs_collection >::vertex_descriptor target) const
Get the edge property.
Definition: graph.hpp:811
NodeInfoRef GetNodeInfo(typename boost::graph_traits< graphs_collection >::vertex_descriptor node)
FIXME: this method should become protected and called by equivalent method in subclasses Get the node...
Definition: graph.hpp:1039
redefinition of map to manage ordered/unordered structures
std::list< vertex > statements_list
List of operation vertices associated with basic block node.
EdgeDescriptor AddEdge(const vertex source, const vertex target, const int selector)
Add an edge with empty information associated.
unsigned long long epp_value
edge instrumented weight
unsigned int cer
id of the control equivalent region
const BBEdgeInfoConstRef CGetBBEdgeInfo(const EdgeDescriptor e) const
Returns the info associated with an edge.
Class used to describe a particular graph with basic blocks as nodes.
absl::flat_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMap
Definition: custom_map.hpp:148
size_t size() const
Returns the number of vertices of the graph representing the original program, associated with the cu...
Definition: basic_block.cpp:76
const NodeInfoConstRef CGetNodeInfo(typename boost::graph_traits< graphs_collection >::vertex_descriptor node) const
Get the node property.
Definition: graph.hpp:781
Base class description of data information associated with each node of a graph.
BBNodeInfo()
Empty constructor.
Definition: basic_block.cpp:63
Information associated with the whole basic-block graph.
refcount< EdgeInfo > EdgeInfoRef
RefCount type definition of the edge_info class structure.
Definition: edge_info.hpp:67
const CustomOrderedSet< unsigned int > & get_live_out() const
Returns the live in of the basic block.
bool empty() const
Returns true if there is no node associated with the basic block.
Definition: basic_block.cpp:91
redefinition of set to manage ordered/unordered structures
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
BBGraphConstRef bb_graph
The basic block graph to which edges belong Note: this should be const, but can not because of assign...
General class used to describe a graph in PandA.
Definition: graph.hpp:771
The key comparison function for vertices set based on levels.
class providing methods to manage a basic blocks graph.
Base class for graph property.
GraphInfoRef GetGraphInfo()
FIXME: this method should become protected and called by equivalent method in subclasses Get the grap...
Definition: graph.hpp:1051
Template definition of refcount.
Base class description of data information associated with each edge of a graph.
Data structures used to represent an edge in operation and basic block graphs.
BBNodeInfoRef GetBBNodeInfo(const vertex node)
Return the info associated with a basic block.
bulk graph.
Definition: graph.hpp:287
unsigned int loop_id
id of the loop to which basic block belongs to (0 if it doesn&#39;t belong to any loop) ...
REF_FORWARD_DECL(bloc)
const GraphInfoConstRef CGetGraphInfo() const
FIXME: this method should become protected and called by equivalent method in subclasses Get the grap...
Definition: graph.hpp:1062
void add_operation_node(const vertex op)
Adds an operation to the list of the statements.
Definition: basic_block.cpp:71
bool operator()(const vertex x, const vertex y) const
Compares position of two vertices sorted in topological order.
const BBNodeInfoConstRef CGetBBNodeInfo(const vertex node) const
Return the info associated with a basic block.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
blocRef block
Structure associated with this basic block in the GCC tree.
unsigned int get_bb_index() const
Returns the index of the basic block.
Definition: basic_block.cpp:96
x
Return the smallest n such that 2^n >= _x.
vertex entry_vertex
Index identifying the entry basic block.
CustomUnorderedMap< unsigned int, vertex > bb_index_map
bb_vertex_order_by_map(const std::map< vertex, unsigned int > &_ref)
Constructor.
const application_managerConstRef AppM
NOTE: this is equivalent to a weakrefcount since deleter should be null.
vertex exit_vertex
Index identifying the exit basic block.
BBGraphConstRef bb_graph
The basic block graph to which vertices belong Note: this should be const, but can not because of ass...
vertex get_last_operation() const
Returns the last operation vertex associated with the basic block.
Definition: basic_block.cpp:86
vertex get_first_operation() const
Returns the first operation vertex associated with the basic block.
Definition: basic_block.cpp:81
const std::map< vertex, unsigned int > & ref
Topological sorted vertices.
This structure defines graphs where nodes are basic_blocks.
boost::graph_traits< graph >::edge_descriptor EdgeDescriptor
edge definition.
Definition: graph.hpp:1316

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