PandA-2024.02
op_cdg_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  */
40 #include "op_cdg_computation.hpp"
42 
44 #include "Parameter.hpp"
45 
47 #include "Dominance.hpp"
48 
50 #include "basic_block.hpp"
51 #include "function_behavior.hpp"
52 #include "hash_helper.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_CONTROL_DEPENDENCE_COMPUTATION, _design_flow_manager, _Param)
60 {
61  debug_level = parameters->get_class_debug_level(GET_CLASS(*this));
62 }
63 
65 
68 {
70  switch(relationship_type)
71  {
73  {
74  relationships.insert(std::make_pair(BB_CONTROL_DEPENDENCE_COMPUTATION, SAME_FUNCTION));
75  relationships.insert(std::make_pair(OPERATIONS_CFG_COMPUTATION, SAME_FUNCTION));
76  relationships.insert(std::make_pair(OP_ORDER_COMPUTATION, SAME_FUNCTION));
77  break;
78  }
81  {
82  break;
83  }
84  default:
85  {
87  }
88  }
89  return relationships;
90 }
91 
93 {
94  if(bb_version != 0 and bb_version != function_behavior->GetBBVersion())
95  {
97  if(boost::num_vertices(*cdg) != 0)
98  {
99  EdgeIterator edge, edge_end;
100  for(boost::tie(edge, edge_end) = boost::edges(*cdg); edge != edge_end; edge++)
101  {
102  function_behavior->ogc->RemoveSelector(*edge, CDG_SELECTOR);
103  }
104  }
105  }
106 }
107 
109 {
110  const auto fcfg = function_behavior->fcfg;
111  const auto bb_cdg = function_behavior->CGetBBGraph(FunctionBehavior::CDG_BB);
112  EdgeIterator edge, edge_end;
113  for(boost::tie(edge, edge_end) = boost::edges(*bb_cdg); edge != edge_end; edge++)
114  {
115  const auto source = boost::source(*edge, *bb_cdg);
116  const auto target = boost::target(*edge, *bb_cdg);
117  const auto source_operations = bb_cdg->CGetBBNodeInfo(source)->statements_list;
118  const auto target_operations = bb_cdg->CGetBBNodeInfo(target)->statements_list;
119  if(source_operations.size() and target_operations.size())
120  {
121  const auto labels = bb_cdg->CGetBBEdgeInfo(*edge)->get_labels(CFG_SELECTOR);
122  const auto source_operation = source_operations.back();
123  for(const auto target_operation : target_operations)
124  {
126  "---Adding Control Dependence " + GET_NAME(fcfg, source_operation) + "-->" +
127  GET_NAME(fcfg, target_operation));
128  function_behavior->ogc->AddEdge(source_operation, target_operation, CDG_SELECTOR);
129  for(const auto label : labels)
130  {
131  function_behavior->ogc->add_edge_info(source_operation, target_operation, CDG_SELECTOR, label);
132  }
133  }
134  }
135  }
136 
137  VertexIterator basic_block, basic_block_end;
138  for(boost::tie(basic_block, basic_block_end) = boost::vertices(*bb_cdg); basic_block != basic_block_end;
139  basic_block++)
140  {
141  const auto bb_node_info = bb_cdg->CGetBBNodeInfo(*basic_block);
142  const auto cer_index = bb_node_info->cer;
143  for(const auto statement : bb_node_info->statements_list)
144  {
145  fcfg->GetOpNodeInfo(statement)->cer = cer_index;
146  }
147  }
148 
149  if(parameters->getOption<bool>(OPT_print_dot))
150  {
151  function_behavior->CGetOpGraph(FunctionBehavior::CDG)->WriteDot("OP_CDG.dot");
152  }
154 }
void Initialize() override
Initialize the step (i.e., like a constructor, but executed just before exec.
#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;.
string target
Definition: lenet_tvm.py:16
#define GET_CLASS(obj)
Macro returning the actual type of an object.
DesignFlowStep_Status InternalExec() override
Performs the computation of the CDG representation.
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.
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
Control dependence graph.
#define CDG_SELECTOR
Control dependence edge selector.
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.
~OpCdgComputation() override
Destructor.
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.
Basic block control dependence graph.
Class specification of the basic_block structure.
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
this class is used to manage the command-line or XML options.
int debug_level
The debug level.
Analysis step computing operation control dependencies.
This class provides methods to build an operations graph.
OpCdgComputation(const ParameterConstRef Param, const application_managerRef AppM, unsigned int function_id, const DesignFlowManagerConstRef design_flow_manager)
Constructor.
#define CFG_SELECTOR
Control flow graph edge selector.
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