abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcSweep.c File Reference
#include "base/abc/abc.h"
#include "base/main/main.h"
#include "proof/fraig/fraig.h"
#include "misc/extra/extraBdd.h"

Go to the source code of this file.

Functions

static
ABC_NAMESPACE_IMPL_START void 
Abc_NtkFraigSweepUsingExdc (Fraig_Man_t *pMan, Abc_Ntk_t *pNtk)
 DECLARATIONS ///. More...
 
static stmm_tableAbc_NtkFraigEquiv (Abc_Ntk_t *pNtk, int fUseInv, int fVerbose, int fVeryVerbose)
 
static void Abc_NtkFraigTransform (Abc_Ntk_t *pNtk, stmm_table *tEquiv, int fUseInv, int fVerbose)
 
static void Abc_NtkFraigMergeClassMapped (Abc_Ntk_t *pNtk, Abc_Obj_t *pChain, int fUseInv, int fVerbose)
 
static void Abc_NtkFraigMergeClass (Abc_Ntk_t *pNtk, Abc_Obj_t *pChain, int fUseInv, int fVerbose)
 
static int Abc_NodeDroppingCost (Abc_Obj_t *pNode)
 
static int Abc_NtkReduceNodes (Abc_Ntk_t *pNtk, Vec_Ptr_t *vNodes)
 
static void Abc_NodeSweep (Abc_Obj_t *pNode, int fVerbose)
 
static void Abc_NodeConstantInput (Abc_Obj_t *pNode, Abc_Obj_t *pFanin, int fConst0)
 
int Abc_NtkFraigSweep (Abc_Ntk_t *pNtk, int fUseInv, int fExdc, int fVerbose, int fVeryVerbose)
 FUNCTION DEFINITIONS ///. More...
 
int Abc_NtkCleanup (Abc_Ntk_t *pNtk, int fVerbose)
 
int Abc_NtkCleanupNodes (Abc_Ntk_t *pNtk, Vec_Ptr_t *vRoots, int fVerbose)
 
int Abc_NtkSweep (Abc_Ntk_t *pNtk, int fVerbose)
 
int Abc_NodeRemoveNonCurrentObjects (Abc_Ntk_t *pNtk)
 
void Abc_NtkSetTravId_rec (Abc_Obj_t *pObj)
 
int Abc_NtkCheckConstant_rec (Abc_Obj_t *pObj)
 
int Abc_NtkLatchSweep (Abc_Ntk_t *pNtk)
 
int Abc_NtkReplaceAutonomousLogic (Abc_Ntk_t *pNtk)
 
int Abc_NtkCleanupSeq (Abc_Ntk_t *pNtk, int fLatchSweep, int fAutoSweep, int fVerbose)
 
int Abc_NtkSweepBufsInvs (Abc_Ntk_t *pNtk, int fVerbose)
 

Function Documentation

void Abc_NodeConstantInput ( Abc_Obj_t pNode,
Abc_Obj_t pFanin,
int  fConst0 
)
static

Function*************************************************************

Synopsis [Replaces the local function by its cofactor.]

Description []

SideEffects []

SeeAlso []

Definition at line 669 of file abcSweep.c.

670 {
671  DdManager * dd = (DdManager *)pNode->pNtk->pManFunc;
672  DdNode * bVar, * bTemp;
673  int iFanin;
674  assert( Abc_NtkIsBddLogic(pNode->pNtk) );
675  if ( (iFanin = Vec_IntFind( &pNode->vFanins, pFanin->Id )) == -1 )
676  {
677  printf( "Node %s should be among", Abc_ObjName(pFanin) );
678  printf( " the fanins of node %s...\n", Abc_ObjName(pNode) );
679  return;
680  }
681  bVar = Cudd_NotCond( Cudd_bddIthVar(dd, iFanin), fConst0 );
682  pNode->pData = Cudd_Cofactor( dd, bTemp = (DdNode *)pNode->pData, bVar ); Cudd_Ref( (DdNode *)pNode->pData );
683  Cudd_RecursiveDeref( dd, bTemp );
684 }
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
Definition: cudd.h:278
static int Vec_IntFind(Vec_Int_t *p, int Entry)
Definition: vecInt.h:895
Vec_Int_t vFanins
Definition: abc.h:143
void * pManFunc
Definition: abc.h:191
DdNode * Cudd_Cofactor(DdManager *dd, DdNode *f, DdNode *g)
Definition: cuddCof.c:123
Abc_Ntk_t * pNtk
Definition: abc.h:130
static int Abc_NtkIsBddLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:265
int Id
Definition: abc.h:132
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
DdNode * Cudd_bddIthVar(DdManager *dd, int i)
Definition: cuddAPI.c:416
#define Cudd_NotCond(node, c)
Definition: cudd.h:383
#define assert(ex)
Definition: util_old.h:213
void * pData
Definition: abc.h:145
void Cudd_Ref(DdNode *n)
Definition: cuddRef.c:129
int Abc_NodeDroppingCost ( Abc_Obj_t pNode)
static

Function*************************************************************

Synopsis [Returns the number of literals saved if this node becomes useless.]

Description []

SideEffects []

SeeAlso []

Definition at line 456 of file abcSweep.c.

457 {
458  return 1;
459 }
int Abc_NodeRemoveNonCurrentObjects ( Abc_Ntk_t pNtk)

Function*************************************************************

Synopsis [Removes all objects whose trav ID is not current.]

Description []

SideEffects []

SeeAlso []

Definition at line 698 of file abcSweep.c.

699 {
700  Abc_Obj_t * pObj;
701  int Counter, i;
702  int fVerbose = 0;
703 
704  // report on the nodes to be deleted
705  if ( fVerbose )
706  {
707  printf( "These nodes will be deleted: \n" );
708  Abc_NtkForEachObj( pNtk, pObj, i )
709  if ( !Abc_NodeIsTravIdCurrent( pObj ) )
710  {
711  printf( " " );
712  Abc_ObjPrint( stdout, pObj );
713  }
714  }
715 
716  // delete the nodes
717  Counter = 0;
718  Abc_NtkForEachObj( pNtk, pObj, i )
719  if ( !Abc_NodeIsTravIdCurrent( pObj ) )
720  {
721  Abc_NtkDeleteObj( pObj );
722  Counter++;
723  }
724  return Counter;
725 }
ABC_DLL void Abc_ObjPrint(FILE *pFile, Abc_Obj_t *pObj)
Definition: abcPrint.c:1287
ABC_DLL void Abc_NtkDeleteObj(Abc_Obj_t *pObj)
Definition: abcObj.c:167
if(last==0)
Definition: sparse_int.h:34
static int Counter
static int Abc_NodeIsTravIdCurrent(Abc_Obj_t *p)
Definition: abc.h:411
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition: abc.h:446
static void Abc_NodeSweep ( Abc_Obj_t pNode,
int  fVerbose 
)
static
int Abc_NtkCheckConstant_rec ( Abc_Obj_t pObj)

Function*************************************************************

Synopsis [Check if the fanin of this latch is a constant.]

Description [Returns 0/1 if constant; -1 if not a constant.]

SideEffects []

SeeAlso []

Definition at line 758 of file abcSweep.c.

