46 #include "config_HAVE_HEXFLOAT.hpp" 48 #include "config_NPROFILE.hpp" 90 removed_pointer_plus(0),
91 removable_pointer_plus(0),
92 unremoved_pointer_plus(0),
97 collapse_into_counter(0)
106 "Node " +
STR(decl_node) +
131 THROW_ASSERT(index > 0,
"Expected a positive index (" +
STR(index) +
")");
141 THROW_ASSERT(i > 0 and i <
last_node_id,
"(C) Expected a positive index less than the total number of tree nodes (" +
155 THROW_ASSERT(i > 0 and i <
last_node_id,
"(C) Expected a positive index less than the total number of tree nodes (" +
164 THROW_ASSERT(i > 0 and i <
last_node_id,
"(C) Expected a positive index less than the total number of tree nodes (" +
186 return tn ? tn->index : 0;
195 const auto& curr_tn = function_decl_node.second;
196 const auto fd = GetPointerS<const function_decl>(curr_tn);
198 std::string simple_name, mangled_name;
199 if(id_name->get_kind() == identifier_node_K)
201 const auto in = GetPointerS<const identifier_node>(id_name);
202 if(!in->operator_flag)
204 simple_name = in->strg;
210 if(mangled_id_name->
get_kind() == identifier_node_K)
212 auto* in = GetPointer<identifier_node>(mangled_id_name);
213 if(!in->operator_flag)
215 mangled_name = in->strg;
219 const auto name = [&]() {
224 if(!demangled_name.empty())
226 return demangled_name.substr(0, demangled_name.find(
'('));
231 if(name == function_name || function_name == std::string(
"-") ||
232 (!simple_name.empty() && function_name == simple_name) ||
233 (!mangled_name.empty() && mangled_name == function_name))
245 unsigned int function_id = 0;
249 auto* fd = GetPointer<function_decl>(curr_tn);
251 std::string simple_name, mangled_name;
252 if(id_name->get_kind() == identifier_node_K)
254 auto* in = GetPointer<identifier_node>(id_name);
255 if(!in->operator_flag)
257 simple_name = in->strg;
263 if(mangled_id_name->
get_kind() == identifier_node_K)
265 auto* in = GetPointer<identifier_node>(mangled_id_name);
266 if(!in->operator_flag)
268 mangled_name = in->strg;
273 if(name == function_name || function_name == std::string(
"-") ||
274 (!simple_name.empty() && function_name == simple_name) ||
275 (!mangled_name.empty() && mangled_name == function_name))
277 function_id = function_decl_node.first;
289 unsigned int node_index = 0;
290 for(node_index = 0; node_index <=
last_node_id; node_index++)
294 os <<
"@" <<
tree_nodes.find(node_index)->first <<
" ";
295 tree_nodes.find(node_index)->second->visit(&RW);
307 if(GetPointer<function_decl>(id_func.second)->body)
309 id_func.second->visit(&gimple_writer);
315 std::map<TreeVocabularyTokenTypes_TokenEnum, std::string>& tree_node_schema)
351 const std::map<TreeVocabularyTokenTypes_TokenEnum, std::string>& tree_node_schema)
353 if(tree_node_type == identifier_node_K)
356 if(tree_node_schema.find(
TOK(
TOK_STRG)) != tree_node_schema.end())
360 else if(tree_node_schema.find(
TOK(
TOK_OPERATOR)) != tree_node_schema.end())
366 THROW_ERROR(
"Incorrect schema for identifier_node: no TOK_STRG nor TOK_OPERATOR");
371 const auto tns_end = tree_node_schema.end();
372 for(
auto tns = tree_node_schema.begin(); tns != tns_end; ++tns)
374 key +=
";" +
STOK2(tns->first) +
"=" + tns->second;
385 unsigned int node_id = ti.first;
392 if(ti.second->get_kind() == tree_node_type and TNF.
check(ti.second))
409 "-->Collapsing into " +
STR(tree_node_index) +
" (" + std::string(
GET_NODE(tn)->get_kind_text()) +
414 const std::string gimple_file_name =
Param->getOption<std::string>(OPT_output_temporary_directory) +
418 std::ofstream gimple_file(gimple_file_name.c_str());
426 case gimple_assign_K:
428 stack.push_front(tn);
429 auto* gm = GetPointer<gimple_assign>(curr_tn);
433 if(
GET_NODE(gm->op1)->get_kind() != nop_expr_K ||
435 GetPointer<nop_expr>(
GET_NODE(gm->op1))->type))
437 collapse_into(funID, stmt_to_bloc, gm->op1, removed_nodes, AppM);
444 stack.push_front(tn);
445 auto* gc = GetPointer<gimple_cond>(curr_tn);
446 collapse_into(funID, stmt_to_bloc, gc->op0, removed_nodes, AppM);
453 auto* ue = GetPointer<unary_expr>(curr_tn);
454 collapse_into(funID, stmt_to_bloc, ue->op, removed_nodes, AppM);
459 auto* be = GetPointer<binary_expr>(curr_tn);
460 collapse_into(funID, stmt_to_bloc, be->op0, removed_nodes, AppM);
461 collapse_into(funID, stmt_to_bloc, be->op1, removed_nodes, AppM);
465 case gimple_switch_K:
467 auto* se = GetPointer<gimple_switch>(curr_tn);
468 collapse_into(funID, stmt_to_bloc, se->op0, removed_nodes, AppM);
473 auto* te = GetPointer<ternary_expr>(curr_tn);
474 collapse_into(funID, stmt_to_bloc, te->op0, removed_nodes, AppM);
475 collapse_into(funID, stmt_to_bloc, te->op1, removed_nodes, AppM);
478 collapse_into(funID, stmt_to_bloc, te->op2, removed_nodes, AppM);
484 auto* qe = GetPointer<quaternary_expr>(curr_tn);
485 collapse_into(funID, stmt_to_bloc, qe->op0, removed_nodes, AppM);
486 collapse_into(funID, stmt_to_bloc, qe->op1, removed_nodes, AppM);
489 collapse_into(funID, stmt_to_bloc, qe->op2, removed_nodes, AppM);
493 collapse_into(funID, stmt_to_bloc, qe->op3, removed_nodes, AppM);
499 auto* le = GetPointer<lut_expr>(curr_tn);
500 collapse_into(funID, stmt_to_bloc, le->op0, removed_nodes, AppM);
501 collapse_into(funID, stmt_to_bloc, le->op1, removed_nodes, AppM);
504 collapse_into(funID, stmt_to_bloc, le->op2, removed_nodes, AppM);
508 collapse_into(funID, stmt_to_bloc, le->op3, removed_nodes, AppM);
512 collapse_into(funID, stmt_to_bloc, le->op4, removed_nodes, AppM);
516 collapse_into(funID, stmt_to_bloc, le->op5, removed_nodes, AppM);
520 collapse_into(funID, stmt_to_bloc, le->op6, removed_nodes, AppM);
524 collapse_into(funID, stmt_to_bloc, le->op7, removed_nodes, AppM);
528 collapse_into(funID, stmt_to_bloc, le->op8, removed_nodes, AppM);
546 case target_mem_ref_K:
547 case target_mem_ref461_K:
549 case gimple_multi_way_if_K:
550 case function_decl_K:
556 auto* sn = GetPointer<ssa_name>(curr_tn);
558 if(sn->CGetDefStmts().size() == 1)
560 auto* gm = GetPointer<gimple_assign>(
GET_NODE(sn->CGetDefStmt()));
562 if((!gm and
GET_NODE(sn->CGetDefStmt())->get_kind() == gimple_asm_K) ||
563 (!gm and
GET_NODE(sn->CGetDefStmt())->get_kind() == nop_expr_K) ||
564 (!gm and
GET_NODE(sn->CGetDefStmt())->get_kind() == gimple_nop_K))
570 THROW_ERROR(
"unexpected statement " + sn->CGetDefStmt()->ToString());
575 "---The gimple assignment where ssa name is defined has virtual def");
581 if(
GET_NODE(gm->op1)->get_kind() == nop_expr_K &&
583 GetPointer<nop_expr>(
GET_NODE(gm->op1))->type))
586 "---The gimple assignment where ssa name is defined has a non-builtin nop_expr");
595 collapse_into(funID, stmt_to_bloc, sn->CGetDefStmt(), removed_nodes, AppM);
597 " not defined in a gimple modify stmt, nor in gimple_asm, nor in a nop_expr");
602 std::string(
GET_NODE(sn->CGetDefStmt())->get_kind_text()) +
")");
606 for(
const auto& use : sn->CGetUseStmts())
613 auto* fd = GetPointer<function_decl>(temp);
614 auto*
sl = GetPointer<statement_list>(
GET_NODE(fd->body));
615 const std::map<unsigned int, blocRef>& list_of_bloc = sl->list_of_bloc;
618 THROW_ASSERT(stmt_to_bloc.find((*(
stack.rbegin()))->index) != stmt_to_bloc.end(),
619 "BB of statement " +
STR((*(
stack.begin()))->index) +
" not found");
620 THROW_ASSERT(list_of_bloc.find(stmt_to_bloc.find((*(
stack.begin()))->index)->second) != list_of_bloc.end(),
621 "BB of statement not found");
622 blocRef curr_block = list_of_bloc.find(stmt_to_bloc.find((*(
stack.begin()))->index)->second)->second;
624 unsigned int curr_block_index;
627 std::deque<tree_nodeRef>::iterator stack_it;
628 for(stack_it =
stack.begin(); stack_it !=
stack.end(); stack_it++)
630 if(
GET_NODE(*stack_it)->get_kind() == gimple_cond_K)
632 curr_block_index = (stmt_to_bloc.find(
GET_INDEX_NODE(*stack_it)))->second;
633 curr_block = list_of_bloc.find(curr_block_index)->second;
635 "---Found gimple_cond in block: " +
640 THROW_ASSERT(curr_block,
"Conditional expression not found in stack");
646 "Statement not found in stmt_to_bloc map: " +
STR(
GET_INDEX_NODE(sn->CGetDefStmt())));
647 const blocRef def_block =
648 list_of_bloc.find((stmt_to_bloc.find(
GET_INDEX_NODE(sn->CGetDefStmt())))->second)->second;
653 if(sn->CGetNumberUses() != 1)
658 if(
GET_NODE(gm->op1)->get_kind() != ssa_name_K and
GET_NODE(gm->op1)->get_kind() != var_decl_K)
668 bool in_between =
false;
669 bool memdef_found =
false;
670 for(
const auto& stmt : curr_block->CGetStmtList())
672 if(in_between and
GET_NODE(stmt)->get_kind() == gimple_assign_K)
674 auto* gms = GetPointer<gimple_assign>(
GET_NODE(stmt));
693 "---None of uses of current ssa contains virtual defs so continuing in collapsing");
696 if(curr_block == def_block)
700 for(
auto const& use : sn->CGetUseStmts())
702 THROW_ASSERT(stmt_to_bloc.find(use.first->index) != stmt_to_bloc.end(),
703 STR(use.first->index) +
" is not in stmt_to_bloc");
704 unsigned int copy_block_index = (stmt_to_bloc.find(use.first->index))->second;
705 copy_bloc_to_stmt[copy_block_index].push_back(use.first);
707 "ssa_name is used in operation " +
STR(use.first->index) +
" of BB" +
708 STR(copy_block_index));
712 for(
auto& copy_block_it : copy_bloc_to_stmt)
714 const blocRef copy_block = list_of_bloc.find(copy_block_it.first)->second;
715 std::vector<tree_nodeRef> copy_block_use_stmts = copy_block_it.second;
717 if(copy_block != curr_block)
721 STR(copy_block_it.first) +
" (!= " +
725 std::map<TreeVocabularyTokenTypes_TokenEnum, std::string> IR_schema;
740 auto* new_sn = GetPointer<ssa_name>(
GET_NODE(tree_reindexRef_sn));
741 for(
const auto& use_stmt : sn->CGetUseStmts())
743 for(decltype(use_stmt.second) repetition = 0; repetition < use_stmt.second; repetition++)
745 new_sn->AddUseStmt(use_stmt.first);
750 for(
auto& copy_block_use_stmt : copy_block_use_stmts)
754 new_sn->AddUseStmt(copy_block_use_stmt);
768 if(GetPointer<const ssa_name>(
GET_NODE(gm->op1)))
770 auto* sn_right = GetPointer<ssa_name>(
GET_NODE(gm->op1));
771 sn_right->AddUseStmt(tree_reindexRef_gm);
774 auto* new_gm = GetPointer<gimple_assign>(
GET_NODE(tree_reindexRef_gm));
775 new_gm->memuse = gm->memuse;
776 new_gm->memdef = gm->memdef;
777 new_gm->vuses = gm->vuses;
778 new_gm->vdef = gm->vdef;
779 new_gm->vovers = gm->vovers;
782 for(
const auto& copy_block_stmt : copy_block->CGetStmtList())
784 if(
GET_NODE(copy_block_stmt)->get_kind() != gimple_label_K)
786 copy_block->PushBefore(tree_reindexRef_gm, copy_block_stmt, AppM);
791 stmt_to_bloc[
GET_INDEX_NODE(tree_reindexRef_gm)] = copy_block_it.first;
809 if(
GET_NODE(top)->get_kind() == gimple_cond_K)
811 auto* gc = GetPointer<gimple_cond>(
GET_NODE(top));
812 gc->memuse = gm->memuse;
813 gc->vuses = gm->vuses;
814 gc->vovers = gm->vovers;
816 else if(
GET_NODE(top)->get_kind() == gimple_assign_K)
818 auto* top_gm = GetPointer<gimple_assign>(
GET_NODE(top));
819 top_gm->memuse = gm->memuse;
820 top_gm->vuses = gm->vuses;
821 top_gm->vovers = gm->vovers;
825 THROW_ERROR(
"Unsupported type of tree node during collapsing");
832 if(def_block == curr_block)
834 for(
const auto& use : sn->CGetUseStmts())
837 THROW_ASSERT(stmt_to_bloc.find(use.first->index) != stmt_to_bloc.end(),
838 "Statement not found in stmt_to_bloc map: " +
STR(use.first->index));
839 unsigned int use_block_index = (stmt_to_bloc.find(use.first->index))->second;
841 const blocRef use_block = list_of_bloc.find(use_block_index)->second;
842 if(use_block == curr_block)
844 auto statement = use.first;
855 for(
const auto& stmt : curr_block->CGetStmtList())
862 curr_block->RemoveStmt(stmt, AppM);
876 case aggr_init_expr_K:
878 auto* ce = GetPointer<call_expr>(curr_tn);
879 const std::vector<tree_nodeRef>&
args = ce->args;
880 std::vector<tree_nodeRef>::const_iterator
arg, arg_end = args.end();
881 for(arg = args.begin(); arg != arg_end; ++
arg)
883 collapse_into(funID, stmt_to_bloc, *arg, removed_nodes, AppM);
889 stack.push_front(tn);
890 auto* ce = GetPointer<gimple_call>(curr_tn);
891 const std::vector<tree_nodeRef>&
args = ce->args;
892 std::vector<tree_nodeRef>::const_iterator
arg, arg_end = args.end();
893 for(arg = args.begin(); arg != arg_end; ++
arg)
895 collapse_into(funID, stmt_to_bloc, *arg, removed_nodes, AppM);
902 case case_label_expr_K:
908 case gimple_pragma_K:
909 case gimple_predict_K:
911 case gimple_return_K:
913 case identifier_node_K:
914 case namespace_decl_K:
915 case statement_list_K:
917 case translation_unit_decl_K:
918 case template_decl_K:
934 const std::string raw_file_name =
Param->getOption<std::string>(OPT_output_temporary_directory) +
936 STR(tree_node_index) +
".raw";
937 std::ofstream raw_file(raw_file_name.c_str());
940 const std::string gimple_file_name =
Param->getOption<std::string>(OPT_output_temporary_directory) +
942 STR(tree_node_index) +
".gimple";
944 std::ofstream gimple_file(gimple_file_name.c_str());
956 THROW_ASSERT(!GetPointer<const gimple_node>(
GET_NODE(new_node)),
"new node cannot be a gimple_node");
958 "old node cannot be a gimple_node: " +
STR(old_node));
971 "-->Replacing " + old_node->
ToString() +
" (" +
GET_NODE(old_node)->get_kind_text() +
") with " +
973 ") starting from node: " + tn->
ToString() +
"(" +
GET_NODE(tn)->get_kind_text() +
")");
977 const auto gn = GetPointer<const gimple_node>(
GET_NODE(stmt));
980 const auto ga = GetPointer<const gimple_assign>(
GET_NODE(stmt));
981 const auto gp = GetPointer<const gimple_phi>(
GET_NODE(stmt));
987 for(
const auto& used_ssa : used_ssas)
991 GetPointerS<ssa_name>(
GET_NODE(used_ssa.first))->RemoveUse(stmt);
998 for(
const auto& new_used_ssa : new_used_ssas)
1002 GetPointerS<ssa_name>(
GET_NODE(new_used_ssa.first))->AddUseStmt(stmt);
1008 if(gn->vdef && gn->vdef->index == old_node->
index)
1010 const auto vssa = GetPointerS<ssa_name>(
GET_NODE(new_node));
1011 vssa->SetDefStmt(stmt);
1013 if(gn->memdef && gn->memdef->index == old_node->
index)
1015 const auto vssa = GetPointerS<ssa_name>(
GET_NODE(new_node));
1016 vssa->SetDefStmt(stmt);
1018 if(ga && ga->op0->index == old_node->
index &&
GET_NODE(old_node)->get_kind() == ssa_name_K)
1020 GetPointerS<ssa_name>(
GET_NODE(new_node))->SetDefStmt(stmt);
1022 if(gp && gp->res->index == old_node->
index && !GetPointer<cst_node>(
GET_CONST_NODE(new_node)))
1027 "---Setting " +
STR(stmt) +
" as new define statement of " +
STR(new_node));
1028 GetPointerS<ssa_name>(
GET_NODE(new_node))->SetDefStmt(stmt);
1034 "<--Replaced " + old_node->
ToString() +
" (" +
GET_NODE(old_node)->get_kind_text() +
") with " +
1036 ") New statement: " + tn->
ToString());
1039 const auto gn = GetPointer<gimple_node>(curr_tn);
1051 const auto vuse_it = gn->vuses.find(old_node);
1052 if(vuse_it != gn->vuses.end())
1054 gn->vuses.erase(vuse_it);
1055 const auto old_vssa = GetPointerS<ssa_name>(
GET_NODE(old_node));
1056 old_vssa->RemoveUse(stmt);
1057 if(gn->AddVuse(new_node))
1059 const auto new_vssa = GetPointerS<ssa_name>(
GET_NODE(new_node));
1060 new_vssa->AddUseStmt(stmt);
1063 const auto vover_it = gn->vovers.find(old_node);
1064 if(vover_it != gn->vovers.end())
1066 gn->vovers.erase(vover_it);
1067 const auto old_vssa = GetPointerS<ssa_name>(
GET_NODE(old_node));
1068 old_vssa->RemoveUse(stmt);
1069 if(gn->AddVover(new_node))
1071 const auto new_vssa = GetPointerS<ssa_name>(
GET_NODE(new_node));
1072 new_vssa->AddUseStmt(stmt);
1081 switch(curr_tn->get_kind())
1083 case gimple_assign_K:
1085 const auto gm = GetPointerS<gimple_assign>(curr_tn);
1088 for(
auto& use : gm->use_set->variables)
1092 for(
auto& clb : gm->clobbered_set->variables)
1104 auto* gasm = GetPointerS<gimple_asm>(curr_tn);
1121 auto* gc = GetPointerS<gimple_cond>(curr_tn);
1127 auto* ue = GetPointerS<unary_expr>(curr_tn);
1133 auto* be = GetPointerS<binary_expr>(curr_tn);
1138 case gimple_switch_K:
1140 auto* se = GetPointerS<gimple_switch>(curr_tn);
1144 case gimple_multi_way_if_K:
1146 auto* gmwi = GetPointerS<gimple_multi_way_if>(curr_tn);
1147 for(
auto& cond : gmwi->list_of_cond)
1158 auto* te = GetPointerS<ternary_expr>(curr_tn);
1169 auto* qe = GetPointerS<quaternary_expr>(curr_tn);
1184 auto* le = GetPointerS<lut_expr>(curr_tn);
1219 auto* gp = GetPointerS<gimple_phi>(curr_tn);
1220 for(
auto& def_edge : gp->list_of_def_edge)
1227 case target_mem_ref_K:
1229 auto tmr = GetPointerS<target_mem_ref>(curr_tn);
1244 case target_mem_ref461_K:
1246 auto tmr = GetPointerS<target_mem_ref461>(curr_tn);
1272 case gimple_label_K:
1274 case function_decl_K:
1283 case aggr_init_expr_K:
1285 auto* ce = GetPointerS<call_expr>(curr_tn);
1286 for(
auto&
arg : ce->args)
1294 auto* gc = GetPointerS<gimple_call>(curr_tn);
1295 for(
auto&
arg : gc->args)
1299 for(
auto& use : gc->use_set->variables)
1303 for(
auto& clb : gc->clobbered_set->variables)
1309 case gimple_return_K:
1311 auto* gr = GetPointerS<gimple_return>(curr_tn);
1320 auto* constr = GetPointerS<constructor>(curr_tn);
1321 for(
auto& idx_value : constr->list_of_idx_valu)
1329 auto* tl = GetPointerS<tree_list>(curr_tn);
1336 tl = tl->chan ? GetPointerS<tree_list>(
GET_NODE(tl->chan)) :
nullptr;
1342 case case_label_expr_K:
1347 case gimple_pragma_K:
1348 case gimple_predict_K:
1350 case gimple_while_K:
1351 case identifier_node_K:
1352 case namespace_decl_K:
1353 case statement_list_K:
1355 case translation_unit_decl_K:
1356 case template_decl_K:
1367 curr_tn->get_kind_text());
1370 "<--Replaced " + old_node->
ToString() +
" (" +
GET_NODE(old_node)->get_kind_text() +
") with " +
1372 ") New statement: " + tn->
ToString());
1382 switch(curr_tn->get_kind())
1384 case gimple_assign_K:
1386 auto* gm = GetPointer<gimple_assign>(curr_tn);
1396 auto* gc = GetPointer<gimple_cond>(curr_tn);
1402 if(curr_tn->get_kind() == addr_expr_K)
1410 auto* ue = GetPointer<unary_expr>(curr_tn);
1416 auto* be = GetPointer<binary_expr>(curr_tn);
1421 case gimple_switch_K:
1423 auto* se = GetPointer<gimple_switch>(curr_tn);
1427 case gimple_multi_way_if_K:
1429 auto* gmwi = GetPointer<gimple_multi_way_if>(curr_tn);
1430 for(
const auto& cond : gmwi->list_of_cond)
1441 auto* te = GetPointer<ternary_expr>(curr_tn);
1452 auto* qe = GetPointer<quaternary_expr>(curr_tn);
1467 auto* le = GetPointer<lut_expr>(curr_tn);
1511 case gimple_label_K:
1514 case target_mem_ref_K:
1515 case target_mem_ref461_K:
1516 case function_decl_K:
1522 auto* sn = GetPointer<ssa_name>(curr_tn);
1523 for(
const auto& use_stmt : sn->CGetUseStmts())
1527 for(decltype(use_stmt.second) repetition = 0; repetition < use_stmt.second; repetition++)
1529 sn->RemoveUse(use_stmt.first);
1536 case aggr_init_expr_K:
1538 auto* ce = GetPointer<call_expr>(curr_tn);
1539 std::vector<tree_nodeRef>&
args = ce->args;
1540 std::vector<tree_nodeRef>::iterator
arg, arg_end = args.end();
1541 for(arg = args.begin(); arg != arg_end; ++
arg)
1549 auto* ce = GetPointer<gimple_call>(curr_tn);
1550 std::vector<tree_nodeRef>&
args = ce->args;
1551 std::vector<tree_nodeRef>::iterator
arg, arg_end = args.end();
1552 for(arg = args.begin(); arg != arg_end; ++
arg)
1560 case case_label_expr_K:
1567 case gimple_pragma_K:
1568 case gimple_predict_K:
1570 case gimple_return_K:
1571 case gimple_while_K:
1572 case identifier_node_K:
1573 case namespace_decl_K:
1574 case statement_list_K:
1576 case translation_unit_decl_K:
1577 case template_decl_K:
1589 curr_tn->get_kind_text());
1603 switch(curr_tn->get_kind())
1605 case gimple_assign_K:
1607 auto* gm = GetPointer<gimple_assign>(curr_tn);
1617 auto* gc = GetPointer<gimple_cond>(curr_tn);
1623 if(curr_tn->get_kind() == addr_expr_K)
1631 auto* ue = GetPointer<unary_expr>(curr_tn);
1637 auto* be = GetPointer<binary_expr>(curr_tn);
1642 case gimple_switch_K:
1644 auto* se = GetPointer<gimple_switch>(curr_tn);
1648 case gimple_multi_way_if_K:
1650 auto* gmwi = GetPointer<gimple_multi_way_if>(curr_tn);
1651 for(
const auto& cond : gmwi->list_of_cond)
1662 auto* te = GetPointer<ternary_expr>(curr_tn);
1673 auto* qe = GetPointer<quaternary_expr>(curr_tn);
1688 auto* le = GetPointer<lut_expr>(curr_tn);
1732 case gimple_label_K:
1735 case target_mem_ref_K:
1736 case target_mem_ref461_K:
1737 case function_decl_K:
1743 auto* sn = GetPointer<ssa_name>(curr_tn);
1744 sn->AddUseStmt(stmt);
1748 case aggr_init_expr_K:
1750 auto* ce = GetPointer<call_expr>(curr_tn);
1751 const std::vector<tree_nodeRef>&
args = ce->args;
1752 std::vector<tree_nodeRef>::const_iterator
arg, arg_end = args.end();
1753 for(arg = args.begin(); arg != arg_end; ++
arg)
1761 auto* ce = GetPointer<gimple_call>(curr_tn);
1762 std::vector<tree_nodeRef>&
args = ce->args;
1763 std::vector<tree_nodeRef>::iterator
arg, arg_end = args.end();
1764 for(arg = args.begin(); arg != arg_end; ++
arg)
1772 case case_label_expr_K:
1779 case gimple_pragma_K:
1780 case gimple_predict_K:
1782 case gimple_return_K:
1783 case gimple_while_K:
1784 case identifier_node_K:
1785 case namespace_decl_K:
1786 case statement_list_K:
1788 case translation_unit_decl_K:
1789 case template_decl_K:
1801 curr_tn->get_kind_text());
1848 std::string raw_file_name =
Param->getOption<std::string>(OPT_output_temporary_directory) +
"before_tree_merge_" +
1850 std::ofstream raw_file(raw_file_name.c_str());
1851 raw_file << TM_this;
1858 std::string symbol_name;
1859 std::string symbol_scope;
1864 auto* dn = GetPointer<decl_node>(tn);
1868 if(
check_for_type(tn, TM_this, symbol_name, symbol_scope, global_type_symbol_table, ti.first))
1876 global_type_symbol_table.find(symbol_name) == global_type_symbol_table.end(),
1877 "duplicated symbol in global_type_symbol_table: " + global_type_symbol_table.find(symbol_name)->first +
1878 " " +
STR(global_type_symbol_table.find(symbol_name)->second) +
" " +
STR(ti.first));
1880 "---Is INSERTED in the symbol table " + symbol_name +
" --> " +
STR(ti.first));
1881 global_type_symbol_table[symbol_name] = ti.first;
1883 if(tn->
get_kind() == record_type_K and GetPointer<record_type>(tn)->unql and
1886 global_type_symbol_table[
"u struct " + symbol_name] =
GET_INDEX_NODE(GetPointer<record_type>(tn)->unql);
1887 global_type_unql_symbol_table[
GET_INDEX_NODE(GetPointer<record_type>(tn)->unql)] =
1888 "u struct " + symbol_name;
1890 else if(tn->
get_kind() == union_type_K and GetPointer<union_type>(tn)->unql and
1893 global_type_symbol_table[
"u union " + symbol_name] =
GET_INDEX_NODE(GetPointer<union_type>(tn)->unql);
1894 global_type_unql_symbol_table[
GET_INDEX_NODE(GetPointer<union_type>(tn)->unql)] =
1895 "u union " + symbol_name;
1902 for(
const auto& ti : tree_nodes)
1906 auto* dn = GetPointer<decl_node>(tn);
1910 if(
check_for_decl(tn, TM_this, symbol_name, symbol_scope, ti.first, global_type_unql_symbol_table))
1919 if((GetPointer<function_decl>(tn) and GetPointer<function_decl>(tn)->static_flag) or
1920 (GetPointer<var_decl>(tn) and
1921 (GetPointer<var_decl>(tn)->static_flag or GetPointer<var_decl>(tn)->static_static_flag)))
1925 (GetPointer<function_decl>(tn) and GetPointer<function_decl>(tn)->body) or
1926 (GetPointer<var_decl>(tn) and
1927 static_symbol_table.find(symbol_name +
"-" + symbol_scope) == static_symbol_table.end()) or
1928 (GetPointer<function_decl>(tn) and not GetPointer<function_decl>(tn)->body and
1929 static_function_header_symbol_table.find(symbol_name +
"-" + symbol_scope) ==
1930 static_function_header_symbol_table.end()),
1931 "duplicated static symbol in the current tree_manager: " + symbol_name +
"-" + symbol_scope +
" " +
1933 if(GetPointer<function_decl>(tn) and !GetPointer<function_decl>(tn)->body)
1935 static_function_header_symbol_table.insert(symbol_name +
"-" + symbol_scope);
1939 static_symbol_table.insert(symbol_name +
"-" + symbol_scope);
1944 if(dn->get_kind() == function_decl_K and
1945 global_decl_symbol_table.find(symbol_name +
"-" + symbol_scope) != global_decl_symbol_table.end())
1947 if(GetPointer<function_decl>(
1948 tree_nodes.find(global_decl_symbol_table.find(symbol_name +
"-" + symbol_scope)->second)->second)
1953 if(GetPointer<function_decl>(tn)->undefined_flag)
1959 else if(dn->get_kind() == var_decl_K and
1960 global_decl_symbol_table.find(symbol_name +
"-" + symbol_scope) != global_decl_symbol_table.end())
1962 if(!GetPointer<var_decl>(
1963 tree_nodes.find(global_decl_symbol_table.find(symbol_name +
"-" + symbol_scope)->second)->second)
1968 if(GetPointer<var_decl>(tn)->extern_flag)
1974 else if(dn->get_kind() != function_decl_K && dn->get_kind() != var_decl_K && dn->get_kind() != type_decl_K)
1984 "---Adding to global declaration table " + symbol_name +
"-" + symbol_scope +
" (" +
1985 STR(ti.first) +
")");
1987 global_decl_symbol_table[symbol_name +
"-" + symbol_scope] = ti.first;
1994 auto gtust_i_end = global_type_unql_symbol_table.end();
1995 for(
auto gtust_i = global_type_unql_symbol_table.begin(); gtust_i != gtust_i_end; ++gtust_i)
1999 auto gst_i_end = global_decl_symbol_table.end();
2000 for(
auto gst_i = global_decl_symbol_table.begin(); gst_i != gst_i_end; ++gst_i)
2005 gst_i_end = global_type_symbol_table.end();
2006 for(
auto gst_i = global_type_symbol_table.begin(); gst_i != gst_i_end; ++gst_i)
2037 std::map<unsigned int, tree_nodeRef> source_tree_nodes;
2038 for(
auto source_tree_node : source_tree_manager->tree_nodes)
2040 source_tree_nodes.insert(source_tree_node);
2043 auto& source_tree_nodes = source_tree_manager->tree_nodes;
2049 "-->Analyzing " +
STR(source_tree_nodes.size()) +
" tree nodes of second tree manager");
2050 for(
const auto& ti_source : source_tree_nodes)
2054 auto* dn = GetPointer<decl_node>(tn);
2058 if(GetPointer<identifier_node>(tn))
2060 auto*
id = GetPointer<identifier_node>(tn);
2065 remap[ti_source.first] = node_id;
2073 else if(
check_for_type(tn, source_tree_manager, symbol_name, symbol_scope, global_type_symbol_table,
2082 STR(ti_source.first) +
"-ntype>" + symbol_name +
"-" + symbol_scope);
2083 if(tn->
get_kind() == record_type_K and GetPointer<record_type>(tn)->unql and
2086 auto gst_it = global_type_symbol_table.find(
"u struct " + symbol_name);
2087 if(gst_it != global_type_symbol_table.end())
2089 remap[
GET_INDEX_NODE(GetPointer<record_type>(tn)->unql)] = gst_it->second;
2090 global_type_unql_symbol_table[
GET_INDEX_NODE(GetPointer<record_type>(tn)->unql)] =
2091 "u struct " + symbol_name;
2093 STR(
GET_INDEX_NODE(GetPointer<record_type>(tn)->unql)) +
"-nutype>" + symbol_name);
2098 unsigned int new_tree_index;
2099 if(remap.find(
GET_INDEX_NODE(GetPointer<record_type>(tn)->unql)) == remap.end())
2102 not_yet_remapped.insert(
GET_INDEX_NODE(GetPointer<record_type>(tn)->unql));
2103 remap[
GET_INDEX_NODE(GetPointer<record_type>(tn)->unql)] = new_tree_index;
2104 to_be_visited.insert(
GET_INDEX_NODE(GetPointer<record_type>(tn)->unql));
2108 new_tree_index = remap[
GET_INDEX_NODE(GetPointer<record_type>(tn)->unql)];
2110 global_type_symbol_table[
"u struct " + symbol_name] = new_tree_index;
2111 global_type_unql_symbol_table[
GET_INDEX_NODE(GetPointer<record_type>(tn)->unql)] =
2112 "u struct " + symbol_name;
2114 "other " +
STR(
GET_INDEX_NODE(GetPointer<record_type>(tn)->unql)) +
"-nutype>" +
2118 else if(tn->
get_kind() == union_type_K and GetPointer<union_type>(tn)->unql and
2121 auto gst_it = global_type_symbol_table.find(
"u union " + symbol_name);
2122 if(gst_it != global_type_symbol_table.end())
2124 remap[
GET_INDEX_NODE(GetPointer<union_type>(tn)->unql)] = gst_it->second;
2125 global_type_unql_symbol_table[
GET_INDEX_NODE(GetPointer<union_type>(tn)->unql)] =
2126 "u union " + symbol_name;
2128 STR(
GET_INDEX_NODE(GetPointer<union_type>(tn)->unql)) +
"-nutype>" + symbol_name);
2133 unsigned int new_tree_index;
2134 if(remap.find(
GET_INDEX_NODE(GetPointer<union_type>(tn)->unql)) == remap.end())
2137 remap[
GET_INDEX_NODE(GetPointer<union_type>(tn)->unql)] = new_tree_index;
2138 not_yet_remapped.insert(
GET_INDEX_NODE(GetPointer<union_type>(tn)->unql));
2139 to_be_visited.insert(
GET_INDEX_NODE(GetPointer<union_type>(tn)->unql));
2143 new_tree_index = remap[
GET_INDEX_NODE(GetPointer<union_type>(tn)->unql)];
2145 global_type_symbol_table[
"u union " + symbol_name] = new_tree_index;
2146 global_type_unql_symbol_table[
GET_INDEX_NODE(GetPointer<union_type>(tn)->unql)] =
2147 "u union " + symbol_name;
2153 auto gst_it = global_type_symbol_table.find(symbol_name);
2154 if(gst_it == global_type_symbol_table.end())
2156 if(remap.find(ti_source.first) == remap.end())
2159 global_type_symbol_table[symbol_name] = remap[ti_source.first] = new_tree_index;
2160 not_yet_remapped.insert(ti_source.first);
2161 to_be_visited.insert(ti_source.first);
2168 if(tn->
get_kind() == record_type_K)
2171 if(tree_nodes.find(gst_it->second) != tree_nodes.end())
2173 if(GetPointer<record_type>(tree_nodes.find(gst_it->second)->second) and
2174 GetPointer<record_type>(tree_nodes.find(gst_it->second)->second)->list_of_flds.empty() and
2175 !GetPointer<record_type>(tn)->list_of_flds.empty())
2177 not_yet_remapped.insert(ti_source.first);
2178 to_be_visited.insert(ti_source.first);
2180 "RECORD TYPE: " + gst_it->first +
" " +
STR(ti_source.first));
2185 THROW_ASSERT(source_tree_nodes.find(gst_it->second) != source_tree_nodes.end(),
2186 "There is a symbol which is not present in this nor tree_manager nor the other");
2187 if(GetPointer<record_type>(source_tree_nodes.find(gst_it->second)->second)
2188 ->list_of_flds.empty() and
2189 !GetPointer<record_type>(tn)->list_of_flds.empty())
2191 not_yet_remapped.insert(ti_source.first);
2192 to_be_visited.insert(ti_source.first);
2194 "RECORD TYPE: " + gst_it->first +
" " +
STR(ti_source.first));
2201 if(tree_nodes.find(gst_it->second) != tree_nodes.end())
2203 if(GetPointer<union_type>(tree_nodes.find(gst_it->second)->second) and
2204 GetPointer<union_type>(tree_nodes.find(gst_it->second)->second)->list_of_flds.empty() and
2205 !GetPointer<union_type>(tn)->list_of_flds.empty())
2207 not_yet_remapped.insert(ti_source.first);
2208 to_be_visited.insert(ti_source.first);
2210 "UNION TYPE: " + gst_it->first +
" " +
STR(ti_source.first));
2215 THROW_ASSERT(source_tree_nodes.find(gst_it->second) != source_tree_nodes.end(),
2216 "There is a symbol which is not present in this nor tree_manager nor the other");
2217 if(GetPointer<union_type>(source_tree_nodes.find(gst_it->second)->second)->list_of_flds.empty() and
2218 !GetPointer<union_type>(tn)->list_of_flds.empty())
2220 not_yet_remapped.insert(ti_source.first);
2221 to_be_visited.insert(ti_source.first);
2223 "UNION TYPE: " + gst_it->first +
" " +
STR(ti_source.first));
2227 remap[ti_source.first] = gst_it->second;
2236 for(
const auto& ti_source : source_tree_nodes)
2240 auto* dn = GetPointer<decl_node>(tn);
2244 "-->Examining declaration node " +
STR(ti_source.first) +
" of second tree:" +
STR(tn));
2245 if(
check_for_decl(tn, source_tree_manager, symbol_name, symbol_scope, ti_source.first,
2246 global_type_unql_symbol_table))
2252 STR(ti_source.first) +
"-ndecl>" + symbol_name +
"-" + symbol_scope);
2254 if((GetPointer<function_decl>(tn) and GetPointer<function_decl>(tn)->static_flag) or
2255 (GetPointer<var_decl>(tn) and
2256 (GetPointer<var_decl>(tn)->static_flag or GetPointer<var_decl>(tn)->static_static_flag)))
2259 if(GetPointer<function_decl>(tn))
2262 if(GetPointer<function_decl>(tn)->body)
2267 remap[ti_source.first] = new_index;
2268 not_yet_remapped.insert(ti_source.first);
2269 to_be_visited.insert(ti_source.first);
2271 static_implementation_functions[symbol_name] = ti_source.first;
2274 if(static_forward_declaration_functions.find(symbol_name) !=
2275 static_forward_declaration_functions.end())
2277 remap[static_forward_declaration_functions[symbol_name]] = new_index;
2283 static_forward_declaration_functions[symbol_name] = ti_source.first;
2285 if(static_implementation_functions.find(symbol_name) != static_implementation_functions.end())
2287 remap[ti_source.first] = remap[static_implementation_functions[symbol_name]];
2293 if(source_static_symbol_table.find(symbol_name) != source_static_symbol_table.end())
2296 unsigned int node_id_source =
2297 source_tree_manager->find_identifier_nodeID(source_static_symbol_table.find(symbol_name)->second);
2300 dn->name = source_tree_manager->GetTreeReindex(node_id_source);
2302 else if(static_symbol_table.find(symbol_name +
"-" + symbol_scope) != static_symbol_table.end() or
2303 static_function_header_symbol_table.find(symbol_name +
"-" + symbol_scope) !=
2304 static_function_header_symbol_table.end())
2307 "---Already present in destination static symbol table");
2312 unsigned int node_id_this, node_id_source;
2317 node_id_source = source_tree_manager->find_identifier_nodeID(symbol_name +
STR(counter));
2318 }
while((node_id_this > 0 || node_id_source > 0));
2319 std::map<TreeVocabularyTokenTypes_TokenEnum, std::string> tree_node_schema;
2321 node_id_source = source_tree_manager->new_tree_node_id(ti_source.first);
2322 source_tree_manager->create_tree_node(node_id_source, identifier_node_K, tree_node_schema);
2325 dn->name = source_tree_manager->GetTreeReindex(node_id_source);
2326 source_static_symbol_table[symbol_name] = symbol_name +
STR(counter);
2330 if(not GetPointer<function_decl>(tn))
2332 static_symbol_table.insert(symbol_name +
"-" + symbol_scope);
2341 auto gst_it = global_decl_symbol_table.find(symbol_name +
"-" + symbol_scope);
2342 if(gst_it == global_decl_symbol_table.end())
2345 unsigned int new_index;
2347 global_decl_symbol_table[symbol_name +
"-" + symbol_scope] = remap[ti_source.first] = new_index;
2348 if(dn->get_kind() == function_decl_K and not GetPointer<const function_decl>(tn)->body)
2350 reverse_remap[new_index] = ti_source.first;
2352 if(dn->get_kind() == var_decl_K and GetPointer<const var_decl>(tn)->extern_flag)
2354 reverse_remap[new_index] = ti_source.first;
2356 not_yet_remapped.insert(ti_source.first);
2357 to_be_visited.insert(ti_source.first);
2365 if((tn->
get_kind() == function_decl_K
2372 and GetPointer<function_decl>(tn)->body) ||
2375 (!GetPointer<var_decl>(tree_nodes.find(gst_it->second)->second) ||
2376 GetPointer<var_decl>(tree_nodes.find(gst_it->second)->second)->extern_flag) and
2377 !GetPointer<var_decl>(tn)->extern_flag) ||
2380 (tn->
get_kind() == function_decl_K and
2381 GetPointer<function_decl>(tree_nodes.find(gst_it->second)->second) and
2382 (GetPointer<function_decl>(tree_nodes.find(gst_it->second)->second))->include_name ==
2384 !(GetPointer<function_decl>(tn))->include_name.empty() and
2385 (GetPointer<function_decl>(tn))->include_name !=
"<built-in>"))
2389 not_yet_remapped.insert(ti_source.first);
2390 to_be_visited.insert(ti_source.first);
2391 remap[ti_source.first] = gst_it->second;
2394 if(reverse_remap.find(gst_it->second) != reverse_remap.end())
2396 THROW_ASSERT(not_yet_remapped.find(reverse_remap.find(gst_it->second)->second) !=
2397 not_yet_remapped.end(),
2398 "Trying to cancel remapping of " +
STR(reverse_remap.find(gst_it->second)->second));
2399 not_yet_remapped.erase(reverse_remap.find(gst_it->second)->second);
2404 remap[ti_source.first] = gst_it->second;
2419 auto it_to_be_visited_end = to_be_visited.end();
2420 for(
auto it_to_be_visited = to_be_visited.begin(); it_to_be_visited_end != it_to_be_visited; ++it_to_be_visited)
2422 source_tree_manager->get_tree_node_const(*it_to_be_visited)->visit(&TNR);
2426 for(
auto& function_decl_node : source_tree_manager->function_decl_nodes)
2429 auto* fd = GetPointer<function_decl>(curr_tn);
2430 if(remap.find(function_decl_node.first) == remap.end())
2432 remap[function_decl_node.first] =
new_tree_node_id(function_decl_node.first);
2434 "Function decl: old " +
STR(function_decl_node.first) +
" - new " +
2435 STR(remap[function_decl_node.first]));
2437 not_yet_remapped.insert(function_decl_node.first);
2441 auto it_remap_end = remap.end();
2442 for(
auto it_remap = remap.begin(); it_remap_end != it_remap; ++it_remap)
2445 "Original " +
STR(it_remap->first) +
" New " +
STR(it_remap->second));
2449 auto it_not_yet_remapped_end = not_yet_remapped.end();
2450 for(
auto it_not_yet_remapped = not_yet_remapped.begin(); it_not_yet_remapped_end != it_not_yet_remapped;
2451 ++it_not_yet_remapped)
2454 "Original " +
STR(*it_not_yet_remapped) +
" New " +
STR(remap[*it_not_yet_remapped]));
2456 source_tree_manager->get_tree_node_const(*it_not_yet_remapped));
2460 std::string(source_tree_manager->get_tree_node_const(*it_not_yet_remapped)->get_kind_text()));
2465 std::string raw_file_name =
Param->getOption<std::string>(OPT_output_temporary_directory) +
"after_" +
2467 std::cerr << raw_file_name << std::endl;
2468 std::ofstream raw_file(raw_file_name.c_str());
2469 raw_file << TM_this;
2479 THROW_ASSERT(GetPointer<decl_node>(tn),
"Node should be a declaration node");
2480 const decl_node* dn = GetPointer<decl_node>(tn);
2481 symbol_name = symbol_scope =
"";
2487 if(
GET_NODE(dn->
name)->get_kind() == identifier_node_K)
2490 "---check_for_decl is considering: " + GetPointer<identifier_node>(
GET_NODE(dn->
name))->strg +
2494 if(GetPointer<memory_tag>(tn) || dn->
get_kind() == parm_decl_K || dn->
get_kind() == result_decl_K)
2506 global_type_unql_symbol_table.find(
GET_INDEX_NODE(dn->
scpe)) == global_type_unql_symbol_table.end()))
2513 "expected an identifier_node: " +
STR(
GET_NODE(dn->
mngl)->get_kind_text()));
2517 "expected an identifier_node: " +
STR(
GET_NODE(dn->
name)->get_kind_text()) +
" " +
STR(node_id));
2522 symbol_name = GetPointer<identifier_node>(
GET_NODE(dn->
name))->strg;
2525 symbol_name = symbol_name.substr(strlen(
"__builtin_"));
2532 symbol_name = GetPointer<identifier_node>(
GET_NODE(dn->
mngl))->strg;
2537 symbol_name = GetPointer<identifier_node>(
GET_NODE(dn->
mngl))->strg;
2542 symbol_name = GetPointer<identifier_node>(
GET_NODE(dn->
mngl))->strg;
2548 "expected an identifier_node: " +
STR(
GET_NODE(dn->
name)->get_kind_text()) +
" " +
STR(node_id));
2549 symbol_name = GetPointer<identifier_node>(
GET_NODE(dn->
name))->strg;
2552 symbol_name = symbol_name.substr(strlen(
"__builtin_"));
2566 const auto quals =
type->qual;
2567 std::string type_name;
2568 if(
GET_NODE(
type->name)->get_kind() == identifier_node_K)
2570 type_name = GetPointer<identifier_node>(
GET_NODE(
type->name))->strg;
2584 symbol_scope = type_name;
2589 symbol_scope =
"struct " + type_name;
2593 symbol_scope = symbol_scope +
"#F";
2598 global_type_unql_symbol_table.find(
GET_INDEX_NODE(dn->
scpe)) != global_type_unql_symbol_table.end())
2610 symbol_scope =
"#F";
2621 std::string& symbol_scope,
2626 auto*
type = GetPointer<type_node>(tn);
2627 symbol_name = symbol_scope =
"";
2636 const auto quals =
type->qual;
2637 std::string type_name;
2639 if(
GET_NODE(
type->name)->get_kind() == identifier_node_K)
2641 type_name = GetPointer<identifier_node>(
GET_NODE(
type->name))->strg;
2655 symbol_name = type_name +
"#unqualified";
2659 symbol_name = type_name;
2662 else if(
type->name and tn->
get_kind() == record_type_K)
2664 symbol_name =
"struct " + type_name;
2668 symbol_name =
"union " + type_name;
2670 else if(
type->name and tn->
get_kind() == enumeral_type_K)
2672 symbol_name =
"enum " + type_name;
2676 symbol_name = type_name;
2683 return global_type_symbol_table.find(symbol_name) != global_type_symbol_table.end();
2701 THROW_ASSERT(op,
"improper use of add_identifier_node");
2708 std::map<unsigned int, tree_nodeRef>::const_iterator beg, end;
2711 functions.insert(beg->first);
2727 auto* sn = GetPointer<ssa_name>(tn);
2782 const auto key = std::make_pair(val, type->
index);
2786 return unique_cst->second;
2790 std::map<TreeVocabularyTokenTypes_TokenEnum, std::string> IR_schema;
2825 std::stringstream ssX;
2827 ssX << std::hexfloat <<
value;
2831 sprintf(buffer,
"%La", value);
2841 return Param->isOption(OPT_input_format) &&
2851 std::string simple_name;
2852 if(id_name->
get_kind() == identifier_node_K)
2854 auto* in = GetPointer<identifier_node>(id_name);
2855 if(!in->operator_flag)
2857 simple_name = in->strg;
2859 if(!simple_name.empty())
2861 if(
Param->isOption(OPT_top_functions_names))
2863 const auto top_functions_names =
Param->getOption<std::list<std::string>>(OPT_top_functions_names);
2864 for(
const auto& top_function_name : top_functions_names)
2866 if(simple_name == top_function_name)
2872 if(
Param->isOption(OPT_top_design_name))
2874 const auto top_rtldesign_function =
Param->getOption<std::string>(OPT_top_design_name);
2875 if(simple_name == top_rtldesign_function)
2889 auto* fd = GetPointer<function_decl>(fd_node);
2890 auto*
sl = GetPointer<statement_list>(
GET_NODE(fd->body));
2892 for(
const auto& bb : sl->list_of_bloc)
2894 std::list<tree_nodeRef> whole_list = bb.second->CGetStmtList();
2895 for(
auto&
phi : bb.second->CGetPhiList())
2897 whole_list.push_back(
phi);
2899 for(
auto& statement_node : whole_list)
2901 auto orig_string = statement_node->ToString();
2903 for(
auto& ssa : ssas)
2908 auto* sn = GetPointer<ssa_name>(tn);
2910 for(
auto& use : sn->CGetUseStmts())
2913 if(used_ssa.find(tn) == used_ssa.end())
2924 std::cerr <<
"stmt: " << orig_string <<
" var: " << sn->ToString() << std::endl;
2925 for(
auto& stmt : sn->CGetUseStmts())
#define GET_NODE(t)
Macro used to hide implementation details when accessing a tree_node from another tree_node...
tree_nodeRef create_unique_const(const std::string &val, const tree_nodeConstRef &type)
void increment_unremoved_pointer_plus()
Increment the number of not removed pointer plus.
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
void * top(node_stack *head)
unsigned int next_vers
Next version number for ssa variables.
File containing functions and utilities to support the printing of debug messagges.
unsigned int get_removed_pointer_plus() const
Return the number of removed pointer plus.
void add_parallel_loop()
increment the number a parallel loop
#define PRINT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
#define STOK(token)
Macro used to convert a token symbol into the corresponding string.
const ParameterConstRef Param
Set of parameters.
std::string ToString() const
Print this node as string in gimple format.
void increment_removable_pointer_plus()
Increment the number of removable pointer plus.
#define CASE_BINARY_EXPRESSION
This macro collects all case labels for binary_expr objects.
const CustomUnorderedSet< unsigned int > GetAllFunctions() const
Returns all the functions in the tree_manager.
const tree_nodeRef CGetTreeReindex(const unsigned int i) const
Return a tree_reindex wrapping the i-th tree_node.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
void ReplaceTreeNode(const tree_nodeRef &stmt, const tree_nodeRef &old_node, const tree_nodeRef &new_node)
Replace the occurrences of tree node old_node with new_node in statement identified by tn...
static std::string bambu_ir_info
The version of the frontend compiler.
tree_nodeRef name
name field contains an identifier_node used to represent a name.
struct definition of the function_decl tree node.
unsigned int get_removable_pointer_plus() const
Return the number of not removed pointer plus.
unsigned int last_node_id
last node_id used
static std::string GetString(const enum kind k)
Given a kind, return the corresponding string.
tree_nodeRef mngl
mngl field contains the name of the object as the assembler will see it.
unsigned int get_next_available_tree_node_id() const
return the next available tree node id.
exceptions managed by PandA
void AddTreeNode(const unsigned int i, const tree_nodeRef &curr)
Add to the tree manager the current node.
unsigned int get_unremoved_pointer_plus() const
Return the number of not removed pointer plus.
A simple interface to token object of the raw files.
#define GET_INDEX_NODE(t)
Macro used to hide implementation details when accessing a tree_node from another tree_node...
static std::string print_function_name(const tree_managerConstRef &TM, const function_decl *fd)
Return the name of the function in a string.
absl::flat_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMapUnstable
unsigned int get_next_vers()
Return the next unused version number for ssa variables.
Data structure describing a basic block at tree level.
This class is used to perform the re-index of all tree nodes.
void create_tree_node(const unsigned int node_id, const tree_nodeRef &tn)
tree_node visitors
unsigned int added_goto
the number of added goto
#define TOK(token)
Macro used to convert a token symbol into a treeVocabularyTokenTypes.
std::string include_name
include_name is a filename string, this can be the location of a reference, if no definition has been...
const tree_nodeConstRef CGetTreeNode(const unsigned int i) const
bool builtin_flag
flag true when the function is a builtin
virtual enum kind get_kind() const =0
Virtual function returning the type of the actual class.
#define STR(s)
Macro which performs a lexical_cast to a string.
void RecursiveReplaceTreeNode(tree_nodeRef &tn, const tree_nodeRef old_node, const tree_nodeRef &new_node, const tree_nodeRef &stmt, bool definition)
Replace the occurrences of tree node old_node with new_node in statement identified by tn...
Auxiliary methods for manipulating string.
tree_manager(const ParameterConstRef &Param)
This is the constructor of the tree_manager which initializes the vector of functions.
static bool HasToBeDeclared(const tree_managerConstRef &TM, const tree_nodeConstRef &type)
Return true if the type has to be declared.
unsigned int function_index_mngl(const std::string &function_name) const
Return the index of a function given its mangled name.
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.
static bool IsSignedIntegerType(const tree_nodeConstRef &type)
Return true if the treenode is of integer type.
#define STOK2(token)
Macro used to convert an int token symbol into the corresponding string.
#define ASSERT_PARAMETER(parameter)
unsigned int function_index(const std::string &function_name) const
Return the index of a function given its name.
virtual std::string get_kind_text() const =0
Virtual function returning the name of the actual class.
bool starts_with(const std::string &str, const std::string &pattern)
bool is_top_function(const function_decl *fd) const
is_top_function checks if a function is one of the application top functions.
static unsigned long long Size(const tree_nodeConstRef &tn)
Return the size of a tree object.
std::set< Key, Compare, Alloc > OrderedSetStd
absl::flat_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMap
unsigned int find(enum kind tree_node_type, const std::map< TreeVocabularyTokenTypes_TokenEnum, std::string > &tree_node_schema)
if there exist return the node id of a tree node compatible with the tree_node_schema and of type tre...
#define CASE_QUATERNARY_EXPRESSION
This macro collects all case labels for quaternary_expr objects.
#define CASE_UNARY_EXPRESSION
This macro collects all case labels for unary_expr objects.
unsigned int new_tree_node_id(const unsigned int ask=0)
Return a new node id in the intermediate representation.
tree_nodeRef CreateUniqueRealCst(long double value, const tree_nodeConstRef &type)
memoization of integer constants
int debug_level
The debug level.
void add_function(unsigned int index, tree_nodeRef curr)
Add to the function_decl_nodes the current node.
CustomUnorderedMapUnstable< std::string, unsigned int > identifiers_unique_table
this table stores all identifier_nodes with their nodeID.
unsigned int n_pl
the number of parallel loops
bool check_ssa_uses(unsigned int fun_id) const
check_ssa_uses check if the uses of a ssa are correct
void erase_usage_info(const tree_nodeRef &tn, const tree_nodeRef &stmt)
Erase the information about variable usage (remove stmt from use_stmts attribute) in ssa variables re...
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 create_tree_node(const unsigned int node_id, enum kind tree_node_type, std::map< TreeVocabularyTokenTypes_TokenEnum, std::string > &tree_node_schema)
Factory method.
void increment_removed_pointer_plus()
Increment the number of removed pointer plus.
tree_nodeRef CreateUniqueIntegerCst(integer_cst_t value, const tree_nodeConstRef &type)
memoization of integer constants
static std::string return_qualifier_prefix(const TreeVocabularyTokenTypes_TokenEnum quals)
return the prefix given a qualifier
tree_nodeRef GetTreeReindex(const unsigned int i)
Return a tree_reindex wrapping the i-th tree_node.
bool check(const tree_nodeRef &t)
tree_node visitors
unsigned long get_function_decl_node_n() const
Return the number of function_decl_node.
bool check_for_decl(const tree_nodeRef &tn, const tree_managerRef &TM, std::string &symbol_name, std::string &symbol_scope, unsigned int node_id, const CustomUnorderedMap< unsigned int, std::string > &global_type_unql_symbol_table)
check for decl_node and return true if not suitable for symbol table or otherwise its symbol_name and...
unsigned int get_implementation_node(unsigned int decl_node) const
Return the index of function_decl node that implements the declaration node.
void add_goto()
Increment the number of added gotos.
#define GET_CONST_NODE(t)
Classes specification of the tree_node data structures.
unsigned int unremoved_pointer_plus
the number of unremoved pointer_plus
void merge_tree_managers(const tree_managerRef &source_tree_manager)
merge two tree manager: this with TM_source
This file collects some utility functions and macros.
tree node merger classess.
#define DEBUG_LEVEL_NONE
no debugging print is performed.
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
bool static_flag
static_flag is true if function has been defined (macro TREE_STATIC)
refcount< tree_manager > tree_managerRef
void collapse_into(const unsigned int &funID, CustomUnorderedMapUnstable< unsigned int, unsigned int > &stmt_to_bloc, const tree_nodeRef &tn, CustomUnorderedSet< unsigned int > &removed_nodes, const application_managerRef AppM)
Collapse operations chains into the examinated node.
#define CASE_TYPE_NODES
This macro collects all case labels for type objects.
This file collects some utility functions.
std::map< unsigned int, tree_nodeRef > function_decl_nodes
Variable containing set of function_declaration with their index node.
bool is_CPP() const
is_CPP return true in case we have at least one CPP source code
tree_nodeRef GetTreeNode(const unsigned int index) const
Return the index-th tree_node (modifiable version)
#define GET_FUNCTION_DEBUG_LEVEL(parameters)
Macro returning the debug_level of a function.
std::map< _Key, _Tp, _Compare, _Alloc > OrderedMapStd
Class specification of the tree_reindex support class.
#define CASE_FAKE_NODES
This macro collects all case labels for fake or empty nodes.
void create_tree_node(const unsigned int node_id, enum kind)
tree_node visitors
unsigned int find_identifier_nodeID(const std::string &str) const
Return the nodeID of the identifier_node representing string str.
OrderedMapStd< unsigned int, tree_nodeRef > tree_nodes
Variable containing set of tree_nodes.
bool is_tree_node(unsigned int i) const
Return true if there exists a tree node associated with the given id, false otherwise.
unsigned int get_n_pl() const
return the number of parallel loops
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Parameters_FileFormat
File formats.
unsigned int collapse_into_counter
Index of current call of collapse_into_counter.
void insert_usage_info(const tree_nodeRef &tn, const tree_nodeRef &stmt)
Insert the information about variable usage (insert stmt in use_stmts attribute) in ssa variables rec...
#define DEBUG_PARAMETER(parameter)
macro used to solve problem of parameters used only in not-release
#define DEBUG_LEVEL_PARANOIC
paranoid level debugging print is performed.
unsigned int get_added_goto() const
Return the number of added gotos.
Classes specification of the tree_node data structures not present in the gcc.
this class is used to manage the command-line or XML options.
#define CASE_CPP_NODES
This macro collects all case labels for cpp nodes.
static std::string get_type_name(const tree_managerConstRef &TM, const unsigned int index)
Return name of the type.
refcount< tree_node > tree_nodeRef
RefCount type definition of the tree_node class structure.
unsigned counter[N_THREADS]
void print(std::ostream &os) const
Function that prints the class tree_manager.
#define GET_INDEX_CONST_NODE(t)
CustomUnorderedMapUnstable< std::string, unsigned int > find_cache
cache for tree_manager::find
bool check_for_type(const tree_nodeRef &tn, const tree_managerRef &TM, std::string &symbol_name, std::string &symbol_scope, const CustomUnorderedMapUnstable< std::string, unsigned int > &global_type_symbol_table, unsigned int node_id)
check for type and return true if not suitable for symbol table or otherwise its symbol_name and symb...
void add_identifier_node(unsigned int nodeID, const std::string &str)
Add an identifier_node to the corresponding unique table.
static void ComputeSsaUses(const tree_nodeRef &, TreeNodeMap< size_t > &uses)
recursively compute the references to the ssa_name variables used in a statement
tree_nodeRef scpe
scope declaration
tree_nodeRef GetFunction(const std::string &function_name) const
Return the index of a function given its name.
std::string cxa_demangle(const std::string &input)
unsigned int find_sc_main_node() const
Determine the index node of "sc_main" function in tree_node vector.
struct definition of the declaration node structures.
#define CASE_TERNARY_EXPRESSION
This macro collects all case labels for ternary_expr objects.
Class specification of the manager of the tree structures extracted from the raw file.
CustomUnorderedMap< std::pair< std::string, unsigned int >, tree_nodeRef > unique_cst_map
unsigned int removable_pointer_plus
the number of removable pointer_plus
unsigned int removed_pointer_plus
the number of removed pointer_plus
static bool IsRealType(const tree_nodeConstRef &type)
Return true if the treenode is of real type.
void PrintGimple(std::ostream &os, const bool use_uid) const
Function that prints the bodies of function in gimple format.
#define CASE_PRAGMA_NODES
This macro collects all case labels for pragma objects.
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...
Implementation of the wrapper to Gcc for C sources.