src/aig/ivy/ivyObj.c File Reference

#include "ivy.h"
Include dependency graph for ivyObj.c:

Go to the source code of this file.

Functions

Ivy_Obj_tIvy_ObjCreatePi (Ivy_Man_t *p)
Ivy_Obj_tIvy_ObjCreatePo (Ivy_Man_t *p, Ivy_Obj_t *pDriver)
Ivy_Obj_tIvy_ObjCreate (Ivy_Man_t *p, Ivy_Obj_t *pGhost)
void Ivy_ObjConnect (Ivy_Man_t *p, Ivy_Obj_t *pObj, Ivy_Obj_t *pFan0, Ivy_Obj_t *pFan1)
void Ivy_ObjDisconnect (Ivy_Man_t *p, Ivy_Obj_t *pObj)
void Ivy_ObjPatchFanin0 (Ivy_Man_t *p, Ivy_Obj_t *pObj, Ivy_Obj_t *pFaninNew)
void Ivy_ObjDelete (Ivy_Man_t *p, Ivy_Obj_t *pObj, int fFreeTop)
void Ivy_ObjDelete_rec (Ivy_Man_t *p, Ivy_Obj_t *pObj, int fFreeTop)
void Ivy_ObjReplace (Ivy_Man_t *p, Ivy_Obj_t *pObjOld, Ivy_Obj_t *pObjNew, int fDeleteOld, int fFreeTop, int fUpdateLevel)
void Ivy_NodeFixBufferFanins (Ivy_Man_t *p, Ivy_Obj_t *pNode, int fUpdateLevel)

Function Documentation

void Ivy_NodeFixBufferFanins ( Ivy_Man_t p,
Ivy_Obj_t pNode,
int  fUpdateLevel 
)

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

Synopsis [Fixes buffer fanins.]

Description [This situation happens because NodeReplace is a lazy procedure, which does not propagate the change to the fanouts but instead records the change in the form of a buf/inv node.]

SideEffects []

SeeAlso []

Definition at line 439 of file ivyObj.c.

00440 {
00441     Ivy_Obj_t * pFanReal0, * pFanReal1, * pResult;
00442     if ( Ivy_ObjIsPo(pNode) )
00443     {
00444         if ( !Ivy_ObjIsBuf(Ivy_ObjFanin0(pNode)) )
00445             return;
00446         pFanReal0 = Ivy_ObjReal( Ivy_ObjChild0(pNode) );
00447         Ivy_ObjPatchFanin0( p, pNode, pFanReal0 );
00448 //        Ivy_ManCheckFanouts( p );
00449         return;
00450     }
00451     if ( !Ivy_ObjIsBuf(Ivy_ObjFanin0(pNode)) && !Ivy_ObjIsBuf(Ivy_ObjFanin1(pNode)) )
00452         return;
00453     // get the real fanins
00454     pFanReal0 = Ivy_ObjReal( Ivy_ObjChild0(pNode) );
00455     pFanReal1 = Ivy_ObjReal( Ivy_ObjChild1(pNode) );
00456     // get the new node
00457     if ( Ivy_ObjIsNode(pNode) )
00458         pResult = Ivy_Oper( p, pFanReal0, pFanReal1, Ivy_ObjType(pNode) );
00459     else if ( Ivy_ObjIsLatch(pNode) )
00460         pResult = Ivy_Latch( p, pFanReal0, Ivy_ObjInit(pNode) );
00461     else 
00462         assert( 0 );
00463 
00464 //printf( "===== Replacing %d by %d.\n", pNode->Id, pResult->Id );
00465 //Ivy_ObjPrintVerbose( p, pNode, 0 );   printf( "\n" );
00466 //Ivy_ObjPrintVerbose( p, pResult, 0 ); printf( "\n" );
00467 
00468     // perform the replacement
00469     Ivy_ObjReplace( p, pNode, pResult, 1, 0, fUpdateLevel ); 
00470 }

void Ivy_ObjConnect ( Ivy_Man_t p,
Ivy_Obj_t pObj,
Ivy_Obj_t pFan0,
Ivy_Obj_t pFan1 
)

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

Synopsis [Connect the object to the fanin.]

Description []

SideEffects []

SeeAlso []

Definition at line 147 of file ivyObj.c.