759 {
760  if ( Abc_ObjFaninNum(pObj) == 0 )
761  {
762  if ( !Abc_ObjIsNode(pObj) )
763  return -1;
764  if ( Abc_NodeIsConst0(pObj) )
765  return 0;
766  if ( Abc_NodeIsConst1(pObj) )
767  return 1;
768  assert( 0 );
769  return -1;
770  }
771  if ( Abc_ObjIsLatch(pObj) || Abc_ObjFaninNum(pObj) > 1 )
772  return -1;
773  if ( !Abc_ObjIsNode(pObj) || Abc_NodeIsBuf(pObj) )
774  return Abc_NtkCheckConstant_rec( Abc_ObjFanin0(pObj) );
775  if ( Abc_NodeIsInv(pObj) )
776  {
777  int RetValue = Abc_NtkCheckConstant_rec( Abc_ObjFanin0(pObj) );
778  if ( RetValue == 0 )
779  return 1;
780  if ( RetValue == 1 )
781  return 0;
782  return RetValue;
783  }
784  assert( 0 );
785  return -1;
786 }
static int Abc_ObjIsLatch(Abc_Obj_t *pObj)
Definition: abc.h:356
ABC_DLL int Abc_NodeIsConst0(Abc_Obj_t *pNode)
Definition: abcObj.c:860
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
ABC_DLL int Abc_NodeIsBuf(Abc_Obj_t *pNode)
Definition: abcObj.c:920
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
int Abc_NtkCheckConstant_rec(Abc_Obj_t *pObj)
Definition: abcSweep.c:758
ABC_DLL int Abc_NodeIsInv(Abc_Obj_t *pNode)
Definition: abcObj.c:950
ABC_DLL int Abc_NodeIsConst1(Abc_Obj_t *pNode)
Definition: abcObj.c:890
#define assert(ex)
Definition: util_old.h:213
int Abc_NtkCleanup ( Abc_Ntk_t pNtk,
int  fVerbose 
)

Function*************************************************************

Synopsis [Removes dangling nodes.]

Description [Returns the number of nodes removed.]

SideEffects []

SeeAlso []

Definition at line 476 of file abcSweep.c.

477 {
478  Vec_Ptr_t * vNodes;
479  int Counter;
480  assert( Abc_NtkIsLogic(pNtk) );
481  // mark the nodes reachable from the POs
482  vNodes = Abc_NtkDfs( pNtk, 0 );
483  Counter = Abc_NtkReduceNodes( pNtk, vNodes );
484  if ( fVerbose )
485  printf( "Cleanup removed %d dangling nodes.\n", Counter );
486  Vec_PtrFree( vNodes );
487  return Counter;
488 }
static int Abc_NtkIsLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:250
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
ABC_DLL Vec_Ptr_t * Abc_NtkDfs(Abc_Ntk_t *pNtk, int fCollectAll)
Definition: abcDfs.c:81
static int Counter
#define assert(ex)
Definition: util_old.h:213
static int Abc_NtkReduceNodes(Abc_Ntk_t *pNtk, Vec_Ptr_t *vNodes)
Definition: abcSweep.c:535
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
int Abc_NtkCleanupNodes ( Abc_Ntk_t pNtk,
Vec_Ptr_t vRoots,
int  fVerbose 
)

Function*************************************************************

Synopsis [Removes dangling nodes.]

Description [Returns the number of nodes removed.]

SideEffects []

SeeAlso []

Definition at line 501 of file abcSweep.c.

502 {
503  Vec_Ptr_t * vNodes, * vStarts;
504  Abc_Obj_t * pObj;
505  int i, Counter;
506  assert( Abc_NtkIsLogic(pNtk) );
507  // collect starting nodes into one array
508  vStarts = Vec_PtrAlloc( 1000 );
509  Abc_NtkForEachCo( pNtk, pObj, i )
510  Vec_PtrPush( vStarts, pObj );
511  Vec_PtrForEachEntry( Abc_Obj_t *, vRoots, pObj, i )
512  if ( pObj )
513  Vec_PtrPush( vStarts, pObj );
514  // mark the nodes reachable from the POs
515  vNodes = Abc_NtkDfsNodes( pNtk, (Abc_Obj_t **)Vec_PtrArray(vStarts), Vec_PtrSize(vStarts) );
516  Vec_PtrFree( vStarts );
517  Counter = Abc_NtkReduceNodes( pNtk, vNodes );
518  if ( fVerbose )
519  printf( "Cleanup removed %d dangling nodes.\n", Counter );
520  Vec_PtrFree( vNodes );
521  return Counter;
522 }
static int Abc_NtkIsLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:250
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
int nodes
Definition: abcSaucy.c:61
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition: abc.h:519
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
if(last==0)
Definition: sparse_int.h:34
static int Counter
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
#define assert(ex)
Definition: util_old.h:213
ABC_DLL Vec_Ptr_t * Abc_NtkDfsNodes(Abc_Ntk_t *pNtk, Abc_Obj_t **ppNodes, int nNodes)
Definition: abcDfs.c:120
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static void ** Vec_PtrArray(Vec_Ptr_t *p)
Definition: vecPtr.h:279
static int Abc_NtkReduceNodes(Abc_Ntk_t *pNtk, Vec_Ptr_t *vNodes)
Definition: abcSweep.c:535
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
int Abc_NtkCleanupSeq ( Abc_Ntk_t pNtk,
int  fLatchSweep,
int  fAutoSweep,
int  fVerbose 
)

Function*************************************************************

Synopsis [Sequential cleanup.]

Description [Performs three tasks:

  • Removes logic that does not feed into POs.
  • Removes latches driven by constant values equal to the initial state.
  • Replaces the autonomous components by additional PI variables.]

SideEffects []

SeeAlso []

Definition at line 909 of file abcSweep.c.

910 {
911  Vec_Ptr_t * vNodes;
912  int Counter;
913  assert( Abc_NtkIsLogic(pNtk) );
914  // mark the nodes reachable from the POs
915  vNodes = Abc_NtkDfsSeq( pNtk );
916  Vec_PtrFree( vNodes );
917  // remove the non-marked nodes
918  Counter = Abc_NodeRemoveNonCurrentObjects( pNtk );
919  if ( fVerbose )
920  printf( "Cleanup removed %4d dangling objects.\n", Counter );
921  // check if some of the latches can be removed
922  if ( fLatchSweep )
923  {
924  Counter = Abc_NtkLatchSweep( pNtk );
925  if ( fVerbose )
926  printf( "Cleanup removed %4d redundant latches.\n", Counter );
927  }
928  // detect the autonomous components
929  if ( fAutoSweep )
930  {
931  vNodes = Abc_NtkDfsSeqReverse( pNtk );
932  Vec_PtrFree( vNodes );
933  // replace them by PIs
934  Counter = Abc_NtkReplaceAutonomousLogic( pNtk );
935  if ( fVerbose )
936  printf( "Cleanup added %4d additional PIs.\n", Counter );
937  // remove the non-marked nodes
938  Counter = Abc_NodeRemoveNonCurrentObjects( pNtk );
939  if ( fVerbose )
940  printf( "Cleanup removed %4d autonomous objects.\n", Counter );
941  }
942  // check
943  if ( !Abc_NtkCheck( pNtk ) )
944  printf( "Abc_NtkCleanupSeq: The network check has failed.\n" );
945  return 1;
946 }
int Abc_NodeRemoveNonCurrentObjects(Abc_Ntk_t *pNtk)
Definition: abcSweep.c:698
static int Abc_NtkIsLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:250
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition: abcCheck.c:61
ABC_DLL Vec_Ptr_t * Abc_NtkDfsSeq(Abc_Ntk_t *pNtk)
Definition: abcDfs.c:397
ABC_DLL Vec_Ptr_t * Abc_NtkDfsSeqReverse(Abc_Ntk_t *pNtk)
Definition: abcDfs.c:454
static int Counter
int Abc_NtkReplaceAutonomousLogic(Abc_Ntk_t *pNtk)
Definition: abcSweep.c:852
int Abc_NtkLatchSweep(Abc_Ntk_t *pNtk)
Definition: abcSweep.c:802
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
stmm_table * Abc_NtkFraigEquiv ( Abc_Ntk_t pNtk,
int  fUseInv,
int  fVerbose,
int  fVeryVerbose 
)
static

