PandA-2024.02
bb_reachability_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  */
45 
47 #include "Parameter.hpp"
48 
50 #include "loop.hpp"
51 #include "loops.hpp"
52 
54 #include "application_manager.hpp"
55 #include "basic_block.hpp"
56 #include "function_behavior.hpp"
57 
59 #include "graph.hpp"
60 
62 #include "tree_basic_block.hpp"
63 
65 #include "custom_map.hpp"
66 #include "custom_set.hpp"
67 #include "dbgPrintHelper.hpp" // for DEBUG_LEVEL_
68 #include "hash_helper.hpp"
69 #include "string_manipulation.hpp" // for GET_CLASS
70 
72  unsigned int _function_id,
73  const DesignFlowManagerConstRef _design_flow_manager)
74  : FunctionFrontendFlowStep(_AppM, _function_id, BB_REACHABILITY_COMPUTATION, _design_flow_manager, _Param)
75 {
76  debug_level = _Param->get_class_debug_level(GET_CLASS(*this), DEBUG_LEVEL_NONE);
77 }
78 
80 
82 {
83  if(bb_version != 0 and bb_version != function_behavior->GetBBVersion())
84  {
85  function_behavior->bb_reachability.clear();
86  function_behavior->feedback_bb_reachability.clear();
87  }
88 }
89 
92 {
94  switch(relationship_type)
95  {
97  {
98  relationships.insert(std::make_pair(ADD_BB_ECFG_EDGES, SAME_FUNCTION));
99  relationships.insert(std::make_pair(BB_FEEDBACK_EDGES_IDENTIFICATION, SAME_FUNCTION));
100  break;
101  }
104  {
105  break;
106  }
107  default:
108  {
109  THROW_UNREACHABLE("");
110  }
111  }
112  return relationships;
113 }
114 
116 {
118  const BBGraphConstRef ecfg = function_behavior->CGetBBGraph(FunctionBehavior::EBB);
119 
121  auto& bb_reachability = function_behavior->bb_reachability;
122  auto& feedback_bb_reachability = function_behavior->feedback_bb_reachability;
123 
124  std::deque<vertex> container;
125  boost::topological_sort(*ecfg, std::back_inserter(container));
126  std::deque<vertex>::const_iterator it, it_end;
127  it_end = container.end();
128  for(it = container.begin(); it != it_end; ++it)
129  {
131  " Examining basic block " + std::to_string(ecfg->CGetBBNodeInfo(*it)->block->number));
132  OutEdgeIterator eo, eo_end;
133  for(boost::tie(eo, eo_end) = boost::out_edges(*it, *ecfg); eo != eo_end; eo++)
134  {
135  vertex previous = boost::target(*eo, *ecfg);
136  bb_reachability[*it].insert(previous);
137  bb_reachability[*it].insert(bb_reachability[previous].begin(), bb_reachability[previous].end());
138  }
139  }
140 
141  feedback_bb_reachability = bb_reachability;
142 
144  const LoopConstRef zero_loop = function_behavior->CGetLoops()->CGetLoop(0);
145  const CustomOrderedSet<LoopConstRef>& first_level_loops = zero_loop->GetChildren();
146  CustomOrderedSet<LoopConstRef>::const_iterator first_level_loop, first_level_loop_end = first_level_loops.end();
147  for(first_level_loop = first_level_loops.begin(); first_level_loop != first_level_loop_end; ++first_level_loop)
148  {
149  CustomUnorderedSet<vertex> loop_blocks;
150  (*first_level_loop)->get_recursively_bb(loop_blocks);
151  CustomUnorderedSet<vertex>::const_iterator loop_block, loop_block_end = loop_blocks.end();
152  for(loop_block = loop_blocks.begin(); loop_block != loop_block_end; ++loop_block)
153  {
154  feedback_bb_reachability[*loop_block].insert(loop_blocks.begin(), loop_blocks.end());
155  }
156  }
158 }
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
boost::graph_traits< graph >::out_edge_iterator OutEdgeIterator
out_edge_iterator definition.
Definition: graph.hpp:1312
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;.
BBReachabilityComputation(const ParameterConstRef Param, const application_managerRef AppM, unsigned int function_id, const DesignFlowManagerConstRef design_flow_manager)
Constructor.
string target
Definition: lenet_tvm.py:16
#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.
~BBReachabilityComputation() override
Destructor.
Class specification of the graph structures.
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...
Analysis step computing reachability between basic blocks.
redefinition of map to manage ordered/unordered structures
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
redefinition of set to manage ordered/unordered structures
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
DesignFlowStep_Status
The status of a step.
#define DEBUG_LEVEL_NONE
no debugging print is performed.
DesignFlowStep_Status InternalExec() override
Computes the reachability between operations according to the control flow graph WITHOUT feedback...
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.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
interface of loops finding algorithm
this class is used to manage the command-line or XML options.
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.
void Initialize() override
Initialize the step (i.e., like a constructor, but executed just before exec.
int debug_level
The debug level.
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