abcCollapse.c 5.7 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/**CFile****************************************************************

  FileName    [abcCollapse.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Network and node package.]

  Synopsis    [Collapsing the network into two-levels.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - June 20, 2005.]

  Revision    [$Id: abcCollapse.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]

***********************************************************************/

21 22
#include "base/abc/abc.h"
#include "misc/extra/extraBdd.h"
Alan Mishchenko committed
23

24 25 26
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
27 28 29 30
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

Alan Mishchenko committed
31
static Abc_Ntk_t * Abc_NtkFromGlobalBdds( Abc_Ntk_t * pNtk );
Alan Mishchenko committed
32 33 34
static Abc_Obj_t * Abc_NodeFromGlobalBdds( Abc_Ntk_t * pNtkNew, DdManager * dd, DdNode * bFunc );

////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
35
///                     FUNCTION DEFINITIONS                         ///
Alan Mishchenko committed
36 37 38 39 40 41 42 43 44 45 46 47 48
////////////////////////////////////////////////////////////////////////

/**Function*************************************************************

  Synopsis    [Collapses the network.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
49
Abc_Ntk_t * Abc_NtkCollapse( Abc_Ntk_t * pNtk, int fBddSizeMax, int fDualRail, int fReorder, int fVerbose )
Alan Mishchenko committed
50 51
{
    Abc_Ntk_t * pNtkNew;
52
    abctime clk = Abc_Clock();
Alan Mishchenko committed
53

Alan Mishchenko committed
54
    assert( Abc_NtkIsStrash(pNtk) );
Alan Mishchenko committed
55
    // compute the global BDDs
Alan Mishchenko committed
56
    if ( Abc_NtkBuildGlobalBdds(pNtk, fBddSizeMax, 1, fReorder, fVerbose) == NULL )
Alan Mishchenko committed
57 58
        return NULL;
    if ( fVerbose )
Alan Mishchenko committed
59
    {
60
        DdManager * dd = (DdManager *)Abc_NtkGlobalBddMan( pNtk );
Alan Mishchenko committed
61
        printf( "Shared BDD size = %6d nodes.  ", Cudd_ReadKeys(dd) - Cudd_ReadDead(dd) );
62
        ABC_PRT( "BDD construction time", Abc_Clock() - clk );
Alan Mishchenko committed
63
    }
Alan Mishchenko committed
64

Alan Mishchenko committed
65
    // create the new network
Alan Mishchenko committed
66
    pNtkNew = Abc_NtkFromGlobalBdds( pNtk );
Alan Mishchenko committed
67 68
//    Abc_NtkFreeGlobalBdds( pNtk );
    Abc_NtkFreeGlobalBdds( pNtk, 1 );
Alan Mishchenko committed
69 70
    if ( pNtkNew == NULL )
    {
Alan Mishchenko committed
71 72
//        Cudd_Quit( pNtk->pManGlob );
//        pNtk->pManGlob = NULL;
Alan Mishchenko committed
73 74
        return NULL;
    }
Alan Mishchenko committed
75 76
//    Extra_StopManager( pNtk->pManGlob );
//    pNtk->pManGlob = NULL;
Alan Mishchenko committed
77 78 79 80

    // make the network minimum base
    Abc_NtkMinimumBase( pNtkNew );

Alan Mishchenko committed
81 82 83
    if ( pNtk->pExdc )
        pNtkNew->pExdc = Abc_NtkDup( pNtk->pExdc );

Alan Mishchenko committed
84
    // make sure that everything is okay
Alan Mishchenko committed
85
    if ( !Abc_NtkCheck( pNtkNew ) )
Alan Mishchenko committed
86 87 88 89 90 91 92 93
    {
        printf( "Abc_NtkCollapse: The network check has failed.\n" );
        Abc_NtkDelete( pNtkNew );
        return NULL;
    }
    return pNtkNew;
}

Alan Mishchenko committed
94 95 96

//int runtime1, runtime2;

Alan Mishchenko committed
97 98 99 100 101 102 103 104 105 106 107
/**Function*************************************************************

  Synopsis    [Derives the network with the given global BDD.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
108
Abc_Ntk_t * Abc_NtkFromGlobalBdds( Abc_Ntk_t * pNtk )
Alan Mishchenko committed
109
{
Alan Mishchenko committed
110 111 112
//    extern void Extra_ShuffleTest( reo_man * p, DdManager * dd, DdNode * Func );
//    reo_man * pReo;

Alan Mishchenko committed
113 114
    ProgressBar * pProgress;
    Abc_Ntk_t * pNtkNew;
Alan Mishchenko committed
115 116
    Abc_Obj_t * pNode, * pDriver, * pNodeNew;
//    DdManager * dd = pNtk->pManGlob;
117
    DdManager * dd = (DdManager *)Abc_NtkGlobalBddMan( pNtk );
Alan Mishchenko committed
118
    int i;
Alan Mishchenko committed
119 120 121 122

//    pReo = Extra_ReorderInit( Abc_NtkCiNum(pNtk), 1000 );
//    runtime1 = runtime2 = 0;

Alan Mishchenko committed
123
    // start the new network
Alan Mishchenko committed
124
    pNtkNew = Abc_NtkStartFrom( pNtk, ABC_NTK_LOGIC, ABC_FUNC_BDD );
Alan Mishchenko committed
125
    // make sure the new manager has the same number of inputs
126
    Cudd_bddIthVar( (DdManager *)pNtkNew->pManFunc, dd->size-1 );
Alan Mishchenko committed
127 128 129 130 131
    // process the POs
    pProgress = Extra_ProgressBarStart( stdout, Abc_NtkCoNum(pNtk) );
    Abc_NtkForEachCo( pNtk, pNode, i )
    {
        Extra_ProgressBarUpdate( pProgress, i, NULL );
Alan Mishchenko committed
132 133 134 135 136 137 138
        pDriver = Abc_ObjFanin0(pNode);
        if ( Abc_ObjIsCi(pDriver) && !strcmp(Abc_ObjName(pNode), Abc_ObjName(pDriver)) )
        {
            Abc_ObjAddFanin( pNode->pCopy, pDriver->pCopy );
            continue;
        }
//        pNodeNew = Abc_NodeFromGlobalBdds( pNtkNew, dd, Vec_PtrEntry(pNtk->vFuncsGlob, i) );
139
        pNodeNew = Abc_NodeFromGlobalBdds( pNtkNew, dd, (DdNode *)Abc_ObjGlobalBdd(pNode) );
Alan Mishchenko committed
140
        Abc_ObjAddFanin( pNode->pCopy, pNodeNew );
Alan Mishchenko committed
141 142 143

//        Extra_ShuffleTest( pReo, dd, Abc_ObjGlobalBdd(pNode) );

Alan Mishchenko committed
144 145
    }
    Extra_ProgressBarStop( pProgress );
Alan Mishchenko committed
146 147

//    Extra_ReorderQuit( pReo );
Alan Mishchenko committed
148 149
//ABC_PRT( "Reo ", runtime1 );
//ABC_PRT( "Cudd", runtime2 );
Alan Mishchenko committed
150

Alan Mishchenko committed
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
    return pNtkNew;
}

/**Function*************************************************************

  Synopsis    [Derives the network with the given global BDD.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Obj_t * Abc_NodeFromGlobalBdds( Abc_Ntk_t * pNtkNew, DdManager * dd, DdNode * bFunc )
{
    Abc_Obj_t * pNodeNew, * pTemp;
    int i;
    // create a new node
    pNodeNew = Abc_NtkCreateNode( pNtkNew );
    // add the fanins in the order, in which they appear in the reordered manager
    Abc_NtkForEachCi( pNtkNew, pTemp, i )
        Abc_ObjAddFanin( pNodeNew, Abc_NtkCi(pNtkNew, dd->invperm[i]) );
    // transfer the function
175
    pNodeNew->pData = Extra_TransferLevelByLevel( dd, (DdManager *)pNtkNew->pManFunc, bFunc );  Cudd_Ref( (DdNode *)pNodeNew->pData );
Alan Mishchenko committed
176 177 178 179 180 181 182 183 184
    return pNodeNew;
}


////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


185 186
ABC_NAMESPACE_IMPL_END