Function*************************************************************

Synopsis [Collects equivalence classes of node in the network.]

Description []

SideEffects []

SeeAlso []

Definition at line 188 of file abcSweep.c.

189 {
190  Abc_Obj_t * pList, * pNode, * pNodeAig;
191  Fraig_Node_t * gNode;
192  Abc_Obj_t ** ppSlot;
193  stmm_table * tStrash2Net;
194  stmm_table * tResult;
195  stmm_generator * gen;
196  int c, Counter;
197 
198  // create mapping of strashed nodes into the corresponding network nodes
200  Abc_NtkForEachNode( pNtk, pNode, c )
201  {
202  // skip the constant input nodes
203  if ( Abc_ObjFaninNum(pNode) == 0 )
204  continue;
205  // get the strashed node
206  pNodeAig = pNode->pCopy;
207  // skip the dangling nodes
208  if ( pNodeAig == NULL )
209  continue;
210  // skip the nodes that fanout into COs
211  if ( Abc_NodeFindCoFanout(pNode) )
212  continue;
213  // get the FRAIG node
214  gNode = Fraig_NotCond( Abc_ObjRegular(pNodeAig)->pCopy, (int)Abc_ObjIsComplement(pNodeAig) );
215  if ( !stmm_find_or_add( tStrash2Net, (char *)Fraig_Regular(gNode), (char ***)&ppSlot ) )
216  *ppSlot = NULL;
217  // add the node to the list
218  pNode->pNext = *ppSlot;
219  *ppSlot = pNode;
220  // mark the node if it is complemented
221  pNode->fPhase = Fraig_IsComplement(gNode);
222  }
223 
224  // print the classes
225  c = 0;
226  Counter = 0;
228  stmm_foreach_item( tStrash2Net, gen, (char **)&gNode, (char **)&pList )
229  {
230  // skip the trival classes
231  if ( pList == NULL || pList->pNext == NULL )
232  continue;
233  // add the non-trival class
234  stmm_insert( tResult, (char *)pList, NULL );
235  // count nodes in the non-trival classes
236  for ( pNode = pList; pNode; pNode = pNode->pNext )
237  Counter++;
238 
239  if ( fVeryVerbose )
240  {
241  printf( "Class %2d : {", c );
242  for ( pNode = pList; pNode; pNode = pNode->pNext )
243  {
244  pNode->pCopy = NULL;
245  printf( " %s", Abc_ObjName(pNode) );
246  printf( "(%c)", pNode->fPhase? '-' : '+' );
247  printf( "(%d)", pNode->Level );
248  }
249  printf( " }\n" );
250  c++;
251  }
252  }
253  if ( fVerbose || fVeryVerbose )
254  {
255  printf( "Sweeping stats for network \"%s\":\n", pNtk->pName );
256  printf( "Internal nodes = %d. Different functions (up to compl) = %d.\n", Abc_NtkNodeNum(pNtk), stmm_count(tStrash2Net) );
257  printf( "Non-trivial classes = %d. Nodes in non-trivial classes = %d.\n", stmm_count(tResult), Counter );
258  }
259  stmm_free_table( tStrash2Net );
260  return tResult;
261 }
stmm_table * stmm_init_table(stmm_compare_func_type compare, stmm_hash_func_type hash)
Definition: stmm.c:69
int stmm_insert(stmm_table *table, char *key, char *value)
Definition: stmm.c:200
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
#define stmm_count(table)
Definition: stmm.h:76
unsigned Level
Definition: abc.h:142
static int Abc_NtkNodeNum(Abc_Ntk_t *pNtk)
Definition: abc.h:293
Abc_Obj_t * pCopy
Definition: abc.h:148
int stmm_ptrhash(const char *x, int size)
Definition: stmm.c:533
static int Counter
int stmm_find_or_add(stmm_table *table, char *key, char ***slot)
Definition: stmm.c:266
#define Fraig_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: fraig.h:107
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
int stmm_ptrcmp(const char *x, const char *y)
Definition: stmm.c:545
void stmm_free_table(stmm_table *table)
Definition: stmm.c:79
static Abc_Obj_t * Abc_ObjRegular(Abc_Obj_t *p)
Definition: abc.h:323
ABC_DLL Abc_Obj_t * Abc_NodeFindCoFanout(Abc_Obj_t *pNode)
Definition: abcUtil.c:779
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
#define Fraig_Regular(p)
Definition: fraig.h:108
#define Fraig_NotCond(p, c)
Definition: fraig.h:110
Abc_Obj_t * pNext
Definition: abc.h:131
#define stmm_foreach_item(table, gen, key, value)
Definition: stmm.h:121
static int Abc_ObjIsComplement(Abc_Obj_t *p)
Definition: abc.h:322
unsigned fPhase
Definition: abc.h:137
char * pName
Definition: abc.h:158
void Abc_NtkFraigMergeClass ( Abc_Ntk_t pNtk,
Abc_Obj_t pChain,
int  fUseInv,
int  fVerbose 
)
static

Function*************************************************************

Synopsis [Process one equivalence class of nodes.]

Description [This function does not remove the nodes. It only switches around the connections.]

SideEffects []

SeeAlso []

Definition at line 389 of file abcSweep.c.

