abc/src/opt/dar/darRefact.c
/**Function*************************************************************

  Synopsis    [Counts the number of new nodes added when using this graph.]

  Description [AIG nodes for the fanins should be assigned to pNode->pFunc 
  of the leaves of the graph before calling this procedure. 
  Returns -1 if the number of nodes and levels exceeded the given limit or 
  the number of levels exceeded the maximum allowed level.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Function
Synopsis    [Counts the number of new nodes added when using this graph.]

Description [AIG nodes for the fanins should be assigned to pNode->pFunc
of the leaves of the graph before calling this procedure.
Returns -1 if the number of nodes and levels exceeded the given limit or
the number of levels exceeded the maximum allowed level.]




Function Synopsis [ Counts the number of new nodes added when using this graph . ] Description [ AIG nodes for the fanins should be assigned to pNode - > pFunc of the leaves of the graph before calling this procedure . Returns - 1 if the number of nodes and levels exceeded the given limit or the number of levels exceeded the maximum allowed level . ]
int Dar_RefactTryGraph( Aig_Man_t * pAig, Aig_Obj_t * pRoot, Vec_Ptr_t * vCut, Kit_Graph_t * pGraph, int NodeMax, int LevelMax )
{
    Kit_Node_t * pNode, * pNode0, * pNode1;
    Aig_Obj_t * pAnd, * pAnd0, * pAnd1;
    int i, Counter, LevelNew, LevelOld;
    if ( Kit_GraphIsConst(pGraph) || Kit_GraphIsVar(pGraph) )
        return 0;
    Kit_GraphForEachLeaf( pGraph, pNode, i )
    {
        pNode->pFunc = Vec_PtrEntry(vCut, i);
        pNode->Level = Aig_Regular((Aig_Obj_t *)pNode->pFunc)->Level;
        assert( Aig_Regular((Aig_Obj_t *)pNode->pFunc)->Level < (1<<24)-1 );
    }
    Counter = 0;
    Kit_GraphForEachNode( pGraph, pNode, i )
    {
        pNode0 = Kit_GraphNode( pGraph, pNode->eEdge0.Node );
        pNode1 = Kit_GraphNode( pGraph, pNode->eEdge1.Node );
        pAnd0 = (Aig_Obj_t *)pNode0->pFunc; 
        pAnd1 = (Aig_Obj_t *)pNode1->pFunc; 
        if ( pAnd0 && pAnd1 )
        {
            pAnd0 = Aig_NotCond( pAnd0, pNode->eEdge0.fCompl );
            pAnd1 = Aig_NotCond( pAnd1, pNode->eEdge1.fCompl );
            pAnd  = Aig_TableLookupTwo( pAig, pAnd0, pAnd1 );
            if ( Aig_Regular(pAnd) == pRoot )
                return -1;
        }
        else
            pAnd = NULL;
        if ( pAnd == NULL || Aig_ObjIsTravIdCurrent(pAig, Aig_Regular(pAnd)) )
        {
            if ( ++Counter > NodeMax )
                return -1;
        }
        LevelNew = 1 + Abc_MaxInt( pNode0->Level, pNode1->Level );
        if ( pAnd )
        {
            if ( Aig_Regular(pAnd) == Aig_ManConst1(pAig) )
                LevelNew = 0;
            else if ( Aig_Regular(pAnd) == Aig_Regular(pAnd0) )
                LevelNew = (int)Aig_Regular(pAnd0)->Level;
            else if ( Aig_Regular(pAnd) == Aig_Regular(pAnd1) )
                LevelNew = (int)Aig_Regular(pAnd1)->Level;
            LevelOld = (int)Aig_Regular(pAnd)->Level;
        }
        if ( LevelNew > LevelMax )
            return -1;
        pNode->pFunc = pAnd;
        pNode->Level = LevelNew;
    }
    return Counter;
}
int Dar_RefactTryGraph ( Aig_Man_t * pAig , Aig_Obj_t * pRoot , Vec_Ptr_t * vCut , Kit_Graph_t * pGraph , int NodeMax , int LevelMax ) { Kit_Node_t * pNode , * pNode0 , * pNode1 ; Aig_Obj_t * pAnd , * pAnd0 , * pAnd1 ; int i , Counter , LevelNew , LevelOld ; if ( Kit_GraphIsConst ( pGraph ) || Kit_GraphIsVar ( pGraph ) ) return 0 ; Kit_GraphForEachLeaf ( pGraph , pNode , i ) { pNode -> pFunc = Vec_PtrEntry ( vCut , i ) ; pNode -> Level = Aig_Regular ( ( Aig_Obj_t * ) pNode -> pFunc ) -> Level ; assert ( Aig_Regular ( ( Aig_Obj_t * ) pNode -> pFunc ) -> Level < ( 1 << 24 ) - 1 ) ; } Counter = 0 ; Kit_GraphForEachNode ( pGraph , pNode , i ) { pNode0 = Kit_GraphNode ( pGraph , pNode -> eEdge0 . Node ) ; pNode1 = Kit_GraphNode ( pGraph , pNode -> eEdge1 . Node ) ; pAnd0 = ( Aig_Obj_t * ) pNode0 -> pFunc ; pAnd1 = ( Aig_Obj_t * ) pNode1 -> pFunc ; if ( pAnd0 && pAnd1 ) { pAnd0 = Aig_NotCond ( pAnd0 , pNode -> eEdge0 . fCompl ) ; pAnd1 = Aig_NotCond ( pAnd1 , pNode -> eEdge1 . fCompl ) ; pAnd = Aig_TableLookupTwo ( pAig , pAnd0 , pAnd1 ) ; if ( Aig_Regular ( pAnd ) == pRoot ) return -1 ; } else pAnd = NULL ; if ( pAnd == NULL || Aig_ObjIsTravIdCurrent ( pAig , Aig_Regular ( pAnd ) ) ) { if ( ++ Counter > NodeMax ) return -1 ; } LevelNew = 1 + Abc_MaxInt ( pNode0 -> Level , pNode1 -> Level ) ; if ( pAnd ) { if ( Aig_Regular ( pAnd ) == Aig_ManConst1 ( pAig ) ) LevelNew = 0 ; else if ( Aig_Regular ( pAnd ) == Aig_Regular ( pAnd0 ) ) LevelNew = ( int ) Aig_Regular ( pAnd0 ) -> Level ; else if ( Aig_Regular ( pAnd ) == Aig_Regular ( pAnd1 ) ) LevelNew = ( int ) Aig_Regular ( pAnd1 ) -> Level ; LevelOld = ( int ) Aig_Regular ( pAnd ) -> Level ; } if ( LevelNew > LevelMax ) return -1 ; pNode -> pFunc = pAnd ; pNode -> Level = LevelNew ; } return Counter ; }
Function
Synopsis    [Counts the number of new nodes added when using this graph.]
Function Synopsis [ Counts the number of new nodes added when using this graph . ]
// check for constant function or a literal // set the levels of the leaves //printf( "Trying:\n" ); // compute the AIG size after adding the internal nodes // get the children of this node // get the AIG nodes corresponding to the children  // if they are both present, find the resulting node // return -1 if the node is the same as the original root // count the number of added nodes // count the number of new levels //            assert( LevelNew == LevelOld ); /*
printf( "Checking " );
Ref_ObjPrint( pAnd0 );
printf( " and " );
Ref_ObjPrint( pAnd1 );
printf( "  Result " );
Ref_ObjPrint( pNode->pFunc );
printf( "\n" );
*/