abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcBalance.c File Reference
#include "base/abc/abc.h"

Go to the source code of this file.

Functions

static
ABC_NAMESPACE_IMPL_START void 
Abc_NtkBalancePerform (Abc_Ntk_t *pNtk, Abc_Ntk_t *pNtkAig, int fDuplicate, int fSelective, int fUpdateLevel)
 DECLARATIONS ///. More...
 
static Abc_Obj_tAbc_NodeBalance_rec (Abc_Ntk_t *pNtkNew, Abc_Obj_t *pNode, Vec_Vec_t *vStorage, int Level, int fDuplicate, int fSelective, int fUpdateLevel)
 
static Vec_Ptr_tAbc_NodeBalanceCone (Abc_Obj_t *pNode, Vec_Vec_t *vSuper, int Level, int fDuplicate, int fSelective)
 
static int Abc_NodeBalanceCone_rec (Abc_Obj_t *pNode, Vec_Ptr_t *vSuper, int fFirst, int fDuplicate, int fSelective)
 
static void Abc_NtkMarkCriticalNodes (Abc_Ntk_t *pNtk)
 
static Vec_Ptr_tAbc_NodeBalanceConeExor (Abc_Obj_t *pNode)
 
Abc_Ntk_tAbc_NtkBalance (Abc_Ntk_t *pNtk, int fDuplicate, int fSelective, int fUpdateLevel)
 FUNCTION DEFINITIONS ///. More...
 
int Abc_NodeBalanceFindLeft (Vec_Ptr_t *vSuper)
 
void Abc_NodeBalancePermute (Abc_Ntk_t *pNtkNew, Vec_Ptr_t *vSuper, int LeftBound)
 
int Abc_NodeBalanceConeExor_rec (Abc_Obj_t *pNode, Vec_Ptr_t *vSuper, int fFirst)
 
Vec_Ptr_tAbc_NodeFindCone_rec (Abc_Obj_t *pNode)
 
void Abc_NtkBalanceAttach (Abc_Ntk_t *pNtk)
 
void Abc_NtkBalanceDetach (Abc_Ntk_t *pNtk)
 
int Abc_NtkBalanceLevel_rec (Abc_Obj_t *pNode)
 
void Abc_NtkBalanceLevel (Abc_Ntk_t *pNtk)
 

Function Documentation

Abc_Obj_t * Abc_NodeBalance_rec ( Abc_Ntk_t pNtkNew,
Abc_Obj_t pNodeOld,
Vec_Vec_t vStorage,
int  Level,
int  fDuplicate,
int  fSelective,
int  fUpdateLevel 
)
static

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

Synopsis [Rebalances the multi-input node rooted at pNodeOld.]

Description []

SideEffects []

SeeAlso []

Definition at line 241 of file abcBalance.c.

