ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
abcFanio.c
Go to the documentation of this file.
1
20
21#include "abc.h"
22
24
25
29
33
45static inline void Vec_IntPushMem( Mem_Step_t * pMemMan, Vec_Int_t * p, int Entry )
46{
47 if ( p->nSize == p->nCap )
48 {
49 int * pArray;
50 int i;
51
52 if ( p->nSize == 0 )
53 p->nCap = 1;
54 if ( pMemMan )
55 pArray = (int *)Mem_StepEntryFetch( pMemMan, p->nCap * 8 );
56 else
57 pArray = ABC_ALLOC( int, p->nCap * 2 );
58 if ( p->pArray )
59 {
60 for ( i = 0; i < p->nSize; i++ )
61 pArray[i] = p->pArray[i];
62 if ( pMemMan )
63 Mem_StepEntryRecycle( pMemMan, (char *)p->pArray, p->nCap * 4 );
64 else
65 ABC_FREE( p->pArray );
66 }
67 p->nCap *= 2;
68 p->pArray = pArray;
69 }
70 p->pArray[p->nSize++] = Entry;
71}
72
84void Abc_ObjAddFanin( Abc_Obj_t * pObj, Abc_Obj_t * pFanin )
85{
86 Abc_Obj_t * pFaninR = Abc_ObjRegular(pFanin);
87 assert( !Abc_ObjIsComplement(pObj) );
88 assert( pObj->pNtk == pFaninR->pNtk );
89 assert( pObj->Id >= 0 && pFaninR->Id >= 0 );
90 assert( !Abc_ObjIsPi(pObj) && !Abc_ObjIsPo(pFaninR) ); // fanin of PI or fanout of PO
91 assert( !Abc_ObjIsCo(pObj) || !Abc_ObjFaninNum(pObj) ); // CO with two fanins
92 assert( !Abc_ObjIsNet(pObj) || !Abc_ObjFaninNum(pObj) ); // net with two fanins
93 Vec_IntPushMem( pObj->pNtk->pMmStep, &pObj->vFanins, pFaninR->Id );
94 Vec_IntPushMem( pObj->pNtk->pMmStep, &pFaninR->vFanouts, pObj->Id );
95 if ( Abc_ObjIsComplement(pFanin) )
96 Abc_ObjSetFaninC( pObj, Abc_ObjFaninNum(pObj)-1 );
97}
98
99
111void Abc_ObjDeleteFanin( Abc_Obj_t * pObj, Abc_Obj_t * pFanin )
112{
113 assert( !Abc_ObjIsComplement(pObj) );
114 assert( !Abc_ObjIsComplement(pFanin) );
115 assert( pObj->pNtk == pFanin->pNtk );
116 assert( pObj->Id >= 0 && pFanin->Id >= 0 );
117 if ( !Vec_IntRemove( &pObj->vFanins, pFanin->Id ) )
118 {
119 printf( "The obj %d is not found among the fanins of obj %d ...\n", pFanin->Id, pObj->Id );
120 return;
121 }
122 if ( !Vec_IntRemove( &pFanin->vFanouts, pObj->Id ) )
123 {
124 printf( "The obj %d is not found among the fanouts of obj %d ...\n", pObj->Id, pFanin->Id );
125 return;
126 }
127}
128
129
142{
143 Vec_Int_t * vFaninsOld;
144 Abc_Obj_t * pFanin;
145 int k;
146 // remove old fanins
147 vFaninsOld = &pObj->vFanins;
148 for ( k = vFaninsOld->nSize - 1; k >= 0; k-- )
149 {
150 pFanin = Abc_NtkObj( pObj->pNtk, vFaninsOld->pArray[k] );
151 Abc_ObjDeleteFanin( pObj, pFanin );
152 }
153 pObj->fCompl0 = 0;
154 pObj->fCompl1 = 0;
155 assert( vFaninsOld->nSize == 0 );
156}
157
172void Abc_ObjPatchFanin( Abc_Obj_t * pObj, Abc_Obj_t * pFaninOld, Abc_Obj_t * pFaninNew )
173{
174 Abc_Obj_t * pFaninNewR = Abc_ObjRegular(pFaninNew);
175 int iFanin;//, nLats;//, fCompl;
176 assert( !Abc_ObjIsComplement(pObj) );
177 assert( !Abc_ObjIsComplement(pFaninOld) );
178 assert( pFaninOld != pFaninNewR );
179// assert( pObj != pFaninOld );
180// assert( pObj != pFaninNewR );
181 assert( pObj->pNtk == pFaninOld->pNtk );
182 assert( pObj->pNtk == pFaninNewR->pNtk );
183 if ( (iFanin = Vec_IntFind( &pObj->vFanins, pFaninOld->Id )) == -1 )
184 {
185 printf( "Node %s is not among", Abc_ObjName(pFaninOld) );
186 printf( " the fanins of node %s...\n", Abc_ObjName(pObj) );
187 return;
188 }
189
190 // remember the attributes of the old fanin
191// fCompl = Abc_ObjFaninC(pObj, iFanin);
192 // replace the old fanin entry by the new fanin entry (removes attributes)
193 Vec_IntWriteEntry( &pObj->vFanins, iFanin, pFaninNewR->Id );
194 // set the attributes of the new fanin
195// if ( fCompl ^ Abc_ObjIsComplement(pFaninNew) )
196// Abc_ObjSetFaninC( pObj, iFanin );
197 if ( Abc_ObjIsComplement(pFaninNew) )
198 Abc_ObjXorFaninC( pObj, iFanin );
199
200// if ( Abc_NtkIsSeq(pObj->pNtk) && (nLats = Seq_ObjFaninL(pObj, iFanin)) )
201// Seq_ObjSetFaninL( pObj, iFanin, nLats );
202 // update the fanout of the fanin
203 if ( !Vec_IntRemove( &pFaninOld->vFanouts, pObj->Id ) )
204 {
205 printf( "Node %s is not among", Abc_ObjName(pObj) );
206 printf( " the fanouts of its old fanin %s...\n", Abc_ObjName(pFaninOld) );
207// return;
208 }
209 Vec_IntPushMem( pObj->pNtk->pMmStep, &pFaninNewR->vFanouts, pObj->Id );
210}
211
223void Abc_ObjPatchFanoutFanin( Abc_Obj_t * pObj, int iObjNew )
224{
225 Abc_Obj_t * pFanout;
226 int i, k, Entry;
227 // update fanouts of the node to point to this one
228 Abc_ObjForEachFanout( pObj, pFanout, i )
229 {
230 Vec_IntForEachEntry( &pFanout->vFanins, Entry, k )
231 if ( Entry == (int)Abc_ObjId(pObj) )
232 {
233 Vec_IntWriteEntry( &pFanout->vFanins, k, iObjNew );
234 break;
235 }
236 assert( k < Vec_IntSize(&pFanout->vFanins) );
237 }
238}
239
252{
253 Abc_Obj_t * pNodeNew;
254 int iFanoutIndex, iFaninIndex;
255 // find pNodeOut among the fanouts of pNodeIn
256 if ( (iFanoutIndex = Vec_IntFind( &pNodeIn->vFanouts, pNodeOut->Id )) == -1 )
257 {
258 printf( "Node %s is not among", Abc_ObjName(pNodeOut) );
259 printf( " the fanouts of node %s...\n", Abc_ObjName(pNodeIn) );
260 return NULL;
261 }
262 // find pNodeIn among the fanins of pNodeOut
263 if ( (iFaninIndex = Vec_IntFind( &pNodeOut->vFanins, pNodeIn->Id )) == -1 )
264 {
265 printf( "Node %s is not among", Abc_ObjName(pNodeIn) );
266 printf( " the fanins of node %s...\n", Abc_ObjName(pNodeOut) );
267 return NULL;
268 }
269 // create the new node
270 pNodeNew = Abc_NtkCreateObj( pNodeIn->pNtk, Type );
271 // add pNodeIn as fanin and pNodeOut as fanout
272 Vec_IntPushMem( pNodeNew->pNtk->pMmStep, &pNodeNew->vFanins, pNodeIn->Id );
273 Vec_IntPushMem( pNodeNew->pNtk->pMmStep, &pNodeNew->vFanouts, pNodeOut->Id );
274 // update the fanout of pNodeIn
275 Vec_IntWriteEntry( &pNodeIn->vFanouts, iFanoutIndex, pNodeNew->Id );
276 // update the fanin of pNodeOut
277 Vec_IntWriteEntry( &pNodeOut->vFanins, iFaninIndex, pNodeNew->Id );
278 return pNodeNew;
279}
280
292void Abc_ObjTransferFanout( Abc_Obj_t * pNodeFrom, Abc_Obj_t * pNodeTo )
293{
294 Vec_Ptr_t * vFanouts;
295 int nFanoutsOld, i;
296 assert( !Abc_ObjIsComplement(pNodeFrom) );
297 assert( !Abc_ObjIsComplement(pNodeTo) );
298 assert( !Abc_ObjIsPo(pNodeFrom) && !Abc_ObjIsPo(pNodeTo) );
299 assert( pNodeFrom->pNtk == pNodeTo->pNtk );
300 assert( pNodeFrom != pNodeTo );
301 assert( !Abc_ObjIsNode(pNodeFrom) || Abc_ObjFanoutNum(pNodeFrom) > 0 );
302 // get the fanouts of the old node
303 nFanoutsOld = Abc_ObjFanoutNum(pNodeTo);
304 vFanouts = Vec_PtrAlloc( nFanoutsOld );
305 Abc_NodeCollectFanouts( pNodeFrom, vFanouts );
306 // patch the fanin of each of them
307 for ( i = 0; i < vFanouts->nSize; i++ )
308 Abc_ObjPatchFanin( (Abc_Obj_t *)vFanouts->pArray[i], pNodeFrom, pNodeTo );
309 assert( Abc_ObjFanoutNum(pNodeFrom) == 0 );
310 assert( Abc_ObjFanoutNum(pNodeTo) == nFanoutsOld + vFanouts->nSize );
311 Vec_PtrFree( vFanouts );
312}
313
325void Abc_ObjReplace( Abc_Obj_t * pNodeOld, Abc_Obj_t * pNodeNew )
326{
327 assert( !Abc_ObjIsComplement(pNodeOld) );
328 assert( !Abc_ObjIsComplement(pNodeNew) );
329 assert( pNodeOld->pNtk == pNodeNew->pNtk );
330 assert( pNodeOld != pNodeNew );
331 assert( Abc_ObjFanoutNum(pNodeOld) > 0 );
332 // transfer the fanouts to the old node
333 Abc_ObjTransferFanout( pNodeOld, pNodeNew );
334 // remove the old node
335 Abc_NtkDeleteObj_rec( pNodeOld, 1 );
336}
337
349void Abc_ObjReplaceByConstant( Abc_Obj_t * pNode, int fConst1 )
350{
351 Abc_Obj_t * pNodeNew;
352 assert( Abc_NtkIsLogic(pNode->pNtk) );
353 assert( !Abc_ObjIsCo(pNode) );
354 pNodeNew = fConst1 ? Abc_NtkCreateNodeConst1(pNode->pNtk) : Abc_NtkCreateNodeConst0(pNode->pNtk);
355 // transfer the fanouts to the old node
356 Abc_ObjTransferFanout( pNode, pNodeNew );
357 // remove the old node
358 if ( Abc_ObjIsNode(pNode) )
359 Abc_NtkDeleteObj_rec( pNode, 1 );
360}
361
373int Abc_ObjFanoutFaninNum( Abc_Obj_t * pFanout, Abc_Obj_t * pFanin )
374{
375 Abc_Obj_t * pObj;
376 int i;
377 Abc_ObjForEachFanin( pFanout, pObj, i )
378 if ( pObj == pFanin )
379 return i;
380 return -1;
381}
382
383
387
388
390
void Abc_ObjTransferFanout(Abc_Obj_t *pNodeFrom, Abc_Obj_t *pNodeTo)
Definition abcFanio.c:292
void Abc_ObjRemoveFanins(Abc_Obj_t *pObj)
Definition abcFanio.c:141
void Abc_ObjPatchFanoutFanin(Abc_Obj_t *pObj, int iObjNew)
Definition abcFanio.c:223
void Abc_ObjDeleteFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition abcFanio.c:111
void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition abcFanio.c:84
void Abc_ObjPatchFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFaninOld, Abc_Obj_t *pFaninNew)
Definition abcFanio.c:172
int Abc_ObjFanoutFaninNum(Abc_Obj_t *pFanout, Abc_Obj_t *pFanin)
Definition abcFanio.c:373
Abc_Obj_t * Abc_ObjInsertBetween(Abc_Obj_t *pNodeIn, Abc_Obj_t *pNodeOut, Abc_ObjType_t Type)
Definition abcFanio.c:251
void Abc_ObjReplaceByConstant(Abc_Obj_t *pNode, int fConst1)
Definition abcFanio.c:349
void Abc_ObjReplace(Abc_Obj_t *pNodeOld, Abc_Obj_t *pNodeNew)
Definition abcFanio.c:325
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst1(Abc_Ntk_t *pNtk)
Definition abcObj.c:643
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst0(Abc_Ntk_t *pNtk)
Definition abcObj.c:612
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition abc.h:527
#define Abc_ObjForEachFanout(pObj, pFanout, i)
Definition abc.h:529
Abc_ObjType_t
Definition abc.h:86
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition abcNames.c:49
ABC_DLL void Abc_NtkDeleteObj_rec(Abc_Obj_t *pObj, int fOnlyNodes)
Definition abcObj.c:278
ABC_DLL void Abc_NodeCollectFanouts(Abc_Obj_t *pNode, Vec_Ptr_t *vNodes)
Definition abcUtil.c:1647
ABC_DLL Abc_Obj_t * Abc_NtkCreateObj(Abc_Ntk_t *pNtk, Abc_ObjType_t Type)
Definition abcObj.c:109
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Cube * p
Definition exorList.c:222
char * Mem_StepEntryFetch(Mem_Step_t *p, int nBytes)
Definition mem.c:553
void Mem_StepEntryRecycle(Mem_Step_t *p, char *pEntry, int nBytes)
Definition mem.c:586
struct Mem_Step_t_ Mem_Step_t
Definition mem.h:35
Mem_Step_t * pMmStep
Definition abc.h:190
Vec_Int_t vFanins
Definition abc.h:143
Abc_Ntk_t * pNtk
Definition abc.h:130
int Id
Definition abc.h:132
Vec_Int_t vFanouts
Definition abc.h:144
unsigned fCompl1
Definition abc.h:141
unsigned fCompl0
Definition abc.h:140
#define assert(ex)
Definition util_old.h:213
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42