Skip to content

Commit

Permalink
Merge pull request #130 from ferrandi/fix/hls_soft_div
Browse files Browse the repository at this point in the history
Fix/hls soft div
  • Loading branch information
Ansaya committed Feb 28, 2023
2 parents bfa48cc + 9f820d7 commit 0b02cb3
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 40 deletions.
4 changes: 4 additions & 0 deletions panda_regressions/hls/bambu_specific_test/soft_mul.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
long long soft_mul(long long a, long long b)
{
return a * b;
}
18 changes: 9 additions & 9 deletions panda_regressions/hls/bambu_specific_test_list
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
bambu_specific_test/930608-1.c.gimplePSSA --use-raw -s --expose-globals
bambu_specific_test/990829-1.c.gimplePSSA --use-raw
bambu_specific_test/20020108-1.c.gimplePSSA --use-raw
bambu_specific_test/bambu1.c -O0 --configuration-name=O0
bambu_specific_test/memset-chk.c -O0 --configuration-name=O0
bambu_specific_test/bambu1.c -O1 --configuration-name=O1
bambu_specific_test/memset-chk.c -O1 --configuration-name=O1
bambu_specific_test/bambu1.c -O2 --configuration-name=O2
bambu_specific_test/memset-chk.c -O2 --configuration-name=O2
bambu_specific_test/bambu1.c -O3 --configuration-name=O3
bambu_specific_test/990829-1.c.gimplePSSA --use-raw
bambu_specific_test/20020108-1.c.gimplePSSA --use-raw
bambu_specific_test/930608-1.c.gimplePSSA --use-raw -s --expose-globals
bambu_specific_test/pta-field-1.c.gimplePSSA --use-raw -O1
bambu_specific_test/divconst-2.c.gimplePSSA --use-raw
bambu_specific_test/memset-chk.c -O0 --configuration-name=O0
bambu_specific_test/memset-chk.c -O1 --configuration-name=O1
bambu_specific_test/memset-chk.c -O2 --configuration-name=O2
bambu_specific_test/pr35472.c.gimplePSSA --use-raw -O3
bambu_specific_test/pta-field-1.c.gimplePSSA --use-raw -O1
bambu_specific_test/soft_mul.c --top-fname=soft_mul --device-name=nx1h140tsp --generate-tb=a=4,b=5
bambu_specific_test/unsafe-fp-assoc-1.c.gimplePSSA --use-raw --pretty-print=output.c
bambu_specific_test/divconst-2.c.gimplePSSA --use-raw

64 changes: 34 additions & 30 deletions src/frontend_analysis/IR_analysis/hls_div_cg_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,35 +139,39 @@ DesignFlowStep_Status hls_div_cg_ext::InternalExec()
const tree_manipulationRef tree_man(new tree_manipulation(TreeM, parameters, AppM));

const auto curr_tn = TreeM->GetTreeNode(function_id);
const auto fd = GetPointerS<function_decl>(curr_tn);
const auto sl = GetPointerS<statement_list>(GET_NODE(fd->body));

THROW_ASSERT(GetPointer<const HLS_manager>(AppM)->get_HLS_target(), "unexpected condition");
const auto hls_target = GetPointer<const HLS_manager>(AppM)->get_HLS_target();
if(hls_target->get_target_device()->has_parameter("use_soft_64_mul") &&
hls_target->get_target_device()->get_parameter<size_t>("use_soft_64_mul"))
const auto fname = tree_helper::GetFunctionName(TreeM, curr_tn);
if(fname != "__umul64" && fname != "__mul64")
{
use64bitMul = true;
}
const auto fd = GetPointerS<function_decl>(curr_tn);
const auto sl = GetPointerS<statement_list>(GET_NODE(fd->body));

bool modified = false;
for(const auto& idx_bb : sl->list_of_bloc)
{
const auto& BB = idx_bb.second;
for(const auto& stmt : BB->CGetStmtList())
THROW_ASSERT(GetPointer<const HLS_manager>(AppM)->get_HLS_target(), "unexpected condition");
const auto hls_target = GetPointer<const HLS_manager>(AppM)->get_HLS_target();
if(hls_target->get_target_device()->has_parameter("use_soft_64_mul") &&
hls_target->get_target_device()->get_parameter<size_t>("use_soft_64_mul"))
{
INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level,
"-->Examine " + STR(GET_INDEX_NODE(stmt)) + " " + GET_NODE(stmt)->ToString());
modified |= recursive_examinate(stmt, stmt, tree_man);
INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level,
"<--Examined " + STR(GET_INDEX_NODE(stmt)) + " " + GET_NODE(stmt)->ToString());
use64bitMul = true;
}
}