242 {
243  Abc_Aig_t * pMan = (Abc_Aig_t *)pNtkNew->pManFunc;
244  Abc_Obj_t * pNodeNew, * pNode1, * pNode2;
245  Vec_Ptr_t * vSuper;
246  int i, LeftBound;
247  assert( !Abc_ObjIsComplement(pNodeOld) );
248  // return if the result if known
249  if ( pNodeOld->pCopy )
250  return pNodeOld->pCopy;
251  assert( Abc_ObjIsNode(pNodeOld) );
252  // get the implication supergate
253 // Abc_NodeBalanceConeExor( pNodeOld );
254  vSuper = Abc_NodeBalanceCone( pNodeOld, vStorage, Level, fDuplicate, fSelective );
255  if ( vSuper->nSize == 0 )
256  { // it means that the supergate contains two nodes in the opposite polarity
257  pNodeOld->pCopy = Abc_ObjNot(Abc_AigConst1(pNtkNew));
258  return pNodeOld->pCopy;
259  }
260  // for each old node, derive the new well-balanced node
261  for ( i = 0; i < vSuper->nSize; i++ )
262  {
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]) );
265  }
266  if ( vSuper->nSize < 2 )
267  printf( "BUG!\n" );
268  // sort the new nodes by level in the decreasing order
269  Vec_PtrSort( vSuper, (int (*)(void))Abc_NodeCompareLevelsDecrease );
270  // balance the nodes
271  assert( vSuper->nSize > 1 );
272  while ( vSuper->nSize > 1 )
273  {
274  // find the left bound on the node to be paired
275  LeftBound = (!fUpdateLevel)? 0 : Abc_NodeBalanceFindLeft( vSuper );
276  // find the node that can be shared (if no such node, randomize choice)
277  Abc_NodeBalancePermute( pNtkNew, vSuper, LeftBound );
278  // pull out the last two nodes
279  pNode1 = (Abc_Obj_t *)Vec_PtrPop(vSuper);
280  pNode2 = (Abc_Obj_t *)Vec_PtrPop(vSuper);
281  Abc_VecObjPushUniqueOrderByLevel( vSuper, Abc_AigAnd(pMan, pNode1, pNode2) );
282  }
283  // make sure the balanced node is not assigned
284  assert( pNodeOld->pCopy == NULL );
285  // mark the old node with the new node
286  pNodeOld->pCopy = (Abc_Obj_t *)vSuper->pArray[0];
287  vSuper->nSize = 0;
288 // if ( Abc_ObjRegular(pNodeOld->pCopy) == Abc_AigConst1(pNtkNew) )
289 // printf( "Constant node\n" );
290 // assert( pNodeOld->Level >= Abc_ObjRegular(pNodeOld->pCopy)->Level );
291  return pNodeOld->pCopy;
292 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
Definition: abcAig.c:683
static void Vec_PtrSort(Vec_Ptr_t *p, int(*Vec_PtrSortCompare)()) ___unused
Definition: vecPtr.h:851
static void * Vec_PtrPop(Vec_Ptr_t *p)
Definition: vecPtr.h:677
DECLARATIONS ///.
Definition: abcAig.c:52
static Abc_Obj_t * Abc_NodeBalance_rec(Abc_Ntk_t *pNtkNew, Abc_Obj_t *pNode, Vec_Vec_t *vStorage, int Level, int fDuplicate, int fSelective, int fUpdateLevel)
Definition: abcBalance.c:241
void * pManFunc
Definition: abc.h:191
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
int Abc_NodeBalanceFindLeft(Vec_Ptr_t *vSuper)
Definition: abcBalance.c:154
ABC_DLL Abc_Obj_t * Abc_AigAnd(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
Definition: abcAig.c:700
Abc_Obj_t * pCopy
Definition: abc.h:148
ABC_DLL void Abc_VecObjPushUniqueOrderByLevel(Vec_Ptr_t *p, Abc_Obj_t *pNode)
Definition: abcUtil.c:1228
static Vec_Ptr_t * Abc_NodeBalanceCone(Abc_Obj_t *pNode, Vec_Vec_t *vSuper, int Level, int fDuplicate, int fSelective)
Definition: abcBalance.c:307
static Abc_Obj_t * Abc_ObjRegular(Abc_Obj_t *p)
Definition: abc.h:323
ABC_DLL int Abc_NodeCompareLevelsDecrease(Abc_Obj_t **pp1, Abc_Obj_t **pp2)
Definition: abcUtil.c:1675
static Abc_Obj_t * Abc_ObjNotCond(Abc_Obj_t *p, int c)
Definition: abc.h:325
#define assert(ex)
Definition: util_old.h:213
static Abc_Obj_t * Abc_ObjNot(Abc_Obj_t *p)
Definition: abc.h:324
void Abc_NodeBalancePermute(Abc_Ntk_t *pNtkNew, Vec_Ptr_t *vSuper, int LeftBound)
Definition: abcBalance.c:192
static int Abc_ObjIsComplement(Abc_Obj_t *p)
Definition: abc.h:322
Vec_Ptr_t * Abc_NodeBalanceCone ( Abc_Obj_t pNode,
Vec_Vec_t vStorage,
int  Level,
int  fDuplicate,
int  fSelective 
)
static

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

Synopsis [Collects the nodes in the cone delimited by fMarkA==1.]

Description [Returns -1 if the AND-cone has the same node in both polarities. Returns 1 if the AND-cone has the same node in the same polarity. Returns 0 if the AND-cone has no repeated nodes.]

SideEffects []

SeeAlso []

Definition at line 307 of file abcBalance.c.

308 {
309  Vec_Ptr_t * vNodes;
310  int RetValue, i;
311  assert( !Abc_ObjIsComplement(pNode) );
312  // extend the storage
313  if ( Vec_VecSize( vStorage ) <= Level )
314  Vec_VecPush( vStorage, Level, 0 );
315  // get the temporary array of nodes
316  vNodes = Vec_VecEntry( vStorage, Level );
317  Vec_PtrClear( vNodes );
318  // collect the nodes in the implication supergate
319  RetValue = Abc_NodeBalanceCone_rec( pNode, vNodes, 1, fDuplicate, fSelective );
320  assert( vNodes->nSize > 1 );
321  // unmark the visited nodes
322  for ( i = 0; i < vNodes->nSize; i++ )
323  Abc_ObjRegular((Abc_Obj_t *)vNodes->pArray[i])->fMarkB = 0;
324  // if we found the node and its complement in the same implication supergate,
325  // return empty set of nodes (meaning that we should use constant-0 node)
326  if ( RetValue == -1 )
327  vNodes->nSize = 0;
328  return vNodes;
329 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static void Vec_VecPush(Vec_Vec_t *p, int Level, void *Entry)
Definition: vecVec.h:456
static int Abc_NodeBalanceCone_rec(Abc_Obj_t *pNode, Vec_Ptr_t *vSuper, int fFirst, int fDuplicate, int fSelective)
Definition: abcBalance.c:345
static Abc_Obj_t * Abc_ObjRegular(Abc_Obj_t *p)
Definition: abc.h:323
unsigned fMarkB
Definition: abc.h:135
static int Vec_VecSize(Vec_Vec_t *p)
Definition: vecVec.h:222
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
static Vec_Ptr_t * Vec_VecEntry(Vec_Vec_t *p, int i)
Definition: vecVec.h:271
static int Abc_ObjIsComplement(Abc_Obj_t *p)
Definition: abc.h:322
int Abc_NodeBalanceCone_rec ( Abc_Obj_t pNode,
Vec_Ptr_t vSuper,
int  fFirst,
int  fDuplicate,
int  fSelective 
)
static

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

Synopsis [Collects the nodes in the cone delimited by fMarkA==1.]

Description [Returns -1 if the AND-cone has the same node in both polarities. Returns 1 if the AND-cone has the same node in the same polarity. Returns 0 if the AND-cone has no repeated nodes.]

SideEffects []

SeeAlso []

Definition at line 345 of file abcBalance.c.

346 {
347  int RetValue1, RetValue2, i;
348  // check if the node is visited
349  if ( Abc_ObjRegular(pNode)->fMarkB )
350  {
351  // check if the node occurs in the same polarity
352  for ( i = 0; i < vSuper->nSize; i++ )
353  if ( vSuper->pArray[i] == pNode )
354  return 1;
355  // check if the node is present in the opposite polarity
356  for ( i = 0; i < vSuper->nSize; i++ )
357  if ( vSuper->pArray[i] == Abc_ObjNot(pNode) )
358  return -1;
359  assert( 0 );
360  return 0;
361  }
362  // if the new node is complemented or a PI, another gate begins
363  if ( !fFirst && (Abc_ObjIsComplement(pNode) || !Abc_ObjIsNode(pNode) || (!fDuplicate && !fSelective && (Abc_ObjFanoutNum(pNode) > 1)) || Vec_PtrSize(vSuper) > 10000) )
364  {
365  Vec_PtrPush( vSuper, pNode );
366  Abc_ObjRegular(pNode)->fMarkB = 1;
367  return 0;
368  }
369  assert( !Abc_ObjIsComplement(pNode) );
370  assert( Abc_ObjIsNode(pNode) );
371  // go through the branches
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 )
375  return -1;
376  // return 1 if at least one branch has a duplicate
377  return RetValue1 || RetValue2;
378 }
static int Abc_ObjFanoutNum(Abc_Obj_t *pObj)
Definition: abc.h:365
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static Abc_Obj_t * Abc_ObjChild0(Abc_Obj_t *pObj)
Definition: abc.h:383
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
static int Abc_NodeBalanceCone_rec(Abc_Obj_t *pNode, Vec_Ptr_t *vSuper, int fFirst, int fDuplicate, int fSelective)
Definition: abcBalance.c:345
static Abc_Obj_t * Abc_ObjRegular(Abc_Obj_t *p)
Definition: abc.h:323
unsigned fMarkB
Definition: abc.h:135
#define assert(ex)
Definition: util_old.h:213
static Abc_Obj_t * Abc_ObjNot(Abc_Obj_t *p)
Definition: abc.h:324
static int Abc_ObjIsComplement(Abc_Obj_t *p)
Definition: abc.h:322
static Abc_Obj_t * Abc_ObjChild1(Abc_Obj_t *pObj)
Definition: abc.h:384
Vec_Ptr_t * Abc_NodeBalanceConeExor ( Abc_Obj_t pNode)
static

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 428 of file abcBalance.c.

429 {
430  Vec_Ptr_t * vSuper;
431  if ( !pNode->fExor )
432  return NULL;
433  vSuper = Vec_PtrAlloc( 10 );
434  Abc_NodeBalanceConeExor_rec( pNode, vSuper, 1 );
435  printf( "%d ", Vec_PtrSize(vSuper) );
436  Vec_PtrFree( vSuper );
437  return NULL;
438 }
int Abc_NodeBalanceConeExor_rec(Abc_Obj_t *pNode, Vec_Ptr_t *vSuper, int fFirst)
Definition: abcBalance.c:392
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
unsigned fExor
Definition: abc.h:138
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
int Abc_NodeBalanceConeExor_rec ( Abc_Obj_t pNode,
Vec_Ptr_t vSuper,
int  fFirst 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 392 of file abcBalance.c.

393 {
394  int RetValue1, RetValue2, i;
395  // check if the node occurs in the same polarity
396  for ( i = 0; i < vSuper->nSize; i++ )
397  if ( vSuper->pArray[i] == pNode )
398  return 1;
399  // if the new node is complemented or a PI, another gate begins
400  if ( !fFirst && (!pNode->fExor || !Abc_ObjIsNode(pNode)) )
401  {
402  Vec_PtrPush( vSuper, pNode );
403  return 0;
404  }
405  assert( !Abc_ObjIsComplement(pNode) );
406  assert( Abc_ObjIsNode(pNode) );
407  assert( pNode->fExor );
408  // go through the branches
409  RetValue1 = Abc_NodeBalanceConeExor_rec( Abc_ObjFanin0(Abc_ObjFanin0(pNode)), vSuper, 0 );
410  RetValue2 = Abc_NodeBalanceConeExor_rec( Abc_ObjFanin1(Abc_ObjFanin0(pNode)), vSuper, 0 );
411  if ( RetValue1 == -1 || RetValue2 == -1 )
412  return -1;
413  // return 1 if at least one branch has a duplicate
414  return RetValue1 || RetValue2;
415 }
int Abc_NodeBalanceConeExor_rec(Abc_Obj_t *pNode, Vec_Ptr_t *vSuper, int fFirst)
Definition: abcBalance.c:392
static Abc_Obj_t * Abc_ObjFanin1(Abc_Obj_t *pObj)
Definition: abc.h:374
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
#define assert(ex)
Definition: util_old.h:213
unsigned fExor
Definition: abc.h:138
static int Abc_ObjIsComplement(Abc_Obj_t *p)
Definition: abc.h:322
int Abc_NodeBalanceFindLeft ( Vec_Ptr_t vSuper)

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

Synopsis [Finds the left bound on the next candidate to be paired.]

Description [The nodes in the array are in the decreasing order of levels. The last node in the array has the smallest level. By default it would be paired with the next node on the left. However, it may be possible to pair it with some other node on the left, in such a way that the new node is shared. This procedure finds the index of the left-most node, which can be paired with the last node.]

SideEffects []

SeeAlso []

Definition at line 154 of file abcBalance.c.

155 {
156  Abc_Obj_t * pNodeRight, * pNodeLeft;
157  int Current;
158  // if two or less nodes, pair with the first
159  if ( Vec_PtrSize(vSuper) < 3 )
160  return 0;
161  // set the pointer to the one before the last
162  Current = Vec_PtrSize(vSuper) - 2;
163  pNodeRight = (Abc_Obj_t *)Vec_PtrEntry( vSuper, Current );
164  // go through the nodes to the left of this one
165  for ( Current--; Current >= 0; Current-- )
166  {
167  // get the next node on the left
168  pNodeLeft = (Abc_Obj_t *)Vec_PtrEntry( vSuper, Current );
169  // if the level of this node is different, quit the loop
170  if ( Abc_ObjRegular(pNodeLeft)->Level != Abc_ObjRegular(pNodeRight)->Level )
171  break;
172  }
173  Current++;
174  // get the node, for which the equality holds
175  pNodeLeft = (Abc_Obj_t *)Vec_PtrEntry( vSuper, Current );
176  assert( Abc_ObjRegular(pNodeLeft)->Level == Abc_ObjRegular(pNodeRight)->Level );
177  return Current;
178 }
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
unsigned Level
Definition: abc.h:142
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
static Abc_Obj_t * Abc_ObjRegular(Abc_Obj_t *p)
Definition: abc.h:323
#define assert(ex)
Definition: util_old.h:213
void Abc_NodeBalancePermute ( Abc_Ntk_t pNtkNew,
Vec_Ptr_t vSuper,
int  LeftBound 
)

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

Synopsis [Moves closer to the end the node that is best for sharing.]

Description [If there is no node with sharing, randomly chooses one of the legal nodes.]

SideEffects []

SeeAlso []

Definition at line 192 of file abcBalance.c.

193 {
194  Abc_Obj_t * pNode1, * pNode2, * pNode3;
195  int RightBound, i;
196  // get the right bound
197  RightBound = Vec_PtrSize(vSuper) - 2;
198  assert( LeftBound <= RightBound );
199  if ( LeftBound == RightBound )
200  return;
201  // get the two last nodes
202  pNode1 = (Abc_Obj_t *)Vec_PtrEntry( vSuper, RightBound + 1 );
203  pNode2 = (Abc_Obj_t *)Vec_PtrEntry( vSuper, RightBound );
204  // find the first node that can be shared
205  for ( i = RightBound; i >= LeftBound; i-- )
206  {
207  pNode3 = (Abc_Obj_t *)Vec_PtrEntry( vSuper, i );
208  if ( Abc_AigAndLookup( (Abc_Aig_t *)pNtkNew->pManFunc, pNode1, pNode3 ) )
209  {
210  if ( pNode3 == pNode2 )
211  return;
212  Vec_PtrWriteEntry( vSuper, i, pNode2 );
213  Vec_PtrWriteEntry( vSuper, RightBound, pNode3 );
214  return;
215  }
216  }
217 /*
218  // we did not find the node to share, randomize choice
219  {
220  int Choice = rand() % (RightBound - LeftBound + 1);
221  pNode3 = Vec_PtrEntry( vSuper, LeftBound + Choice );
222  if ( pNode3 == pNode2 )
223  return;
224  Vec_PtrWriteEntry( vSuper, LeftBound + Choice, pNode2 );
225  Vec_PtrWriteEntry( vSuper, RightBound, pNode3 );
226  }
227 */
228 }
ABC_DLL Abc_Obj_t * Abc_AigAndLookup(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
Definition: abcAig.c:403
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
DECLARATIONS ///.
Definition: abcAig.c:52
void * pManFunc
Definition: abc.h:191
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
#define assert(ex)
Definition: util_old.h:213
Vec_Ptr_t* Abc_NodeFindCone_rec ( Abc_Obj_t pNode)

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

Synopsis [Collects the nodes in the implication supergate.]

Description []

SideEffects []

SeeAlso []

Definition at line 453 of file abcBalance.c.

454 {
455  Vec_Ptr_t * vNodes;
456  Abc_Obj_t * pNodeC, * pNodeT, * pNodeE;
457  int RetValue, i;
458  assert( !Abc_ObjIsComplement(pNode) );
459  if ( Abc_ObjIsCi(pNode) )
460  return NULL;
461  // start the new array
462  vNodes = Vec_PtrAlloc( 4 );
463  // if the node is the MUX collect its fanins
464  if ( Abc_NodeIsMuxType(pNode) )
465  {
466  pNodeC = Abc_NodeRecognizeMux( pNode, &pNodeT, &pNodeE );
467  Vec_PtrPush( vNodes, Abc_ObjRegular(pNodeC) );
468  Vec_PtrPushUnique( vNodes, Abc_ObjRegular(pNodeT) );
469  Vec_PtrPushUnique( vNodes, Abc_ObjRegular(pNodeE) );
470  }
471  else
472  {
473  // collect the nodes in the implication supergate
474  RetValue = Abc_NodeBalanceCone_rec( pNode, vNodes, 1, 1, 0 );
475  assert( vNodes->nSize > 1 );
476  // unmark the visited nodes
477  Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNode, i )
478  Abc_ObjRegular(pNode)->fMarkB = 0;
479  // if we found the node and its complement in the same implication supergate,
480  // return empty set of nodes (meaning that we should use constant-0 node)
481  if ( RetValue == -1 )
482  vNodes->nSize = 0;
483  }
484  // call for the fanin
485  Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNode, i )
486  {
487  pNode = Abc_ObjRegular(pNode);
488  if ( pNode->pCopy )
489  continue;
490  pNode->pCopy = (Abc_Obj_t *)Abc_NodeFindCone_rec( pNode );
491  }
492  return vNodes;
493 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static int Abc_ObjIsCi(Abc_Obj_t *pObj)
Definition: abc.h:351
static int Vec_PtrPushUnique(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:656
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
Vec_Ptr_t * Abc_NodeFindCone_rec(Abc_Obj_t *pNode)
Definition: abcBalance.c:453
ABC_DLL int Abc_NodeIsMuxType(Abc_Obj_t *pNode)
Definition: abcUtil.c:1301
if(last==0)
Definition: sparse_int.h:34
static int Abc_NodeBalanceCone_rec(Abc_Obj_t *pNode, Vec_Ptr_t *vSuper, int fFirst, int fDuplicate, int fSelective)
Definition: abcBalance.c:345
static Abc_Obj_t * Abc_ObjRegular(Abc_Obj_t *p)
Definition: abc.h:323
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
#define assert(ex)
Definition: util_old.h:213
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static int Abc_ObjIsComplement(Abc_Obj_t *p)
Definition: abc.h:322
ABC_DLL Abc_Obj_t * Abc_NodeRecognizeMux(Abc_Obj_t *pNode, Abc_Obj_t **ppNodeT, Abc_Obj_t **ppNodeE)
Definition: abcUtil.c:1389
Abc_Ntk_t* Abc_NtkBalance ( Abc_Ntk_t pNtk,
int  fDuplicate,
int  fSelective,
int  fUpdateLevel 
)

FUNCTION DEFINITIONS ///.

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

Synopsis [Balances the AIG network.]

Description []

SideEffects []

SeeAlso []

Definition at line 53 of file abcBalance.c.

54 {
55 // extern void Abc_NtkHaigTranfer( Abc_Ntk_t * pNtkOld, Abc_Ntk_t * pNtkNew );
56  Abc_Ntk_t * pNtkAig;
57  assert( Abc_NtkIsStrash(pNtk) );
58  // compute the required times
59  if ( fSelective )
60  {
61  Abc_NtkStartReverseLevels( pNtk, 0 );
63  }
64  // perform balancing
65  pNtkAig = Abc_NtkStartFrom( pNtk, ABC_NTK_STRASH, ABC_FUNC_AIG );
66  // transfer HAIG
67 // Abc_NtkHaigTranfer( pNtk, pNtkAig );
68  // perform balancing
69  Abc_NtkBalancePerform( pNtk, pNtkAig, fDuplicate, fSelective, fUpdateLevel );
70  Abc_NtkFinalize( pNtk, pNtkAig );
71  Abc_AigCleanup( (Abc_Aig_t *)pNtkAig->pManFunc );
72  // undo the required times
73  if ( fSelective )
74  {
76  Abc_NtkCleanMarkA( pNtk );
77  }
78  if ( pNtk->pExdc )
79  pNtkAig->pExdc = Abc_NtkDup( pNtk->pExdc );
80  // make sure everything is okay
81  if ( !Abc_NtkCheck( pNtkAig ) )
82  {
83  printf( "Abc_NtkBalance: The network check has failed.\n" );
84  Abc_NtkDelete( pNtkAig );
85  return NULL;
86  }
87 //Abc_NtkPrintCiLevels( pNtkAig );
88  return pNtkAig;
89 }
static int Abc_NtkIsStrash(Abc_Ntk_t *pNtk)
Definition: abc.h:251
Abc_Ntk_t * pExdc
Definition: abc.h:201
ABC_DLL Abc_Ntk_t * Abc_NtkDup(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:419
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition: abcCheck.c:61
DECLARATIONS ///.
Definition: abcAig.c:52
static ABC_NAMESPACE_IMPL_START void Abc_NtkBalancePerform(Abc_Ntk_t *pNtk, Abc_Ntk_t *pNtkAig, int fDuplicate, int fSelective, int fUpdateLevel)
DECLARATIONS ///.
Definition: abcBalance.c:102
ABC_DLL void Abc_NtkStopReverseLevels(Abc_Ntk_t *pNtk)
Definition: abcTiming.c:1190
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:1233
void * pManFunc
Definition: abc.h:191
ABC_DLL void Abc_NtkCleanMarkA(Abc_Ntk_t *pNtk)
Definition: abcUtil.c:663
ABC_DLL Abc_Ntk_t * Abc_NtkStartFrom(Abc_Ntk_t *pNtk, Abc_NtkType_t Type, Abc_NtkFunc_t Func)
Definition: abcNtk.c:106
ABC_DLL int Abc_AigCleanup(Abc_Aig_t *pMan)
Definition: abcAig.c:194
static void Abc_NtkMarkCriticalNodes(Abc_Ntk_t *pNtk)
Definition: abcBalance.c:612
ABC_DLL void Abc_NtkFinalize(Abc_Ntk_t *pNtk, Abc_Ntk_t *pNtkNew)
Definition: abcNtk.c:302
ABC_DLL void Abc_NtkStartReverseLevels(Abc_Ntk_t *pNtk, int nMaxLevelIncrease)
Definition: abcTiming.c:1162
#define assert(ex)
Definition: util_old.h:213
void Abc_NtkBalanceAttach ( Abc_Ntk_t pNtk)

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

Synopsis [Attaches the implication supergates to internal nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 506 of file abcBalance.c.

507 {
508  Abc_Obj_t * pNode;
509  int i;
510  Abc_NtkCleanCopy( pNtk );
511  Abc_NtkForEachCo( pNtk, pNode, i )
512  {
513  pNode = Abc_ObjFanin0(pNode);
514  if ( pNode->pCopy )
515  continue;
516  pNode->pCopy = (Abc_Obj_t *)Abc_NodeFindCone_rec( pNode );
517  }
518 }
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition: abc.h:519
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
Vec_Ptr_t * Abc_NodeFindCone_rec(Abc_Obj_t *pNode)
Definition: abcBalance.c:453
Abc_Obj_t * pCopy
Definition: abc.h:148
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
Definition: abcUtil.c:507
void Abc_NtkBalanceDetach ( Abc_Ntk_t pNtk)

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

Synopsis [Attaches the implication supergates to internal nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 531 of file abcBalance.c.

532 {
533  Abc_Obj_t * pNode;
534  int i;
535  Abc_NtkForEachNode( pNtk, pNode, i )
536  if ( pNode->pCopy )
537  {
538  Vec_PtrFree( (Vec_Ptr_t *)pNode->pCopy );
539  pNode->pCopy = NULL;
540  }
541 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
Abc_Obj_t * pCopy
Definition: abc.h:148
if(last==0)
Definition: sparse_int.h:34
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
void Abc_NtkBalanceLevel ( Abc_Ntk_t pNtk)

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

Synopsis [Compute levels of implication supergates.]

Description []

SideEffects []

SeeAlso []

Definition at line 590 of file abcBalance.c.

591 {
592  Abc_Obj_t * pNode;
593  int i;
594  Abc_NtkForEachObj( pNtk, pNode, i )
595  pNode->Level = 0;
596  Abc_NtkForEachCo( pNtk, pNode, i )
598 }
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition: abc.h:519
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition: abc.h:446
int Abc_NtkBalanceLevel_rec(Abc_Obj_t *pNode)
Definition: abcBalance.c:554
int Abc_NtkBalanceLevel_rec ( Abc_Obj_t pNode)

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

Synopsis [Compute levels of implication supergates.]

Description []

SideEffects []

SeeAlso []

Definition at line 554 of file abcBalance.c.

555 {
556  Vec_Ptr_t * vSuper;
557  Abc_Obj_t * pFanin;
558  int i, LevelMax;
559  assert( !Abc_ObjIsComplement(pNode) );
560  if ( pNode->Level > 0 )
561  return pNode->Level;
562  if ( Abc_ObjIsCi(pNode) )
563  return 0;
564  vSuper = (Vec_Ptr_t *)pNode->pCopy;
565  assert( vSuper != NULL );
566  LevelMax = 0;
567  Vec_PtrForEachEntry( Abc_Obj_t *, vSuper, pFanin, i )
568  {
569  pFanin = Abc_ObjRegular(pFanin);
570  Abc_NtkBalanceLevel_rec(pFanin);
571  if ( LevelMax < (int)pFanin->Level )
572  LevelMax = pFanin->Level;
573  }
574  pNode->Level = LevelMax + 1;
575  return pNode->Level;
576 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static int Abc_ObjIsCi(Abc_Obj_t *pObj)
Definition: abc.h:351
unsigned Level
Definition: abc.h:142
Abc_Obj_t * pCopy
Definition: abc.h:148
static Abc_Obj_t * Abc_ObjRegular(Abc_Obj_t *p)
Definition: abc.h:323
#define assert(ex)
Definition: util_old.h:213
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static int Abc_ObjIsComplement(Abc_Obj_t *p)
Definition: abc.h:322
int Abc_NtkBalanceLevel_rec(Abc_Obj_t *pNode)
Definition: abcBalance.c:554
void Abc_NtkBalancePerform ( Abc_Ntk_t pNtk,
Abc_Ntk_t pNtkAig,
int  fDuplicate,
int  fSelective,
int  fUpdateLevel 
)
static

DECLARATIONS ///.

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

FileName [abcBalance.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Network and node package.]

Synopsis [Performs global balancing of the AIG by the number of levels.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

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

]

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

Synopsis [Balances the AIG network.]

Description []

SideEffects []

SeeAlso []

Definition at line 102 of file abcBalance.c.

103 {
104  ProgressBar * pProgress;
105  Vec_Vec_t * vStorage;
106  Abc_Obj_t * pNode;
107  int i;
108  // transfer level
109  Abc_NtkForEachCi( pNtk, pNode, i )
110  pNode->pCopy->Level = pNode->Level;
111  // set the level of PIs of AIG according to the arrival times of the old network
113  // allocate temporary storage for supergates
114  vStorage = Vec_VecStart( 10 );
115  // perform balancing of POs
116  pProgress = Extra_ProgressBarStart( stdout, Abc_NtkCoNum(pNtk) );
117  if ( pNtk->nBarBufs == 0 )
118  {
119  Abc_NtkForEachCo( pNtk, pNode, i )
120  {
121  Extra_ProgressBarUpdate( pProgress, i, NULL );
122  Abc_NodeBalance_rec( pNtkAig, Abc_ObjFanin0(pNode), vStorage, 0, fDuplicate, fSelective, fUpdateLevel );
123  }
124  }
125  else
126  {
127  Abc_NtkForEachLiPo( pNtk, pNode, i )
128  {
129  Extra_ProgressBarUpdate( pProgress, i, NULL );
130  Abc_NodeBalance_rec( pNtkAig, Abc_ObjFanin0(pNode), vStorage, 0, fDuplicate, fSelective, fUpdateLevel );
131  if ( i < pNtk->nBarBufs )
133  }
134  }
135  Extra_ProgressBarStop( pProgress );
136  Vec_VecFree( vStorage );
137 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.
Definition: vecVec.h:42
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition: abc.h:519
static void Vec_VecFree(Vec_Vec_t *p)
Definition: vecVec.h:347
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
static int Abc_NtkCoNum(Abc_Ntk_t *pNtk)
Definition: abc.h:288
static Abc_Obj_t * Abc_NodeBalance_rec(Abc_Ntk_t *pNtkNew, Abc_Obj_t *pNode, Vec_Vec_t *vStorage, int Level, int fDuplicate, int fSelective, int fUpdateLevel)
Definition: abcBalance.c:241
unsigned Level
Definition: abc.h:142
DECLARATIONS ///.
if(last==0)
Definition: sparse_int.h:34
static Vec_Vec_t * Vec_VecStart(int nSize)
Definition: vecVec.h:168
void Extra_ProgressBarStop(ProgressBar *p)
#define Abc_NtkForEachLiPo(pNtk, pCo, i)
Definition: abc.h:521
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition: abc.h:515
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
ABC_DLL void Abc_NtkSetNodeLevelsArrival(Abc_Ntk_t *pNtk)
Definition: abcTiming.c:591
static void Extra_ProgressBarUpdate(ProgressBar *p, int nItemsCur, char *pString)
Definition: extra.h:243
static Abc_Obj_t * Abc_ObjFanout0(Abc_Obj_t *pObj)
Definition: abc.h:371
void Abc_NtkMarkCriticalNodes ( Abc_Ntk_t pNtk)
static

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

Synopsis [Marks the nodes on the critical and near critical paths.]

Description []

SideEffects []

SeeAlso []

Definition at line 612 of file abcBalance.c.

613 {
614  Abc_Obj_t * pNode;
615  int i, Counter = 0;
616  Abc_NtkForEachNode( pNtk, pNode, i )
617  if ( Abc_ObjRequiredLevel(pNode) - pNode->Level <= 1 )
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) );
620 }
static int Abc_NtkNodeNum(Abc_Ntk_t *pNtk)
Definition: abc.h:293
ABC_DLL int Abc_ObjRequiredLevel(Abc_Obj_t *pObj)
Definition: abcTiming.c:1102
if(last==0)
Definition: sparse_int.h:34
static int Counter
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461