PandA-2024.02
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
CWriter Class Reference

Class used to write the C code representing a program, this class can't be directly instantiated since the backend is not specified yet. More...

#include <c_writer.hpp>

Inheritance diagram for CWriter:
Inheritance graph
[legend]
Collaboration diagram for CWriter:
Collaboration graph
[legend]

Public Member Functions

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 WriteFunctionImplementation (unsigned int function_id)
 Write function implementation. 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 WriteHeader ()
 Writes the header of the file. More...
 
virtual void WriteGlobalDeclarations ()
 Writes the global declarations. 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...
 
virtual void WriteFile (const std::string &file_name)
 Writes the final C file. More...
 
virtual void WriteBuiltinWaitCall ()
 Writes implementation of __builtin_wait_call. More...
 

Static Public Member Functions

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...
 

Protected Member Functions

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 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< vertexbb_frontier
 
CustomOrderedSet< vertexbb_analyzed
 
std::map< unsigned int, std::string > basic_blocks_labels
 
CustomOrderedSet< vertexgoto_list
 
var_pp_functorConstRef local_rec_variableFunctor
 
FunctionBehaviorConstRef local_rec_function_behavior
 
CustomOrderedSet< vertexlocal_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
 

Detailed Description

Class used to write the C code representing a program, this class can't be directly instantiated since the backend is not specified yet.

So a subclass must be created which redefines all the abstract methods of this class.

Definition at line 91 of file c_writer.hpp.

Constructor & Destructor Documentation

◆ CWriter()

CWriter::CWriter ( const HLS_managerConstRef  _HLSMgr,
const InstructionWriterRef  instruction_writer,
const IndentedOutputStreamRef  indented_output_stream,
const ParameterConstRef  Param,
bool  verbose = true 
)
protected

Constructor of the class.

Parameters
HLSMgris the hls manager
instruction_writeris the instruction writer to use to print the single instruction
indented_output_streamis the stream where code has to be printed
Paramis the set of parameters
verbosetells if annotations

Definition at line 140 of file c_writer.cpp.

References ~CWriter().

Referenced by CreateCWriter().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~CWriter()

CWriter::~CWriter ( )
virtualdefault

Referenced by CWriter().

Here is the caller graph for this function:

Member Function Documentation

◆ compute_phi_nodes()

void CWriter::compute_phi_nodes ( const FunctionBehaviorConstRef  function_behavior,
const OpVertexSet instructions,
var_pp_functorConstRef  variableFunctor 
)
protected

Determines the instructions coming out from phi-node splitting.

compute the assignment introduced by the phi nodes destruction

in case we declare the variables introduced during the phi nodes destruction

Definition at line 1110 of file c_writer.cpp.

References IndentedOutputStream::Append(), FunctionBehavior::CGetBBGraph(), BBGraph::CGetBBGraphInfo(), FunctionBehavior::CGetBehavioralHelper(), FunctionBehavior::CGetOpGraph(), OpGraph::CGetOpNodeInfo(), FunctionBehavior::DOM_TREE, FunctionBehavior::FBB, FunctionBehavior::FCFG, GET_TYPE, tree_helper::get_type_index(), indented_output_stream, insert_copies(), tree_helper::print_type(), THROW_ASSERT, TM, and TYPE_PHI.

Referenced by DeclareLocalVariables().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_new_identifier()

unsigned int CWriter::create_new_identifier ( std::map< unsigned int, std::string > &  symbol_table)
protected

create an identifier for the temporaries created by phi node destruction

Parameters
symbol_tableis the symbol table where the new id is inserted return an id for the symbol created

Definition at line 1641 of file c_writer.cpp.

References counter, fake_max_tree_node_id, tree_manager::find_identifier_nodeID(), STR, and TM.

Referenced by schedule_copies().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateCWriter()

CWriterRef CWriter::CreateCWriter ( const CBackendInformationConstRef  c_backend_information,
const HLS_managerConstRef  hls_man,
const IndentedOutputStreamRef  indented_output_stream,
const ParameterConstRef  parameters,
const bool  verbose 
)
static

Factory method.

