PandA-2024.02
bb_order_computation.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  */
42 #include "bb_order_computation.hpp"
44 
46 #include "Parameter.hpp"
47 
49 #include "basic_block.hpp"
50 #include "function_behavior.hpp"
51 #include "level_constructor.hpp"
52 
54 #include "behavioral_helper.hpp"
55 #include "dbgPrintHelper.hpp" // for DEBUG_LEVEL_
56 #include "hash_helper.hpp"
57 #include "string_manipulation.hpp" // for GET_CLASS
58 #include "tree_basic_block.hpp"
59 
61  unsigned int _function_id, const DesignFlowManagerConstRef _design_flow_manager)
62  : FunctionFrontendFlowStep(_AppM, _function_id, BB_ORDER_COMPUTATION, _design_flow_manager, _Param)
63 {
64  debug_level = parameters->get_class_debug_level(GET_CLASS(*this), DEBUG_LEVEL_NONE);
65 }
66 
68 
71 {
73  switch(relationship_type)
74  {
76  {
77  relationships.insert(std::make_pair(BB_FEEDBACK_EDGES_IDENTIFICATION, SAME_FUNCTION));
78  break;
79  }
82  {
83  break;
84  }
85  default:
86  {
88  }
89  }
90  return relationships;
91 }
92 
94 {
95  if(bb_version != 0 and bb_version != function_behavior->GetBBVersion())
96  {
97  function_behavior->bb_map_levels.clear();
98  function_behavior->bb_deque_levels.clear();
99  }
100 }
101 
103 {
105  "-->Starting order computation on function " +
106  function_behavior->CGetBehavioralHelper()->get_function_name());
107  const BBGraphConstRef ebb = function_behavior->CGetBBGraph(FunctionBehavior::EBB);
108  VertexIterator bb_v, bb_v_end;
110  std::list<vertex> to_visit;
111  unsigned int index;
112  std::map<graph::vertex_descriptor, bool> MARK;
113 
115  for(boost::tie(bb_v, bb_v_end) = boost::vertices(*ebb); bb_v != bb_v_end; ++bb_v)
116  {
117  MARK[*bb_v] = false;
118  }
120  to_visit.push_front(ebb->CGetBBGraphInfo()->entry_vertex);
121  index = 0;
122  while(!to_visit.empty())
123  {
124  vertex actual = to_visit.front();
126  "-->Checking vertex BB" + std::to_string(ebb->CGetBBNodeInfo(actual)->block->number));
127  to_visit.pop_front();
128  MARK[actual] = true;
129  function_behavior->bb_lm->add(actual, index++);
130  graph::out_edge_iterator o, o_end;
131  graph::in_edge_iterator i, i_end;
132  vertex then = NULL_VERTEX;
134  for(boost::tie(o, o_end) = boost::out_edges(actual, *ebb); o != o_end; o++)
135  {
136  bool toadd = true;
137  vertex next = boost::target(*o, *ebb);
139  "-->Checking successor vertex BB" + std::to_string(ebb->CGetBBNodeInfo(next)->block->number));
141  for(boost::tie(i, i_end) = boost::in_edges(next, *ebb); i != i_end; i++)
142  {
143  if(!MARK[boost::source(*i, *ebb)])
144  {
146  "---Checking its predecessor BB" +
147  std::to_string(ebb->CGetBBNodeInfo(boost::source(*i, *ebb))->block->number) +
148  " - Not marked");
149  toadd = false;
150  break;
151  }
153  "---Checking its predecessor BB" +
154  std::to_string(ebb->CGetBBNodeInfo(boost::source(*i, *ebb))->block->number) +
155  " - Marked");
156  }
157  if(toadd)
158  {
159  if(ebb->CGetBBEdgeInfo(*o)->cfg_edge_T())
160  {
161  then = next;
162  }
164  if(next != then)
165  {
166  to_visit.push_front(next);
167  }
168  }
170  }
171  if(then)
172  {
173  to_visit.push_front(then);
174  }
176  }
177 
179  const std::map<vertex, unsigned int>& bb_map_levels = function_behavior->get_bb_map_levels();
180  if(bb_map_levels.find(ebb->CGetBBGraphInfo()->exit_vertex) == bb_map_levels.end())
181  {
182  function_behavior->bb_lm->add(ebb->CGetBBGraphInfo()->exit_vertex, index++);
183  }
186 }
~BBOrderComputation() override
Destructor.
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
File containing functions and utilities to support the printing of debug messagges.
string target
Definition: lenet_tvm.py:16
#define GET_CLASS(obj)
Macro returning the actual type of an object.
Data structore used to build the topological order of the operations vertices.
RelationshipType
The relationship type.
Source must be executed to satisfy target.
Basic block control flow graph with edges imposing that basic block inside a loop are executed before...
Data structure describing a basic block at tree level.
unsigned int bb_version
The version of the basic block intermediate representation on which this step has been applied...
Auxiliary methods for manipulating string.
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
Definition: exceptions.hpp:292
void Initialize() override
Initialize the step (i.e., like a constructor, but executed just before exec.
DesignFlowStep_Status InternalExec() override
Computes a topological order of the operations according to the control flow graph.
#define index(x, y)
Definition: Keccak.c:74
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
boost::graph_traits< graph >::vertex_iterator VertexIterator
vertex_iterator definition.
Definition: graph.hpp:1307
const ParameterConstRef parameters
Set of input parameters.
DesignFlowStep_Status
The status of a step.
#define DEBUG_LEVEL_NONE
no debugging print is performed.
Class specification of the basic_block structure.
BBOrderComputation(const ParameterConstRef Param, const application_managerRef AppM, unsigned int function_id, const DesignFlowManagerConstRef design_flow_manager)
Constructor.
This file collects some hash functors.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
this class is used to manage the command-line or XML options.
int debug_level
The debug level.
const CustomUnorderedSet< std::pair< FrontendFlowStepType, FunctionRelationship > > ComputeFrontendRelationships(const DesignFlowStep::RelationshipType relationship_type) const override
Return the set of analyses in relationship with this design step.
#define NULL_VERTEX
null vertex definition
Definition: graph.hpp:1305
A brief description of the C++ Header File.
const FunctionBehaviorRef function_behavior
The function behavior of the function to be analyzed.

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