ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
abcHaig.c
Go to the documentation of this file.
1
20
21#include "base/abc/abc.h"
22
24
25
29
33
34
47{
48 Vec_Ptr_t * vObjs;
49 Hop_Obj_t * pObj;
50 int i;
51 vObjs = Vec_PtrAlloc( 4098 );
52 Vec_PtrForEachEntry( Hop_Obj_t *, p->vObjs, pObj, i )
53 {
54 if ( pObj->pData == NULL )
55 continue;
56 pObj->pData = Hop_ObjRepr( pObj );
57 Vec_PtrPush( vObjs, pObj );
58 }
59 return vObjs;
60}
61
74{
75 Vec_Ptr_t * vClasses;
76 Hop_Obj_t * pObj, * pRepr;
77 int i;
78
79 // count classes
80 vClasses = Vec_PtrAlloc( 4098 );
81 Vec_PtrForEachEntry( Hop_Obj_t *, vMembers, pObj, i )
82 {
83 pRepr = (Hop_Obj_t *)pObj->pData;
84 assert( pRepr->pData == NULL );
85 if ( pRepr->fMarkA == 0 ) // new
86 {
87 pRepr->fMarkA = 1;
88 Vec_PtrPush( vClasses, pRepr );
89 }
90 }
91
92 // set representatives as representatives
93 Vec_PtrForEachEntry( Hop_Obj_t *, vClasses, pObj, i )
94 {
95 pObj->fMarkA = 0;
96 pObj->pData = pObj;
97 }
98
99 // go through the members and update
100 Vec_PtrForEachEntry( Hop_Obj_t *, vMembers, pObj, i )
101 {
102 pRepr = (Hop_Obj_t *)pObj->pData;
103 if ( ((Hop_Obj_t *)pRepr->pData)->Id > pObj->Id )
104 pRepr->pData = pObj;
105 }
106
107 // change representatives of the class
108 Vec_PtrForEachEntry( Hop_Obj_t *, vMembers, pObj, i )
109 {
110 pRepr = (Hop_Obj_t *)pObj->pData;
111 pObj->pData = pRepr->pData;
112 assert( ((Hop_Obj_t *)pObj->pData)->Id <= pObj->Id );
113 }
114
115 // update classes
116 Vec_PtrForEachEntry( Hop_Obj_t *, vClasses, pObj, i )
117 {
118 pRepr = (Hop_Obj_t *)pObj->pData;
119 assert( pRepr->pData == pRepr );
120// pRepr->pData = NULL;
121 Vec_PtrWriteEntry( vClasses, i, pRepr );
122 Vec_PtrPush( vMembers, pObj );
123 }
124
125 Vec_PtrForEachEntry( Hop_Obj_t *, vMembers, pObj, i )
126 if ( pObj->pData == pObj )
127 pObj->pData = NULL;
128
129/*
130 Vec_PtrForEachEntry( Hop_Obj_t *, vMembers, pObj, i )
131 {
132 printf( "ObjId = %4d : ", pObj->Id );
133 if ( pObj->pData == NULL )
134 {
135 printf( "NULL" );
136 }
137 else
138 {
139 printf( "%4d", ((Hop_Obj_t *)pObj->pData)->Id );
140 assert( ((Hop_Obj_t *)pObj->pData)->Id <= pObj->Id );
141 }
142 printf( "\n" );
143 }
144*/
145 return vClasses;
146}
147
160{
161 Hop_Obj_t * pObj;
162 int i, Counter = 0;
163 Vec_PtrForEachEntry( Hop_Obj_t *, p->vObjs, pObj, i )
164 {
165 if ( pObj->pData == NULL )
166 continue;
167 if ( Hop_ObjRefs(pObj) > 0 )
168 Counter++;
169 }
170 printf( "The number of class members with fanouts = %5d.\n", Counter );
171 return Counter;
172}
173
174
186static inline Hop_Obj_t * Hop_ObjReprHop( Hop_Obj_t * pObj )
187{
188 Hop_Obj_t * pRepr;
189 assert( pObj->pNext != NULL );
190 if ( pObj->pData == NULL )
191 return pObj->pNext;
192 pRepr = (Hop_Obj_t *)pObj->pData;
193 assert( pRepr->pData == pRepr );
194 return Hop_NotCond( pRepr->pNext, pObj->fPhase ^ pRepr->fPhase );
195}
196
208static inline Hop_Obj_t * Hop_ObjChild0Hop( Hop_Obj_t * pObj ) { return Hop_NotCond( Hop_ObjReprHop(Hop_ObjFanin0(pObj)), Hop_ObjFaninC0(pObj) ); }
209static inline Hop_Obj_t * Hop_ObjChild1Hop( Hop_Obj_t * pObj ) { return Hop_NotCond( Hop_ObjReprHop(Hop_ObjFanin1(pObj)), Hop_ObjFaninC1(pObj) ); }
210
223{
224 Hop_Man_t * pNew;
225 Hop_Obj_t * pObj;
226 int i, Counter = 0;
227 Vec_PtrForEachEntry( Hop_Obj_t *, p->vObjs, pObj, i )
228 pObj->pNext = NULL;
229 // start the HOP package
230 pNew = Hop_ManStart();
231 pNew->vObjs = Vec_PtrAlloc( p->nCreated );
232 Vec_PtrPush( pNew->vObjs, Hop_ManConst1(pNew) );
233 // map the constant node
234 Hop_ManConst1(p)->pNext = Hop_ManConst1(pNew);
235 // map the CIs
236 Hop_ManForEachPi( p, pObj, i )
237 pObj->pNext = Hop_ObjCreatePi(pNew);
238 // map the internal nodes
239 Vec_PtrForEachEntry( Hop_Obj_t *, p->vObjs, pObj, i )
240 {
241 if ( !Hop_ObjIsNode(pObj) )
242 continue;
243 pObj->pNext = Hop_And( pNew, Hop_ObjChild0Hop(pObj), Hop_ObjChild1Hop(pObj) );
244// assert( !Hop_IsComplement(pObj->pNext) );
245 if ( Hop_ManConst1(pNew) == Hop_Regular(pObj->pNext) )
246 Counter++;
247 if ( pObj->pData ) // member of the class
248 Hop_Regular(pObj->pNext)->pData = Hop_Regular(((Hop_Obj_t *)pObj->pData)->pNext);
249 }
250// printf( " Counter = %d.\n", Counter );
251 // transfer the POs
252 Hop_ManForEachPo( p, pObj, i )
253 Hop_ObjCreatePo( pNew, Hop_ObjChild0Hop(pObj) );
254 // check the new manager
255 if ( !Hop_ManCheck(pNew) )
256 {
257 printf( "Abc_NtkHaigReconstruct: Check for History AIG has failed.\n" );
258 Hop_ManStop(pNew);
259 return NULL;
260 }
261 return pNew;
262}
263
264
277{
278 if ( pNode == NULL )
279 return 0;
280 if ( pNode == pOld )
281 return 1;
282 // check the trivial cases
283 if ( Abc_ObjIsCi(pNode) )
284 return 0;
285 assert( Abc_ObjIsNode(pNode) );
286 // if this node is already visited, skip
287 if ( Abc_NodeIsTravIdCurrent( pNode ) )
288 return 0;
289 // mark the node as visited
290 Abc_NodeSetTravIdCurrent( pNode );
291 // check the children
292 if ( Abc_NtkHaigCheckTfi_rec( Abc_ObjFanin0(pNode), pOld ) )
293 return 1;
294 if ( Abc_NtkHaigCheckTfi_rec( Abc_ObjFanin1(pNode), pOld ) )
295 return 1;
296 // check equivalent nodes
297 return Abc_NtkHaigCheckTfi_rec( (Abc_Obj_t *)pNode->pData, pOld );
298}
299
312{
313 assert( !Abc_ObjIsComplement(pOld) );
314 assert( !Abc_ObjIsComplement(pNew) );
315 Abc_NtkIncrementTravId(pNtk);
316 return Abc_NtkHaigCheckTfi_rec( pNew, pOld );
317}
318
330static inline Abc_Obj_t * Hop_ObjChild0Next( Hop_Obj_t * pObj ) { return Abc_ObjNotCond( (Abc_Obj_t *)Hop_ObjFanin0(pObj)->pNext, Hop_ObjFaninC0(pObj) ); }
331static inline Abc_Obj_t * Hop_ObjChild1Next( Hop_Obj_t * pObj ) { return Abc_ObjNotCond( (Abc_Obj_t *)Hop_ObjFanin1(pObj)->pNext, Hop_ObjFaninC1(pObj) ); }
332
345{
346 Abc_Ntk_t * pNtkAig;
347 Abc_Obj_t * pObjOld, * pObjAbcThis, * pObjAbcRepr;
348 Hop_Obj_t * pObj;
349 int i;
350 assert( p->nCreated == Vec_PtrSize(p->vObjs) );
351
352 // start the new network
353 pNtkAig = Abc_NtkStartFrom( pNtk, ABC_NTK_STRASH, ABC_FUNC_AIG );
354
355 // transfer new nodes to the PIs of HOP
356 Hop_ManConst1(p)->pNext = (Hop_Obj_t *)Abc_AigConst1( pNtkAig );
357 Hop_ManForEachPi( p, pObj, i )
358 pObj->pNext = (Hop_Obj_t *)Abc_NtkCi( pNtkAig, i );
359
360 // construct new nodes
361 Vec_PtrForEachEntry( Hop_Obj_t *, p->vObjs, pObj, i )
362 {
363 if ( !Hop_ObjIsNode(pObj) )
364 continue;
365 pObj->pNext = (Hop_Obj_t *)Abc_AigAnd( (Abc_Aig_t *)pNtkAig->pManFunc, Hop_ObjChild0Next(pObj), Hop_ObjChild1Next(pObj) );
366 assert( !Hop_IsComplement(pObj->pNext) );
367 }
368
369 // set the COs
370 Abc_NtkForEachCo( pNtk, pObjOld, i )
371 Abc_ObjAddFanin( pObjOld->pCopy, Hop_ObjChild0Next(Hop_ManPo(p,i)) );
372
373 // construct choice nodes
374 Vec_PtrForEachEntry( Hop_Obj_t *, p->vObjs, pObj, i )
375 {
376 // skip the node without choices
377 if ( pObj->pData == NULL )
378 continue;
379 // skip the representative of the class
380 if ( pObj->pData == pObj )
381 continue;
382 // do not create choices for constant 1 and PIs
383 if ( !Hop_ObjIsNode((Hop_Obj_t *)pObj->pData) )
384 continue;
385 // get the corresponding new nodes
386 pObjAbcThis = (Abc_Obj_t *)pObj->pNext;
387 pObjAbcRepr = (Abc_Obj_t *)((Hop_Obj_t *)pObj->pData)->pNext;
388 // the new node cannot be already in the class
389 assert( pObjAbcThis->pData == NULL );
390 // the new node cannot have fanouts
391 assert( Abc_ObjFanoutNum(pObjAbcThis) == 0 );
392 // these should be different nodes
393 assert( pObjAbcRepr != pObjAbcThis );
394 // do not create choices if there is a path from pObjAbcThis to pObjAbcRepr
395 if ( !Abc_NtkHaigCheckTfi( pNtkAig, pObjAbcRepr, pObjAbcThis ) )
396 {
397 // find the last node in the class
398 while ( pObjAbcRepr->pData )
399 pObjAbcRepr = (Abc_Obj_t *)pObjAbcRepr->pData;
400 // add the new node at the end of the list
401 pObjAbcRepr->pData = pObjAbcThis;
402 }
403 }
404
405 // finish the new network
406// Abc_NtkFinalize( pNtk, pNtkAig );
407// Abc_AigCleanup( pNtkAig->pManFunc );
408 // check correctness of the network
409 if ( !Abc_NtkCheck( pNtkAig ) )
410 {
411 printf( "Abc_NtkHaigUse: The network check has failed.\n" );
412 Abc_NtkDelete( pNtkAig );
413 return NULL;
414 }
415 return pNtkAig;
416}
417
430{
431 Vec_Ptr_t * vMembers, * vClasses;
432
433 // collect members of the classes and make them point to reprs
434 vMembers = Abc_NtkHaigCollectMembers( pMan );
435 printf( "Collected %6d class members.\n", Vec_PtrSize(vMembers) );
436
437 // create classes
438 vClasses = Abc_NtkHaigCreateClasses( vMembers );
439 printf( "Collected %6d classes. (Ave = %5.2f)\n", Vec_PtrSize(vClasses),
440 (float)(Vec_PtrSize(vMembers))/Vec_PtrSize(vClasses) );
441
442 Vec_PtrFree( vMembers );
443 Vec_PtrFree( vClasses );
444}
445
458{
459 Hop_Obj_t * pObj, * pRepr;
460 int i, nClasses, nMembers, nFanouts, nNormals;
461 // clear self-classes
462 Vec_PtrForEachEntry( Hop_Obj_t *, p->vObjs, pObj, i )
463 {
464 // fix the strange situation of double-loop
465 pRepr = (Hop_Obj_t *)pObj->pData;
466 if ( pRepr && pRepr->pData == pObj )
467 pRepr->pData = pRepr;
468 // remove self-loops
469 if ( pObj->pData == pObj )
470 pObj->pData = NULL;
471 }
472 // set representatives
473 Vec_PtrForEachEntry( Hop_Obj_t *, p->vObjs, pObj, i )
474 {
475 if ( pObj->pData == NULL )
476 continue;
477 // get representative of the node
478 pRepr = Hop_ObjRepr( pObj );
479 pRepr->pData = pRepr;
480 // set the representative
481 pObj->pData = pRepr;
482 }
483 // make each class point to the smallest topological order
484 Vec_PtrForEachEntry( Hop_Obj_t *, p->vObjs, pObj, i )
485 {
486 if ( pObj->pData == NULL )
487 continue;
488 pRepr = Hop_ObjRepr( pObj );
489 if ( pRepr->Id > pObj->Id )
490 {
491 pRepr->pData = pObj;
492 pObj->pData = pObj;
493 }
494 else
495 pObj->pData = pRepr;
496 }
497 // count classes, members, and fanouts - and verify
498 nMembers = nClasses = nFanouts = nNormals = 0;
499 Vec_PtrForEachEntry( Hop_Obj_t *, p->vObjs, pObj, i )
500 {
501 if ( pObj->pData == NULL )
502 continue;
503 // count members
504 nMembers++;
505 // count the classes and fanouts
506 if ( pObj->pData == pObj )
507 nClasses++;
508 else if ( Hop_ObjRefs(pObj) > 0 )
509 nFanouts++;
510 else
511 nNormals++;
512 // compare representatives
513 pRepr = Hop_ObjRepr( pObj );
514 assert( pObj->pData == pRepr );
515 assert( pRepr->Id <= pObj->Id );
516 }
517// printf( "Nodes = %7d. Member = %7d. Classes = %6d. Fanouts = %6d. Normals = %6d.\n",
518// Hop_ManNodeNum(p), nMembers, nClasses, nFanouts, nNormals );
519 return nFanouts;
520}
521
534{
535 Abc_Ntk_t * pNtkAig;
536 Hop_Man_t * pManTemp;
537
538 // iteratively reconstruct the HOP manager to create choice nodes
539 while ( Abc_NtkHaigResetReprs( pMan ) )
540 {
541 pMan = Abc_NtkHaigReconstruct( pManTemp = pMan );
542 Hop_ManStop( pManTemp );
543 }
544
545 // traverse in the topological order and create new AIG
546 pNtkAig = Abc_NtkHaigRecreateAig( pNtk, pMan );
547 Hop_ManStop( pMan );
548 return pNtkAig;
549}
550
554
555
557
int Abc_NtkHaigCheckTfi(Abc_Ntk_t *pNtk, Abc_Obj_t *pOld, Abc_Obj_t *pNew)
Definition abcHaig.c:311
int Abc_NtkHaigCheckTfi_rec(Abc_Obj_t *pNode, Abc_Obj_t *pOld)
Definition abcHaig.c:276
int Abc_NtkHaigResetReprs(Hop_Man_t *p)
Definition abcHaig.c:457
Vec_Ptr_t * Abc_NtkHaigCreateClasses(Vec_Ptr_t *vMembers)
Definition abcHaig.c:73
Hop_Man_t * Abc_NtkHaigReconstruct(Hop_Man_t *p)
Definition abcHaig.c:222
int Abc_NtkHaigCountFans(Hop_Man_t *p)
Definition abcHaig.c:159
void Abc_NtkHaigResetReprsOld(Hop_Man_t *pMan)
Definition abcHaig.c:429
Abc_Ntk_t * Abc_NtkHopRemoveLoops(Abc_Ntk_t *pNtk, Hop_Man_t *pMan)
Definition abcHaig.c:533
ABC_NAMESPACE_IMPL_START Vec_Ptr_t * Abc_NtkHaigCollectMembers(Hop_Man_t *p)
DECLARATIONS ///.
Definition abcHaig.c:46
Abc_Ntk_t * Abc_NtkHaigRecreateAig(Abc_Ntk_t *pNtk, Hop_Man_t *p)
Definition abcHaig.c:344
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition abc.h:522
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition abcFanio.c:84
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition abcCheck.c:64
struct Abc_Aig_t_ Abc_Aig_t
Definition abc.h:117
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
@ ABC_NTK_STRASH
Definition abc.h:58
ABC_DLL Abc_Obj_t * Abc_AigAnd(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
Definition abcAig.c:700
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition abcNtk.c:1421
@ ABC_FUNC_AIG
Definition abc.h:67
ABC_DLL Abc_Ntk_t * Abc_NtkStartFrom(Abc_Ntk_t *pNtk, Abc_NtkType_t Type, Abc_NtkFunc_t Func)
Definition abcNtk.c:157
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
Definition abcAig.c:683
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
Cube * p
Definition exorList.c:222
Hop_Obj_t * Hop_ObjCreatePo(Hop_Man_t *p, Hop_Obj_t *pDriver)
Definition hopObj.c:67
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition hop.h:49
int Hop_ManCheck(Hop_Man_t *p)
DECLARATIONS ///.
Definition hopCheck.c:45
#define Hop_ManForEachPi(p, pObj, i)
ITERATORS ///.
Definition hop.h:259
Hop_Obj_t * Hop_And(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
Definition hopOper.c:104
void Hop_ManStop(Hop_Man_t *p)
Definition hopMan.c:84
#define Hop_ManForEachPo(p, pObj, i)
Definition hop.h:262
Hop_Obj_t * Hop_ObjCreatePi(Hop_Man_t *p)
DECLARATIONS ///.
Definition hopObj.c:45
Hop_Man_t * Hop_ManStart()
DECLARATIONS ///.
Definition hopMan.c:45
Hop_Obj_t * Hop_ObjRepr(Hop_Obj_t *pObj)
Definition hopObj.c:241
struct Hop_Obj_t_ Hop_Obj_t
Definition hop.h:50
void * pManFunc
Definition abc.h:191
void * pData
Definition abc.h:145
Abc_Obj_t * pCopy
Definition abc.h:148
Abc_Obj_t * pNext
Definition abc.h:131
unsigned int fPhase
Definition hop.h:76
Hop_Obj_t * pNext
Definition hop.h:71
unsigned int fMarkA
Definition hop.h:77
int Id
Definition hop.h:80
void * pData
Definition hop.h:68
#define assert(ex)
Definition util_old.h:213
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55