PandA-2024.02
Public Member Functions | Protected Member Functions | Protected Attributes
EdgeCWriter Class Reference

Class use to write the C code with instrumented edges. More...

#include <edge_c_writer.hpp>

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

Public Member Functions

 EdgeCWriter (const HLS_managerConstRef _HLSMgr, const InstructionWriterRef instruction_writer, const IndentedOutputStreamRef indented_output_stream, const ParameterConstRef Param, bool verbose=true)
 Constructor of the class. More...
 
virtual ~EdgeCWriter () override
 
virtual void Initialize () override
 Initialize data structure. More...
 
virtual void WriteHeader () override
 Writes the header of the file. More...
 
const std::map< unsigned int, std::map< unsigned int, unsigned int > > & CGetFunctionLoopToId () const
 Returns the map which associates to each loop a unique id. More...
 
- Public Member Functions inherited from CWriter
virtual ~CWriter ()
 
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 WriteFunctionDeclaration (const unsigned int funId)
 Writes the declaration of the function whose id in the tree is funId. 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...
 

Protected Member Functions

virtual void print_loop_ending (EdgeDescriptor e)
 Dump operations requested for record information about a loop path which ends. More...
 
virtual void print_loop_escaping (EdgeDescriptor e)
 Dump operations requested for record information about a path which exit from a loop. More...
 
virtual void print_loop_starting (EdgeDescriptor e)
 Dump initializations of variable for recording a loop path. More...
 
virtual void print_edge (EdgeDescriptor e, unsigned int index)
 Dump operation requested for instrument an edges. More...
 
virtual void print_end_path (unsigned int fun_id, unsigned int loop_id)
 Print operations needed to store into symbol table information about last path. More...
 
virtual void print_loop_switching (EdgeDescriptor e)
 Print operation requested for record information about a path which exit from a loop and immediately enter in another. More...
 
void writeRoutineInstructions_rec (vertex current_vertex, bool bracket)
 Write recursively instructions belonging to a basic block of task or of a function. More...
 
void writeRoutineInstructions (const unsigned int function_index, const OpVertexSet &instructions, const var_pp_functorConstRef variableFunctor, vertex bb_start=NULL_VERTEX, CustomOrderedSet< vertex > bb_end=CustomOrderedSet< vertex >()) override
 Writes the instructions of the current routine, being it a task or a function of the original program. 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

std::map< vertex, EdgeDescriptorlocal_inc
 Increment which should be added before the label in a basic block. More...
 
std::set< EdgeDescriptor, ltedge< BBGraph > > dumped_edges
 Set of already dumped edges. More...
 
std::map< unsigned int, std::map< unsigned int, unsigned int > > fun_loop_to_index
 Map a pair function - loop to an unique index. More...
 
unsigned int counter
 The size of fun_loop_to_index. More...
 
BBGraphConstRef support_cfg
 Special control flow graphs. More...
 
unsigned int fun_id
 Index of the current function. 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< 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
 

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

Detailed Description

Class use to write the C code with instrumented edges.

Definition at line 65 of file edge_c_writer.hpp.

Constructor & Destructor Documentation

◆ EdgeCWriter()

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

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 output stream
Paramis the set of parameters
verbosetells if annotations

Definition at line 61 of file edge_c_writer.cpp.

References CWriter::debug_level, GET_CLASS, CWriter::Param, and ~EdgeCWriter().

Here is the call graph for this function:

◆ ~EdgeCWriter()

EdgeCWriter::~EdgeCWriter ( )
overridevirtualdefault

Referenced by EdgeCWriter().

Here is the caller graph for this function:

Member Function Documentation

◆ CGetFunctionLoopToId()

const std::map< unsigned int, std::map< unsigned int, unsigned int > > & EdgeCWriter::CGetFunctionLoopToId ( ) const

Returns the map which associates to each loop a unique id.

Returns
the map which associates to each loop a unique id

Definition at line 1525 of file edge_c_writer.cpp.

References fun_loop_to_index.

◆ Initialize()

void EdgeCWriter::Initialize ( )
overridevirtual

Initialize data structure.

Reimplemented from CWriter.

Definition at line 73 of file edge_c_writer.cpp.

References counter, fun_loop_to_index, CWriter::HLSMgr, and CWriter::Initialize().

Here is the call graph for this function:

◆ print_edge()

void EdgeCWriter::print_edge ( EdgeDescriptor  e,
unsigned int  index 
)
protectedvirtual

Dump operation requested for instrument an edges.

Parameters
eis the edge
indexis the index of the variable to be incremented

