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 );
43static void Abc_NodeSweep(
Abc_Obj_t * pNode,
int fVerbose );
71 assert( !Abc_NtkIsStrash(pNtk) );
75 if ( Abc_NtkIsMappedLogic(pNtk) )
104 if ( pNtk->
pExdc == NULL )
105 printf(
"Warning: Networks has no EXDC.\n" );
107 Abc_NtkFraigSweepUsingExdc( pMan, pNtk );
113 tEquiv = Abc_NtkFraigEquiv( pNtk, fUseInv, fVerbose, fVeryVerbose );
116 Abc_NtkFraigTransform( pNtk, tEquiv, fUseInv, fVerbose );
124 if ( Abc_NtkHasMapping(pNtk) )
132 printf(
"Abc_NtkFraigSweep: The network check has failed.\n" );
163 if ( Abc_ObjFaninNum(pNode) == 0 )
166 pNodeAig = pNode->
pCopy;
168 if ( pNodeAig == NULL )
171 gNode =
Fraig_NotCond( Abc_ObjRegular(pNodeAig)->pCopy, (
int)Abc_ObjIsComplement(pNodeAig) );
175 Abc_ObjRegular(pNodeAig)->pCopy = (
Abc_Obj_t *)
Fraig_NotCond( gNodeRes, (
int)Abc_ObjIsComplement(pNodeAig) );
190stmm_table * Abc_NtkFraigEquiv(
Abc_Ntk_t * pNtk,
int fUseInv,
int fVerbose,
int fVeryVerbose )
205 if ( Abc_ObjFaninNum(pNode) == 0 )
208 pNodeAig = pNode->
pCopy;
210 if ( pNodeAig == NULL )
216 gNode =
Fraig_NotCond( Abc_ObjRegular(pNodeAig)->pCopy, (
int)Abc_ObjIsComplement(pNodeAig) );
220 pNode->
pNext = *ppSlot;
233 if ( pList == NULL || pList->pNext == NULL )
238 for ( pNode = pList; pNode; pNode = pNode->
pNext )
243 printf(
"Class %2d : {", c );
244 for ( pNode = pList; pNode; pNode = pNode->
pNext )
248 printf(
"(%c)", pNode->
fPhase?
'-' :
'+' );
249 printf(
"(%d)", pNode->
Level );
255 if ( fVerbose || fVeryVerbose )
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 );
277void Abc_NtkFraigTransform(
Abc_Ntk_t * pNtk,
stmm_table * tEquiv,
int fUseInv,
int fVerbose )
284 if ( Abc_NtkHasMapping( pNtk ) )
288 Abc_NtkFraigMergeClassMapped( pNtk, pList, fUseInv, fVerbose );
293 Abc_NtkFraigMergeClass( pNtk, pList, fUseInv, fVerbose );
309void Abc_NtkFraigMergeClassMapped(
Abc_Ntk_t * pNtk,
Abc_Obj_t * pChain,
int fUseInv,
int fVerbose )
313 float Arrival1, Arrival2;
320 pListDir = pListInv = NULL;
321 for ( pNode = pChain, pNext = pChain->
pNext;
323 pNode = pNext, pNext = pNode? pNode->
pNext : NULL )
328 pNode->
pNext = pListDir;
333 pNode->
pNext = pListInv;
340 for ( pNode = pListDir; pNode; pNode = pNode->
pNext )
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)) )
354 for ( pNode = pListDir; pNode; pNode = pNode->
pNext )
355 if ( pNode != pNodeMin )
360 for ( pNode = pListInv; pNode; pNode = pNode->
pNext )
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)) )
374 for ( pNode = pListInv; pNode; pNode = pNode->
pNext )
375 if ( pNode != pNodeMin )
391void Abc_NtkFraigMergeClass(
Abc_Ntk_t * pNtk,
Abc_Obj_t * pChain,
int fUseInv,
int fVerbose )
402 for ( pNode = pChain->
pNext; pNode; pNode = pNode->
pNext )
405 Abc_NodeDroppingCost(pNodeMin) < Abc_NodeDroppingCost(pNode) ) )
410 pListDir = pListInv = NULL;
411 for ( pNode = pChain, pNext = pChain->
pNext;
413 pNode = pNext, pNext = pNode? pNode->
pNext : NULL )
415 if ( pNode == pNodeMin )
420 pNode->
pNext = pListDir;
425 pNode->
pNext = pListInv;
431 for ( pNode = pListDir; pNode; pNode = pNode->
pNext )
435 if ( pListInv == NULL )
442 for ( pNode = pListInv; pNode; pNode = pNode->
pNext )
458int Abc_NodeDroppingCost(
Abc_Obj_t * pNode )
482 assert( Abc_NtkIsLogic(pNtk) );
485 Counter = Abc_NtkReduceNodes( pNtk, vNodes );
487 printf(
"Cleanup removed %d dangling nodes.\n", Counter );
488 Vec_PtrFree( vNodes );
508 assert( Abc_NtkIsLogic(pNtk) );
510 vStarts = Vec_PtrAlloc( 1000 );
512 Vec_PtrPush( vStarts, pObj );
515 Vec_PtrPush( vStarts, pObj );
518 Vec_PtrFree( vStarts );
519 Counter = Abc_NtkReduceNodes( pNtk, vNodes );
521 printf(
"Cleanup removed %d dangling nodes.\n", Counter );
522 Vec_PtrFree( vNodes );
541 assert( Abc_NtkIsLogic(pNtk) );
558 printf(
"Abc_NtkCleanup: The network check has failed.\n" );
581 DdNode * bVar, * bTemp;
584 if ( (iFanin = Vec_IntFind( &pNode->
vFanins, pFanin->Id )) == -1 )
586 printf(
"Node %s should be among",
Abc_ObjName(pFanin) );
587 printf(
" the fanins of node %s...\n",
Abc_ObjName(pNode) );
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 );
611 assert( Abc_NtkIsLogic(pNtk) );
615 fprintf( stdout,
"Converting to BDD has failed.\n" );
619 nNodesOld = Abc_NtkNodeNum(pNtk);
625 vNodes = Vec_PtrAlloc( 100 );
627 if ( Abc_ObjFaninNum(pNode) < 2 )
628 Vec_PtrPush( vNodes, pNode );
630 while ( Vec_PtrSize(vNodes) > 0 )
634 if ( !Abc_ObjIsNode(pNode) )
638 if ( pFanout == NULL )
640 assert( Abc_ObjIsNode(pFanout) );
642 if ( Abc_ObjFaninNum(pNode) == 0 )
646 assert( Abc_ObjFaninNum(pNode) == 1 );
647 pDriver = Abc_ObjFanin0(pNode);
655 if ( Abc_ObjFaninNum(pFanout) < 2 )
656 Vec_PtrPush( vNodes, pFanout );
658 if ( Abc_ObjFanoutNum(pNode) > 0 )
659 Vec_PtrPush( vNodes, pNode );
663 Vec_PtrFree( vNodes );
670 pNode = Abc_ObjFanin0(pFanout);
671 if ( Abc_ObjFaninNum(pNode) != 1 )
673 pDriver = Abc_ObjFanin0(pNode);
674 if ( !(Abc_ObjFanoutNum(pDriver) == 1 && Abc_ObjIsNode(pDriver)) )
685 printf(
"Sweep removed %d nodes.\n", nNodesOld - Abc_NtkNodeNum(pNtk) );
686 return nNodesOld - Abc_NtkNodeNum(pNtk);
717 printf(
"These nodes will be deleted: \n" );
719 if ( !Abc_NodeIsTravIdCurrent( pObj ) )
729 if ( !Abc_NodeIsTravIdCurrent( pObj ) )
750 Abc_NodeSetTravIdCurrent(pObj);
751 if ( Abc_ObjFaninNum(pObj) == 0 )
753 assert( Abc_ObjFaninNum(pObj) == 1 );
770 if ( Abc_ObjFaninNum(pObj) == 0 )
772 if ( !Abc_ObjIsNode(pObj) )
781 if ( Abc_ObjIsLatch(pObj) || Abc_ObjFaninNum(pObj) > 1 )
814 Abc_Obj_t * pFanin, * pLatch, * pLatchPivot = NULL;
815 int Counter, RetValue, i;
822 if ( RetValue == -1 )
825 if ( (RetValue == 1 && Abc_LatchIsInit0(pLatch)) ||
826 (RetValue == 0 && Abc_LatchIsInit1(pLatch)) )
829 if ( pLatchPivot == NULL )
831 pLatchPivot = pLatch;
834 if ( Abc_LatchInit(pLatch) != Abc_LatchInit(pLatchPivot) )
837 pFanin = Abc_ObjFanout0(pLatchPivot);
840 pFanin = Abc_ObjFanin0(Abc_ObjFanin0(pLatch));
868 vNodes = Vec_PtrAlloc( 100 );
872 if ( !Abc_NodeIsTravIdCurrent(pNode) )
878 if ( Abc_NodeIsTravIdCurrent(pFanin) )
887 assert( !Abc_ObjIsLatch(pFanin) );
888 Vec_PtrPush( vNodes, pFanin );
895 pFanin = Abc_NtkCreatePi(pNtk);
897 Abc_NodeSetTravIdCurrent( pFanin );
900 Counter = Vec_PtrSize(vNodes);
901 Vec_PtrFree( vNodes );
923 assert( Abc_NtkIsLogic(pNtk) );
926 Vec_PtrFree( vNodes );
930 printf(
"Cleanup removed %4d dangling objects.\n", Counter );
936 printf(
"Cleanup removed %4d redundant latches.\n", Counter );
942 Vec_PtrFree( vNodes );
946 printf(
"Cleanup added %4d additional PIs.\n", Counter );
950 printf(
"Cleanup removed %4d autonomous objects.\n", Counter );
954 printf(
"Abc_NtkCleanupSeq: The network check has failed.\n" );
973 int i, k, fChanges = 1, Counter = 0;
974 assert( Abc_NtkIsLogic(pNtk) );
978 fprintf( stdout,
"Converting to SOP has failed.\n" );
984 Abc_NtkIncrementTravId( pNtk );
994 if ( Abc_NodeIsTravIdCurrent(pFanin) )
997 if ( !Abc_ObjIsNode(pFanin) || Abc_ObjFaninNum(pFanin) != 1 )
1012 if ( Abc_ObjFanoutNum(pFanin) == 0 )
1018 printf(
"Removed %d single input nodes.\n", Counter );
Fraig_Node_t * Abc_NtkToFraigExdc(Fraig_Man_t *pMan, Abc_Ntk_t *pNtkMain, Abc_Ntk_t *pNtkExdc)
int Abc_NodeRemoveNonCurrentObjects(Abc_Ntk_t *pNtk)
int Abc_NtkCleanupNodes(Abc_Ntk_t *pNtk, Vec_Ptr_t *vRoots, int fVerbose)
int Abc_NtkCleanup(Abc_Ntk_t *pNtk, int fVerbose)
void Abc_NtkSetTravId_rec(Abc_Obj_t *pObj)
int Abc_NtkCheckConstant_rec(Abc_Obj_t *pObj)
int Abc_NtkSweepBufsInvs(Abc_Ntk_t *pNtk, int fVerbose)
int Abc_NtkSweep(Abc_Ntk_t *pNtk, int fVerbose)
int Abc_NtkReplaceAutonomousLogic(Abc_Ntk_t *pNtk)
int Abc_NtkCleanupSeq(Abc_Ntk_t *pNtk, int fLatchSweep, int fAutoSweep, int fVerbose)
int Abc_NtkFraigSweep(Abc_Ntk_t *pNtk, int fUseInv, int fExdc, int fVerbose, int fVeryVerbose)
FUNCTION DEFINITIONS ///.
int Abc_NtkLatchSweep(Abc_Ntk_t *pNtk)
struct Abc_Obj_t_ Abc_Obj_t
#define Abc_NtkForEachCo(pNtk, pCo, i)
ABC_DLL void Abc_NodeComplementInput(Abc_Obj_t *pNode, Abc_Obj_t *pFanin)
ABC_DLL float Abc_NtkDelayTrace(Abc_Ntk_t *pNtk, Abc_Obj_t *pOut, Abc_Obj_t *pIn, int fPrint)
ABC_DLL void Abc_NtkDeleteObj(Abc_Obj_t *pObj)
ABC_DLL int Abc_NodeIsBuf(Abc_Obj_t *pNode)
#define Abc_NtkForEachLatch(pNtk, pObj, i)
ABC_DLL Vec_Ptr_t * Abc_NtkDfs(Abc_Ntk_t *pNtk, int fCollectAll)
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
#define Abc_ObjForEachFanin(pObj, pFanin, i)
ABC_DLL int Abc_NtkToBdd(Abc_Ntk_t *pNtk)
ABC_DLL void Abc_ObjPrint(FILE *pFile, Abc_Obj_t *pObj)
ABC_DLL int Abc_NodeIsInv(Abc_Obj_t *pNode)
ABC_DLL Vec_Ptr_t * Abc_NtkDfsSeq(Abc_Ntk_t *pNtk)
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
ABC_DLL void Abc_NtkDeleteObj_rec(Abc_Obj_t *pObj, int fOnlyNodes)
struct Abc_Ntk_t_ Abc_Ntk_t
ABC_DLL char * Abc_ObjAssignName(Abc_Obj_t *pObj, char *pName, char *pSuffix)
ABC_DLL int Abc_NodeIsConst0(Abc_Obj_t *pNode)
ABC_DLL void Abc_ObjTransferFanout(Abc_Obj_t *pObjOld, Abc_Obj_t *pObjNew)
ABC_DLL int Abc_NtkLevel(Abc_Ntk_t *pNtk)
ABC_DLL int Abc_NtkToAig(Abc_Ntk_t *pNtk)
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeInv(Abc_Ntk_t *pNtk, Abc_Obj_t *pFanin)
ABC_DLL Abc_Ntk_t * Abc_NtkStrash(Abc_Ntk_t *pNtk, int fAllNodes, int fCleanup, int fRecord)
ABC_DLL int Abc_ObjPointerCompare(void **pp1, void **pp2)
ABC_DLL int Abc_NtkMinimumBase(Abc_Ntk_t *pNtk)
DECLARATIONS ///.
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
ABC_DLL Vec_Ptr_t * Abc_NtkDfsNodes(Abc_Ntk_t *pNtk, Abc_Obj_t **ppNodes, int nNodes)
ABC_DLL Abc_Obj_t * Abc_NodeFindCoFanout(Abc_Obj_t *pNode)
ABC_DLL void Abc_ObjPatchFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFaninOld, Abc_Obj_t *pFaninNew)
ABC_DLL void * Abc_NtkToFraig(Abc_Ntk_t *pNtk, void *pParams, int fAllNodes, int fExdc)
ABC_DLL Abc_Obj_t * Abc_NodeFindNonCoFanout(Abc_Obj_t *pNode)
ABC_DLL float Abc_NodeReadArrivalWorst(Abc_Obj_t *pNode)
ABC_DLL int Abc_NodeIsConst1(Abc_Obj_t *pNode)
#define Abc_NtkForEachNode(pNtk, pNode, i)
ABC_DLL int Abc_NodeMinimumBase(Abc_Obj_t *pNode)
ABC_DLL Vec_Ptr_t * Abc_NtkDfsSeqReverse(Abc_Ntk_t *pNtk)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
ABC_DLL void * Abc_FrameReadLibGen()
#define Fraig_IsComplement(p)
GLOBAL VARIABLES ///.
void Fraig_ManFree(Fraig_Man_t *pMan)
void Fraig_ParamsSetDefault(Fraig_Params_t *pParams)
#define Fraig_NotCond(p, c)
typedefABC_NAMESPACE_HEADER_START struct Fraig_ManStruct_t_ Fraig_Man_t
INCLUDES ///.
struct Fraig_NodeStruct_t_ Fraig_Node_t
struct Fraig_ParamsStruct_t_ Fraig_Params_t
Fraig_Node_t * Fraig_NodeAnd(Fraig_Man_t *p, Fraig_Node_t *p1, Fraig_Node_t *p2)
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Hop_Obj_t * Hop_Compose(Hop_Man_t *p, Hop_Obj_t *pRoot, Hop_Obj_t *pFunc, int iVar)
Hop_Obj_t * Hop_IthVar(Hop_Man_t *p, int i)
FUNCTION DEFINITIONS ///.
void Hop_ManStop(Hop_Man_t *p)
struct Hop_Obj_t_ Hop_Obj_t
int stmm_ptrhash(const char *x, int size)
int stmm_insert(stmm_table *table, char *key, char *value)
int stmm_find_or_add(stmm_table *table, char *key, char ***slot)
int stmm_ptrcmp(const char *x, const char *y)
void stmm_free_table(stmm_table *table)
stmm_table * stmm_init_table(stmm_compare_func_type compare, stmm_hash_func_type hash)
#define stmm_count(table)
#define stmm_foreach_item(table, gen, key, value)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.