summaryrefslogtreecommitdiffstats
path: root/src/proof/pdr/pdrClass.c
blob: 5dd4c4a974c3f0165219ccf7a74d016ee264e00d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/**CFile****************************************************************

  FileName    [pdrClass.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Property driven reachability.]

  Synopsis    [Equivalence classes of register outputs.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - November 20, 2010.]

  Revision    [$Id: pdrClass.c,v 1.00 2010/11/20 00:00:00 alanmi Exp $]

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

#include "pdrInt.h"

ABC_NAMESPACE_IMPL_START


////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

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

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

  Synopsis    [Performs duplication with the variable map.]

  Description [Var map contains -1 if const0 and <reg_num> otherwise.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Aig_Man_t * Pdr_ManRehashWithMap( Aig_Man_t * pAig, Vec_Int_t * vMap )
{
    Aig_Man_t * pFrames;
    Aig_Obj_t * pObj;
    int i, iReg;
    assert( Vec_IntSize(vMap) == Aig_ManRegNum(pAig) );
    // start the fraig package
    pFrames = Aig_ManStart( Aig_ManObjNumMax(pAig) );
    pFrames->pName = Abc_UtilStrsav( pAig->pName );
    pFrames->pSpec = Abc_UtilStrsav( pAig->pSpec );
    // create CI mapping
    Aig_ManCleanData( pAig );
    Aig_ManConst1(pAig)->pData = Aig_ManConst1(pFrames);
    Aig_ManForEachCi( pAig, pObj, i )
        pObj->pData = Aig_ObjCreateCi(pFrames);
    Saig_ManForEachLo( pAig, pObj, i )
    {
        iReg = Vec_IntEntry(vMap, i);
        if ( iReg == -1 )
            pObj->pData = Aig_ManConst0(pFrames);
        else
            pObj->pData = Saig_ManLo(pAig, iReg)->pData;
    }
    // add internal nodes of this frame
    Aig_ManForEachNode( pAig, pObj, i )
        pObj->pData = Aig_And( pFrames, Aig_ObjChild0Copy(pObj), Aig_ObjChild1Copy(pObj) );
    // add output nodes
    Aig_ManForEachCo( pAig, pObj, i )
        pObj->pData = Aig_ObjCreateCo( pFrames, Aig_ObjChild0Copy(pObj) );
    // finish off
    Aig_ManCleanup( pFrames );
    Aig_ManSetRegNum( pFrames, Aig_ManRegNum(pAig) );
    return pFrames;
}

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

  Synopsis    [Creates mapping of registers.]

  Description [Var map contains -1 if const0 and <reg_num> otherwise.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Vec_Int_t * Pdr_ManCreateMap( Aig_Man_t * p )
{
    Aig_Obj_t * pObj;
    Vec_Int_t * vMap;
    int * pLit2Id, Lit, i;
    pLit2Id = ABC_ALLOC( int, Aig_ManObjNumMax(p) * 2 );
    for ( i = 0; i < Aig_ManObjNumMax(p) * 2; i++ )
        pLit2Id[i] = -1;
    vMap = Vec_IntAlloc( Aig_ManRegNum(p) );
    Saig_ManForEachLi( p, pObj, i )
    {
        if ( Aig_ObjChild0(pObj) == Aig_ManConst0(p) )
        {
            Vec_IntPush( vMap, -1 );
            continue;
        }
        Lit = 2 * Aig_ObjFaninId0(pObj) + Aig_ObjFaninC0(pObj);
        if ( pLit2Id[Lit] < 0 ) // the first time
            pLit2Id[Lit] = i;
        Vec_IntPush( vMap, pLit2Id[Lit] );
    }
    ABC_FREE( pLit2Id );
    return vMap;
}

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

  Synopsis    [Counts reduced registers.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Pdr_ManCountMap( Vec_Int_t * vMap )
{
    int i, Entry, Counter = 0;
    Vec_IntForEachEntry( vMap, Entry, i )
        if ( Entry != i )
            Counter++;
    return Counter;
}

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

  Synopsis    [Counts reduced registers.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Pdr_ManPrintMap( Vec_Int_t * vMap )
{
    Vec_Int_t * vMarks;
    int f, i, iClass, Entry, Counter = 0;
    Abc_Print( 1, "    Consts: " );
    Vec_IntForEachEntry( vMap, Entry, i )
        if ( Entry == -1 )
            Abc_Print( 1, "%d ", i );
    Abc_Print( 1, "\n" );
    vMarks = Vec_IntAlloc( 100 );
    Vec_IntForEachEntry( vMap, iClass, f )
    {
        if ( iClass == -1 )
            continue;
        if ( iClass == f )
            continue;
        // check previous classes
        if ( Vec_IntFind( vMarks, iClass ) >= 0 )
            continue;
        Vec_IntPush( vMarks, iClass );
        // print class
        Abc_Print( 1, "    Class %d : ", iClass );
        Vec_IntForEachEntry( vMap, Entry, i )
            if ( Entry == iClass )
                Abc_Print( 1, "%d ", i );
        Abc_Print( 1, "\n" );
    }
    Vec_IntFree( vMarks );
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Pdr_ManEquivClasses( Aig_Man_t * pAig )
{
    Vec_Int_t * vMap;
    Aig_Man_t * pTemp;
    int f, nFrames = 100;
    assert( Saig_ManRegNum(pAig) > 0 );
    // start the map
    vMap = Vec_IntAlloc( 0 );
    Vec_IntFill( vMap, Aig_ManRegNum(pAig), -1 );
    // iterate and print changes
    for ( f = 0; f < nFrames; f++ )
    {
        // implement variable map
        pTemp = Pdr_ManRehashWithMap( pAig, vMap );
        // report the result
        Abc_Print( 1, "F =%4d : Total = %6d. Nodes = %6d. RedRegs = %6d. Prop = %s\n", 
            f+1, Aig_ManNodeNum(pAig), Aig_ManNodeNum(pTemp), Pdr_ManCountMap(vMap), 
            Aig_ObjChild0(Aig_ManCo(pTemp,0)) == Aig_ManConst0(pTemp) ? "proof" : "unknown" );
        // recreate the map
        Pdr_ManPrintMap( vMap );
        Vec_IntFree( vMap );
        vMap = Pdr_ManCreateMap( pTemp );
        Aig_ManStop( pTemp );
        if ( Pdr_ManCountMap(vMap) == 0 )
            break;
    }
    Vec_IntFree( vMap );
}

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


ABC_NAMESPACE_IMPL_END