PandA-2024.02
|
#include <hls_c_writer.hpp>
Public Member Functions | |
HLSCWriter (const CBackendInformationConstRef hls_c_backend_information, const HLS_managerConstRef _HLSMgr, const InstructionWriterRef instruction_writer, const IndentedOutputStreamRef indented_output_stream, const ParameterConstRef _parameters, bool verbose=true) | |
Constructor of the class. More... | |
virtual | ~HLSCWriter () |
void | WriteFile (const std::string &file_name) override |
Writes the final C file. More... | |
void | WriteHeader () override |
Writes the header of the file. More... | |
Public Member Functions inherited from CWriter | |
virtual | ~CWriter () |
virtual void | Initialize () |
Initialize data structure. More... | |
const InstructionWriterRef | getInstructionWriter () const |
Returns the instruction writer. More... | |
const CustomSet< unsigned int > | GetLocalVariables (const unsigned int function_id) const |
Compute the local variables of a function. More... | |
virtual void | StartFunctionBody (const unsigned int function_id) |
Writes the body of the function to the specified stream. More... | |
virtual void | WriteFunctionBody (const unsigned int function_id) |
Writes the body of a function. More... | |
virtual void | EndFunctionBody (unsigned int funId) |
Writes the code necessary to close a function (this function was a function also present in the original specification) More... | |
virtual void | writeRoutineInstructions (const unsigned int function_index, const OpVertexSet &instructions, var_pp_functorConstRef variableFunctor, vertex bb_start=NULL_VERTEX, CustomOrderedSet< vertex > bb_end=CustomOrderedSet< vertex >()) |
Writes the instructions of the current routine, being it a task or a function of the original program. More... | |
virtual void | WriteFunctionDeclaration (const unsigned int funId) |
Writes the declaration of the function whose id in the tree is funId. More... | |
virtual void | writeInclude (const std::string &file_name) |
Writes an include directive. More... | |
virtual void | DeclareType (const tree_nodeConstRef &varType, const BehavioralHelperConstRef &behavioral_helper, CustomSet< std::string > &locally_declared_type) |
This method should be called only if the type associated with the variable is a non built_in type and, in case the non built_in type hasn't been declared yet, it declares it; this method is used to declared new types with scope limited to a routine (be it a function of a task) More... | |
virtual void | DeclareVariable (const tree_nodeConstRef &curVar, CustomSet< unsigned int > &already_declared_variables, CustomSet< std::string > &locally_declared_type, const BehavioralHelperConstRef &behavioral_helper, const var_pp_functorConstRef &varFunc) |
Declares the local variable; in case the variable used in the intialization of curVar hasn't been declared yet it get declared. More... | |
virtual void | declare_cast_types (unsigned int funId, CustomSet< std::string > &locally_declared_types) |
Declare all the types used in conversions. More... | |
virtual void | DeclareLocalVariables (const CustomSet< unsigned int > &to_be_declared, CustomSet< unsigned int > &already_declared_variables, CustomSet< std::string > &already_declared_types, const BehavioralHelperConstRef behavioral_helper, const var_pp_functorConstRef varFunc) |
Declares the local variable; in case the variable used in the intialization of curVar hasn't been declared yet it get declared. More... | |
virtual void | DeclareFunctionTypes (const tree_nodeConstRef &tn) |
Declares the types of the parameters of a function. More... | |
Protected Member Functions | |
void | WriteParamDecl (const BehavioralHelperConstRef behavioral_helper) |
Write declaration of the top function parameters. More... | |
void | WriteParamInitialization (const BehavioralHelperConstRef behavioral_helper, const std::map< std::string, std::string > &curr_test_vector) |
Initialize the parameters of the function. More... | |
void | WriteTestbenchFunctionCall (const BehavioralHelperConstRef behavioral_helper) |
Writes a call to the top function to be tested, using its parameters. More... | |
void | WriteSimulatorInitMemory (const unsigned int function_id) |
Write some print statements used to dump the values used by the HDL to initialize the memory before the simulation. More... | |
virtual void | WriteExtraInitCode () |
Write additional initialization code needed by subclasses. More... | |
virtual void | WriteExtraCodeBeforeEveryMainCall () |
virtual void | WriteMainTestbench () |
Writes the main() of the testbench C program. More... | |
void | WriteGlobalDeclarations () override |
Writes the global declarations. More... | |
void | WriteFunctionImplementation (unsigned int function_index) override |
Write function implementation. More... | |
void | WriteBuiltinWaitCall () override |
Writes implementation of __builtin_wait_call. More... | |
Protected Member Functions inherited from CWriter | |
void | writeRoutineInstructions_rec (vertex current_vertex, bool bracket, const unsigned int function_index) |
Write recursively instructions belonging to a basic block of task or of a function. More... | |
virtual void | writePreInstructionInfo (const FunctionBehaviorConstRef, const vertex) |
Write additional information on the given statement vertex, before the statement itself. More... | |
virtual void | writePostInstructionInfo (const FunctionBehaviorConstRef, const vertex) |
Write additional information on the given statement vertex, after the statements itself. More... | |
virtual void | WriteBodyLoop (const unsigned int function_index, const unsigned int, vertex current_vertex, bool bracket) |
Write the instructions belonging to a body loop. More... | |
void | compute_phi_nodes (const FunctionBehaviorConstRef function_behavior, const OpVertexSet &instructions, var_pp_functorConstRef variableFunctor) |
Determines the instructions coming out from phi-node splitting. More... | |
void | insert_copies (vertex b, const BBGraphConstRef bb_domGraph, const BBGraphConstRef bb_fcfgGraph, var_pp_functorConstRef variableFunctor, const CustomSet< unsigned int > &phi_instructions, std::map< unsigned int, unsigned int > &created_variables, std::map< unsigned int, std::string > &symbol_table, std::map< unsigned int, std::deque< std::string >> &array_of_stacks) |
Compute the copy assignments needed by the phi nodes destruction Further details can be found in: More... | |
void | schedule_copies (vertex b, const BBGraphConstRef bb_domGraph, const BBGraphConstRef bb_fcfgGraph, var_pp_functorConstRef variableFunctor, const CustomSet< unsigned int > &phi_instructions, std::map< unsigned int, unsigned int > &created_variables, std::map< unsigned int, std::string > &symbol_table, std::list< unsigned int > &pushed, std::map< unsigned int, std::deque< std::string >> &array_of_stacks) |
insert copies according the algorithm described in Briggs et. More... | |
unsigned int | create_new_identifier (std::map< unsigned int, std::string > &symbol_table) |
create an identifier for the temporaries created by phi node destruction More... | |
void | push_stack (std::string symbol_name, unsigned int dest_i, std::list< unsigned int > &pushed, std::map< unsigned int, std::deque< std::string >> &array_of_stacks) |
push on the stack of temporary variables that has to replaced More... | |
void | pop_stack (std::list< unsigned int > &pushed, std::map< unsigned int, std::deque< std::string >> &array_of_stacks) |
remove from the stack all the temporaries More... | |
void | WriteHashTableImplementation () |
Write the implementation of a hash table with long long int as key and long long int as value. More... | |
virtual void | WriteBBHeader (const unsigned int bb_number, const unsigned int function_index) |
CWriter (const HLS_managerConstRef _HLSMgr, const InstructionWriterRef instruction_writer, const IndentedOutputStreamRef indented_output_stream, const ParameterConstRef Param, bool verbose=true) | |
Constructor of the class. More... | |
Protected Attributes | |
const CBackendInformationConstRef | c_backend_info |
Backend information. More... | |
Protected Attributes inherited from CWriter | |
const HLS_managerConstRef | HLSMgr |
the hls manager More... | |
const tree_managerConstRef | TM |
The tree manager. More... | |
const IndentedOutputStreamRef | indented_output_stream |
Represents the stream we are currently writing to. More... | |
CustomSet< std::string > | globally_declared_types |
This set contains the list of the non built_in types already declared in the global scope. More... | |
CustomSet< unsigned int > | globallyDeclVars |
const InstructionWriterRef | instrWriter |
Contains the class used to write instructions. More... | |
size_t | bb_label_counter |
Counter of the invocations of writeRoutineInstructions; this counter allows to print different labels in differnt tasks to avoid problem due to multiple tasks inlineing. More... | |
bool | verbose |
Verbosity means that a comment is printed for each line in the output file. More... | |
const ParameterConstRef | Param |
set of parameters More... | |
int | debug_level |
the debug level More... | |
int | output_level |
the output level More... | |
unsigned int | fake_max_tree_node_id |
std::map< unsigned int, std::string > | basic_block_prefix |
string to be printed at the beginning of a given basic block More... | |
std::map< unsigned int, std::string > | basic_block_tail |
string to be printed at the end of a given basic block More... | |
std::map< vertex, std::map< unsigned int, std::string > > | renaming_table |
renaming table used by phi node destruction procedure More... | |
CustomOrderedSet< vertex > | bb_frontier |
CustomOrderedSet< vertex > | bb_analyzed |
std::map< unsigned int, std::string > | basic_blocks_labels |
CustomOrderedSet< vertex > | goto_list |
var_pp_functorConstRef | local_rec_variableFunctor |
FunctionBehaviorConstRef | local_rec_function_behavior |
CustomOrderedSet< vertex > | local_rec_instructions |
const dominance< BBGraph > * | dominators |
const dominance< BBGraph > * | post_dominators |
BBGraphConstRef | local_rec_bb_fcfgGraph |
OpGraphConstRef | local_rec_cfgGraph |
BehavioralHelperConstRef | local_rec_behavioral_helper |
std::vector< std::string > | additionalIncludes |
CustomOrderedSet< std::string > | writtenIncludes |
Additional Inherited Members | |
Static Public Member Functions inherited from CWriter | |
static CWriterRef | CreateCWriter (const CBackendInformationConstRef c_backend_information, const HLS_managerConstRef hls_man, const IndentedOutputStreamRef indented_output_stream, const ParameterConstRef parameters, const bool verbose) |
Factory method. More... | |
Definition at line 52 of file hls_c_writer.hpp.
HLSCWriter::HLSCWriter | ( | const CBackendInformationConstRef | hls_c_backend_information, |
const HLS_managerConstRef | _HLSMgr, | ||
const InstructionWriterRef | instruction_writer, | ||
const IndentedOutputStreamRef | indented_output_stream, | ||
const ParameterConstRef | _parameters, | ||
bool | verbose = true |
||
) |
Constructor of the class.
hls_c_backend_information | is the information about backend |
HLSMgr | is the hls manager |
instruction_writer | is the instruction writer to use to print the single instruction |
indented_output_stream | is the stream where code has to be printed |
Param | is the set of parameters |
verbose | tells if annotations |
Definition at line 83 of file hls_c_writer.cpp.
References CWriter::debug_level, GET_CLASS, and ~HLSCWriter().
|
virtualdefault |
|
overrideprotectedvirtual |
Writes implementation of __builtin_wait_call.
Do nothing
Reimplemented from CWriter.
Definition at line 1174 of file hls_c_writer.cpp.
|
protectedvirtual |
Reimplemented in DiscrepancyAnalysisCWriter.
Definition at line 573 of file hls_c_writer.cpp.
Referenced by WriteMainTestbench().
|
protectedvirtual |
Write additional initialization code needed by subclasses.
Reimplemented in DiscrepancyAnalysisCWriter.
Definition at line 569 of file hls_c_writer.cpp.
Referenced by WriteMainTestbench().
|
overridevirtual |
Writes the final C file.
file_name | is the name of the file to be generated |
Reimplemented from CWriter.
Definition at line 1154 of file hls_c_writer.cpp.
References GET_INDEX_CONST_NODE, tree_manager::GetFunction(), CWriter::HLSMgr, INDENT_OUT_MEX, CWriter::indented_output_stream, CWriter::output_level, OUTPUT_LEVEL_VERBOSE, CWriter::Param, THROW_ASSERT, CWriter::TM, IndentedOutputStream::WriteFile(), and WriteMainTestbench().
|
overrideprotectedvirtual |
Write function implementation.
function_id | is the index of the function to be written |
Do nothing
Reimplemented from CWriter.
Definition at line 1169 of file hls_c_writer.cpp.
|
overrideprotectedvirtual |
Writes the global declarations.
Reimplemented from CWriter.
Definition at line 189 of file hls_c_writer.cpp.
References CWriter::instrWriter.
|
overridevirtual |
Writes the header of the file.
Reimplemented from CWriter.
Definition at line 95 of file hls_c_writer.cpp.
References IndentedOutputStream::Append(), tree_manager::CGetTreeNode(), tree_helper::GetMangledFunctionName(), CWriter::HLSMgr, CWriter::indented_output_stream, string_to_container(), and CWriter::TM.
|
protectedvirtual |
Writes the main() of the testbench C program.
Reimplemented in DiscrepancyAnalysisCWriter.
Definition at line 577 of file hls_c_writer.cpp.
References IndentedOutputStream::Append(), IndentedOutputStream::AppendIndented(), test_panda::arg, tree_helper::CGetElements(), tree_helper::CGetPointedType(), tree_helper::CGetType(), cxa_prefix_mangled(), CWriter::debug_level, DEBUG_LEVEL_VERY_PEDANTIC, GET_INDEX_CONST_NODE, tree_helper::GetArrayTotalSize(), tree_manager::GetFunction(), tree_helper::GetFunctionReturnType(), CWriter::HLSMgr, INDENT_DBG_MEX, CWriter::indented_output_stream, INFERRED_INTERFACE_GENERATION, tree_helper::IsArrayType(), tree_helper::IsPointerType(), tree_helper::IsRealType(), tree_helper::IsStructType(), tree_helper::IsUnionType(), tree_helper::IsVectorType(), tree_helper::IsVoidType(), param, CWriter::Param, tree_helper::PrintType(), RETURN_PORT_NAME, tree_helper::Size(), starts_with(), STR, THROW_ASSERT, THROW_ERROR, CWriter::TM, WriteExtraCodeBeforeEveryMainCall(), WriteExtraInitCode(), WriteParamDecl(), WriteParamInitialization(), WriteSimulatorInitMemory(), and WriteTestbenchFunctionCall().
Referenced by WriteFile().
|
protected |
Write declaration of the top function parameters.
Declaration and initialization are separate statements.
Definition at line 194 of file hls_c_writer.cpp.
References IndentedOutputStream::Append(), tree_helper::CGetType(), BehavioralHelper::get_function_name(), BehavioralHelper::GetParameters(), CWriter::indented_output_stream, tree_helper::IsPointerType(), tree_helper::IsVectorType(), param, tree_helper::PrintType(), BehavioralHelper::PrintVariable(), THROW_ERROR, CWriter::TM, and test_panda::type.
Referenced by WriteMainTestbench(), and DiscrepancyAnalysisCWriter::WriteMainTestbench().
|
protected |
Initialize the parameters of the function.
Declaration and initialization are separate statements and the declaration code must be printed before the initialization code.
behavioral_helper | is the function to which the parameters are referred |
curr_test_vector | is the test vector used to initialize the parameters |
Definition at line 213 of file hls_c_writer.cpp.
References IndentedOutputStream::Append(), tree_helper::CGetPointedType(), tree_helper::CGetType(), CWriter::debug_level, DEBUG_LEVEL_VERY_PEDANTIC, ends_with(), GET_CONST_NODE, GET_INDEX_CONST_NODE, BehavioralHelper::GetMangledFunctionName(), BehavioralHelper::GetParameters(), tree_helper::GetRealType(), CWriter::HLSMgr, INDENT_DBG_MEX, CWriter::indented_output_stream, tree_helper::IsPointerType(), tree_helper::IsRealType(), tree_helper::IsVoidType(), param, lenet_tvm::params, tree_helper::PrintType(), BehavioralHelper::PrintVariable(), STR, THROW_ASSERT, THROW_ERROR, CWriter::TM, U, and wrapper_def().
Referenced by WriteMainTestbench(), and DiscrepancyAnalysisCWriter::WriteMainTestbench().
|
protected |
Write some print statements used to dump the values used by the HDL to initialize the memory before the simulation.
(This function actually also reserves memory out of the top function to be tested, if needed. This should not be done here, but in a separate memory allocation step, and will be moved soon).
Definition at line 418 of file hls_c_writer.cpp.
References align(), IndentedOutputStream::Append(), CWriter::debug_level, DEBUG_LEVEL_VERY_PEDANTIC, TestbenchGeneration::generate_init_file(), CWriter::HLSMgr, INDENT_DBG_MEX, CWriter::indented_output_stream, max, CWriter::Param, test_panda::parameters, STR, and CWriter::TM.
Referenced by WriteMainTestbench().
|
protected |
Writes a call to the top function to be tested, using its parameters.
The code for the declaration and initialization of such parameters must be written before a call to obtain meaningful outcome.
behavioral_helper | refers to the function to be tested |
Definition at line 353 of file hls_c_writer.cpp.
References IndentedOutputStream::Append(), BehavioralHelper::get_function_index(), BehavioralHelper::get_function_name(), GET_INDEX_CONST_NODE, BehavioralHelper::GetFunctionReturnType(), BehavioralHelper::GetMangledFunctionName(), BehavioralHelper::GetParameters(), CWriter::HLSMgr, CWriter::indented_output_stream, tree_helper::IsPointerType(), param, CWriter::Param, BehavioralHelper::PrintVariable(), and RETURN_PORT_NAME.
Referenced by WriteMainTestbench(), and DiscrepancyAnalysisCWriter::WriteMainTestbench().
|
protected |
Backend information.
Definition at line 56 of file hls_c_writer.hpp.
Referenced by DiscrepancyAnalysisCWriter::WriteExtraInitCode().