390 {
391  Abc_Obj_t * pListDir, * pListInv;
392  Abc_Obj_t * pNodeMin, * pNodeMinInv;
393  Abc_Obj_t * pNode, * pNext;
394 
395  assert( pChain );
396  assert( pChain->pNext );
397 
398  // find the node with the smallest number of logic levels
399  pNodeMin = pChain;
400  for ( pNode = pChain->pNext; pNode; pNode = pNode->pNext )
401  if ( pNodeMin->Level > pNode->Level ||
402  ( pNodeMin->Level == pNode->Level &&
403  Abc_NodeDroppingCost(pNodeMin) < Abc_NodeDroppingCost(pNode) ) )
404  pNodeMin = pNode;
405 
406  // divide the nodes into two parts:
407  // those that need the invertor and those that don't need
408  pListDir = pListInv = NULL;
409  for ( pNode = pChain, pNext = pChain->pNext;
410  pNode;
411  pNode = pNext, pNext = pNode? pNode->pNext : NULL )
412  {
413  if ( pNode == pNodeMin )
414  continue;
415  // check to which class the node belongs
416  if ( pNodeMin->fPhase == pNode->fPhase )
417  {
418  pNode->pNext = pListDir;
419  pListDir = pNode;
420  }
421  else
422  {
423  pNode->pNext = pListInv;
424  pListInv = pNode;
425  }
426  }
427 
428  // move the fanouts of the direct nodes
429  for ( pNode = pListDir; pNode; pNode = pNode->pNext )
430  Abc_ObjTransferFanout( pNode, pNodeMin );
431 
432  // skip if there are no inverted nodes
433  if ( pListInv == NULL )
434  return;
435 
436  // add the invertor
437  pNodeMinInv = Abc_NtkCreateNodeInv( pNtk, pNodeMin );
438 
439  // move the fanouts of the inverted nodes
440  for ( pNode = pListInv; pNode; pNode = pNode->pNext )
441  Abc_ObjTransferFanout( pNode, pNodeMinInv );
442 }
static int Abc_NodeDroppingCost(Abc_Obj_t *pNode)
Definition: abcSweep.c:456
unsigned Level
Definition: abc.h:142
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeInv(Abc_Ntk_t *pNtk, Abc_Obj_t *pFanin)
Definition: abcObj.c:662
ABC_DLL void Abc_ObjTransferFanout(Abc_Obj_t *pObjOld, Abc_Obj_t *pObjNew)
Definition: abcFanio.c:264
Abc_Obj_t * pNext
Definition: abc.h:131
#define assert(ex)
Definition: util_old.h:213
unsigned fPhase
Definition: abc.h:137
void Abc_NtkFraigMergeClassMapped ( Abc_Ntk_t pNtk,
Abc_Obj_t pChain,
int  fUseInv,
int  fVerbose 
)
static

Function*************************************************************

