PandA-2024.02
c_backend.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  */
44 #include "c_backend.hpp"
45 
46 #include "Parameter.hpp"
48 #include "application_manager.hpp"
49 #include "behavioral_helper.hpp"
52 #include "c_writer.hpp"
53 #include "call_graph.hpp"
54 #include "call_graph_manager.hpp"
55 #include "custom_map.hpp"
56 #include "custom_set.hpp"
57 #include "dbgPrintHelper.hpp"
58 #include "design_flow_graph.hpp"
59 #include "design_flow_manager.hpp"
60 #include "frontend_flow_step.hpp"
62 #include "function_behavior.hpp"
63 #include "graph.hpp"
65 #include "hls_function_step.hpp"
66 #include "hls_manager.hpp"
68 #include "op_graph.hpp"
69 #include "prettyPrintVertex.hpp"
70 #include "refcount.hpp"
71 #include "string_manipulation.hpp"
72 #include "tree_helper.hpp"
73 #include "tree_manager.hpp"
74 #include "tree_node.hpp"
75 #include "tree_reindex.hpp"
76 #include "utility.hpp"
77 #include "var_pp_functor.hpp"
78 
79 #include <deque>
80 #include <filesystem>
81 #include <fstream>
82 #include <iosfwd>
83 #include <list>
84 #include <ostream>
85 #include <sstream>
86 #include <string>
87 #include <utility>
88 #include <vector>
89 
90 #include <boost/config.hpp>
91 #include <boost/graph/adjacency_list.hpp>
92 #include <boost/graph/filtered_graph.hpp>
93 #include <boost/graph/graph_utility.hpp>
94 #include <boost/graph/topological_sort.hpp>
95 
96 #include "config_PACKAGE_NAME.hpp"
97 #include "config_RELEASE.hpp"
98 
99 CBackend::CBackend(const CBackendInformationConstRef _c_backend_information,
100  const DesignFlowManagerConstRef _design_flow_manager, const application_managerConstRef _AppM,
101  const ParameterConstRef _parameters)
102  : DesignFlowStep(_design_flow_manager, _parameters),
103  indented_output_stream(new IndentedOutputStream()),
104  writer(CWriter::CreateCWriter(_c_backend_information, RefcountCast<const HLS_manager>(_AppM),
105  indented_output_stream, _parameters,
106  _parameters->getOption<int>(OPT_debug_level) >= DEBUG_LEVEL_VERBOSE)),
107  AppM(_AppM),
108  TM(_AppM->get_tree_manager()),
109  c_backend_info(_c_backend_information)
110 {
111  debug_level = parameters->get_class_debug_level(GET_CLASS(*this));
112 }
113 
114 DesignFlowStepFactoryConstRef CBackend::CGetDesignFlowStepFactory() const
115 {
116  return design_flow_manager.lock()->CGetDesignFlowStepFactory("CBackend");
117 }
118 
119 std::string CBackend::GetSignature() const
120 {
122 }
123 
125 {
126  return c_backend_info->GetSignature();
127 }
128 
129 std::string CBackend::GetName() const
130 {
131  return GetSignature();
132 }
133 
135  const DesignFlowStep::RelationshipType relationship_type)
136 {
137  const auto DFMgr = design_flow_manager.lock();
138  switch(relationship_type)
139  {
141  {
142  switch(c_backend_info->type)
143  {
144  case(CBackendInformation::CB_SEQUENTIAL):
145  {
147  frontend_relationships;
148  frontend_relationships.insert(std::make_pair(BAMBU_FRONTEND_FLOW, FrontendFlowStep::WHOLE_APPLICATION));
149  FrontendFlowStep::CreateSteps(DFMgr, frontend_relationships, AppM, relationships);
150  break;
151  }
152 #if HAVE_HOST_PROFILING_BUILT
153  case(CBackendInformation::CB_BBP):
154  {
156  frontend_relationships;
157  frontend_relationships.insert(
158  std::make_pair(BASIC_BLOCKS_CFG_COMPUTATION, FrontendFlowStep::ALL_FUNCTIONS));
159  frontend_relationships.insert(
160  std::make_pair(DEAD_CODE_ELIMINATION_IPA, FrontendFlowStep::WHOLE_APPLICATION));
161  frontend_relationships.insert(std::make_pair(LOOP_COMPUTATION, FrontendFlowStep::ALL_FUNCTIONS));
162  frontend_relationships.insert(std::make_pair(NI_SSA_LIVENESS, FrontendFlowStep::ALL_FUNCTIONS));
163  frontend_relationships.insert(
164  std::make_pair(OPERATIONS_CFG_COMPUTATION, FrontendFlowStep::ALL_FUNCTIONS));
165  frontend_relationships.insert(std::make_pair(VAR_ANALYSIS, FrontendFlowStep::ALL_FUNCTIONS));
166  FrontendFlowStep::CreateSteps(DFMgr, frontend_relationships, AppM, relationships);
167  break;
168  }
169 #endif
170 #if HAVE_HLS_BUILT
171  case(CBackendInformation::CB_DISCREPANCY_ANALYSIS):
172  case(CBackendInformation::CB_HLS):
173  {
174  // The first time this step is added, we add the dependence
175  // from the complete call graph computation. Ideally we would
176  // need also the dependence from the HLS steps,
177  // but at this point we don't know the top function yet.
178  // The trick is that the dependencies will be recomputed again
179  // before this is executed. At that time the top
180  // function will be ready. The dependencies from HLS steps are
181  // added after the check on the call graph for this reason.
182  const auto frontend_step_factory =
183  GetPointer<const FrontendFlowStepFactory>(DFMgr->CGetDesignFlowStepFactory("Frontend"));
184  const auto call_graph_computation_step =
185  DFMgr->GetDesignFlowStep(ApplicationFrontendFlowStep::ComputeSignature(COMPLETE_CALL_GRAPH));
186  const auto cg_design_flow_step =
187  call_graph_computation_step ?
188  DFMgr->CGetDesignFlowGraph()
189  ->CGetDesignFlowStepInfo(call_graph_computation_step)
190  ->design_flow_step :
191  frontend_step_factory->CreateApplicationFrontendFlowStep(COMPLETE_CALL_GRAPH);
192  relationships.insert(cg_design_flow_step);
193 
194  // Root function cannot be computed at the beginning so if the
195  // call graph is not ready yet we exit. The relationships will
196  // be computed again after the call graph computation.
197  const auto CGM = AppM->CGetCallGraphManager();
198  if(boost::num_vertices(*(CGM->CGetCallGraph())))
199  {
200  const auto hls_step_factory =
201  GetPointer<const HLSFlowStepFactory>(DFMgr->CGetDesignFlowStepFactory("HLS"));
202  relationships.insert(hls_step_factory->CreateHLSFlowStep(HLSFlowStep_Type::TEST_VECTOR_PARSER,
204  // const auto is_hw_discrepancy =
205  // parameters->isOption(OPT_discrepancy_hw) && parameters->getOption<bool>(OPT_discrepancy_hw);
206  // if(c_backend_info->type == CBackendInformation::CB_DISCREPANCY_ANALYSIS && !is_hw_discrepancy)
207  // {
208  // relationships.insert(hls_step_factory->CreateHLSFlowStep(HLSFlowStep_Type::VCD_SIGNAL_SELECTION,
209  // HLSFlowStepSpecializationConstRef()));
210  // }
211  }
212 
213  break;
214  }
215 #endif
216  default:
217  {
218  THROW_UNREACHABLE("");
219  }
220  }
221  break;
222  }
224  {
225  switch(c_backend_info->type)
226  {
227  case(CBackendInformation::CB_SEQUENTIAL):
228 #if HAVE_HOST_PROFILING_BUILT
229  case(CBackendInformation::CB_BBP):
230 #endif
231  {
233  frontend_relationships;
234  frontend_relationships.insert(
235  std::make_pair(FrontendFlowStepType::MULTIPLE_ENTRY_IF_REDUCTION, FrontendFlowStep::ALL_FUNCTIONS));
236  FrontendFlowStep::CreateSteps(DFMgr, frontend_relationships, AppM, relationships);
237  if(c_backend_info->type == CBackendInformation::CB_SEQUENTIAL)
238  {
239  // The first time this step is added, we add the dependence
240  // from the complete call graph computation. Ideally we would
241  // need also the dependence from the HLS steps,
242  // but at this point we don't know the top function yet.
243  // The trick is that the dependencies will be recomputed again
244  // before this is executed. At that time the top
245  // function will be ready. The dependencies from HLS steps are
246  // added after the check on the call graph for this reason.
247  const auto frontend_step_factory =
248  GetPointer<const FrontendFlowStepFactory>(DFMgr->CGetDesignFlowStepFactory("Frontend"));
249  const auto call_graph_computation_step =
250  DFMgr->GetDesignFlowStep(ApplicationFrontendFlowStep::ComputeSignature(COMPLETE_CALL_GRAPH));
251  const auto cg_design_flow_step =
252  call_graph_computation_step ?
253  DFMgr->CGetDesignFlowGraph()
254  ->CGetDesignFlowStepInfo(call_graph_computation_step)
255  ->design_flow_step :
256  frontend_step_factory->CreateApplicationFrontendFlowStep(COMPLETE_CALL_GRAPH);
257  relationships.insert(cg_design_flow_step);
258 
259  // Root function cannot be computed at the beginning so if the
260  // call graph is not ready yet we exit. The relationships will
261  // be computed again after the call graph computation.
262  const auto CGM = AppM->CGetCallGraphManager();
263  if(boost::num_vertices(*(CGM->CGetCallGraph())))
264  {
265  const auto top_symbols = parameters->getOption<std::vector<std::string>>(OPT_top_functions_names);
266  THROW_ASSERT(top_symbols.size() == 1, "Expected single top function name");
267  const auto top_fnode = AppM->get_tree_manager()->GetFunction(top_symbols.front());
268  const auto hls_step_factory =
269  GetPointer<const HLSFlowStepFactory>(DFMgr->CGetDesignFlowStepFactory("HLS"));
270  const auto hls_top_function = DFMgr->GetDesignFlowStep(HLSFunctionStep::ComputeSignature(
272  GET_INDEX_CONST_NODE(top_fnode)));
273  const auto hls_top_function_step =
274  hls_top_function ?
275  DFMgr->CGetDesignFlowGraph()->CGetDesignFlowStepInfo(hls_top_function)->design_flow_step :
276  hls_step_factory->CreateHLSFlowStep(HLSFlowStep_Type::HLS_SYNTHESIS_FLOW,
277  GET_INDEX_CONST_NODE(top_fnode));
278  relationships.insert(hls_top_function_step);
279  }
280  }
281  break;
282  }
283 #if HAVE_HLS_BUILT
284  case(CBackendInformation::CB_DISCREPANCY_ANALYSIS):
285  case(CBackendInformation::CB_HLS):
286  {
287  break;
288  }
289 #endif
290  default:
291  {
292  THROW_UNREACHABLE("");
293  }
294  }
295  break;
296  }
298  {
299  break;
300  }
301  default:
302  {
303  THROW_UNREACHABLE("");
304  }
305  }
306 }
307 
309 {
310  return true;
311 }
312 
314 {
315  writer->Initialize();
316  std::filesystem::path src_filename(c_backend_info->src_filename);
317  std::filesystem::create_directories(src_filename.parent_path());
318  if(std::filesystem::exists(c_backend_info->src_filename))
319  {
320  std::filesystem::remove_all(c_backend_info->src_filename);
321  }
322  already_visited.clear();
323  if(c_backend_info->type != CBackendInformation::CB_HLS)
324  {
325  functions_to_be_declared = AppM->get_functions_without_body();
326  functions_to_be_defined = AppM->get_functions_with_body();
327  }
328 }
329 
331 {
332  INDENT_DBG_MEX(DEBUG_LEVEL_PEDANTIC, debug_level, "-->writing " + c_backend_info->src_filename);
333  // first write panda header
334  INDENT_DBG_MEX(DEBUG_LEVEL_PEDANTIC, debug_level, "-->writing panda header");
336  indented_output_stream->Append(" * Politecnico di Milano\n");
337  indented_output_stream->Append(" * Code created using " PACKAGE_NAME " - " + parameters->PrintVersion());
340  if(parameters->isOption(OPT_cat_args))
341  {
342  indented_output_stream->Append(" * " + parameters->getOption<std::string>(OPT_program_name) +
343  " executed with: " + parameters->getOption<std::string>(OPT_cat_args) + "\n");
344  }
345  indented_output_stream->Append(" */\n");
346  INDENT_DBG_MEX(DEBUG_LEVEL_PEDANTIC, debug_level, "<--written panda header");
347  // write cwriter specific header
348  INDENT_DBG_MEX(DEBUG_LEVEL_PEDANTIC, debug_level, "-->writing header");
349  writer->WriteHeader();
350  INDENT_DBG_MEX(DEBUG_LEVEL_PEDANTIC, debug_level, "<--written header");
351  writeIncludes();
354  writer->WriteFile(c_backend_info->src_filename);
355  INDENT_DBG_MEX(DEBUG_LEVEL_PEDANTIC, debug_level, "<--written " + c_backend_info->src_filename);
357 }
358 
360 {
361  return writer;
362 }
363 
365 {
366  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Writing global declarations");
367  writer->WriteGlobalDeclarations();
368  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Writing function prototypes");
369  for(const auto extBeg : functions_to_be_declared)
370  {
371  const auto BH = AppM->CGetFunctionBehavior(extBeg)->CGetBehavioralHelper();
373  "-->Writing external function prototype: " + BH->get_function_name());
374  if(BH->function_has_to_be_printed(extBeg))
375  {
376  writer->DeclareFunctionTypes(TM->CGetTreeReindex(extBeg));
377  writer->WriteFunctionDeclaration(extBeg);
378  }
380  "<--Written external function prototype: " + BH->get_function_name());
381  }
382 
384  for(const auto it : functions)
385  {
386  const auto BH = AppM->CGetFunctionBehavior(it)->CGetBehavioralHelper();
388  "-->Writing function prototype of " + BH->get_function_name());
389 
390  if(parameters->isOption(OPT_pretty_print))
391  {
392  const auto f_name = BH->get_function_name();
393  if(starts_with(f_name, "__builtin_"))
394  {
395  indented_output_stream->Append("#define " + f_name + " _bambu_" + f_name + "\n");
396  }
397  }
398 
399  if(BH->function_has_to_be_printed(it))
400  {
401  writer->DeclareFunctionTypes(TM->CGetTreeReindex(it));
402  writer->WriteFunctionDeclaration(it);
403  }
405  "<--Written function prototype of " + BH->get_function_name());
406  }
407  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Written function prototypes");
408  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Written global declarations");
409 }
410 
412 {
413  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Writing implementations");
414  // First of all I declare the functions and then the tasks
415  for(const auto it : functions_to_be_defined)
416  {
417  const auto BH = AppM->CGetFunctionBehavior(it)->CGetBehavioralHelper();
418  if(BH->function_has_to_be_printed(it))
419  {
420  writer->WriteFunctionImplementation(it);
421  }
422  }
423  if(AppM->CGetCallGraphManager()->ExistsAddressedFunction())
424  {
425  writer->WriteBuiltinWaitCall();
426  }
427  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Written implementations");
428 }
429 
431 {
432  CustomOrderedSet<std::string> includes_to_write;
433  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Computing includes for external functions");
434  for(const auto f_id : functions_to_be_defined)
435  {
436  const auto FB = AppM->CGetFunctionBehavior(f_id);
437  const auto BH = FB->CGetBehavioralHelper();
438  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Computing includes for " + BH->get_function_name());
439  AnalyzeInclude(TM->CGetTreeReindex(f_id), BH, includes_to_write);
440 
441  TreeNodeConstSet decl_nodes;
442  const auto& tmp_vars = writer->GetLocalVariables(f_id);
443  for(const auto& tmp_var : tmp_vars)
444  {
445  decl_nodes.insert(TM->CGetTreeReindex(tmp_var));
446  }
447  const auto funParams = BH->GetParameters();
448  decl_nodes.insert(funParams.begin(), funParams.end());
449  const auto& vars = AppM->GetGlobalVariables();
450  decl_nodes.insert(vars.begin(), vars.end());
451 
452  for(const auto& v : decl_nodes)
453  {
454  const auto variable_type = tree_helper::CGetType(v);
456  "-->Analyzing includes for variable " + BH->PrintVariable(v->index) + " of type " +
457  STR(variable_type));
458  AnalyzeInclude(variable_type, BH, includes_to_write);
460  "<--Analyzed includes for variable " + BH->PrintVariable(v->index) + " of type " +
461  STR(variable_type));
462  }
463 
464  const auto op_graph = FB->CGetOpGraph(FunctionBehavior::DFG);
465  VertexIterator v, vEnd;
466  for(boost::tie(v, vEnd) = boost::vertices(*op_graph); v != vEnd; v++)
467  {
468  const auto& node = op_graph->CGetOpNodeInfo(*v)->node;
469  if(node)
470  {
471  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Analyzing includes for operation " + STR(node));
472  TreeNodeConstSet types;
473  BH->GetTypecast(node, types);
474  for(const auto& type : types)
475  {
476  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Analyzing includes for type " + STR(type));
477  AnalyzeInclude(type, BH, includes_to_write);
478  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Analyzed includes for type " + STR(type));
479  }
480  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Analyzed includes for operation " + STR(node));
481  }
482  }
483  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Computed includes for " + BH->get_function_name());
484  }
485  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Computed includes for external functions");
486 
487  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Writing includes");
488  for(const auto& s : includes_to_write)
489  {
491  writer->writeInclude(s);
492  }
493  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Written includes");
494 }
495 
497  CustomOrderedSet<std::string>& includes_to_write)
498 {
499  if(already_visited.count(tn->index))
500  {
501  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Skipped already analyzed " + STR(tn->index));
502  return;
503  }
505  "-->Computing include for " + STR(tn->index) + " " +
506  (tree_helper::IsFunctionDeclaration(tn) ? "" : STR(tn)));
507  already_visited.insert(tn->index);
508  bool is_system;
509  const auto decl = std::get<0>(tree_helper::GetSourcePath(tn, is_system));
510  if(!decl.empty() && decl != "<built-in>" && is_system && !tree_helper::IsInLibbambu(tn))
511  {
512  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Adding " + decl + " to the list of includes");
513  includes_to_write.insert(decl);
514  }
515  else
516  {
517  const auto type = tree_helper::CGetType(tn);
518  const auto types_to_be_declared_before =
519  tree_helper::GetTypesToBeDeclaredBefore(type, parameters->getOption<bool>(OPT_without_transformation));
520  for(const auto& type_to_be_declared : types_to_be_declared_before)
521  {
522  AnalyzeInclude(type_to_be_declared, BH, includes_to_write);
523  }
524  const auto types_to_be_declared_after =
525  tree_helper::GetTypesToBeDeclaredAfter(type, parameters->getOption<bool>(OPT_without_transformation));
526  for(const auto& type_to_be_declared : types_to_be_declared_after)
527  {
528  AnalyzeInclude(type_to_be_declared, BH, includes_to_write);
529  }
530  }
532 }
533 
535  std::list<unsigned int>& funParams, CustomUnorderedSet<unsigned int>& vars)
536 {
537  // I simply have to go over all the vertices and get the used variables;
538  // the variables which have to be declared are all those variables but
539  // the globals ones
540  VertexIterator v, vEnd;
541  for(boost::tie(v, vEnd) = boost::vertices(*inGraph); v != vEnd; v++)
542  {
543  const auto& vars_temp = inGraph->CGetOpNodeInfo(*v)->cited_variables;
544  vars.insert(vars_temp.begin(), vars_temp.end());
545  }
546 
547  // I have to take out the variables global to the whole program and the function parameters
548  for(const auto var : gblVariables)
549  {
550  vars.erase(var);
551  }
552  for(const auto var : funParams)
553  {
554  vars.erase(var);
555  }
556 }
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
std::string GetName() const final
Return the name of this design step.
Definition: c_backend.cpp:129
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;.
Factory class to create c backend.
File containing functions and utilities to support the printing of debug messagges.
#define DEBUG_LEVEL_PEDANTIC
very verbose debugging print is performed.
static std::set< tree_nodeConstRef, TreeNodeConstSorter > GetTypesToBeDeclaredAfter(const tree_nodeConstRef &tn, const bool without_transformation)
Return the types to be declared after declaring index type.
const IndentedOutputStreamRef indented_output_stream
The output stream.
Definition: c_backend.hpp:82
#define GET_CLASS(obj)
Macro returning the actual type of an object.
Definition of the class representing a generic C application.
Class used to write the C code representing a program, this class can&#39;t be directly instantiated sinc...
Definition: c_writer.hpp:91
RelationshipType
The relationship type.
Source must be executed to satisfy target.
std::string GetSignature() const final
Return a unified identifier of this design step.
Definition: c_backend.cpp:119
void compute_variables(const OpGraphConstRef inGraph, const CustomUnorderedSet< unsigned int > &gblVariables, std::list< unsigned int > &funParams, CustomUnorderedSet< unsigned int > &vars)
Computes the variables which have to be declared for a function.
Definition: c_backend.cpp:534
Class specification of the graph structures.
The base class for design step.
static bool IsFunctionDeclaration(const tree_nodeConstRef &type)
Return true if treenode is a function_decl.
const tree_managerConstRef TM
The tree_manager.
Definition: c_backend.hpp:91
Class to print indented code.
bool HasToBeExecuted() const override
Check if this step has actually to be executed.
Definition: c_backend.cpp:308
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.
redefinition of map to manage ordered/unordered structures
Base class to pass information to a c backend.
static bool IsInLibbambu(const tree_managerConstRef &TM, const unsigned int index)
Return true if the decl node or type is in libbambu.
Simple class used to drive the backend in order to be able to print c source code.
A set of const tree node.
Definition: tree_node.hpp:267
#define STR(s)
Macro which performs a lexical_cast to a string.
virtual void writeIncludes()
Writes the file header, i.e the comments at the beginning of the file.
Definition: c_backend.cpp:430
Auxiliary methods for manipulating string.
static std::string GetCurrentTimeStamp()
Return a timestamp of the current time.
Definition: utility.cpp:55
const OpNodeInfoConstRef CGetOpNodeInfo(const vertex node) const
Returns the info associated with a node.
Definition: op_graph.hpp:843
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
Definition: exceptions.hpp:292
bool starts_with(const std::string &str, const std::string &pattern)
Factory for hls flow step.
static std::set< tree_nodeConstRef, TreeNodeConstSorter > GetTypesToBeDeclaredBefore(const tree_nodeConstRef &tn, const bool without_transformation)
Return the types to be declared before declaring index type.
DesignFlowStepFactoryConstRef CGetDesignFlowStepFactory() const override
Return the factory to create this type of steps.
Definition: c_backend.cpp:114
void Append(const std::string &str)
Append a string to the output.
static std::tuple< std::string, unsigned int, unsigned int > GetSourcePath(const tree_nodeConstRef &node, bool &is_system)
Return where a function or a type is defined.
const unsigned int index
Represent the index read from the raw file and the index-1 of the vector of tree_node associated to t...
Definition: tree_node.hpp:146
Classes to describe design flow graph.
void ComputeRelationships(DesignFlowStepSet &relationship, const DesignFlowStep::RelationshipType relationship_type) override
Compute the relationships of a step with other steps.
Definition: c_backend.cpp:134
redefinition of set to manage ordered/unordered structures
static const std::string ComputeSignature(const FrontendFlowStepType frontend_flow_step_type)
Compute the signature of a function frontend flow step.
const Wrefcount< const DesignFlowManager > design_flow_manager
The design flow manager.
This class contains the base representation for a generic frontend flow step.
boost::graph_traits< graph >::vertex_iterator VertexIterator
vertex_iterator definition.
Definition: graph.hpp:1307
Classes specification of the tree_node data structures.
const ParameterConstRef parameters
Set of input parameters.
DesignFlowStep_Status
The status of a step.
void Initialize() override
Initialize the step (i.e., like a constructor, but executed just before exec.
Definition: c_backend.cpp:313
const CBackendInformationConstRef c_backend_info
Definition: c_backend.hpp:156
This file collects some utility functions and macros.
Call graph hierarchy.
Wrapper of design_flow.
This file collects some utility functions.
Template definition of refcount.
const CWriterRef GetCWriter() const
Definition: c_backend.cpp:359
virtual void WriteGlobalDeclarations()
Write the global declarations.
Definition: c_backend.cpp:364
refcount< T > lock() const
Definition: refcount.hpp:212
const CWriterRef writer
the writer
Definition: c_backend.hpp:85
Helper class supporting the printing of vertexes of a graph.
DesignFlowStep_Status Exec() override
Execute the step.
Definition: c_backend.cpp:330
Class specification of the tree_reindex support class.
virtual void AnalyzeInclude(const tree_nodeConstRef &tn, const BehavioralHelperConstRef &BH, CustomOrderedSet< std::string > &includes)
Analyze a variable or a type to identify the includes to be added.
Definition: c_backend.cpp:496
CustomOrderedSet< unsigned int > functions_to_be_declared
This set usually is equal to the set of functions without a body.
Definition: c_backend.hpp:137
virtual void writeImplementations()
Definition: c_backend.cpp:411
This class contains the methods to create a frontend flow step.
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
static tree_nodeConstRef CGetType(const tree_nodeConstRef &node)
Return the treenode of the type of node.
this class is used to manage the command-line or XML options.
This file contains the routines necessary to create a C executable program.
Wrapper to call graph.
CustomUnorderedSet< unsigned int > already_visited
The set of already analyzed nodes during search of header to include; it is used to avoid infinite re...
Definition: c_backend.hpp:79
Class to print indented code.
int debug_level
The debug level.
refcount< const HLSFlowStepSpecialization > HLSFlowStepSpecializationConstRef
const refcount definition of the class
Definition: hls_step.hpp:93
#define GET_INDEX_CONST_NODE(t)
Definition: tree_node.hpp:363
#define DEBUG_LEVEL_VERBOSE
verbose debugging print is performed.
CustomOrderedSet< unsigned int > functions_to_be_defined
Definition: c_backend.hpp:140
CBackend(const CBackendInformationConstRef c_backend_information, const DesignFlowManagerConstRef design_flow_manager, const application_managerConstRef AppM, const ParameterConstRef _parameters)
Constructor.
Definition: c_backend.cpp:99
This class contains the base representation for a generic frontend flow step which works on the whole...
static std::string ComputeSignature(const CBackendInformationConstRef type)
Compute the signature for a c backend step.
Definition: c_backend.cpp:124
const application_managerConstRef AppM
the manager of the application
Definition: c_backend.hpp:88
Class specification of the manager of the tree structures extracted from the raw file.
A brief description of the C++ Header File.
static void CreateSteps(const DesignFlowManagerConstRef design_flow_manager, const CustomUnorderedSet< std::pair< FrontendFlowStepType, FunctionRelationship >> &frontend_relationships, const application_managerConstRef application_manager, DesignFlowStepSet &relationships)
Create the relationship steps of a step with other steps starting from already specified dependencies...
#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:50 for PandA-2024.02 by doxygen 1.8.13