abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ivyFanout.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [ivyFanout.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [And-Inverter Graph package.]
8 
9  Synopsis [Representation of the fanouts.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - May 11, 2006.]
16 
17  Revision [$Id: ivyFanout.c,v 1.00 2006/05/11 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "ivy.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 // getting hold of the next fanout of the node
31 static inline Ivy_Obj_t * Ivy_ObjNextFanout( Ivy_Obj_t * pObj, Ivy_Obj_t * pFanout )
32 {
33  assert( !Ivy_IsComplement(pObj) );
34  assert( !Ivy_IsComplement(pFanout) );
35  if ( pFanout == NULL )
36  return NULL;
37  if ( Ivy_ObjFanin0(pFanout) == pObj )
38  return pFanout->pNextFan0;
39  assert( Ivy_ObjFanin1(pFanout) == pObj );
40  return pFanout->pNextFan1;
41 }
42 
43 // getting hold of the previous fanout of the node
44 static inline Ivy_Obj_t * Ivy_ObjPrevFanout( Ivy_Obj_t * pObj, Ivy_Obj_t * pFanout )
45 {
46  assert( !Ivy_IsComplement(pObj) );
47  assert( !Ivy_IsComplement(pFanout) );
48  if ( pFanout == NULL )
49  return NULL;
50  if ( Ivy_ObjFanin0(pFanout) == pObj )
51  return pFanout->pPrevFan0;
52  assert( Ivy_ObjFanin1(pFanout) == pObj );
53  return pFanout->pPrevFan1;
54 }
55 
56 // getting hold of the place where the next fanout will be attached
57 static inline Ivy_Obj_t ** Ivy_ObjNextFanoutPlace( Ivy_Obj_t * pObj, Ivy_Obj_t * pFanout )
58 {
59  assert( !Ivy_IsComplement(pObj) );
60  assert( !Ivy_IsComplement(pFanout) );
61  if ( Ivy_ObjFanin0(pFanout) == pObj )
62  return &pFanout->pNextFan0;
63  assert( Ivy_ObjFanin1(pFanout) == pObj );
64  return &pFanout->pNextFan1;
65 }
66 
67 // getting hold of the place where the next fanout will be attached
68 static inline Ivy_Obj_t ** Ivy_ObjPrevFanoutPlace( Ivy_Obj_t * pObj, Ivy_Obj_t * pFanout )
69 {
70  assert( !Ivy_IsComplement(pObj) );
71  assert( !Ivy_IsComplement(pFanout) );
72  if ( Ivy_ObjFanin0(pFanout) == pObj )
73  return &pFanout->pPrevFan0;
74  assert( Ivy_ObjFanin1(pFanout) == pObj );
75  return &pFanout->pPrevFan1;
76 }
77 
78 // getting hold of the place where the next fanout will be attached
79 static inline Ivy_Obj_t ** Ivy_ObjPrevNextFanoutPlace( Ivy_Obj_t * pObj, Ivy_Obj_t * pFanout )
80 {
81  Ivy_Obj_t * pTemp;
82  assert( !Ivy_IsComplement(pObj) );
83  assert( !Ivy_IsComplement(pFanout) );
84  pTemp = Ivy_ObjPrevFanout(pObj, pFanout);
85  if ( pTemp == NULL )
86  return &pObj->pFanout;
87  if ( Ivy_ObjFanin0(pTemp) == pObj )
88  return &pTemp->pNextFan0;
89  assert( Ivy_ObjFanin1(pTemp) == pObj );
90  return &pTemp->pNextFan1;
91 }
92 
93 // getting hold of the place where the next fanout will be attached
94 static inline Ivy_Obj_t ** Ivy_ObjNextPrevFanoutPlace( Ivy_Obj_t * pObj, Ivy_Obj_t * pFanout )
95 {
96  Ivy_Obj_t * pTemp;
97  assert( !Ivy_IsComplement(pObj) );
98  assert( !Ivy_IsComplement(pFanout) );
99  pTemp = Ivy_ObjNextFanout(pObj, pFanout);
100  if ( pTemp == NULL )
101  return NULL;
102  if ( Ivy_ObjFanin0(pTemp) == pObj )
103  return &pTemp->pPrevFan0;
104  assert( Ivy_ObjFanin1(pTemp) == pObj );
105  return &pTemp->pPrevFan1;
106 }
107 
108 // iterator through the fanouts of the node
109 #define Ivy_ObjForEachFanoutInt( pObj, pFanout ) \
110  for ( pFanout = (pObj)->pFanout; pFanout; \
111  pFanout = Ivy_ObjNextFanout(pObj, pFanout) )
112 
113 // safe iterator through the fanouts of the node
114 #define Ivy_ObjForEachFanoutIntSafe( pObj, pFanout, pFanout2 ) \
115  for ( pFanout = (pObj)->pFanout, \
116  pFanout2 = Ivy_ObjNextFanout(pObj, pFanout); \
117  pFanout; \
118  pFanout = pFanout2, \
119  pFanout2 = Ivy_ObjNextFanout(pObj, pFanout) )
120 
121 ////////////////////////////////////////////////////////////////////////
122 /// FUNCTION DEFINITIONS ///
123 ////////////////////////////////////////////////////////////////////////
124 
125 /**Function*************************************************************
126 
127  Synopsis [Starts the fanout representation.]
128 
129  Description []
130 
131  SideEffects []
132 
133  SeeAlso []
134 
135 ***********************************************************************/
137 {
138  Ivy_Obj_t * pObj;
139  int i;
140  assert( !p->fFanout );
141  p->fFanout = 1;
142  Ivy_ManForEachObj( p, pObj, i )
143  {
144  if ( Ivy_ObjFanin0(pObj) )
145  Ivy_ObjAddFanout( p, Ivy_ObjFanin0(pObj), pObj );
146  if ( Ivy_ObjFanin1(pObj) )
147  Ivy_ObjAddFanout( p, Ivy_ObjFanin1(pObj), pObj );
148  }
149 }
150 
151 /**Function*************************************************************
152 
153  Synopsis [Stops the fanout representation.]
154 
155  Description []
156 
157  SideEffects []
158 
159  SeeAlso []
160 
161 ***********************************************************************/
163 {
164  Ivy_Obj_t * pObj;
165  int i;
166  assert( p->fFanout );
167  p->fFanout = 0;
168  Ivy_ManForEachObj( p, pObj, i )
169  pObj->pFanout = pObj->pNextFan0 = pObj->pNextFan1 = pObj->pPrevFan0 = pObj->pPrevFan1 = NULL;
170 }
171 
172 /**Function*************************************************************
173 
174  Synopsis [Add the fanout.]
175 
176  Description []
177 
178  SideEffects []
179 
180  SeeAlso []
181 
182 ***********************************************************************/
183 void Ivy_ObjAddFanout( Ivy_Man_t * p, Ivy_Obj_t * pFanin, Ivy_Obj_t * pFanout )
184 {
185  assert( p->fFanout );
186  if ( pFanin->pFanout )
187  {
188  *Ivy_ObjNextFanoutPlace(pFanin, pFanout) = pFanin->pFanout;
189  *Ivy_ObjPrevFanoutPlace(pFanin, pFanin->pFanout) = pFanout;
190  }
191  pFanin->pFanout = pFanout;
192 }
193 
194 /**Function*************************************************************
195 
196  Synopsis [Removes the fanout.]
197 
198  Description []
199 
200  SideEffects []
201 
202  SeeAlso []
203 
204 ***********************************************************************/
205 void Ivy_ObjDeleteFanout( Ivy_Man_t * p, Ivy_Obj_t * pFanin, Ivy_Obj_t * pFanout )
206 {
207  Ivy_Obj_t ** ppPlace1, ** ppPlace2, ** ppPlaceN;
208  assert( pFanin->pFanout != NULL );
209 
210  ppPlace1 = Ivy_ObjNextFanoutPlace(pFanin, pFanout);
211  ppPlaceN = Ivy_ObjPrevNextFanoutPlace(pFanin, pFanout);
212  assert( *ppPlaceN == pFanout );
213  if ( ppPlaceN )
214  *ppPlaceN = *ppPlace1;
215 
216  ppPlace2 = Ivy_ObjPrevFanoutPlace(pFanin, pFanout);
217  ppPlaceN = Ivy_ObjNextPrevFanoutPlace(pFanin, pFanout);
218  assert( ppPlaceN == NULL || *ppPlaceN == pFanout );
219  if ( ppPlaceN )
220  *ppPlaceN = *ppPlace2;
221 
222  *ppPlace1 = NULL;
223  *ppPlace2 = NULL;
224 }
225 
226 /**Function*************************************************************
227 
228  Synopsis [Replaces the fanout of pOld to be pFanoutNew.]
229 
230  Description []
231 
232  SideEffects []
233 
234  SeeAlso []
235 
236 ***********************************************************************/
237 void Ivy_ObjPatchFanout( Ivy_Man_t * p, Ivy_Obj_t * pFanin, Ivy_Obj_t * pFanoutOld, Ivy_Obj_t * pFanoutNew )
238 {
239  Ivy_Obj_t ** ppPlace;
240  ppPlace = Ivy_ObjPrevNextFanoutPlace(pFanin, pFanoutOld);
241  assert( *ppPlace == pFanoutOld );
242  if ( ppPlace )
243  *ppPlace = pFanoutNew;
244  ppPlace = Ivy_ObjNextPrevFanoutPlace(pFanin, pFanoutOld);
245  assert( ppPlace == NULL || *ppPlace == pFanoutOld );
246  if ( ppPlace )
247  *ppPlace = pFanoutNew;
248  // assuming that pFanoutNew already points to the next fanout
249 }
250 
251 /**Function*************************************************************
252 
253  Synopsis [Starts iteration through the fanouts.]
254 
255  Description [Copies the currently available fanouts into the array.]
256 
257  SideEffects [Can be used while the fanouts are being removed.]
258 
259  SeeAlso []
260 
261 ***********************************************************************/
263 {
264  Ivy_Obj_t * pFanout;
265  assert( p->fFanout );
266  assert( !Ivy_IsComplement(pObj) );
267  Vec_PtrClear( vArray );
268  Ivy_ObjForEachFanoutInt( pObj, pFanout )
269  Vec_PtrPush( vArray, pFanout );
270 }
271 
272 /**Function*************************************************************
273 
274  Synopsis [Reads one fanout.]
275 
276  Description [Returns fanout if there is only one fanout.]
277 
278  SideEffects []
279 
280  SeeAlso []
281 
282 ***********************************************************************/
284 {
285  return pObj->pFanout;
286 }
287 
288 /**Function*************************************************************
289 
290  Synopsis [Reads one fanout.]
291 
292  Description [Returns fanout if there is only one fanout.]
293 
294  SideEffects []
295 
296  SeeAlso []
297 
298 ***********************************************************************/
300 {
301  Ivy_Obj_t * pFanout;
302  int Counter = 0;
303  Ivy_ObjForEachFanoutInt( pObj, pFanout )
304  Counter++;
305  return Counter;
306 }
307 
308 ////////////////////////////////////////////////////////////////////////
309 /// END OF FILE ///
310 ////////////////////////////////////////////////////////////////////////
311 
312 
314 
Ivy_Obj_t * Ivy_ObjReadFirstFanout(Ivy_Man_t *p, Ivy_Obj_t *pObj)
Definition: ivyFanout.c:283
static int Ivy_IsComplement(Ivy_Obj_t *p)
Definition: ivy.h:196
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
Ivy_Obj_t * pPrevFan0
Definition: ivy.h:91
void Ivy_ObjDeleteFanout(Ivy_Man_t *p, Ivy_Obj_t *pFanin, Ivy_Obj_t *pFanout)
Definition: ivyFanout.c:205
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void Ivy_ObjCollectFanouts(Ivy_Man_t *p, Ivy_Obj_t *pObj, Vec_Ptr_t *vArray)
Definition: ivyFanout.c:262
#define Ivy_ObjForEachFanoutInt(pObj, pFanout)
Definition: ivyFanout.c:109
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
Ivy_Obj_t * pFanout
Definition: ivy.h:88
Ivy_Obj_t * pNextFan0
Definition: ivy.h:89
static Ivy_Obj_t * Ivy_ObjFanin1(Ivy_Obj_t *pObj)
Definition: ivy.h:272
Ivy_Obj_t * pNextFan1
Definition: ivy.h:90
void Ivy_ManStartFanout(Ivy_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition: ivyFanout.c:136
static Ivy_Obj_t * Ivy_ObjFanin0(Ivy_Obj_t *pObj)
Definition: ivy.h:271
static Ivy_Obj_t ** Ivy_ObjNextPrevFanoutPlace(Ivy_Obj_t *pObj, Ivy_Obj_t *pFanout)
Definition: ivyFanout.c:94
void Ivy_ManStopFanout(Ivy_Man_t *p)
Definition: ivyFanout.c:162
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Definition: ivy.h:73
void Ivy_ObjPatchFanout(Ivy_Man_t *p, Ivy_Obj_t *pFanin, Ivy_Obj_t *pFanoutOld, Ivy_Obj_t *pFanoutNew)
Definition: ivyFanout.c:237
static int Counter
typedefABC_NAMESPACE_HEADER_START struct Ivy_Man_t_ Ivy_Man_t
INCLUDES ///.
Definition: ivy.h:46
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
int Ivy_ObjFanoutNum(Ivy_Man_t *p, Ivy_Obj_t *pObj)
Definition: ivyFanout.c:299
static Ivy_Obj_t ** Ivy_ObjPrevNextFanoutPlace(Ivy_Obj_t *pObj, Ivy_Obj_t *pFanout)
Definition: ivyFanout.c:79
void Ivy_ObjAddFanout(Ivy_Man_t *p, Ivy_Obj_t *pFanin, Ivy_Obj_t *pFanout)
Definition: ivyFanout.c:183
static Ivy_Obj_t * Ivy_ObjPrevFanout(Ivy_Obj_t *pObj, Ivy_Obj_t *pFanout)
Definition: ivyFanout.c:44
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
static Ivy_Obj_t ** Ivy_ObjNextFanoutPlace(Ivy_Obj_t *pObj, Ivy_Obj_t *pFanout)
Definition: ivyFanout.c:57
static ABC_NAMESPACE_IMPL_START Ivy_Obj_t * Ivy_ObjNextFanout(Ivy_Obj_t *pObj, Ivy_Obj_t *pFanout)
DECLARATIONS ///.
Definition: ivyFanout.c:31
#define Ivy_ManForEachObj(p, pObj, i)
Definition: ivy.h:393
Ivy_Obj_t * pPrevFan1
Definition: ivy.h:92
static Ivy_Obj_t ** Ivy_ObjPrevFanoutPlace(Ivy_Obj_t *pObj, Ivy_Obj_t *pFanout)
Definition: ivyFanout.c:68