72 #define F_SIGN(out, in) (((out & 3) << 2) | (in & 3)) 73 #define F_TYPE_IN(f_sign) (f_sign & 3) 74 #define F_TYPE_OUT(f_sign) ((f_sign >> 2) & 3) 85 const auto tn = _tn->get_kind() == tree_reindex_K ?
GET_CONST_NODE(_tn) : _tn;
86 const auto type = GetPointer<const type_node>(tn);
88 if(tn->get_kind() != integer_type_K)
92 const auto it = GetPointer<const integer_type>(tn);
94 if((it->prec !=
type->algn && it->prec > 64) || (
type->algn == 128))
107 :
HLSCWriter(_c_backend_information, _HLSMgr, _instruction_writer, _indented_output_stream, _parameters, _verbose),
111 (
Param->isOption(OPT_discrepancy_hw) &&
Param->getOption<
bool>(OPT_discrepancy_hw)),
112 "Step " +
STR(__PRETTY_FUNCTION__) +
" should not be added without discrepancy");
120 void _Dec2Bin_(FILE* __bambu_testbench_fp, long long int num, unsigned int precision) 123 unsigned long long int ull_value = (unsigned long long int)num; 124 for(i = 0; i < precision; ++i) 125 fprintf(__bambu_testbench_fp, "%c", (((1LLU << (precision - i - 1)) & ull_value) ? '1' : '0')); 128 void _Ptd2Bin_(FILE* __bambu_testbench_fp, unsigned char* num, unsigned int precision) 134 value = *(num + precision / 8); 135 for(j = 8 - precision % 8; j < 8; ++j) 136 fprintf(__bambu_testbench_fp, "%c", (((1LLU << (8 - j - 1)) & value) ? '1' : '0')); 138 for(i = 0; i < 8 * (precision / 8); i = i + 8) 140 value = *(num + (precision / 8) - (i / 8) - 1); 141 for(j = 0; j < 8; ++j) 142 fprintf(__bambu_testbench_fp, "%c", (((1LLU << (8 - j - 1)) & value) ? '1' : '0')); 146 float _Int32_ViewConvert(unsigned int i) 157 double _Int64_ViewConvert(unsigned long long i) 161 unsigned long long bits; 168 unsigned char _FPs32Mismatch_(float c, float e, float max_ulp) 170 unsigned int binary_c = *((unsigned int*)&c); 171 unsigned int binary_e = *((unsigned int*)&e); 172 unsigned int binary_abs_c = binary_c & (~(1U << 31)); 173 unsigned int binary_abs_e = binary_e & (~(1U << 31)); 174 unsigned int denom_0 = 0x34000000; 175 unsigned int denom_e = ((binary_abs_e >> 23) - 23) << 23; 177 unsigned int binary_cme = *((unsigned int*)&cme); 178 unsigned int binary_abs_cme = binary_cme & (~(1U << 31)); 179 float abs_cme = *((float*)&binary_abs_cme); 181 if(binary_abs_c > 0X7F800000 && binary_abs_c > 0X7F800000) 183 else if(binary_abs_c == 0X7F800000 && binary_abs_e == 0X7F800000) 185 if((binary_c >> 31) != (binary_e >> 31)) 190 else if(binary_abs_c == 0X7F800000 || binary_abs_e == 0X7F800000 || binary_abs_c > 0X7F800000 || 191 binary_abs_e == 0X7F800000) 195 if(binary_abs_e == 0) 196 ulp = abs_cme / (*((float*)&denom_0)); 198 ulp = abs_cme / (*((float*)&denom_e)); 199 return ulp > max_ulp; 203 unsigned char _FPs64Mismatch_(double c, double e, double max_ulp) 205 unsigned long long int binary_c = *((unsigned long long int*)&c); 206 unsigned long long int binary_e = *((unsigned long long int*)&e); 207 unsigned long long int binary_abs_c = binary_c & (~(1ULL << 63)); 208 unsigned long long int binary_abs_e = binary_e & (~(1ULL << 63)); 209 unsigned long long int denom_0 = 0x3CB0000000000000; 210 unsigned long long int denom_e = ((binary_abs_e >> 52) - 52) << 52; 212 unsigned long long int binary_cme = *((unsigned int*)&cme); 213 unsigned long long int binary_abs_cme = binary_cme & (~(1U << 31)); 214 double abs_cme = *((double*)&binary_abs_cme); 216 if(binary_abs_c > 0X7FF0000000000000 && binary_abs_c > 0X7FF0000000000000) 218 else if(binary_abs_c == 0X7FF0000000000000 && binary_abs_e == 0X7FF0000000000000) 220 if((binary_c >> 63) != (binary_e >> 63)) 225 else if(binary_abs_c == 0X7FF0000000000000 || binary_abs_e == 0X7FF0000000000000 || 226 binary_abs_c > 0X7FF0000000000000 || binary_abs_e == 0X7FF0000000000000) 230 if(binary_abs_e == 0) 231 ulp = abs_cme / (*((double*)&denom_0)); 233 ulp = abs_cme / (*((double*)&denom_e)); 234 return ulp > max_ulp; 238 void _CheckBuiltinFPs32_(char* chk_str, unsigned char neq, float par_expected, float par_res, float par_a, float par_b) 242 printf("\n\n***********************************************************\nERROR ON A BASIC FLOATING POINT " 243 "OPERATION : %s : expected=%a (%.20e) res=%a (%.20e) a=%a (%.20e) b=%a " 244 "(%.20e)\n***********************************************************\n\n", 245 chk_str, par_expected, par_expected, par_res, par_res, par_a, par_a, par_b, par_b); 250 void _CheckBuiltinFPs64_(char* chk_str, unsigned char neq, double par_expected, double par_res, double par_a, 255 printf("\n\n***********************************************************\nERROR ON A BASIC FLOATING POINT " 256 "OPERATION : %s : expected=%a (%.35e) res=%a (%.35e) a=%a (%.35e) b=%a " 257 "(%.35e)\n***********************************************************\n\n", 258 chk_str, par_expected, par_expected, par_res, par_res, par_a, par_a, par_b, par_b); 267 const auto top_symbols =
Param->getOption<std::vector<std::string>>(OPT_top_functions_names);
268 THROW_ASSERT(top_symbols.size() == 1,
"Expected single top function name");
271 const auto top_bh = top_fb->CGetBehavioralHelper();
272 const auto top_fname = top_bh->get_function_name();
275 const auto& test_vectors =
HLSMgr->RSim->test_vectors;
292 THROW_ERROR(
"return type of function under test " + top_fname +
" is " +
STR(ret_type) +
293 "\nco-simulation does not support vectorized return types at top level");
300 for(
unsigned int v_idx = 0; v_idx < test_vectors.size(); v_idx++)
304 const auto& curr_test_vector = test_vectors.at(v_idx);
326 const auto st_tn_id = node_info->GetNodeId();
333 if(
kind == gimple_return_K)
337 else if(
kind == gimple_call_K)
340 "tree node " +
STR(st_tn_id) +
" is a gimple_call but does not actually call a function");
341 THROW_ASSERT(node_info->called.size() == 1,
"tree node " +
STR(st_tn_id) +
" calls more than a function");
342 const auto called_id = *node_info->called.begin();
344 const auto* fu_dec = GetPointer<const function_decl>(called_fun_decl_node);
362 else if(
kind == gimple_assign_K)
364 const auto* g_as_node = GetPointer<const gimple_assign>(curr_tn);
366 if(rhs->get_kind() == call_expr_K || rhs->get_kind() == aggr_init_expr_K)
368 THROW_ASSERT(!node_info->called.empty(),
"rhs of gimple_assign node " +
STR(st_tn_id) +
369 " is a call_expr but does not actually call a function");
371 "rhs of gimple_assign node " +
STR(st_tn_id) +
" is a call_expr but calls more than a function");
372 const auto called_id = *node_info->called.begin();
386 if(
Param->isOption(OPT_discrepancy_hw) &&
Param->getOption<
bool>(OPT_discrepancy_hw))
395 const auto st_tn_id = instrGraph->
CGetOpNodeInfo(statement)->GetNodeId();
401 if(curr_tn->
get_kind() != gimple_assign_K && curr_tn->
get_kind() != gimple_phi_K)
407 if(
Param->isOption(OPT_discrepancy_only))
411 if(!discrepancy_functions.empty() && discrepancy_functions.find(fu_name) == discrepancy_functions.end())
417 const hlsConstRef
hls =
HLSMgr->get_HLS(funId);
419 technology_nodeRef fu_tech_n = hls->allocation_information->get_fu(hls->Rfu->get_assign(statement));
423 const operation* oper = GetPointer<operation>(op_tech_n);
429 const auto g_as_node = GetPointer<const gimple_assign>(curr_tn);
430 const auto g_phi_node = GetPointer<const gimple_phi>(curr_tn);
431 bool is_virtual =
false;
435 ssa = g_as_node->op0;
439 ssa = g_phi_node->res;
440 is_virtual = g_phi_node->virtual_flag;
443 if(ssa &&
GET_CONST_NODE(ssa)->get_kind() == ssa_name_K && !is_virtual)
449 const auto* ssaname = GetPointerS<const ssa_name>(
GET_CONST_NODE(ssa));
450 bool is_temporary = ssaname->var ? GetPointer<const decl_node>(
GET_NODE(ssaname->var))->artificial_flag :
true;
454 if(is_lost || has_no_meaning_in_software)
457 if(is_discrepancy_address)
464 if(has_no_meaning_in_software)
481 "Tree Node " +
STR(ssa->
index) +
" is has no meaning in software but is not an address");
493 if(is_discrepancy_address)
531 const auto STGMan = hls->STG;
532 const auto stg_info = STGMan->CGetStg()->CGetStateTransitionGraphInfo();
538 for(
const auto& s : STGMan->get_starting_states(statement))
540 init_state_ids.insert(stg_info->vertex_to_state_id.at(s));
542 for(
const auto& s : STGMan->get_execution_states(statement))
544 exec_state_ids.insert(stg_info->vertex_to_state_id.at(s));
546 for(
const auto& s : STGMan->get_ending_states(statement))
548 end_state_ids.insert(stg_info->vertex_to_state_id.at(s));
551 THROW_ASSERT(!init_state_ids.empty(),
"operation not properly scheduled: " 552 "number of init states = " +
553 STR(init_state_ids.size()));
554 THROW_ASSERT(!exec_state_ids.empty(),
"operation not properly scheduled: " 555 "number of exec states = " +
556 STR(exec_state_ids.size()));
557 THROW_ASSERT(!end_state_ids.empty(),
"operation not properly scheduled: " 558 "number of ending states = " +
559 STR(end_state_ids.size()));
564 for(
const auto& s : init_state_ids)
569 for(
const auto& s : exec_state_ids)
574 for(
const auto& s : end_state_ids)
584 if(ssa_bitsize > type_bitsize)
586 THROW_ERROR(std::string(
"variable size mismatch: ") +
"ssa node id = " +
STR(ssa->
index) +
" has size = " +
587 STR(ssa_bitsize) +
" type node id = " +
STR(ssa_type->index) +
" has size = " +
STR(type_bitsize));
592 STR(ssa->
index) +
"; ssa " + var_name +
"; btsz " +
STR(ssa_bitsize) +
603 STR(type_bitsize) +
");\n");
613 THROW_ASSERT(!(is_discrepancy_address && (is_real || is_complex)),
614 "variable " +
STR(var_name) +
" with node id " +
STR(ssa->
index) +
" has type id = " +
615 STR(ssa_type->index) +
" is complex = " +
STR(is_complex) +
" is real = " +
STR(is_real));
617 auto vec_base_bitsize = type_bitsize;
621 "ssa node id = " +
STR(ssa->
index) +
" type node id = " +
STR(ssa_type->index));
626 "ssa node id = " +
STR(ssa->
index) +
" type node id = " +
STR(ssa_type->index) +
627 " type_bitsize = " +
STR(type_bitsize) +
" elem_bitsize = " +
STR(elem_bitsize));
629 vec_base_bitsize = elem_bitsize;
640 THROW_ASSERT(vec_base_bitsize % 2 == 0,
"complex variables must have size multiple of 2" 642 STR(ssa->
index) +
"\ntype node id = " +
STR(ssa_type->index) +
643 "\nvec_base_bitsize = " +
STR(vec_base_bitsize));
660 if(is_discrepancy_address)
674 if(rhs->get_kind() == call_expr_K || rhs->get_kind() == aggr_init_expr_K)
678 THROW_ASSERT(!node_info->called.empty(),
"rhs of gimple_assign node " +
STR(st_tn_id) +
679 " is a call_expr but does not actually call a function");
680 THROW_ASSERT(node_info->called.size() == 1,
"rhs of gimple_assign node " +
STR(st_tn_id) +
681 " is a call_expr but calls more than a function");
682 const auto called_id = *node_info->called.begin();
683 const auto BHC =
HLSMgr->CGetFunctionBehavior(called_id)->CGetBehavioralHelper();
684 if(BHC->has_implementation() && BHC->function_has_to_be_printed(called_id))
686 const auto ce = GetPointerS<const call_expr>(rhs);
687 const auto& actual_args = ce->args;
689 if(op0->get_kind() == addr_expr_K && (actual_args.size() == 1 || actual_args.size() == 2))
691 const auto ue = GetPointerS<const unary_expr>(op0);
694 "tree node not currently supported " + fn->get_kind_text());
695 const auto fd = GetPointerS<const function_decl>(fn);
698 static const std::map<std::string, std::pair<unsigned int, std::string>>
699 basic_unary_operations_relation = {
708 {
"__int64_to_float32e8m23b_127nih",
710 {
"__int64_to_float64e11m52b_1023nih",
717 {
"__float32_to_int64_round_to_zeroe8m23b_127nih",
719 {
"__float32_to_uint32_round_to_zeroe8m23b_127nih",
721 {
"__float32_to_uint64_round_to_zeroe8m23b_127nih",
723 {
"__float64_to_int32_round_to_zeroe11m52b_1023nih",
725 {
"__float64_to_int64_round_to_zeroe11m52b_1023nih",
727 {
"__float64_to_uint32_round_to_zeroe11m52b_1023nih",
729 {
"__float64_to_uint64_round_to_zeroe11m52b_1023nih",
732 static const std::map<std::string, std::pair<bool, std::string>> basic_binary_operations_relation =
734 {
"__float_adde8m23b_127nih", {
false,
"+"}},
735 {
"__float_sube8m23b_127nih", {
false,
"-"}},
736 {
"__float_mule8m23b_127nih", {
false,
"*"}},
737 {
"__float_divSRT4e8m23b_127nih", {
false,
"/"}},
738 {
"__float_divGe8m23b_127nih", {
false,
"/"}},
739 {
"__float_lee8m23b_127nih", {
false,
"<="}},
740 {
"__float_lte8m23b_127nih", {
false,
"<"}},
741 {
"__float_gee8m23b_127nih", {
false,
">="}},
742 {
"__float_gte8m23b_127nih", {
false,
">"}},
743 {
"__float_eqe8m23b_127nih", {
false,
"=="}},
744 {
"__float_ltgt_quiete8m23b_127nih", {
false,
"!="}},
745 {
"__float_adde11m52b_1023nih", {
true,
"+"}},
746 {
"__float_sube11m52b_1023nih", {
true,
"-"}},
747 {
"__float_mule11m52b_1023nih", {
true,
"*"}},
748 {
"__float_divSRT4e11m52b_1023nih", {
true,
"/"}},
749 {
"__float_divGe11m52b_1023nih", {
true,
"/"}},
750 {
"__float_lee11m52b_1023nih", {
true,
"<="}},
751 {
"__float_lte11m52b_1023nih", {
true,
"<"}},
752 {
"__float_gee11m52b_1023nih", {
true,
">="}},
753 {
"__float_gte11m52b_1023nih", {
true,
">"}},
754 {
"__float_eqe11m52b_1023nih", {
true,
"=="}},
755 {
"__float_ltgt_quiete11m52b_1023nih", {
true,
"!="}},
757 const auto unary_op_relation = basic_unary_operations_relation.find(oper->
get_name());
758 const auto binary_op_relation = basic_binary_operations_relation.find(oper->
get_name());
760 if(unary_op_relation != basic_unary_operations_relation.end() && actual_args.size() >= 1)
762 const auto& f_sign = unary_op_relation->second.first;
763 const auto& cast_op = unary_op_relation->second.second;
764 auto var1 = BHC->PrintVariable(
GET_INDEX_NODE(actual_args.at(0)));
765 auto res_name = var_name;
768 const std::string view_convert =
770 var1 = view_convert +
"(" + var1 +
")";
774 const std::string view_convert =
775 F_TYPE_OUT(f_sign) == FLOAT_TYPE ?
"_Int32_ViewConvert" :
"_Int64_ViewConvert";
776 res_name = view_convert +
"(" + res_name +
")";
778 const auto computation =
"(" + cast_op +
"(" + var1 +
"))";
779 const auto check_string0 =
"\"" + res_name +
"==" + computation +
"\"";
782 const auto check_string1 =
783 (
F_TYPE_OUT(f_sign) == FLOAT_TYPE ?
"_FPs32Mismatch_(" :
"_FPs64Mismatch_(") +
784 computation +
", " + res_name +
"," +
STR(
Param->getOption<
double>(OPT_max_ulp)) +
")";
786 (
F_TYPE_OUT(f_sign) == FLOAT_TYPE ?
"_CheckBuiltinFPs32_(" :
"_CheckBuiltinFPs64_(") +
787 check_string0 +
", " + check_string1 +
"," + computation +
"," + var_name +
"," + var1 +
793 const auto int_cast =
795 const auto fp_format =
F_TYPE_IN(f_sign) == FLOAT_TYPE ?
"%.20e" :
"%.35e";
797 "if(" + res_name +
"!=" + computation +
798 ") { printf(\"\\n\\n***********************************************************\\nERROR " 799 "ON A BASIC FLOATING POINT OPERATION : %s : expected=" +
800 int_format +
" res=" + int_format +
"a=%a (" + fp_format +
801 ")\\n***********************************************************\\n\\n\", " +
802 check_string0 +
", " + int_cast + computation +
", " + int_cast + res_name +
", " +
803 var1 +
", " + var1 +
");\nexit(1);\n}\n");
806 else if(binary_op_relation != basic_binary_operations_relation.end() && actual_args.size() >= 2)
808 const auto& is_double_type = binary_op_relation->second.first;
809 const auto& op_symbol = binary_op_relation->second.second;
810 const std::string view_convert = is_double_type ?
"_Int64_ViewConvert" :
"_Int32_ViewConvert";
812 view_convert +
"(" + BHC->PrintVariable(
GET_INDEX_NODE(actual_args.at(0))) +
")";
814 view_convert +
"(" + BHC->PrintVariable(
GET_INDEX_NODE(actual_args.at(1))) +
")";
815 const auto res_name = view_convert +
"(" + var_name +
")";
816 const auto computation =
"(" + var1 + op_symbol + var2 +
")";
817 const auto check_string0 =
"\"" + view_convert +
"(" + var_name +
")==" + computation +
"\"";
818 const auto check_string1 = (is_double_type ?
"_FPs64Mismatch_" :
"_FPs32Mismatch_") +
819 std::string(
"(") + computation +
", " + res_name +
"," +
820 STR(
Param->getOption<
double>(OPT_max_ulp)) +
")";
822 (is_double_type ?
"_CheckBuiltinFPs64_(" :
"_CheckBuiltinFPs32_(") + check_string0 +
", " +
823 check_string1 +
"," + computation +
"," + res_name +
"," + var1 +
"," + var2 +
");\n");
837 const bool is_hw_discrepancy =
Param->isOption(OPT_discrepancy_hw) &&
Param->getOption<
bool>(OPT_discrepancy_hw);
843 if(!is_hw_discrepancy)
846 long long unsigned int __bambu_discrepancy_tot_assigned_ssa = 0; 847 long long unsigned int __bambu_discrepancy_tot_lost_ssa = 0; 848 long long unsigned int __bambu_discrepancy_tot_check_ssa = 0; 849 long long unsigned int __bambu_discrepancy_tot_lost_addr_ssa = 0; 850 long long unsigned int __bambu_discrepancy_temp_lost_addr_ssa = 0; 851 long long unsigned int __bambu_discrepancy_opt_lost_addr_ssa = 0; 852 long long unsigned int __bambu_discrepancy_tot_lost_int_ssa = 0; 853 long long unsigned int __bambu_discrepancy_temp_lost_int_ssa = 0; 854 long long unsigned int __bambu_discrepancy_tot_check_addr_ssa = 0; 855 long long unsigned int __bambu_discrepancy_temp_check_addr_ssa = 0; 856 long long unsigned int __bambu_discrepancy_tot_check_int_ssa = 0; 857 long long unsigned int __bambu_discrepancy_temp_check_int_ssa = 0; 879 if(!is_hw_discrepancy)
882 if(
Param->isOption(OPT_cat_args))
885 " executed with: " +
Param->getOption<std::string>(OPT_cat_args) +
886 "\\n\", stdout);\n");
889 "\"Assigned ssa = %llu\\nChecked ssa = %llu\\nLost ssa = %llu\\n\", " 890 "__bambu_discrepancy_tot_assigned_ssa, __bambu_discrepancy_tot_check_ssa, " 891 "__bambu_discrepancy_tot_lost_ssa);\n");
894 "\"Normal ssa = %llu\\nAddress ssa = %llu\\n\", " 895 "__bambu_discrepancy_tot_lost_int_ssa + __bambu_discrepancy_tot_check_int_ssa, " 896 "__bambu_discrepancy_tot_lost_addr_ssa + __bambu_discrepancy_tot_check_addr_ssa);\n");
899 "\"CHECKED: %llu\\nNormal ssa = %llu\\nNormal tmp ssa = %llu\\nAddr ssa = %llu\\nAddr tmp ssa = %llu\\n\", " 900 "__bambu_discrepancy_tot_check_ssa, __bambu_discrepancy_tot_check_int_ssa, " 901 "__bambu_discrepancy_temp_check_int_ssa, " 902 "__bambu_discrepancy_tot_check_addr_ssa, __bambu_discrepancy_temp_check_addr_ssa);\n");
904 "\"LOST: %llu\\nNormal ssa lost = %llu\\nNormal tmp ssa lost = %llu\\nAddr ssa " 905 "lost = %llu\\nAddr tmp ssa lost = %llu\\nOpt tmp ssa lost = %llu\\n\", " 906 "__bambu_discrepancy_tot_lost_ssa, __bambu_discrepancy_tot_lost_int_ssa, " 907 "__bambu_discrepancy_temp_lost_int_ssa, " 908 "__bambu_discrepancy_tot_lost_addr_ssa, __bambu_discrepancy_temp_lost_addr_ssa, " 909 "__bambu_discrepancy_opt_lost_addr_ssa);\n");
917 const auto top_symbols =
Param->getOption<std::vector<std::string>>(OPT_top_functions_names);
918 THROW_ASSERT(top_symbols.size() == 1,
"Expected single top function name");
921 const auto behavioral_helper = fun_behavior->CGetBehavioralHelper();
923 behavioral_helper->get_function_name() +
"_discrepancy.data";
934 "fprintf(__bambu_discrepancy_fp, \"CONTEXT LL_%llu\\n\", __bambu_discrepancy_context);\n");
935 if(
Param->isOption(OPT_discrepancy_hw) &&
Param->getOption<
bool>(OPT_discrepancy_hw))
943 for(
const auto& var_node :
HLSMgr->GetGlobalVariables())
949 "bitsize of a variable in memory must be multiple of 8 --> is " +
STR(bitsize));
951 " VAR_ADDR LL_%lu\\n\", &" +
952 STR(behavioral_helper->PrintVariable(var_node->index)) +
");//size " +
972 "fprintf(__bambu_discrepancy_fp, \"CONTEXT LL_%llu\\n\", __bambu_discrepancy_context);\n");
975 if(
Param->isOption(OPT_discrepancy_hw) &&
Param->getOption<
bool>(OPT_discrepancy_hw))
990 "bitsize of a variable in memory must be multiple of 8 --> is " +
STR(bitsize));
997 for(
const auto& var : to_be_declared)
999 if(FB->is_variable_mem(var))
1003 "bitsize of a variable in memory must be multiple of 8 --> is " +
STR(bitsize));
1013 const auto FB =
HLSMgr->CGetFunctionBehavior(function_index);
1014 const auto BH = FB->CGetBehavioralHelper();
1015 const auto funName = BH->get_function_name();
1017 THROW_ASSERT(GetPointer<function_decl>(node_fun),
"expected a function decl");
1019 (funName !=
"main");
1022 GetPointerS<function_decl>(node_fun)->static_flag =
true;
1027 GetPointerS<function_decl>(node_fun)->static_flag =
false;
1034 STR(bb_number) +
"\\n\");\n");
1039 const auto FB =
HLSMgr->CGetFunctionBehavior(funId);
1040 const auto BH = FB->CGetBehavioralHelper();
1041 const auto funName = BH->get_function_name();
1043 THROW_ASSERT(GetPointer<function_decl>(node_fun),
"expected a function decl");
1044 const auto prepend_static =
1048 GetPointerS<function_decl>(node_fun)->static_flag =
true;
1053 GetPointerS<function_decl>(node_fun)->static_flag =
false;
#define GET_NODE(t)
Macro used to hide implementation details when accessing a tree_node from another tree_node...
void WriteGlobalDeclarations() override
Writes the global declarations.
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
static bool IsUnionType(const tree_nodeConstRef &type)
Return if treenode is an union.
static bool IsComplexType(const tree_nodeConstRef &type)
Return if treenode is a complex.
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;.
void WriteFunctionDeclaration(const unsigned int funId) override
Writes the declaration of the function whose id in the tree is funId.
const CBackendInformationConstRef c_backend_info
Backend information.
This file contains the structures needed to manage a graph that will represent the state transition g...
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.
int debug_level
the debug level
Definition of the class representing a generic C application.
void WriteBBHeader(const unsigned int bb_number, const unsigned int function_index) override
mathematical utility function not provided by standard libraries
std::vector< tree_nodeRef > GetParameters() const
Return the list of index of original parameters of the function.
void WriteFunctionImplementation(unsigned int function_index) override
Write function implementation.
static bool is_static(const tree_managerConstRef &TM, const unsigned int index)
FIXME: to be remove after substitution with IsStaticDeclaration.
static tree_nodeConstRef CGetElements(const tree_nodeConstRef &type)
Given an array or a vector return the element type.
std::string c_trace_filename
name of the file that contains the c trace to parse
void WriteExtraCodeBeforeEveryMainCall() override
unsigned int get_function_index() const
Return the index of the function.
Collect information about resource performance.
Class to print indented code.
time_infoRef time_m
class representing the timing information associated with this operation
#define BUILTIN_WAIT_CALL
constant defining the builtin wait call intrinsic function
#define GET_INDEX_NODE(t)
Macro used to hide implementation details when accessing a tree_node from another tree_node...
unsigned long long n_checked_operations
TreeNodeSet ssa_to_skip_if_address
Set of tree nodes.
const tree_managerConstRef TM
The tree manager.
void DeclareLocalVariables(const CustomSet< unsigned int > &to_be_declared, CustomSet< unsigned int > &already_declared_variables, CustomSet< std::string > &locally_declared_type, const BehavioralHelperConstRef BH, const var_pp_functorConstRef varFunc) override
Declares the local variable; in case the variable used in the initialization of curVar hasn't been de...
void WriteExtraInitCode() override
Write additional initialization code needed by subclasses.
const tree_nodeConstRef CGetTreeNode(const unsigned int i) const
bool has_implementation() const
Return true if function has implementation.
virtual void WriteFunctionDeclaration(const unsigned int funId)
Writes the declaration of the function whose id in the tree is funId.
unsigned int get_cycles() const
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.
Auxiliary methods for manipulating string.
void WriteTestbenchFunctionCall(const BehavioralHelperConstRef behavioral_helper)
Writes a call to the top function to be tested, using its parameters.
const OpNodeInfoConstRef CGetOpNodeInfo(const vertex node) const
Returns the info associated with a node.
static bool is_large_integer(const tree_nodeConstRef &_tn)
const IndentedOutputStreamRef indented_output_stream
Represents the stream we are currently writing to.
static unsigned long long Size(const tree_nodeConstRef &tn)
Return the size of a tree object.
#define EXIT_ID
constant used to represent tree node index of exit operation
static bool IsSystemType(const tree_nodeConstRef &type)
Return true if variable or type is a system one.
This class specifies the characteristic of a particular operation working on a given functional unit...
void WriteParamInitialization(const BehavioralHelperConstRef behavioral_helper, const std::map< std::string, std::string > &curr_test_vector)
Initialize the parameters of the function.
const ParameterConstRef Param
set of parameters
void Append(const std::string &str)
Append a string to the output.
This class writes different HDL based descriptions (VHDL, Verilog, SystemC) starting from a structura...
Class specification of the data structures used to manage technology information. ...
TreeNodeSet address_ssa
Set of tree nodes representing the ssa_name to be treated as addresses in discrepancy analysis...
#define F_TYPE_IN(f_sign)
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...
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
static bool IsVectorType(const tree_nodeConstRef &type)
Return true if the treenode is a vector.
This file contains the structures needed to manage a graph that will represent the state transition g...
void WriteMainTestbench() override
Writes the main() of the testbench C program.
const std::string & get_name() const override
Returns the name of the operation.
#define GET_CONST_NODE(t)
const BehavioralHelperConstRef CGetBehavioralHelper() const
Returns the helper associated with the function.
static std::string NormalizeTypename(const std::string &id)
Return normalized name of types and variables.
bool function_has_to_be_printed(unsigned int f_id) const
returns true if the function body has to be printed by the C backend
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
std::string PrintVariable(unsigned int var) const
Print the name of the variable associated to the index.
T compute_n_bytes(T bitsize)
This file collects some utility functions.
tree_nodeRef GetTreeNode(const unsigned int index) const
Return the index-th tree_node (modifiable version)
DiscrepancyAnalysisCWriter(const CBackendInformationConstRef _c_backend_information, const HLS_managerConstRef _HLSMgr, const InstructionWriterRef _instruction_writer, const IndentedOutputStreamRef _indented_output_stream, const ParameterConstRef _parameters, bool _verbose)
Constructor.
void WriteBuiltinWaitCall() override
Writes implementation of __builtin_wait_call.
const HLS_managerConstRef HLSMgr
the hls manager
TreeNodeSet ssa_to_skip
Set of tree nodes representing the ssa_name to be skipped in discrepancy analysis.
void writePreInstructionInfo(const FunctionBehaviorConstRef FB, const vertex statement) override
Write extra information on the given statement vertex, before the statement itself.
This class describes all classes used to represent a structural object.
Class specification of the tree_reindex support class.
#define ENTRY_ID
constant used to represent tree node index of entry operation
Data structure used to store the functional-unit binding of the vertexes.
const OpGraphConstRef CGetOpGraph(FunctionBehavior::graph_type gt) const
This method returns the operation graphs.
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...
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.
void writePostInstructionInfo(const FunctionBehaviorConstRef fun_behavior, const vertex) override
Write extra information on the given statement vertex, after the statement itself.
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.
static bool IsStructType(const tree_nodeConstRef &type)
Return true if treenode is a record.
static bool is_extern(const tree_managerConstRef &TM, const unsigned int index)
FIXME: to be remove after substitution with IsExternDeclaration.
virtual void WriteBuiltinWaitCall()
Writes implementation of __builtin_wait_call.
#define F_TYPE_OUT(f_sign)
this class is used to manage the command-line or XML options.
virtual void WriteGlobalDeclarations()
Writes the global declarations.
Control flow graph with feedback.
Data structure that contains all information about high level synthesis process.
#define GET_INDEX_CONST_NODE(t)
void WriteTestbenchHelperFunctions()
Data structure definition for high-level synthesis flow.
static tree_nodeConstRef GetFunctionReturnType(const tree_nodeConstRef &function, bool void_as_null=true)
Return the return type of a function.
tree_nodeRef GetFunction(const std::string &function_name) const
Return the index of a function given its name.
void WriteParamDecl(const BehavioralHelperConstRef behavioral_helper)
Write declaration of the top function parameters.
Datastructure to represent memory information in high-level synthesis.
Class specification of the manager of the tree structures extracted from the raw file.
virtual void WriteFunctionImplementation(unsigned int function_id)
Write function implementation.
static bool IsRealType(const tree_nodeConstRef &type)
Return true if the treenode is of real type.
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...