30static void Abc_NtkBalancePerform(
Abc_Ntk_t * pNtk,
Abc_Ntk_t * pNtkAig,
int fDuplicate,
int fSelective,
int fUpdateLevel );
33static int Abc_NodeBalanceCone_rec(
Abc_Obj_t * pNode,
Vec_Ptr_t * vSuper,
int fFirst,
int fDuplicate,
int fSelective );
34static void Abc_NtkMarkCriticalNodes(
Abc_Ntk_t * pNtk );
57 assert( Abc_NtkIsStrash(pNtk) );
62 Abc_NtkMarkCriticalNodes( pNtk );
69 Abc_NtkBalancePerform( pNtk, pNtkAig, fDuplicate, fSelective, fUpdateLevel );
83 printf(
"Abc_NtkBalance: The network check has failed.\n" );
102void Abc_NtkBalancePerform(
Abc_Ntk_t * pNtk,
Abc_Ntk_t * pNtkAig,
int fDuplicate,
int fSelective,
int fUpdateLevel )
114 vStorage = Vec_VecStart( 10 );
121 Extra_ProgressBarUpdate( pProgress, i, NULL );
122 Abc_NodeBalance_rec( pNtkAig, Abc_ObjFanin0(pNode), vStorage, 0, fDuplicate, fSelective, fUpdateLevel );
129 Extra_ProgressBarUpdate( pProgress, i, NULL );
130 Abc_NodeBalance_rec( pNtkAig, Abc_ObjFanin0(pNode), vStorage, 0, fDuplicate, fSelective, fUpdateLevel );
131 if ( i < pNtk->nBarBufs )
132 Abc_ObjFanout0(Abc_ObjFanout0(pNode))->Level = Abc_ObjFanin0(pNode)->Level;
136 Vec_VecFree( vStorage );
159 if ( Vec_PtrSize(vSuper) < 3 )
162 Current = Vec_PtrSize(vSuper) - 2;
163 pNodeRight = (
Abc_Obj_t *)Vec_PtrEntry( vSuper, Current );
165 for ( Current--; Current >= 0; Current-- )
168 pNodeLeft = (
Abc_Obj_t *)Vec_PtrEntry( vSuper, Current );
170 if ( Abc_ObjRegular(pNodeLeft)->Level != Abc_ObjRegular(pNodeRight)->Level )
175 pNodeLeft = (
Abc_Obj_t *)Vec_PtrEntry( vSuper, Current );
176 assert( Abc_ObjRegular(pNodeLeft)->Level == Abc_ObjRegular(pNodeRight)->Level );
197 RightBound = Vec_PtrSize(vSuper) - 2;
198 assert( LeftBound <= RightBound );
199 if ( LeftBound == RightBound )
202 pNode1 = (
Abc_Obj_t *)Vec_PtrEntry( vSuper, RightBound + 1 );
203 pNode2 = (
Abc_Obj_t *)Vec_PtrEntry( vSuper, RightBound );
205 for ( i = RightBound; i >= LeftBound; i-- )
207 pNode3 = (
Abc_Obj_t *)Vec_PtrEntry( vSuper, i );
210 if ( pNode3 == pNode2 )
212 Vec_PtrWriteEntry( vSuper, i, pNode2 );
213 Vec_PtrWriteEntry( vSuper, RightBound, pNode3 );
244 Abc_Obj_t * pNodeNew, * pNode1, * pNode2;
247 assert( !Abc_ObjIsComplement(pNodeOld) );
249 if ( pNodeOld->pCopy )
250 return pNodeOld->pCopy;
251 assert( Abc_ObjIsNode(pNodeOld) );
254 vSuper = Abc_NodeBalanceCone( pNodeOld, vStorage, Level, fDuplicate, fSelective );
255 if ( vSuper->nSize == 0 )
258 return pNodeOld->pCopy;
261 for ( i = 0; i < vSuper->nSize; i++ )
263 pNodeNew = Abc_NodeBalance_rec( pNtkNew, Abc_ObjRegular((
Abc_Obj_t *)vSuper->pArray[i]), vStorage, Level + 1, fDuplicate, fSelective, fUpdateLevel );
264 vSuper->pArray[i] = Abc_ObjNotCond( pNodeNew, Abc_ObjIsComplement((
Abc_Obj_t *)vSuper->pArray[i]) );
266 if ( vSuper->nSize < 2 )
271 assert( vSuper->nSize > 1 );
272 while ( vSuper->nSize > 1 )
279 pNode1 = (
Abc_Obj_t *)Vec_PtrPop(vSuper);
280 pNode2 = (
Abc_Obj_t *)Vec_PtrPop(vSuper);
284 assert( pNodeOld->pCopy == NULL );
286 pNodeOld->pCopy = (
Abc_Obj_t *)vSuper->pArray[0];
291 return pNodeOld->pCopy;
311 assert( !Abc_ObjIsComplement(pNode) );
313 if ( Vec_VecSize( vStorage ) <= Level )
314 Vec_VecPush( vStorage, Level, 0 );
316 vNodes = Vec_VecEntry( vStorage, Level );
317 Vec_PtrClear( vNodes );
319 RetValue = Abc_NodeBalanceCone_rec( pNode, vNodes, 1, fDuplicate, fSelective );
320 assert( vNodes->nSize > 1 );
322 for ( i = 0; i < vNodes->nSize; i++ )
323 Abc_ObjRegular((
Abc_Obj_t *)vNodes->pArray[i])->fMarkB = 0;
326 if ( RetValue == -1 )
345int Abc_NodeBalanceCone_rec(
Abc_Obj_t * pNode,
Vec_Ptr_t * vSuper,
int fFirst,
int fDuplicate,
int fSelective )
347 int RetValue1, RetValue2, i;
349 if ( Abc_ObjRegular(pNode)->fMarkB )
352 for ( i = 0; i < vSuper->nSize; i++ )
353 if ( vSuper->pArray[i] == pNode )
356 for ( i = 0; i < vSuper->nSize; i++ )
357 if ( vSuper->pArray[i] == Abc_ObjNot(pNode) )
363 if ( !fFirst && (Abc_ObjIsComplement(pNode) || !Abc_ObjIsNode(pNode) || (!fDuplicate && !fSelective && (Abc_ObjFanoutNum(pNode) > 1)) || Vec_PtrSize(vSuper) > 10000) )
365 Vec_PtrPush( vSuper, pNode );
366 Abc_ObjRegular(pNode)->fMarkB = 1;
369 assert( !Abc_ObjIsComplement(pNode) );
370 assert( Abc_ObjIsNode(pNode) );
372 RetValue1 = Abc_NodeBalanceCone_rec( Abc_ObjChild0(pNode), vSuper, 0, fDuplicate, fSelective );
373 RetValue2 = Abc_NodeBalanceCone_rec( Abc_ObjChild1(pNode), vSuper, 0, fDuplicate, fSelective );
374 if ( RetValue1 == -1 || RetValue2 == -1 )
377 return RetValue1 || RetValue2;
394 int RetValue1, RetValue2, i;
396 for ( i = 0; i < vSuper->nSize; i++ )
397 if ( vSuper->pArray[i] == pNode )
400 if ( !fFirst && (!pNode->
fExor || !Abc_ObjIsNode(pNode)) )
402 Vec_PtrPush( vSuper, pNode );
405 assert( !Abc_ObjIsComplement(pNode) );
406 assert( Abc_ObjIsNode(pNode) );
411 if ( RetValue1 == -1 || RetValue2 == -1 )
414 return RetValue1 || RetValue2;
433 vSuper = Vec_PtrAlloc( 10 );
435 printf(
"%d ", Vec_PtrSize(vSuper) );
436 Vec_PtrFree( vSuper );
458 assert( !Abc_ObjIsComplement(pNode) );
459 if ( Abc_ObjIsCi(pNode) )
462 vNodes = Vec_PtrAlloc( 4 );
467 Vec_PtrPush( vNodes, Abc_ObjRegular(pNodeC) );
468 Vec_PtrPushUnique( vNodes, Abc_ObjRegular(pNodeT) );
469 Vec_PtrPushUnique( vNodes, Abc_ObjRegular(pNodeE) );
474 RetValue = Abc_NodeBalanceCone_rec( pNode, vNodes, 1, 1, 0 );
475 assert( vNodes->nSize > 1 );
478 Abc_ObjRegular(pNode)->fMarkB = 0;
481 if ( RetValue == -1 )
487 pNode = Abc_ObjRegular(pNode);
513 pNode = Abc_ObjFanin0(pNode);
559 assert( !Abc_ObjIsComplement(pNode) );
560 if ( pNode->
Level > 0 )
562 if ( Abc_ObjIsCi(pNode) )
569 pFanin = Abc_ObjRegular(pFanin);
571 if ( LevelMax < (
int)pFanin->
Level )
572 LevelMax = pFanin->
Level;
574 pNode->
Level = LevelMax + 1;
612void Abc_NtkMarkCriticalNodes(
Abc_Ntk_t * pNtk )
618 pNode->
fMarkA = 1, Counter++;
619 printf(
"The number of nodes on the critical paths = %6d (%5.2f %%)\n", Counter, 100.0 * Counter / Abc_NtkNodeNum(pNtk) );
Vec_Ptr_t * Abc_NodeFindCone_rec(Abc_Obj_t *pNode)
void Abc_NtkBalanceAttach(Abc_Ntk_t *pNtk)
int Abc_NtkBalanceLevel_rec(Abc_Obj_t *pNode)
void Abc_NtkBalanceDetach(Abc_Ntk_t *pNtk)
Abc_Ntk_t * Abc_NtkBalance(Abc_Ntk_t *pNtk, int fDuplicate, int fSelective, int fUpdateLevel)
FUNCTION DEFINITIONS ///.
int Abc_NodeBalanceConeExor_rec(Abc_Obj_t *pNode, Vec_Ptr_t *vSuper, int fFirst)
void Abc_NodeBalancePermute(Abc_Ntk_t *pNtkNew, Vec_Ptr_t *vSuper, int LeftBound)
void Abc_NtkBalanceLevel(Abc_Ntk_t *pNtk)
int Abc_NodeBalanceFindLeft(Vec_Ptr_t *vSuper)
struct Abc_Obj_t_ Abc_Obj_t
ABC_DLL void Abc_NtkCleanMarkA(Abc_Ntk_t *pNtk)
#define Abc_NtkForEachCo(pNtk, pCo, i)
ABC_DLL void Abc_VecObjPushUniqueOrderByLevel(Vec_Ptr_t *p, Abc_Obj_t *pNode)
ABC_DLL int Abc_ObjRequiredLevel(Abc_Obj_t *pObj)
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
struct Abc_Aig_t_ Abc_Aig_t
struct Abc_Ntk_t_ Abc_Ntk_t
ABC_DLL void Abc_NtkFinalize(Abc_Ntk_t *pNtk, Abc_Ntk_t *pNtkNew)
ABC_DLL Abc_Obj_t * Abc_AigAndLookup(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
ABC_DLL void Abc_NtkStopReverseLevels(Abc_Ntk_t *pNtk)
ABC_DLL int Abc_AigCleanup(Abc_Aig_t *pMan)
ABC_DLL void Abc_NtkStartReverseLevels(Abc_Ntk_t *pNtk, int nMaxLevelIncrease)
ABC_DLL Abc_Obj_t * Abc_AigAnd(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
#define Abc_NtkForEachCi(pNtk, pCi, i)
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
ABC_DLL int Abc_NodeIsMuxType(Abc_Obj_t *pNode)
ABC_DLL void Abc_NtkSetNodeLevelsArrival(Abc_Ntk_t *pNtk)
ABC_DLL Abc_Obj_t * Abc_NodeRecognizeMux(Abc_Obj_t *pNode, Abc_Obj_t **ppNodeT, Abc_Obj_t **ppNodeE)
ABC_DLL Abc_Ntk_t * Abc_NtkStartFrom(Abc_Ntk_t *pNtk, Abc_NtkType_t Type, Abc_NtkFunc_t Func)
ABC_DLL Abc_Ntk_t * Abc_NtkDup(Abc_Ntk_t *pNtk)
ABC_DLL int Abc_NodeCompareLevelsDecrease(Abc_Obj_t **pp1, Abc_Obj_t **pp2)
#define Abc_NtkForEachLiPo(pNtk, pCo, i)
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
#define Abc_NtkForEachNode(pNtk, pNode, i)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
ABC_NAMESPACE_IMPL_START typedef char ProgressBar
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.