51 #include "config_HAVE_HOST_PROFILING_BUILT.hpp" 52 #include "config_PACKAGE_NAME.hpp" 53 #include "config_PACKAGE_VERSION.hpp" 54 #include "config_RELEASE.hpp" 80 #if HAVE_HOST_PROFILING_BUILT 88 #include <boost/range/adaptor/reversed.hpp> 91 #include <boost/functional/hash/hash.hpp> 97 struct hash<
std::pair<tree_nodeRef, tree_nodeRef>>
98 :
public std::unary_function<std::pair<tree_nodeRef, tree_nodeRef>, std::size_t>
100 std::size_t operator()(
const std::pair<tree_nodeRef, tree_nodeRef>& val)
const 103 boost::hash_combine(hash_value, val.first);
104 boost::hash_combine(hash_value, val.second);
114 :
public std::binary_function<std::pair<tree_nodeRef, tree_nodeRef>, std::pair<tree_nodeRef, tree_nodeRef>, bool>
123 bool operator()(
const std::pair<tree_nodeRef, tree_nodeRef>&
x,
const std::pair<tree_nodeRef, tree_nodeRef>& y)
const 125 if(x.first->index == y.first->index)
127 return x.second->index < y.second->index;
131 return x.first->index < y.first->index;
143 TM(_HLSMgr->get_tree_manager()),
144 indented_output_stream(_indented_output_stream),
145 instrWriter(_instruction_writer),
149 debug_level(_Param->get_class_debug_level(
"CWriter")),
150 output_level(_Param->getOption<int>(OPT_output_level)),
151 fake_max_tree_node_id(0),
153 post_dominators(nullptr)
163 const auto app_man = RefcountCast<const application_manager>(hls_man);
164 switch(c_backend_info->type)
166 #if HAVE_HOST_PROFILING_BUILT 167 case(CBackendInformation::CB_BBP):
176 case(CBackendInformation::CB_DISCREPANCY_ANALYSIS):
182 indented_output_stream, parameters, verbose));
185 case(CBackendInformation::CB_HLS):
190 new HLSCWriter(c_backend_info, hls_man, instruction_writer, indented_output_stream, parameters, verbose));
192 case(CBackendInformation::CB_SEQUENTIAL):
196 return CWriterRef(
new CWriter(hls_man, instruction_writer, indented_output_stream, parameters, verbose));
208 const auto function_behavior =
HLSMgr->CGetFunctionBehavior(funId);
209 const auto BH = function_behavior->CGetBehavioralHelper();
213 for(boost::tie(v, vEnd) = boost::vertices(*inGraph); v != vEnd; v++)
215 const auto& node = inGraph->CGetOpNodeInfo(*v)->node;
219 BH->GetTypecast(node, types);
220 for(
const auto& t : types)
251 boost::tie(statement, statement_end);
252 boost::tie(statement, statement_end) = boost::vertices(*op_graph);
253 vertices.insert(statement, statement_end);
272 #include <sys/types.h> 275 bool is_readc_needed =
false;
276 bool is_builtin_cond_expr32 =
false;
277 for(
auto extfun :
HLSMgr->get_functions_without_body())
282 is_readc_needed =
true;
286 is_builtin_cond_expr32 =
true;
293 "short int __bambu_readc(int fd){char buf[1];int res = read(fd,buf,1);return res > 0 ? buf[0] : -1;}\n");
295 "long long int __bambu_read4c(int fd){long long int buf;int res = read(fd,&buf,4);return res == 4 ? buf : " 296 "(res==3 ? (buf|(1ULL<<35)) : (res==2 ? (buf|(1ULL<<35)|(1ULL<<34)) : (res == 1 ? " 297 "(buf|(1ULL<<35)|(1ULL<<34)|(1ULL<<33)) : " 298 "(buf|(1ULL<<35)|(1ULL<<34)|(1ULL<<33)|(1ULL<<32))) ));}\n");
300 if(is_builtin_cond_expr32)
314 THROW_ASSERT(functions.size() > 0,
"at least one function is expected");
315 unsigned int first_fun = *functions.begin();
316 const auto BH =
HLSMgr->CGetFunctionBehavior(first_fun)->CGetBehavioralHelper();
318 const auto& gblVariables =
HLSMgr->GetGlobalVariables();
321 for(
const auto& glbVar : gblVariables)
326 if(
HLSMgr->CGetCallGraphManager()->ExistsAddressedFunction())
335 const auto FB =
HLSMgr->CGetFunctionBehavior(tn->
index);
336 const auto BH = FB->CGetBehavioralHelper();
342 for(
const auto& parameter_type : BH->GetParameterTypes())
364 for(boost::tie(v, vEnd) = boost::vertices(*inGraph); v != vEnd; v++)
366 const auto& vars_temp = inGraph->CGetOpNodeInfo(*v)->cited_variables;
367 vars.insert(vars_temp.begin(), vars_temp.end());
374 const auto FB =
HLSMgr->CGetFunctionBehavior(funId);
375 const auto BH = FB->CGetBehavioralHelper();
376 const auto funName = BH->get_function_name();
377 if(funName !=
"main")
389 const auto BH =
HLSMgr->CGetFunctionBehavior(function_id)->CGetBehavioralHelper();
392 for(
const auto& funParam : BH->GetParameters())
394 vars.erase(funParam->index);
397 for(
const auto& gblVariable :
HLSMgr->GetGlobalVariables())
399 vars.erase(gblVariable->index);
406 DeclareLocalVariables(vars, already_declared_variables, locally_declared_types, BH, variableFunctor);
434 const unsigned int bb_number = bb_node_info->block->number;
439 "current_vertex cannot be part of the basic block frontier");
464 const auto& bb_number_PD = bb_node_info_pd->block->number;
466 std::string frontier_string;
485 bool is_there =
false;
486 const auto& stmts_list = bb_node_info->statements_list;
487 for(
const auto st : boost::adaptors::reverse(stmts_list))
504 "This is basic block is not empty in this task. Last operation to be printed id " +
512 bool last_statement_is_a_cond_or_goto =
514 last_stmt == stmts_list.back();
516 THROW_ASSERT(!last_statement_is_a_cond_or_goto || !is_there ||
517 (last_statement_is_a_cond_or_goto && last_stmt == stmts_list.back()),
518 "inconsistent recursion");
521 if(start_with_a_label)
535 "Basic block has an indegree > 1 and not associated label");
537 for(boost::tie(inE, inEEnd) = boost::in_edges(current_vertex, *
local_rec_bb_fcfgGraph); inE != inEEnd; inE++)
542 if(pred_bb_node_info->statements_list.size() &&
547 "Basic block is the first case of a case preceded by a case without break");
555 "Basic block should start with a label since is the body of a short-circuit");
560 else if((!
bb_analyzed.count(source) || current_vertex == source) &&
561 (stmts_list.empty() ||
565 "Basic block is the header of a loop and it does not end with while or for");
571 add_bb_label = add_bb_label && !start_with_a_label;
572 bool add_semicolon =
false;
576 if(analyze_bb_PD || is_there || add_bb_label || add_phi_nodes_assignment || add_phi_nodes_assignment_prefix)
582 add_semicolon =
true;
590 add_semicolon =
true;
592 else if(start_with_a_label)
594 add_semicolon =
true;
598 std::list<vertex>::const_iterator vIter, vIterBegin;
599 vIter = stmts_list.begin();
604 "There are instructions to be printed for this pair task - basic block");
609 for(
const auto& rvt :
renaming_table.find(current_vertex)->second)
614 bool label_has_to_be_printed = start_with_a_label;
620 if(prefix_has_to_be_printed and not label_has_to_be_printed)
622 prefix_has_to_be_printed =
false;
631 label_has_to_be_printed =
false;
641 if(start_with_a_label && vIter == vIterBegin)
653 bool isLastIntruction = last_stmt == *vIter;
658 if(add_phi_nodes_assignment && isLastIntruction && print_phi_now)
672 add_semicolon =
false;
681 if(!isLastIntruction)
686 if(add_phi_nodes_assignment && !print_phi_now)
696 const unsigned int& bb_true_number = bb_node_info->block->true_edge;
697 THROW_ASSERT(bb_graph_info->bb_index_map.find(bb_true_number) != bb_graph_info->bb_index_map.end(),
698 "BB" +
STR(bb_true_number) +
" does not exist");
699 const vertex true_vertex = bb_graph_info->bb_index_map.find(bb_true_number)->second;
700 THROW_ASSERT(bb_graph_info->bb_index_map.find(bb_node_info->block->false_edge) !=
701 bb_graph_info->bb_index_map.end(),
702 "BB" +
STR(bb_node_info->block->false_edge) +
" does not exist");
703 vertex false_vertex = bb_graph_info->bb_index_map.find(bb_node_info->block->false_edge)->second;
704 bool add_false_to_goto =
false;
711 add_false_to_goto =
true;
720 "I do not know the destination");
729 if(add_false_to_goto)
737 false_vertex = bb_graph_info->bb_index_map.find(bb_node_info->block->false_edge)->second;
750 "I do not know the destination");
764 if(target_bb_node_info->statements_list.empty() or
771 "I do not know the destination");
781 const unsigned int& bb_true_number = bb_node_info->block->true_edge;
782 const vertex true_vertex = bb_graph_info->bb_index_map.find(bb_true_number)->second;
788 bb_node_info->block->number, true_vertex,
true);
792 THROW_ERROR(
"Body of a loop has yet been printed before the while statement");
800 const unsigned int bb_false_number = bb_node_info->block->false_edge;
801 const vertex false_vertex = bb_graph_info->bb_index_map.find(bb_false_number)->second;
821 auto* gmwi = GetPointer<gimple_multi_way_if>(node);
822 std::map<unsigned int, bool> add_elseif_to_goto;
823 for(
const auto& cond : gmwi->list_of_cond)
825 unsigned int bb_index_num = cond.second;
826 const vertex bb_vertex = bb_graph_info->bb_index_map.find(bb_index_num)->second;
827 if(cond != gmwi->list_of_cond.front())
831 add_elseif_to_goto[bb_index_num] = to_be_added;
839 add_elseif_to_goto[bb_index_num] =
false;
842 for(
const auto& cond : gmwi->list_of_cond)
844 unsigned int bb_index_num = cond.second;
845 const vertex bb_vertex = bb_graph_info->bb_index_map.find(bb_index_num)->second;
846 if(cond != gmwi->list_of_cond.front())
860 if(add_elseif_to_goto.find(bb_index_num) != add_elseif_to_goto.end() &&
861 add_elseif_to_goto.find(bb_index_num)->second)
876 "I do not know the destination " +
STR(bb_index_num));
896 bool empty_block =
false;
900 const unsigned int bb_number_next_bb = next_bb_node_info->block->number;
906 for(eIdBeg = Set.begin(), eIdEnd = Set.end(); eIdBeg != eIdEnd; ++eIdBeg)
918 analyze_bb_PD =
true;
950 const unsigned int next_bb_number = next_bb_node_info->block->number;
953 "I do not know the destination " +
STR(next_bb_number));
962 if(last_statement_is_a_cond_or_goto)
981 if(current_vertex == bbentry)
995 "Not adding goto since target is in the frontier");
1002 if(target_bb_node_info->statements_list.size() and
1007 "Not adding a goto since target is a while/for");
1018 const unsigned int next_bb_number = next_bb_node_info->block->number;
1020 "I do not know the destination");
1026 }
while(*vIter++ != last_stmt);
1032 if(add_phi_nodes_assignment)
1035 add_semicolon =
false;
1038 ((stmts_list.empty()) ||
1043 if(current_vertex == bbentry)
1050 "only one edge expected BB(" +
STR(bb_number) +
") Fun(" +
1053 for(boost::tie(oE, oEEnd) = boost::out_edges(current_vertex, *
local_rec_bb_fcfgGraph); oE != oEEnd; oE++)
1067 if(target_bb_node_info->statements_list.size() and
1077 const unsigned int next_bb_number = next_bb_node_info->block->number;
1079 "I do not know the destination");
1082 add_semicolon =
false;
1101 if((analyze_bb_PD || is_there || add_bb_label || add_phi_nodes_assignment || add_phi_nodes_assignment_prefix) &&
1118 for(
const auto instruction : instructions)
1122 phi_instructions.insert(cfgGraph->
CGetOpNodeInfo(instruction)->GetNodeId());
1125 if(!phi_instructions.empty())
1127 std::map<unsigned int, unsigned int> created_variables;
1128 std::map<unsigned int, std::string> symbol_table;
1129 std::map<unsigned int, std::deque<std::string>> array_of_stacks;
1131 phi_instructions, created_variables, symbol_table, array_of_stacks);
1133 if(!created_variables.empty())
1135 auto cv_it_end = created_variables.end();
1136 for(
auto cv_it = created_variables.begin(); cv_it != cv_it_end; ++cv_it)
1138 THROW_ASSERT(symbol_table.find(cv_it->first) != symbol_table.end(),
"variable not found in symbol_table");
1139 unsigned real_var = cv_it->second;
1143 false,
false, real_var, phi_functor));
1155 const auto function_behavior =
HLSMgr->CGetFunctionBehavior(function_index);
1156 const auto BH = function_behavior->CGetBehavioralHelper();
1159 if(instructions.empty())
1162 "<--CWriter::writeRoutineInstructions - instructions is an empty set");
1165 else if(instructions.size() == 1)
1170 "<--CWriter::writeRoutineInstructions - instructions is a set with only entry");
1183 bbentry = bb_fcfgGraph->CGetBBGraphInfo()->entry_vertex;
1192 bb_exit.insert(bb_fcfgGraph->CGetBBGraphInfo()->exit_vertex);
1201 for(boost::tie(vi, vi_end) = boost::vertices(*bb_fcfgGraph); vi != vi_end; vi++)
1203 size_t delta = bb_exit.count(*vi) ? 1u : 0u;
1204 if(boost::in_degree(*vi, *bb_fcfgGraph) <= (1 + delta))
1207 "---Skipped BB" +
STR(bb_fcfgGraph->CGetBBNodeInfo(*vi)->block->number));
1210 const auto bb_node_info = bb_fcfgGraph->CGetBBNodeInfo(*vi);
1211 const unsigned int le = BH->start_with_a_label(bb_node_info->block);
1213 (le ? BH->get_label_name(le) :
1214 (
"BB_LABEL_" +
STR(bb_node_info->block->number)) +
1217 "---Label of BB" +
STR(bb_fcfgGraph->CGetBBNodeInfo(*vi)->block->number) +
" is " +
1223 bb_analyzed.insert(bb_exit.begin(), bb_exit.end());
1228 bb_frontier.insert(bb_exit.begin(), bb_exit.end());
1241 if(!bb_start && bb_end.size() == 0)
1244 for(boost::tie(oE, oEEnd) = boost::out_edges(bbentry, *bb_fcfgGraph); oE != oEEnd; oE++)
1259 std::inserter(not_yet_considered, not_yet_considered.begin()) );
1260 while(!not_yet_considered.empty())
1262 vertex next_bb = *not_yet_considered.begin();
1263 not_yet_considered.erase(next_bb);
1265 not_yet_considered.clear();
1268 std::inserter(not_yet_considered, not_yet_considered.begin()) );
1270 const auto& exit = bb_fcfgGraph->CGetBBGraphInfo()->exit_vertex;
1285 const auto without_transformation =
Param->getOption<
bool>(OPT_without_transformation);
1297 locally_declared_types.insert(type_name);
1303 "<--Type has not to be declared since it is declared in included " + decl);
1306 const auto types_to_be_declared_before =
1308 for(
const auto& type_to_be_declared : types_to_be_declared_before)
1310 DeclareType(type_to_be_declared, BH, locally_declared_types);
1320 const auto types_to_be_declared_after =
1322 for(
const auto& type_to_be_declared : types_to_be_declared_after)
1324 DeclareType(type_to_be_declared, BH, locally_declared_types);
1334 if(already_declared_variables.count(curVar->
index))
1339 already_declared_variables.insert(curVar->
index);
1344 for(
const auto initVar : initVars)
1347 "For variable " +
STR(curVar) +
" recursing on " +
STR(initVar));
1348 if(!already_declared_variables.count(initVar) && !
globallyDeclVars.count(initVar))
1357 DeclareType(variable_type, BH, locally_declared_types);
1399 const auto TreeMan =
TM;
1400 const auto is_to_declare = [&p, &TreeMan](
unsigned int obj) ->
bool {
1401 if(std::find(p.cbegin(), p.cend(), obj) != p.cend())
1405 const tree_nodeRef node = TreeMan->get_tree_node_const(obj);
1406 if(node->
get_kind() == parm_decl_K)
1410 auto* sa = GetPointer<ssa_name>(node);
1411 if(sa && (sa->volatile_flag || (
GET_NODE(sa->CGetDefStmt())->get_kind() == gimple_nop_K)) && sa->var &&
1412 (
GET_NODE(sa->var)->get_kind() == parm_decl_K))
1421 for(
const auto var : to_be_declared)
1423 if(is_to_declare(var))
1433 for(boost::tie(v, vEnd) = boost::vertices(*data); v != vEnd; v++)
1435 vertices.insert(*v);
1444 std::map<unsigned int, unsigned int>& created_variables,
1445 std::map<unsigned int, std::string>& symbol_table,
1446 std::map<
unsigned int, std::deque<std::string>>& array_of_stacks)
1448 std::list<unsigned int> pushed;
1450 for(
const auto& aos : array_of_stacks)
1452 if(!aos.second.empty())
1455 symbol_table[aos.first] = aos.second.back();
1458 schedule_copies(b, bb_domGraph, bb_fcfgGraph, variableFunctor, phi_instructions, created_variables, symbol_table,
1459 pushed, array_of_stacks);
1461 for(boost::tie(oi, oend) = boost::out_edges(b, *bb_domGraph); oi != oend; ++oi)
1464 insert_copies(c, bb_domGraph, bb_fcfgGraph, variableFunctor, phi_instructions, created_variables, symbol_table,
1472 std::map<unsigned int, unsigned int>& created_variables,
1473 std::map<unsigned int, std::string>& symbol_table, std::list<unsigned int>& pushed,
1474 std::map<
unsigned int, std::deque<std::string>>& array_of_stacks)
1478 unsigned int bi_id = bb_node_info->block->number;
1481 std::map<unsigned int, unsigned int>
map;
1483 std::map<unsigned int, unsigned int> bb_dest_definition;
1485 for(boost::tie(oi, oend) = boost::out_edges(b, *bb_fcfgGraph); oi != oend; ++oi)
1489 for(
const auto& phi_op : si->block->CGetPhiList())
1491 if(phi_instructions.find(
GET_INDEX_NODE(phi_op)) == phi_instructions.end())
1495 auto* pn = GetPointer<gimple_phi>(
GET_NODE(phi_op));
1498 bool is_virtual = pn->virtual_flag;
1501 bb_dest_definition[dest_i] = si->block->number;
1502 for(
const auto& def_edge : pn->CGetDefEdgesList())
1504 if(def_edge.second == bi_id)
1508 copy_set.insert(std::pair<tree_nodeRef, tree_nodeRef>(src, dest));
1510 map[dest_i] = dest_i;
1511 used_by_another.insert(src_i);
1520 for(
auto cs_it = copy_set.begin(); cs_it != copy_set.end();)
1522 auto current_it = cs_it;
1524 if(used_by_another.find(
GET_INDEX_NODE(current_it->second)) == used_by_another.end())
1526 worklist.insert(*current_it);
1527 copy_set.erase(current_it);
1532 while(!worklist.empty() || !copy_set.empty())
1537 for(
auto& wl : worklist)
1548 bool add_copy =
false;
1550 for(boost::tie(o_it, o_it_end) = boost::out_edges(b, *bb_domGraph); o_it != o_it_end; ++o_it)
1558 if(tgt_bi && tgt_bi->block->live_in.find(dest_i) != tgt_bi->block->live_in.end())
1569 symbol_table.find(t_i)->second +
" = " + (*variableFunctor)(dest_i) +
";\n";
1570 created_variables[t_i] = dest_i;
1573 push_stack(symbol_table.find(t_i)->second, dest_i, pushed, array_of_stacks);
1577 std::string copy_statement;
1578 if(symbol_table.find(map.find(src_i)->second) != symbol_table.end())
1581 (*variableFunctor)(dest_i) +
" = " + symbol_table.find(map.find(src_i)->second)->second +
";\n";
1583 else if(dest_i != map.find(src_i)->second)
1586 (*variableFunctor)(dest_i) +
" = " + (*variableFunctor)(map.find(src_i)->second) +
";\n";
1592 for(
auto cs1_it = copy_set.begin(); cs1_it != copy_set.end();)
1594 auto current1_it = cs1_it;
1596 if(src == current1_it->second)
1598 worklist_restart.insert(*current1_it);
1599 copy_set.erase(current1_it);
1603 worklist = worklist_restart;
1604 worklist_restart.clear();
1605 }
while(!worklist.empty());
1607 auto cs2_it_end = copy_set.end();
1608 auto cs2_it = copy_set.begin();
1609 if(cs2_it != cs2_it_end)
1611 auto current2_it = cs2_it;
1616 bool add_temporary =
false;
1617 for(; cs2_it != cs2_it_end; ++cs2_it)
1621 add_temporary =
true;
1630 basic_block_tail[bi_id] += symbol_table.find(t_i)->second +
" = " + (*variableFunctor)(dest_i) +
";\n";
1631 created_variables[t_i] = dest_i;
1635 worklist.insert(*current2_it);
1636 copy_set.erase(current2_it);
1644 unsigned int node_id_this = 0;
1645 std::string new_name;
1651 }
while(node_id_this > 0);
1655 return node_id_this;
1659 std::map<
unsigned int, std::deque<std::string>>& array_of_stacks)
1661 THROW_ASSERT(std::find(pushed.begin(), pushed.end(), dest_i) == pushed.end(),
"multiple push is not allowed");
1662 array_of_stacks[dest_i].push_back(symbol_name);
1663 pushed.push_back(dest_i);
1667 std::map<
unsigned int, std::deque<std::string>>& array_of_stacks)
1669 for(
auto var_id : pushed)
1671 THROW_ASSERT(array_of_stacks.find(var_id) != array_of_stacks.end(),
"the array of stacks is inconsistent");
1672 THROW_ASSERT(!array_of_stacks.find(var_id)->second.empty(),
"the variable is not mapped");
1673 array_of_stacks.find(var_id)->second.pop_back();
1825 "int st_gen_int(st_generator *gen, unsigned long long * key_p, unsigned long long * value_p)\n");
1860 "int st_find_or_add(st_table *table, unsigned long long key, unsigned long long ** slot)\n");
1910 "st_gen_int(gen,key,value) || (st_free_gen(gen),0);)\n");
1929 for(
const unsigned int id :
HLSMgr->CGetCallGraphManager()->GetAddressedFunctions())
1931 const auto BH =
HLSMgr->CGetFunctionBehavior(
id)->CGetBehavioralHelper();
1934 std::vector<std::pair<std::string, std::string>> typeAndName;
1935 for(
const auto& I : BH->GetParameters())
1951 type =
"unsigned int";
1961 const auto name = BH->PrintVariable(I->index);
1962 typeAndName.push_back(std::make_pair(
type, name));
1964 for(
const auto& I : typeAndName)
1969 std::string returnType;
1976 if(returnType_size < 32)
1983 if(returnType_size < 32)
1985 returnType =
"unsigned int";
1990 if(returnType_size < 64)
1992 returnType =
"double";
1998 returnType =
"void";
2000 if(returnType !=
"void")
2005 const auto typeAndNameSize = typeAndName.size();
2008 for(
size_t i = 0; i < typeAndNameSize - 1; ++i)
2015 if(returnType !=
"void")
#define GET_NODE(t)
Macro used to hide implementation details when accessing a tree_node from another tree_node...
OpGraphConstRef local_rec_cfgGraph
#define TYPE_SWITCH
constant identifying the node type of a SWITCH operation.
std::string PrintVarDeclaration(unsigned int var, const var_pp_functorConstRef vppf, bool init_has_to_be_printed) const
This function prints the declaration of a variable without the closing ";".
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
int GetSelector() const
Return the selector of this graph.
Vertex get_immediate_dominator(Vertex v) const
Return the immediate dominator of a Vertex.
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.
boost::graph_traits< graph >::out_edge_iterator OutEdgeIterator
out_edge_iterator definition.
#define GET_TYPE(data, vertex_index)
Helper macro returning the type associated with a node.
const dominance< BBGraph > * dominators
CustomOrderedSet< vertex > goto_list
void WriteFile(const std::string &file_name)
Write the indented output on a file.
static void clear_renaming_table()
remove all the entries from the renaming table
#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.
#define TYPE_MULTIIF
constant identifying the a multi-way if
#define TYPE_VPHI
constant string identifying an operation node of type virtual phi-nodes
const tree_nodeRef CGetTreeReindex(const unsigned int i) const
Return a tree_reindex wrapping the i-th tree_node.
std::string get_function_name() const
Return the name of the function.
virtual unsigned int end_with_a_cond_or_goto(const blocRef &block) const
Return the nodeID of the last statement of a basic block in case that statement is a cond or a goto e...
int debug_level
the debug level
#define TYPE_IF
constant identifying the node type of an IF operation.
Definition of the class representing a generic C application.
const dominance< BBGraph > * post_dominators
virtual void Initialize()
Initialize data structure.
static std::string print_type(const tree_managerConstRef &TM, unsigned int type, bool global=false, bool print_qualifiers=false, bool print_storage=false, unsigned int var=0, const var_pp_functorConstRef &vppf=var_pp_functorConstRef(), const std::string &prefix="", const std::string &tail="")
Print a type and its variable in case var is not zero.
const CustomSet< unsigned int > GetLocalVariables(const unsigned int function_id) const
Compute the local variables of a function.
const BBGraphInfoConstRef CGetBBGraphInfo() const
Returns the property associated with the graph.
CustomOrderedSet< vertex > bb_frontier
virtual void WriteBBHeader(const unsigned int bb_number, const unsigned int function_index)
void WriteHashTableImplementation()
Write the implementation of a hash table with long long int as key and long long int as value...
#define GET_NAME(data, vertex_index)
Helper macro returning the name associated with a node.
unsigned int get_next_available_tree_node_id() const
return the next available tree node id.
CustomSet< unsigned int > globallyDeclVars
boost::graph_traits< graph >::in_edge_iterator InEdgeIterator
in_edge_iterator definition.
unsigned int get_function_index() const
Return the index of the function.
Class to print indented code.
Simple class to print single instruction.
#define BUILTIN_WAIT_CALL
constant defining the builtin wait call intrinsic function
Definition of hash function for EdgeDescriptor.
static const unsigned int EXIT_BLOCK_ID
constant identifying the exit basic block
bool verbose
Verbosity means that a comment is printed for each line in the output file.
#define GET_INDEX_NODE(t)
Macro used to hide implementation details when accessing a tree_node from another tree_node...
#define TYPE_INIT
Constant string identifying an operation that is a variable initialization.
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
Simple class to print single instruction.
const tree_managerConstRef TM
The tree manager.
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
Data structure describing a basic block at tree level.
static unsigned int get_type_index(const tree_managerConstRef &TM, const unsigned int index, long long int &vec_size, bool &is_a_pointer, bool &is_a_function)
Return the treenode index of the type of index.
dominance< BBGraph > * post_dominators
This class stores post-dominator information.
A set of operation vertices.
static bool IsInLibbambu(const tree_managerConstRef &TM, const unsigned int index)
Return true if the decl node or type is in libbambu.
virtual void WriteFunctionDeclaration(const unsigned int funId)
Writes the declaration of the function whose id in the tree is funId.
#define TYPE_PHI
constant string identifying an operation node of type PHI
virtual enum kind get_kind() const =0
Virtual function returning the type of the actual class.
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.
#define FB_CFG_SELECTOR
Feedback control flow edge selector.
virtual std::string PrintConstant(const tree_nodeConstRef &var, const var_pp_functorConstRef vppf=var_pp_functorConstRef()) const
Print the constant associated with var.
std::string ToString(ActorGraphBackend_Type actor_graph_backend_type)
Header include.
refcount< CWriter > CWriterRef
static bool HasToBeDeclared(const tree_managerConstRef &TM, const tree_nodeConstRef &type)
Return true if the type has to be declared.
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.
virtual void WriteFile(const std::string &file_name)
Writes the final C file.
static bool IsUnsignedIntegerType(const tree_nodeConstRef &type)
Return true if the treenode is of unsigned integer type.
const tree_nodeRef get_tree_node_const(unsigned int i) const
Return the reference to the i-th tree_node Constant version of get_tree_node.
#define TYPE_LABEL
A vertex is of type TYPE_LABEL when it is a target of a goto expression.
static bool IsSignedIntegerType(const tree_nodeConstRef &type)
Return true if the treenode is of integer type.
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
const BBEdgeInfoConstRef CGetBBEdgeInfo(const EdgeDescriptor e) const
Returns the info associated with an edge.
const IndentedOutputStreamRef indented_output_stream
Represents the stream we are currently writing to.
Standard functor that returns the name of a variable.
const std::list< unsigned int > get_parameters() const
Return the list of index of original parameters of the function.
static unsigned long long Size(const tree_nodeConstRef &tn)
Return the size of a tree object.
std::set< Key, Compare, Alloc > OrderedSetStd
virtual void EndFunctionBody(unsigned int funId)
Writes the code necessary to close a function (this function was a function also present in the origi...
static bool IsSystemType(const tree_nodeConstRef &type)
Return true if variable or type is a system one.
unsigned map[NUM_VERTICES]
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.
const ParameterConstRef Param
set of parameters
virtual unsigned int GetInit(unsigned int var, CustomUnorderedSet< unsigned int > &list_of_variables) const
return the initialization object associated with the variable.
Class use to write the C code with instruented edges for basic blocks profiling.
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.
Basic block dominator tree.
#define default_COND
constant used to represent label "default" of a switch construct
virtual void StartFunctionBody(const unsigned int function_id)
Writes the body of the function to the specified stream.
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...
void compute_phi_nodes(const FunctionBehaviorConstRef function_behavior, const OpVertexSet &instructions, var_pp_functorConstRef variableFunctor)
Determines the instructions coming out from phi-node splitting.
CustomSet< std::string > globally_declared_types
This set contains the list of the non built_in types already declared in the global scope...
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...
Basic block control flow graph with feedback.
virtual int unsigned start_with_a_label(const blocRef &block) const
Return the nodeID of the first statement of a basic block in case that statement is a label expressio...
static void rename_a_variable(unsigned int var, const std::string &new_name)
rename a variable
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Abstract class to write an actor graphs.
CWriter(const HLS_managerConstRef _HLSMgr, const InstructionWriterRef instruction_writer, const IndentedOutputStreamRef indented_output_stream, const ParameterConstRef Param, bool verbose=true)
Constructor of the class.
This file contains the routines necessary to create a C executable program with instrumented edges fo...
#define TYPE_FOR
constant string identifying the node type of an WHILE operation.
#define GET_CONST_NODE(t)
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 dec...
CustomOrderedSet< std::string > writtenIncludes
const BehavioralHelperConstRef CGetBehavioralHelper() const
Returns the helper associated with the function.
boost::graph_traits< graph >::vertex_iterator VertexIterator
vertex_iterator definition.
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: ...
virtual void WriteBodyLoop(const unsigned int function_index, const unsigned int, vertex current_vertex, bool bracket)
Write the instructions belonging to a body loop.
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
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.
std::string PrintVariable(unsigned int var) const
Print the name of the variable associated to the index.
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.
This file collects some utility functions.
static unsigned int GetRealType(const tree_managerConstRef &TM, unsigned int index)
Return the real type.
virtual void DeclareFunctionTypes(const tree_nodeConstRef &tn)
Declares the types of the parameters of a function.
dominance< BBGraph > * dominators
This class stores dominator information.
const HLS_managerConstRef HLSMgr
the hls manager
virtual void WriteHeader()
Writes the header of the file.
unsigned int create_new_identifier(std::map< unsigned int, std::string > &symbol_table)
create an identifier for the temporaries created by phi node destruction
std::map< unsigned int, std::string > basic_blocks_labels
virtual void declare_cast_types(unsigned int funId, CustomSet< std::string > &locally_declared_types)
Declare all the types used in conversions.
size_t bb_label_counter
Counter of the invocations of writeRoutineInstructions; this counter allows to print different labels...
CustomOrderedSet< vertex > bb_analyzed
static InstructionWriterRef CreateInstructionWriter(const ActorGraphBackend_Type actor_graph_backend_type, const application_managerConstRef AppM, const IndentedOutputStreamRef indented_output_stream, const ParameterConstRef parameters)
Factory method.
struct definition of the type node structures.
Class specification of the tree_reindex support class.
FunctionBehaviorConstRef local_rec_function_behavior
const OpGraphConstRef CGetOpGraph(FunctionBehavior::graph_type gt) const
This method returns the operation graphs.
Class specification of the basic_block structure.
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 dec...
unsigned int find_identifier_nodeID(const std::string &str) const
Return the nodeID of the identifier_node representing string str.
static std::string PrintType(const tree_managerConstRef &TM, const tree_nodeConstRef &type, bool global=false, bool print_qualifiers=false, bool print_storage=false, const tree_nodeConstRef &var=nullptr, const var_pp_functorConstRef &vppf=var_pp_functorConstRef(), const std::string &prefix="", const std::string &tail="")
Print a type and its variable in case var is not zero.
virtual void WriteFunctionBody(const unsigned int function_id)
Writes the body of a function.
const BBNodeInfoConstRef CGetBBNodeInfo(const vertex node) const
Return the info associated with a basic block.
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.
const BBGraphConstRef CGetBBGraph(FunctionBehavior::bb_graph_type gt=FunctionBehavior::BB) const
This method returns the basic block graphs.
const LoopsConstRef CGetLoops() const
Return the loops.
#define TYPE_WHILE
constant string identifying the node type of an WHILE operation.
interface of loops finding algorithm
virtual void WriteBuiltinWaitCall()
Writes implementation of __builtin_wait_call.
Classes specification of the tree_node data structures not present in the gcc.
std::map< unsigned int, std::string > basic_block_prefix
string to be printed at the beginning of a given basic block
this class is used to manage the command-line or XML options.
virtual void writeInclude(const std::string &file_name)
Writes an include directive.
std::vector< std::string > additionalIncludes
virtual void WriteGlobalDeclarations()
Writes the global declarations.
This file contains the routines necessary to create a C executable program.
unsigned int fake_max_tree_node_id
#define TYPE_ENTRY
constant identifying the node type of an entry node.
bool operator()(const std::pair< tree_nodeRef, tree_nodeRef > &x, const std::pair< tree_nodeRef, tree_nodeRef > &y) const
Compare position of two const tree nodes.
Control flow graph with feedback.
unsigned counter[N_THREADS]
#define DOALL_LOOP
parallelizable for loop
x
Return the smallest n such that 2^n >= _x.
specialization of the instruction writer for the discrepancy analysis
std::map< vertex, std::map< unsigned int, std::string > > renaming_table
renaming table used by phi node destruction procedure
refcount< var_pp_functor > var_pp_functorRef
virtual std::string print_type_declaration(unsigned int type) const
Print the declaration of a non built-in type.
const InstructionWriterRef getInstructionWriter() const
Returns the instruction writer.
BBGraphConstRef local_rec_bb_fcfgGraph
static std::string GetTypeName(const tree_nodeConstRef &type)
Return name of the type.
#define CFG_SELECTOR
Control flow graph edge selector.
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...
static tree_nodeConstRef GetFunctionReturnType(const tree_nodeConstRef &function, bool void_as_null=true)
Return the return type of a function.
BehavioralHelperConstRef local_rec_behavioral_helper
var_pp_functorConstRef local_rec_variableFunctor
#define NULL_VERTEX
null vertex definition
Class specification of the manager of the tree structures extracted from the raw file.
virtual void WriteFunctionImplementation(unsigned int function_id)
Write function implementation.
virtual void writePostInstructionInfo(const FunctionBehaviorConstRef, const vertex)
Write additional information on the given statement vertex, after the statements itself.
A brief description of the C++ Header File.
CustomOrderedSet< vertex > local_rec_instructions
static bool IsRealType(const tree_nodeConstRef &type)
Return true if the treenode is of real type.
virtual void writePreInstructionInfo(const FunctionBehaviorConstRef, const vertex)
Write additional information on the given statement vertex, before the statement itself.
std::map< unsigned int, std::string > basic_block_tail
string to be printed at the end of a given basic block
const InstructionWriterRef instrWriter
Contains the class used to write instructions.
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...