Skip to content

Commit

Permalink
gather remaining inputs and create netlist graph
Browse files Browse the repository at this point in the history
  • Loading branch information
SJulianS committed May 21, 2024
1 parent 006fe3c commit e9651e5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
13 changes: 13 additions & 0 deletions plugins/hawkeye/include/hawkeye/state_candidate.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#pragma once

#include "graph_algorithm/netlist_graph.h"
#include "hal_core/defines.h"
#include "hawkeye/register_candidate.h"

Expand Down Expand Up @@ -54,6 +55,13 @@ namespace hal
*/
Netlist* get_netlist() const;

/**
* Get the netlist graph of the state candidate.
*
* @returns The netlist graph.
*/
graph_algorithm::NetlistGraph* get_graph() const;

/**
* Get the size of the candidate, i.e., the width of its registers.
*
Expand Down Expand Up @@ -116,6 +124,11 @@ namespace hal
*/
std::unique_ptr<Netlist> m_netlist;

/**
* The netlist to which the candidate belongs.
*/
std::unique_ptr<graph_algorithm::NetlistGraph> m_graph;

/**
* The bit-size of the candidate.
*/
Expand Down
9 changes: 8 additions & 1 deletion plugins/hawkeye/python/python_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,19 @@ namespace hal
)");

py_hawkeye_state_candidate.def("get_netlist", &hawkeye::StateCandidate::get_netlist, R"(
Get the netlist associated with the candidate.
Get the netlist of the state candidate. The netlist will be a partial copy of the netlist of the register candidate.
:returns: The netlist of the candidate.
:rtype: hal_py.Netlist
)");

py_hawkeye_state_candidate.def("get_graph", &hawkeye::StateCandidate::get_graph, R"(
Get the netlist graph of the state candidate.
:returns: The netlist graph of the candidate.
:rtype: graph_algorithm.NetlistGraph
)");

py_hawkeye_state_candidate.def("get_size", &hawkeye::StateCandidate::get_size, R"(
Get the size of the candidate, i.e., the width of its registers.
Expand Down
40 changes: 32 additions & 8 deletions plugins/hawkeye/src/state_candidate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,16 @@ namespace hal
log_info("hawkeye", "successfully identified control inputs in {} seconds", duration_in_seconds);

// copy partial netlist
auto state_cand = StateCandidate();
state_cand.m_netlist = netlist_factory::create_netlist(candidate->get_netlist()->get_gate_library());
auto* copied_nl = state_cand.m_netlist.get();
auto state_cand = std::make_unique<StateCandidate>();
state_cand->m_netlist = std::move(netlist_factory::create_netlist(candidate->get_netlist()->get_gate_library()));
auto* copied_nl = state_cand->m_netlist.get();

state_cand->m_size = candidate->get_size();

for (const auto* g : candidate->get_input_reg())
{
auto* new_g = copied_nl->create_gate(g->get_id(), g->get_type(), g->get_name());
state_cand.m_in_reg.insert(new_g);
state_cand->m_in_reg.insert(new_g);

copy_out_eps_of_gate(copied_nl, g, new_g, &state_inputs); // only fan-out EPs for state input register
}
Expand All @@ -199,7 +201,7 @@ namespace hal
{
auto* new_g = copied_nl->create_gate(g->get_id(), g->get_type(), g->get_name());
new_g->set_data_map(g->get_data_map()); // take care of LUT INIT strings
state_cand.m_state_logic.insert(new_g);
state_cand->m_state_logic.insert(new_g);

copy_in_eps_of_gate(copied_nl, g, new_g);
copy_out_eps_of_gate(copied_nl, g, new_g);
Expand All @@ -210,7 +212,7 @@ namespace hal
for (const auto* g : candidate->get_output_reg())
{
auto* new_g = copied_nl->create_gate(g->get_id(), g->get_type(), g->get_name());
state_cand.m_out_reg.insert(new_g);
state_cand->m_out_reg.insert(new_g);

copy_in_eps_of_gate(copied_nl, g, new_g, &state_outputs); // only fan-in EPs for state output register
}
Expand All @@ -222,20 +224,42 @@ namespace hal
{
// only differences: do not enforce ID (already taken by in_reg FF) and append suffix to name
auto* new_g = copied_nl->create_gate(g->get_type(), g->get_name() + "_OUT");
state_cand.m_out_reg.insert(new_g);
state_cand->m_out_reg.insert(new_g);

copy_in_eps_of_gate(copied_nl, g, new_g, &state_outputs); // only fan-in EPs for state output register
}
}

// TODO fill control and other inputs
for (const auto* control_net : control_inputs)
{
state_cand->m_state_inputs.insert(copied_nl->get_net_by_id(control_net->get_id()));
}

for (const auto* other_net : other_inputs)
{
state_cand->m_state_inputs.insert(copied_nl->get_net_by_id(other_net->get_id()));
}

auto nl_graph_res = graph_algorithm::NetlistGraph::from_netlist(copied_nl);
if (nl_graph_res.is_error())
{
return ERR(nl_graph_res.get_error());
}
state_cand->m_graph = std::move(nl_graph_res.get());

return OK(std::move(state_cand));
}

Netlist* StateCandidate::get_netlist() const
{
return m_netlist.get();
}

graph_algorithm::NetlistGraph* StateCandidate::get_graph() const
{
return m_graph.get();
}

u32 StateCandidate::get_size() const
{
return m_size;
Expand Down

0 comments on commit e9651e5

Please sign in to comment.