Parameters
c_backend_informationis the information about the backend we are creating
hls_manis the hls manager
indented_output_streamis the output stream
parametersis the set of input parameters
verbosetells if produced source code has to be commented

Definition at line 159 of file c_writer.cpp.

References BA_NONE, InstructionWriter::CreateInstructionWriter(), CWriter(), and THROW_UNREACHABLE.

Here is the call graph for this function:

◆ declare_cast_types()

void CWriter::declare_cast_types ( unsigned int  funId,
CustomSet< std::string > &  locally_declared_types 
)
virtual

Declare all the types used in conversions.

Parameters
function_idis the function to be condiered
locally_declared_typesis the set of already declared types

Definition at line 206 of file c_writer.cpp.

References DeclareType(), FunctionBehavior::DFG, and HLSMgr.

Referenced by StartFunctionBody().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeclareFunctionTypes()

void CWriter::DeclareFunctionTypes ( const tree_nodeConstRef tn)
virtual

Declares the types of the parameters of a function.

Parameters
fun_idis the index of the function

Definition at line 333 of file c_writer.cpp.

References debug_level, DEBUG_LEVEL_VERY_PEDANTIC, DeclareType(), tree_helper::GetFunctionReturnType(), globally_declared_types, HLSMgr, INDENT_DBG_MEX, tree_node::index, and STR.

Here is the call graph for this function:

◆ DeclareLocalVariables()

void CWriter::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 
)
virtual

Declares the local variable; in case the variable used in the intialization of curVar hasn't been declared yet it get declared.

Parameters
to_be_declaredis the set of variables which have to be declared
already_decl_variablesis the set of already declared variables
locally_declared_typeis the set of already declared types
helperis the behavioral helper associated with the function
varFuncis the printer functor

Reimplemented in DiscrepancyAnalysisCWriter.

Definition at line 1393 of file c_writer.cpp.

References FunctionBehavior::CGetOpGraph(), tree_manager::CGetTreeReindex(), compute_phi_nodes(), debug_level, DEBUG_LEVEL_PEDANTIC, DeclareVariable(), FunctionBehavior::DFG, BehavioralHelper::get_function_index(), BehavioralHelper::get_function_name(), tree_node::get_kind(), GET_NODE, BehavioralHelper::get_parameters(), HLSMgr, INDENT_DBG_MEX, STR, THROW_ASSERT, and TM.

Referenced by DiscrepancyAnalysisCWriter::DeclareLocalVariables(), and StartFunctionBody().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeclareType()

void CWriter::DeclareType ( const tree_nodeConstRef varType,
const BehavioralHelperConstRef behavioral_helper,
CustomSet< std::string > &  locally_declared_type 
)
virtual

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)

Parameters
varTypethe type to be declared
BHthe behavioral helper associated to the function which declare type
locally_declared_typeis the set of type already declared in this function
routine_nameis the name of the routina (function or thread)

Definition at line 1278 of file c_writer.cpp.

References IndentedOutputStream::Append(), debug_level, DEBUG_LEVEL_VERY_PEDANTIC, GET_CONST_NODE, BehavioralHelper::get_function_name(), tree_helper::GetRealType(), tree_helper::GetSourcePath(), tree_helper::GetTypeName(), tree_helper::GetTypesToBeDeclaredAfter(), tree_helper::GetTypesToBeDeclaredBefore(), globally_declared_types, tree_helper::HasToBeDeclared(), INDENT_DBG_MEX, indented_output_stream, tree_helper::IsInLibbambu(), Param, BehavioralHelper::print_type_declaration(), STR, TM, ToString(), and verbose.

Referenced by declare_cast_types(), DeclareFunctionTypes(), and DeclareVariable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeclareVariable()

void CWriter::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 
)
virtual

Declares the local variable; in case the variable used in the intialization of curVar hasn't been declared yet it get declared.

Parameters
curVaris the variable to be declared
already_decl_variablesis the set of already declared variables
locally_declared_typeis the set of already declared types
behavioral_helperis the behavioral helper
varFuncis the printer functor

Definition at line 1330 of file c_writer.cpp.

