mockturtle
mockturtle copied to clipboard
ALAP in depth_view
I implemented a draft (but not complete -- consideration of inverter cost is missing, and maybe some more details, plus documentation and tests etc. are also missing) during research but didn't need it in the end, so just to keep a back-up here in case someone decides that it's useful and makes a PR in the future.
As a public member function of depth_view:
void ALAP()
{
_levels.reset( 0 );
this->incr_trav_id();
this->foreach_po( [&]( auto const& f ) {
const auto n = this->get_node( f );
if ( !this->is_constant( n ) && this->visited( n ) != this->trav_id() && !this->is_pi( n ) )
{
_levels[n] = _depth;
compute_levels_ALAP( n );
}
} );
}
As a private member function of depth_view:
void compute_levels_ALAP( node const& n )
{
this->set_visited( n, this->trav_id() );
this->foreach_fanin( n, [&]( auto const& fi ) {
auto const ni = this->get_node( fi );
if ( !this->is_constant( ni ) && !this->is_pi( ni ) )
{
assert( _levels[n] >= _cost_fn( *this, ni ) );
auto fi_level = _levels[n] - _cost_fn( *this, ni );
if ( this->visited( ni ) != this->trav_id() || _levels[ni] > fi_level )
{
_levels[ni] = fi_level;
compute_levels_ALAP( ni );
}
}
} );
}