PandA-2024.02
basic_blocks_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  */
45 #include "basic_block.hpp" // for BBGraph, BBGraphsCo...
46 #include "cdfg_edge_info.hpp" // for CFG_SELECTOR, CDG_S...
47 #include "exceptions.hpp" // for THROW_ASSERT
48 #include "string_manipulation.hpp" // for STR
49 #include "tree_basic_block.hpp" // for bloc, BB_ENTRY, BB_...
50 #include <boost/tuple/tuple.hpp> // for tie
51 #include <cstddef> // for size_t
52 #include <string> // for allocator, operator+
53 #include <utility> // for pair
54 
56  : bg(_bg), bb_graph(new BBGraph(bg, -1)), bb_index_map(bb_graph->GetBBGraphInfo()->bb_index_map)
57 {
58 }
59 
61 
63 {
64  size_t index = boost::num_vertices(*bg);
65  vertex v = bg->AddVertex(NodeInfoRef(new BBNodeInfo()));
66  if(index == 0)
67  {
68  THROW_ASSERT(index == BB_ENTRY, "wrong value of the BB_ENTRY constant");
69  bb_graph->GetBBGraphInfo()->entry_vertex = v;
70  }
71  else if(index == 1)
72  {
73  THROW_ASSERT(index == BB_EXIT, "wrong value of the BB_EXIT constant");
74  bb_graph->GetBBGraphInfo()->exit_vertex = v;
75  }
76  bb_graph->GetBBNodeInfo(v)->block = info;
77  bb_index_map[info->number] = v;
78  return v;
79 }
80 
82 {
83  return bg->AddEdge(source, target, selector);
84 }
85 
87 {
88  bg->clear();
89  bb_index_map.clear();
90 }
91 
92 void BasicBlocksGraphConstructor::RemoveEdge(const vertex source, const vertex target, const int selector)
93 {
94  bg->RemoveSelector(source, target, selector);
95 }
96 
98 {
99  bg->RemoveSelector(edge, selector);
100 }
101 
103  const unsigned label)
104 {
105  EdgeDescriptor e;
106  bool inserted;
107  boost::tie(e, inserted) = boost::edge(source, target, *bg);
108  THROW_ASSERT(inserted, "Edge BB" + STR(bb_graph->CGetBBNodeInfo(source)->block->number) + "-->BB" +
109  STR(bb_graph->CGetBBNodeInfo(target)->block->number) + " doesn't exists");
110  THROW_ASSERT(type & (CFG_SELECTOR | FB_CFG_SELECTOR | CDG_SELECTOR | FB_CDG_SELECTOR), "Not supported label type");
111  bb_graph->GetBBEdgeInfo(e)->labels[type].insert(label);
112 }
113 
115 {
116  return AddEdge(source, bb_graph->GetBBGraphInfo()->exit_vertex, CFG_SELECTOR);
117 }
118 
120 {
121  return AddEdge(bb_graph->GetBBGraphInfo()->entry_vertex, target, CFG_SELECTOR);
122 }
123 
124 bool BasicBlocksGraphConstructor::check_vertex(unsigned int block_index) const
125 {
126  return bb_index_map.find(block_index) != bb_index_map.end();
127 }
128 
129 vertex BasicBlocksGraphConstructor::Cget_vertex(unsigned int block_index) const
130 {
131  THROW_ASSERT(bb_index_map.find(block_index) != bb_index_map.end(),
132  "this vertex does not exist " + std::to_string(block_index));
133  return bb_index_map.find(block_index)->second;
134 }
135 
137 {
138  bb_graph->GetBBNodeInfo(Cget_vertex(index))->statements_list.push_back(op);
139 }
bool check_vertex(unsigned int block_index) const
return true in case the vertex has been already created
Definition of the node_info object for the basic_block graph.
string target
Definition: lenet_tvm.py:16
#define BB_EXIT
constant identifying the basic block node of type exit
void add_operation_to_bb(vertex op, unsigned int index)
Add an operation to its basic block.
exceptions managed by PandA
EdgeDescriptor AddEdge(const vertex source, const vertex target, const int selector)
Add an edge selector.
This class provides methods to build a basic blocks graph.
#define FB_CDG_SELECTOR
Feedback control dependence edge selector.
Data structure describing a basic block at tree level.
#define STR(s)
Macro which performs a lexical_cast to a string.
Auxiliary methods for manipulating string.
BasicBlocksGraphConstructor(BBGraphsCollectionRef _bg)
Constructor.
#define FB_CFG_SELECTOR
Feedback control flow edge selector.
CustomUnorderedMap< unsigned int, vertex > & bb_index_map
Map between basic block node index and vertices.
~BasicBlocksGraphConstructor()
Destructor.
const BBGraphRef bb_graph
Reference to graph with all the edges.
vertex Cget_vertex(unsigned int block_index) const
return a vertex of the graph given the functionID.
Class used to describe a particular graph with basic blocks as nodes.
#define CDG_SELECTOR
Control dependence edge selector.
void Clear()
Remove all vertices and edges.
void RemoveEdge(const vertex source, const vertex target, const int selector)
Remove an edge selector.
#define index(x, y)
Definition: Keccak.c:74
#define BB_ENTRY
constant identifying the basic block node of type entry
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
void add_bb_edge_info(const vertex source, const vertex target, int type, const unsigned int label)
add label to edge between vertex source and vertex target
vertex add_vertex(const blocRef info)
Add a new vertex to the basic blocks graphs.
EdgeDescriptor connect_to_entry(const vertex target)
add edge between entry and target
refcount< NodeInfo > NodeInfoRef
RefCount type definition of the NodeInfo class structure.
Definition: node_info.hpp:98
Data structures used to represent an edge in operation and basic block graphs.
const BBGraphsCollectionRef bg
reference to the bulk basic blocks graph
Class specification of the basic_block structure.
EdgeDescriptor connect_to_exit(const vertex source)
add edge between source and exit
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
#define CFG_SELECTOR
Control flow graph edge selector.
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