References IndentedOutputStream::Append(), tree_manager::CGetTreeReindex(), tree_helper::CGetType(), debug_level, DEBUG_LEVEL_PEDANTIC, DEBUG_LEVEL_VERY_PEDANTIC, DeclareType(), GET_CONST_NODE, BehavioralHelper::GetInit(), globallyDeclVars, INDENT_DBG_MEX, indented_output_stream, tree_node::index, instrWriter, tree_helper::IsInLibbambu(), tree_helper::IsSystemType(), BehavioralHelper::PrintVarDeclaration(), STR, TM, and verbose.

Referenced by DeclareLocalVariables(), and WriteGlobalDeclarations().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EndFunctionBody()

void CWriter::EndFunctionBody ( unsigned int  funId)
virtual

Writes the code necessary to close a function (this function was a function also present in the original specification)

Definition at line 409 of file c_writer.cpp.

References IndentedOutputStream::Append(), basic_block_prefix, basic_block_tail, indented_output_stream, renaming_table, STR, and verbose.

Referenced by WriteFunctionImplementation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getInstructionWriter()

const InstructionWriterRef CWriter::getInstructionWriter ( ) const

Returns the instruction writer.

Returns
the instruction writer

Definition at line 1378 of file c_writer.cpp.

References instrWriter.

◆ GetLocalVariables()

const CustomSet< unsigned int > CWriter::GetLocalVariables ( const unsigned int  function_id) const

Compute the local variables of a function.

Parameters
function_idis the index of a function
Returns
the local variables of a function

Definition at line 356 of file c_writer.cpp.

References FunctionBehavior::DFG, and HLSMgr.

Referenced by StartFunctionBody().

Here is the caller graph for this function:

◆ Initialize()

void CWriter::Initialize ( )
virtual

Initialize data structure.

Reimplemented in EdgeCWriter.

Definition at line 228 of file c_writer.cpp.

References additionalIncludes, fake_max_tree_node_id, tree_manager::get_next_available_tree_node_id(), globally_declared_types, globallyDeclVars, instrWriter, TM, and writtenIncludes.

Referenced by EdgeCWriter::Initialize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ insert_copies()

void CWriter::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 
)
protected

Compute the copy assignments needed by the phi nodes destruction Further details can be found in:

  • Preston Briggs, Keith D. Cooper, Timothy J. Harvey and L. Taylor Simpson, "Practical Improvements to the Construction and Destruction of Static Single Assignment Form", Software – Practice and Experience 1998

fill the renaming table for basic block b

Definition at line 1442 of file c_writer.cpp.

References pop_stack(), renaming_table, schedule_copies(), and lenet_tvm::target.

Referenced by compute_phi_nodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pop_stack()

void CWriter::pop_stack ( std::list< unsigned int > &  pushed,
std::map< unsigned int, std::deque< std::string >> &  array_of_stacks 
)
protected

remove from the stack all the temporaries

Parameters
pushedis the list of variables to be renamed
array_of_stacksis the array of stacks used by the phi node destruction procedure

Definition at line 1666 of file c_writer.cpp.

References THROW_ASSERT.

Referenced by insert_copies().

Here is the caller graph for this function:

◆ push_stack()

void CWriter::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 
)
protected

push on the stack of temporary variables that has to replaced

Parameters
symbol_nameis the new identifier for dest_i
dest_iis the id of the variable to be renamed
pushedis the list of variables to be renamed
array_of_stacksis the array of stacks used by the phi node destruction procedure

Definition at line 1658 of file c_writer.cpp.

References THROW_ASSERT.

Referenced by schedule_copies().

Here is the caller graph for this function:

◆ schedule_copies()

void CWriter::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 
)
protected

insert copies according the algorithm described in Briggs et.

al.

Pass One: initialize the data structures

Pass two: Set up the worklist of initial copies

Pass Three: Iterate over the worklist, inserting copies

if dest live_out(b) wrt the original algorithm an optimization has been added: in case b does not dominate any other node we can skip the creation of t

insert a copy from dest to a new temp t at phi-node defining dest

push(t, Stack[dest])

insert a copy operation from map[src] to dest at the end of b

check if dest_i is source of any other pair in copy_set this optimization is not described in the original algorithm

create a new symbol

