Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Remove dangling PIs and redundant POs during network parsing #321

Closed
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ struct fanout_substitution_params
* Maximum number of outputs any gate is allowed to have before substitution applies.
*/
uint32_t threshold = 1ul;
/**
* Omit dangling PIs.
*/
bool cleanup_dangling_pis = true;
/**
* Omit redundant POs, i.e. POs connected to a PI or constant.
*/
bool remove_redundant_pos = true;
};

namespace detail
Expand Down Expand Up @@ -135,6 +143,12 @@ class fanout_substitution_impl
// restore signal names if applicable
fiction::restore_names(ntk_topo, substituted, old2new);

// Remove dangling PIs and POs
if (ps.cleanup_dangling_pis || ps.remove_redundant_pos)
{
substituted = mockturtle::cleanup_dangling(substituted, ps.cleanup_dangling_pis, ps.remove_redundant_pos);
}

return substituted;
}

Expand Down
18 changes: 18 additions & 0 deletions test/algorithms/network_transformation/fanout_substitution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,21 @@ TEST_CASE("Consistent fanout substitution after balancing", "[fanout-substitutio
auto balanced_tec = network_balancing<technology_network>(substituted_tec);
CHECK(is_fanout_substituted(balanced_tec));
}

TEST_CASE("Cleanup dangling PIs", "[fanout-substitution]")
{
const auto aig = blueprints::maj4_network<mockturtle::aig_network>();
const auto aig_with_dangling_pi = blueprints::dangling_pi_network<mockturtle::aig_network>();

fanout_substitution_params ps_breadth{fanout_substitution_params::substitution_strategy::BREADTH, 3, 1, true, true};
simon1hofmann marked this conversation as resolved.
Show resolved Hide resolved
const auto substituted_breadth = fanout_substitution<technology_network>(aig_with_dangling_pi, ps_breadth);
CHECK(substituted_breadth.size() == (aig.size() + 35));
CHECK(is_fanout_substituted(substituted_breadth, ps_breadth));
check_eq(aig, substituted_breadth);

fanout_substitution_params ps_depth{fanout_substitution_params::substitution_strategy::DEPTH, 2, 2, true, true};
simon1hofmann marked this conversation as resolved.
Show resolved Hide resolved
const auto substituted_depth = fanout_substitution<technology_network>(aig_with_dangling_pi, ps_depth);
CHECK(substituted_depth.size() == (aig.size() + 34));
CHECK(is_fanout_substituted(substituted_depth, ps_depth));
check_eq(aig, substituted_depth);
}
25 changes: 25 additions & 0 deletions test/utils/blueprints/network_blueprints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,31 @@ mockturtle::names_view<Ntk> topolinano_network()
return ntk;
}

template <typename Ntk>
mockturtle::names_view<Ntk> dangling_pi_network()
{
mockturtle::names_view<Ntk> ntk{};

const auto a = ntk.create_pi("a");
const auto b = ntk.create_pi("b");
const auto c = ntk.create_pi("c");
const auto d = ntk.create_pi("d");
const auto e = ntk.create_pi("e");
ntk.create_pi("f");

const auto m1 = ntk.create_maj(a, b, c);
const auto m2 = ntk.create_maj(b, c, d);
const auto m3 = ntk.create_maj(c, d, e);
const auto m4 = ntk.create_maj(m1, m2, m3);

ntk.create_po(m1, "m1");
ntk.create_po(m2, "m2");
ntk.create_po(m3, "m3");
ntk.create_po(m4, "m4");

return ntk;
}

} // namespace blueprints

#endif // FICTION_NETWORK_BLUEPRINTS_HPP
Loading