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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
/**CFile****************************************************************
FileName [gia.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Scalable AIG package.]
Synopsis []
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: gia.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "gia.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
static inline int Gia_ObjDom( Gia_Man_t * p, Gia_Obj_t * pObj ) { return Vec_IntEntry(p->vDoms, Gia_ObjId(p, pObj)); }
static inline void Gia_ObjSetDom( Gia_Man_t * p, Gia_Obj_t * pObj, int d ) { Vec_IntWriteEntry(p->vDoms, Gia_ObjId(p, pObj), d); }
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Computes one-node dominators.]
Description [For each node, computes the closest one-node dominator,
which can be the node itself if the node has no other dominators.]
SideEffects []
SeeAlso []
***********************************************************************/
static inline void Gia_ManAddDom( Gia_Man_t * p, Gia_Obj_t * pObj, int iDom0 )
{
int iDom1, iDomNext;
if ( Gia_ObjDom(p, pObj) == -1 )
{
Gia_ObjSetDom( p, pObj, iDom0 );
return;
}
iDom1 = Gia_ObjDom( p, pObj );
while ( 1 )
{
if ( iDom0 > iDom1 )
{
iDomNext = Gia_ObjDom( p, Gia_ManObj(p, iDom1) );
if ( iDomNext == iDom1 )
break;
iDom1 = iDomNext;
continue;
}
if ( iDom1 > iDom0 )
{
iDomNext = Gia_ObjDom( p, Gia_ManObj(p, iDom0) );
if ( iDomNext == iDom0 )
break;
iDom0 = iDomNext;
continue;
}
assert( iDom0 == iDom1 );
Gia_ObjSetDom( p, pObj, iDom0 );
return;
}
Gia_ObjSetDom( p, pObj, Gia_ObjId(p, pObj) );
}
static inline void Gia_ManComputeDoms( Gia_Man_t * p )
{
Gia_Obj_t * pObj;
int i;
if ( p->vDoms == NULL )
p->vDoms = Vec_IntAlloc( 0 );
Vec_IntFill( p->vDoms, Gia_ManObjNum(p), -1 );
Gia_ManForEachObjReverse( p, pObj, i )
{
if ( i == 0 || Gia_ObjIsCi(pObj) )
continue;
if ( Gia_ObjIsCo(pObj) )
{
Gia_ObjSetDom( p, pObj, i );
Gia_ManAddDom( p, Gia_ObjFanin0(pObj), i );
continue;
}
assert( Gia_ObjIsAnd(pObj) );
Gia_ManAddDom( p, Gia_ObjFanin0(pObj), i );
Gia_ManAddDom( p, Gia_ObjFanin1(pObj), i );
}
}
/**Function*************************************************************
Synopsis [Returns the number of internal nodes in the MFFC.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline int Gia_NodeDeref_rec( Gia_Man_t * p, Gia_Obj_t * pNode )
{
Gia_Obj_t * pFanin;
int Counter = 0;
if ( Gia_ObjIsCi(pNode) )
return 0;
assert( Gia_ObjIsAnd(pNode) );
pFanin = Gia_ObjFanin0(pNode);
assert( Gia_ObjRefNum(p, pFanin) > 0 );
if ( Gia_ObjRefDec(p, pFanin) == 0 )
Counter += Gia_NodeDeref_rec( p, pFanin );
pFanin = Gia_ObjFanin1(pNode);
assert( Gia_ObjRefNum(p, pFanin) > 0 );
if ( Gia_ObjRefDec(p, pFanin) == 0 )
Counter += Gia_NodeDeref_rec( p, pFanin );
return Counter + 1;
}
static inline int Gia_NodeRef_rec( Gia_Man_t * p, Gia_Obj_t * pNode )
{
Gia_Obj_t * pFanin;
int Counter = 0;
if ( Gia_ObjIsCi(pNode) )
return 0;
assert( Gia_ObjIsAnd(pNode) );
pFanin = Gia_ObjFanin0(pNode);
if ( Gia_ObjRefInc(p, pFanin) == 0 )
Counter += Gia_NodeRef_rec( p, pFanin );
pFanin = Gia_ObjFanin1(pNode);
if ( Gia_ObjRefInc(p, pFanin) == 0 )
Counter += Gia_NodeRef_rec( p, pFanin );
return Counter + 1;
}
static inline void Gia_NodeCollect_rec( Gia_Man_t * p, Gia_Obj_t * pNode, Vec_Int_t * vSupp, Vec_Int_t * vSuppRefs )
{
if ( Gia_ObjIsTravIdCurrent(p, pNode) )
return;
Gia_ObjSetTravIdCurrent(p, pNode);
if ( Gia_ObjRefNum(p, pNode) || Gia_ObjIsCi(pNode) )
{
Vec_IntPush( vSupp, Gia_ObjId(p, pNode) );
Vec_IntPush( vSuppRefs, Gia_ObjRefNum(p, pNode) );
return;
}
assert( Gia_ObjIsAnd(pNode) );
Gia_NodeCollect_rec( p, Gia_ObjFanin0(pNode), vSupp, vSuppRefs );
Gia_NodeCollect_rec( p, Gia_ObjFanin1(pNode), vSupp, vSuppRefs );
}
static inline int Gia_NodeMffcSizeSupp( Gia_Man_t * p, Gia_Obj_t * pNode, Vec_Int_t * vSupp, Vec_Int_t * vSuppRefs )
{
int ConeSize1, ConeSize2, i, iObj;
assert( !Gia_IsComplement(pNode) );
assert( Gia_ObjIsAnd(pNode) );
Vec_IntClear( vSupp );
Vec_IntClear( vSuppRefs );
Gia_ManIncrementTravId( p );
ConeSize1 = Gia_NodeDeref_rec( p, pNode );
Gia_NodeCollect_rec( p, Gia_ObjFanin0(pNode), vSupp, vSuppRefs );
Gia_NodeCollect_rec( p, Gia_ObjFanin1(pNode), vSupp, vSuppRefs );
ConeSize2 = Gia_NodeRef_rec( p, pNode );
assert( ConeSize1 == ConeSize2 );
assert( ConeSize1 >= 0 );
// record supp refs
Vec_IntForEachEntry( vSupp, iObj, i )
Vec_IntAddToEntry( vSuppRefs, i, -Gia_ObjRefNumId(p, iObj) );
return ConeSize1;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Gia_ManDomDerive_rec( Gia_Man_t * pNew, Gia_Man_t * p, Gia_Obj_t * pNode )
{
if ( Gia_ObjIsTravIdCurrent(p, pNode) )
return pNode->Value;
Gia_ObjSetTravIdCurrent(p, pNode);
assert( Gia_ObjIsAnd(pNode) );
Gia_ManDomDerive_rec( pNew, p, Gia_ObjFanin0(pNode) );
Gia_ManDomDerive_rec( pNew, p, Gia_ObjFanin1(pNode) );
return pNode->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pNode), Gia_ObjFanin1Copy(pNode) );
}
Gia_Man_t * Gia_ManDomDerive( Gia_Man_t * p, Gia_Obj_t * pRoot, Vec_Int_t * vSupp, int nVars )
{
Gia_Man_t * pNew, * pTemp;
int nMints = 1 << nVars;
int i, m, iResLit;
assert( nVars >= 0 && nVars <= 5 );
pNew = Gia_ManStart( Gia_ManObjNum(p) );
pNew->pName = Abc_UtilStrsav( p->pName );
pNew->pSpec = Abc_UtilStrsav( p->pSpec );
Gia_ManConst0(p)->Value = 0;
Gia_ManHashAlloc( pNew );
for ( i = 0; i < Vec_IntSize(vSupp); i++ )
Gia_ManAppendCi(pNew);
for ( m = 0; m < nMints; m++ )
{
Gia_Obj_t * pObj;
Gia_ManIncrementTravId( p );
Gia_ManForEachObjVec( vSupp, p, pObj, i )
{
if ( i < nVars )
pObj->Value = (m >> i) & 1;
else
pObj->Value = Gia_ObjToLit(pNew, Gia_ManCi(pNew, i));
Gia_ObjSetTravIdCurrent( p, pObj );
}
iResLit = Gia_ManDomDerive_rec( pNew, p, pRoot );
Gia_ManAppendCo( pNew, iResLit );
}
Gia_ManHashStop( pNew );
pNew = Gia_ManCleanup( pTemp = pNew );
Gia_ManStop( pTemp );
return pNew;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_ManComputeDomsTry( Gia_Man_t * p )
{
extern void Gia_ManCollapseTestTest( Gia_Man_t * p );
Vec_Int_t * vSupp, * vSuppRefs;
Gia_Man_t * pNew;
Gia_Obj_t * pObj;
int i, nSize, Entry, k;
abctime clk = Abc_Clock();
ABC_FREE( p->pRefs );
Gia_ManLevelNum( p );
Gia_ManCreateRefs( p );
Gia_ManComputeDoms( p );
Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
vSupp = Vec_IntAlloc( 1000 );
vSuppRefs = Vec_IntAlloc( 1000 );
Gia_ManForEachObj( p, pObj, i )
{
if ( !Gia_ObjIsAnd(pObj) && !Gia_ObjIsCo(pObj) )
continue;
if ( Gia_ObjDom(p, pObj) != i )
continue;
if ( Gia_ObjIsCo(pObj) )
pObj = Gia_ObjFanin0(pObj);
if ( !Gia_ObjIsAnd(pObj) )
continue;
nSize = Gia_NodeMffcSizeSupp( p, pObj, vSupp, vSuppRefs );
if ( nSize < 10 )//|| nSize > 100 )
continue;
// sort by cost
Vec_IntSelectSortCost2( Vec_IntArray(vSupp), Vec_IntSize(vSupp), Vec_IntArray(vSuppRefs) );
printf( "Obj %6d : ", i );
printf( "Cone = %4d ", nSize );
printf( "Supp = %4d ", Vec_IntSize(vSupp) );
// Vec_IntForEachEntry( vSuppRefs, Entry, k )
// printf( "%d(%d) ", -Entry, Gia_ObjLevelId(p, Vec_IntEntry(vSupp, k)) );
printf( "\n" );
// selected k
for ( k = 0; k < Vec_IntSize(vSupp); k++ )
if ( Vec_IntEntry(vSuppRefs, k) == 1 )
break;
k = Abc_MinInt( k, 3 );
k = 0;
// dump
pNew = Gia_ManDomDerive( p, pObj, vSupp, k );
Gia_DumpAiger( pNew, "mffc", i, 6 );
Gia_ManCollapseTestTest( pNew );
Gia_ManStop( pNew );
}
Vec_IntFree( vSuppRefs );
Vec_IntFree( vSupp );
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END
|