00148 {
00149     assert( !Ivy_IsComplement(pObj) );
00150     assert( Ivy_ObjIsPi(pObj) || Ivy_ObjIsOneFanin(pObj) || pFan1 != NULL );
00151     // add the first fanin
00152     pObj->pFanin0 = pFan0;
00153     pObj->pFanin1 = pFan1;
00154     // increment references of the fanins and add their fanouts
00155     if ( Ivy_ObjFanin0(pObj) != NULL )
00156     {
00157         Ivy_ObjRefsInc( Ivy_ObjFanin0(pObj) );
00158         if ( p->fFanout )
00159             Ivy_ObjAddFanout( p, Ivy_ObjFanin0(pObj), pObj );
00160     }
00161     if ( Ivy_ObjFanin1(pObj) != NULL )
00162     {
00163         Ivy_ObjRefsInc( Ivy_ObjFanin1(pObj) );
00164         if ( p->fFanout )
00165             Ivy_ObjAddFanout( p, Ivy_ObjFanin1(pObj), pObj );
00166     }
00167     // add the node to the structural hash table
00168     Ivy_TableInsert( p, pObj );
00169 }

Ivy_Obj_t* Ivy_ObjCreate ( Ivy_Man_t p,
Ivy_Obj_t pGhost 
)

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

Synopsis [Create the new node assuming it does not exist.]

Description []

SideEffects []

SeeAlso []

Definition at line 74 of file ivyObj.c.

00075 {
00076     Ivy_Obj_t * pObj;
00077     assert( !Ivy_IsComplement(pGhost) );
00078     assert( Ivy_ObjIsGhost(pGhost) );
00079     assert( Ivy_TableLookup(p, pGhost) == NULL );
00080     // get memory for the new object
00081     pObj = Ivy_ManFetchMemory( p );
00082     assert( Ivy_ObjIsNone(pObj) );
00083     pObj->Id = Vec_PtrSize(p->vObjs);
00084     Vec_PtrPush( p->vObjs, pObj );
00085     // add basic info (fanins, compls, type, init)
00086     pObj->Type = pGhost->Type;
00087     pObj->Init = pGhost->Init;
00088     // add connections
00089     Ivy_ObjConnect( p, pObj, pGhost->pFanin0, pGhost->pFanin1 );
00090     // compute level
00091     if ( Ivy_ObjIsNode(pObj) )
00092         pObj->Level = Ivy_ObjLevelNew(pObj);
00093     else if ( Ivy_ObjIsLatch(pObj) )
00094         pObj->Level = 0;
00095     else if ( Ivy_ObjIsOneFanin(pObj) )
00096         pObj->Level = Ivy_ObjFanin0(pObj)->Level;
00097     else if ( !Ivy_ObjIsPi(pObj) )
00098         assert( 0 );
00099     // create phase
00100     if ( Ivy_ObjIsNode(pObj) )
00101         pObj->fPhase = Ivy_ObjFaninPhase(Ivy_ObjChild0(pObj)) & Ivy_ObjFaninPhase(Ivy_ObjChild1(pObj));
00102     else if ( Ivy_ObjIsOneFanin(pObj) )
00103         pObj->fPhase = Ivy_ObjFaninPhase(Ivy_ObjChild0(pObj));
00104     // set the fail TFO flag
00105     if ( Ivy_ObjIsNode(pObj) )
00106         pObj->fFailTfo = Ivy_ObjFanin0(pObj)->fFailTfo | Ivy_ObjFanin1(pObj)->fFailTfo;
00107     // mark the fanins in a special way if the node is EXOR
00108     if ( Ivy_ObjIsExor(pObj) )
00109     {
00110         Ivy_ObjFanin0(pObj)->fExFan = 1;
00111         Ivy_ObjFanin1(pObj)->fExFan = 1;
00112     }
00113     // add PIs/POs to the arrays
00114     if ( Ivy_ObjIsPi(pObj) )
00115         Vec_PtrPush( p->vPis, pObj );
00116     else if ( Ivy_ObjIsPo(pObj) )
00117         Vec_PtrPush( p->vPos, pObj );
00118 //    else if ( Ivy_ObjIsBuf(pObj) )
00119 //        Vec_PtrPush( p->vBufs, pObj );
00120     if ( p->vRequired && Vec_IntSize(p->vRequired) <= pObj->Id )
00121         Vec_IntFillExtra( p->vRequired, 2 * Vec_IntSize(p->vRequired), 1000000 );
00122     // update node counters of the manager
00123     p->nObjs[Ivy_ObjType(pObj)]++;
00124     p->nCreated++;
00125 
00126 //    printf( "Adding %sAIG node: ", p->pHaig==NULL? "H":" " );
00127 //    Ivy_ObjPrintVerbose( p, pObj, p->pHaig==NULL );
00128 //    printf( "\n" );
00129 
00130     // if HAIG is defined, create a corresponding node
00131     if ( p->pHaig )
00132         Ivy_ManHaigCreateObj( p, pObj );
00133     return pObj;
00134 }

