Skip to content

Commit

Permalink
Refactoring to dynamic cast overhead
Browse files Browse the repository at this point in the history
  • Loading branch information
Ansaya committed May 6, 2024
1 parent cae0a03 commit 0aec1c4
Show file tree
Hide file tree
Showing 11 changed files with 252 additions and 261 deletions.
2 changes: 1 addition & 1 deletion src/HLS/hls_function_step.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void HLSFunctionStep::ComputeRelationships(DesignFlowStepSet& design_flow_step_s
const DesignFlowStep::RelationshipType relationship_type)
{
INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Computing relationships of " + GetName());
const auto hls_flow_step_factory = GetPointer<const HLSFlowStepFactory>(CGetDesignFlowStepFactory());
const auto hls_flow_step_factory = GetPointerS<const HLSFlowStepFactory>(CGetDesignFlowStepFactory());
const auto DFM = design_flow_manager.lock();
const auto DFG = DFM->CGetDesignFlowGraph();
const auto CGM = HLSMgr->CGetCallGraphManager();
Expand Down
12 changes: 6 additions & 6 deletions src/HLS/hls_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ std::string HLS_manager::get_constant_string(unsigned int node_id, unsigned long
else if(tree_helper::IsComplexType(node_type))
{
const auto cc = GetPointerS<const complex_cst>(node);
const auto rcc = GetPointer<const real_cst>(cc->real);
std::string trimmed_value_r;
if(rcc)
if(cc->real->get_kind() == real_cst_K)
{
const auto rcc = GetPointerS<const real_cst>(cc->real);
std::string C_value_r = rcc->valr;
if(C_value_r == "Inf")
{
Expand All @@ -207,10 +207,10 @@ std::string HLS_manager::get_constant_string(unsigned int node_id, unsigned long
{
trimmed_value_r = convert_to_binary(tree_helper::GetConstValue(cc->real), precision / 2);
}
const auto icc = GetPointer<const real_cst>(cc->imag);
std::string trimmed_value_i;
if(icc)
if(cc->imag->get_kind() == real_cst_K)
{
const auto icc = GetPointerS<const real_cst>(cc->imag);
std::string C_value_i = icc->valr;
if(C_value_i == "Inf")
{
Expand Down Expand Up @@ -296,8 +296,8 @@ bool HLS_manager::is_register_compatible(unsigned int var) const
bool HLS_manager::is_reading_writing_function(unsigned funID) const
{
auto fun_node = TM->GetTreeNode(funID);
auto fd = GetPointer<function_decl>(fun_node);
THROW_ASSERT(fd, "unexpected condition");
THROW_ASSERT(fun_node->get_kind() == function_decl_K, "unexpected condition");
auto fd = GetPointerS<function_decl>(fun_node);
return fd->reading_memory || fd->writing_memory;
}

Expand Down
6 changes: 3 additions & 3 deletions src/HLS/hls_step.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ void HLS_step::ComputeRelationships(DesignFlowStepSet& design_flow_step_set,
const DesignFlowStep::RelationshipType relationship_type)
{
INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Computing relationships of " + GetName());
const auto hls_flow_step_factory = GetPointer<const HLSFlowStepFactory>(CGetDesignFlowStepFactory());
const auto hls_flow_step_factory = GetPointerS<const HLSFlowStepFactory>(CGetDesignFlowStepFactory());
const auto DFM = design_flow_manager.lock();
const auto DFG = DFM->CGetDesignFlowGraph();
const auto CGM = HLSMgr->CGetCallGraphManager();
Expand All @@ -310,7 +310,7 @@ void HLS_step::ComputeRelationships(DesignFlowStepSet& design_flow_step_set,
case HLSFlowStep_Relationship::TOP_FUNCTION:
{
const auto frontend_flow_step_factory =
GetPointer<const FrontendFlowStepFactory>(DFM->CGetDesignFlowStepFactory(DesignFlowStep::FRONTEND));
GetPointerS<const FrontendFlowStepFactory>(DFM->CGetDesignFlowStepFactory(DesignFlowStep::FRONTEND));
const auto call_graph_computation_step =
DFM->GetDesignFlowStep(ApplicationFrontendFlowStep::ComputeSignature(COMPLETE_CALL_GRAPH));
const auto cg_design_flow_step =
Expand Down Expand Up @@ -338,7 +338,7 @@ void HLS_step::ComputeRelationships(DesignFlowStepSet& design_flow_step_set,
case HLSFlowStep_Relationship::ALL_FUNCTIONS:
{
const auto frontend_flow_step_factory =
GetPointer<const FrontendFlowStepFactory>(DFM->CGetDesignFlowStepFactory(DesignFlowStep::FRONTEND));
GetPointerS<const FrontendFlowStepFactory>(DFM->CGetDesignFlowStepFactory(DesignFlowStep::FRONTEND));
const auto call_graph_computation_step =
DFM->GetDesignFlowStep(ApplicationFrontendFlowStep::ComputeSignature(COMPLETE_CALL_GRAPH));
const auto cg_design_flow_step =
Expand Down
408 changes: 202 additions & 206 deletions src/HLS/module_allocation/allocation_information.cpp

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions src/behavior/OrderedInstructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ OrderedBasicBlock::OrderedBasicBlock(const blocRef& BasicB)

bool OrderedBasicBlock::dominates(const tree_nodeConstRef& A, const tree_nodeConstRef& B)
{
THROW_ASSERT(GetPointer<const gimple_node>(A)->bb_index == GetPointer<const gimple_node>(B)->bb_index,
THROW_ASSERT(GetPointerS<const gimple_node>(A)->bb_index == GetPointerS<const gimple_node>(B)->bb_index,
"Instructions must be in the same basic block!");
THROW_ASSERT(GetPointer<const gimple_node>(A)->bb_index == BB->number, "Instructions must be in the tracked block!");
THROW_ASSERT(GetPointerS<const gimple_node>(A)->bb_index == BB->number,
"Instructions must be in the tracked block!");

// Phi statements always comes before non-phi statements
if(A->get_kind() == gimple_phi_K && B->get_kind() != gimple_phi_K)
Expand Down Expand Up @@ -183,8 +184,8 @@ bool OrderedInstructions::dominates(const tree_nodeConstRef& InstA, const tree_n
THROW_ASSERT(InstA, "Instruction A cannot be null");
THROW_ASSERT(InstB, "Instruction B cannot be null");

const auto BBIA = GetPointer<const gimple_node>(InstA)->bb_index;
const auto BBIB = GetPointer<const gimple_node>(InstB)->bb_index;
const auto BBIA = GetPointerS<const gimple_node>(InstA)->bb_index;
const auto BBIB = GetPointerS<const gimple_node>(InstB)->bb_index;

// Use ordered basic block to do dominance check in case the 2 instructions
// are in the same basic block.
Expand All @@ -201,7 +202,7 @@ bool OrderedInstructions::dominates(const tree_nodeConstRef& InstA, const tree_n
THROW_ASSERT(BB->number == BBIA,
"Intermediate BB not allowed here"); // Intermediate BB shadows its incoming BB, thus its index
// is different from associated vertex
OBB = OBBMap.insert({BBIA, absl::make_unique<OrderedBasicBlock>(BB)}).first;
OBB = OBBMap.insert({BBIA, std::make_unique<OrderedBasicBlock>(BB)}).first;
}
return OBB->second->dominates(InstA, InstB);
}
Expand Down
50 changes: 22 additions & 28 deletions src/behavior/call_graph_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,7 @@ void CallGraphManager::AddFunctionAndCallPoint(const application_managerRef AppM
unsigned int called_id, unsigned int call_id,
enum FunctionEdgeInfo::CallType call_type)
{
if(tree_helper::print_function_name(
tree_manager, GetPointer<const function_decl>(tree_manager->GetTreeNode(called_id))) != BUILTIN_WAIT_CALL)
if(tree_helper::GetFunctionName(tree_manager, tree_manager->GetTreeNode(called_id)) != BUILTIN_WAIT_CALL)
{
if(!IsVertex(called_id))
{
Expand Down Expand Up @@ -446,8 +445,7 @@ void CallGraphManager::RemoveCallPoint(EdgeDescriptor e, const unsigned int call
void CallGraphManager::RemoveCallPoint(const unsigned int caller_id, const unsigned int called_id,
const unsigned int call_id)
{
const auto called_name = tree_helper::print_function_name(
tree_manager, GetPointer<const function_decl>(tree_manager->GetTreeNode(called_id)));
const auto called_name = tree_helper::GetFunctionName(tree_manager, tree_manager->GetTreeNode(called_id));
if(called_name == BUILTIN_WAIT_CALL)
{
return;
Expand All @@ -457,12 +455,8 @@ void CallGraphManager::RemoveCallPoint(const unsigned int caller_id, const unsig
EdgeDescriptor e;
bool found;
boost::tie(e, found) = boost::edge(caller_vertex, called_vertex, *CGetCallGraph());
#if HAVE_ASSERTS
const auto caller_name = "(" + STR(caller_id) + ") " +
tree_helper::print_function_name(
tree_manager, GetPointerS<const function_decl>(tree_manager->GetTreeNode(caller_id)));
#endif
THROW_ASSERT(found, "call id " + STR(call_id) + " is not a call point in function " + caller_name +
THROW_ASSERT(found, "call id " + STR(call_id) + " is not a call point in function (" + STR(caller_id) + ") " +
tree_helper::GetFunctionName(tree_manager, tree_manager->GetTreeNode(caller_id)) +
" for function (" + STR(called_id) + ") " + called_name);
RemoveCallPoint(e, call_id);
}
Expand Down Expand Up @@ -735,7 +729,7 @@ void CallGraphManager::call_graph_computation_recursive(CustomUnorderedSet<unsig
}
/// check for nested function
const tree_nodeRef fun = TM->GetTreeNode(ind);
const auto* fd = GetPointer<const function_decl>(fun);
const auto* fd = GetPointerS<const function_decl>(fun);
if(fd->scpe && fd->scpe->get_kind() == function_decl_K)
{
THROW_ERROR_CODE(NESTED_FUNCTIONS_EC, "Nested functions not yet supported " + STR(ind));
Expand All @@ -756,7 +750,7 @@ void CallGraphManager::call_graph_computation_recursive(CustomUnorderedSet<unsig
}
case gimple_return_K:
{
auto* re = GetPointer<gimple_return>(tn);
auto* re = GetPointerS<gimple_return>(tn);
if(re->op)
{
call_graph_computation_recursive(AV, AM, current, TM, re->op, node_stmt, call_type, DL);
Expand All @@ -765,7 +759,7 @@ void CallGraphManager::call_graph_computation_recursive(CustomUnorderedSet<unsig
}
case gimple_assign_K:
{
auto* me = GetPointer<gimple_assign>(tn);
auto* me = GetPointerS<gimple_assign>(tn);

INDENT_DBG_MEX(DEBUG_LEVEL_PEDANTIC, DL, "---Analyzing left part");
call_graph_computation_recursive(AV, AM, current, TM, me->op0, node_stmt, call_type, DL);
Expand All @@ -785,11 +779,11 @@ void CallGraphManager::call_graph_computation_recursive(CustomUnorderedSet<unsig
case aggr_init_expr_K:
case call_expr_K:
{
auto* ce = GetPointer<call_expr>(tn);
auto* ce = GetPointerS<call_expr>(tn);
tree_nodeRef fun_node = ce->fn;
if(fun_node->get_kind() == addr_expr_K)
{
auto* ue = GetPointer<unary_expr>(fun_node);
auto* ue = GetPointerS<unary_expr>(fun_node);
fun_node = ue->op;
}
else if(fun_node->get_kind() == obj_type_ref_K)
Expand All @@ -807,11 +801,11 @@ void CallGraphManager::call_graph_computation_recursive(CustomUnorderedSet<unsig
}
case gimple_call_K:
{
auto* ce = GetPointer<gimple_call>(tn);
auto* ce = GetPointerS<gimple_call>(tn);
tree_nodeRef fun_node = ce->fn;
if(fun_node->get_kind() == addr_expr_K)
{
auto* ue = GetPointer<unary_expr>(fun_node);
auto* ue = GetPointerS<unary_expr>(fun_node);
fun_node = ue->op;
}
else if(fun_node->get_kind() == obj_type_ref_K)
Expand All @@ -828,42 +822,42 @@ void CallGraphManager::call_graph_computation_recursive(CustomUnorderedSet<unsig
}
case cond_expr_K:
{
auto* ce = GetPointer<cond_expr>(tn);
auto* ce = GetPointerS<cond_expr>(tn);
call_graph_computation_recursive(AV, AM, current, TM, ce->op0, node_stmt, call_type, DL);
call_graph_computation_recursive(AV, AM, current, TM, ce->op1, node_stmt, call_type, DL);
call_graph_computation_recursive(AV, AM, current, TM, ce->op2, node_stmt, call_type, DL);
break;
}
case gimple_cond_K:
{
auto* gc = GetPointer<gimple_cond>(tn);
auto* gc = GetPointerS<gimple_cond>(tn);
call_graph_computation_recursive(AV, AM, current, TM, gc->op0, node_stmt, call_type, DL);
break;
}
/* Unary expressions. */
case CASE_UNARY_EXPRESSION:
{
auto* ue = GetPointer<unary_expr>(tn);
auto* ue = GetPointerS<unary_expr>(tn);
call_graph_computation_recursive(AV, AM, current, TM, ue->op, node_stmt, call_type, DL);
break;
}
case CASE_BINARY_EXPRESSION:
{
auto* be = GetPointer<binary_expr>(tn);
auto* be = GetPointerS<binary_expr>(tn);
call_graph_computation_recursive(AV, AM, current, TM, be->op0, node_stmt, call_type, DL);
call_graph_computation_recursive(AV, AM, current, TM, be->op1, node_stmt, call_type, DL);
break;
}
/*ternary expressions*/
case gimple_switch_K:
{
auto* se = GetPointer<gimple_switch>(tn);
auto* se = GetPointerS<gimple_switch>(tn);
call_graph_computation_recursive(AV, AM, current, TM, se->op0, node_stmt, call_type, DL);
break;
}
case gimple_multi_way_if_K:
{
auto* gmwi = GetPointer<gimple_multi_way_if>(tn);
auto* gmwi = GetPointerS<gimple_multi_way_if>(tn);
for(const auto& cond : gmwi->list_of_cond)
{
if(cond.first)
Expand Down Expand Up @@ -897,7 +891,7 @@ void CallGraphManager::call_graph_computation_recursive(CustomUnorderedSet<unsig
case insertelement_expr_K:
case bit_ior_concat_expr_K:
{
auto* te = GetPointer<ternary_expr>(tn);
auto* te = GetPointerS<ternary_expr>(tn);
call_graph_computation_recursive(AV, AM, current, TM, te->op0, node_stmt, call_type, DL);
call_graph_computation_recursive(AV, AM, current, TM, te->op1, node_stmt, call_type, DL);
if(te->op2)
Expand All @@ -908,7 +902,7 @@ void CallGraphManager::call_graph_computation_recursive(CustomUnorderedSet<unsig
}
case CASE_QUATERNARY_EXPRESSION:
{
auto* qe = GetPointer<quaternary_expr>(tn);
auto* qe = GetPointerS<quaternary_expr>(tn);
call_graph_computation_recursive(AV, AM, current, TM, qe->op0, node_stmt, call_type, DL);
call_graph_computation_recursive(AV, AM, current, TM, qe->op1, node_stmt, call_type, DL);
if(qe->op2)
Expand All @@ -923,7 +917,7 @@ void CallGraphManager::call_graph_computation_recursive(CustomUnorderedSet<unsig
}
case lut_expr_K:
{
auto* le = GetPointer<lut_expr>(tn);
auto* le = GetPointerS<lut_expr>(tn);
call_graph_computation_recursive(AV, AM, current, TM, le->op0, node_stmt, call_type, DL);
call_graph_computation_recursive(AV, AM, current, TM, le->op1, node_stmt, call_type, DL);
if(le->op2)
Expand Down Expand Up @@ -958,7 +952,7 @@ void CallGraphManager::call_graph_computation_recursive(CustomUnorderedSet<unsig
}
case constructor_K:
{
auto* c = GetPointer<constructor>(tn);
auto* c = GetPointerS<constructor>(tn);
for(const auto& i : c->list_of_idx_valu)
{
call_graph_computation_recursive(AV, AM, current, TM, i.second, node_stmt, call_type, DL);
Expand All @@ -968,7 +962,7 @@ void CallGraphManager::call_graph_computation_recursive(CustomUnorderedSet<unsig
case var_decl_K:
{
/// var decl performs an assignment when init is not null
auto* vd = GetPointer<var_decl>(tn);
auto* vd = GetPointerS<var_decl>(tn);
if(vd->init)
{
call_graph_computation_recursive(AV, AM, current, TM, vd->init, node_stmt, call_type, DL);
Expand Down
2 changes: 1 addition & 1 deletion src/behavior/op_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const std::string OpNodeInfo::GetOperation() const
}
THROW_ASSERT(node, "");
THROW_ASSERT(GetPointer<const gimple_node>(node), "Node is not a gimple_node but a " + node->get_kind_text());
return GetPointer<const gimple_node>(node)->operation;
return GetPointerS<const gimple_node>(node)->operation;
}

unsigned int OpNodeInfo::GetNodeId() const
Expand Down
4 changes: 2 additions & 2 deletions src/behavior/operations_graph_constructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ vertex operations_graph_constructor::getIndex(const std::string& source)
return index_map.find(source)->second;
}
NodeInfoRef node_info(new OpNodeInfo());
GetPointer<OpNodeInfo>(node_info)->vertex_name = source;
GetPointerS<OpNodeInfo>(node_info)->vertex_name = source;
const vertex v_og = og->AddVertex(node_info);
index_map[source] = v_og;
return index_map[source];
Expand Down Expand Up @@ -137,7 +137,7 @@ void operations_graph_constructor::AddOperation(const tree_managerRef TM, const
const unsigned int updated_node_id = op_graph->GetOpNodeInfo(current)->GetNodeId();
if(updated_node_id != 0 && updated_node_id != ENTRY_ID && updated_node_id != EXIT_ID)
{
GetPointer<gimple_node>(TM->GetTreeNode(updated_node_id))->operation = operation_t;
GetPointerS<gimple_node>(TM->GetTreeNode(updated_node_id))->operation = operation_t;
}
GET_NODE_INFO(og, OpNodeInfo, current)->bb_index = bb_index;
if(src == ENTRY)
Expand Down
2 changes: 1 addition & 1 deletion src/frontend_analysis/frontend_flow_step.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void FrontendFlowStep::CreateSteps(
const application_managerConstRef application_manager, DesignFlowStepSet& relationships)
{
const auto design_flow_graph = design_flow_manager->CGetDesignFlowGraph();
const auto frontend_flow_step_factory = GetPointer<const FrontendFlowStepFactory>(
const auto frontend_flow_step_factory = GetPointerS<const FrontendFlowStepFactory>(
design_flow_manager->CGetDesignFlowStepFactory(DesignFlowStep::FRONTEND));
for(const auto& [step_type, rel_type] : frontend_relationships)
{
Expand Down
Loading

0 comments on commit 0aec1c4

Please sign in to comment.