ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
giaFanout.c
Go to the documentation of this file.
1
20
21#include "gia.h"
22
24
25
29
30// 0: first iFan
31// 1: prev iFan0
32// 2: prev iFan1
33// 3: next iFan0
34// 4: next iFan1
35
36static inline int Gia_FanoutCreate( int FanId, int Num ) { assert( Num < 2 ); return (FanId << 1) | Num; }
37static inline int * Gia_FanoutObj( int * pData, int ObjId ) { return pData + 5*ObjId; }
38static inline int * Gia_FanoutPrev( int * pData, int iFan ) { return pData + 5*(iFan >> 1) + 1 + (iFan & 1); }
39static inline int * Gia_FanoutNext( int * pData, int iFan ) { return pData + 5*(iFan >> 1) + 3 + (iFan & 1); }
40
41// these two procedures are only here for the use inside the iterator
42static inline int Gia_ObjFanout0Int( Gia_Man_t * p, int ObjId ) { assert(ObjId < p->nFansAlloc); return p->pFanData[5*ObjId]; }
43static inline int Gia_ObjFanoutNext( Gia_Man_t * p, int iFan ) { assert(iFan/2 < p->nFansAlloc); return p->pFanData[5*(iFan >> 1) + 3 + (iFan & 1)]; }
44
45// iterator over the fanouts
46#define Gia_ObjForEachFanout( p, pObj, pFanout, iFan, i ) \
47 for ( assert(p->pFanData), i = 0; (i < (int)(pObj)->nRefs) && \
48 (((iFan) = i? Gia_ObjFanoutNext(p, iFan) : Gia_ObjFanout0Int(p, Gia_ObjId(p, pObj))), 1) && \
49 (((pFanout) = Gia_ManObj(p, iFan>>1)), 1); i++ )
50
54
67{
68 Gia_Obj_t * pObj;
69 int i;
70 // allocate fanout datastructure
71 assert( p->pFanData == NULL );
72 p->nFansAlloc = 2 * Gia_ManObjNum(p);
73 if ( p->nFansAlloc < (1<<12) )
74 p->nFansAlloc = (1<<12);
75 p->pFanData = ABC_ALLOC( int, 5 * p->nFansAlloc );
76 memset( p->pFanData, 0, sizeof(int) * 5 * p->nFansAlloc );
77 // add fanouts for all objects
78 Gia_ManForEachObj( p, pObj, i )
79 {
80 if ( Gia_ObjChild0(pObj) )
81 Gia_ObjAddFanout( p, Gia_ObjFanin0(pObj), pObj );
82 if ( Gia_ObjChild1(pObj) )
83 Gia_ObjAddFanout( p, Gia_ObjFanin1(pObj), pObj );
84 }
85}
86
99{
100 assert( p->pFanData != NULL );
101 ABC_FREE( p->pFanData );
102 p->nFansAlloc = 0;
103}
104
116void Gia_ObjAddFanout( Gia_Man_t * p, Gia_Obj_t * pObj, Gia_Obj_t * pFanout )
117{
118 int iFan, * pFirst, * pPrevC, * pNextC, * pPrev, * pNext;
119 assert( p->pFanData );
120 assert( !Gia_IsComplement(pObj) && !Gia_IsComplement(pFanout) );
121 assert( Gia_ObjId(p, pFanout) > 0 );
122 if ( Gia_ObjId(p, pObj) >= p->nFansAlloc || Gia_ObjId(p, pFanout) >= p->nFansAlloc )
123 {
124 int nFansAlloc = 2 * Abc_MaxInt( Gia_ObjId(p, pObj), Gia_ObjId(p, pFanout) );
125 p->pFanData = ABC_REALLOC( int, p->pFanData, 5 * nFansAlloc );
126 memset( p->pFanData + 5 * p->nFansAlloc, 0, sizeof(int) * 5 * (nFansAlloc - p->nFansAlloc) );
127 p->nFansAlloc = nFansAlloc;
128 }
129 assert( Gia_ObjId(p, pObj) < p->nFansAlloc && Gia_ObjId(p, pFanout) < p->nFansAlloc );
130 iFan = Gia_FanoutCreate( Gia_ObjId(p, pFanout), Gia_ObjWhatFanin(p, pFanout, pObj) );
131 pPrevC = Gia_FanoutPrev( p->pFanData, iFan );
132 pNextC = Gia_FanoutNext( p->pFanData, iFan );
133 pFirst = Gia_FanoutObj( p->pFanData, Gia_ObjId(p, pObj) );
134 if ( *pFirst == 0 )
135 {
136 *pFirst = iFan;
137 *pPrevC = iFan;
138 *pNextC = iFan;
139 }
140 else
141 {
142 pPrev = Gia_FanoutPrev( p->pFanData, *pFirst );
143 pNext = Gia_FanoutNext( p->pFanData, *pPrev );
144 assert( *pNext == *pFirst );
145 *pPrevC = *pPrev;
146 *pNextC = *pFirst;
147 *pPrev = iFan;
148 *pNext = iFan;
149 }
150}
151
164{
165 int iFan, * pFirst, * pPrevC, * pNextC, * pPrev, * pNext;
166 assert( p->pFanData && Gia_ObjId(p, pObj) < p->nFansAlloc && Gia_ObjId(p, pFanout) < p->nFansAlloc );
167 assert( !Gia_IsComplement(pObj) && !Gia_IsComplement(pFanout) );
168 assert( Gia_ObjId(p, pFanout) > 0 );
169 iFan = Gia_FanoutCreate( Gia_ObjId(p, pFanout), Gia_ObjWhatFanin(p, pFanout, pObj) );
170 pPrevC = Gia_FanoutPrev( p->pFanData, iFan );
171 pNextC = Gia_FanoutNext( p->pFanData, iFan );
172 pPrev = Gia_FanoutPrev( p->pFanData, *pNextC );
173 pNext = Gia_FanoutNext( p->pFanData, *pPrevC );
174 assert( *pPrev == iFan );
175 assert( *pNext == iFan );
176 pFirst = Gia_FanoutObj( p->pFanData, Gia_ObjId(p, pObj) );
177 assert( *pFirst > 0 );
178 if ( *pFirst == iFan )
179 {
180 if ( *pNextC == iFan )
181 {
182 *pFirst = 0;
183 *pPrev = 0;
184 *pNext = 0;
185 *pPrevC = 0;
186 *pNextC = 0;
187 return;
188 }
189 *pFirst = *pNextC;
190 }
191 *pPrev = *pPrevC;
192 *pNext = *pNextC;
193 *pPrevC = 0;
194 *pNextC = 0;
195}
196
197
198
199
212{
213 Vec_Int_t * vEdgeMap;
214 Gia_Obj_t * pObj;
215 int i, iOffset;
216 iOffset = Gia_ManObjNum(p);
217 vEdgeMap = Vec_IntStart( iOffset + Gia_ManMuxNum(p) + 2 * Gia_ManAndNum(p) + Gia_ManCoNum(p) - Gia_ManBufNum(p) );
218 Gia_ManForEachObj( p, pObj, i )
219 {
220 Vec_IntWriteEntry( vEdgeMap, i, iOffset );
221 iOffset += Vec_IntEntry( vFanoutNums, Gia_ObjId(p, pObj) );
222 }
223 assert( iOffset <= Vec_IntSize(vEdgeMap) );
224 return vEdgeMap;
225}
226
239{
240 Vec_Int_t * vCounts;
241 int * pRefsOld;
242 Gia_Obj_t * pObj, * pFanin;
243 int i, iFanout;
244 assert( p->vFanoutNums == NULL );
245 assert( p->vFanout == NULL );
246 // recompute reference counters
247 pRefsOld = p->pRefs; p->pRefs = NULL;
249 p->vFanoutNums = Vec_IntAllocArray( p->pRefs, Gia_ManObjNum(p) );
250 p->pRefs = pRefsOld;
251 // start the fanout maps
252 p->vFanout = Gia_ManStartFanoutMap( p, p->vFanoutNums );
253 // incrementally add fanouts
254 vCounts = Vec_IntStart( Gia_ManObjNum(p) );
255 Gia_ManForEachObj( p, pObj, i )
256 {
257 if ( Gia_ObjIsAnd(pObj) || Gia_ObjIsCo(pObj) )
258 {
259 pFanin = Gia_ObjFanin0(pObj);
260 iFanout = Vec_IntEntry( vCounts, Gia_ObjId(p, pFanin) );
261 Gia_ObjSetFanout( p, pFanin, iFanout, pObj );
262 Vec_IntAddToEntry( vCounts, Gia_ObjId(p, pFanin), 1 );
263 }
264 if ( Gia_ObjIsAnd(pObj) && !Gia_ObjIsBuf(pObj) )
265 {
266 pFanin = Gia_ObjFanin1(pObj);
267 iFanout = Vec_IntEntry( vCounts, Gia_ObjId(p, pFanin) );
268 Gia_ObjSetFanout( p, pFanin, iFanout, pObj );
269 Vec_IntAddToEntry( vCounts, Gia_ObjId(p, pFanin), 1 );
270 }
271 if ( Gia_ObjIsMux(p, pObj) )
272 {
273
274 pFanin = Gia_ObjFanin2(p, pObj);
275 iFanout = Vec_IntEntry( vCounts, Gia_ObjId(p, pFanin) );
276 Gia_ObjSetFanout( p, pFanin, iFanout, pObj );
277 Vec_IntAddToEntry( vCounts, Gia_ObjId(p, pFanin), 1 );
278 }
279 }
280 // double-check the current number of fanouts added
281 Gia_ManForEachObj( p, pObj, i )
282 assert( Vec_IntEntry(vCounts, i) == Gia_ObjFanoutNum(p, pObj) );
283 Vec_IntFree( vCounts );
284}
285
286
299{
300 Gia_Obj_t * pObj;
301 int i, iOffset = Gia_ManObjNum(p);
302 Vec_Int_t * vEdgeMap = Vec_IntAlloc( 2 * iOffset );
303 Vec_IntFill( vEdgeMap, iOffset, 0 );
304 Gia_ManForEachObj( p, pObj, i )
305 {
306 if ( Vec_IntEntry(vFanoutNums, i) == 0 )
307 continue;
308 Vec_IntWriteEntry( vEdgeMap, i, iOffset );
309 iOffset += Vec_IntEntry( vFanoutNums, i );
310 Vec_IntFillExtra( vEdgeMap, iOffset, 0 );
311 }
312 //printf( "Fanout map is %.2fx larger than AIG manager.\n", 1.0*Vec_IntSize(vEdgeMap)/Gia_ManObjNum(p) );
313 return vEdgeMap;
314}
315
328{
329 int * pFanins = Gia_ObjLutFanins( p, iObj );
330 int i, k, nFanins = Gia_ObjLutSize( p, iObj );
331 for ( i = 0; i < nFanins; i++ )
332 for ( k = i + 1; k < nFanins; k++ )
333 assert( pFanins[i] != pFanins[k] );
334}
336{
337 Vec_Int_t * vCounts;
338 int * pRefsOld;
339 Gia_Obj_t * pObj, * pFanin;
340 int i, k, iFan, iFanout, Index;
341 assert( p->vFanoutNums == NULL );
342 assert( p->vFanout == NULL );
343 // recompute reference counters
344 pRefsOld = p->pLutRefs; p->pLutRefs = NULL;
346 p->vFanoutNums = Vec_IntAllocArray( p->pLutRefs, Gia_ManObjNum(p) );
347 p->pLutRefs = pRefsOld;
348 // start the fanout maps
349 p->vFanout = Gia_ManStartMappingFanoutMap( p, p->vFanoutNums );
350 if ( pvIndex )
351 *pvIndex = Vec_IntStart( Vec_IntSize(p->vFanout) );
352 // incrementally add fanouts
353 vCounts = Vec_IntStart( Gia_ManObjNum(p) );
354 Gia_ManForEachLut( p, i )
355 {
357 pObj = Gia_ManObj( p, i );
358 Gia_LutForEachFaninIndex( p, i, iFan, k, Index )
359 {
360 pFanin = Gia_ManObj( p, iFan );
361 iFanout = Vec_IntEntry( vCounts, iFan );
362 Gia_ObjSetFanout( p, pFanin, iFanout, pObj );
363 Vec_IntAddToEntry( vCounts, iFan, 1 );
364 if ( pvIndex )
365 Vec_IntWriteEntry( *pvIndex, Vec_IntEntry(p->vFanout, iFan) + iFanout, Index );
366 }
367 }
368 Gia_ManForEachCo( p, pObj, i )
369 {
370 iFan = Gia_ObjFaninId0p(p, pObj);
371 pFanin = Gia_ManObj( p, iFan );
372 iFanout = Vec_IntEntry( vCounts, iFan );
373 Gia_ObjSetFanout( p, pFanin, iFanout, pObj );
374 Vec_IntAddToEntry( vCounts, iFan, 1 );
375 }
376 // double-check the current number of fanouts added
377 Gia_ManForEachObj( p, pObj, i )
378 assert( Vec_IntEntry(vCounts, i) == Gia_ObjFanoutNum(p, pObj) );
379 Vec_IntFree( vCounts );
380}
381
394{
395 Vec_IntFreeP( &p->vFanoutNums );
396 Vec_IntFreeP( &p->vFanout );
397}
398
399
412{
413 Gia_Obj_t * pObj, * pFanout;
414 int i, k;
416 Gia_ManForEachObj( p, pObj, i )
417 {
418 Gia_ObjPrint( p, pObj );
419 printf( " Fanouts : " );
420 Gia_ObjForEachFanoutStatic( p, pObj, pFanout, k )
421 printf( "%5d ", Gia_ObjId(p, pFanout) );
422 printf( "\n" );
423 }
425}
426
430
431
433
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_REALLOC(type, obj, num)
Definition abc_global.h:268
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Cube * p
Definition exorList.c:222
void Gia_ManFanoutStart(Gia_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition giaFanout.c:66
void Gia_ManStaticFanoutStart(Gia_Man_t *p)
Definition giaFanout.c:238
void Gia_ManStaticFanoutStop(Gia_Man_t *p)
Definition giaFanout.c:393
void Gia_ManStaticFanoutTest(Gia_Man_t *p)
Definition giaFanout.c:411
void Gia_ManStaticMappingFanoutStart(Gia_Man_t *p, Vec_Int_t **pvIndex)
Definition giaFanout.c:335
Vec_Int_t * Gia_ManStartMappingFanoutMap(Gia_Man_t *p, Vec_Int_t *vFanoutNums)
Definition giaFanout.c:298
Vec_Int_t * Gia_ManStartFanoutMap(Gia_Man_t *p, Vec_Int_t *vFanoutNums)
Definition giaFanout.c:211
void Gia_ObjCheckDupMappingFanins(Gia_Man_t *p, int iObj)
Definition giaFanout.c:327
void Gia_ObjRemoveFanout(Gia_Man_t *p, Gia_Obj_t *pObj, Gia_Obj_t *pFanout)
Definition giaFanout.c:163
void Gia_ManFanoutStop(Gia_Man_t *p)
Definition giaFanout.c:98
void Gia_ObjAddFanout(Gia_Man_t *p, Gia_Obj_t *pObj, Gia_Obj_t *pFanout)
Definition giaFanout.c:116
#define Gia_ObjForEachFanoutStatic(p, pObj, pFanout, i)
Definition gia.h:1125
#define Gia_ManForEachLut(p, i)
Definition gia.h:1157
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
void Gia_ObjPrint(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition giaUtil.c:1456
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
void Gia_ManCreateRefs(Gia_Man_t *p)
Definition giaUtil.c:779
#define Gia_ManForEachObj(p, pObj, i)
MACRO DEFINITIONS ///.
Definition gia.h:1190
#define Gia_ManForEachCo(p, pObj, i)
Definition gia.h:1236
void Gia_ManSetLutRefs(Gia_Man_t *p)
Definition giaIf.c:295
#define Gia_LutForEachFaninIndex(p, i, iFan, k, Index)
Definition gia.h:1163
#define assert(ex)
Definition util_old.h:213
char * memset()