Ivy_Obj_t* Ivy_ObjCreatePi ( Ivy_Man_t p  ) 

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

FileName [ivyObj.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [And-Inverter Graph package.]

Synopsis [Adding/removing objects.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

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

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

Synopsis [Create the new node assuming it does not exist.]

Description []

SideEffects []

SeeAlso []

Definition at line 42 of file ivyObj.c.

00043 {
00044     return Ivy_ObjCreate( p, Ivy_ObjCreateGhost(p, NULL, NULL, IVY_PI, IVY_INIT_NONE) );
00045 }

Ivy_Obj_t* Ivy_ObjCreatePo ( Ivy_Man_t p,
Ivy_Obj_t pDriver 
)

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

Synopsis [Create the new node assuming it does not exist.]

Description []

SideEffects []

SeeAlso []

Definition at line 58 of file ivyObj.c.

00059 {
00060     return Ivy_ObjCreate( p, Ivy_ObjCreateGhost(p, pDriver, NULL, IVY_PO, IVY_INIT_NONE) );
00061 }

void Ivy_ObjDelete ( Ivy_Man_t p,
Ivy_Obj_t pObj,
int  fFreeTop 
)

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

Synopsis [Deletes the node.]

Description []

SideEffects []

SeeAlso []

Definition at line 252 of file ivyObj.c.

00253 {
00254     assert( !Ivy_IsComplement(pObj) );
00255     assert( Ivy_ObjRefs(pObj) == 0 || !fFreeTop );
00256     // update node counters of the manager
00257     p->nObjs[pObj->Type]--;
00258     p->nDeleted++;
00259     // remove connections
00260     Ivy_ObjDisconnect( p, pObj );
00261     // remove PIs/POs from the arrays
00262     if ( Ivy_ObjIsPi(pObj) )
00263         Vec_PtrRemove( p->vPis, pObj );
00264     else if ( Ivy_ObjIsPo(pObj) )
00265         Vec_PtrRemove( p->vPos, pObj );
00266     else if ( p->fFanout && Ivy_ObjIsBuf(pObj) )
00267         Vec_PtrRemove( p->vBufs, pObj );
00268     // clean and recycle the entry
00269     if ( fFreeTop )
00270     {
00271         // free the node
00272         Vec_PtrWriteEntry( p->vObjs, pObj->Id, NULL );
00273         Ivy_ManRecycleMemory( p, pObj );
00274     }
00275     else
00276     {
00277         int nRefsOld = pObj->nRefs;
00278         Ivy_Obj_t * pFanout = pObj->pFanout;
00279         Ivy_ObjClean( pObj );
00280         pObj->pFanout = pFanout;
00281         pObj->nRefs = nRefsOld;
00282     }
00283 }

void Ivy_ObjDelete_rec ( Ivy_Man_t p,
Ivy_Obj_t pObj,
int  fFreeTop 
)

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

Synopsis [Deletes the MFFC of the node.]

Description []

SideEffects []

SeeAlso []

Definition at line 296 of file ivyObj.c.

00297 {
00298     Ivy_Obj_t * pFanin0, * pFanin1;
00299     assert( !Ivy_IsComplement(pObj) );
00300     assert( !Ivy_ObjIsNone(pObj) );
00301     if ( Ivy_ObjIsConst1(pObj) || Ivy_ObjIsPi(pObj) )
00302         return;
00303     pFanin0 = Ivy_ObjFanin0(pObj);
00304     pFanin1 = Ivy_ObjFanin1(pObj);
00305     Ivy_ObjDelete( p, pObj, fFreeTop );
00306     if ( pFanin0 && !Ivy_ObjIsNone(pFanin0) && Ivy_ObjRefs(pFanin0) == 0 )
00307         Ivy_ObjDelete_rec( p, pFanin0, 1 );
00308     if ( pFanin1 && !Ivy_ObjIsNone(pFanin1) && Ivy_ObjRefs(pFanin1) == 0 )
00309         Ivy_ObjDelete_rec( p, pFanin1, 1 );
00310 }

void Ivy_ObjDisconnect ( Ivy_Man_t p,
Ivy_Obj_t pObj 
)

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

Synopsis [Connect the object to the fanin.]

Description []

SideEffects []

SeeAlso []

Definition at line 182 of file ivyObj.c.

00183 {
00184     assert( !Ivy_IsComplement(pObj) );
00185     assert( Ivy_ObjIsPi(pObj) || Ivy_ObjIsOneFanin(pObj) || Ivy_ObjFanin1(pObj) != NULL );
00186     // remove connections
00187     if ( pObj->pFanin0 != NULL )
00188     {
00189         Ivy_ObjRefsDec(Ivy_ObjFanin0(pObj));
00190         if ( p->fFanout )
00191             Ivy_ObjDeleteFanout( p, Ivy_ObjFanin0(pObj), pObj );
00192     }
00193     if ( pObj->pFanin1 != NULL )
00194     {
00195         Ivy_ObjRefsDec(Ivy_ObjFanin1(pObj));
00196         if ( p->fFanout )
00197             Ivy_ObjDeleteFanout( p, Ivy_ObjFanin1(pObj), pObj );
00198     }
00199     assert( pObj->pNextFan0 == NULL );
00200     assert( pObj->pNextFan1 == NULL );
00201     assert( pObj->pPrevFan0 == NULL );
00202     assert( pObj->pPrevFan1 == NULL );
00203     // remove the node from the structural hash table
00204     Ivy_TableDelete( p, pObj );
00205     // add the first fanin
00206     pObj->pFanin0 = NULL;
00207     pObj->pFanin1 = NULL;
00208 }

void Ivy_ObjPatchFanin0 ( Ivy_Man_t p,
Ivy_Obj_t pObj,
Ivy_Obj_t pFaninNew 
)

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

Synopsis [Replaces the first fanin of the node by the new fanin.]

Description []

SideEffects []

SeeAlso []

Definition at line 221 of file ivyObj.c.

00222 {
00223     Ivy_Obj_t * pFaninOld;
00224     assert( !Ivy_IsComplement(pObj) );
00225     pFaninOld = Ivy_ObjFanin0(pObj);
00226     // decrement ref and remove fanout
00227     Ivy_ObjRefsDec( pFaninOld );
00228     if ( p->fFanout )
00229         Ivy_ObjDeleteFanout( p, pFaninOld, pObj );
00230     // update the fanin
00231     pObj->pFanin0 = pFaninNew;
00232     // increment ref and add fanout
00233     Ivy_ObjRefsInc( Ivy_Regular(pFaninNew) );
00234     if ( p->fFanout )
00235         Ivy_ObjAddFanout( p, Ivy_Regular(pFaninNew), pObj );
00236     // get rid of old fanin
00237     if ( !Ivy_ObjIsPi(pFaninOld) && !Ivy_ObjIsConst1(pFaninOld) && Ivy_ObjRefs(pFaninOld) == 0 )
00238         Ivy_ObjDelete_rec( p, pFaninOld, 1 );
00239 }

void Ivy_ObjReplace ( Ivy_Man_t p,
Ivy_Obj_t pObjOld,
Ivy_Obj_t pObjNew,
int  fDeleteOld,
int  fFreeTop,
int  fUpdateLevel 
)

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

Synopsis [Replaces one object by another.]

Description [Both objects are currently in the manager. The new object (pObjNew) should be used instead of the old object (pObjOld). If the new object is complemented or used, the buffer is added.]

SideEffects []

SeeAlso []

Definition at line 325 of file ivyObj.c.

00326 {
00327     int nRefsOld;//, clk;
00328     // the object to be replaced cannot be complemented
00329     assert( !Ivy_IsComplement(pObjOld) );
00330     // the object to be replaced cannot be a terminal
00331     assert( Ivy_ObjIsNone(pObjOld) || !Ivy_ObjIsPi(pObjOld) );
00332     // the object to be used cannot be a PO or assert
00333     assert( !Ivy_ObjIsBuf(Ivy_Regular(pObjNew)) );
00334     // the object cannot be the same
00335     assert( pObjOld != Ivy_Regular(pObjNew) );
00336 //printf( "Replacing %d by %d.\n", Ivy_Regular(pObjOld)->Id, Ivy_Regular(pObjNew)->Id );
00337 
00338     // if HAIG is defined, create the choice node
00339     if ( p->pHaig )
00340     {
00341 //        if ( pObjOld->Id == 31 )
00342 //        {
00343 //            Ivy_ManShow( p, 0 );
00344 //            Ivy_ManShow( p->pHaig, 1 );
00345 //        }
00346         Ivy_ManHaigCreateChoice( p, pObjOld, pObjNew );
00347     }
00348     // if the new object is complemented or already used, add the buffer
00349     if ( Ivy_IsComplement(pObjNew) || Ivy_ObjIsLatch(pObjNew) || Ivy_ObjRefs(pObjNew) > 0 || Ivy_ObjIsPi(pObjNew) || Ivy_ObjIsConst1(pObjNew) )
00350         pObjNew = Ivy_ObjCreate( p, Ivy_ObjCreateGhost(p, pObjNew, NULL, IVY_BUF, IVY_INIT_NONE) );
00351     assert( !Ivy_IsComplement(pObjNew) );
00352     if ( fUpdateLevel )
00353     {
00354 //clk = clock();
00355         // if the new node's arrival time is different, recursively update arrival time of the fanouts
00356         if ( p->fFanout && !Ivy_ObjIsBuf(pObjNew) && pObjOld->Level != pObjNew->Level )
00357         {
00358             assert( Ivy_ObjIsNode(pObjOld) );
00359             pObjOld->Level = pObjNew->Level;
00360             Ivy_ObjUpdateLevel_rec( p, pObjOld );
00361         }
00362 //p->time1 += clock() - clk;
00363         // if the new node's required time has changed, recursively update required time of the fanins
00364 //clk = clock();
00365         if ( p->vRequired )
00366         {
00367             int ReqNew = Vec_IntEntry(p->vRequired, pObjOld->Id);
00368             if ( ReqNew < Vec_IntEntry(p->vRequired, pObjNew->Id) )
00369             {
00370                 Vec_IntWriteEntry( p->vRequired, pObjNew->Id, ReqNew );
00371                 Ivy_ObjUpdateLevelR_rec( p, pObjNew, ReqNew );
00372             }
00373         }
00374 //p->time2 += clock() - clk;
00375     }
00376     // delete the old object
00377     if ( fDeleteOld )
00378         Ivy_ObjDelete_rec( p, pObjOld, fFreeTop );
00379     // make sure object is not pointing to itself
00380     assert( Ivy_ObjFanin0(pObjNew) == NULL || pObjOld != Ivy_ObjFanin0(pObjNew) );
00381     assert( Ivy_ObjFanin1(pObjNew) == NULL || pObjOld != Ivy_ObjFanin1(pObjNew) );
00382     // make sure the old node has no fanin fanout pointers
00383     if ( p->fFanout )
00384     {
00385         assert( pObjOld->pFanout != NULL );
00386         assert( pObjNew->pFanout == NULL );
00387         pObjNew->pFanout = pObjOld->pFanout;
00388     }
00389     // transfer the old object
00390     assert( Ivy_ObjRefs(pObjNew) == 0 );
00391     nRefsOld = pObjOld->nRefs;  
00392     Ivy_ObjOverwrite( pObjOld, pObjNew );
00393     pObjOld->nRefs = nRefsOld;
00394     // patch the fanout of the fanins 
00395     if ( p->fFanout )
00396     {
00397         Ivy_ObjPatchFanout( p, Ivy_ObjFanin0(pObjOld), pObjNew, pObjOld );
00398         if ( Ivy_ObjFanin1(pObjOld) )
00399         Ivy_ObjPatchFanout( p, Ivy_ObjFanin1(pObjOld), pObjNew, pObjOld );
00400     }
00401     // update the hash table
00402     Ivy_TableUpdate( p, pObjNew, pObjOld->Id );
00403     // recycle the object that was taken over by pObjOld
00404     Vec_PtrWriteEntry( p->vObjs, pObjNew->Id, NULL );
00405     Ivy_ManRecycleMemory( p, pObjNew );
00406     // if the new node is the buffer propagate it
00407     if ( p->fFanout && Ivy_ObjIsBuf(pObjOld) )
00408         Vec_PtrPush( p->vBufs, pObjOld );
00409 //    Ivy_ManCheckFanouts( p );
00410 //    printf( "\n" );
00411 /*
00412     if ( p->pHaig )
00413     {
00414         int x;
00415         Ivy_ManShow( p, 0, NULL );
00416         Ivy_ManShow( p->pHaig, 1, NULL );
00417         x = 0;
00418     }
00419 */
00420 //    if ( Ivy_ManCheckFanoutNums(p) )
00421 //    {
00422 //        int x = 0;
00423 //    }
00424 }


Generated on Tue Jan 5 12:18:25 2010 for abc70930 by  doxygen 1.6.1