ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
aigObj.c
Go to the documentation of this file.
1
20
21#include "aig.h"
22
24
25
29
33
46{
47 Aig_Obj_t * pObj;
48 pObj = Aig_ManFetchMemory( p );
49 pObj->Type = AIG_OBJ_CI;
50 Vec_PtrPush( p->vCis, pObj );
51 p->nObjs[AIG_OBJ_CI]++;
52 return pObj;
53}
54
67{
68 Aig_Obj_t * pObj;
69 pObj = Aig_ManFetchMemory( p );
70 pObj->Type = AIG_OBJ_CO;
71 Vec_PtrPush( p->vCos, pObj );
72 Aig_ObjConnect( p, pObj, pDriver, NULL );
73 p->nObjs[AIG_OBJ_CO]++;
74 return pObj;
75}
76
77
90{
91 Aig_Obj_t * pObj;
92 assert( !Aig_IsComplement(pGhost) );
93 assert( Aig_ObjIsHash(pGhost) );
94// assert( pGhost == &p->Ghost );
95 // get memory for the new object
96 pObj = Aig_ManFetchMemory( p );
97 pObj->Type = pGhost->Type;
98 // add connections
99 Aig_ObjConnect( p, pObj, pGhost->pFanin0, pGhost->pFanin1 );
100 // update node counters of the manager
101 p->nObjs[Aig_ObjType(pObj)]++;
102 assert( pObj->pData == NULL );
103 // create the power counter
104 if ( p->vProbs )
105 {
106 float Prob0 = Abc_Int2Float( Vec_IntEntry( p->vProbs, Aig_ObjFaninId0(pObj) ) );
107 float Prob1 = Abc_Int2Float( Vec_IntEntry( p->vProbs, Aig_ObjFaninId1(pObj) ) );
108 Prob0 = Aig_ObjFaninC0(pObj)? 1.0 - Prob0 : Prob0;
109 Prob1 = Aig_ObjFaninC1(pObj)? 1.0 - Prob1 : Prob1;
110 Vec_IntSetEntry( p->vProbs, pObj->Id, Abc_Float2Int(Prob0 * Prob1) );
111 }
112 return pObj;
113}
114
126void Aig_ObjConnect( Aig_Man_t * p, Aig_Obj_t * pObj, Aig_Obj_t * pFan0, Aig_Obj_t * pFan1 )
127{
128 assert( !Aig_IsComplement(pObj) );
129 assert( !Aig_ObjIsCi(pObj) );
130 // add the first fanin
131 pObj->pFanin0 = pFan0;
132 pObj->pFanin1 = pFan1;
133 // increment references of the fanins and add their fanouts
134 if ( pFan0 != NULL )
135 {
136 assert( Aig_ObjFanin0(pObj)->Type > 0 );
137 Aig_ObjRef( Aig_ObjFanin0(pObj) );
138 if ( p->pFanData )
139 Aig_ObjAddFanout( p, Aig_ObjFanin0(pObj), pObj );
140 }
141 if ( pFan1 != NULL )
142 {
143 assert( Aig_ObjFanin1(pObj)->Type > 0 );
144 Aig_ObjRef( Aig_ObjFanin1(pObj) );
145 if ( p->pFanData )
146 Aig_ObjAddFanout( p, Aig_ObjFanin1(pObj), pObj );
147 }
148 // set level and phase
149 pObj->Level = Aig_ObjLevelNew( pObj );
150 pObj->fPhase = Aig_ObjPhaseReal(pFan0) & Aig_ObjPhaseReal(pFan1);
151 // add the node to the structural hash table
152 if ( p->pTable && Aig_ObjIsHash(pObj) )
153 Aig_TableInsert( p, pObj );
154 // add the node to the dynamically updated topological order
155// if ( p->pOrderData && Aig_ObjIsNode(pObj) )
156// Aig_ObjOrderInsert( p, pObj->Id );
157 assert( !Aig_ObjIsNode(pObj) || pObj->Level > 0 );
158}
159
172{
173 assert( !Aig_IsComplement(pObj) );
174 // remove connections
175 if ( pObj->pFanin0 != NULL )
176 {
177 if ( p->pFanData )
178 Aig_ObjRemoveFanout( p, Aig_ObjFanin0(pObj), pObj );
179 Aig_ObjDeref(Aig_ObjFanin0(pObj));
180 }
181 if ( pObj->pFanin1 != NULL )
182 {
183 if ( p->pFanData )
184 Aig_ObjRemoveFanout( p, Aig_ObjFanin1(pObj), pObj );
185 Aig_ObjDeref(Aig_ObjFanin1(pObj));
186 }
187 // remove the node from the structural hash table
188 if ( p->pTable && Aig_ObjIsHash(pObj) )
189 Aig_TableDelete( p, pObj );
190 // add the first fanin
191 pObj->pFanin0 = NULL;
192 pObj->pFanin1 = NULL;
193 // remove the node from the dynamically updated topological order
194// if ( p->pOrderData && Aig_ObjIsNode(pObj) )
195// Aig_ObjOrderRemove( p, pObj->Id );
196}
197
210{
211 assert( !Aig_IsComplement(pObj) );
212 assert( !Aig_ObjIsTerm(pObj) );
213 assert( Aig_ObjRefs(pObj) == 0 );
214 if ( p->pFanData && Aig_ObjIsBuf(pObj) )
215 Vec_PtrRemove( p->vBufs, pObj );
216 p->nObjs[pObj->Type]--;
217 Vec_PtrWriteEntry( p->vObjs, pObj->Id, NULL );
218 Aig_ManRecycleMemory( p, pObj );
219}
220
232void Aig_ObjDelete_rec( Aig_Man_t * p, Aig_Obj_t * pObj, int fFreeTop )
233{
234 Aig_Obj_t * pFanin0, * pFanin1;
235 assert( !Aig_IsComplement(pObj) );
236 if ( Aig_ObjIsConst1(pObj) || Aig_ObjIsCi(pObj) )
237 return;
238 assert( !Aig_ObjIsCo(pObj) );
239 pFanin0 = Aig_ObjFanin0(pObj);
240 pFanin1 = Aig_ObjFanin1(pObj);
241 Aig_ObjDisconnect( p, pObj );
242 if ( fFreeTop )
243 Aig_ObjDelete( p, pObj );
244 if ( pFanin0 && !Aig_ObjIsNone(pFanin0) && Aig_ObjRefs(pFanin0) == 0 )
245 Aig_ObjDelete_rec( p, pFanin0, 1 );
246 if ( pFanin1 && !Aig_ObjIsNone(pFanin1) && Aig_ObjRefs(pFanin1) == 0 )
247 Aig_ObjDelete_rec( p, pFanin1, 1 );
248}
249
262{
263 assert( Aig_ObjIsCo(pObj) );
264 Aig_ObjDeref(Aig_ObjFanin0(pObj));
265 pObj->pFanin0 = NULL;
266 p->nObjs[pObj->Type]--;
267 Vec_PtrWriteEntry( p->vObjs, pObj->Id, NULL );
268 Aig_ManRecycleMemory( p, pObj );
269}
270
282void Aig_ObjPatchFanin0( Aig_Man_t * p, Aig_Obj_t * pObj, Aig_Obj_t * pFaninNew )
283{
284 Aig_Obj_t * pFaninOld;
285 assert( !Aig_IsComplement(pObj) );
286 assert( Aig_ObjIsCo(pObj) );
287 pFaninOld = Aig_ObjFanin0(pObj);
288 // decrement ref and remove fanout
289 if ( p->pFanData )
290 Aig_ObjRemoveFanout( p, pFaninOld, pObj );
291 Aig_ObjDeref( pFaninOld );
292 // update the fanin
293 pObj->pFanin0 = pFaninNew;
294 pObj->Level = Aig_ObjLevelNew( pObj );
295 pObj->fPhase = Aig_ObjPhaseReal(pObj->pFanin0);
296 // increment ref and add fanout
297 if ( p->pFanData )
298 Aig_ObjAddFanout( p, Aig_ObjFanin0(pObj), pObj );
299 Aig_ObjRef( Aig_ObjFanin0(pObj) );
300 // get rid of old fanin
301 if ( !Aig_ObjIsCi(pFaninOld) && !Aig_ObjIsConst1(pFaninOld) && Aig_ObjRefs(pFaninOld) == 0 )
302 Aig_ObjDelete_rec( p, pFaninOld, 1 );
303}
304
317{
318 int fShowFanouts = 0;
319 Aig_Obj_t * pTemp;
320 if ( pObj == NULL )
321 {
322 printf( "Object is NULL." );
323 return;
324 }
325 if ( Aig_IsComplement(pObj) )
326 {
327 printf( "Compl " );
328 pObj = Aig_Not(pObj);
329 }
330 assert( !Aig_IsComplement(pObj) );
331 printf( "Node %4d : ", Aig_ObjId(pObj) );
332 if ( Aig_ObjIsConst1(pObj) )
333 printf( "constant 1" );
334 else if ( Aig_ObjIsCi(pObj) )
335 printf( "PI" );
336 else if ( Aig_ObjIsCo(pObj) )
337 printf( "PO( %4d%s )", Aig_ObjFanin0(pObj)->Id, (Aig_ObjFaninC0(pObj)? "\'" : " ") );
338 else if ( Aig_ObjIsBuf(pObj) )
339 printf( "BUF( %d%s )", Aig_ObjFanin0(pObj)->Id, (Aig_ObjFaninC0(pObj)? "\'" : " ") );
340 else
341 printf( "AND( %4d%s, %4d%s )",
342 Aig_ObjFanin0(pObj)->Id, (Aig_ObjFaninC0(pObj)? "\'" : " "),
343 Aig_ObjFanin1(pObj)->Id, (Aig_ObjFaninC1(pObj)? "\'" : " ") );
344 printf( " (refs = %3d)", Aig_ObjRefs(pObj) );
345 if ( fShowFanouts && p->pFanData )
346 {
347 Aig_Obj_t * pFanout;
348 int i;
349 int iFan = -1; // Suppress "might be used uninitialized"
350 printf( "\nFanouts:\n" );
351 Aig_ObjForEachFanout( p, pObj, pFanout, iFan, i )
352 {
353 printf( " " );
354 printf( "Node %4d : ", Aig_ObjId(pFanout) );
355 if ( Aig_ObjIsCo(pFanout) )
356 printf( "PO( %4d%s )", Aig_ObjFanin0(pFanout)->Id, (Aig_ObjFaninC0(pFanout)? "\'" : " ") );
357 else if ( Aig_ObjIsBuf(pFanout) )
358 printf( "BUF( %d%s )", Aig_ObjFanin0(pFanout)->Id, (Aig_ObjFaninC0(pFanout)? "\'" : " ") );
359 else
360 printf( "AND( %4d%s, %4d%s )",
361 Aig_ObjFanin0(pFanout)->Id, (Aig_ObjFaninC0(pFanout)? "\'" : " "),
362 Aig_ObjFanin1(pFanout)->Id, (Aig_ObjFaninC1(pFanout)? "\'" : " ") );
363 printf( "\n" );
364 }
365 return;
366 }
367 // there are choices
368 if ( p->pEquivs && p->pEquivs[pObj->Id] )
369 {
370 // print equivalence class
371 printf( " { %4d ", pObj->Id );
372 for ( pTemp = p->pEquivs[pObj->Id]; pTemp; pTemp = p->pEquivs[pTemp->Id] )
373 printf( " %4d%s", pTemp->Id, (pTemp->fPhase != pObj->fPhase)? "\'" : " " );
374 printf( " }" );
375 return;
376 }
377 // this is a secondary node
378 if ( p->pReprs && p->pReprs[pObj->Id] )
379 printf( " class of %d", pObj->Id );
380}
381
393void Aig_NodeFixBufferFanins( Aig_Man_t * p, Aig_Obj_t * pObj, int fUpdateLevel )
394{
395 Aig_Obj_t * pFanReal0, * pFanReal1, * pResult = NULL;
396 p->nBufFixes++;
397 if ( Aig_ObjIsCo(pObj) )
398 {
399 assert( Aig_ObjIsBuf(Aig_ObjFanin0(pObj)) );
400 pFanReal0 = Aig_ObjReal_rec( Aig_ObjChild0(pObj) );
401 assert( Aig_ObjPhaseReal(Aig_ObjChild0(pObj)) == Aig_ObjPhaseReal(pFanReal0) );
402 Aig_ObjPatchFanin0( p, pObj, pFanReal0 );
403 return;
404 }
405 assert( Aig_ObjIsNode(pObj) );
406 assert( Aig_ObjIsBuf(Aig_ObjFanin0(pObj)) || Aig_ObjIsBuf(Aig_ObjFanin1(pObj)) );
407 // get the real fanins
408 pFanReal0 = Aig_ObjReal_rec( Aig_ObjChild0(pObj) );
409 pFanReal1 = Aig_ObjReal_rec( Aig_ObjChild1(pObj) );
410 // get the new node
411 if ( Aig_ObjIsNode(pObj) )
412 pResult = Aig_Oper( p, pFanReal0, pFanReal1, Aig_ObjType(pObj) );
413// else if ( Aig_ObjIsLatch(pObj) )
414// pResult = Aig_Latch( p, pFanReal0, Aig_ObjInit(pObj) );
415 else
416 assert( 0 );
417 // replace the node with buffer by the node without buffer
418 Aig_ObjReplace( p, pObj, pResult, fUpdateLevel );
419}
420
432int Aig_ManPropagateBuffers( Aig_Man_t * p, int fUpdateLevel )
433{
434 Aig_Obj_t * pObj;
435 int nSteps;
436 assert( p->pFanData );
437 for ( nSteps = 0; Vec_PtrSize(p->vBufs) > 0; nSteps++ )
438 {
439 // get the node with a buffer fanin
440 for ( pObj = (Aig_Obj_t *)Vec_PtrEntryLast(p->vBufs); Aig_ObjIsBuf(pObj); pObj = Aig_ObjFanout0(p, pObj) );
441 // replace this node by a node without buffer
442 Aig_NodeFixBufferFanins( p, pObj, fUpdateLevel );
443 // stop if a cycle occured
444 if ( nSteps > 1000000 )
445 {
446 printf( "Error: A cycle is encountered while propagating buffers.\n" );
447 break;
448 }
449 }
450 return nSteps;
451}
452
467void Aig_ObjReplace( Aig_Man_t * p, Aig_Obj_t * pObjOld, Aig_Obj_t * pObjNew, int fUpdateLevel )
468{
469 Aig_Obj_t * pObjNewR = Aig_Regular(pObjNew);
470 // the object to be replaced cannot be complemented
471 assert( !Aig_IsComplement(pObjOld) );
472 // the object to be replaced cannot be a terminal
473 assert( !Aig_ObjIsCi(pObjOld) && !Aig_ObjIsCo(pObjOld) );
474 // the object to be used cannot be a buffer or a PO
475 assert( !Aig_ObjIsBuf(pObjNewR) && !Aig_ObjIsCo(pObjNewR) );
476 // the object cannot be the same
477 assert( pObjOld != pObjNewR );
478 // make sure object is not pointing to itself
479 assert( pObjOld != Aig_ObjFanin0(pObjNewR) );
480 assert( pObjOld != Aig_ObjFanin1(pObjNewR) );
481 if ( pObjOld == Aig_ObjFanin0(pObjNewR) || pObjOld == Aig_ObjFanin1(pObjNewR) )
482 {
483 printf( "Aig_ObjReplace(): Internal error!\n" );
484 exit(1);
485 }
486 // recursively delete the old node - but leave the object there
487 pObjNewR->nRefs++;
488 Aig_ObjDelete_rec( p, pObjOld, 0 );
489 pObjNewR->nRefs--;
490 // if the new object is complemented or already used, create a buffer
491 p->nObjs[pObjOld->Type]--;
492 if ( Aig_IsComplement(pObjNew) || Aig_ObjRefs(pObjNew) > 0 || !Aig_ObjIsNode(pObjNew) )
493 {
494 pObjOld->Type = AIG_OBJ_BUF;
495 Aig_ObjConnect( p, pObjOld, pObjNew, NULL );
496 p->nBufReplaces++;
497 }
498 else
499 {
500 Aig_Obj_t * pFanin0 = pObjNew->pFanin0;
501 Aig_Obj_t * pFanin1 = pObjNew->pFanin1;
502 int LevelOld = pObjOld->Level;
503 pObjOld->Type = pObjNew->Type;
504 Aig_ObjDisconnect( p, pObjNew );
505 Aig_ObjConnect( p, pObjOld, pFanin0, pFanin1 );
506 // delete the new object
507 Aig_ObjDelete( p, pObjNew );
508 // update levels
509 if ( p->pFanData )
510 {
511 pObjOld->Level = LevelOld;
512 Aig_ManUpdateLevel( p, pObjOld );
513 }
514 if ( fUpdateLevel )
515 {
516 Aig_ObjClearReverseLevel( p, pObjOld );
517 Aig_ManUpdateReverseLevel( p, pObjOld );
518 }
519 }
520 p->nObjs[pObjOld->Type]++;
521 // store buffers if fanout is allocated
522 if ( p->pFanData && Aig_ObjIsBuf(pObjOld) )
523 {
524 Vec_PtrPush( p->vBufs, pObjOld );
525 p->nBufMax = Abc_MaxInt( p->nBufMax, Vec_PtrSize(p->vBufs) );
526 Aig_ManPropagateBuffers( p, fUpdateLevel );
527 }
528}
529
533
534
536
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
Aig_Obj_t * Aig_ObjCreate(Aig_Man_t *p, Aig_Obj_t *pGhost)
Definition aigObj.c:89
void Aig_ObjDeletePo(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition aigObj.c:261
void Aig_ObjDisconnect(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition aigObj.c:171
void Aig_ObjConnect(Aig_Man_t *p, Aig_Obj_t *pObj, Aig_Obj_t *pFan0, Aig_Obj_t *pFan1)
Definition aigObj.c:126
Aig_Obj_t * Aig_ObjCreateCo(Aig_Man_t *p, Aig_Obj_t *pDriver)
Definition aigObj.c:66
void Aig_NodeFixBufferFanins(Aig_Man_t *p, Aig_Obj_t *pObj, int fUpdateLevel)
Definition aigObj.c:393
void Aig_ObjDelete_rec(Aig_Man_t *p, Aig_Obj_t *pObj, int fFreeTop)
Definition aigObj.c:232
ABC_NAMESPACE_IMPL_START Aig_Obj_t * Aig_ObjCreateCi(Aig_Man_t *p)
DECLARATIONS ///.
Definition aigObj.c:45
void Aig_ObjPatchFanin0(Aig_Man_t *p, Aig_Obj_t *pObj, Aig_Obj_t *pFaninNew)
Definition aigObj.c:282
void Aig_ObjReplace(Aig_Man_t *p, Aig_Obj_t *pObjOld, Aig_Obj_t *pObjNew, int fUpdateLevel)
Definition aigObj.c:467
void Aig_ObjDelete(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition aigObj.c:209
int Aig_ManPropagateBuffers(Aig_Man_t *p, int fUpdateLevel)
Definition aigObj.c:432
void Aig_ObjPrint(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition aigObj.c:316
#define Aig_ObjForEachFanout(p, pObj, pFanout, iFan, i)
Definition aig.h:427
Aig_Obj_t * Aig_Oper(Aig_Man_t *p, Aig_Obj_t *p0, Aig_Obj_t *p1, Aig_Type_t Type)
Definition aigOper.c:83
struct Aig_Obj_t_ Aig_Obj_t
Definition aig.h:51
void Aig_TableInsert(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition aigTable.c:173
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition aig.h:50
void Aig_ObjClearReverseLevel(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition aigTiming.c:83
void Aig_ObjAddFanout(Aig_Man_t *p, Aig_Obj_t *pObj, Aig_Obj_t *pFanout)
Definition aigFanout.c:107
Aig_Obj_t * Aig_ObjReal_rec(Aig_Obj_t *pObj)
Definition aigUtil.c:476
@ AIG_OBJ_CO
Definition aig.h:61
@ AIG_OBJ_CI
Definition aig.h:60
@ AIG_OBJ_BUF
Definition aig.h:62
void Aig_ManUpdateReverseLevel(Aig_Man_t *p, Aig_Obj_t *pObjNew)
Definition aigTiming.c:247
void Aig_ManUpdateLevel(Aig_Man_t *p, Aig_Obj_t *pObjNew)
Definition aigTiming.c:195
void Aig_ObjRemoveFanout(Aig_Man_t *p, Aig_Obj_t *pObj, Aig_Obj_t *pFanout)
Definition aigFanout.c:154
void Aig_TableDelete(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition aigTable.c:196
Cube * p
Definition exorList.c:222
int Id
Definition aig.h:85
unsigned int nRefs
Definition aig.h:81
void * pData
Definition aig.h:87
Aig_Obj_t * pFanin1
Definition aig.h:76
Aig_Obj_t * pFanin0
Definition aig.h:75
unsigned Level
Definition aig.h:82
unsigned int fPhase
Definition aig.h:78
unsigned int Type
Definition aig.h:77
#define assert(ex)
Definition util_old.h:213
VOID_HACK exit()