ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
nwkDfs.c
Go to the documentation of this file.
1
20
21#include "nwk.h"
22
24
25
29
33
46{
47 Nwk_Obj_t * pObj, * pNext;
48 int i, k, iBox, iTerm1, nTerms;
50 Nwk_ManForEachObj( pNtk, pObj, i )
51 {
52 if ( Nwk_ObjIsNode(pObj) || Nwk_ObjIsCo(pObj) )
53 {
54 Nwk_ObjForEachFanin( pObj, pNext, k )
55 {
56 if ( !Nwk_ObjIsTravIdCurrent(pNext) )
57 {
58 printf( "Node %d has fanin %d that is not in a topological order.\n", pObj->Id, pNext->Id );
59 return 0;
60 }
61 }
62 }
63 else if ( Nwk_ObjIsCi(pObj) )
64 {
65 if ( pNtk->pManTime )
66 {
67 iBox = Tim_ManBoxForCi( pNtk->pManTime, pObj->PioId );
68 if ( iBox >= 0 ) // this is not a true PI
69 {
70 iTerm1 = Tim_ManBoxInputFirst( pNtk->pManTime, iBox );
71 nTerms = Tim_ManBoxInputNum( pNtk->pManTime, iBox );
72 for ( k = 0; k < nTerms; k++ )
73 {
74 pNext = Nwk_ManCo( pNtk, iTerm1 + k );
75 if ( !Nwk_ObjIsTravIdCurrent(pNext) )
76 {
77 printf( "Box %d has input %d that is not in a topological order.\n", iBox, pNext->Id );
78 return 0;
79 }
80 }
81 }
82 }
83 }
84 else
85 assert( 0 );
86 Nwk_ObjSetTravIdCurrent( pObj );
87 }
88 return 1;
89}
90
103{
104 Tim_Man_t * pManTimeUnit;
105 Nwk_Obj_t * pObj, * pFanin;
106 int i, k, LevelMax, Level;
108 // clean the levels
109 Nwk_ManForEachObj( pNtk, pObj, i )
110 Nwk_ObjSetLevel( pObj, 0 );
111 // perform level computation
112 LevelMax = 0;
113 pManTimeUnit = pNtk->pManTime ? Tim_ManDup( pNtk->pManTime, 1 ) : NULL;
114 if ( pManTimeUnit )
115 Tim_ManIncrementTravId( pManTimeUnit );
116 Nwk_ManForEachObj( pNtk, pObj, i )
117 {
118 if ( Nwk_ObjIsCi(pObj) )
119 {
120 Level = pManTimeUnit? (int)Tim_ManGetCiArrival( pManTimeUnit, pObj->PioId ) : 0;
121 Nwk_ObjSetLevel( pObj, Level );
122 }
123 else if ( Nwk_ObjIsCo(pObj) )
124 {
125 Level = Nwk_ObjLevel( Nwk_ObjFanin0(pObj) );
126 if ( pManTimeUnit )
127 Tim_ManSetCoArrival( pManTimeUnit, pObj->PioId, (float)Level );
128 Nwk_ObjSetLevel( pObj, Level );
129 if ( LevelMax < Nwk_ObjLevel(pObj) )
130 LevelMax = Nwk_ObjLevel(pObj);
131 }
132 else if ( Nwk_ObjIsNode(pObj) )
133 {
134 Level = 0;
135 Nwk_ObjForEachFanin( pObj, pFanin, k )
136 if ( Level < Nwk_ObjLevel(pFanin) )
137 Level = Nwk_ObjLevel(pFanin);
138 Nwk_ObjSetLevel( pObj, Level + 1 );
139 }
140 else
141 assert( 0 );
142 }
143 // set the old timing manager
144 if ( pManTimeUnit )
145 Tim_ManStop( pManTimeUnit );
146 return LevelMax;
147}
148
161{
162 Tim_Man_t * pManTime = pObj->pMan->pManTime;
163 Nwk_Obj_t * pNext;
164 int i, iBox, iTerm1, nTerms, LevelMax = 0;
165 if ( Nwk_ObjIsTravIdCurrent( pObj ) )
166 return;
167 Nwk_ObjSetTravIdCurrent( pObj );
168 if ( Nwk_ObjIsCi(pObj) )
169 {
170 if ( pManTime )
171 {
172 iBox = Tim_ManBoxForCi( pManTime, pObj->PioId );
173 if ( iBox >= 0 ) // this is not a true PI
174 {
175 iTerm1 = Tim_ManBoxInputFirst( pManTime, iBox );
176 nTerms = Tim_ManBoxInputNum( pManTime, iBox );
177 for ( i = 0; i < nTerms; i++ )
178 {
179 pNext = Nwk_ManCo(pObj->pMan, iTerm1 + i);
180 Nwk_ManLevel_rec( pNext );
181 if ( LevelMax < Nwk_ObjLevel(pNext) )
182 LevelMax = Nwk_ObjLevel(pNext);
183 }
184 LevelMax++;
185 }
186 }
187 }
188 else if ( Nwk_ObjIsNode(pObj) || Nwk_ObjIsCo(pObj) )
189 {
190 Nwk_ObjForEachFanin( pObj, pNext, i )
191 {
192 Nwk_ManLevel_rec( pNext );
193 if ( LevelMax < Nwk_ObjLevel(pNext) )
194 LevelMax = Nwk_ObjLevel(pNext);
195 }
196 if ( Nwk_ObjIsNode(pObj) && Nwk_ObjFaninNum(pObj) > 0 )
197 LevelMax++;
198 }
199 else
200 assert( 0 );
201 Nwk_ObjSetLevel( pObj, LevelMax );
202}
203
216{
217 Nwk_Obj_t * pObj;
218 int i, LevelMax = 0;
219 Nwk_ManForEachObj( pNtk, pObj, i )
220 Nwk_ObjSetLevel( pObj, 0 );
222 Nwk_ManForEachPo( pNtk, pObj, i )
223 {
224 Nwk_ManLevel_rec( pObj );
225 if ( LevelMax < Nwk_ObjLevel(pObj) )
226 LevelMax = Nwk_ObjLevel(pObj);
227 }
228 Nwk_ManForEachCi( pNtk, pObj, i )
229 {
230 Nwk_ManLevel_rec( pObj );
231 if ( LevelMax < Nwk_ObjLevel(pObj) )
232 LevelMax = Nwk_ObjLevel(pObj);
233 }
234 return LevelMax;
235}
236
249{
250 Nwk_Obj_t * pObj;
251 int i, LevelMax = 0;
252 Nwk_ManForEachPo( pNtk, pObj, i )
253 if ( LevelMax < Nwk_ObjLevel(pObj) )
254 LevelMax = Nwk_ObjLevel(pObj);
255 return LevelMax;
256}
257
270{
271 Nwk_Obj_t * pObj;
272 Vec_Vec_t * vLevels;
273 int nLevels, i;
274 assert( Nwk_ManVerifyLevel(pNtk) );
275 nLevels = Nwk_ManLevelMax( pNtk );
276 vLevels = Vec_VecStart( nLevels + 1 );
277 Nwk_ManForEachNode( pNtk, pObj, i )
278 {
279 assert( Nwk_ObjLevel(pObj) <= nLevels );
280 Vec_VecPush( vLevels, Nwk_ObjLevel(pObj), pObj );
281 }
282 return vLevels;
283}
284
285
286
298void Nwk_ManDfs_rec( Nwk_Obj_t * pObj, Vec_Ptr_t * vNodes )
299{
300 Nwk_Obj_t * pNext;
301 int i;
302 if ( Nwk_ObjIsTravIdCurrent( pObj ) )
303 return;
304 Nwk_ObjSetTravIdCurrent( pObj );
305 Nwk_ObjForEachFanin( pObj, pNext, i )
306 Nwk_ManDfs_rec( pNext, vNodes );
307 Vec_PtrPush( vNodes, pObj );
308}
309
322{
323 Vec_Ptr_t * vNodes;
324 Nwk_Obj_t * pObj;
325 int i;
327 vNodes = Vec_PtrAlloc( 100 );
328 Nwk_ManForEachObj( pNtk, pObj, i )
329 {
330 if ( Nwk_ObjIsCi(pObj) )
331 {
332 Nwk_ObjSetTravIdCurrent( pObj );
333 Vec_PtrPush( vNodes, pObj );
334 }
335 else if ( Nwk_ObjIsCo(pObj) )
336 Nwk_ManDfs_rec( pObj, vNodes );
337 }
338 return vNodes;
339}
340
353{
354 Nwk_Obj_t * pNext;
355 int i;
356 if ( Nwk_ObjIsTravIdCurrent( pObj ) )
357 return;
358 Nwk_ObjSetTravIdCurrent( pObj );
359 if ( Nwk_ObjIsCi(pObj) )
360 return;
361 assert( Nwk_ObjIsNode(pObj) );
362 Nwk_ObjForEachFanin( pObj, pNext, i )
363 Nwk_ManDfsNodes_rec( pNext, vNodes );
364 Vec_PtrPush( vNodes, pObj );
365}
366
378Vec_Ptr_t * Nwk_ManDfsNodes( Nwk_Man_t * pNtk, Nwk_Obj_t ** ppNodes, int nNodes )
379{
380 Vec_Ptr_t * vNodes;
381 int i;
382 // set the traversal ID
384 // start the array of nodes
385 vNodes = Vec_PtrAlloc( 100 );
386 // go through the PO nodes and call for each of them
387 for ( i = 0; i < nNodes; i++ )
388 if ( Nwk_ObjIsCo(ppNodes[i]) )
389 Nwk_ManDfsNodes_rec( Nwk_ObjFanin0(ppNodes[i]), vNodes );
390 else
391 Nwk_ManDfsNodes_rec( ppNodes[i], vNodes );
392 return vNodes;
393}
394
407{
408 Nwk_Obj_t * pNext;
409 int i, iBox, iTerm1, nTerms;
410 if ( Nwk_ObjIsTravIdCurrent( pObj ) )
411 return;
412 Nwk_ObjSetTravIdCurrent( pObj );
413 if ( Nwk_ObjIsCo(pObj) )
414 {
415 if ( pObj->pMan->pManTime )
416 {
417 iBox = Tim_ManBoxForCo( pObj->pMan->pManTime, pObj->PioId );
418 if ( iBox >= 0 ) // this is not a true PO
419 {
420 iTerm1 = Tim_ManBoxOutputFirst( pObj->pMan->pManTime, iBox );
421 nTerms = Tim_ManBoxOutputNum( pObj->pMan->pManTime, iBox );
422 for ( i = 0; i < nTerms; i++ )
423 {
424 pNext = Nwk_ManCi(pObj->pMan, iTerm1 + i);
425 Nwk_ManDfsReverse_rec( pNext, vNodes );
426 }
427 }
428 }
429 }
430 else if ( Nwk_ObjIsNode(pObj) || Nwk_ObjIsCi(pObj) )
431 {
432 Nwk_ObjForEachFanout( pObj, pNext, i )
433 Nwk_ManDfsReverse_rec( pNext, vNodes );
434 }
435 else
436 assert( 0 );
437 Vec_PtrPush( vNodes, pObj );
438}
439
452{
453 Vec_Ptr_t * vNodes;
454 Nwk_Obj_t * pObj;
455 int i;
457 vNodes = Vec_PtrAlloc( 100 );
458 Nwk_ManForEachPi( pNtk, pObj, i )
459 Nwk_ManDfsReverse_rec( pObj, vNodes );
460 // add nodes without fanins
461 Nwk_ManForEachNode( pNtk, pObj, i )
462 if ( Nwk_ObjFaninNum(pObj) == 0 && !Nwk_ObjIsTravIdCurrent(pObj) )
463 Vec_PtrPush( vNodes, pObj );
464 return vNodes;
465}
466
479{
480 Nwk_Obj_t * pFanin;
481 int i;
482 // if this node is already visited, skip
483 if ( Nwk_ObjIsTravIdCurrent( pNode ) )
484 return;
485 // mark the node as visited
486 Nwk_ObjSetTravIdCurrent( pNode );
487 // collect the CI
488 if ( Nwk_ObjIsCi(pNode) )
489 {
490 Vec_PtrPush( vNodes, pNode );
491 return;
492 }
493 assert( Nwk_ObjIsNode( pNode ) );
494 // visit the transitive fanin of the node
495 Nwk_ObjForEachFanin( pNode, pFanin, i )
496 Nwk_ManSupportNodes_rec( pFanin, vNodes );
497}
498
510Vec_Ptr_t * Nwk_ManSupportNodes( Nwk_Man_t * pNtk, Nwk_Obj_t ** ppNodes, int nNodes )
511{
512 Vec_Ptr_t * vNodes;
513 int i;
514 // set the traversal ID
516 // start the array of nodes
517 vNodes = Vec_PtrAlloc( 100 );
518 // go through the PO nodes and call for each of them
519 for ( i = 0; i < nNodes; i++ )
520 if ( Nwk_ObjIsCo(ppNodes[i]) )
521 Nwk_ManSupportNodes_rec( Nwk_ObjFanin0(ppNodes[i]), vNodes );
522 else
523 Nwk_ManSupportNodes_rec( ppNodes[i], vNodes );
524 return vNodes;
525}
526
539{
540 Vec_Ptr_t * vSupp;
541 Nwk_Obj_t * pObj;
542 int i, nTotalSupps = 0;
543 Nwk_ManForEachCo( pNtk, pObj, i )
544 {
545 vSupp = Nwk_ManSupportNodes( pNtk, &pObj, 1 );
546 nTotalSupps += Vec_PtrSize( vSupp );
547 Vec_PtrFree( vSupp );
548 }
549 printf( "Total supports = %d.\n", nTotalSupps );
550}
551
552
565{
566 Nwk_Obj_t * pFanin;
567 int i, Counter = 1;
568 if ( Nwk_ObjIsCi(pNode) )
569 return 0;
570 Nwk_ObjForEachFanin( pNode, pFanin, i )
571 {
572 assert( pFanin->nFanouts > 0 );
573 if ( --pFanin->nFanouts == 0 )
574 Counter += Nwk_ObjDeref_rec( pFanin );
575 }
576 return Counter;
577}
578
591{
592 Nwk_Obj_t * pFanin;
593 int i, Counter = 1;
594 if ( Nwk_ObjIsCi(pNode) )
595 return 0;
596 Nwk_ObjForEachFanin( pNode, pFanin, i )
597 {
598 if ( pFanin->nFanouts++ == 0 )
599 Counter += Nwk_ObjRef_rec( pFanin );
600 }
601 return Counter;
602}
603
615void Nwk_ObjMffcLabel_rec( Nwk_Obj_t * pNode, int fTopmost )
616{
617 Nwk_Obj_t * pFanin;
618 int i;
619 // add to the new support nodes
620 if ( !fTopmost && (Nwk_ObjIsCi(pNode) || pNode->nFanouts > 0) )
621 return;
622 // skip visited nodes
623 if ( Nwk_ObjIsTravIdCurrent(pNode) )
624 return;
625 Nwk_ObjSetTravIdCurrent(pNode);
626 // recur on the children
627 Nwk_ObjForEachFanin( pNode, pFanin, i )
628 Nwk_ObjMffcLabel_rec( pFanin, 0 );
629 // collect the internal node
630// printf( "%d ", pNode->Id );
631}
632
645{
646 int Count1, Count2;
647 // dereference the node
648 Count1 = Nwk_ObjDeref_rec( pNode );
649 // collect the nodes inside the MFFC
650 Nwk_ManIncrementTravId( pNode->pMan );
651 Nwk_ObjMffcLabel_rec( pNode, 1 );
652 // reference it back
653 Count2 = Nwk_ObjRef_rec( pNode );
654 assert( Count1 == Count2 );
655 return Count1;
656}
657
661
662
664
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
struct Nwk_Man_t_ Nwk_Man_t
Definition ntlnwk.h:41
int Nwk_ObjRef_rec(Nwk_Obj_t *pNode)
Definition nwkDfs.c:590
ABC_NAMESPACE_IMPL_START int Nwk_ManVerifyTopoOrder(Nwk_Man_t *pNtk)
DECLARATIONS ///.
Definition nwkDfs.c:45
Vec_Ptr_t * Nwk_ManDfsReverse(Nwk_Man_t *pNtk)
Definition nwkDfs.c:451
int Nwk_ObjMffcLabel(Nwk_Obj_t *pNode)
Definition nwkDfs.c:644
void Nwk_ManSupportNodes_rec(Nwk_Obj_t *pNode, Vec_Ptr_t *vNodes)
Definition nwkDfs.c:478
Vec_Vec_t * Nwk_ManLevelize(Nwk_Man_t *pNtk)
Definition nwkDfs.c:269
int Nwk_ManLevel(Nwk_Man_t *pNtk)
Definition nwkDfs.c:215
void Nwk_ManLevel_rec(Nwk_Obj_t *pObj)
Definition nwkDfs.c:160
void Nwk_ManSupportSum(Nwk_Man_t *pNtk)
Definition nwkDfs.c:538
Vec_Ptr_t * Nwk_ManSupportNodes(Nwk_Man_t *pNtk, Nwk_Obj_t **ppNodes, int nNodes)
Definition nwkDfs.c:510
void Nwk_ManDfs_rec(Nwk_Obj_t *pObj, Vec_Ptr_t *vNodes)
Definition nwkDfs.c:298
void Nwk_ObjMffcLabel_rec(Nwk_Obj_t *pNode, int fTopmost)
Definition nwkDfs.c:615
Vec_Ptr_t * Nwk_ManDfs(Nwk_Man_t *pNtk)
Definition nwkDfs.c:321
int Nwk_ObjDeref_rec(Nwk_Obj_t *pNode)
Definition nwkDfs.c:564
void Nwk_ManDfsNodes_rec(Nwk_Obj_t *pObj, Vec_Ptr_t *vNodes)
Definition nwkDfs.c:352
int Nwk_ManLevelBackup(Nwk_Man_t *pNtk)
Definition nwkDfs.c:102
void Nwk_ManDfsReverse_rec(Nwk_Obj_t *pObj, Vec_Ptr_t *vNodes)
Definition nwkDfs.c:406
Vec_Ptr_t * Nwk_ManDfsNodes(Nwk_Man_t *pNtk, Nwk_Obj_t **ppNodes, int nNodes)
Definition nwkDfs.c:378
int Nwk_ManLevelMax(Nwk_Man_t *pNtk)
Definition nwkDfs.c:248
#define Nwk_ManForEachPo(p, pObj, i)
Definition nwk.h:186
ABC_DLL void Nwk_ManIncrementTravId(Nwk_Man_t *pNtk)
DECLARATIONS ///.
Definition nwkUtil.c:47
#define Nwk_ManForEachNode(p, pObj, i)
Definition nwk.h:192
ABC_DLL int Nwk_ManVerifyLevel(Nwk_Man_t *pNtk)
Definition nwkTiming.c:832
#define Nwk_ManForEachCi(p, pObj, i)
ITERATORS ///.
Definition nwk.h:179
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition nwk.h:49
#define Nwk_ManForEachObj(p, pObj, i)
Definition nwk.h:189
#define Nwk_ObjForEachFanout(pObj, pFanout, i)
Definition nwk.h:201
#define Nwk_ManForEachPi(p, pObj, i)
Definition nwk.h:183
#define Nwk_ManForEachCo(p, pObj, i)
Definition nwk.h:181
#define Nwk_ObjForEachFanin(pObj, pFanin, i)
Definition nwk.h:199
Tim_Man_t * pManTime
Definition nwk.h:74
int Tim_ManBoxOutputNum(Tim_Man_t *p, int iBox)
Definition timBox.c:203
void Tim_ManSetCoArrival(Tim_Man_t *p, int iCo, float Delay)
Definition timTime.c:116
typedefABC_NAMESPACE_HEADER_START struct Tim_Man_t_ Tim_Man_t
INCLUDES ///.
Definition tim.h:92
void Tim_ManIncrementTravId(Tim_Man_t *p)
DECLARATIONS ///.
Definition timTrav.c:44
int Tim_ManBoxForCi(Tim_Man_t *p, int iCo)
Definition timBox.c:87
int Tim_ManBoxForCo(Tim_Man_t *p, int iCi)
Definition timBox.c:105
void Tim_ManStop(Tim_Man_t *p)
Definition timMan.c:378
int Tim_ManBoxInputFirst(Tim_Man_t *p, int iBox)
Definition timBox.c:123
int Tim_ManBoxInputNum(Tim_Man_t *p, int iBox)
Definition timBox.c:187
Tim_Man_t * Tim_ManDup(Tim_Man_t *p, int fUnitDelay)
Definition timMan.c:86
float Tim_ManGetCiArrival(Tim_Man_t *p, int iCi)
Definition timTime.c:174
int Tim_ManBoxOutputFirst(Tim_Man_t *p, int iBox)
Definition timBox.c:155
#define assert(ex)
Definition util_old.h:213
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.
Definition vecVec.h:42