PandA-2024.02
hls_function_step.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 "hls_function_step.hpp"
41 
42 #include "behavioral_helper.hpp"
43 #include "call_graph_manager.hpp"
44 #include "dbgPrintHelper.hpp"
45 #include "design_flow_graph.hpp"
46 #include "design_flow_manager.hpp"
47 #include "hls.hpp"
48 #include "hls_device.hpp"
50 #include "hls_manager.hpp"
51 #include "memory.hpp"
52 #include "technology_manager.hpp"
53 #include "tree_helper.hpp"
54 #include "tree_manager.hpp"
55 #include "utility.hpp"
56 
57 HLSFunctionStep::HLSFunctionStep(const ParameterConstRef _Param, const HLS_managerRef _HLSMgr, unsigned int _funId,
58  const DesignFlowManagerConstRef _design_flow_manager,
59  const HLSFlowStep_Type _hls_flow_step_type,
60  const HLSFlowStepSpecializationConstRef _hls_flow_step_specialization)
61  : HLS_step(_Param, _HLSMgr, _design_flow_manager, _hls_flow_step_type, _hls_flow_step_specialization),
62  funId(_funId),
63  bb_version(0),
64  bitvalue_version(0),
65  memory_version(0)
66 {
67 }
68 
70 
72 {
73  CallGraphManagerConstRef CGMan = HLSMgr->CGetCallGraphManager();
74  const auto funcs = CGMan->GetReachedBodyFunctions();
75  THROW_ASSERT(funId, "unexpected case");
76  if(funcs.find(funId) == funcs.end())
77  {
78  return false;
79  }
80  auto FB = HLSMgr->GetFunctionBehavior(funId);
81  if(bb_version == 0 or bb_version != FB->GetBBVersion())
82  {
83  return true;
84  }
85  if(bitvalue_version == 0 or bitvalue_version != FB->GetBitValueVersion())
86  {
87  return true;
88  }
89  if(memory_version == 0 or memory_version != HLSMgr->GetMemVersion())
90  {
91  return true;
92  }
93  std::map<unsigned int, unsigned int> cur_bb_ver;
94  std::map<unsigned int, unsigned int> cur_bitvalue_ver;
95  const CallGraphManagerConstRef call_graph_manager = HLSMgr->CGetCallGraphManager();
96  THROW_ASSERT(funId, "unexpected case");
97  const auto called_functions = call_graph_manager->GetReachedFunctionsFrom(funId);
98  for(auto const called_function : called_functions)
99  {
100  if(called_function == funId)
101  {
102  continue;
103  }
104  const FunctionBehaviorConstRef FBCalled = HLSMgr->CGetFunctionBehavior(called_function);
105  cur_bb_ver[called_function] = FBCalled->GetBBVersion();
106  cur_bitvalue_ver[called_function] = FBCalled->GetBitValueVersion();
107  }
108  return cur_bb_ver != last_bb_ver || cur_bitvalue_ver != last_bitvalue_ver;
109 }
110 
112 {
114  THROW_ASSERT(funId, "unexpected case");
115  HLS = HLSMgr->get_HLS(funId);
116 }
117 
118 std::string HLSFunctionStep::GetSignature() const
119 {
121 }
122 
125  const unsigned int function_id)
126 {
127  return HLS_step::ComputeSignature(hls_flow_step_type, hls_flow_step_specialization) + "::" + STR(function_id);
128 }
129 
130 std::string HLSFunctionStep::GetName() const
131 {
132 #ifndef NDEBUG
133  const std::string version = std::string(bb_version != 0 ? ("(" + STR(bb_version) + ")") : "") +
134  std::string(bitvalue_version != 0 ? ("(" + STR(bitvalue_version) + ")") : "") +
135  std::string(memory_version != 0 ? ("(" + STR(memory_version) + ")") : "");
136 #else
137  const std::string version = "";
138 #endif
139  const std::string function =
140  funId ? "::" + HLSMgr->CGetFunctionBehavior(funId)->CGetBehavioralHelper()->get_function_name() : "";
141  return "HLS::" + GetKindText() + function + version;
142 }
143 
145  const DesignFlowStep::RelationshipType relationship_type)
146 {
147  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Computing relationships of " + GetName());
148  const auto* hls_flow_step_factory = GetPointer<const HLSFlowStepFactory>(CGetDesignFlowStepFactory());
149  const DesignFlowGraphConstRef design_flow_graph = design_flow_manager.lock()->CGetDesignFlowGraph();
150  const CallGraphManagerConstRef call_graph_manager = HLSMgr->CGetCallGraphManager();
151  const tree_managerRef TreeM = HLSMgr->get_tree_manager();
152  const HLS_deviceRef HLS_D = HLSMgr->get_HLS_device();
153  const technology_managerRef TM = HLS_D->get_technology_manager();
154 
156  steps_to_be_created = ComputeHLSRelationships(relationship_type);
157  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Computed steps to be created");
158  for(auto const& step_to_be_created : steps_to_be_created)
159  {
160  switch(std::get<2>(step_to_be_created))
161  {
163  {
164  const auto called_functions = call_graph_manager->GetReachedFunctionsFrom(funId);
165  for(auto const function : called_functions)
166  {
167  if(function != funId)
168  {
169  const auto hls_step = design_flow_manager.lock()->GetDesignFlowStep(HLSFunctionStep::ComputeSignature(
170  std::get<0>(step_to_be_created), std::get<1>(step_to_be_created), function));
171  const auto design_flow_step =
172  hls_step ? design_flow_graph->CGetDesignFlowStepInfo(hls_step)->design_flow_step :
173  hls_flow_step_factory->CreateHLSFlowStep(std::get<0>(step_to_be_created), function,
174  std::get<1>(step_to_be_created));
175  design_flow_step_set.insert(design_flow_step);
176  }
177  }
178  break;
179  }
181  {
182  const auto hls_step = design_flow_manager.lock()->GetDesignFlowStep(HLSFunctionStep::ComputeSignature(
183  std::get<0>(step_to_be_created), std::get<1>(step_to_be_created), funId));
184  const auto design_flow_step =
185  hls_step ? design_flow_graph->CGetDesignFlowStepInfo(hls_step)->design_flow_step :
186  hls_flow_step_factory->CreateHLSFlowStep(std::get<0>(step_to_be_created), funId,
187  std::get<1>(step_to_be_created));
188  design_flow_step_set.insert(design_flow_step);
189  break;
190  }
194  {
196  break;
197  }
198  default:
199  THROW_UNREACHABLE("");
200  }
201  }
202  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Computed function only HLS step dependencies");
203  HLS_step::ComputeRelationships(design_flow_step_set, relationship_type);
204  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Computing relationships of " + GetName());
205 }
206 
208 {
209  DesignFlowStep_Status status;
210  status = InternalExec();
211  THROW_ASSERT(funId, "unexpected case");
212  auto FB = HLSMgr->GetFunctionBehavior(funId);
213  bb_version = FB->GetBBVersion();
214  bitvalue_version = FB->GetBitValueVersion();
215  memory_version = HLSMgr->GetMemVersion();
216  const CallGraphManagerConstRef call_graph_manager = HLSMgr->CGetCallGraphManager();
217  const auto called_functions = call_graph_manager->GetReachedFunctionsFrom(funId);
218  for(auto const called_function : called_functions)
219  {
220  if(called_function == funId)
221  {
222  continue;
223  }
224  const FunctionBehaviorConstRef FBCalled = HLSMgr->CGetFunctionBehavior(called_function);
225  last_bb_ver[called_function] = FBCalled->GetBBVersion();
226  last_bitvalue_ver[called_function] = FBCalled->GetBitValueVersion();
227  }
228  return status;
229 }
static const std::string ComputeSignature(const HLSFlowStep_Type hls_flow_step_type, const HLSFlowStepSpecializationConstRef hls_flow_step_specialization)
Compute the signature of a hls flow step.
Definition: hls_step.cpp:116
void Initialize() override
Initialize the step (i.e., like a constructor, but executed just before exec.
bool HasToBeExecuted() const override
Check if this step has actually to be executed.
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
const HLS_managerRef HLSMgr
information about all the HLS synthesis
Definition: hls_step.hpp:205
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;.
unsigned int GetBitValueVersion() const
Return the version of the bitvalue information.
virtual void Initialize()
Initialize the step (i.e., like a constructor, but executed just before exec.
File containing functions and utilities to support the printing of debug messagges.
std::map< unsigned int, unsigned int > last_bb_ver
last bb version of the called functions
unsigned int bitvalue_version
The version of bitvalue on which this step was applied.
RelationshipType
The relationship type.
HLSFunctionStep(const ParameterConstRef Param, const HLS_managerRef HLSMgr, unsigned int funId, const DesignFlowManagerConstRef design_flow_manager, const HLSFlowStep_Type hls_flow_step_type, const HLSFlowStepSpecializationConstRef hls_flow_step_specialization=HLSFlowStepSpecializationConstRef())
Constructor.
const unsigned int funId
identifier of the function to be processed (0 means that it is a global step)
unsigned int memory_version
The version of memory representation on which this step was applied.
virtual DesignFlowStep_Status InternalExec()=0
Execute the step.
Class specification of the manager of the technology library data structures.
const HLSFlowStep_Type hls_flow_step_type
The type of this step.
Definition: hls_step.hpp:208
static std::string ComputeSignature(const HLSFlowStep_Type hls_flow_step_type, const HLSFlowStepSpecializationConstRef hls_flow_step_specialization, const unsigned int function_id)
Compute the signature of a hls flow step.
void ComputeRelationships(DesignFlowStepSet &design_flow_step_set, const DesignFlowStep::RelationshipType relationship_type) override
Compute the relationships of a step with other steps.
std::string GetSignature() const final
Return a unified identifier of this design step.
#define STR(s)
Macro which performs a lexical_cast to a string.
virtual const CustomUnorderedSet< std::tuple< HLSFlowStep_Type, HLSFlowStepSpecializationConstRef, HLSFlowStep_Relationship > > ComputeHLSRelationships(const DesignFlowStep::RelationshipType relationship_type) const
Return the set of analyses in relationship with this design step.
Definition: hls_step.cpp:101
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
Definition: exceptions.hpp:292
Factory for hls flow step.
HLSFlowStep_Type
Definition: hls_step.hpp:95
unsigned int bb_version
The version of bb intermediate representation on which this step was applied.
Classes to describe design flow graph.
std::map< unsigned int, unsigned int > last_bitvalue_ver
The version of bit value IR representation on which this step was applied.
const Wrefcount< const DesignFlowManager > design_flow_manager
The design flow manager.
DesignFlowStep_Status
The status of a step.
This file collects some utility functions and macros.
Wrapper of design_flow.
This file collects some utility functions.
DesignFlowStepFactoryConstRef CGetDesignFlowStepFactory() const final
Return the factory to create this type of steps.
Definition: hls_step.cpp:407
void ComputeRelationships(DesignFlowStepSet &design_flow_step_set, const DesignFlowStep::RelationshipType relationship_type) override
Compute the relationships of a step with other steps.
Definition: hls_step.cpp:302
refcount< T > lock() const
Definition: refcount.hpp:212
technology_managerRef get_technology_manager() const
Returns the technology manager.
unsigned int GetBBVersion() const
Return the version of the basic block intermediate representation.
std::string GetName() const final
Return the name of this design step.
hlsRef HLS
HLS data structure of the function to be analyzed.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
DesignFlowStep_Status Exec() final
Execute the step.
Wrapper to call graph.
~HLSFunctionStep() override
Destructor.
int debug_level
The debug level.
Data structure definition for high-level synthesis flow.
Datastructure to represent memory information in high-level synthesis.
virtual std::string GetKindText() const
Return the name of the type of this frontend flow step.
Definition: hls_step.cpp:128
Class specification of the manager of the tree structures extracted from the raw file.
const HLSFlowStepSpecializationConstRef hls_flow_step_specialization
The information about specialization.
Definition: hls_step.hpp:211
HLS specialization of generic_device.
#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:53 for PandA-2024.02 by doxygen 1.8.13