dchMan.c 6.14 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6
/**CFile****************************************************************

  FileName    [dchMan.c]

  SystemName  [ABC: Logic synthesis and verification system.]

Alan Mishchenko committed
7
  PackageName [Choice computation for tech-mapping.]
Alan Mishchenko committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

  Synopsis    [Calls to the SAT solver.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - June 29, 2008.]

  Revision    [$Id: dchMan.c,v 1.00 2008/07/29 00:00:00 alanmi Exp $]

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

#include "dchInt.h"

23 24 25
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
26 27 28 29 30 31 32 33 34 35
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
///                     FUNCTION DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////

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

Alan Mishchenko committed
36
  Synopsis    [Creates the manager.]
Alan Mishchenko committed
37 38 39 40 41 42 43 44

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
45
Dch_Man_t * Dch_ManCreate( Aig_Man_t * pAig, Dch_Pars_t * pPars )
Alan Mishchenko committed
46 47 48
{
    Dch_Man_t * p;
    // create interpolation manager
Alan Mishchenko committed
49
    p = ABC_ALLOC( Dch_Man_t, 1 );
Alan Mishchenko committed
50
    memset( p, 0, sizeof(Dch_Man_t) );
Alan Mishchenko committed
51
    p->pPars        = pPars;
Alan Mishchenko committed
52
    p->pAigTotal    = pAig; //Dch_DeriveTotalAig( vAigs );
Alan Mishchenko committed
53
    Aig_ManFanoutStart( p->pAigTotal );
Alan Mishchenko committed
54
    // SAT solving
Alan Mishchenko committed
55
    p->nSatVars     = 1;
Alan Mishchenko committed
56
    p->pSatVars     = ABC_CALLOC( int, Aig_ManObjNumMax(p->pAigTotal) );
Alan Mishchenko committed
57 58 59 60
    p->vUsedNodes   = Vec_PtrAlloc( 1000 );
    p->vFanins      = Vec_PtrAlloc( 100 );
    p->vSimRoots    = Vec_PtrAlloc( 1000 );
    p->vSimClasses  = Vec_PtrAlloc( 1000 );
Alan Mishchenko committed
61
    // equivalences proved
Alan Mishchenko committed
62
    p->pReprsProved = ABC_CALLOC( Aig_Obj_t *, Aig_ManObjNumMax(p->pAigTotal) );
Alan Mishchenko committed
63 64 65 66 67
    return p;
}

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

Alan Mishchenko committed
68 69 70 71 72 73 74 75 76 77 78
  Synopsis    [Prints stats of the manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Dch_ManPrintStats( Dch_Man_t * p )
{
Alan Mishchenko committed
79
    int nNodeNum = Aig_ManNodeNum(p->pAigTotal) / 3;
80
    Abc_Print( 1, "Parameters: Sim words = %d. Conf limit = %d. SAT var max = %d.\n", 
Alan Mishchenko committed
81
        p->pPars->nWords, p->pPars->nBTLimit, p->pPars->nSatVarMax );
82
    Abc_Print( 1, "AIG nodes : Total = %6d. Dangling = %6d. Main = %6d. (%6.2f %%)\n", 
Alan Mishchenko committed
83
        Aig_ManNodeNum(p->pAigTotal), 
Alan Mishchenko committed
84 85 86
        Aig_ManNodeNum(p->pAigTotal)-nNodeNum,
        nNodeNum,
        100.0 * nNodeNum/Aig_ManNodeNum(p->pAigTotal) );
87
    Abc_Print( 1, "SAT solver: Vars = %d. Max cone = %d. Recycles = %d.\n", 
Alan Mishchenko committed
88
        p->nSatVars, p->nConeMax, p->nRecycles );
89
    Abc_Print( 1, "SAT calls : All = %6d. Unsat = %6d. Sat = %6d. Fail = %6d.\n", 
Alan Mishchenko committed
90 91
        p->nSatCalls, p->nSatCalls-p->nSatCallsSat-p->nSatFailsReal, 
        p->nSatCallsSat, p->nSatFailsReal );
92
    Abc_Print( 1, "Choices   : Lits = %6d. Reprs = %5d. Equivs = %5d. Choices = %5d.\n", 
Alan Mishchenko committed
93
        p->nLits, p->nReprs, p->nEquivs, p->nChoices );
94
    Abc_Print( 1, "Choicing runtime statistics:\n" );
Alan Mishchenko committed
95
    p->timeOther = p->timeTotal-p->timeSimInit-p->timeSimSat-p->timeSat-p->timeChoice;
96 97 98 99 100 101 102 103 104
    Abc_PrintTimeP( 1, "Sim init   ", p->timeSimInit,  p->timeTotal );
    Abc_PrintTimeP( 1, "Sim SAT    ", p->timeSimSat,   p->timeTotal );
    Abc_PrintTimeP( 1, "SAT solving", p->timeSat,      p->timeTotal );
    Abc_PrintTimeP( 1, "  sat      ", p->timeSatSat,   p->timeTotal );
    Abc_PrintTimeP( 1, "  unsat    ", p->timeSatUnsat, p->timeTotal );
    Abc_PrintTimeP( 1, "  undecided", p->timeSatUndec, p->timeTotal );
    Abc_PrintTimeP( 1, "Choice     ", p->timeChoice,   p->timeTotal );
    Abc_PrintTimeP( 1, "Other      ", p->timeOther,    p->timeTotal );
    Abc_PrintTimeP( 1, "TOTAL      ", p->timeTotal,    p->timeTotal );
Alan Mishchenko committed
105 106
    if ( p->pPars->timeSynth )
    {
107
    Abc_PrintTime( 1, "Synthesis  ", p->pPars->timeSynth );
Alan Mishchenko committed
108
    }
Alan Mishchenko committed
109
} 
Alan Mishchenko committed
110 111 112 113

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

  Synopsis    [Frees the manager.]
Alan Mishchenko committed
114 115 116 117 118 119 120 121 122 123

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Dch_ManStop( Dch_Man_t * p )
{
Alan Mishchenko committed
124
    Aig_ManFanoutStop( p->pAigTotal );
Alan Mishchenko committed
125
    if ( p->pPars->fVerbose )
Alan Mishchenko committed
126
        Dch_ManPrintStats( p );
Alan Mishchenko committed
127 128
    if ( p->pAigFraig )
        Aig_ManStop( p->pAigFraig );
Alan Mishchenko committed
129 130 131 132
    if ( p->ppClasses )
        Dch_ClassesStop( p->ppClasses );
    if ( p->pSat )
        sat_solver_delete( p->pSat );
Alan Mishchenko committed
133
    Vec_PtrFree( p->vUsedNodes );
Alan Mishchenko committed
134
    Vec_PtrFree( p->vFanins );
Alan Mishchenko committed
135 136
    Vec_PtrFree( p->vSimRoots );
    Vec_PtrFree( p->vSimClasses );
Alan Mishchenko committed
137 138 139
    ABC_FREE( p->pReprsProved );
    ABC_FREE( p->pSatVars );
    ABC_FREE( p );
Alan Mishchenko committed
140 141
}

Alan Mishchenko committed
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
/**Function*************************************************************

  Synopsis    [Recycles the SAT solver.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Dch_ManSatSolverRecycle( Dch_Man_t * p )
{
    int Lit;
    if ( p->pSat )
    {
Alan Mishchenko committed
158 159
        Aig_Obj_t * pObj;
        int i;
160
        Vec_PtrForEachEntry( Aig_Obj_t *, p->vUsedNodes, pObj, i )
Alan Mishchenko committed
161 162 163
            Dch_ObjSetSatNum( p, pObj, 0 );
        Vec_PtrClear( p->vUsedNodes );
//        memset( p->pSatVars, 0, sizeof(int) * Aig_ManObjNumMax(p->pAigTotal) );
Alan Mishchenko committed
164 165 166 167
        sat_solver_delete( p->pSat );
    }
    p->pSat = sat_solver_new();
    sat_solver_setnvars( p->pSat, 1000 );
Alan Mishchenko committed
168 169
    // var 0 is not used
    // var 1 is reserved for const1 node - add the clause
Alan Mishchenko committed
170 171 172
    p->nSatVars = 1;
//    p->nSatVars = 0;
    Lit = toLit( p->nSatVars );
Alan Mishchenko committed
173 174
    if ( p->pPars->fPolarFlip )
        Lit = lit_neg( Lit );
Alan Mishchenko committed
175
    sat_solver_addclause( p->pSat, &Lit, &Lit + 1 );
Alan Mishchenko committed
176 177
    Dch_ObjSetSatNum( p, Aig_ManConst1(p->pAigFraig), p->nSatVars++ );

Alan Mishchenko committed
178
    p->nRecycles++;
Alan Mishchenko committed
179
    p->nCallsSince = 0;
Alan Mishchenko committed
180 181
}

Alan Mishchenko committed
182

Alan Mishchenko committed
183 184


Alan Mishchenko committed
185 186 187 188 189
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


190 191
ABC_NAMESPACE_IMPL_END