ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
abcSweep.c
Go to the documentation of this file.
1
20
21#include "base/abc/abc.h"
22#include "base/main/main.h"
23#include "proof/fraig/fraig.h"
24
25#ifdef ABC_USE_CUDD
26#include "bdd/extrab/extraBdd.h"
27#endif
28
30
34
35static void Abc_NtkFraigSweepUsingExdc( Fraig_Man_t * pMan, Abc_Ntk_t * pNtk );
36static stmm_table * Abc_NtkFraigEquiv( Abc_Ntk_t * pNtk, int fUseInv, int fVerbose, int fVeryVerbose );
37static void Abc_NtkFraigTransform( Abc_Ntk_t * pNtk, stmm_table * tEquiv, int fUseInv, int fVerbose );
38static void Abc_NtkFraigMergeClassMapped( Abc_Ntk_t * pNtk, Abc_Obj_t * pChain, int fUseInv, int fVerbose );
39static void Abc_NtkFraigMergeClass( Abc_Ntk_t * pNtk, Abc_Obj_t * pChain, int fUseInv, int fVerbose );
40static int Abc_NodeDroppingCost( Abc_Obj_t * pNode );
41
42static int Abc_NtkReduceNodes( Abc_Ntk_t * pNtk, Vec_Ptr_t * vNodes );
43static void Abc_NodeSweep( Abc_Obj_t * pNode, int fVerbose );
44
48
62int Abc_NtkFraigSweep( Abc_Ntk_t * pNtk, int fUseInv, int fExdc, int fVerbose, int fVeryVerbose )
63{
64 Fraig_Params_t Params;
65 Abc_Ntk_t * pNtkAig;
66 Fraig_Man_t * pMan;
67 stmm_table * tEquiv;
68 Abc_Obj_t * pObj;
69 int i, fUseTrick;
70
71 assert( !Abc_NtkIsStrash(pNtk) );
72
73 // save gate assignments
74 fUseTrick = 0;
75 if ( Abc_NtkIsMappedLogic(pNtk) )
76 {
77 fUseTrick = 1;
78 Abc_NtkForEachNode( pNtk, pObj, i )
79 pObj->pNext = (Abc_Obj_t *)pObj->pData;
80 }
81 // derive the AIG
82 pNtkAig = Abc_NtkStrash( pNtk, 0, 1, 0 );
83 // reconstruct gate assignments
84 if ( fUseTrick )
85 {
86// extern void * Abc_FrameReadLibGen();
87 Hop_ManStop( (Hop_Man_t *)pNtk->pManFunc );
89 pNtk->ntkFunc = ABC_FUNC_MAP;
90 Abc_NtkForEachNode( pNtk, pObj, i )
91 pObj->pData = pObj->pNext, pObj->pNext = NULL;
92 }
93
94 // perform fraiging of the AIG
95 Fraig_ParamsSetDefault( &Params );
96 Params.fInternal = 1;
97 pMan = (Fraig_Man_t *)Abc_NtkToFraig( pNtkAig, &Params, 0, 0 );
98 // cannot use EXDC with FRAIG because it can create classes of equivalent FRAIG nodes
99 // with representative nodes that do not correspond to the nodes with the current network
100
101 // update FRAIG using EXDC
102 if ( fExdc )
103 {
104 if ( pNtk->pExdc == NULL )
105 printf( "Warning: Networks has no EXDC.\n" );
106 else
107 Abc_NtkFraigSweepUsingExdc( pMan, pNtk );
108 }
109 // assign levels to the nodes of the network
110 Abc_NtkLevel( pNtk );
111
112 // collect the classes of equivalent nets
113 tEquiv = Abc_NtkFraigEquiv( pNtk, fUseInv, fVerbose, fVeryVerbose );
114
115 // transform the network into the equivalent one
116 Abc_NtkFraigTransform( pNtk, tEquiv, fUseInv, fVerbose );
117 stmm_free_table( tEquiv );
118
119 // free the manager
120 Fraig_ManFree( pMan );
121 Abc_NtkDelete( pNtkAig );
122
123 // cleanup the dangling nodes
124 if ( Abc_NtkHasMapping(pNtk) )
125 Abc_NtkCleanup( pNtk, fVerbose );
126 else
127 Abc_NtkSweep( pNtk, fVerbose );
128
129 // check
130 if ( !Abc_NtkCheck( pNtk ) )
131 {
132 printf( "Abc_NtkFraigSweep: The network check has failed.\n" );
133 return 0;
134 }
135 return 1;
136}
137
149void Abc_NtkFraigSweepUsingExdc( Fraig_Man_t * pMan, Abc_Ntk_t * pNtk )
150{
151 Fraig_Node_t * gNodeExdc, * gNode, * gNodeRes;
152 Abc_Obj_t * pNode, * pNodeAig;
153 int i;
154 extern Fraig_Node_t * Abc_NtkToFraigExdc( Fraig_Man_t * pMan, Abc_Ntk_t * pNtk, Abc_Ntk_t * pNtkExdc );
155
156 assert( pNtk->pExdc );
157 // derive FRAIG node representing don't-cares in the EXDC network
158 gNodeExdc = Abc_NtkToFraigExdc( pMan, pNtk, pNtk->pExdc );
159 // update the node pointers
160 Abc_NtkForEachNode( pNtk, pNode, i )
161 {
162 // skip the constant input nodes
163 if ( Abc_ObjFaninNum(pNode) == 0 )
164 continue;
165 // get the strashed node
166 pNodeAig = pNode->pCopy;
167 // skip the dangling nodes
168 if ( pNodeAig == NULL )
169 continue;
170 // get the FRAIG node
171 gNode = Fraig_NotCond( Abc_ObjRegular(pNodeAig)->pCopy, (int)Abc_ObjIsComplement(pNodeAig) );
172 // perform ANDing with EXDC
173 gNodeRes = Fraig_NodeAnd( pMan, gNode, Fraig_Not(gNodeExdc) );
174 // write the node back
175 Abc_ObjRegular(pNodeAig)->pCopy = (Abc_Obj_t *)Fraig_NotCond( gNodeRes, (int)Abc_ObjIsComplement(pNodeAig) );
176 }
177}
178
190stmm_table * Abc_NtkFraigEquiv( Abc_Ntk_t * pNtk, int fUseInv, int fVerbose, int fVeryVerbose )
191{
192 Abc_Obj_t * pList, * pNode, * pNodeAig;
193 Fraig_Node_t * gNode;
194 Abc_Obj_t ** ppSlot;
195 stmm_table * tStrash2Net;
196 stmm_table * tResult;
197 stmm_generator * gen;
198 int c, Counter;
199
200 // create mapping of strashed nodes into the corresponding network nodes
202 Abc_NtkForEachNode( pNtk, pNode, c )
203 {
204 // skip the constant input nodes
205 if ( Abc_ObjFaninNum(pNode) == 0 )
206 continue;
207 // get the strashed node
208 pNodeAig = pNode->pCopy;
209 // skip the dangling nodes
210 if ( pNodeAig == NULL )
211 continue;
212 // skip the nodes that fanout into COs
213 if ( Abc_NodeFindCoFanout(pNode) )
214 continue;
215 // get the FRAIG node
216 gNode = Fraig_NotCond( Abc_ObjRegular(pNodeAig)->pCopy, (int)Abc_ObjIsComplement(pNodeAig) );
217 if ( !stmm_find_or_add( tStrash2Net, (char *)Fraig_Regular(gNode), (char ***)&ppSlot ) )
218 *ppSlot = NULL;
219 // add the node to the list
220 pNode->pNext = *ppSlot;
221 *ppSlot = pNode;
222 // mark the node if it is complemented
223 pNode->fPhase = Fraig_IsComplement(gNode);
224 }
225
226 // print the classes
227 c = 0;
228 Counter = 0;
230 stmm_foreach_item( tStrash2Net, gen, (char **)&gNode, (char **)&pList )
231 {
232 // skip the trival classes
233 if ( pList == NULL || pList->pNext == NULL )
234 continue;
235 // add the non-trival class
236 stmm_insert( tResult, (char *)pList, NULL );
237 // count nodes in the non-trival classes
238 for ( pNode = pList; pNode; pNode = pNode->pNext )
239 Counter++;
240
241 if ( fVeryVerbose )
242 {
243 printf( "Class %2d : {", c );
244 for ( pNode = pList; pNode; pNode = pNode->pNext )
245 {
246 pNode->pCopy = NULL;
247 printf( " %s", Abc_ObjName(pNode) );
248 printf( "(%c)", pNode->fPhase? '-' : '+' );
249 printf( "(%d)", pNode->Level );
250 }
251 printf( " }\n" );
252 c++;
253 }
254 }
255 if ( fVerbose || fVeryVerbose )
256 {
257 printf( "Sweeping stats for network \"%s\":\n", pNtk->pName );
258 printf( "Internal nodes = %d. Different functions (up to compl) = %d.\n", Abc_NtkNodeNum(pNtk), stmm_count(tStrash2Net) );
259 printf( "Non-trivial classes = %d. Nodes in non-trivial classes = %d.\n", stmm_count(tResult), Counter );
260 }
261 stmm_free_table( tStrash2Net );
262 return tResult;
263}
264
265
277void Abc_NtkFraigTransform( Abc_Ntk_t * pNtk, stmm_table * tEquiv, int fUseInv, int fVerbose )
278{
279 stmm_generator * gen;
280 Abc_Obj_t * pList;
281 if ( stmm_count(tEquiv) == 0 )
282 return;
283 // merge nodes in the classes
284 if ( Abc_NtkHasMapping( pNtk ) )
285 {
286 Abc_NtkDelayTrace( pNtk, NULL, NULL, 0 );
287 stmm_foreach_item( tEquiv, gen, (char **)&pList, NULL )
288 Abc_NtkFraigMergeClassMapped( pNtk, pList, fUseInv, fVerbose );
289 }
290 else
291 {
292 stmm_foreach_item( tEquiv, gen, (char **)&pList, NULL )
293 Abc_NtkFraigMergeClass( pNtk, pList, fUseInv, fVerbose );
294 }
295}
296
297
309void Abc_NtkFraigMergeClassMapped( Abc_Ntk_t * pNtk, Abc_Obj_t * pChain, int fUseInv, int fVerbose )
310{
311 Abc_Obj_t * pListDir, * pListInv;
312 Abc_Obj_t * pNodeMin, * pNode, * pNext;
313 float Arrival1, Arrival2;
314
315 assert( pChain );
316 assert( pChain->pNext );
317
318 // divide the nodes into two parts:
319 // those that need the invertor and those that don't need
320 pListDir = pListInv = NULL;
321 for ( pNode = pChain, pNext = pChain->pNext;
322 pNode;
323 pNode = pNext, pNext = pNode? pNode->pNext : NULL )
324 {
325 // check to which class the node belongs
326 if ( pNode->fPhase == 1 )
327 {
328 pNode->pNext = pListDir;
329 pListDir = pNode;
330 }
331 else
332 {
333 pNode->pNext = pListInv;
334 pListInv = pNode;
335 }
336 }
337
338 // find the node with the smallest number of logic levels
339 pNodeMin = pListDir;
340 for ( pNode = pListDir; pNode; pNode = pNode->pNext )
341 {
342 Arrival1 = Abc_NodeReadArrivalWorst(pNodeMin);
343 Arrival2 = Abc_NodeReadArrivalWorst(pNode );
344// assert( Abc_ObjIsCi(pNodeMin) || Arrival1 > 0 );
345// assert( Abc_ObjIsCi(pNode) || Arrival2 > 0 );
346 if ( Arrival1 > Arrival2 ||
347 (Arrival1 == Arrival2 && pNodeMin->Level > pNode->Level) ||
348 (Arrival1 == Arrival2 && pNodeMin->Level == pNode->Level &&
349 Abc_NodeDroppingCost(pNodeMin) < Abc_NodeDroppingCost(pNode)) )
350 pNodeMin = pNode;
351 }
352
353 // move the fanouts of the direct nodes
354 for ( pNode = pListDir; pNode; pNode = pNode->pNext )
355 if ( pNode != pNodeMin )
356 Abc_ObjTransferFanout( pNode, pNodeMin );
357
358 // find the node with the smallest number of logic levels
359 pNodeMin = pListInv;
360 for ( pNode = pListInv; pNode; pNode = pNode->pNext )
361 {
362 Arrival1 = Abc_NodeReadArrivalWorst(pNodeMin);
363 Arrival2 = Abc_NodeReadArrivalWorst(pNode );
364// assert( Abc_ObjIsCi(pNodeMin) || Arrival1 > 0 );
365// assert( Abc_ObjIsCi(pNode) || Arrival2 > 0 );
366 if ( Arrival1 > Arrival2 ||
367 (Arrival1 == Arrival2 && pNodeMin->Level > pNode->Level) ||
368 (Arrival1 == Arrival2 && pNodeMin->Level == pNode->Level &&
369 Abc_NodeDroppingCost(pNodeMin) < Abc_NodeDroppingCost(pNode)) )
370 pNodeMin = pNode;
371 }
372
373 // move the fanouts of the direct nodes
374 for ( pNode = pListInv; pNode; pNode = pNode->pNext )
375 if ( pNode != pNodeMin )
376 Abc_ObjTransferFanout( pNode, pNodeMin );
377}
378
391void Abc_NtkFraigMergeClass( Abc_Ntk_t * pNtk, Abc_Obj_t * pChain, int fUseInv, int fVerbose )
392{
393 Abc_Obj_t * pListDir, * pListInv;
394 Abc_Obj_t * pNodeMin, * pNodeMinInv;
395 Abc_Obj_t * pNode, * pNext;
396
397 assert( pChain );
398 assert( pChain->pNext );
399
400 // find the node with the smallest number of logic levels
401 pNodeMin = pChain;
402 for ( pNode = pChain->pNext; pNode; pNode = pNode->pNext )
403 if ( pNodeMin->Level > pNode->Level ||
404 ( pNodeMin->Level == pNode->Level &&
405 Abc_NodeDroppingCost(pNodeMin) < Abc_NodeDroppingCost(pNode) ) )
406 pNodeMin = pNode;
407
408 // divide the nodes into two parts:
409 // those that need the invertor and those that don't need
410 pListDir = pListInv = NULL;
411 for ( pNode = pChain, pNext = pChain->pNext;
412 pNode;
413 pNode = pNext, pNext = pNode? pNode->pNext : NULL )
414 {
415 if ( pNode == pNodeMin )
416 continue;
417 // check to which class the node belongs
418 if ( pNodeMin->fPhase == pNode->fPhase )
419 {
420 pNode->pNext = pListDir;
421 pListDir = pNode;
422 }
423 else
424 {
425 pNode->pNext = pListInv;
426 pListInv = pNode;
427 }
428 }
429
430 // move the fanouts of the direct nodes
431 for ( pNode = pListDir; pNode; pNode = pNode->pNext )
432 Abc_ObjTransferFanout( pNode, pNodeMin );
433
434 // skip if there are no inverted nodes
435 if ( pListInv == NULL )
436 return;
437
438 // add the invertor
439 pNodeMinInv = Abc_NtkCreateNodeInv( pNtk, pNodeMin );
440
441 // move the fanouts of the inverted nodes
442 for ( pNode = pListInv; pNode; pNode = pNode->pNext )
443 Abc_ObjTransferFanout( pNode, pNodeMinInv );
444}
445
446
458int Abc_NodeDroppingCost( Abc_Obj_t * pNode )
459{
460 return 1;
461}
462
463
464
465
466
478int Abc_NtkCleanup( Abc_Ntk_t * pNtk, int fVerbose )
479{
480 Vec_Ptr_t * vNodes;
481 int Counter;
482 assert( Abc_NtkIsLogic(pNtk) );
483 // mark the nodes reachable from the POs
484 vNodes = Abc_NtkDfs( pNtk, 0 );
485 Counter = Abc_NtkReduceNodes( pNtk, vNodes );
486 if ( fVerbose )
487 printf( "Cleanup removed %d dangling nodes.\n", Counter );
488 Vec_PtrFree( vNodes );
489 return Counter;
490}
491
503int Abc_NtkCleanupNodes( Abc_Ntk_t * pNtk, Vec_Ptr_t * vRoots, int fVerbose )
504{
505 Vec_Ptr_t * vNodes, * vStarts;
506 Abc_Obj_t * pObj;
507 int i, Counter;
508 assert( Abc_NtkIsLogic(pNtk) );
509 // collect starting nodes into one array
510 vStarts = Vec_PtrAlloc( 1000 );
511 Abc_NtkForEachCo( pNtk, pObj, i )
512 Vec_PtrPush( vStarts, pObj );
513 Vec_PtrForEachEntry( Abc_Obj_t *, vRoots, pObj, i )
514 if ( pObj )
515 Vec_PtrPush( vStarts, pObj );
516 // mark the nodes reachable from the POs
517 vNodes = Abc_NtkDfsNodes( pNtk, (Abc_Obj_t **)Vec_PtrArray(vStarts), Vec_PtrSize(vStarts) );
518 Vec_PtrFree( vStarts );
519 Counter = Abc_NtkReduceNodes( pNtk, vNodes );
520 if ( fVerbose )
521 printf( "Cleanup removed %d dangling nodes.\n", Counter );
522 Vec_PtrFree( vNodes );
523 return Counter;
524}
525
537int Abc_NtkReduceNodes( Abc_Ntk_t * pNtk, Vec_Ptr_t * vNodes )
538{
539 Abc_Obj_t * pNode;
540 int i, Counter;
541 assert( Abc_NtkIsLogic(pNtk) );
542 // mark the nodes reachable from the POs
543 Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNode, i )
544 pNode->fMarkA = 1;
545 // remove the non-marked nodes
546 Counter = 0;
547 Abc_NtkForEachNode( pNtk, pNode, i )
548 if ( pNode->fMarkA == 0 )
549 {
550 Abc_NtkDeleteObj( pNode );
551 Counter++;
552 }
553 // unmark the remaining nodes
554 Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNode, i )
555 pNode->fMarkA = 0;
556 // check
557 if ( !Abc_NtkCheck( pNtk ) )
558 printf( "Abc_NtkCleanup: The network check has failed.\n" );
559 return Counter;
560}
561
562
563
564
565#ifdef ABC_USE_CUDD
566
578void Abc_NodeConstantInput( Abc_Obj_t * pNode, Abc_Obj_t * pFanin, int fConst0 )
579{
580 DdManager * dd = (DdManager *)pNode->pNtk->pManFunc;
581 DdNode * bVar, * bTemp;
582 int iFanin;
583 assert( Abc_NtkIsBddLogic(pNode->pNtk) );
584 if ( (iFanin = Vec_IntFind( &pNode->vFanins, pFanin->Id )) == -1 )
585 {
586 printf( "Node %s should be among", Abc_ObjName(pFanin) );
587 printf( " the fanins of node %s...\n", Abc_ObjName(pNode) );
588 return;
589 }
590 bVar = Cudd_NotCond( Cudd_bddIthVar(dd, iFanin), fConst0 );
591 pNode->pData = Cudd_Cofactor( dd, bTemp = (DdNode *)pNode->pData, bVar ); Cudd_Ref( (DdNode *)pNode->pData );
592 Cudd_RecursiveDeref( dd, bTemp );
593}
594
606int Abc_NtkSweep( Abc_Ntk_t * pNtk, int fVerbose )
607{
608 Vec_Ptr_t * vNodes;
609 Abc_Obj_t * pNode, * pFanout, * pDriver;
610 int i, nNodesOld;
611 assert( Abc_NtkIsLogic(pNtk) );
612 // convert network to BDD representation
613 if ( !Abc_NtkToBdd(pNtk) )
614 {
615 fprintf( stdout, "Converting to BDD has failed.\n" );
616 return 1;
617 }
618 // perform cleanup
619 nNodesOld = Abc_NtkNodeNum(pNtk);
620 Abc_NtkCleanup( pNtk, 0 );
621 // prepare nodes for sweeping
622 //Abc_NtkRemoveDupFanins(pNtk);
623 Abc_NtkMinimumBase(pNtk);
624 // collect sweepable nodes
625 vNodes = Vec_PtrAlloc( 100 );
626 Abc_NtkForEachNode( pNtk, pNode, i )
627 if ( Abc_ObjFaninNum(pNode) < 2 )
628 Vec_PtrPush( vNodes, pNode );
629 // sweep the nodes
630 while ( Vec_PtrSize(vNodes) > 0 )
631 {
632 // get any sweepable node
633 pNode = (Abc_Obj_t *)Vec_PtrPop(vNodes);
634 if ( !Abc_ObjIsNode(pNode) )
635 continue;
636 // get any non-CO fanout of this node
637 pFanout = Abc_NodeFindNonCoFanout(pNode);
638 if ( pFanout == NULL )
639 continue;
640 assert( Abc_ObjIsNode(pFanout) );
641 // transform the function of the fanout
642 if ( Abc_ObjFaninNum(pNode) == 0 )
643 Abc_NodeConstantInput( pFanout, pNode, Abc_NodeIsConst0(pNode) );
644 else
645 {
646 assert( Abc_ObjFaninNum(pNode) == 1 );
647 pDriver = Abc_ObjFanin0(pNode);
648 if ( Abc_NodeIsInv(pNode) )
649 Abc_NodeComplementInput( pFanout, pNode );
650 Abc_ObjPatchFanin( pFanout, pNode, pDriver );
651 }
652 //Abc_NodeRemoveDupFanins( pFanout );
653 Abc_NodeMinimumBase( pFanout );
654 // check if the fanout should be added
655 if ( Abc_ObjFaninNum(pFanout) < 2 )
656 Vec_PtrPush( vNodes, pFanout );
657 // check if the node has other fanouts
658 if ( Abc_ObjFanoutNum(pNode) > 0 )
659 Vec_PtrPush( vNodes, pNode );
660 else
661 Abc_NtkDeleteObj_rec( pNode, 1 );
662 }
663 Vec_PtrFree( vNodes );
664 // sweep a node into its CO fanout if all of this is true:
665 // (a) this node is a single-input node
666 // (b) the driver of the node has only one fanout (this node)
667 // (c) the driver is a node
668 Abc_NtkForEachCo( pNtk, pFanout, i )
669 {
670 pNode = Abc_ObjFanin0(pFanout);
671 if ( Abc_ObjFaninNum(pNode) != 1 )
672 continue;
673 pDriver = Abc_ObjFanin0(pNode);
674 if ( !(Abc_ObjFanoutNum(pDriver) == 1 && Abc_ObjIsNode(pDriver)) )
675 continue;
676 // trasform this CO
677 if ( Abc_NodeIsInv(pNode) )
678 pDriver->pData = Cudd_Not(pDriver->pData);
679 Abc_ObjPatchFanin( pFanout, pNode, pDriver );
680 }
681 // perform cleanup
682 Abc_NtkCleanup( pNtk, 0 );
683 // report
684 if ( fVerbose )
685 printf( "Sweep removed %d nodes.\n", nNodesOld - Abc_NtkNodeNum(pNtk) );
686 return nNodesOld - Abc_NtkNodeNum(pNtk);
687}
688
689
690#else
691
692int Abc_NtkSweep( Abc_Ntk_t * pNtk, int fVerbose ) { return 1; }
693
694#endif
695
696
709{
710 Abc_Obj_t * pObj;
711 int Counter, i;
712 int fVerbose = 0;
713
714 // report on the nodes to be deleted
715 if ( fVerbose )
716 {
717 printf( "These nodes will be deleted: \n" );
718 Abc_NtkForEachObj( pNtk, pObj, i )
719 if ( !Abc_NodeIsTravIdCurrent( pObj ) )
720 {
721 printf( " " );
722 Abc_ObjPrint( stdout, pObj );
723 }
724 }
725
726 // delete the nodes
727 Counter = 0;
728 Abc_NtkForEachObj( pNtk, pObj, i )
729 if ( !Abc_NodeIsTravIdCurrent( pObj ) )
730 {
731 Abc_NtkDeleteObj( pObj );
732 Counter++;
733 }
734 return Counter;
735}
736
749{
750 Abc_NodeSetTravIdCurrent(pObj);
751 if ( Abc_ObjFaninNum(pObj) == 0 )
752 return;
753 assert( Abc_ObjFaninNum(pObj) == 1 );
754 Abc_NtkSetTravId_rec( Abc_ObjFanin0(pObj) );
755}
756
769{
770 if ( Abc_ObjFaninNum(pObj) == 0 )
771 {
772 if ( !Abc_ObjIsNode(pObj) )
773 return -1;
774 if ( Abc_NodeIsConst0(pObj) )
775 return 0;
776 if ( Abc_NodeIsConst1(pObj) )
777 return 1;
778 assert( 0 );
779 return -1;
780 }
781 if ( Abc_ObjIsLatch(pObj) || Abc_ObjFaninNum(pObj) > 1 )
782 return -1;
783 if ( !Abc_ObjIsNode(pObj) || Abc_NodeIsBuf(pObj) )
784 return Abc_NtkCheckConstant_rec( Abc_ObjFanin0(pObj) );
785 if ( Abc_NodeIsInv(pObj) )
786 {
787 int RetValue = Abc_NtkCheckConstant_rec( Abc_ObjFanin0(pObj) );
788 if ( RetValue == 0 )
789 return 1;
790 if ( RetValue == 1 )
791 return 0;
792 return RetValue;
793 }
794 assert( 0 );
795 return -1;
796}
797
813{
814 Abc_Obj_t * pFanin, * pLatch, * pLatchPivot = NULL;
815 int Counter, RetValue, i;
816 Counter = 0;
817 // go through the latches
818 Abc_NtkForEachLatch( pNtk, pLatch, i )
819 {
820 // check if the latch has constant input
821 RetValue = Abc_NtkCheckConstant_rec( Abc_ObjFanin0(pLatch) );
822 if ( RetValue == -1 )
823 continue;
824 // found a latch with constant fanin
825 if ( (RetValue == 1 && Abc_LatchIsInit0(pLatch)) ||
826 (RetValue == 0 && Abc_LatchIsInit1(pLatch)) )
827 {
828 // fanin constant differs from the latch init value
829 if ( pLatchPivot == NULL )
830 {
831 pLatchPivot = pLatch;
832 continue;
833 }
834 if ( Abc_LatchInit(pLatch) != Abc_LatchInit(pLatchPivot) ) // add inverter
835 pFanin = Abc_NtkCreateNodeInv( pNtk, Abc_ObjFanout0(pLatchPivot) );
836 else
837 pFanin = Abc_ObjFanout0(pLatchPivot);
838 }
839 else
840 pFanin = Abc_ObjFanin0(Abc_ObjFanin0(pLatch));
841 // replace latch
842 Abc_ObjTransferFanout( Abc_ObjFanout0(pLatch), pFanin );
843 // delete the extra nodes
844 Abc_NtkDeleteObj_rec( Abc_ObjFanout0(pLatch), 0 );
845 Counter++;
846 }
847 return Counter;
848}
849
863{
864 Abc_Obj_t * pNode, * pFanin;
865 Vec_Ptr_t * vNodes;
866 int i, k, Counter;
867 // collect the nodes that feed into the reachable logic
868 vNodes = Vec_PtrAlloc( 100 );
869 Abc_NtkForEachObj( pNtk, pNode, i )
870 {
871 // skip non-visited fanins
872 if ( !Abc_NodeIsTravIdCurrent(pNode) )
873 continue;
874 // look for non-visited fanins
875 Abc_ObjForEachFanin( pNode, pFanin, k )
876 {
877 // skip visited fanins
878 if ( Abc_NodeIsTravIdCurrent(pFanin) )
879 continue;
880 // skip constants and latches fed by constants
881 if ( Abc_NtkCheckConstant_rec(pFanin) != -1 ||
882 (Abc_ObjIsBo(pFanin) && Abc_NtkCheckConstant_rec(Abc_ObjFanin0(Abc_ObjFanin0(pFanin))) != -1) )
883 {
884 Abc_NtkSetTravId_rec( pFanin );
885 continue;
886 }
887 assert( !Abc_ObjIsLatch(pFanin) );
888 Vec_PtrPush( vNodes, pFanin );
889 }
890 }
891 Vec_PtrUniqify( vNodes, (int (*)(const void *, const void *))Abc_ObjPointerCompare );
892 // replace these nodes by the PIs
893 Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNode, i )
894 {
895 pFanin = Abc_NtkCreatePi(pNtk);
896 Abc_ObjAssignName( pFanin, Abc_ObjName(pFanin), NULL );
897 Abc_NodeSetTravIdCurrent( pFanin );
898 Abc_ObjTransferFanout( pNode, pFanin );
899 }
900 Counter = Vec_PtrSize(vNodes);
901 Vec_PtrFree( vNodes );
902 return Counter;
903}
904
919int Abc_NtkCleanupSeq( Abc_Ntk_t * pNtk, int fLatchSweep, int fAutoSweep, int fVerbose )
920{
921 Vec_Ptr_t * vNodes;
922 int Counter;
923 assert( Abc_NtkIsLogic(pNtk) );
924 // mark the nodes reachable from the POs
925 vNodes = Abc_NtkDfsSeq( pNtk );
926 Vec_PtrFree( vNodes );
927 // remove the non-marked nodes
928 Counter = Abc_NodeRemoveNonCurrentObjects( pNtk );
929 if ( fVerbose )
930 printf( "Cleanup removed %4d dangling objects.\n", Counter );
931 // check if some of the latches can be removed
932 if ( fLatchSweep )
933 {
934 Counter = Abc_NtkLatchSweep( pNtk );
935 if ( fVerbose )
936 printf( "Cleanup removed %4d redundant latches.\n", Counter );
937 }
938 // detect the autonomous components
939 if ( fAutoSweep )
940 {
941 vNodes = Abc_NtkDfsSeqReverse( pNtk );
942 Vec_PtrFree( vNodes );
943 // replace them by PIs
944 Counter = Abc_NtkReplaceAutonomousLogic( pNtk );
945 if ( fVerbose )
946 printf( "Cleanup added %4d additional PIs.\n", Counter );
947 // remove the non-marked nodes
948 Counter = Abc_NodeRemoveNonCurrentObjects( pNtk );
949 if ( fVerbose )
950 printf( "Cleanup removed %4d autonomous objects.\n", Counter );
951 }
952 // check
953 if ( !Abc_NtkCheck( pNtk ) )
954 printf( "Abc_NtkCleanupSeq: The network check has failed.\n" );
955 return 1;
956}
957
969int Abc_NtkSweepBufsInvs( Abc_Ntk_t * pNtk, int fVerbose )
970{
971 Hop_Man_t * pMan;
972 Abc_Obj_t * pObj, * pFanin;
973 int i, k, fChanges = 1, Counter = 0;
974 assert( Abc_NtkIsLogic(pNtk) );
975 // convert network to BDD representation
976 if ( !Abc_NtkToAig(pNtk) )
977 {
978 fprintf( stdout, "Converting to SOP has failed.\n" );
979 return 1;
980 }
981 // get AIG manager
982 pMan = (Hop_Man_t *)pNtk->pManFunc;
983 // label selected nodes
984 Abc_NtkIncrementTravId( pNtk );
985 // iterate till no improvement
986 while ( fChanges )
987 {
988 fChanges = 0;
989 Abc_NtkForEachObj( pNtk, pObj, i )
990 {
991 Abc_ObjForEachFanin( pObj, pFanin, k )
992 {
993 // do not eliminate marked fanins
994 if ( Abc_NodeIsTravIdCurrent(pFanin) )
995 continue;
996 // do not eliminate constant nodes
997 if ( !Abc_ObjIsNode(pFanin) || Abc_ObjFaninNum(pFanin) != 1 )
998 continue;
999 // do not eliminate inverters into COs
1000 if ( Abc_ObjIsCo(pObj) && Abc_NodeIsInv(pFanin) )
1001 continue;
1002 // do not eliminate buffers connecting PIs and POs
1003// if ( Abc_ObjIsCo(pObj) && Abc_ObjIsCi(Abc_ObjFanin0(pFanin)) )
1004// continue;
1005 fChanges = 1;
1006 Counter++;
1007 // update function of the node
1008 if ( Abc_NodeIsInv(pFanin) )
1009 pObj->pData = Hop_Compose( pMan, (Hop_Obj_t *)pObj->pData, Hop_Not(Hop_IthVar(pMan, k)), k );
1010 // update the fanin
1011 Abc_ObjPatchFanin( pObj, pFanin, Abc_ObjFanin0(pFanin) );
1012 if ( Abc_ObjFanoutNum(pFanin) == 0 )
1013 Abc_NtkDeleteObj(pFanin);
1014 }
1015 }
1016 }
1017 if ( fVerbose )
1018 printf( "Removed %d single input nodes.\n", Counter );
1019 return Counter;
1020}
1021
1022
1023
1027
1028
1030
Fraig_Node_t * Abc_NtkToFraigExdc(Fraig_Man_t *pMan, Abc_Ntk_t *pNtkMain, Abc_Ntk_t *pNtkExdc)
Definition abcFraig.c:164
int Abc_NodeRemoveNonCurrentObjects(Abc_Ntk_t *pNtk)
Definition abcSweep.c:708
int Abc_NtkCleanupNodes(Abc_Ntk_t *pNtk, Vec_Ptr_t *vRoots, int fVerbose)
Definition abcSweep.c:503
int Abc_NtkCleanup(Abc_Ntk_t *pNtk, int fVerbose)
Definition abcSweep.c:478
void Abc_NtkSetTravId_rec(Abc_Obj_t *pObj)
Definition abcSweep.c:748
int Abc_NtkCheckConstant_rec(Abc_Obj_t *pObj)
Definition abcSweep.c:768
int Abc_NtkSweepBufsInvs(Abc_Ntk_t *pNtk, int fVerbose)
Definition abcSweep.c:969
int Abc_NtkSweep(Abc_Ntk_t *pNtk, int fVerbose)
Definition abcSweep.c:692
int Abc_NtkReplaceAutonomousLogic(Abc_Ntk_t *pNtk)
Definition abcSweep.c:862
int Abc_NtkCleanupSeq(Abc_Ntk_t *pNtk, int fLatchSweep, int fAutoSweep, int fVerbose)
Definition abcSweep.c:919
int Abc_NtkFraigSweep(Abc_Ntk_t *pNtk, int fUseInv, int fExdc, int fVerbose, int fVeryVerbose)
FUNCTION DEFINITIONS ///.
Definition abcSweep.c:62
int Abc_NtkLatchSweep(Abc_Ntk_t *pNtk)
Definition abcSweep.c:812
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_NodeComplementInput(Abc_Obj_t *pNode, Abc_Obj_t *pFanin)
Definition abcObj.c:1039
ABC_DLL float Abc_NtkDelayTrace(Abc_Ntk_t *pNtk, Abc_Obj_t *pOut, Abc_Obj_t *pIn, int fPrint)
Definition abcTiming.c:1031
ABC_DLL void Abc_NtkDeleteObj(Abc_Obj_t *pObj)
Definition abcObj.c:170
ABC_DLL int Abc_NodeIsBuf(Abc_Obj_t *pNode)
Definition abcObj.c:948
#define Abc_NtkForEachLatch(pNtk, pObj, i)
Definition abc.h:500
ABC_DLL Vec_Ptr_t * Abc_NtkDfs(Abc_Ntk_t *pNtk, int fCollectAll)
Definition abcDfs.c:82
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition abcCheck.c:64
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition abc.h:449
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition abc.h:527
ABC_DLL int Abc_NtkToBdd(Abc_Ntk_t *pNtk)
Definition abcFunc.c:1299
ABC_DLL void Abc_ObjPrint(FILE *pFile, Abc_Obj_t *pObj)
Definition abcPrint.c:1674
ABC_DLL int Abc_NodeIsInv(Abc_Obj_t *pNode)
Definition abcObj.c:980
ABC_DLL Vec_Ptr_t * Abc_NtkDfsSeq(Abc_Ntk_t *pNtk)
Definition abcDfs.c:428
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition abcNames.c:49
ABC_DLL void Abc_NtkDeleteObj_rec(Abc_Obj_t *pObj, int fOnlyNodes)
Definition abcObj.c:278
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
ABC_DLL char * Abc_ObjAssignName(Abc_Obj_t *pObj, char *pName, char *pSuffix)
Definition abcNames.c:69
ABC_DLL int Abc_NodeIsConst0(Abc_Obj_t *pNode)
Definition abcObj.c:884
ABC_DLL void Abc_ObjTransferFanout(Abc_Obj_t *pObjOld, Abc_Obj_t *pObjNew)
Definition abcFanio.c:292
ABC_DLL int Abc_NtkLevel(Abc_Ntk_t *pNtk)
Definition abcDfs.c:1449
ABC_DLL int Abc_NtkToAig(Abc_Ntk_t *pNtk)
Definition abcFunc.c:1333
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeInv(Abc_Ntk_t *pNtk, Abc_Obj_t *pFanin)
Definition abcObj.c:674
ABC_DLL Abc_Ntk_t * Abc_NtkStrash(Abc_Ntk_t *pNtk, int fAllNodes, int fCleanup, int fRecord)
Definition abcStrash.c:265
ABC_DLL int Abc_ObjPointerCompare(void **pp1, void **pp2)
Definition abcUtil.c:1939
ABC_DLL int Abc_NtkMinimumBase(Abc_Ntk_t *pNtk)
DECLARATIONS ///.
Definition abcMinBase.c:892
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition abcNtk.c:1421
ABC_DLL Vec_Ptr_t * Abc_NtkDfsNodes(Abc_Ntk_t *pNtk, Abc_Obj_t **ppNodes, int nNodes)
Definition abcDfs.c:151
ABC_DLL Abc_Obj_t * Abc_NodeFindCoFanout(Abc_Obj_t *pNode)
Definition abcUtil.c:812
ABC_DLL void Abc_ObjPatchFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFaninOld, Abc_Obj_t *pFaninNew)
Definition abcFanio.c:172
@ ABC_FUNC_MAP
Definition abc.h:68
ABC_DLL void * Abc_NtkToFraig(Abc_Ntk_t *pNtk, void *pParams, int fAllNodes, int fExdc)
Definition abcFraig.c:103
ABC_DLL Abc_Obj_t * Abc_NodeFindNonCoFanout(Abc_Obj_t *pNode)
Definition abcUtil.c:833
ABC_DLL float Abc_NodeReadArrivalWorst(Abc_Obj_t *pNode)
Definition abcTiming.c:111
ABC_DLL int Abc_NodeIsConst1(Abc_Obj_t *pNode)
Definition abcObj.c:916
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition abc.h:464
ABC_DLL int Abc_NodeMinimumBase(Abc_Obj_t *pNode)
Definition abcMinBase.c:893
ABC_DLL Vec_Ptr_t * Abc_NtkDfsSeqReverse(Abc_Ntk_t *pNtk)
Definition abcDfs.c:485
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
ABC_DLL void * Abc_FrameReadLibGen()
Definition mainFrame.c:59
#define Fraig_IsComplement(p)
GLOBAL VARIABLES ///.
Definition fraig.h:107
#define Fraig_Regular(p)
Definition fraig.h:108
void Fraig_ManFree(Fraig_Man_t *pMan)
Definition fraigMan.c:262
#define Fraig_Not(p)
Definition fraig.h:109
void Fraig_ParamsSetDefault(Fraig_Params_t *pParams)
Definition fraigMan.c:122
#define Fraig_NotCond(p, c)
Definition fraig.h:110
typedefABC_NAMESPACE_HEADER_START struct Fraig_ManStruct_t_ Fraig_Man_t
INCLUDES ///.
Definition fraig.h:40
struct Fraig_NodeStruct_t_ Fraig_Node_t
Definition fraig.h:41
struct Fraig_ParamsStruct_t_ Fraig_Params_t
Definition fraig.h:44
Fraig_Node_t * Fraig_NodeAnd(Fraig_Man_t *p, Fraig_Node_t *p1, Fraig_Node_t *p2)
Definition fraigApi.c:212
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition hop.h:49
Hop_Obj_t * Hop_Compose(Hop_Man_t *p, Hop_Obj_t *pRoot, Hop_Obj_t *pFunc, int iVar)
Definition hopDfs.c:415
Hop_Obj_t * Hop_IthVar(Hop_Man_t *p, int i)
FUNCTION DEFINITIONS ///.
Definition hopOper.c:63
void Hop_ManStop(Hop_Man_t *p)
Definition hopMan.c:84
struct Hop_Obj_t_ Hop_Obj_t
Definition hop.h:50
int stmm_ptrhash(const char *x, int size)
Definition stmm.c:533
int stmm_insert(stmm_table *table, char *key, char *value)
Definition stmm.c:200
int stmm_find_or_add(stmm_table *table, char *key, char ***slot)
Definition stmm.c:266
int stmm_ptrcmp(const char *x, const char *y)
Definition stmm.c:545
void stmm_free_table(stmm_table *table)
Definition stmm.c:79
stmm_table * stmm_init_table(stmm_compare_func_type compare, stmm_hash_func_type hash)
Definition stmm.c:69
#define stmm_count(table)
Definition stmm.h:76
#define stmm_foreach_item(table, gen, key, value)
Definition stmm.h:121
char * pName
Definition abc.h:158
Abc_Ntk_t * pExdc
Definition abc.h:201
void * pManFunc
Definition abc.h:191
Abc_NtkFunc_t ntkFunc
Definition abc.h:157
void * pData
Definition abc.h:145
Vec_Int_t vFanins
Definition abc.h:143
Abc_Ntk_t * pNtk
Definition abc.h:130
Abc_Obj_t * pCopy
Definition abc.h:148
unsigned fMarkA
Definition abc.h:134
unsigned fPhase
Definition abc.h:137
Abc_Obj_t * pNext
Definition abc.h:131
unsigned Level
Definition abc.h:142
#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