PandA-2024.02
dataflow_cg_ext.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) 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  */
43 #include "dataflow_cg_ext.hpp"
44 
45 #include "Parameter.hpp"
46 #include "application_manager.hpp"
47 #include "behavioral_helper.hpp"
48 #include "call_graph_manager.hpp"
49 #include "dbgPrintHelper.hpp"
51 #include "function_behavior.hpp"
52 #include "hls_manager.hpp"
53 #include "tree_helper.hpp"
54 #include "tree_manager.hpp"
55 #include "tree_manipulation.hpp"
56 #include "tree_reindex.hpp"
57 
59  unsigned int _function_id, const DesignFlowManagerConstRef _design_flow_manager)
60  : FunctionFrontendFlowStep(_AppM, _function_id, DATAFLOW_CG_EXT, _design_flow_manager, _parameters)
61 {
62  debug_level = parameters->get_class_debug_level(GET_CLASS(*this), DEBUG_LEVEL_NONE);
63 }
64 
67 {
69  switch(relationship_type)
70  {
72  {
73  relationships.insert(std::make_pair(DATAFLOW_CG_EXT, CALLING_FUNCTIONS));
74  relationships.insert(std::make_pair(FUNCTION_ANALYSIS, WHOLE_APPLICATION));
75  relationships.insert(std::make_pair(USE_COUNTING, SAME_FUNCTION));
76  break;
77  }
79  {
80  break;
81  }
83  {
84  break;
85  }
86  default:
87  {
89  }
90  }
91  return relationships;
92 }
93 
95 {
97 }
98 
99 static void CleanVirtuals(const tree_managerRef& TM, const tree_nodeRef& call_stmt)
100 {
101  const auto gn = GetPointerS<gimple_node>(GET_NODE(call_stmt));
102  if(gn->vdef)
103  {
104  dead_code_elimination::kill_vdef(TM, gn->vdef);
105  gn->vdef = nullptr;
106  }
107  std::for_each(gn->vuses.begin(), gn->vuses.end(),
108  [&](auto& it) { GetPointer<ssa_name>(GET_NODE(it))->RemoveUse(call_stmt); });
109  gn->vuses.clear();
110  std::for_each(gn->vovers.begin(), gn->vovers.end(),
111  [&](auto& it) { GetPointer<ssa_name>(GET_NODE(it))->RemoveUse(call_stmt); });
112  gn->vovers.clear();
113  THROW_ASSERT(!gn->memdef && !gn->memuse, "Unexpected condition");
114 }
115 
117 {
118  const auto HLSMgr = GetPointer<HLS_manager>(AppM);
119  const auto fsymbol = function_behavior->CGetBehavioralHelper()->GetMangledFunctionName();
120  const auto func_arch = HLSMgr->module_arch->GetArchitecture(fsymbol);
121  const auto is_dataflow_top = func_arch &&
122  func_arch->attrs.find(FunctionArchitecture::func_dataflow) != func_arch->attrs.end() &&
123  func_arch->attrs.find(FunctionArchitecture::func_dataflow)->second == "top";
124  if(!is_dataflow_top)
125  {
127  }
128 
129  const auto TM = AppM->get_tree_manager();
130  const auto CGM = AppM->GetCallGraphManager();
131  const auto CG = CGM->CGetCallGraph();
132  const auto f_v = CGM->GetVertex(function_id);
133 
134  tree_manipulation tree_man(TM, parameters, AppM);
135 
136  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Expand Dataflow modules");
137  std::vector<unsigned int> new_modules;
138  BOOST_FOREACH(EdgeDescriptor ie, boost::out_edges(f_v, *CG))
139  {
140  const auto target_id = CGM->get_function(boost::target(ie, *CG));
141  const auto tsymbol = AppM->CGetFunctionBehavior(target_id)->CGetBehavioralHelper()->GetMangledFunctionName();
142  const auto tarch = HLSMgr->module_arch->GetArchitecture(tsymbol);
143  const auto is_dataflow_module = tarch &&
144  tarch->attrs.find(FunctionArchitecture::func_dataflow) != tarch->attrs.end() &&
145  tarch->attrs.find(FunctionArchitecture::func_dataflow)->second == "module";
146  if(!is_dataflow_module)
147  {
148  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Function " + tsymbol + " is not a dataflow module");
149  continue;
150  }
151  const auto call_info = CG->CGetFunctionEdgeInfo(ie);
152  if(call_info->function_addresses.size() || call_info->indirect_call_points.size())
153  {
154  THROW_ERROR("Address/indirect function calls not supported in dataflow.");
155  }
156 
157  const auto fnode = TM->CGetTreeReindex(function_id);
158  std::vector<unsigned int> call_points(++call_info->direct_call_points.begin(),
159  call_info->direct_call_points.end());
160  {
161  const auto first_call = TM->CGetTreeReindex(*call_info->direct_call_points.begin());
162  CleanVirtuals(TM, first_call);
163  }
164  for(auto call_id : call_points)
165  {
166  const auto call_node = TM->CGetTreeReindex(call_id);
167  const auto module_suffix = "_" + std::to_string(call_id);
169  "---Clone module " + tsymbol + " -> " + tsymbol + module_suffix);
170  CleanVirtuals(TM, call_node);
171  tree_man.VersionFunctionCall(call_node, fnode, module_suffix);
172  const auto version_symbol = tsymbol + module_suffix;
173  const auto version_fnode = TM->GetFunction(version_symbol);
174  THROW_ASSERT(version_fnode, "Expected version function node for " + version_symbol);
175  new_modules.push_back(GET_INDEX_CONST_NODE(version_fnode));
176  const auto march = FunctionArchitectureRef(new FunctionArchitecture(*tarch));
177  march->attrs.at(FunctionArchitecture::func_symbol) += module_suffix;
178  march->attrs.at(FunctionArchitecture::func_symbol) += module_suffix;
179  HLSMgr->module_arch->AddArchitecture(version_symbol, march);
180  }
181  }
183 
184  if(new_modules.size())
185  {
186  auto root_functions = CGM->GetRootFunctions();
187  root_functions.insert(new_modules.begin(), new_modules.end());
188  CGM->SetRootFunctions(root_functions);
189  function_behavior->UpdateBBVersion();
191  }
192 
194 }
#define GET_NODE(t)
Macro used to hide implementation details when accessing a tree_node from another tree_node...
Definition: tree_node.hpp:343
DesignFlowStep_Status InternalExec() override
Execute the step.
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
Data structure representing the entire HLS information.
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
static void CleanVirtuals(const tree_managerRef &TM, const tree_nodeRef &call_stmt)
File containing functions and utilities to support the printing of debug messagges.
Step successfully executed.
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.
unsigned int bb_version
The version of the basic block intermediate representation on which this step has been applied...
bool HasToBeExecuted() const override
Check if this step has actually to be executed.
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
Definition: exceptions.hpp:292
bool HasToBeExecuted() const override
Check if this step has actually to be executed.
Dataflow call graph extension.
const ParameterConstRef parameters
Set of input parameters.
DesignFlowStep_Status
The status of a step.
Eliminate dead code.
Class defining some useful functions to create tree nodes and to manipulate the tree manager...
#define DEBUG_LEVEL_NONE
no debugging print is performed.
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
Definition: exceptions.hpp:263
static tree_nodeRef kill_vdef(const tree_managerRef &TM, const tree_nodeRef &vdef)
Replace virtual ssa definition with gimple nop.
This file collects some utility functions.
const unsigned int function_id
The index of the function to be analyzed.
const application_managerRef AppM
The application manager.
bool VersionFunctionCall(const tree_nodeRef &call_node, const tree_nodeRef &caller_node, const std::string &version_suffix)
Perform function call versioning.
Class specification of the tree_reindex support class.
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.
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.
Wrapper to call graph.
int debug_level
The debug level.
dataflow_cg_ext(const ParameterConstRef _parameters, const application_managerRef AppM, unsigned int function_id, const DesignFlowManagerConstRef design_flow_manager)
#define GET_INDEX_CONST_NODE(t)
Definition: tree_node.hpp:363
This class creates a layer to add nodes and to manipulate the tree_nodes manager. ...
Class specification of the manager of the tree structures extracted from the raw file.
A brief description of the C++ Header File.
const FunctionBehaviorRef function_behavior
The function behavior of the function to be analyzed.
boost::graph_traits< graph >::edge_descriptor EdgeDescriptor
edge definition.
Definition: graph.hpp:1316
#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