Reimplemented in BasicBlocksProfilingCWriter.

Definition at line 92 of file edge_c_writer.cpp.

References dumped_edges.

Referenced by writeRoutineInstructions_rec().

Here is the caller graph for this function:

◆ print_end_path()

void EdgeCWriter::print_end_path ( unsigned int  fun_id,
unsigned int  loop_id 
)
protectedvirtual

Print operations needed to store into symbol table information about last path.

Parameters
fun_idis the index of the function
loop_idis the index of the loop

Definition at line 97 of file edge_c_writer.cpp.

Referenced by writeRoutineInstructions_rec().

Here is the caller graph for this function:

◆ print_loop_ending()

void EdgeCWriter::print_loop_ending ( EdgeDescriptor  e)
protectedvirtual

Dump operations requested for record information about a loop path which ends.

Parameters
eis the feedback or outgoing edge

Reimplemented in BasicBlocksProfilingCWriter.

Definition at line 101 of file edge_c_writer.cpp.

Referenced by writeRoutineInstructions_rec().

Here is the caller graph for this function:

◆ print_loop_escaping()

void EdgeCWriter::print_loop_escaping ( EdgeDescriptor  e)
protectedvirtual

Dump operations requested for record information about a path which exit from a loop.

Parameters
eis the feedback or outgoing edge

Reimplemented in BasicBlocksProfilingCWriter.

Definition at line 105 of file edge_c_writer.cpp.

Referenced by writeRoutineInstructions_rec().

Here is the caller graph for this function:

◆ print_loop_starting()

void EdgeCWriter::print_loop_starting ( EdgeDescriptor  e)
protectedvirtual

Dump initializations of variable for recording a loop path.

Parameters
eis the incoming edged

Reimplemented in BasicBlocksProfilingCWriter.

Definition at line 109 of file edge_c_writer.cpp.

Referenced by writeRoutineInstructions_rec().

Here is the caller graph for this function:

◆ print_loop_switching()

void EdgeCWriter::print_loop_switching ( EdgeDescriptor  e)
protectedvirtual

Print operation requested for record information about a path which exit from a loop and immediately enter in another.

Parameters
eis the edge

Reimplemented in BasicBlocksProfilingCWriter.

Definition at line 113 of file edge_c_writer.cpp.

Referenced by writeRoutineInstructions_rec().

Here is the caller graph for this function:

◆ WriteHeader()

void EdgeCWriter::WriteHeader ( )
overridevirtual

Writes the header of the file.

Reimplemented from CWriter.

Definition at line 1530 of file edge_c_writer.cpp.

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

Here is the call graph for this function:

◆ writeRoutineInstructions()

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

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
var_pp_functoris 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 from CWriter.

Definition at line 1378 of file edge_c_writer.cpp.

References IndentedOutputStream::Append(), CWriter::basic_blocks_labels, CWriter::bb_analyzed, CWriter::bb_frontier, CWriter::bb_label_counter, FunctionBehavior::CGetBBGraph(), BBGraph::CGetBBGraphInfo(), BBGraph::CGetBBNodeInfo(), FunctionBehavior::CGetBehavioralHelper(), FunctionBehavior::CGetOpGraph(), CWriter::debug_level, DEBUG_LEVEL_PEDANTIC, DEBUG_LEVEL_VERY_PEDANTIC, CWriter::dominators, FunctionBehavior::dominators, dumped_edges, edges, bloc::EXIT_BLOCK_ID, FunctionBehavior::FBB, FunctionBehavior::FCFG, fun_id, refcount< T >::get(), BehavioralHelper::get_function_index(), BehavioralHelper::get_function_name(), BehavioralHelper::get_label_name(), GET_TYPE, CWriter::goto_list, CWriter::HLSMgr, INDENT_DBG_MEX, CWriter::indented_output_stream, local_inc, CWriter::local_rec_function_behavior, CWriter::local_rec_instructions, CWriter::local_rec_variableFunctor, CWriter::post_dominators, FunctionBehavior::post_dominators, FunctionBehavior::PPG, PROFILING_EC, BehavioralHelper::start_with_a_label(), support_cfg, lenet_tvm::target, THROW_ERROR_CODE, TYPE_ENTRY, CWriter::WriteFile(), and writeRoutineInstructions_rec().

Here is the call graph for this function:

◆ writeRoutineInstructions_rec()

void EdgeCWriter::writeRoutineInstructions_rec ( vertex  current_vertex,
bool  bracket 
)
protected

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

Parameters
function_behavioris the function to which instructions belong
current_vertexis the basic block which is being printed
instructionsare the instructions which belongs to this task/function
brackettells if bracket should be added before and after this basic block