Synopsis [Transforms the list of one-phase equivalent nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 307 of file abcSweep.c.

308 {
309  Abc_Obj_t * pListDir, * pListInv;
310  Abc_Obj_t * pNodeMin, * pNode, * pNext;
311  float Arrival1, Arrival2;
312 
313  assert( pChain );
314  assert( pChain->pNext );
315 
316  // divide the nodes into two parts:
317  // those that need the invertor and those that don't need
318  pListDir = pListInv = NULL;
319  for ( pNode = pChain, pNext = pChain->pNext;
320  pNode;
321  pNode = pNext, pNext = pNode? pNode->pNext : NULL )
322  {
323  // check to which class the node belongs
324  if ( pNode->fPhase == 1 )
325  {
326  pNode->pNext = pListDir;
327  pListDir = pNode;
328  }
329  else
330  {
331  pNode->pNext = pListInv;
332  pListInv = pNode;
333  }
334  }
335 
336  // find the node with the smallest number of logic levels
337  pNodeMin = pListDir;
338  for ( pNode = pListDir; pNode; pNode = pNode->pNext )
339  {
340  Arrival1 = Abc_NodeReadArrivalWorst(pNodeMin);
341  Arrival2 = Abc_NodeReadArrivalWorst(pNode );
342 // assert( Abc_ObjIsCi(pNodeMin) || Arrival1 > 0 );
343 // assert( Abc_ObjIsCi(pNode) || Arrival2 > 0 );
344  if ( Arrival1 > Arrival2 ||
345  (Arrival1 == Arrival2 && pNodeMin->Level > pNode->Level) ||
346  (Arrival1 == Arrival2 && pNodeMin->Level == pNode->Level &&
347  Abc_NodeDroppingCost(pNodeMin) < Abc_NodeDroppingCost(pNode)) )
348  pNodeMin = pNode;
349  }
350 
351  // move the fanouts of the direct nodes
352  for ( pNode = pListDir; pNode; pNode = pNode->pNext )
353  if ( pNode != pNodeMin )
354  Abc_ObjTransferFanout( pNode, pNodeMin );
355 
356  // find the node with the smallest number of logic levels
357  pNodeMin = pListInv;
358  for ( pNode = pListInv; pNode; pNode = pNode->pNext )
359  {
360  Arrival1 = Abc_NodeReadArrivalWorst(pNodeMin);
361  Arrival2 = Abc_NodeReadArrivalWorst(pNode );
362 // assert( Abc_ObjIsCi(pNodeMin) || Arrival1 > 0 );
363 // assert( Abc_ObjIsCi(pNode) || Arrival2 > 0 );
364  if ( Arrival1 > Arrival2 ||
365  (Arrival1 == Arrival2 && pNodeMin->Level > pNode->Level) ||
366  (Arrival1 == Arrival2 && pNodeMin->Level == pNode->Level &&
367  Abc_NodeDroppingCost(pNodeMin) < Abc_NodeDroppingCost(pNode)) )
368  pNodeMin = pNode;
369  }
370 
371  // move the fanouts of the direct nodes
372  for ( pNode = pListInv; pNode; pNode = pNode->pNext )
373  if ( pNode != pNodeMin )
374  Abc_ObjTransferFanout( pNode, pNodeMin );
375 }
static int Abc_NodeDroppingCost(Abc_Obj_t *pNode)
Definition: abcSweep.c:456
unsigned Level
Definition: abc.h:142
ABC_DLL void Abc_ObjTransferFanout(Abc_Obj_t *pObjOld, Abc_Obj_t *pObjNew)
Definition: abcFanio.c:264
ABC_DLL float Abc_NodeReadArrivalWorst(Abc_Obj_t *pNode)
Definition: abcTiming.c:95
Abc_Obj_t * pNext
Definition: abc.h:131
#define assert(ex)
Definition: util_old.h:213
unsigned fPhase
Definition: abc.h:137
int Abc_NtkFraigSweep ( Abc_Ntk_t pNtk,
int  fUseInv,
int  fExdc,
int  fVerbose,
int  fVeryVerbose 
)

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis [Sweping functionally equivalence nodes.]

Description [Removes gates with equivalent functionality. Works for both technology-independent and mapped networks. If the flag is set, allows adding inverters at the gate outputs.]

SideEffects []

SeeAlso []

Definition at line 60 of file abcSweep.c.

61 {
62  Fraig_Params_t Params;
63  Abc_Ntk_t * pNtkAig;
64  Fraig_Man_t * pMan;
65  stmm_table * tEquiv;
66  Abc_Obj_t * pObj;
67  int i, fUseTrick;
68 
69  assert( !Abc_NtkIsStrash(pNtk) );
70 
71  // save gate assignments
72  fUseTrick = 0;
73  if ( Abc_NtkIsMappedLogic(pNtk) )
74  {
75  fUseTrick = 1;
76  Abc_NtkForEachNode( pNtk, pObj, i )
77  pObj->pNext = (Abc_Obj_t *)pObj->pData;
78  }
79  // derive the AIG
80  pNtkAig = Abc_NtkStrash( pNtk, 0, 1, 0 );
81  // reconstruct gate assignments
82  if ( fUseTrick )
83  {
84 // extern void * Abc_FrameReadLibGen();
85  Hop_ManStop( (Hop_Man_t *)pNtk->pManFunc );
86  pNtk->pManFunc = Abc_FrameReadLibGen();
87  pNtk->ntkFunc = ABC_FUNC_MAP;
88  Abc_NtkForEachNode( pNtk, pObj, i )
89  pObj->pData = pObj->pNext, pObj->pNext = NULL;
90  }
91 
92  // perform fraiging of the AIG
93  Fraig_ParamsSetDefault( &Params );
94  Params.fInternal = 1;
95  pMan = (Fraig_Man_t *)Abc_NtkToFraig( pNtkAig, &Params, 0, 0 );
96  // cannot use EXDC with FRAIG because it can create classes of equivalent FRAIG nodes
97  // with representative nodes that do not correspond to the nodes with the current network
98 
99  // update FRAIG using EXDC
100  if ( fExdc )
101  {
102  if ( pNtk->pExdc == NULL )
103  printf( "Warning: Networks has no EXDC.\n" );
104  else
105  Abc_NtkFraigSweepUsingExdc( pMan, pNtk );
106  }
107  // assign levels to the nodes of the network
108  Abc_NtkLevel( pNtk );
109 
110  // collect the classes of equivalent nets
111  tEquiv = Abc_NtkFraigEquiv( pNtk, fUseInv, fVerbose, fVeryVerbose );
112 
113  // transform the network into the equivalent one
114  Abc_NtkFraigTransform( pNtk, tEquiv, fUseInv, fVerbose );
115  stmm_free_table( tEquiv );
116 
117  // free the manager
118  Fraig_ManFree( pMan );
119  Abc_NtkDelete( pNtkAig );
120 
121  // cleanup the dangling nodes
122  if ( Abc_NtkHasMapping(pNtk) )
123  Abc_NtkCleanup( pNtk, fVerbose );
124  else
125  Abc_NtkSweep( pNtk, fVerbose );
126 
127  // check
128  if ( !Abc_NtkCheck( pNtk ) )
129  {
130  printf( "Abc_NtkFraigSweep: The network check has failed.\n" );
131  return 0;
132  }
133  return 1;
134 }
static int Abc_NtkIsStrash(Abc_Ntk_t *pNtk)
Definition: abc.h:251
static stmm_table * Abc_NtkFraigEquiv(Abc_Ntk_t *pNtk, int fUseInv, int fVerbose, int fVeryVerbose)
Definition: abcSweep.c:188
ABC_DLL void * Abc_FrameReadLibGen()
Definition: mainFrame.c:56
static ABC_NAMESPACE_IMPL_START void Abc_NtkFraigSweepUsingExdc(Fraig_Man_t *pMan, Abc_Ntk_t *pNtk)
DECLARATIONS ///.
Definition: abcSweep.c:147
typedefABC_NAMESPACE_HEADER_START struct Fraig_ManStruct_t_ Fraig_Man_t
INCLUDES ///.
Definition: fraig.h:40
static void Abc_NtkFraigTransform(Abc_Ntk_t *pNtk, stmm_table *tEquiv, int fUseInv, int fVerbose)
Definition: abcSweep.c:275
void Fraig_ManFree(Fraig_Man_t *pMan)
Definition: fraigMan.c:262
ABC_DLL Abc_Ntk_t * Abc_NtkStrash(Abc_Ntk_t *pNtk, int fAllNodes, int fCleanup, int fRecord)
Definition: abcStrash.c:265
static int Abc_NtkHasMapping(Abc_Ntk_t *pNtk)
Definition: abc.h:256
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition: abcCheck.c:61
int Abc_NtkCleanup(Abc_Ntk_t *pNtk, int fVerbose)
Definition: abcSweep.c:476
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:1233
void Hop_ManStop(Hop_Man_t *p)
Definition: hopMan.c:84
if(last==0)
Definition: sparse_int.h:34
void Fraig_ParamsSetDefault(Fraig_Params_t *pParams)
Definition: fraigMan.c:122
int Abc_NtkSweep(Abc_Ntk_t *pNtk, int fVerbose)
Definition: abcSweep.c:574
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
void stmm_free_table(stmm_table *table)
Definition: stmm.c:79
static int Abc_NtkIsMappedLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:267
#define assert(ex)
Definition: util_old.h:213
ABC_DLL int Abc_NtkLevel(Abc_Ntk_t *pNtk)
Definition: abcDfs.c:1265
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition: hop.h:49
ABC_DLL void * Abc_NtkToFraig(Abc_Ntk_t *pNtk, void *pParams, int fAllNodes, int fExdc)
Definition: abcFraig.c:103
void Abc_NtkFraigSweepUsingExdc ( Fraig_Man_t pMan,
Abc_Ntk_t pNtk 
)
static

DECLARATIONS ///.

CFile****************************************************************

FileName [abcDsd.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Network and node package.]

Synopsis [Technology dependent sweep.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id:
abcDsd.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

Function*************************************************************

Synopsis [Sweep the network using EXDC.]

Description []

SideEffects []

SeeAlso []

Definition at line 147 of file abcSweep.c.

148 {
149  Fraig_Node_t * gNodeExdc, * gNode, * gNodeRes;
150  Abc_Obj_t * pNode, * pNodeAig;
151  int i;
152  extern Fraig_Node_t * Abc_NtkToFraigExdc( Fraig_Man_t * pMan, Abc_Ntk_t * pNtk, Abc_Ntk_t * pNtkExdc );
153 
154  assert( pNtk->pExdc );
155  // derive FRAIG node representing don't-cares in the EXDC network
156  gNodeExdc = Abc_NtkToFraigExdc( pMan, pNtk, pNtk->pExdc );
157  // update the node pointers
158  Abc_NtkForEachNode( pNtk, pNode, i )
159  {
160  // skip the constant input nodes
161  if ( Abc_ObjFaninNum(pNode) == 0 )
162  continue;
163  // get the strashed node
164  pNodeAig = pNode->pCopy;
165  // skip the dangling nodes
166  if ( pNodeAig == NULL )
167  continue;
168  // get the FRAIG node
169  gNode = Fraig_NotCond( Abc_ObjRegular(pNodeAig)->pCopy, (int)Abc_ObjIsComplement(pNodeAig) );
170  // perform ANDing with EXDC
171  gNodeRes = Fraig_NodeAnd( pMan, gNode, Fraig_Not(gNodeExdc) );
172  // write the node back
173  Abc_ObjRegular(pNodeAig)->pCopy = (Abc_Obj_t *)Fraig_NotCond( gNodeRes, (int)Abc_ObjIsComplement(pNodeAig) );
174  }
175 }
typedefABC_NAMESPACE_HEADER_START struct Fraig_ManStruct_t_ Fraig_Man_t
INCLUDES ///.
Definition: fraig.h:40
Abc_Ntk_t * pExdc
Definition: abc.h:201
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
Fraig_Node_t * Abc_NtkToFraigExdc(Fraig_Man_t *pMan, Abc_Ntk_t *pNtkMain, Abc_Ntk_t *pNtkExdc)
Definition: abcFraig.c:164
#define Fraig_Not(p)
Definition: fraig.h:109
Fraig_Node_t * Fraig_NodeAnd(Fraig_Man_t *p, Fraig_Node_t *p1, Fraig_Node_t *p2)
Definition: fraigApi.c:212
Abc_Obj_t * pCopy
Definition: abc.h:148
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
static Abc_Obj_t * Abc_ObjRegular(Abc_Obj_t *p)
Definition: abc.h:323
#define Fraig_NotCond(p, c)
Definition: fraig.h:110
#define assert(ex)
Definition: util_old.h:213
static int Abc_ObjIsComplement(Abc_Obj_t *p)
Definition: abc.h:322
void Abc_NtkFraigTransform ( Abc_Ntk_t pNtk,
stmm_table tEquiv,
int  fUseInv,
int  fVerbose 
)
static

Function*************************************************************

Synopsis [Transforms the network using the equivalence relation on nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 275 of file abcSweep.c.

276 {
277  stmm_generator * gen;
278  Abc_Obj_t * pList;
279  if ( stmm_count(tEquiv) == 0 )
280  return;
281  // merge nodes in the classes
282  if ( Abc_NtkHasMapping( pNtk ) )
283  {
284  Abc_NtkDelayTrace( pNtk, NULL, NULL, 0 );
285  stmm_foreach_item( tEquiv, gen, (char **)&pList, NULL )
286  Abc_NtkFraigMergeClassMapped( pNtk, pList, fUseInv, fVerbose );
287  }
288  else
289  {
290  stmm_foreach_item( tEquiv, gen, (char **)&pList, NULL )
291  Abc_NtkFraigMergeClass( pNtk, pList, fUseInv, fVerbose );
292  }
293 }
ABC_DLL float Abc_NtkDelayTrace(Abc_Ntk_t *pNtk, Abc_Obj_t *pOut, Abc_Obj_t *pIn, int fPrint)
Definition: abcTiming.c:919
static int Abc_NtkHasMapping(Abc_Ntk_t *pNtk)
Definition: abc.h:256
#define stmm_count(table)
Definition: stmm.h:76
static void Abc_NtkFraigMergeClassMapped(Abc_Ntk_t *pNtk, Abc_Obj_t *pChain, int fUseInv, int fVerbose)
Definition: abcSweep.c:307
else
Definition: sparse_int.h:55
static void Abc_NtkFraigMergeClass(Abc_Ntk_t *pNtk, Abc_Obj_t *pChain, int fUseInv, int fVerbose)
Definition: abcSweep.c:389
#define stmm_foreach_item(table, gen, key, value)
Definition: stmm.h:121
int Abc_NtkLatchSweep ( Abc_Ntk_t pNtk)

Function*************************************************************

Synopsis [Removes redundant latches.]

Description [The redundant latches are of two types:

  • Latches fed by a constant which matches the init value of the latch.
  • Latches fed by a constant which does not match the init value of the latch can be all replaced by one latch.]

SideEffects []

SeeAlso []

Definition at line 802 of file abcSweep.c.

803 {
804  Abc_Obj_t * pFanin, * pLatch, * pLatchPivot = NULL;
805  int Counter, RetValue, i;
806  Counter = 0;
807  // go through the latches
808  Abc_NtkForEachLatch( pNtk, pLatch, i )
809  {
810  // check if the latch has constant input
811  RetValue = Abc_NtkCheckConstant_rec( Abc_ObjFanin0(pLatch) );
812  if ( RetValue == -1 )
813  continue;
814  // found a latch with constant fanin
815  if ( (RetValue == 1 && Abc_LatchIsInit0(pLatch)) ||
816  (RetValue == 0 && Abc_LatchIsInit1(pLatch)) )
817  {
818  // fanin constant differs from the latch init value
819  if ( pLatchPivot == NULL )
820  {
821  pLatchPivot = pLatch;
822  continue;
823  }
824  if ( Abc_LatchInit(pLatch) != Abc_LatchInit(pLatchPivot) ) // add inverter
825  pFanin = Abc_NtkCreateNodeInv( pNtk, Abc_ObjFanout0(pLatchPivot) );
826  else
827  pFanin = Abc_ObjFanout0(pLatchPivot);
828  }
829  else
830  pFanin = Abc_ObjFanin0(Abc_ObjFanin0(pLatch));
831  // replace latch
832  Abc_ObjTransferFanout( Abc_ObjFanout0(pLatch), pFanin );
833  // delete the extra nodes
834  Abc_NtkDeleteObj_rec( Abc_ObjFanout0(pLatch), 0 );
835  Counter++;
836  }
837  return Counter;
838 }
static int Abc_LatchInit(Abc_Obj_t *pLatch)
Definition: abc.h:425
ABC_DLL void Abc_NtkDeleteObj_rec(Abc_Obj_t *pObj, int fOnlyNodes)
Definition: abcObj.c:273
static int Abc_LatchIsInit0(Abc_Obj_t *pLatch)
Definition: abc.h:422
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeInv(Abc_Ntk_t *pNtk, Abc_Obj_t *pFanin)
Definition: abcObj.c:662
static int Counter
#define Abc_NtkForEachLatch(pNtk, pObj, i)
Definition: abc.h:497
static int Abc_LatchIsInit1(Abc_Obj_t *pLatch)
Definition: abc.h:423
int Abc_NtkCheckConstant_rec(Abc_Obj_t *pObj)
Definition: abcSweep.c:758
ABC_DLL void Abc_ObjTransferFanout(Abc_Obj_t *pObjOld, Abc_Obj_t *pObjNew)
Definition: abcFanio.c:264
static Abc_Obj_t * Abc_ObjFanout0(Abc_Obj_t *pObj)
Definition: abc.h:371
int Abc_NtkReduceNodes ( Abc_Ntk_t pNtk,
Vec_Ptr_t vNodes 
)
static

Function*************************************************************

Synopsis [Preserves the nodes collected in the array.]

Description [Returns the number of nodes removed.]

SideEffects []

SeeAlso []

Definition at line 535 of file abcSweep.c.

536 {
537  Abc_Obj_t * pNode;
538  int i, Counter;
539  assert( Abc_NtkIsLogic(pNtk) );
540  // mark the nodes reachable from the POs
541  Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNode, i )
542  pNode->fMarkA = 1;
543  // remove the non-marked nodes
544  Counter = 0;
545  Abc_NtkForEachNode( pNtk, pNode, i )
546  if ( pNode->fMarkA == 0 )
547  {
548  Abc_NtkDeleteObj( pNode );
549  Counter++;
550  }
551  // unmark the remaining nodes
552  Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNode, i )
553  pNode->fMarkA = 0;
554  // check
555  if ( !Abc_NtkCheck( pNtk ) )
556  printf( "Abc_NtkCleanup: The network check has failed.\n" );
557  return Counter;
558 }
static int Abc_NtkIsLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:250
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition: abcCheck.c:61
int Abc_NtkCleanup(Abc_Ntk_t *pNtk, int fVerbose)
Definition: abcSweep.c:476
static void check(int expr)
Definition: satSolver.c:46
ABC_DLL void Abc_NtkDeleteObj(Abc_Obj_t *pObj)
Definition: abcObj.c:167
if(last==0)
Definition: sparse_int.h:34
static int Counter
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
#define assert(ex)
Definition: util_old.h:213
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
int Abc_NtkReplaceAutonomousLogic ( Abc_Ntk_t pNtk)

Function*************************************************************

Synopsis [Replaces autonumnous logic by free inputs.]

Description [Assumes that non-autonomous logic is marked with the current ID.]

SideEffects []

SeeAlso []

Definition at line 852 of file abcSweep.c.

853 {
854  Abc_Obj_t * pNode, * pFanin;
855  Vec_Ptr_t * vNodes;
856  int i, k, Counter;
857  // collect the nodes that feed into the reachable logic
858  vNodes = Vec_PtrAlloc( 100 );
859  Abc_NtkForEachObj( pNtk, pNode, i )
860  {
861  // skip non-visited fanins
862  if ( !Abc_NodeIsTravIdCurrent(pNode) )
863  continue;
864  // look for non-visited fanins
865  Abc_ObjForEachFanin( pNode, pFanin, k )
866  {
867  // skip visited fanins
868  if ( Abc_NodeIsTravIdCurrent(pFanin) )
869  continue;
870  // skip constants and latches fed by constants
871  if ( Abc_NtkCheckConstant_rec(pFanin) != -1 ||
872  (Abc_ObjIsBo(pFanin) && Abc_NtkCheckConstant_rec(Abc_ObjFanin0(Abc_ObjFanin0(pFanin))) != -1) )
873  {
874  Abc_NtkSetTravId_rec( pFanin );
875  continue;
876  }
877  assert( !Abc_ObjIsLatch(pFanin) );
878  Vec_PtrPush( vNodes, pFanin );
879  }
880  }
881  Vec_PtrUniqify( vNodes, (int (*)(void))Abc_ObjPointerCompare );
882  // replace these nodes by the PIs
883  Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNode, i )
884  {
885  pFanin = Abc_NtkCreatePi(pNtk);
886  Abc_ObjAssignName( pFanin, Abc_ObjName(pFanin), NULL );
887  Abc_NodeSetTravIdCurrent( pFanin );
888  Abc_ObjTransferFanout( pNode, pFanin );
889  }
890  Counter = Vec_PtrSize(vNodes);
891  Vec_PtrFree( vNodes );
892  return Counter;
893 }
ABC_DLL int Abc_ObjPointerCompare(void **pp1, void **pp2)
Definition: abcUtil.c:1899
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static int Abc_ObjIsBo(Abc_Obj_t *pObj)
Definition: abc.h:350
static int Abc_ObjIsLatch(Abc_Obj_t *pObj)
Definition: abc.h:356
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
ABC_DLL char * Abc_ObjAssignName(Abc_Obj_t *pObj, char *pName, char *pSuffix)
Definition: abcNames.c:68
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
static void Vec_PtrUniqify(Vec_Ptr_t *p, int(*Vec_PtrSortCompare)()) ___unused
Definition: vecPtr.h:875
void Abc_NtkSetTravId_rec(Abc_Obj_t *pObj)
Definition: abcSweep.c:738
static int Counter
static Abc_Obj_t * Abc_NtkCreatePi(Abc_Ntk_t *pNtk)
Definition: abc.h:303
int Abc_NtkCheckConstant_rec(Abc_Obj_t *pObj)
Definition: abcSweep.c:758
ABC_DLL void Abc_ObjTransferFanout(Abc_Obj_t *pObjOld, Abc_Obj_t *pObjNew)
Definition: abcFanio.c:264
static int Abc_NodeIsTravIdCurrent(Abc_Obj_t *p)
Definition: abc.h:411
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition: abc.h:524
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
#define assert(ex)
Definition: util_old.h:213
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition: abc.h:446
static void Abc_NodeSetTravIdCurrent(Abc_Obj_t *p)
Definition: abc.h:409
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
void Abc_NtkSetTravId_rec ( Abc_Obj_t pObj)

