Skip to content
Prev Previous commit
window_rewriting.
  • Loading branch information
hriener committed Apr 23, 2021
commit 343ccfb4f4e2ce7535ecd425de0ce42a92accb80
17 changes: 12 additions & 5 deletions include/mockturtle/algorithms/window_rewriting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,14 +509,10 @@ class window_rewriting_impl
ntk.resize_levels();
if ( ps.level_update_strategy == window_rewriting_params::precise )
{
assert( count_reachable_dead_nodes_from_node( ntk, n ) == 0u );
assert( count_nodes_with_dead_fanins( ntk, n ) == 0u );
call_with_stopwatch( st.time_levels, [&]() { update_node_level_precise( n ); } );
}
else if ( ps.level_update_strategy == window_rewriting_params::eager )
{
assert( count_reachable_dead_nodes_from_node( ntk, n ) == 0u );
assert( count_nodes_with_dead_fanins( ntk, n ) == 0u );
call_with_stopwatch( st.time_levels, [&]() { update_node_level_eager( n ); } );
}

Expand All @@ -527,6 +523,9 @@ class window_rewriting_impl
/* precisely update node levels using an iterative topological sorting approach */
void update_node_level_precise( node const& n )
{
assert( count_reachable_dead_nodes_from_node( ntk, n ) == 0u );
// assert( count_nodes_with_dead_fanins( ntk, n ) == 0u );

/* compute level of current node */
uint32_t level_offset{0};
ntk.foreach_fanin( n, [&]( signal const& fi ){
Expand All @@ -535,6 +534,10 @@ class window_rewriting_impl
++level_offset;

/* add node into levels */
if ( levels.size() < 1u )
{
levels.resize( 1u );
}
levels[0].emplace_back( n );

for ( uint32_t level_index = 0u; level_index < levels.size(); ++level_index )
Expand All @@ -549,9 +552,14 @@ class window_rewriting_impl
/* recompute level of this node */
uint32_t lvl{0};
ntk.foreach_fanin( p, [&]( signal const& fi ){
if ( ntk.is_dead( ntk.get_node( fi ) ) )
return;

lvl = std::max( ntk.level( ntk.get_node( fi ) ), lvl );
return;
});
++lvl;
assert( lvl > 0 );

/* update level and add fanouts to levels[.] if the recomputed
level is different from the current level */
Expand All @@ -576,7 +584,6 @@ class window_rewriting_impl
levels[level_index].clear();
}
levels.clear();
levels.resize( ntk.depth() );
}

/* eagerly update the node levels without topologically sorting (may
Expand Down
7 changes: 3 additions & 4 deletions include/mockturtle/utils/debugging_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ void count_nodes_with_dead_fanins_recur( Ntk const& ntk, typename Ntk::node cons
{
return;
}
ntk.paint( n );

ntk.foreach_fanin( n, [&]( signal const& s ){
if ( ntk.is_dead( ntk.get_node( s ) ) )
Expand All @@ -233,16 +234,15 @@ void count_nodes_with_dead_fanins_recur( Ntk const& ntk, typename Ntk::node cons
}
});

ntk.paint( n );
ntk.foreach_fanout( n, [&]( node const& fo ){
count_reachable_dead_nodes_from_node_recur( ntk, fo, nodes );
count_nodes_with_dead_fanins_recur( ntk, fo, nodes );
});
}

} /* namespace detail */

template<typename Ntk>
inline uint64_t count_nodes_with_dead_fanins( Ntk const& ntk, typename Ntk::node const& n )
uint64_t count_nodes_with_dead_fanins( Ntk const& ntk, typename Ntk::node const& n )
{
static_assert( is_network_type_v<Ntk>, "Ntk is not a network type" );
static_assert( has_color_v<Ntk>, "Ntk does not implement the color function" );
Expand All @@ -255,7 +255,6 @@ inline uint64_t count_nodes_with_dead_fanins( Ntk const& ntk, typename Ntk::node
static_assert( has_paint_v<Ntk>, "Ntk does not implement the paint function" );

using node = typename Ntk::node;
using signal = typename Ntk::signal;

ntk.new_color();

Expand Down