insert a copy from dest to a new temp t at the end of b

Definition at line 1470 of file c_writer.cpp.

References basic_block_prefix, basic_block_tail, BBGraph::CGetBBNodeInfo(), create_new_identifier(), GET_INDEX_NODE, GET_NODE, map, push_stack(), renaming_table, and lenet_tvm::target.

Referenced by insert_copies().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StartFunctionBody()

void CWriter::StartFunctionBody ( const unsigned int  function_id)
virtual

Writes the body of the function to the specified stream.

Parameters
funIdis the index of the function

Definition at line 384 of file c_writer.cpp.

References IndentedOutputStream::Append(), declare_cast_types(), DeclareLocalVariables(), GetLocalVariables(), HLSMgr, indented_output_stream, and instrWriter.

Referenced by WriteFunctionImplementation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteBBHeader()

void CWriter::WriteBBHeader ( const unsigned int  bb_number,
const unsigned int  function_index 
)
protectedvirtual

Reimplemented in DiscrepancyAnalysisCWriter.

Definition at line 1918 of file c_writer.cpp.

Referenced by writeRoutineInstructions_rec().

Here is the caller graph for this function:

◆ WriteBodyLoop()

void CWriter::WriteBodyLoop ( const unsigned int  function_index,
const unsigned  int,
vertex  current_vertex,
bool  bracket 
)
protectedvirtual

Write the instructions belonging to a body loop.

Parameters
function_indexis the identifier of the function to which instructions belong
loop_idis the index of the loop to be printed
current_vertexis the first basic block of the loop
brackettells if bracket should be added before and after this basic block

Definition at line 238 of file c_writer.cpp.

References writeRoutineInstructions_rec().

Referenced by writeRoutineInstructions_rec().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteBuiltinWaitCall()

void CWriter::WriteBuiltinWaitCall ( )
virtual

◆ WriteFile()

void CWriter::WriteFile ( const std::string &  file_name)
virtual

Writes the final C file.

Parameters
file_nameis the name of the file to be generated

Reimplemented in HLSCWriter.

Definition at line 1913 of file c_writer.cpp.

References indented_output_stream, and IndentedOutputStream::WriteFile().

Referenced by EdgeCWriter::writeRoutineInstructions().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteFunctionBody()

void CWriter::WriteFunctionBody ( const unsigned int  function_id)
virtual

Writes the body of a function.

Parameters
function_idis the function whose body has to be printed

Definition at line 243 of file c_writer.cpp.

References FunctionBehavior::CFG, FunctionBehavior::CGetBehavioralHelper(), FunctionBehavior::CGetOpGraph(), BehavioralHelper::get_function_name(), HLSMgr, THROW_ASSERT, and writeRoutineInstructions().

Referenced by WriteFunctionImplementation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteFunctionDeclaration()

void CWriter::WriteFunctionDeclaration ( const unsigned int  funId)
virtual

Writes the declaration of the function whose id in the tree is funId.

Reimplemented in DiscrepancyAnalysisCWriter.

Definition at line 372 of file c_writer.cpp.

References IndentedOutputStream::Append(), HLSMgr, indented_output_stream, and instrWriter.

Referenced by DiscrepancyAnalysisCWriter::WriteFunctionDeclaration().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteFunctionImplementation()

void CWriter::WriteFunctionImplementation ( unsigned int  function_id)
virtual

Write function implementation.

Parameters
function_idis the index of the function to be written

Reimplemented in HLSCWriter, and DiscrepancyAnalysisCWriter.

Definition at line 258 of file c_writer.cpp.

References EndFunctionBody(), StartFunctionBody(), and WriteFunctionBody().

Referenced by DiscrepancyAnalysisCWriter::WriteFunctionImplementation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteGlobalDeclarations()

void CWriter::WriteGlobalDeclarations ( )
virtual

Writes the global declarations.

Writing auxiliary variables used by instruction writer

Writing declarations of global variables

Reimplemented in HLSCWriter, BasicBlocksProfilingCWriter, and DiscrepancyAnalysisCWriter.

Definition at line 307 of file c_writer.cpp.

