PandA-2024.02
op_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 "op_order_computation.hpp"
44 
46 #include "Parameter.hpp"
47 
49 #include "dbgPrintHelper.hpp" // for DEBUG_LEVEL_
50 #include "function_behavior.hpp"
51 #include "hash_helper.hpp"
52 #include "level_constructor.hpp"
53 #include "op_graph.hpp"
55 #include "string_manipulation.hpp" // for GET_CLASS
56 
58  unsigned int _function_id, const DesignFlowManagerConstRef _design_flow_manager)
59  : FunctionFrontendFlowStep(_AppM, _function_id, OP_ORDER_COMPUTATION, _design_flow_manager, _Param)
60 {
61  debug_level = parameters->get_class_debug_level(GET_CLASS(*this), DEBUG_LEVEL_NONE);
62 }
63 
65 
68 {
70  switch(relationship_type)
71  {
73  {
74  relationships.insert(std::make_pair(OP_FEEDBACK_EDGES_IDENTIFICATION, SAME_FUNCTION));
75  break;
76  }
79  {
80  break;
81  }
82  default:
83  {
85  }
86  }
87  return relationships;
88 }
89 
91 {
92  if(bb_version != 0 and bb_version != function_behavior->GetBBVersion())
93  {
94  function_behavior->map_levels.clear();
95  function_behavior->deque_levels.clear();
96  }
97 }
98 
100 {
101  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Starting order computation on Operation CFG");
102  const OpGraphConstRef cfg = function_behavior->CGetOpGraph(FunctionBehavior::ECFG);
103  graph::vertex_iterator v, v_end;
104  std::list<vertex> to_visit;
105  unsigned int index;
107  std::map<graph::vertex_descriptor, bool> MARK;
108 
110  for(boost::tie(v, v_end) = boost::vertices(*cfg); v != v_end; ++v)
111  {
112  MARK[*v] = false;
113  }
114  // Vertex list to be visited
115  to_visit.push_front(function_behavior->ogc->CgetIndex(ENTRY));
116  index = 0;
117  while(!to_visit.empty())
118  {
119  vertex actual = to_visit.front();
121  "-->Checking vertex " + GET_NAME(cfg, actual) + " : " + std::to_string(index));
122  to_visit.pop_front();
123  MARK[actual] = true;
124  function_behavior->lm->add(actual, index++);
125  graph::out_edge_iterator o, o_end;
126  graph::in_edge_iterator i, i_end;
127  vertex then = NULL_VERTEX;
129  for(boost::tie(o, o_end) = boost::out_edges(actual, *cfg); o != o_end; o++)
130  {
131  bool toadd = true;
132  vertex next = boost::target(*o, *cfg);
133  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Considering successor " + GET_NAME(cfg, next));
135  for(boost::tie(i, i_end) = boost::in_edges(next, *cfg); i != i_end; i++)
136  {
137  if(!MARK[boost::source(*i, *cfg)])
138  {
140  "---Not adding because of predecessor " + GET_NAME(cfg, boost::source(*i, *cfg)));
141  toadd = false;
142  break;
143  }
144  }
145  if(toadd)
146  {
147  if(Cget_edge_info<OpEdgeInfo>(*o, *cfg) && CFG_TRUE_CHECK(cfg, *o))
148  {
149  then = next;
150  }
152  if(next != then)
153  {
154  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Adding next " + GET_NAME(cfg, next));
155  to_visit.push_front(next);
156  }
157  }
159  }
160  if(then)
161  {
162  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Adding then " + GET_NAME(cfg, then));
163  to_visit.push_front(then);
164  }
166  }
168  const std::map<vertex, unsigned int>& map_levels = function_behavior->get_map_levels();
169  if(map_levels.find(function_behavior->ogc->CgetIndex(EXIT)) == map_levels.end())
170  {
171  function_behavior->lm->add(function_behavior->ogc->CgetIndex(EXIT), index++);
172  }
173 #ifndef NDEBUG
174  const auto exit = cfg->CGetOpGraphInfo()->exit_vertex;
175  for(boost::tie(v, v_end) = boost::vertices(*cfg); v != v_end; v++)
176  {
177  if(*v == exit)
178  {
179  continue;
180  }
181  THROW_ASSERT(MARK[*v], "Operation " + GET_NAME(cfg, *v) + " not analyzed");
182  }
183 #endif
186 }
#define CFG_TRUE_CHECK(data, edge_index)
check if the edge is a then control flow edge
#define EXIT
Definition: global.h:46
#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.
#define GET_NAME(data, vertex_index)
Helper macro returning the name associated with a node.
unsigned int bb_version
The version of the basic block intermediate representation on which this step has been applied...
Auxiliary methods for manipulating string.
Analysis step computing a topological order of the operations.
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
Definition: exceptions.hpp:292
#define ENTRY
Superclass include.
Extended control flow graph.
#define index(x, y)
Definition: Keccak.c:74
const OpGraphInfoConstRef CGetOpGraphInfo() const
Returns the property associated with the graph.
Definition: op_graph.hpp:871
OpOrderComputation(const ParameterConstRef Param, const application_managerRef AppM, unsigned int function_id, const DesignFlowManagerConstRef design_flow_manager)
Constructor.
void Initialize() override
Initialize the step (i.e., like a constructor, but executed just before exec.
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
const ParameterConstRef parameters
Set of input parameters.
DesignFlowStep_Status
The status of a step.
#define DEBUG_LEVEL_NONE
no debugging print is performed.
~OpOrderComputation() override
Destructor.
DesignFlowStep_Status InternalExec() override
Computes a topological order of the operations according to the control flow graph.
This file collects some hash functors.
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
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.
this class is used to manage the command-line or XML options.
int debug_level
The debug level.
This class provides methods to build an operations graph.
#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.
#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:51 for PandA-2024.02 by doxygen 1.8.13