PandA-2024.02
add_op_loop_flow_edges.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 
48 #include "loop.hpp"
49 #include "loops.hpp"
50 
52 #include "application_manager.hpp"
53 #include "basic_block.hpp"
54 #include "behavioral_helper.hpp"
55 #include "function_behavior.hpp"
56 #include "op_graph.hpp"
58 
60 #include "tree_basic_block.hpp"
61 
63 #include "Parameter.hpp"
64 #include "dbgPrintHelper.hpp" // for DEBUG_LEVEL_
65 #include "hash_helper.hpp"
66 #include "string_manipulation.hpp" // for GET_CLASS
67 
69  unsigned int _function_id, const DesignFlowManagerConstRef _design_flow_manager)
70  : FunctionFrontendFlowStep(_AppM, _function_id, ADD_OP_LOOP_FLOW_EDGES, _design_flow_manager, _parameters)
71 {
72  debug_level = parameters->get_class_debug_level(GET_CLASS(*this), DEBUG_LEVEL_NONE);
73 }
74 
76 
79 {
81  switch(relationship_type)
82  {
84  {
85  relationships.insert(std::make_pair(OP_CONTROL_DEPENDENCE_COMPUTATION, SAME_FUNCTION));
86  relationships.insert(std::make_pair(OP_FEEDBACK_EDGES_IDENTIFICATION, SAME_FUNCTION));
87  relationships.insert(std::make_pair(OP_REACHABILITY_COMPUTATION, SAME_FUNCTION));
88  relationships.insert(std::make_pair(SCALAR_SSA_DATA_FLOW_ANALYSIS, SAME_FUNCTION));
89  relationships.insert(std::make_pair(VIRTUAL_AGGREGATE_DATA_FLOW_ANALYSIS, SAME_FUNCTION));
90  break;
91  }
94  {
95  break;
96  }
97  default:
98  {
100  }
101  }
102  return relationships;
103 }
104 
106 {
107  if(bb_version != 0 && bb_version != function_behavior->GetBBVersion())
108  {
109  const OpGraphConstRef flg = function_behavior->CGetOpGraph(FunctionBehavior::FLG);
110  if(boost::num_vertices(*flg) != 0)
111  {
112  EdgeIterator edge, edge_end;
113  for(boost::tie(edge, edge_end) = boost::edges(*flg); edge != edge_end; edge++)
114  {
115  function_behavior->ogc->RemoveSelector(*edge, FLG_SELECTOR);
116  }
117  }
118  }
119 }
120 
122 {
124  const OpGraphConstRef fcfg = function_behavior->CGetOpGraph(FunctionBehavior::FCFG);
125 
127  const OpGraphConstRef fflsaodg = function_behavior->CGetOpGraph(FunctionBehavior::FFLSAODG);
128 
130  const BBGraphRef fbb = function_behavior->GetBBGraph(FunctionBehavior::FBB);
131 
134 
136  const std::list<LoopConstRef>& loops = function_behavior->CGetLoops()->GetList();
137 
139  std::list<LoopConstRef>::const_iterator loop, loop_end = loops.end();
140  for(loop = loops.begin(); loop != loop_end; ++loop)
141  {
142  PRINT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "Considering loop " + std::to_string((*loop)->GetId()));
143  if(!(*loop)->IsReducible())
144  {
145  THROW_ERROR_CODE(IRREDUCIBLE_LOOPS_EC, "Irreducible loops not yet supported");
146  }
147 
149  const CustomUnorderedSet<vertex>& loop_bb = (*loop)->get_blocks();
150  CustomUnorderedSet<vertex>::const_iterator it, it_end = loop_bb.end();
151  for(it = loop_bb.begin(); it != it_end; ++it)
152  {
153  const BBNodeInfoConstRef bb_node_info = fbb->CGetBBNodeInfo(*it);
155  const std::list<vertex>& statements_list = bb_node_info->statements_list;
156  std::list<vertex>::const_iterator it2, it2_end = statements_list.end();
157  for(it2 = statements_list.begin(); it2 != it2_end; ++it2)
158  {
159  if(bb_node_info->block->number != bb_node_info->loop_id)
160  {
162  loop_operations[(*loop)->GetId()].insert(*it2);
163  }
164  }
165  }
166 
168  const vertex header = (*loop)->GetHeader();
169  const BBNodeInfoConstRef bb_node_info = fbb->CGetBBNodeInfo(header);
170  const std::list<vertex>& statements_list = bb_node_info->statements_list;
171  THROW_ASSERT(statements_list.size(), "Header of a loop " + std::to_string((*loop)->GetId()) + " is empty");
172  const vertex last_statement = *(statements_list.rbegin());
173 
176  auto it3_end = loop_operations[(*loop)->GetId()].end();
177  for(auto it3 = loop_operations[(*loop)->GetId()].begin(); it3 != it3_end; ++it3)
178  {
180  "Adding flow edge from " + GET_NAME(fcfg, last_statement) + " to " + GET_NAME(fcfg, *it3));
181  function_behavior->ogc->AddEdge(last_statement, *it3, FLG_SELECTOR);
182  }
184  const vertex first_statement = *(statements_list.begin());
185  for(auto it3 = loop_operations[(*loop)->GetId()].begin(); it3 != it3_end; ++it3)
186  {
188  "Adding a feedback flow edge from " + GET_NAME(fcfg, *it3) + " to " +
189  GET_NAME(fcfg, first_statement));
190  function_behavior->ogc->AddEdge(*it3, first_statement, FB_FLG_SELECTOR);
191  }
192  }
193 
194 #ifndef NDEBUG
195  const std::string function_name = function_behavior->CGetBehavioralHelper()->get_function_name();
196 #endif
197  if(parameters->getOption<bool>(OPT_print_dot))
198  {
199  function_behavior->CGetOpGraph(FunctionBehavior::FLG)->WriteDot("OP_FL.dot");
200  function_behavior->CGetOpGraph(FunctionBehavior::FFLSAODG)->WriteDot("OP_FFLSAODG.dot");
201  }
202 #ifndef NDEBUG
203  try
204  {
205  const OpGraphConstRef flsaodg = function_behavior->CGetOpGraph(FunctionBehavior::FLSAODG);
206  std::deque<vertex> vertices;
207  boost::topological_sort(*flsaodg, std::front_inserter(vertices));
208  }
209  catch(const char* msg)
210  {
211  THROW_UNREACHABLE("flsaodg graph of function " + function_name + " is not acyclic");
212  }
213  catch(const std::string& msg)
214  {
215  THROW_UNREACHABLE("flsaodg graph of function " + function_name + " is not acyclic");
216  }
217  catch(const std::exception& ex)
218  {
219  THROW_UNREACHABLE("flsaodg graph of function " + function_name + " is not acyclic");
220  }
221  catch(...)
222  {
223  THROW_UNREACHABLE("flsaodg graph of function " + function_name + " is not acyclic");
224  }
225 #endif
227 }
#define FLG_SELECTOR
Flow edge selector.
Definition: op_graph.hpp:515
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
File containing functions and utilities to support the printing of debug messagges.
#define PRINT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
Definition of the class representing a generic C application.
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.
Analysis step which adds flow edges for scheduling to operation graphs.
DesignFlowStep_Status InternalExec() override
Performs the adding of flow edges to operation graphs.
#define FB_FLG_SELECTOR
Feedback flow edge selector.
Definition: op_graph.hpp:518
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.
boost::graph_traits< graph >::edge_iterator EdgeIterator
edge_iterator definition.
Definition: graph.hpp:1314
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
Definition: exceptions.hpp:292
unsigned edges[4545]
Definition: graph.h:25
absl::flat_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMap
Definition: custom_map.hpp:148
~AddOpLoopFlowEdges() override
Destructor.
Basic block control flow graph with feedback.
AddOpLoopFlowEdges(const ParameterConstRef _parameters, const application_managerRef AppM, unsigned int function_id, const DesignFlowManagerConstRef design_flow_manager)
Constructor.
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.
void Initialize() override
Initialize the step (i.e., like a constructor, but executed just before exec.
Class specification of the basic_block structure.
This file collects some hash functors.
interface of a loop
const BBNodeInfoConstRef CGetBBNodeInfo(const vertex node) const
Return the info associated with a basic block.
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
irreducible loops are not currently supported
Definition: exceptions.hpp:324
#define THROW_ERROR_CODE(code, str_expr)
helper function used to throw an error with a code error
Definition: exceptions.hpp:266
interface of loops finding algorithm
System dependence + anti-dependence + output dependence graph + flow graph.
this class is used to manage the command-line or XML options.
Control flow graph with feedback.
int debug_level
The debug level.
This class provides methods to build an operations graph.
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.
System dependence + anti-dependence + output dependence graph + flow graph with feedback.
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