abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcFanio.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [abcFanio.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Network and node package.]
8 
9  Synopsis [Various procedures to connect fanins/fanouts.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: abcFanio.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "abc.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis []
37 
38  Description []
39 
40  SideEffects []
41 
42  SeeAlso []
43 
44 ***********************************************************************/
45 static 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 
73 /**Function*************************************************************
74 
75  Synopsis [Creates fanout/fanin relationship between the nodes.]
76 
77  Description []
78 
79  SideEffects []
80 
81  SeeAlso []
82 
83 ***********************************************************************/
84 void 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 
100 /**Function*************************************************************
101 
102  Synopsis [Destroys fanout/fanin relationship between the nodes.]
103 
104  Description []
105 
106  SideEffects []
107 
108  SeeAlso []
109 
110 ***********************************************************************/
111 void 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 
130 /**Function*************************************************************
131 
132  Synopsis [Destroys fanout/fanin relationship between the nodes.]
133 
134  Description []
135 
136  SideEffects []
137 
138  SeeAlso []
139 
140 ***********************************************************************/
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 
158 /**Function*************************************************************
159 
160  Synopsis [Replaces a fanin of the node.]
161 
162  Description [The node is pObj. An old fanin of this node (pFaninOld) has to be
163  replaced by a new fanin (pFaninNew). Assumes that the node and the old fanin
164  are not complemented. The new fanin can be complemented. In this case, the
165  polarity of the new fanin will change, compared to the polarity of the old fanin.]
166 
167  SideEffects []
168 
169  SeeAlso []
170 
171 ***********************************************************************/
172 void 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 
212 /**Function*************************************************************
213 
214  Synopsis [Inserts one-input node of the type specified between the nodes.]
215 
216  Description []
217 
218  SideEffects []
219 
220  SeeAlso []
221 
222 ***********************************************************************/
224 {
225  Abc_Obj_t * pNodeNew;
226  int iFanoutIndex, iFaninIndex;
227  // find pNodeOut among the fanouts of pNodeIn
228  if ( (iFanoutIndex = Vec_IntFind( &pNodeIn->vFanouts, pNodeOut->Id )) == -1 )
229  {
230  printf( "Node %s is not among", Abc_ObjName(pNodeOut) );
231  printf( " the fanouts of node %s...\n", Abc_ObjName(pNodeIn) );
232  return NULL;
233  }
234  // find pNodeIn among the fanins of pNodeOut
235  if ( (iFaninIndex = Vec_IntFind( &pNodeOut->vFanins, pNodeIn->Id )) == -1 )
236  {
237  printf( "Node %s is not among", Abc_ObjName(pNodeIn) );
238  printf( " the fanins of node %s...\n", Abc_ObjName(pNodeOut) );
239  return NULL;
240  }
241  // create the new node
242  pNodeNew = Abc_NtkCreateObj( pNodeIn->pNtk, Type );
243  // add pNodeIn as fanin and pNodeOut as fanout
244  Vec_IntPushMem( pNodeNew->pNtk->pMmStep, &pNodeNew->vFanins, pNodeIn->Id );
245  Vec_IntPushMem( pNodeNew->pNtk->pMmStep, &pNodeNew->vFanouts, pNodeOut->Id );
246  // update the fanout of pNodeIn
247  Vec_IntWriteEntry( &pNodeIn->vFanouts, iFanoutIndex, pNodeNew->Id );
248  // update the fanin of pNodeOut
249  Vec_IntWriteEntry( &pNodeOut->vFanins, iFaninIndex, pNodeNew->Id );
250  return pNodeNew;
251 }
252 
253 /**Function*************************************************************
254 
255  Synopsis [Transfers fanout from the old node to the new node.]
256 
257  Description []
258 
259  SideEffects []
260 
261  SeeAlso []
262 
263 ***********************************************************************/
264 void Abc_ObjTransferFanout( Abc_Obj_t * pNodeFrom, Abc_Obj_t * pNodeTo )
265 {
266  Vec_Ptr_t * vFanouts;
267  int nFanoutsOld, i;
268  assert( !Abc_ObjIsComplement(pNodeFrom) );
269  assert( !Abc_ObjIsComplement(pNodeTo) );
270  assert( !Abc_ObjIsPo(pNodeFrom) && !Abc_ObjIsPo(pNodeTo) );
271  assert( pNodeFrom->pNtk == pNodeTo->pNtk );
272  assert( pNodeFrom != pNodeTo );
273  assert( !Abc_ObjIsNode(pNodeFrom) || Abc_ObjFanoutNum(pNodeFrom) > 0 );
274  // get the fanouts of the old node
275  nFanoutsOld = Abc_ObjFanoutNum(pNodeTo);
276  vFanouts = Vec_PtrAlloc( nFanoutsOld );
277  Abc_NodeCollectFanouts( pNodeFrom, vFanouts );
278  // patch the fanin of each of them
279  for ( i = 0; i < vFanouts->nSize; i++ )
280  Abc_ObjPatchFanin( (Abc_Obj_t *)vFanouts->pArray[i], pNodeFrom, pNodeTo );
281  assert( Abc_ObjFanoutNum(pNodeFrom) == 0 );
282  assert( Abc_ObjFanoutNum(pNodeTo) == nFanoutsOld + vFanouts->nSize );
283  Vec_PtrFree( vFanouts );
284 }
285 
286 /**Function*************************************************************
287 
288  Synopsis [Replaces the node by a new node.]
289 
290  Description []
291 
292  SideEffects []
293 
294  SeeAlso []
295 
296 ***********************************************************************/
297 void Abc_ObjReplace( Abc_Obj_t * pNodeOld, Abc_Obj_t * pNodeNew )
298 {
299  assert( !Abc_ObjIsComplement(pNodeOld) );
300  assert( !Abc_ObjIsComplement(pNodeNew) );
301  assert( pNodeOld->pNtk == pNodeNew->pNtk );
302  assert( pNodeOld != pNodeNew );
303  assert( Abc_ObjFanoutNum(pNodeOld) > 0 );
304  // transfer the fanouts to the old node
305  Abc_ObjTransferFanout( pNodeOld, pNodeNew );
306  // remove the old node
307  Abc_NtkDeleteObj_rec( pNodeOld, 1 );
308 }
309 
310 /**Function*************************************************************
311 
312  Synopsis [Returns the index of the fanin in the fanin list of the fanout.]
313 
314  Description []
315 
316  SideEffects []
317 
318  SeeAlso []
319 
320 ***********************************************************************/
321 int Abc_ObjFanoutFaninNum( Abc_Obj_t * pFanout, Abc_Obj_t * pFanin )
322 {
323  Abc_Obj_t * pObj;
324  int i;
325  Abc_ObjForEachFanin( pFanout, pObj, i )
326  if ( pObj == pFanin )
327  return i;
328  return -1;
329 }
330 
331 
332 ////////////////////////////////////////////////////////////////////////
333 /// END OF FILE ///
334 ////////////////////////////////////////////////////////////////////////
335 
336 
338 
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition: abcFanio.c:84
unsigned fCompl0
Definition: abc.h:140
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Abc_Obj_t * Abc_ObjInsertBetween(Abc_Obj_t *pNodeIn, Abc_Obj_t *pNodeOut, Abc_ObjType_t Type)
Definition: abcFanio.c:223
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static int Abc_ObjFanoutNum(Abc_Obj_t *pObj)
Definition: abc.h:365
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
void Abc_ObjDeleteFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition: abcFanio.c:111
static int Abc_ObjIsPi(Abc_Obj_t *pObj)
Definition: abc.h:347
static int Vec_IntFind(Vec_Int_t *p, int Entry)
Definition: vecInt.h:895
ABC_DLL void Abc_NtkDeleteObj_rec(Abc_Obj_t *pObj, int fOnlyNodes)
Definition: abcObj.c:273
Vec_Int_t vFanins
Definition: abc.h:143
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
void Abc_ObjPatchFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFaninOld, Abc_Obj_t *pFaninNew)
Definition: abcFanio.c:172
ABC_DLL Abc_Obj_t * Abc_NtkCreateObj(Abc_Ntk_t *pNtk, Abc_ObjType_t Type)
Definition: abcObj.c:106
static Abc_Obj_t * Abc_NtkObj(Abc_Ntk_t *pNtk, int i)
Definition: abc.h:314
unsigned fCompl1
Definition: abc.h:141
static int Abc_ObjIsCo(Abc_Obj_t *pObj)
Definition: abc.h:352
void Mem_StepEntryRecycle(Mem_Step_t *p, char *pEntry, int nBytes)
Definition: mem.c:570
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
static void Abc_ObjSetFaninC(Abc_Obj_t *pObj, int i)
Definition: abc.h:380
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
if(last==0)
Definition: sparse_int.h:34
Abc_ObjType_t
Definition: abc.h:86
char * Mem_StepEntryFetch(Mem_Step_t *p, int nBytes)
Definition: mem.c:537
int Abc_ObjFanoutFaninNum(Abc_Obj_t *pFanout, Abc_Obj_t *pFanin)
Definition: abcFanio.c:321
static int Vec_IntRemove(Vec_Int_t *p, int Entry)
Definition: vecInt.h:915
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
Vec_Int_t vFanouts
Definition: abc.h:144
void Abc_ObjReplace(Abc_Obj_t *pNodeOld, Abc_Obj_t *pNodeNew)
Definition: abcFanio.c:297
static Abc_Obj_t * Abc_ObjRegular(Abc_Obj_t *p)
Definition: abc.h:323
Abc_Ntk_t * pNtk
Definition: abc.h:130
void Abc_ObjRemoveFanins(Abc_Obj_t *pObj)
Definition: abcFanio.c:141
void Abc_ObjTransferFanout(Abc_Obj_t *pNodeFrom, Abc_Obj_t *pNodeTo)
Definition: abcFanio.c:264
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition: abc.h:524
#define ABC_FREE(obj)
Definition: abc_global.h:232
int Id
Definition: abc.h:132
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
static int Abc_ObjIsNet(Abc_Obj_t *pObj)
Definition: abc.h:354
static void Abc_ObjXorFaninC(Abc_Obj_t *pObj, int i)
Definition: abc.h:381
Mem_Step_t * pMmStep
Definition: abc.h:190
static int Abc_ObjIsPo(Abc_Obj_t *pObj)
Definition: abc.h:348
#define assert(ex)
Definition: util_old.h:213
ABC_DLL void Abc_NodeCollectFanouts(Abc_Obj_t *pNode, Vec_Ptr_t *vNodes)
Definition: abcUtil.c:1607
static int Abc_ObjIsComplement(Abc_Obj_t *p)
Definition: abc.h:322
static ABC_NAMESPACE_IMPL_START void Vec_IntPushMem(Mem_Step_t *pMemMan, Vec_Int_t *p, int Entry)
DECLARATIONS ///.
Definition: abcFanio.c:45
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223