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

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START
Ivy_Man_t
Ivy_ManStart ()
 DECLARATIONS ///. More...
 
Ivy_Man_tIvy_ManStartFrom (Ivy_Man_t *p)
 
Ivy_Man_tIvy_ManDup (Ivy_Man_t *p)
 
Ivy_Man_tIvy_ManFrames (Ivy_Man_t *pMan, int nLatches, int nFrames, int fInit, Vec_Ptr_t **pvMapping)
 
void Ivy_ManStop (Ivy_Man_t *p)
 
int Ivy_ManCleanup (Ivy_Man_t *p)
 
void Ivy_ManCleanupSeq_rec (Ivy_Obj_t *pObj)
 
int Ivy_ManCleanupSeq (Ivy_Man_t *p)
 
int Ivy_ManLatchIsSelfFeed_rec (Ivy_Obj_t *pLatch, Ivy_Obj_t *pLatchRoot)
 
int Ivy_ManLatchIsSelfFeed (Ivy_Obj_t *pLatch)
 
int Ivy_ManPropagateBuffers (Ivy_Man_t *p, int fUpdateLevel)
 
void Ivy_ManPrintStats (Ivy_Man_t *p)
 
void Ivy_ManMakeSeq (Ivy_Man_t *p, int nLatches, int *pInits)
 

Function Documentation

int Ivy_ManCleanup ( Ivy_Man_t p)

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

Synopsis [Removes nodes without fanout.]

Description [Returns the number of dangling nodes removed.]

SideEffects []

SeeAlso []

Definition at line 265 of file ivyMan.c.

