PandA-2024.02
basic_block.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  */
46 #include "basic_block.hpp"
47 
48 #include "Parameter.hpp" // for OPT_dot_directory
49 #include "application_manager.hpp" // for FunctionBehaviorCon...
50 #include "behavioral_helper.hpp" // for BehavioralHelper
51 #include "behavioral_writer_helper.hpp" // for BBWriter, BBEdgeWriter
52 #include "function_behavior.hpp" // for BBGraphsCollectionRef
53 #include "graph.hpp" // for vertex, EdgeDescriptor
54 #include "tree_basic_block.hpp" // for bloc, blocRef
55 #include <boost/graph/adjacency_list.hpp> // for adjacency_list, source
56 #include <boost/graph/detail/adjacency_list.hpp> // for num_vertices, adj_l...
57 #include <boost/graph/detail/edge.hpp> // for operator!=, operator==
58 #include <boost/graph/filtered_graph.hpp> // for source, target
59 #include <boost/iterator/iterator_facade.hpp> // for operator!=, operator++
60 #include <filesystem> // for create_directories
61 #include <utility>
62 
63 BBNodeInfo::BBNodeInfo() : loop_id(0), cer(0)
64 {
65 }
66 
67 BBNodeInfo::BBNodeInfo(blocRef _block) : loop_id(0), cer(0), block(std::move(_block))
68 {
69 }
70 
72 {
73  statements_list.push_back(op);
74 }
75 
76 size_t BBNodeInfo::size() const
77 {
78  return statements_list.size();
79 }
80 
82 {
83  return statements_list.front();
84 }
85 
87 {
88  return statements_list.back();
89 }
90 
91 bool BBNodeInfo::empty() const
92 {
93  return statements_list.empty();
94 }
95 
96 unsigned int BBNodeInfo::get_bb_index() const
97 {
98  return block->number;
99 }
100 
102 {
103  return block->live_in;
104 }
105 
107 {
108  return block->live_out;
109 }
110 
111 /*const std::map<unsigned int, unsigned int> & BBNodeInfo::get_live_out_phi_defs() const
112 {
113  return block->live_out_phi_defs;
114 }*/
115 
116 BBEdgeInfo::BBEdgeInfo() : epp_value(0)
117 {
118 }
119 
120 BBEdgeInfo::~BBEdgeInfo() = default;
121 
122 void BBEdgeInfo::set_epp_value(unsigned long long _epp_value)
123 {
124  epp_value = _epp_value;
125 }
126 
127 unsigned long long BBEdgeInfo::get_epp_value() const
128 {
129  return epp_value;
130 }
131 
132 BBGraphInfo::BBGraphInfo(const application_managerConstRef _AppM, const unsigned int _function_index)
133  : GraphInfo(), AppM(_AppM), function_index(_function_index), entry_vertex(NULL_VERTEX), exit_vertex(NULL_VERTEX)
134 {
135 }
136 
138  : graphs_collection(RefcountCast<GraphInfo>(bb_graph_info), _parameters)
139 {
140 }
141 
143 
144 BBGraph::BBGraph(const BBGraphsCollectionRef _g, int _selector) : graph(_g.get(), _selector)
145 {
146 }
147 
149  : graph(_g.get(), _selector, sub)
150 {
151 }
152 
153 void BBGraph::WriteDot(const std::string& file_name, const int detail_level) const
154 {
156  WriteDot(file_name, annotated, detail_level);
157 }
158 
159 void BBGraph::WriteDot(const std::string& file_name, const CustomUnorderedSet<vertex>& annotated, const int) const
160 {
161  const auto bb_graph_info = CGetBBGraphInfo();
162  const auto function_name = bb_graph_info->AppM->CGetFunctionBehavior(bb_graph_info->function_index)
163  ->CGetBehavioralHelper()
164  ->get_function_name();
165  std::string output_directory =
166  collection->parameters->getOption<std::string>(OPT_dot_directory) + "/" + function_name + "/";
167  if(not std::filesystem::exists(output_directory))
168  {
169  std::filesystem::create_directories(output_directory);
170  }
171  const std::string full_name = output_directory + file_name;
172  const VertexWriterConstRef bb_writer(new BBWriter(this, annotated));
173  const EdgeWriterConstRef bb_edge_writer(new BBEdgeWriter(this));
174  InternalWriteDot<const BBWriter, const BBEdgeWriter>(full_name, bb_writer, bb_edge_writer);
175 }
176 
177 size_t BBGraph::num_bblocks() const
178 {
179  return boost::num_vertices(m_g) - 2;
180 }
181 
183 {
184  return labels.find(CDG_SELECTOR) != labels.end() and
185  labels.find(CDG_SELECTOR)->second.find(T_COND) != labels.find(CDG_SELECTOR)->second.end();
186 }
187 
189 {
190  return labels.find(CDG_SELECTOR) != labels.end() and
191  labels.find(CDG_SELECTOR)->second.find(F_COND) != labels.find(CDG_SELECTOR)->second.end();
192 }
193 
195 {
196  return labels.find(CFG_SELECTOR) != labels.end() and
197  labels.find(CFG_SELECTOR)->second.find(T_COND) != labels.find(CFG_SELECTOR)->second.end();
198 }
199 
201 {
202  return labels.find(CFG_SELECTOR) != labels.end() and
203  labels.find(CFG_SELECTOR)->second.find(F_COND) != labels.find(CFG_SELECTOR)->second.end();
204 }
205 
207 {
208  return !cdg_edge_T() and !cdg_edge_F() and !cfg_edge_T() and !cfg_edge_F() and
209  (labels.find(CDG_SELECTOR) != labels.end() or labels.find(CFG_SELECTOR) != labels.end());
210 }
211 
213 {
214  if(labels.find(selector) != labels.end())
215  {
216  return labels.find(selector)->second;
217  }
218  else
219  {
221  }
222 }
223 
224 #if !HAVE_UNORDERED
225 BBVertexSorter::BBVertexSorter(const BBGraphConstRef _bb_graph) : bb_graph(_bb_graph)
226 {
227 }
228 
229 bool BBVertexSorter::operator()(const vertex x, const vertex y) const
230 {
231  return bb_graph->CGetBBNodeInfo(x)->block->number < bb_graph->CGetBBNodeInfo(y)->block->number;
232 }
233 
234 BBEdgeSorter::BBEdgeSorter(const BBGraphConstRef _bb_graph) : bb_graph(_bb_graph), bb_sorter(_bb_graph)
235 {
236 }
237 
239 {
240  const vertex source_x = boost::source(x, *bb_graph);
241  const vertex source_y = boost::source(y, *bb_graph);
242  if(source_x == source_y)
243  {
245  }
246  else
247  {
248  return bb_sorter(source_x, source_y);
249  }
250 }
251 #endif
BBVertexSorter bb_sorter
The vertex sorter.
const CustomOrderedSet< unsigned int > & get_live_in() const
Returns the live in of the basic block.
const ParameterConstRef parameters
Set of input parameters.
Definition: graph.hpp:291
Base class storing user data information to the whole graph.
Definition: graph_info.hpp:60
string target
Definition: lenet_tvm.py:16
bool operator()(const vertex x, const vertex y) const
Compare position of two vertices.
Definition of the class representing a generic C application.
const CustomOrderedSet< unsigned int > get_labels(const int selector) const
Return the labels associated with a selector.
void WriteDot(const std::string &file_name, const int detail_level=0) const
Writes this graph in dot format.
const BBGraphInfoConstRef CGetBBGraphInfo() const
Returns the property associated with the graph.
Class specification of the graph structures.
bool cdg_edge_F() const
Function returning true when the edge is an else control dependence edge, false otherwise.
Definition of hash function for EdgeDescriptor.
Definition: graph.hpp:1321
BBGraphsCollection(const BBGraphInfoRef bb_graph_info, const ParameterConstRef parameters)
Constructor.
Data structure describing a basic block at tree level.
BBEdgeSorter(const BBGraphConstRef bb_graph)
Constructor.
std::list< vertex > statements_list
List of operation vertices associated with basic block node.
bool cfg_edge_T() const
Function returning true when the edge is a then control flow edge, false otherwise.
bool cdg_edge_T() const
Function returning true when the edge is a then control dependence edge, false otherwise.
unsigned long long epp_value
edge instrumented weight
unsigned int cer
id of the control equivalent region
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
#define CDG_SELECTOR
Control dependence edge selector.
BBNodeInfo()
Empty constructor.
Definition: basic_block.cpp:63
const int selector
selector
Definition: graph.hpp:849
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
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
#define T_COND
constant used to represent control edges representing a true edge of a conditional statement...
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
~BBGraphsCollection() override
Destructor.
This struct specifies the block node.
Definition: tree_node.hpp:1820
bool cfg_edge_F() const
Function returning true when the edge is an else control flow edge, false otherwise.
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) ...
string full_name
Definition: test_panda.py:841
BBVertexSorter(const BBGraphConstRef bb_graph)
Constructor.
void add_operation_node(const vertex op)
Adds an operation to the list of the statements.
Definition: basic_block.cpp:71
Collect all structs used to write a graph in the dot format.
Class specification of the basic_block structure.
BBGraph(const BBGraphsCollectionRef _g, int selector)
Standard constructor.
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
bool switch_p() const
Function returning true when the edge is a control flow edge exiting from a switch, false otherwise.
void set_epp_value(unsigned long long _epp_value)
Function that sets the epp_edge associated with the edge.
BBGraphInfo(const application_managerConstRef AppM, const unsigned int function_index)
Constructor with profiling information.
this class is used to manage the command-line or XML options.
~BBEdgeInfo() override
Destructor.
#define F_COND
constant used to represent control edges representing a false edge of a conditional statement...
unsigned int get_bb_index() const
Returns the index of the basic block.
Definition: basic_block.cpp:96
size_t num_bblocks() const
Returns the number of basic blocks contained into the graph.
bool operator()(const EdgeDescriptor x, const EdgeDescriptor y) const
Compare position of two edges.
x
Return the smallest n such that 2^n >= _x.
BBEdgeInfo()
Constructor.
BBGraphConstRef bb_graph
The basic block graph to which vertices belong Note: this should be const, but can not because of ass...
graphs_collection * collection
The graph collection.
Definition: graph.hpp:846
Class which prints the edge of a basic block graph in dot format.
#define CFG_SELECTOR
Control flow graph edge selector.
vertex get_last_operation() const
Returns the last operation vertex associated with the basic block.
Definition: basic_block.cpp:86
unsigned long long get_epp_value() const
Function returning the epp_value associated with the edge.
vertex get_first_operation() const
Returns the first operation vertex associated with the basic block.
Definition: basic_block.cpp:81
#define NULL_VERTEX
null vertex definition
Definition: graph.hpp:1305
A brief description of the C++ Header File.
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