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> 96 #include "config_PACKAGE_NAME.hpp" 97 #include "config_RELEASE.hpp" 104 writer(
CWriter::CreateCWriter(_c_backend_information, RefcountCast<const
HLS_manager>(_AppM),
105 indented_output_stream, _parameters,
108 TM(_AppM->get_tree_manager()),
109 c_backend_info(_c_backend_information)
126 return c_backend_info->GetSignature();
138 switch(relationship_type)
144 case(CBackendInformation::CB_SEQUENTIAL):
147 frontend_relationships;
148 frontend_relationships.insert(std::make_pair(BAMBU_FRONTEND_FLOW, FrontendFlowStep::WHOLE_APPLICATION));
152 #if HAVE_HOST_PROFILING_BUILT 153 case(CBackendInformation::CB_BBP):
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));
171 case(CBackendInformation::CB_DISCREPANCY_ANALYSIS):
172 case(CBackendInformation::CB_HLS):
182 const auto frontend_step_factory =
183 GetPointer<const FrontendFlowStepFactory>(DFMgr->CGetDesignFlowStepFactory(
"Frontend"));
184 const auto call_graph_computation_step =
186 const auto cg_design_flow_step =
187 call_graph_computation_step ?
188 DFMgr->CGetDesignFlowGraph()
189 ->CGetDesignFlowStepInfo(call_graph_computation_step)
191 frontend_step_factory->CreateApplicationFrontendFlowStep(COMPLETE_CALL_GRAPH);
192 relationships.insert(cg_design_flow_step);
197 const auto CGM =
AppM->CGetCallGraphManager();
198 if(boost::num_vertices(*(CGM->CGetCallGraph())))
200 const auto hls_step_factory =
201 GetPointer<const HLSFlowStepFactory>(DFMgr->CGetDesignFlowStepFactory(
"HLS"));
227 case(CBackendInformation::CB_SEQUENTIAL):
228 #if HAVE_HOST_PROFILING_BUILT 229 case(CBackendInformation::CB_BBP):
233 frontend_relationships;
234 frontend_relationships.insert(
235 std::make_pair(FrontendFlowStepType::MULTIPLE_ENTRY_IF_REDUCTION, FrontendFlowStep::ALL_FUNCTIONS));
247 const auto frontend_step_factory =
248 GetPointer<const FrontendFlowStepFactory>(DFMgr->CGetDesignFlowStepFactory(
"Frontend"));
249 const auto call_graph_computation_step =
251 const auto cg_design_flow_step =
252 call_graph_computation_step ?
253 DFMgr->CGetDesignFlowGraph()
254 ->CGetDesignFlowStepInfo(call_graph_computation_step)
256 frontend_step_factory->CreateApplicationFrontendFlowStep(COMPLETE_CALL_GRAPH);
257 relationships.insert(cg_design_flow_step);
262 const auto CGM =
AppM->CGetCallGraphManager();
263 if(boost::num_vertices(*(CGM->CGetCallGraph())))
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"));
273 const auto hls_top_function_step =
275 DFMgr->CGetDesignFlowGraph()->CGetDesignFlowStepInfo(hls_top_function)->design_flow_step :
278 relationships.insert(hls_top_function_step);
284 case(CBackendInformation::CB_DISCREPANCY_ANALYSIS):
285 case(CBackendInformation::CB_HLS):
317 std::filesystem::create_directories(src_filename.parent_path());
343 " executed with: " +
parameters->getOption<std::string>(OPT_cat_args) +
"\n");
367 writer->WriteGlobalDeclarations();
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))
376 writer->DeclareFunctionTypes(
TM->CGetTreeReindex(extBeg));
377 writer->WriteFunctionDeclaration(extBeg);
380 "<--Written external function prototype: " + BH->get_function_name());
384 for(
const auto it : functions)
386 const auto BH =
AppM->CGetFunctionBehavior(it)->CGetBehavioralHelper();
388 "-->Writing function prototype of " + BH->get_function_name());
392 const auto f_name = BH->get_function_name();
399 if(BH->function_has_to_be_printed(it))
401 writer->DeclareFunctionTypes(
TM->CGetTreeReindex(it));
402 writer->WriteFunctionDeclaration(it);
405 "<--Written function prototype of " + BH->get_function_name());
417 const auto BH =
AppM->CGetFunctionBehavior(it)->CGetBehavioralHelper();
418 if(BH->function_has_to_be_printed(it))
420 writer->WriteFunctionImplementation(it);
423 if(
AppM->CGetCallGraphManager()->ExistsAddressedFunction())
425 writer->WriteBuiltinWaitCall();
436 const auto FB =
AppM->CGetFunctionBehavior(f_id);
437 const auto BH = FB->CGetBehavioralHelper();
442 const auto& tmp_vars =
writer->GetLocalVariables(f_id);
443 for(
const auto& tmp_var : tmp_vars)
445 decl_nodes.insert(
TM->CGetTreeReindex(tmp_var));
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());
452 for(
const auto& v : decl_nodes)
456 "-->Analyzing includes for variable " + BH->PrintVariable(v->index) +
" of type " +
460 "<--Analyzed includes for variable " + BH->PrintVariable(v->index) +
" of type " +
466 for(boost::tie(v, vEnd) = boost::vertices(*op_graph); v != vEnd; v++)
468 const auto& node = op_graph->CGetOpNodeInfo(*v)->node;
473 BH->GetTypecast(node, types);
474 for(
const auto&
type : types)
488 for(
const auto& s : includes_to_write)
505 "-->Computing include for " +
STR(tn->
index) +
" " +
513 includes_to_write.insert(decl);
518 const auto types_to_be_declared_before =
520 for(
const auto& type_to_be_declared : types_to_be_declared_before)
524 const auto types_to_be_declared_after =
526 for(
const auto& type_to_be_declared : types_to_be_declared_after)
541 for(boost::tie(v, vEnd) = boost::vertices(*inGraph); v != vEnd; v++)
543 const auto& vars_temp = inGraph->
CGetOpNodeInfo(*v)->cited_variables;
544 vars.insert(vars_temp.begin(), vars_temp.end());
548 for(
const auto var : gblVariables)
552 for(
const auto var : funParams)
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
std::string GetName() const final
Return the name of this design step.
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.
#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't be directly instantiated sinc...
RelationshipType
The relationship type.
Source must be executed to satisfy target.
std::string GetSignature() const final
Return a unified identifier of this design step.
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.
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.
Class to print indented code.
bool HasToBeExecuted() const override
Check if this step has actually to be executed.
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
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.
#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.
Auxiliary methods for manipulating string.
static std::string GetCurrentTimeStamp()
Return a timestamp of the current time.
const OpNodeInfoConstRef CGetOpNodeInfo(const vertex node) const
Returns the info associated with a node.
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
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.
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...
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.
Target must be reexecuted.
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.
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.
const CBackendInformationConstRef c_backend_info
This file collects some utility functions and macros.
This file collects some utility functions.
Template definition of refcount.
const CWriterRef GetCWriter() const
virtual void WriteGlobalDeclarations()
Write the global declarations.
refcount< T > lock() const
const CWriterRef writer
the writer
Helper class supporting the printing of vertexes of a graph.
DesignFlowStep_Status Exec() override
Execute the step.
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.
CustomOrderedSet< unsigned int > functions_to_be_declared
This set usually is equal to the set of functions without a body.
virtual void writeImplementations()
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...
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.
CustomUnorderedSet< unsigned int > already_visited
The set of already analyzed nodes during search of header to include; it is used to avoid infinite re...
Class to print indented code.
int debug_level
The debug level.
refcount< const HLSFlowStepSpecialization > HLSFlowStepSpecializationConstRef
const refcount definition of the class
#define GET_INDEX_CONST_NODE(t)
#define DEBUG_LEVEL_VERBOSE
verbose debugging print is performed.
CustomOrderedSet< unsigned int > functions_to_be_defined
CBackend(const CBackendInformationConstRef c_backend_information, const DesignFlowManagerConstRef design_flow_manager, const application_managerConstRef AppM, const ParameterConstRef _parameters)
Constructor.
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.
const application_managerConstRef AppM
the manager of the application
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 ...