the entry vertex

the exit vertex

get immediate post-dominator

compute the last statement

check the feasibility

check for basic block label

print each instruction

fill the renamin table in case is needed

We can print results of split of phi nodes if they have not yet been printed and if label has already been printed (or there was not any label to be printed)

If there is not any label to be printed, label_has_to_be_printed is already false, otherwise the label will be printed during this loop iteration

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

added a fake indent

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

added a fake indent

Definition at line 117 of file edge_c_writer.cpp.

References IndentedOutputStream::Append(), CWriter::basic_block_prefix, CWriter::basic_block_tail, CWriter::basic_blocks_labels, CWriter::bb_analyzed, CWriter::bb_frontier, CFG_SELECTOR, BBGraph::CGetBBEdgeInfo(), FunctionBehavior::CGetBBGraph(), BBGraph::CGetBBGraphInfo(), BBGraph::CGetBBNodeInfo(), FunctionBehavior::CGetBehavioralHelper(), FunctionBehavior::CGetLoops(), FunctionBehavior::CGetOpGraph(), OpGraph::CGetOpNodeInfo(), tree_manager::CGetTreeReindex(), BehavioralHelper::clear_renaming_table(), CWriter::debug_level, DEBUG_LEVEL_VERY_PEDANTIC, default_COND, DOALL_LOOP, CWriter::dominators, BehavioralHelper::end_with_a_cond_or_goto(), FB_CFG_SELECTOR, FunctionBehavior::FBB, FunctionBehavior::FCFG, fun_id, fun_loop_to_index, 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(), CWriter::goto_list, CWriter::HLSMgr, INDENT_DBG_MEX, CWriter::indented_output_stream, CWriter::instrWriter, local_inc, CWriter::local_rec_function_behavior, CWriter::local_rec_instructions, CWriter::local_rec_variableFunctor, NULL_VERTEX, CWriter::post_dominators, print_edge(), print_end_path(), print_loop_ending(), print_loop_escaping(), print_loop_starting(), print_loop_switching(), BehavioralHelper::PrintConstant(), BehavioralHelper::PrintVariable(), PROFILING_EC, BehavioralHelper::rename_a_variable(), CWriter::renaming_table, BehavioralHelper::start_with_a_label(), STR, support_cfg, lenet_tvm::target, THROW_ASSERT, THROW_ERROR, THROW_ERROR_CODE, CWriter::TM, TYPE_FOR, TYPE_IF, TYPE_INIT, TYPE_LABEL, TYPE_LAST_OP, TYPE_MULTIIF, TYPE_RET, TYPE_SWITCH, TYPE_VPHI, TYPE_WHILE, and CWriter::verbose.

Referenced by writeRoutineInstructions().

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

Field Documentation

◆ counter

unsigned int EdgeCWriter::counter
protected

The size of fun_loop_to_index.

Definition at line 78 of file edge_c_writer.hpp.

Referenced by Initialize().

◆ dumped_edges

std::set<EdgeDescriptor, ltedge<BBGraph> > EdgeCWriter::dumped_edges
protected

Set of already dumped edges.

Definition at line 72 of file edge_c_writer.hpp.

Referenced by BasicBlocksProfilingCWriter::print_edge(), print_edge(), and writeRoutineInstructions().

◆ fun_id

unsigned int EdgeCWriter::fun_id
protected

Index of the current function.

Definition at line 84 of file edge_c_writer.hpp.

Referenced by BasicBlocksProfilingCWriter::print_edge(), writeRoutineInstructions(), and writeRoutineInstructions_rec().

◆ fun_loop_to_index

std::map<unsigned int, std::map<unsigned int, unsigned int> > EdgeCWriter::fun_loop_to_index
protected

Map a pair function - loop to an unique index.

Definition at line 75 of file edge_c_writer.hpp.

Referenced by CGetFunctionLoopToId(), Initialize(), and writeRoutineInstructions_rec().

◆ local_inc

std::map<vertex, EdgeDescriptor> EdgeCWriter::local_inc
protected

Increment which should be added before the label in a basic block.

Definition at line 69 of file edge_c_writer.hpp.

Referenced by writeRoutineInstructions(), and writeRoutineInstructions_rec().

◆ support_cfg

BBGraphConstRef EdgeCWriter::support_cfg
protected

Special control flow graphs.

Definition at line 81 of file edge_c_writer.hpp.

Referenced by BasicBlocksProfilingCWriter::print_edge(), writeRoutineInstructions(), and writeRoutineInstructions_rec().


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

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