266 {
267  Ivy_Obj_t * pNode;
268  int i, nNodesOld;
269  nNodesOld = Ivy_ManNodeNum(p);
270  Ivy_ManForEachObj( p, pNode, i )
271  if ( Ivy_ObjIsNode(pNode) || Ivy_ObjIsLatch(pNode) || Ivy_ObjIsBuf(pNode) )
272  if ( Ivy_ObjRefs(pNode) == 0 )
273  Ivy_ObjDelete_rec( p, pNode, 1 );
274 //printf( "Cleanup removed %d nodes.\n", nNodesOld - Ivy_ManNodeNum(p) );
275  return nNodesOld - Ivy_ManNodeNum(p);
276 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Ivy_ObjIsLatch(Ivy_Obj_t *pObj)
Definition: ivy.h:241
static int Ivy_ObjRefs(Ivy_Obj_t *pObj)
Definition: ivy.h:264
if(last==0)
Definition: sparse_int.h:34
Definition: ivy.h:73
static int Ivy_ObjIsNode(Ivy_Obj_t *pObj)
Definition: ivy.h:245
void Ivy_ObjDelete_rec(Ivy_Man_t *p, Ivy_Obj_t *pObj, int fFreeTop)
Definition: ivyObj.c:299
static int Ivy_ObjIsBuf(Ivy_Obj_t *pObj)
Definition: ivy.h:244
static int Ivy_ManNodeNum(Ivy_Man_t *p)
Definition: ivy.h:227
#define Ivy_ManForEachObj(p, pObj, i)
Definition: ivy.h:393
int Ivy_ManCleanupSeq ( Ivy_Man_t p)

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

Synopsis [Removes logic that does not feed into POs.]

Description [Returns the number of dangling nodes removed.]

SideEffects []

SeeAlso []

Definition at line 311 of file ivyMan.c.

312 {
313  Vec_Ptr_t * vNodes;
314  Ivy_Obj_t * pObj;
315  int i, RetValue;
316  // mark the constant and PIs
318  Ivy_ManForEachPi( p, pObj, i )
319  Ivy_ObjSetMarkA( pObj );
320  // mark nodes visited from POs
321  Ivy_ManForEachPo( p, pObj, i )
322  Ivy_ManCleanupSeq_rec( pObj );
323  // collect unmarked nodes
324  vNodes = Vec_PtrAlloc( 100 );
325  Ivy_ManForEachObj( p, pObj, i )
326  {
327  if ( Ivy_ObjIsMarkA(pObj) )
328  Ivy_ObjClearMarkA(pObj);
329  else
330  Vec_PtrPush( vNodes, pObj );
331  }
332  if ( Vec_PtrSize(vNodes) == 0 )
333  {
334  Vec_PtrFree( vNodes );
335 //printf( "Sequential sweep cleaned out %d nodes.\n", 0 );
336  return 0;
337  }
338  // disconnect the marked objects
339  Vec_PtrForEachEntry( Ivy_Obj_t *, vNodes, pObj, i )
340  Ivy_ObjDisconnect( p, pObj );
341  // remove the dangling objects
342  Vec_PtrForEachEntry( Ivy_Obj_t *, vNodes, pObj, i )
343  {
344  assert( Ivy_ObjIsNode(pObj) || Ivy_ObjIsLatch(pObj) || Ivy_ObjIsBuf(pObj) );
345  assert( Ivy_ObjRefs(pObj) == 0 );
346  // update node counters of the manager
347  p->nObjs[pObj->Type]--;
348  p->nDeleted++;
349  // delete buffer from the array of buffers
350  if ( p->fFanout && Ivy_ObjIsBuf(pObj) )
351  Vec_PtrRemove( p->vBufs, pObj );
352  // free the node
353  Vec_PtrWriteEntry( p->vObjs, pObj->Id, NULL );
354  Ivy_ManRecycleMemory( p, pObj );
355  }
356  // return the number of nodes freed
357  RetValue = Vec_PtrSize(vNodes);
358  Vec_PtrFree( vNodes );
359 //printf( "Sequential sweep cleaned out %d nodes.\n", RetValue );
360  return RetValue;
361 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static Ivy_Obj_t * Ivy_ManConst1(Ivy_Man_t *p)
Definition: ivy.h:199
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define Ivy_ManForEachPi(p, pObj, i)
ITERATORS ///.
Definition: ivy.h:387
#define Ivy_ManForEachPo(p, pObj, i)
Definition: ivy.h:390
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static int Ivy_ObjIsMarkA(Ivy_Obj_t *pObj)
Definition: ivy.h:250
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
void Ivy_ManCleanupSeq_rec(Ivy_Obj_t *pObj)
Definition: ivyMan.c:289
static int Ivy_ObjIsLatch(Ivy_Obj_t *pObj)
Definition: ivy.h:241
static void Vec_PtrRemove(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:714
static void Ivy_ObjSetMarkA(Ivy_Obj_t *pObj)
Definition: ivy.h:251
static void Ivy_ObjClearMarkA(Ivy_Obj_t *pObj)
Definition: ivy.h:252
static int Ivy_ObjRefs(Ivy_Obj_t *pObj)
Definition: ivy.h:264
Definition: ivy.h:73
static int Ivy_ObjIsNode(Ivy_Obj_t *pObj)
Definition: ivy.h:245
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
void Ivy_ObjDisconnect(Ivy_Man_t *p, Ivy_Obj_t *pObj)
Definition: ivyObj.c:185
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
static void Ivy_ManRecycleMemory(Ivy_Man_t *p, Ivy_Obj_t *pEntry)
Definition: ivy.h:374
static int Ivy_ObjIsBuf(Ivy_Obj_t *pObj)
Definition: ivy.h:244
#define assert(ex)
Definition: util_old.h:213
#define Ivy_ManForEachObj(p, pObj, i)
Definition: ivy.h:393
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
void Ivy_ManCleanupSeq_rec ( Ivy_Obj_t pObj)

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

Synopsis [Marks nodes reachable from the given one.]

Description [Returns the number of dangling nodes removed.]

SideEffects []

SeeAlso []

Definition at line 289 of file ivyMan.c.

290 {
291  if ( Ivy_ObjIsMarkA(pObj) )
292  return;
293  Ivy_ObjSetMarkA(pObj);
294  if ( pObj->pFanin0 != NULL )
296  if ( pObj->pFanin1 != NULL )
298 }
Ivy_Obj_t * pFanin1
Definition: ivy.h:87
static int Ivy_ObjIsMarkA(Ivy_Obj_t *pObj)
Definition: ivy.h:250
void Ivy_ManCleanupSeq_rec(Ivy_Obj_t *pObj)
Definition: ivyMan.c:289
static Ivy_Obj_t * Ivy_ObjFanin1(Ivy_Obj_t *pObj)
Definition: ivy.h:272
Ivy_Obj_t * pFanin0
Definition: ivy.h:86
static Ivy_Obj_t * Ivy_ObjFanin0(Ivy_Obj_t *pObj)
Definition: ivy.h:271
static void Ivy_ObjSetMarkA(Ivy_Obj_t *pObj)
Definition: ivy.h:251
Ivy_Man_t* Ivy_ManDup ( Ivy_Man_t p)

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

Synopsis [Duplicates the AIG manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 110 of file ivyMan.c.

111 {
112  Vec_Int_t * vNodes, * vLatches;
113  Ivy_Man_t * pNew;
114  Ivy_Obj_t * pObj;
115  int i;
116  // collect latches and nodes in the DFS order
117  vNodes = Ivy_ManDfsSeq( p, &vLatches );
118  // create the new manager
119  pNew = Ivy_ManStart();
120  // create the PIs
122  Ivy_ManForEachPi( p, pObj, i )
123  pObj->pEquiv = Ivy_ObjCreatePi(pNew);
124  // create the fake PIs for latches
125  Ivy_ManForEachNodeVec( p, vLatches, pObj, i )
126  pObj->pEquiv = Ivy_ObjCreatePi(pNew);
127  // duplicate internal nodes
128  Ivy_ManForEachNodeVec( p, vNodes, pObj, i )
129  if ( Ivy_ObjIsBuf(pObj) )
130  pObj->pEquiv = Ivy_ObjChild0Equiv(pObj);
131  else
132  pObj->pEquiv = Ivy_And( pNew, Ivy_ObjChild0Equiv(pObj), Ivy_ObjChild1Equiv(pObj) );
133  // add the POs
134  Ivy_ManForEachPo( p, pObj, i )
135  Ivy_ObjCreatePo( pNew, Ivy_ObjChild0Equiv(pObj) );
136  // transform additional PI nodes into latches and connect them
137  Ivy_ManForEachNodeVec( p, vLatches, pObj, i )
138  {
139  assert( !Ivy_ObjFaninC0(pObj) );
140  pObj->pEquiv->Type = IVY_LATCH;
141  pObj->pEquiv->Init = pObj->Init;
142  Ivy_ObjConnect( pNew, pObj->pEquiv, Ivy_ObjChild0Equiv(pObj), NULL );
143  }
144  // shrink the arrays
145  Vec_PtrShrink( pNew->vPis, Ivy_ManPiNum(p) );
146  // update the counters of different objects
147  pNew->nObjs[IVY_PI] -= Ivy_ManLatchNum(p);
148  pNew->nObjs[IVY_LATCH] += Ivy_ManLatchNum(p);
149  // free arrays
150  Vec_IntFree( vNodes );
151  Vec_IntFree( vLatches );
152  // make sure structural hashing did not change anything
153  assert( Ivy_ManNodeNum(p) == Ivy_ManNodeNum(pNew) );
154  assert( Ivy_ManLatchNum(p) == Ivy_ManLatchNum(pNew) );
155  // check the resulting network
156  if ( !Ivy_ManCheck(pNew) )
157  printf( "Ivy_ManMakeSeq(): The check has failed.\n" );
158  return pNew;
159 }
static Ivy_Obj_t * Ivy_ManConst1(Ivy_Man_t *p)
Definition: ivy.h:199
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
#define Ivy_ManForEachPi(p, pObj, i)
ITERATORS ///.
Definition: ivy.h:387
Definition: ivy.h:57
#define Ivy_ManForEachPo(p, pObj, i)
Definition: ivy.h:390
static int Ivy_ManLatchNum(Ivy_Man_t *p)
Definition: ivy.h:221
static Ivy_Obj_t * Ivy_ObjChild1Equiv(Ivy_Obj_t *pObj)
Definition: ivy.h:276
Vec_Int_t * Ivy_ManDfsSeq(Ivy_Man_t *p, Vec_Int_t **pvLatches)
Definition: ivyDfs.c:121
ABC_NAMESPACE_IMPL_START Ivy_Man_t * Ivy_ManStart()
DECLARATIONS ///.
Definition: ivyMan.c:45
void Ivy_ObjConnect(Ivy_Man_t *p, Ivy_Obj_t *pObj, Ivy_Obj_t *pFan0, Ivy_Obj_t *pFan1)
Definition: ivyObj.c:150
Ivy_Obj_t * Ivy_ObjCreatePo(Ivy_Man_t *p, Ivy_Obj_t *pDriver)
Definition: ivyObj.c:61
static Ivy_Obj_t * Ivy_ObjChild0Equiv(Ivy_Obj_t *pObj)
Definition: ivy.h:275
if(last==0)
Definition: sparse_int.h:34
else
Definition: sparse_int.h:55
Definition: ivy.h:73
typedefABC_NAMESPACE_HEADER_START struct Ivy_Man_t_ Ivy_Man_t
INCLUDES ///.
Definition: ivy.h:46
static int Ivy_ManPiNum(Ivy_Man_t *p)
Definition: ivy.h:218
#define Ivy_ManForEachNodeVec(p, vIds, pObj, i)
Definition: ivy.h:408
static int Ivy_ObjIsBuf(Ivy_Obj_t *pObj)
Definition: ivy.h:244
#define assert(ex)
Definition: util_old.h:213
Ivy_Obj_t * Ivy_ObjCreatePi(Ivy_Man_t *p)
DECLARATIONS ///.
Definition: ivyObj.c:45
static int Ivy_ManNodeNum(Ivy_Man_t *p)
Definition: ivy.h:227
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static void Vec_PtrShrink(Vec_Ptr_t *p, int nSizeNew)
Definition: vecPtr.h:528
Definition: ivy.h:54
static int Ivy_ObjFaninC0(Ivy_Obj_t *pObj)
Definition: ivy.h:269
Ivy_Obj_t * Ivy_And(Ivy_Man_t *p, Ivy_Obj_t *p0, Ivy_Obj_t *p1)
Definition: ivyOper.c:84
int Ivy_ManCheck(Ivy_Man_t *p)
DECLARATIONS ///.
Definition: ivyCheck.c:45
Ivy_Obj_t * pEquiv
Definition: ivy.h:93
Ivy_Man_t* Ivy_ManFrames ( Ivy_Man_t pMan,
int  nLatches,
int  nFrames,
int  fInit,
Vec_Ptr_t **  pvMapping 
)

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

Synopsis [Stops the AIG manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 172 of file ivyMan.c.

173 {
174  Vec_Ptr_t * vMapping;
175  Ivy_Man_t * pNew;
176  Ivy_Obj_t * pObj;
177  int i, f, nPis, nPos, nIdMax;
178  assert( Ivy_ManLatchNum(pMan) == 0 );
179  assert( nFrames > 0 );
180  // prepare the mapping
181  nPis = Ivy_ManPiNum(pMan) - nLatches;
182  nPos = Ivy_ManPoNum(pMan) - nLatches;
183  nIdMax = Ivy_ManObjIdMax(pMan);
184  // create the new manager
185  pNew = Ivy_ManStart();
186  // set the starting values of latch inputs
187  for ( i = 0; i < nLatches; i++ )
188  Ivy_ManPo(pMan, nPos+i)->pEquiv = fInit? Ivy_Not(Ivy_ManConst1(pNew)) : Ivy_ObjCreatePi(pNew);
189  // add timeframes
190  vMapping = Vec_PtrStart( nIdMax * nFrames + 1 );
191  for ( f = 0; f < nFrames; f++ )
192  {
193  // create PIs
194  Ivy_ManConst1(pMan)->pEquiv = Ivy_ManConst1(pNew);
195  for ( i = 0; i < nPis; i++ )
196  Ivy_ManPi(pMan, i)->pEquiv = Ivy_ObjCreatePi(pNew);
197  // transfer values to latch outputs
198  for ( i = 0; i < nLatches; i++ )
199  Ivy_ManPi(pMan, nPis+i)->pEquiv = Ivy_ManPo(pMan, nPos+i)->pEquiv;
200  // perform strashing
201  Ivy_ManForEachNode( pMan, pObj, i )
202  pObj->pEquiv = Ivy_And( pNew, Ivy_ObjChild0Equiv(pObj), Ivy_ObjChild1Equiv(pObj) );
203  // create POs
204  for ( i = 0; i < nPos; i++ )
205  Ivy_ManPo(pMan, i)->pEquiv = Ivy_ObjCreatePo( pNew, Ivy_ObjChild0Equiv(Ivy_ManPo(pMan, i)) );
206  // set the results of latch inputs
207  for ( i = 0; i < nLatches; i++ )
208  Ivy_ManPo(pMan, nPos+i)->pEquiv = Ivy_ObjChild0Equiv(Ivy_ManPo(pMan, nPos+i));
209  // save the pointers in this frame
210  Ivy_ManForEachObj( pMan, pObj, i )
211  Vec_PtrWriteEntry( vMapping, f * nIdMax + i, pObj->pEquiv );
212  }
213  // connect latches
214  if ( !fInit )
215  for ( i = 0; i < nLatches; i++ )
216  Ivy_ObjCreatePo( pNew, Ivy_ManPo(pMan, nPos+i)->pEquiv );
217  // remove dangling nodes
218  Ivy_ManCleanup(pNew);
219  *pvMapping = vMapping;
220  // check the resulting network
221  if ( !Ivy_ManCheck(pNew) )
222  printf( "Ivy_ManFrames(): The check has failed.\n" );
223  return pNew;
224 }
static Vec_Ptr_t * Vec_PtrStart(int nSize)
Definition: vecPtr.h:106
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static Ivy_Obj_t * Ivy_ManConst1(Ivy_Man_t *p)
Definition: ivy.h:199
static Ivy_Obj_t * Ivy_ManPi(Ivy_Man_t *p, int i)
Definition: ivy.h:201
static int Ivy_ManLatchNum(Ivy_Man_t *p)
Definition: ivy.h:221
#define Ivy_ManForEachNode(p, pObj, i)
Definition: ivy.h:402
static int Ivy_ManPoNum(Ivy_Man_t *p)
Definition: ivy.h:219
for(p=first;p->value< newval;p=p->next)
static Ivy_Obj_t * Ivy_ObjChild1Equiv(Ivy_Obj_t *pObj)
Definition: ivy.h:276
static void check(int expr)
Definition: satSolver.c:46
ABC_NAMESPACE_IMPL_START Ivy_Man_t * Ivy_ManStart()
DECLARATIONS ///.
Definition: ivyMan.c:45
static int Ivy_ManObjIdMax(Ivy_Man_t *p)
Definition: ivy.h:226
Ivy_Obj_t * Ivy_ObjCreatePo(Ivy_Man_t *p, Ivy_Obj_t *pDriver)
Definition: ivyObj.c:61
static Ivy_Obj_t * Ivy_ObjChild0Equiv(Ivy_Obj_t *pObj)
Definition: ivy.h:275
if(last==0)
Definition: sparse_int.h:34
Definition: ivy.h:73
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
typedefABC_NAMESPACE_HEADER_START struct Ivy_Man_t_ Ivy_Man_t
INCLUDES ///.
Definition: ivy.h:46
static int Ivy_ManPiNum(Ivy_Man_t *p)
Definition: ivy.h:218
static Ivy_Obj_t * Ivy_Not(Ivy_Obj_t *p)
Definition: ivy.h:194
Ivy_Man_t * Ivy_ManFrames(Ivy_Man_t *pMan, int nLatches, int nFrames, int fInit, Vec_Ptr_t **pvMapping)
Definition: ivyMan.c:172
int Ivy_ManCleanup(Ivy_Man_t *p)
Definition: ivyMan.c:265
#define assert(ex)
Definition: util_old.h:213
Ivy_Obj_t * Ivy_ObjCreatePi(Ivy_Man_t *p)
DECLARATIONS ///.
Definition: ivyObj.c:45
static Ivy_Obj_t * Ivy_ManPo(Ivy_Man_t *p, int i)
Definition: ivy.h:202
#define Ivy_ManForEachObj(p, pObj, i)
Definition: ivy.h:393
Ivy_Obj_t * Ivy_And(Ivy_Man_t *p, Ivy_Obj_t *p0, Ivy_Obj_t *p1)
Definition: ivyOper.c:84
int Ivy_ManCheck(Ivy_Man_t *p)
DECLARATIONS ///.
Definition: ivyCheck.c:45
Ivy_Obj_t * pEquiv
Definition: ivy.h:93
int Ivy_ManLatchIsSelfFeed ( Ivy_Obj_t pLatch)

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

Synopsis [Checks if latches form self-loop.]

Description []

SideEffects []

SeeAlso []

Definition at line 395 of file ivyMan.c.

396 {
397  if ( !Ivy_ObjIsLatch(pLatch) )
398  return 0;
399  return Ivy_ManLatchIsSelfFeed_rec( Ivy_ObjFanin0(pLatch), pLatch );
400 }
int Ivy_ManLatchIsSelfFeed_rec(Ivy_Obj_t *pLatch, Ivy_Obj_t *pLatchRoot)
Definition: ivyMan.c:375
static int Ivy_ObjIsLatch(Ivy_Obj_t *pObj)
Definition: ivy.h:241
static Ivy_Obj_t * Ivy_ObjFanin0(Ivy_Obj_t *pObj)
Definition: ivy.h:271
int Ivy_ManLatchIsSelfFeed_rec ( Ivy_Obj_t pLatch,
Ivy_Obj_t pLatchRoot 
)

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

Synopsis [Checks if latches form self-loop.]

Description []

SideEffects []

SeeAlso []

Definition at line 375 of file ivyMan.c.

376 {
377  if ( !Ivy_ObjIsLatch(pLatch) && !Ivy_ObjIsBuf(pLatch) )
378  return 0;
379  if ( pLatch == pLatchRoot )
380  return 1;
381  return Ivy_ManLatchIsSelfFeed_rec( Ivy_ObjFanin0(pLatch), pLatchRoot );
382 }
int Ivy_ManLatchIsSelfFeed_rec(Ivy_Obj_t *pLatch, Ivy_Obj_t *pLatchRoot)
Definition: ivyMan.c:375
static int Ivy_ObjIsLatch(Ivy_Obj_t *pObj)
Definition: ivy.h:241
static Ivy_Obj_t * Ivy_ObjFanin0(Ivy_Obj_t *pObj)
Definition: ivy.h:271
static int Ivy_ObjIsBuf(Ivy_Obj_t *pObj)
Definition: ivy.h:244
void Ivy_ManMakeSeq ( Ivy_Man_t p,
int  nLatches,
int *  pInits 
)

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

Synopsis [Converts a combinational AIG manager into a sequential one.]

Description []

SideEffects []

SeeAlso []

Definition at line 482 of file ivyMan.c.

483 {
484  Ivy_Obj_t * pObj, * pLatch;
485  Ivy_Init_t Init;
486  int i;
487  if ( nLatches == 0 )
488  return;
489  assert( nLatches < Ivy_ManPiNum(p) && nLatches < Ivy_ManPoNum(p) );
490  assert( Ivy_ManPiNum(p) == Vec_PtrSize(p->vPis) );
491  assert( Ivy_ManPoNum(p) == Vec_PtrSize(p->vPos) );
492  assert( Vec_PtrSize( p->vBufs ) == 0 );
493  // create fanouts
494  if ( p->fFanout == 0 )
496  // collect the POs to be converted into latches
497  for ( i = 0; i < nLatches; i++ )
498  {
499  // get the latch value
500  Init = pInits? (Ivy_Init_t)pInits[i] : IVY_INIT_0;
501  // create latch
502  pObj = Ivy_ManPo( p, Ivy_ManPoNum(p) - nLatches + i );
503  pLatch = Ivy_Latch( p, Ivy_ObjChild0(pObj), Init );
504  Ivy_ObjDisconnect( p, pObj );
505  // recycle the old PO object
506  Vec_PtrWriteEntry( p->vObjs, pObj->Id, NULL );
507  Ivy_ManRecycleMemory( p, pObj );
508  // convert the corresponding PI to a buffer and connect it to the latch
509  pObj = Ivy_ManPi( p, Ivy_ManPiNum(p) - nLatches + i );
510  pObj->Type = IVY_BUF;
511  Ivy_ObjConnect( p, pObj, pLatch, NULL );
512  // save the buffer
513  Vec_PtrPush( p->vBufs, pObj );
514  }
515  // shrink the arrays
516  Vec_PtrShrink( p->vPis, Ivy_ManPiNum(p) - nLatches );
517  Vec_PtrShrink( p->vPos, Ivy_ManPoNum(p) - nLatches );
518  // update the counters of different objects
519  p->nObjs[IVY_PI] -= nLatches;
520  p->nObjs[IVY_PO] -= nLatches;
521  p->nObjs[IVY_BUF] += nLatches;
522  p->nDeleted -= 2 * nLatches;
523  // remove dangling nodes
524  Ivy_ManCleanup(p);
526 /*
527  // check for dangling nodes
528  Ivy_ManForEachObj( p, pObj, i )
529  if ( !Ivy_ObjIsPi(pObj) && !Ivy_ObjIsPo(pObj) && !Ivy_ObjIsConst1(pObj) )
530  {
531  assert( Ivy_ObjRefs(pObj) > 0 );
532  assert( Ivy_ObjRefs(pObj) == Ivy_ObjFanoutNum(p, pObj) );
533  }
534 */
535  // perform hashing by propagating the buffers
537  if ( Ivy_ManBufNum(p) )
538  printf( "The number of remaining buffers is %d.\n", Ivy_ManBufNum(p) );
539  // fix the levels
541  // check the resulting network
542  if ( !Ivy_ManCheck(p) )
543  printf( "Ivy_ManMakeSeq(): The check has failed.\n" );
544 }
Ivy_Obj_t * Ivy_Latch(Ivy_Man_t *p, Ivy_Obj_t *pObj, Ivy_Init_t Init)
Definition: ivyOper.c:287
Definition: ivy.h:55
static Ivy_Obj_t * Ivy_ManPi(Ivy_Man_t *p, int i)
Definition: ivy.h:201
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Ivy_ManBufNum(Ivy_Man_t *p)
Definition: ivy.h:224
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static int Ivy_ManPoNum(Ivy_Man_t *p)
Definition: ivy.h:219
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
void Ivy_ManResetLevels(Ivy_Man_t *p)
Definition: ivyUtil.c:292
void Ivy_ObjConnect(Ivy_Man_t *p, Ivy_Obj_t *pObj, Ivy_Obj_t *pFan0, Ivy_Obj_t *pFan1)
Definition: ivyObj.c:150
int Ivy_ManCleanupSeq(Ivy_Man_t *p)
Definition: ivyMan.c:311
Ivy_Init_t
Definition: ivy.h:65
Definition: ivy.h:60
Definition: ivy.h:73
static Ivy_Obj_t * Ivy_ObjChild0(Ivy_Obj_t *pObj)
Definition: ivy.h:273
int Ivy_ManPropagateBuffers(Ivy_Man_t *p, int fUpdateLevel)
Definition: ivyMan.c:414
void Ivy_ManStartFanout(Ivy_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition: ivyFanout.c:136
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
static int Ivy_ManPiNum(Ivy_Man_t *p)
Definition: ivy.h:218
void Ivy_ObjDisconnect(Ivy_Man_t *p, Ivy_Obj_t *pObj)
Definition: ivyObj.c:185
static void Ivy_ManRecycleMemory(Ivy_Man_t *p, Ivy_Obj_t *pEntry)
Definition: ivy.h:374
int Ivy_ManCleanup(Ivy_Man_t *p)
Definition: ivyMan.c:265
Definition: ivy.h:67
#define assert(ex)
Definition: util_old.h:213
static Ivy_Obj_t * Ivy_ManPo(Ivy_Man_t *p, int i)
Definition: ivy.h:202
static void Vec_PtrShrink(Vec_Ptr_t *p, int nSizeNew)
Definition: vecPtr.h:528
Definition: ivy.h:54
int Ivy_ManCheck(Ivy_Man_t *p)
DECLARATIONS ///.
Definition: ivyCheck.c:45
void Ivy_ManPrintStats ( Ivy_Man_t p)

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

Synopsis [Stops the AIG manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 456 of file ivyMan.c.

457 {
458  printf( "PI/PO = %d/%d ", Ivy_ManPiNum(p), Ivy_ManPoNum(p) );
459  printf( "A = %7d. ", Ivy_ManAndNum(p) );
460  printf( "L = %5d. ", Ivy_ManLatchNum(p) );
461 // printf( "X = %d. ", Ivy_ManExorNum(p) );
462 // printf( "B = %3d. ", Ivy_ManBufNum(p) );
463  printf( "MaxID = %7d. ", Ivy_ManObjIdMax(p) );
464 // printf( "Cre = %d. ", p->nCreated );
465 // printf( "Del = %d. ", p->nDeleted );
466  printf( "Lev = %3d. ", Ivy_ManLatchNum(p)? -1 : Ivy_ManLevels(p) );
467  printf( "\n" );
468  fflush( stdout );
469 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Ivy_ManLatchNum(Ivy_Man_t *p)
Definition: ivy.h:221
static int Ivy_ManPoNum(Ivy_Man_t *p)
Definition: ivy.h:219
int Ivy_ManLevels(Ivy_Man_t *p)
Definition: ivyUtil.c:249
static int Ivy_ManObjIdMax(Ivy_Man_t *p)
Definition: ivy.h:226
static int Ivy_ManPiNum(Ivy_Man_t *p)
Definition: ivy.h:218
static int Ivy_ManAndNum(Ivy_Man_t *p)
Definition: ivy.h:222
int Ivy_ManPropagateBuffers ( Ivy_Man_t p,
int  fUpdateLevel 
)

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

Synopsis [Returns the number of dangling nodes removed.]

Description []

SideEffects []

SeeAlso []

Definition at line 414 of file ivyMan.c.

415 {
416  Ivy_Obj_t * pNode;
417  int LimitFactor = 100;
418  int NodeBeg = Ivy_ManNodeNum(p);
419  int nSteps;
420  for ( nSteps = 0; Vec_PtrSize(p->vBufs) > 0; nSteps++ )
421  {
422  pNode = (Ivy_Obj_t *)Vec_PtrEntryLast(p->vBufs);
423  while ( Ivy_ObjIsBuf(pNode) )
424  pNode = Ivy_ObjReadFirstFanout( p, pNode );
425  // check if this buffer should remain
426  if ( Ivy_ManLatchIsSelfFeed(pNode) )
427  {
428  Vec_PtrPop(p->vBufs);
429  continue;
430  }
431 //printf( "Propagating buffer %d with input %d and output %d\n", Ivy_ObjFaninId0(pNode), Ivy_ObjFaninId0(Ivy_ObjFanin0(pNode)), pNode->Id );
432 //printf( "Latch num %d\n", Ivy_ManLatchNum(p) );
433  Ivy_NodeFixBufferFanins( p, pNode, fUpdateLevel );
434  if ( nSteps > NodeBeg * LimitFactor )
435  {
436  printf( "Structural hashing is not finished after %d forward latch moves.\n", NodeBeg * LimitFactor );
437  printf( "This circuit cannot be forward-retimed completely. Quitting.\n" );
438  break;
439  }
440  }
441 // printf( "Number of steps = %d. Nodes beg = %d. Nodes end = %d.\n", nSteps, NodeBeg, Ivy_ManNodeNum(p) );
442  return nSteps;
443 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static void * Vec_PtrPop(Vec_Ptr_t *p)
Definition: vecPtr.h:677
void Ivy_NodeFixBufferFanins(Ivy_Man_t *p, Ivy_Obj_t *pNode, int fUpdateLevel)
Definition: ivyObj.c:442
static void * Vec_PtrEntryLast(Vec_Ptr_t *p)
Definition: vecPtr.h:413
int Ivy_ManLatchIsSelfFeed(Ivy_Obj_t *pLatch)
Definition: ivyMan.c:395
Definition: ivy.h:73
static int Ivy_ObjIsBuf(Ivy_Obj_t *pObj)
Definition: ivy.h:244
static int Ivy_ManNodeNum(Ivy_Man_t *p)
Definition: ivy.h:227
Ivy_Obj_t * Ivy_ObjReadFirstFanout(Ivy_Man_t *p, Ivy_Obj_t *pObj)
Definition: ivyFanout.c:283

DECLARATIONS ///.

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

FileName [ivyMan.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [And-Inverter Graph package.]

Synopsis [AIG manager.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - May 11, 2006.]

Revision [

Id:
ivy_.c,v 1.00 2006/05/11 00:00:00 alanmi Exp

]FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis [Starts the AIG manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 45 of file ivyMan.c.

46 {
47  Ivy_Man_t * p;
48  // start the manager
49  p = ABC_ALLOC( Ivy_Man_t, 1 );
50  memset( p, 0, sizeof(Ivy_Man_t) );
51  // perform initializations
52  p->Ghost.Id = -1;
53  p->nTravIds = 1;
54  p->fCatchExor = 1;
55  // allocate arrays for nodes
56  p->vPis = Vec_PtrAlloc( 100 );
57  p->vPos = Vec_PtrAlloc( 100 );
58  p->vBufs = Vec_PtrAlloc( 100 );
59  p->vObjs = Vec_PtrAlloc( 100 );
60  // prepare the internal memory manager
61  Ivy_ManStartMemory( p );
62  // create the constant node
63  p->pConst1 = Ivy_ManFetchMemory( p );
64  p->pConst1->fPhase = 1;
65  Vec_PtrPush( p->vObjs, p->pConst1 );
66  p->nCreated = 1;
67  // start the table
68  p->nTableSize = 10007;
69  p->pTable = ABC_ALLOC( int, p->nTableSize );
70  memset( p->pTable, 0, sizeof(int) * p->nTableSize );
71  return p;
72 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
typedefABC_NAMESPACE_HEADER_START struct Ivy_Man_t_ Ivy_Man_t
INCLUDES ///.
Definition: ivy.h:46
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
static Ivy_Obj_t * Ivy_ManFetchMemory(Ivy_Man_t *p)
Definition: ivy.h:364
void Ivy_ManStartMemory(Ivy_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition: ivyMem.c:49
Ivy_Man_t* Ivy_ManStartFrom ( Ivy_Man_t p)

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

Synopsis [Duplicates the AIG manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 85 of file ivyMan.c.

86 {
87  Ivy_Man_t * pNew;
88  Ivy_Obj_t * pObj;
89  int i;
90  // create the new manager
91  pNew = Ivy_ManStart();
92  // create the PIs
94  Ivy_ManForEachPi( p, pObj, i )
95  pObj->pEquiv = Ivy_ObjCreatePi(pNew);
96  return pNew;
97 }
static Ivy_Obj_t * Ivy_ManConst1(Ivy_Man_t *p)
Definition: ivy.h:199
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define Ivy_ManForEachPi(p, pObj, i)
ITERATORS ///.
Definition: ivy.h:387
ABC_NAMESPACE_IMPL_START Ivy_Man_t * Ivy_ManStart()
DECLARATIONS ///.
Definition: ivyMan.c:45
Definition: ivy.h:73
typedefABC_NAMESPACE_HEADER_START struct Ivy_Man_t_ Ivy_Man_t
INCLUDES ///.
Definition: ivy.h:46
Ivy_Obj_t * Ivy_ObjCreatePi(Ivy_Man_t *p)
DECLARATIONS ///.
Definition: ivyObj.c:45
Ivy_Obj_t * pEquiv
Definition: ivy.h:93
void Ivy_ManStop ( Ivy_Man_t p)

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

Synopsis [Stops the AIG manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 238 of file ivyMan.c.

239 {
240  if ( p->time1 ) { ABC_PRT( "Update lev ", p->time1 ); }
241  if ( p->time2 ) { ABC_PRT( "Update levR ", p->time2 ); }
242 // Ivy_TableProfile( p );
243 // if ( p->vFanouts ) Ivy_ManStopFanout( p );
244  if ( p->vChunks ) Ivy_ManStopMemory( p );
245  if ( p->vRequired ) Vec_IntFree( p->vRequired );
246  if ( p->vPis ) Vec_PtrFree( p->vPis );
247  if ( p->vPos ) Vec_PtrFree( p->vPos );
248  if ( p->vBufs ) Vec_PtrFree( p->vBufs );
249  if ( p->vObjs ) Vec_PtrFree( p->vObjs );
250  ABC_FREE( p->pTable );
251  ABC_FREE( p );
252 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void Ivy_ManStopMemory(Ivy_Man_t *p)
Definition: ivyMem.c:66
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define ABC_PRT(a, t)
Definition: abc_global.h:220
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223