References IndentedOutputStream::Append(), BUILTIN_WAIT_CALL, DeclareVariable(), globally_declared_types, globallyDeclVars, HLSMgr, indented_output_stream, instrWriter, STR, and THROW_ASSERT.

Referenced by DiscrepancyAnalysisCWriter::WriteGlobalDeclarations(), and BasicBlocksProfilingCWriter::WriteGlobalDeclarations().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteHashTableImplementation()

void CWriter::WriteHashTableImplementation ( )
protected

Write the implementation of a hash table with long long int as key and long long int as value.

Definition at line 1678 of file c_writer.cpp.

References IndentedOutputStream::Append(), and indented_output_stream.

Here is the call graph for this function:

◆ WriteHeader()

void CWriter::WriteHeader ( )
virtual

Writes the header of the file.

Reimplemented in EdgeCWriter, and HLSCWriter.

Definition at line 265 of file c_writer.cpp.

References IndentedOutputStream::Append(), BehavioralHelper::get_function_name(), HLSMgr, and indented_output_stream.

Here is the call graph for this function:

◆ writeInclude()

void CWriter::writeInclude ( const std::string &  file_name)
virtual

Writes an include directive.

Parameters
file_namethe name of the header file to be included

Definition at line 1383 of file c_writer.cpp.

References IndentedOutputStream::Append(), indented_output_stream, and writtenIncludes.

Here is the call graph for this function:

◆ writePostInstructionInfo()

void CWriter::writePostInstructionInfo ( const FunctionBehaviorConstRef  ,
const vertex   
)
protectedvirtual

Write additional information on the given statement vertex, after the statements itself.

The default for this function is to do nothing, but every derived class can specify its own additional information to print

Reimplemented in DiscrepancyAnalysisCWriter.

Definition at line 426 of file c_writer.cpp.

Referenced by writeRoutineInstructions_rec().

Here is the caller graph for this function:

◆ writePreInstructionInfo()

void CWriter::writePreInstructionInfo ( const FunctionBehaviorConstRef  ,
const vertex   
)
protectedvirtual

Write additional information on the given statement vertex, before the statement itself.

The default for this function is to do nothing, but every derived class can specify its own additional information to print

Reimplemented in DiscrepancyAnalysisCWriter.

Definition at line 422 of file c_writer.cpp.

Referenced by writeRoutineInstructions_rec().

Here is the caller graph for this function:

◆ writeRoutineInstructions()

void CWriter::writeRoutineInstructions ( const unsigned int  function_index,
const OpVertexSet instructions,
var_pp_functorConstRef  variableFunctor,
vertex  bb_start = NULL_VERTEX,
CustomOrderedSet< vertex bb_end = CustomOrderedSet<vertex>() 
)
virtual

Writes the instructions of the current routine, being it a task or a function of the original program.

Parameters
function_indexis the index of the function
instructionsis the instructions which have to be printed
variableFunctoris the variable functor
bb_startis the first basic block to be printed
bb_endis the set of first basic block not to be printed

Then I compute all the labels associated with a basic block with more than one entering edge.

set of basic block already analyzed

store for which basic block the goto has been used

basic block frontier over which writeRoutineInstructions_rec cannot go.

some statements can be in entry

Reimplemented in EdgeCWriter.

Definition at line 1150 of file c_writer.cpp.

References IndentedOutputStream::Append(), basic_blocks_labels, bb_analyzed, bb_frontier, bb_label_counter, FunctionBehavior::CGetBBGraph(), FunctionBehavior::CGetBehavioralHelper(), FunctionBehavior::CGetOpGraph(), debug_level, DEBUG_LEVEL_PEDANTIC, DEBUG_LEVEL_VERY_PEDANTIC, dominators, FunctionBehavior::dominators, bloc::EXIT_BLOCK_ID, FunctionBehavior::FBB, FunctionBehavior::FCFG, GET_TYPE, goto_list, HLSMgr, INDENT_DBG_MEX, indented_output_stream, local_rec_bb_fcfgGraph, local_rec_behavioral_helper, local_rec_cfgGraph, local_rec_function_behavior, local_rec_instructions, local_rec_variableFunctor, post_dominators, FunctionBehavior::post_dominators, STR, lenet_tvm::target, TYPE_ENTRY, and writeRoutineInstructions_rec().