Function*************************************************************

Synopsis [Check if the fanin of this latch is a constant.]

Description [Returns 0/1 if constant; -1 if not a constant.]

SideEffects []

SeeAlso []

Definition at line 738 of file abcSweep.c.

739 {
741  if ( Abc_ObjFaninNum(pObj) == 0 )
742  return;
743  assert( Abc_ObjFaninNum(pObj) == 1 );
745 }
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
void Abc_NtkSetTravId_rec(Abc_Obj_t *pObj)
Definition: abcSweep.c:738
#define assert(ex)
Definition: util_old.h:213
static void Abc_NodeSetTravIdCurrent(Abc_Obj_t *p)
Definition: abc.h:409
int Abc_NtkSweep ( Abc_Ntk_t pNtk,
int  fVerbose 
)

Function*************************************************************

Synopsis [Tranditional sweep of the network.]

Description [Propagates constant and single-input node, removes dangling nodes.]

SideEffects []

SeeAlso []

Definition at line 574 of file abcSweep.c.

575 {
576  Vec_Ptr_t * vNodes;
577  Abc_Obj_t * pNode, * pFanout, * pDriver;
578  int i, nNodesOld;
579  assert( Abc_NtkIsLogic(pNtk) );
580  // convert network to BDD representation
581  if ( !Abc_NtkToBdd(pNtk) )
582  {
583  fprintf( stdout, "Converting to BDD has failed.\n" );
584  return 1;
585  }
586  // perform cleanup
587  nNodesOld = Abc_NtkNodeNum(pNtk);
588  Abc_NtkCleanup( pNtk, 0 );
589  // prepare nodes for sweeping
591  Abc_NtkMinimumBase(pNtk);
592  // collect sweepable nodes
593  vNodes = Vec_PtrAlloc( 100 );
594  Abc_NtkForEachNode( pNtk, pNode, i )
595  if ( Abc_ObjFaninNum(pNode) < 2 )
596  Vec_PtrPush( vNodes, pNode );
597  // sweep the nodes
598  while ( Vec_PtrSize(vNodes) > 0 )
599  {
600  // get any sweepable node
601  pNode = (Abc_Obj_t *)Vec_PtrPop(vNodes);
602  if ( !Abc_ObjIsNode(pNode) )
603  continue;
604  // get any non-CO fanout of this node
605  pFanout = Abc_NodeFindNonCoFanout(pNode);
606  if ( pFanout == NULL )
607  continue;
608  assert( Abc_ObjIsNode(pFanout) );
609  // transform the function of the fanout
610  if ( Abc_ObjFaninNum(pNode) == 0 )
611  Abc_NodeConstantInput( pFanout, pNode, Abc_NodeIsConst0(pNode) );
612  else
613  {
614  assert( Abc_ObjFaninNum(pNode) == 1 );
615  pDriver = Abc_ObjFanin0(pNode);
616  if ( Abc_NodeIsInv(pNode) )
617  Abc_NodeComplementInput( pFanout, pNode );
618  Abc_ObjPatchFanin( pFanout, pNode, pDriver );
619  }
620  Abc_NodeRemoveDupFanins( pFanout );
621  Abc_NodeMinimumBase( pFanout );
622  // check if the fanout should be added
623  if ( Abc_ObjFaninNum(pFanout) < 2 )
624  Vec_PtrPush( vNodes, pFanout );
625  // check if the node has other fanouts
626  if ( Abc_ObjFanoutNum(pNode) > 0 )
627  Vec_PtrPush( vNodes, pNode );
628  else
629  Abc_NtkDeleteObj_rec( pNode, 1 );
630  }
631  Vec_PtrFree( vNodes );
632  // sweep a node into its CO fanout if all of this is true:
633  // (a) this node is a single-input node
634  // (b) the driver of the node has only one fanout (this node)
635  // (c) the driver is a node
636  Abc_NtkForEachCo( pNtk, pFanout, i )
637  {
638  pNode = Abc_ObjFanin0(pFanout);
639  if ( Abc_ObjFaninNum(pNode) != 1 )
640  continue;
641  pDriver = Abc_ObjFanin0(pNode);
642  if ( !(Abc_ObjFanoutNum(pDriver) == 1 && Abc_ObjIsNode(pDriver)) )
643  continue;
644  // trasform this CO
645  if ( Abc_NodeIsInv(pNode) )
646  pDriver->pData = Cudd_Not(pDriver->pData);
647  Abc_ObjPatchFanin( pFanout, pNode, pDriver );
648  }
649  // perform cleanup
650  Abc_NtkCleanup( pNtk, 0 );
651  // report
652  if ( fVerbose )
653  printf( "Sweep removed %d nodes.\n", nNodesOld - Abc_NtkNodeNum(pNtk) );
654  return nNodesOld - Abc_NtkNodeNum(pNtk);
655 }
static int Abc_NtkIsLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:250
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
#define Cudd_Not(node)
Definition: cudd.h:367
ABC_DLL int Abc_NtkMinimumBase(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition: abcMinBase.c:48
ABC_DLL int Abc_NodeIsConst0(Abc_Obj_t *pNode)
Definition: abcObj.c:860
static int Abc_ObjFanoutNum(Abc_Obj_t *pObj)
Definition: abc.h:365
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
ABC_DLL void Abc_NtkDeleteObj_rec(Abc_Obj_t *pObj, int fOnlyNodes)
Definition: abcObj.c:273
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
ABC_DLL int Abc_NtkRemoveDupFanins(Abc_Ntk_t *pNtk)
Definition: abcMinBase.c:116
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition: abc.h:519
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static void * Vec_PtrPop(Vec_Ptr_t *p)
Definition: vecPtr.h:677
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
int Abc_NtkCleanup(Abc_Ntk_t *pNtk, int fVerbose)
Definition: abcSweep.c:476
ABC_DLL void Abc_ObjPatchFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFaninOld, Abc_Obj_t *pFaninNew)
Definition: abcFanio.c:172
ABC_DLL Abc_Obj_t * Abc_NodeFindNonCoFanout(Abc_Obj_t *pNode)
Definition: abcUtil.c:800
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
static int Abc_NtkNodeNum(Abc_Ntk_t *pNtk)
Definition: abc.h:293
if(last==0)
Definition: sparse_int.h:34
ABC_DLL int Abc_NtkToBdd(Abc_Ntk_t *pNtk)
Definition: abcFunc.c:1160
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
static void Abc_NodeConstantInput(Abc_Obj_t *pNode, Abc_Obj_t *pFanin, int fConst0)
Definition: abcSweep.c:669
ABC_DLL int Abc_NodeIsInv(Abc_Obj_t *pNode)
Definition: abcObj.c:950
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
#define assert(ex)
Definition: util_old.h:213
void * pData
Definition: abc.h:145
ABC_DLL int Abc_NodeRemoveDupFanins(Abc_Obj_t *pNode)
Definition: abcMinBase.c:180
ABC_DLL int Abc_NodeMinimumBase(Abc_Obj_t *pNode)
Definition: abcMinBase.c:70
ABC_DLL void Abc_NodeComplementInput(Abc_Obj_t *pNode, Abc_Obj_t *pFanin)
Definition: abcObj.c:1005
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
int Abc_NtkSweepBufsInvs ( Abc_Ntk_t pNtk,
int  fVerbose 
)

