sswMan.c 7.53 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 21 22
/**CFile****************************************************************

  FileName    [sswMan.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Inductive prover with constraints.]

  Synopsis    [Calls to the SAT solver.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - September 1, 2008.]

  Revision    [$Id: sswMan.c,v 1.00 2008/09/01 00:00:00 alanmi Exp $]

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

#include "sswInt.h"

23 24 25
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

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

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

  Synopsis    [Creates the manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Ssw_Man_t * Ssw_ManCreate( Aig_Man_t * pAig, Ssw_Pars_t * pPars )
{
    Ssw_Man_t * p;
Alan Mishchenko committed
48 49 50
    // prepare the sequential AIG
    assert( Saig_ManRegNum(pAig) > 0 );
    Aig_ManFanoutStart( pAig );
51
    Aig_ManSetCioIds( pAig );
Alan Mishchenko committed
52
    // create interpolation manager
53
    p = ABC_ALLOC( Ssw_Man_t, 1 );
Alan Mishchenko committed
54
    memset( p, 0, sizeof(Ssw_Man_t) );
Alan Mishchenko committed
55 56 57
    p->pPars         = pPars;
    p->pAig          = pAig;
    p->nFrames       = pPars->nFramesK + 1;
Alan Mishchenko committed
58
    p->pNodeToFrames = ABC_CALLOC( Aig_Obj_t *, Aig_ManObjNumMax(p->pAig) * p->nFrames );
Alan Mishchenko committed
59 60
    p->vCommon       = Vec_PtrAlloc( 100 );
    p->iOutputLit    = -1;
Alan Mishchenko committed
61
    // allocate storage for sim pattern
62
    p->nPatWords     = Abc_BitWordNum( Saig_ManPiNum(pAig) * p->nFrames + Saig_ManRegNum(pAig) );
63
    p->pPatWords     = ABC_CALLOC( unsigned, p->nPatWords );
Alan Mishchenko committed
64 65 66
    // other
    p->vNewLos       = Vec_PtrAlloc( 100 );
    p->vNewPos       = Vec_IntAlloc( 100 );
Alan Mishchenko committed
67 68
    p->vResimConsts  = Vec_PtrAlloc( 100 );
    p->vResimClasses = Vec_PtrAlloc( 100 );
Alan Mishchenko committed
69
//    p->pPars->fVerbose = 1;
Alan Mishchenko committed
70 71 72 73 74 75 76 77
    return p;
}

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

  Synopsis    [Prints stats of the manager.]

  Description []
78

Alan Mishchenko committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Ssw_ManCountEquivs( Ssw_Man_t * p )
{
    Aig_Obj_t * pObj;
    int i, nEquivs = 0;
    Aig_ManForEachObj( p->pAig, pObj, i )
        nEquivs += ( Aig_ObjRepr(p->pAig, pObj) != NULL );
    return nEquivs;
}

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

  Synopsis    [Prints stats of the manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Ssw_ManPrintStats( Ssw_Man_t * p )
{
Alan Mishchenko committed
106 107
    double nMemory = 1.0*Aig_ManObjNumMax(p->pAig)*p->nFrames*(2*sizeof(int)+2*sizeof(void*))/(1<<20);

108
    Abc_Print( 1, "Parameters: F = %d. AddF = %d. C-lim = %d. Constr = %d. MaxLev = %d. Mem = %0.2f MB.\n",
109
        p->pPars->nFramesK, p->pPars->nFramesAddSim, p->pPars->nBTLimit, Saig_ManConstrNum(p->pAig), p->pPars->nMaxLevs, nMemory );
110 111
    Abc_Print( 1, "AIG       : PI = %d. PO = %d. Latch = %d. Node = %d.  Ave SAT vars = %d.\n",
        Saig_ManPiNum(p->pAig), Saig_ManPoNum(p->pAig), Saig_ManRegNum(p->pAig), Aig_ManNodeNum(p->pAig),
112
        0/(p->pPars->nIters+1) );
113
    Abc_Print( 1, "SAT calls : Proof = %d. Cex = %d. Fail = %d. Lits proved = %d.\n",
Alan Mishchenko committed
114
        p->nSatProof, p->nSatCallsSat, p->nSatFailsReal, Ssw_ManCountEquivs(p) );
115
    Abc_Print( 1, "SAT solver: Vars max = %d. Calls max = %d. Recycles = %d. Sim rounds = %d.\n",
Alan Mishchenko committed
116
        p->nVarsMax, p->nCallsMax, p->nRecyclesTotal, p->nSimRounds );
117 118
    Abc_Print( 1, "NBeg = %d. NEnd = %d. (Gain = %6.2f %%).  RBeg = %d. REnd = %d. (Gain = %6.2f %%).\n",
        p->nNodesBeg, p->nNodesEnd, 100.0*(p->nNodesBeg-p->nNodesEnd)/(p->nNodesBeg?p->nNodesBeg:1),
Alan Mishchenko committed
119 120
        p->nRegsBeg, p->nRegsEnd, 100.0*(p->nRegsBeg-p->nRegsEnd)/(p->nRegsBeg?p->nRegsBeg:1) );

Alan Mishchenko committed
121
    p->timeOther = p->timeTotal-p->timeBmc-p->timeReduce-p->timeMarkCones-p->timeSimSat-p->timeSat;
Alan Mishchenko committed
122 123 124 125 126 127 128 129 130 131
    ABC_PRTP( "BMC        ", p->timeBmc,       p->timeTotal );
    ABC_PRTP( "Spec reduce", p->timeReduce,    p->timeTotal );
    ABC_PRTP( "Mark cones ", p->timeMarkCones, p->timeTotal );
    ABC_PRTP( "Sim SAT    ", p->timeSimSat,    p->timeTotal );
    ABC_PRTP( "SAT solving", p->timeSat,       p->timeTotal );
    ABC_PRTP( "  unsat    ", p->timeSatUnsat,  p->timeTotal );
    ABC_PRTP( "  sat      ", p->timeSatSat,    p->timeTotal );
    ABC_PRTP( "  undecided", p->timeSatUndec,  p->timeTotal );
    ABC_PRTP( "Other      ", p->timeOther,     p->timeTotal );
    ABC_PRTP( "TOTAL      ", p->timeTotal,     p->timeTotal );
132 133 134 135

    // report the reductions
    if ( p->pAig->nConstrs )
    {
136 137
        Abc_Print( 1, "Statistics reflecting the use of constraints:\n" );
        Abc_Print( 1, "Total cones  = %6d.  Constraint cones = %6d. (%6.2f %%)\n",
138
            p->nConesTotal, p->nConesConstr, 100.0*p->nConesConstr/p->nConesTotal );
139
        Abc_Print( 1, "Total equivs = %6d.  Removed equivs   = %6d. (%6.2f %%)\n",
140
            p->nEquivsTotal, p->nEquivsConstr, 100.0*p->nEquivsConstr/p->nEquivsTotal );
141 142
        Abc_Print( 1, "NBeg = %d. NEnd = %d. (Gain = %6.2f %%).  RBeg = %d. REnd = %d. (Gain = %6.2f %%).\n",
            p->nNodesBegC, p->nNodesEndC, 100.0*(p->nNodesBegC-p->nNodesEndC)/(p->nNodesBegC?p->nNodesBegC:1),
143 144
            p->nRegsBegC, p->nRegsEndC,   100.0*(p->nRegsBegC-p->nRegsEndC)/(p->nRegsBegC?p->nRegsBegC:1) );
    }
Alan Mishchenko committed
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
}

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

  Synopsis    [Frees the manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Ssw_ManCleanup( Ssw_Man_t * p )
{
Alan Mishchenko committed
160
//    Aig_ManCleanMarkAB( p->pAig );
Alan Mishchenko committed
161
    assert( p->pMSat == NULL );
Alan Mishchenko committed
162 163
    if ( p->pFrames )
    {
Alan Mishchenko committed
164
        Aig_ManCleanMarkAB( p->pFrames );
Alan Mishchenko committed
165 166
        Aig_ManStop( p->pFrames );
        p->pFrames = NULL;
Alan Mishchenko committed
167
        memset( p->pNodeToFrames, 0, sizeof(Aig_Obj_t *) * Aig_ManObjNumMax(p->pAig) * p->nFrames );
Alan Mishchenko committed
168
    }
169
    if ( p->vSimInfo )
Alan Mishchenko committed
170 171 172 173
    {
        Vec_PtrFree( p->vSimInfo );
        p->vSimInfo = NULL;
    }
Alan Mishchenko committed
174 175 176 177 178 179 180 181 182
    p->nConstrTotal = 0;
    p->nConstrReduced = 0;
}

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

  Synopsis    [Frees the manager.]

  Description []
183

Alan Mishchenko committed
184 185 186 187 188 189 190
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Ssw_ManStop( Ssw_Man_t * p )
{
Alan Mishchenko committed
191
    ABC_FREE( p->pVisited );
192
    if ( p->pPars->fVerbose )//&& p->pPars->nStepsMax == -1 )
Alan Mishchenko committed
193 194 195
        Ssw_ManPrintStats( p );
    if ( p->ppClasses )
        Ssw_ClassesStop( p->ppClasses );
196
    if ( p->pSml )
Alan Mishchenko committed
197
        Ssw_SmlStop( p->pSml );
Alan Mishchenko committed
198 199
    if ( p->vDiffPairs )
        Vec_IntFree( p->vDiffPairs );
200 201
    if ( p->vInits )
        Vec_IntFree( p->vInits );
Alan Mishchenko committed
202 203
    Vec_PtrFree( p->vResimConsts );
    Vec_PtrFree( p->vResimClasses );
Alan Mishchenko committed
204 205
    Vec_PtrFree( p->vNewLos );
    Vec_IntFree( p->vNewPos );
Alan Mishchenko committed
206
    Vec_PtrFree( p->vCommon );
Alan Mishchenko committed
207 208 209
    ABC_FREE( p->pNodeToFrames );
    ABC_FREE( p->pPatWords );
    ABC_FREE( p );
Alan Mishchenko committed
210 211 212 213 214 215 216
}

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


217
ABC_NAMESPACE_IMPL_END