if(modified)
{
function_behavior->UpdateBBVersion();
return DesignFlowStep_Status::SUCCESS;
bool modified = false;
for(const auto& idx_bb : sl->list_of_bloc)
{
const auto& BB = idx_bb.second;
for(const auto& stmt : BB->CGetStmtList())
{
INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level,
"-->Examine " + STR(GET_INDEX_NODE(stmt)) + " " + GET_NODE(stmt)->ToString());
modified |= recursive_examinate(stmt, stmt, tree_man);
INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level,
"<--Examined " + STR(GET_INDEX_NODE(stmt)) + " " + GET_NODE(stmt)->ToString());
}
}

if(modified)
{
function_behavior->UpdateBBVersion();
return DesignFlowStep_Status::SUCCESS;
}
}
return DesignFlowStep_Status::UNCHANGED;
}
Expand Down Expand Up @@ -215,11 +219,11 @@ bool hls_div_cg_ext::recursive_examinate(const tree_nodeRef& current_tree_node,
const auto expr_type = tree_helper::CGetType(ce->args.at(0));
const auto me = tree_man->create_binary_operation(expr_type, ce->args.at(0), ce->args.at(1),
BUILTIN_SRCP, mult_expr_K);
INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Replaced " + STR(current_statement));
TreeM->ReplaceTreeNode(current_statement, current_tree_node, me);
AppM->GetCallGraphManager()->RemoveCallPoint(function_id, GET_INDEX_CONST_NODE(fnode),
GET_INDEX_CONST_NODE(current_statement));
INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level,
"---Replaced " + STR(current_tree_node) + " -> " + STR(ce));
INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "--- -> " + STR(current_statement));
modified = true;
}
}
Expand Down Expand Up @@ -295,12 +299,12 @@ bool hls_div_cg_ext::recursive_examinate(const tree_nodeRef& current_tree_node,
INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Adding call to " + fu_name);
const std::vector<tree_nodeRef> args = {be->op0, be->op1};
const auto ce = tree_man->CreateCallExpr(called_function, args, get_current_srcp());
INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Replaced " + STR(current_statement));
TreeM->ReplaceTreeNode(current_statement, current_tree_node, ce);
CallGraphManager::addCallPointAndExpand(already_visited, AppM, function_id, called_function->index,
GET_INDEX_CONST_NODE(current_statement),
FunctionEdgeInfo::CallType::direct_call, DEBUG_LEVEL_NONE);
INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level,
"---Replaced " + STR(current_tree_node) + " -> " + STR(ce));
INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "--- -> " + STR(current_statement));
modified = true;
}
}
Expand All @@ -321,12 +325,12 @@ bool hls_div_cg_ext::recursive_examinate(const tree_nodeRef& current_tree_node,
INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Adding call to " + fname);
const std::vector<tree_nodeRef> args = {be->op0, be->op1};
const auto ce = tree_man->CreateCallExpr(called_function, args, get_current_srcp());
INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Replaced " + STR(current_statement));
TreeM->ReplaceTreeNode(current_statement, current_tree_node, ce);
CallGraphManager::addCallPointAndExpand(already_visited, AppM, function_id, called_function->index,
GET_INDEX_CONST_NODE(current_statement),
FunctionEdgeInfo::CallType::direct_call, DEBUG_LEVEL_NONE);
INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level,
"---Replaced " + STR(current_tree_node) + " -> " + STR(ce));
INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "--- -> " + STR(current_statement));
modified = true;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/frontend_analysis/IR_analysis/hls_div_cg_ext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class hls_div_cg_ext : public FunctionFrontendFlowStep
/// Already visited tree node (used to avoid infinite recursion)
CustomUnorderedSet<unsigned int> already_visited;

protected:
const tree_managerRef TreeM;

bool use64bitMul;
Expand Down

0 comments on commit 0b02cb3

Please sign in to comment.