Referenced by WriteFunctionBody().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeRoutineInstructions_rec()

void CWriter::writeRoutineInstructions_rec ( vertex  current_vertex,
bool  bracket,
const unsigned int  function_index 
)
protected

Write recursively instructions belonging to a basic block of task or of a function.

Parameters
current_vertexis the basic block which is being printed
brackettells if bracket should be added before and after this basic block
function_indexis the identifier of the function to which instructions belong

compute the last statement

check the feasibility

print each instruction

in case we have phi nodes we check if some assignments should be printed

Feedback edge on the false path of an if

Target is not a while or a for

now we can analyze the following basic blocks

then adjust post dominator

now we can analyze the following basic blocks

in case we have phi nodes we check if some assignments should be printed

Last basic block of a while/for loop

added a fake indent

Definition at line 430 of file c_writer.cpp.

References IndentedOutputStream::Append(), basic_block_prefix, basic_block_tail, basic_blocks_labels, bb_analyzed, bb_frontier, CFG_SELECTOR, BBGraph::CGetBBEdgeInfo(), BBGraph::CGetBBGraphInfo(), BBGraph::CGetBBNodeInfo(), FunctionBehavior::CGetBehavioralHelper(), FunctionBehavior::CGetLoops(), OpGraph::CGetOpNodeInfo(), tree_manager::CGetTreeReindex(), BehavioralHelper::clear_renaming_table(), debug_level, DEBUG_LEVEL_VERY_PEDANTIC, default_COND, DOALL_LOOP, dominators, BehavioralHelper::end_with_a_cond_or_goto(), FB_CFG_SELECTOR, BehavioralHelper::get_function_index(), dominance< GraphObj >::get_immediate_dominator(), GET_INDEX_NODE, tree_node::get_kind(), GET_NAME, tree_manager::get_tree_node_const(), GET_TYPE, graph::GetSelector(), goto_list, INDENT_DBG_MEX, indented_output_stream, instrWriter, local_rec_bb_fcfgGraph, local_rec_behavioral_helper, local_rec_cfgGraph, local_rec_function_behavior, local_rec_instructions, local_rec_variableFunctor, NULL_VERTEX, post_dominators, BehavioralHelper::PrintConstant(), BehavioralHelper::PrintVariable(), BehavioralHelper::rename_a_variable(), renaming_table, BehavioralHelper::start_with_a_label(), STR, lenet_tvm::target, THROW_ASSERT, THROW_ERROR, TM, TYPE_FOR, TYPE_IF, TYPE_INIT, TYPE_LABEL, TYPE_MULTIIF, TYPE_SWITCH, TYPE_VPHI, TYPE_WHILE, verbose, WriteBBHeader(), WriteBodyLoop(), writePostInstructionInfo(), and writePreInstructionInfo().

Referenced by WriteBodyLoop(), and writeRoutineInstructions().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ additionalIncludes

std::vector<std::string> CWriter::additionalIncludes
protected

Definition at line 190 of file c_writer.hpp.

Referenced by Initialize().

◆ basic_block_prefix

std::map<unsigned int, std::string> CWriter::basic_block_prefix
protected

string to be printed at the beginning of a given basic block

Definition at line 130 of file c_writer.hpp.

Referenced by EndFunctionBody(), schedule_copies(), EdgeCWriter::writeRoutineInstructions_rec(), and writeRoutineInstructions_rec().

◆ basic_block_tail

std::map<unsigned int, std::string> CWriter::basic_block_tail
protected

string to be printed at the end of a given basic block

Definition at line 133 of file c_writer.hpp.

Referenced by EndFunctionBody(), schedule_copies(), EdgeCWriter::writeRoutineInstructions_rec(), and writeRoutineInstructions_rec().

◆ basic_blocks_labels

std::map<unsigned int, std::string> CWriter::basic_blocks_labels
protected

◆ bb_analyzed

CustomOrderedSet<vertex> CWriter::bb_analyzed
protected

◆ bb_frontier

CustomOrderedSet<vertex> CWriter::bb_frontier
protected

◆ bb_label_counter