Function*************************************************************

Synopsis [Sweep to remove buffers and inverters.]

Description []

SideEffects []

SeeAlso []

Definition at line 959 of file abcSweep.c.

960 {
961  Hop_Man_t * pMan;
962  Abc_Obj_t * pObj, * pFanin;
963  int i, k, fChanges = 1, Counter = 0;
964  assert( Abc_NtkIsLogic(pNtk) );
965  // convert network to BDD representation
966  if ( !Abc_NtkToAig(pNtk) )
967  {
968  fprintf( stdout, "Converting to SOP has failed.\n" );
969  return 1;
970  }
971  // get AIG manager
972  pMan = (Hop_Man_t *)pNtk->pManFunc;
973  // label selected nodes
974  Abc_NtkIncrementTravId( pNtk );
975  // iterate till no improvement
976  while ( fChanges )
977  {
978  fChanges = 0;
979  Abc_NtkForEachObj( pNtk, pObj, i )
980  {
981  Abc_ObjForEachFanin( pObj, pFanin, k )
982  {
983  // do not eliminate marked fanins
984  if ( Abc_NodeIsTravIdCurrent(pFanin) )
985  continue;
986  // do not eliminate constant nodes
987  if ( !Abc_ObjIsNode(pFanin) || Abc_ObjFaninNum(pFanin) != 1 )
988  continue;
989  // do not eliminate inverters into COs
990  if ( Abc_ObjIsCo(pObj) && Abc_NodeIsInv(pFanin) )
991  continue;
992  // do not eliminate buffers connecting PIs and POs
993 // if ( Abc_ObjIsCo(pObj) && Abc_ObjIsCi(Abc_ObjFanin0(pFanin)) )
994 // continue;
995  fChanges = 1;
996  Counter++;
997  // update function of the node
998  if ( Abc_NodeIsInv(pFanin) )
999  pObj->pData = Hop_Compose( pMan, (Hop_Obj_t *)pObj->pData, Hop_Not(Hop_IthVar(pMan, k)), k );
1000  // update the fanin
1001  Abc_ObjPatchFanin( pObj, pFanin, Abc_ObjFanin0(pFanin) );
1002  if ( Abc_ObjFanoutNum(pFanin) == 0 )
1003  Abc_NtkDeleteObj(pFanin);
1004  }
1005  }
1006  }
1007  if ( fVerbose )
1008  printf( "Removed %d single input nodes.\n", Counter );
1009  return Counter;
1010 }
static int Abc_NtkIsLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:250
static int Abc_ObjFanoutNum(Abc_Obj_t *pObj)
Definition: abc.h:365
Hop_Obj_t * Hop_Compose(Hop_Man_t *p, Hop_Obj_t *pRoot, Hop_Obj_t *pFunc, int iVar)
Definition: hopDfs.c:415
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
static Hop_Obj_t * Hop_Not(Hop_Obj_t *p)
Definition: hop.h:127
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
Definition: hop.h:65
static int Abc_ObjIsCo(Abc_Obj_t *pObj)
Definition: abc.h:352
ABC_DLL void Abc_ObjPatchFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFaninOld, Abc_Obj_t *pFaninNew)
Definition: abcFanio.c:172
void * pManFunc
Definition: abc.h:191
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
ABC_DLL void Abc_NtkDeleteObj(Abc_Obj_t *pObj)
Definition: abcObj.c:167
static int Counter
static int Abc_NodeIsTravIdCurrent(Abc_Obj_t *p)
Definition: abc.h:411
ABC_DLL int Abc_NodeIsInv(Abc_Obj_t *pNode)
Definition: abcObj.c:950
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition: abc.h:524
static void Abc_NtkIncrementTravId(Abc_Ntk_t *p)
Definition: abc.h:406
ABC_DLL int Abc_NtkToAig(Abc_Ntk_t *pNtk)
Definition: abcFunc.c:1192
#define assert(ex)
Definition: util_old.h:213
void * pData
Definition: abc.h:145
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition: abc.h:446
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition: hop.h:49
Hop_Obj_t * Hop_IthVar(Hop_Man_t *p, int i)
FUNCTION DEFINITIONS ///.
Definition: hopOper.c:63