size_t CWriter::bb_label_counter
protected

Counter of the invocations of writeRoutineInstructions; this counter allows to print different labels in differnt tasks to avoid problem due to multiple tasks inlineing.

Definition at line 113 of file c_writer.hpp.

Referenced by EdgeCWriter::writeRoutineInstructions(), and writeRoutineInstructions().

◆ debug_level

int CWriter::debug_level
protected

◆ dominators

const dominance<BBGraph>* CWriter::dominators
protected

◆ fake_max_tree_node_id

unsigned int CWriter::fake_max_tree_node_id
protected

Definition at line 127 of file c_writer.hpp.

Referenced by create_new_identifier(), and Initialize().

◆ globally_declared_types

CustomSet<std::string> CWriter::globally_declared_types
protected

This set contains the list of the non built_in types already declared in the global scope.

Definition at line 104 of file c_writer.hpp.

Referenced by DeclareFunctionTypes(), DeclareType(), Initialize(), and WriteGlobalDeclarations().

◆ globallyDeclVars

CustomSet<unsigned int> CWriter::globallyDeclVars
protected

Definition at line 106 of file c_writer.hpp.

Referenced by DeclareVariable(), Initialize(), and WriteGlobalDeclarations().

◆ goto_list

CustomOrderedSet<vertex> CWriter::goto_list
protected

◆ HLSMgr

const HLS_managerConstRef CWriter::HLSMgr
protected

◆ indented_output_stream

const IndentedOutputStreamRef CWriter::indented_output_stream
protected

◆ instrWriter

const InstructionWriterRef CWriter::instrWriter
protected

◆ local_rec_bb_fcfgGraph

BBGraphConstRef CWriter::local_rec_bb_fcfgGraph
protected

Definition at line 147 of file c_writer.hpp.

Referenced by writeRoutineInstructions(), and writeRoutineInstructions_rec().

◆ local_rec_behavioral_helper

BehavioralHelperConstRef CWriter::local_rec_behavioral_helper
protected

Definition at line 149 of file c_writer.hpp.

Referenced by writeRoutineInstructions(), and writeRoutineInstructions_rec().

◆ local_rec_cfgGraph

OpGraphConstRef CWriter::local_rec_cfgGraph
protected

Definition at line 148 of file c_writer.hpp.

Referenced by writeRoutineInstructions(), and writeRoutineInstructions_rec().

◆ local_rec_function_behavior

FunctionBehaviorConstRef CWriter::local_rec_function_behavior
protected

◆ local_rec_instructions

CustomOrderedSet<vertex> CWriter::local_rec_instructions
protected

◆ local_rec_variableFunctor

var_pp_functorConstRef CWriter::local_rec_variableFunctor
protected

◆ output_level

int CWriter::output_level
protected

the output level

Definition at line 125 of file c_writer.hpp.

Referenced by HLSCWriter::WriteFile().

◆ Param

const ParameterConstRef CWriter::Param
protected

◆ post_dominators

const dominance<BBGraph>* CWriter::post_dominators
protected

◆ renaming_table

std::map<vertex, std::map<unsigned int, std::string> > CWriter::renaming_table
protected

renaming table used by phi node destruction procedure

Definition at line 136 of file c_writer.hpp.

Referenced by EndFunctionBody(), insert_copies(), schedule_copies(), EdgeCWriter::writeRoutineInstructions_rec(), and writeRoutineInstructions_rec().

◆ TM

const tree_managerConstRef CWriter::TM
protected

◆ verbose

bool CWriter::verbose
protected

Verbosity means that a comment is printed for each line in the output file.

Definition at line 116 of file c_writer.hpp.

Referenced by DeclareType(), DeclareVariable(), EndFunctionBody(), EdgeCWriter::writeRoutineInstructions_rec(), and writeRoutineInstructions_rec().

◆ writtenIncludes

CustomOrderedSet<std::string> CWriter::writtenIncludes
protected

Definition at line 191 of file c_writer.hpp.

Referenced by Initialize(), and writeInclude().


The documentation for this class was generated from the following files:

Generated on Mon Feb 12 2024 13:03:49 for PandA-2024.02 by doxygen 1.8.13