abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
giaDfs.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [giaDfs.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Scalable AIG package.]
8 
9  Synopsis [DFS procedures.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: giaDfs.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "gia.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis [Counts the support size of the node.]
37 
38  Description []
39 
40  SideEffects []
41 
42  SeeAlso []
43 
44 ***********************************************************************/
46 {
47  if ( Gia_ObjIsTravIdCurrent(p, pObj) )
48  return;
49  Gia_ObjSetTravIdCurrent(p, pObj);
50  if ( Gia_ObjIsCi(pObj) )
51  {
52  Vec_IntPush( vSupp, Gia_ObjId(p, pObj) );
53  return;
54  }
55  assert( Gia_ObjIsAnd(pObj) );
56  Gia_ManCollectCis_rec( p, Gia_ObjFanin0(pObj), vSupp );
57  Gia_ManCollectCis_rec( p, Gia_ObjFanin1(pObj), vSupp );
58 }
59 
60 /**Function*************************************************************
61 
62  Synopsis [Collects support nodes.]
63 
64  Description []
65 
66  SideEffects []
67 
68  SeeAlso []
69 
70 ***********************************************************************/
71 void Gia_ManCollectCis( Gia_Man_t * p, int * pNodes, int nNodes, Vec_Int_t * vSupp )
72 {
73  Gia_Obj_t * pObj;
74  int i;
75  Vec_IntClear( vSupp );
78  for ( i = 0; i < nNodes; i++ )
79  {
80  pObj = Gia_ManObj( p, pNodes[i] );
81  if ( Gia_ObjIsCo(pObj) )
82  Gia_ManCollectCis_rec( p, Gia_ObjFanin0(pObj), vSupp );
83  else
84  Gia_ManCollectCis_rec( p, pObj, vSupp );
85  }
86 }
87 
88 /**Function*************************************************************
89 
90  Synopsis [Counts the support size of the node.]
91 
92  Description []
93 
94  SideEffects []
95 
96  SeeAlso []
97 
98 ***********************************************************************/
100 {
101  if ( Gia_ObjIsTravIdCurrent(p, pObj) )
102  return;
103  Gia_ObjSetTravIdCurrent(p, pObj);
104  if ( Gia_ObjIsCi(pObj) )
105  return;
106  assert( Gia_ObjIsAnd(pObj) );
107  Gia_ManCollectAnds_rec( p, Gia_ObjFanin0(pObj), vNodes );
108  Gia_ManCollectAnds_rec( p, Gia_ObjFanin1(pObj), vNodes );
109  Vec_IntPush( vNodes, Gia_ObjId(p, pObj) );
110 }
111 
112 /**Function*************************************************************
113 
114  Synopsis [Collects support nodes.]
115 
116  Description []
117 
118  SideEffects []
119 
120  SeeAlso []
121 
122 ***********************************************************************/
123 void Gia_ManCollectAnds( Gia_Man_t * p, int * pNodes, int nNodes, Vec_Int_t * vNodes )
124 {
125  Gia_Obj_t * pObj;
126  int i;
127  Vec_IntClear( vNodes );
128 // Gia_ManIncrementTravId( p );
130  for ( i = 0; i < nNodes; i++ )
131  {
132  pObj = Gia_ManObj( p, pNodes[i] );
133  if ( Gia_ObjIsCo(pObj) )
134  Gia_ManCollectAnds_rec( p, Gia_ObjFanin0(pObj), vNodes );
135  else
136  Gia_ManCollectAnds_rec( p, pObj, vNodes );
137  }
138 }
139 
140 /**Function*************************************************************
141 
142  Synopsis [Counts the support size of the node.]
143 
144  Description []
145 
146  SideEffects []
147 
148  SeeAlso []
149 
150 ***********************************************************************/
152 {
153  if ( Gia_ObjIsTravIdCurrent(p, pObj) )
154  return;
155  Gia_ObjSetTravIdCurrent(p, pObj);
156  if ( Gia_ObjIsCi(pObj) )
157  {
158  Vec_IntPush( vNodes, Gia_ObjId(p, pObj) );
159  return;
160  }
161  assert( Gia_ObjIsAnd(pObj) );
162  Gia_ManCollectNodesCis_rec( p, Gia_ObjFanin0(pObj), vNodes );
163  Gia_ManCollectNodesCis_rec( p, Gia_ObjFanin1(pObj), vNodes );
164  Vec_IntPush( vNodes, Gia_ObjId(p, pObj) );
165 }
166 
167 /**Function*************************************************************
168 
169  Synopsis [Collects support nodes.]
170 
171  Description []
172 
173  SideEffects []
174 
175  SeeAlso []
176 
177 ***********************************************************************/
178 Vec_Int_t * Gia_ManCollectNodesCis( Gia_Man_t * p, int * pNodes, int nNodes )
179 {
180  Vec_Int_t * vNodes;
181  Gia_Obj_t * pObj;
182  int i;
183  vNodes = Vec_IntAlloc( 10000 );
186  for ( i = 0; i < nNodes; i++ )
187  {
188  pObj = Gia_ManObj( p, pNodes[i] );
189  if ( Gia_ObjIsCo(pObj) )
190  Gia_ManCollectNodesCis_rec( p, Gia_ObjFanin0(pObj), vNodes );
191  else
192  Gia_ManCollectNodesCis_rec( p, pObj, vNodes );
193  }
194  return vNodes;
195 }
196 
197 /**Function*************************************************************
198 
199  Synopsis [Collects support nodes.]
200 
201  Description []
202 
203  SideEffects []
204 
205  SeeAlso []
206 
207 ***********************************************************************/
209 {
210  Vec_Int_t * vNodes;
211  Gia_Obj_t * pObj;
212  int i, iNode;
213  abctime clk = Abc_Clock();
214  vNodes = Vec_IntAlloc( 100 );
216  Gia_ManForEachCo( p, pObj, i )
217  {
218  iNode = Gia_ObjId(p, pObj);
219  Gia_ManCollectAnds( p, &iNode, 1, vNodes );
220  }
221  Vec_IntFree( vNodes );
222  ABC_PRT( "DFS from each output", Abc_Clock() - clk );
223 }
224 
225 /**Function*************************************************************
226 
227  Synopsis [Collects support nodes.]
228 
229  Description []
230 
231  SideEffects []
232 
233  SeeAlso []
234 
235 ***********************************************************************/
237 {
238  if ( Gia_ObjIsTravIdCurrent(p, pObj) )
239  return 0;
240  Gia_ObjSetTravIdCurrent(p, pObj);
241  if ( Gia_ObjIsCi(pObj) )
242  return 1;
243  assert( Gia_ObjIsAnd(pObj) );
244  return Gia_ManSuppSize_rec( p, Gia_ObjFanin0(pObj) ) +
246 }
247 
248 /**Function*************************************************************
249 
250  Synopsis [Computes support size of the node.]
251 
252  Description []
253 
254  SideEffects []
255 
256  SeeAlso []
257 
258 ***********************************************************************/
260 {
262  return Gia_ManSuppSize_rec( p, pObj );
263 }
264 
265 /**Function*************************************************************
266 
267  Synopsis [Computes support size of the node.]
268 
269  Description []
270 
271  SideEffects []
272 
273  SeeAlso []
274 
275 ***********************************************************************/
277 {
278  Gia_Obj_t * pObj;
279  int i, Counter = 0;
280  abctime clk = Abc_Clock();
281  Gia_ManForEachObj( p, pObj, i )
282  if ( Gia_ObjIsAnd(pObj) )
283  Counter += (Gia_ManSuppSizeOne(p, pObj) <= 16);
284  printf( "Nodes with small support %d (out of %d)\n", Counter, Gia_ManAndNum(p) );
285  Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
286  return Counter;
287 }
288 
289 /**Function*************************************************************
290 
291  Synopsis [Collects support nodes.]
292 
293  Description []
294 
295  SideEffects []
296 
297  SeeAlso []
298 
299 ***********************************************************************/
300 int Gia_ManSuppSize( Gia_Man_t * p, int * pNodes, int nNodes )
301 {
302  Gia_Obj_t * pObj;
303  int i, Counter = 0;
306  for ( i = 0; i < nNodes; i++ )
307  {
308  pObj = Gia_ManObj( p, pNodes[i] );
309  if ( Gia_ObjIsCo(pObj) )
310  Counter += Gia_ManSuppSize_rec( p, Gia_ObjFanin0(pObj) );
311  else
312  Counter += Gia_ManSuppSize_rec( p, pObj );
313  }
314  return Counter;
315 }
316 
317 /**Function*************************************************************
318 
319  Synopsis [Collects support nodes.]
320 
321  Description []
322 
323  SideEffects []
324 
325  SeeAlso []
326 
327 ***********************************************************************/
329 {
330  if ( Gia_ObjIsTravIdCurrent(p, pObj) )
331  return 0;
332  Gia_ObjSetTravIdCurrent(p, pObj);
333  if ( Gia_ObjIsCi(pObj) )
334  return 0;
335  assert( Gia_ObjIsAnd(pObj) );
336  return 1 + Gia_ManConeSize_rec( p, Gia_ObjFanin0(pObj) ) +
338 }
339 
340 /**Function*************************************************************
341 
342  Synopsis [Collects support nodes.]
343 
344  Description []
345 
346  SideEffects []
347 
348  SeeAlso []
349 
350 ***********************************************************************/
351 int Gia_ManConeSize( Gia_Man_t * p, int * pNodes, int nNodes )
352 {
353  Gia_Obj_t * pObj;
354  int i, Counter = 0;
357  for ( i = 0; i < nNodes; i++ )
358  {
359  pObj = Gia_ManObj( p, pNodes[i] );
360  if ( Gia_ObjIsCo(pObj) )
361  Counter += Gia_ManConeSize_rec( p, Gia_ObjFanin0(pObj) );
362  else
363  Counter += Gia_ManConeSize_rec( p, pObj );
364  }
365  return Counter;
366 }
367 
368 /**Function*************************************************************
369 
370  Synopsis [Levelizes the nodes.]
371 
372  Description []
373 
374  SideEffects []
375 
376  SeeAlso []
377 
378 ***********************************************************************/
380 {
381  Gia_Obj_t * pObj;
382  Vec_Vec_t * vLevels;
383  int nLevels, Level, i;
384  nLevels = Gia_ManLevelNum( p );
385  vLevels = Vec_VecStart( nLevels + 1 );
386  Gia_ManForEachAnd( p, pObj, i )
387  {
388  Level = Gia_ObjLevel( p, pObj );
389  assert( Level <= nLevels );
390  Vec_VecPush( vLevels, Level, pObj );
391  }
392  return vLevels;
393 }
394 
395 /**Function*************************************************************
396 
397  Synopsis [Computes reverse topological order.]
398 
399  Description [Assumes that levels are already assigned.
400  The levels of CO nodes may not be assigned.]
401 
402  SideEffects []
403 
404  SeeAlso []
405 
406 ***********************************************************************/
408 {
409  Gia_Obj_t * pObj;
410  Vec_Vec_t * vLevels;
411  Vec_Ptr_t * vLevel;
412  Vec_Int_t * vResult;
413  int i, k;
414  vLevels = Vec_VecStart( 100 );
415  // make sure levels are assigned
416  Gia_ManForEachAnd( p, pObj, i )
417  assert( Gia_ObjLevel(p, pObj) > 0 );
418  // add CO nodes based on the level of their fanin
419  Gia_ManForEachCo( p, pObj, i )
420  Vec_VecPush( vLevels, Gia_ObjLevel(p, Gia_ObjFanin0(pObj)), pObj );
421  // add other nodes based on their level
422  Gia_ManForEachObj( p, pObj, i )
423  if ( !Gia_ObjIsCo(pObj) )
424  Vec_VecPush( vLevels, Gia_ObjLevel(p, pObj), pObj );
425  // put the nodes in the reverse topological order
426  vResult = Vec_IntAlloc( Gia_ManObjNum(p) );
427  Vec_VecForEachLevelReverse( vLevels, vLevel, i )
428  Vec_PtrForEachEntry( Gia_Obj_t *, vLevel, pObj, k )
429  Vec_IntPush( vResult, Gia_ObjId(p, pObj) );
430  Vec_VecFree( vLevels );
431  return vResult;
432 }
433 
434 /**Function*************************************************************
435 
436  Synopsis []
437 
438  Description []
439 
440  SideEffects []
441 
442  SeeAlso []
443 
444 ***********************************************************************/
445 void Gia_ManCollectSeq_rec( Gia_Man_t * p, int Id, Vec_Int_t * vRoots, Vec_Int_t * vObjs )
446 {
447  Gia_Obj_t * pObj;
448  if ( Gia_ObjIsTravIdCurrentId( p, Id ) )
449  return;
450  Gia_ObjSetTravIdCurrentId( p, Id );
451  pObj = Gia_ManObj( p, Id );
452  if ( Gia_ObjIsAnd(pObj) )
453  {
454  Gia_ManCollectSeq_rec( p, Gia_ObjFaninId0(pObj, Id), vRoots, vObjs );
455  Gia_ManCollectSeq_rec( p, Gia_ObjFaninId1(pObj, Id), vRoots, vObjs );
456  }
457  else if ( Gia_ObjIsCi(pObj) )
458  {
459  if ( Gia_ObjIsRo(p, pObj) )
460  Vec_IntPush( vRoots, Gia_ObjId(p, Gia_ObjRoToRi(p, pObj)) );
461  }
462  else if ( Gia_ObjIsCo(pObj) )
463  Gia_ManCollectSeq_rec( p, Gia_ObjFaninId0(pObj, Id), vRoots, vObjs );
464  else assert( 0 );
465  Vec_IntPush( vObjs, Id );
466 }
467 Vec_Int_t * Gia_ManCollectSeq( Gia_Man_t * p, int * pPos, int nPos )
468 {
469  Vec_Int_t * vObjs, * vRoots;
470  int i, iRoot;
471  // collect roots
472  vRoots = Vec_IntAlloc( 100 );
473  for ( i = 0; i < nPos; i++ )
474  Vec_IntPush( vRoots, Gia_ObjId(p, Gia_ManPo(p, pPos[i])) );
475  // start trav IDs
478  // collect objects
479  vObjs = Vec_IntAlloc( 1000 );
480  Vec_IntPush( vObjs, 0 );
481  Vec_IntForEachEntry( vRoots, iRoot, i )
482  Gia_ManCollectSeq_rec( p, iRoot, vRoots, vObjs );
483  Vec_IntFree( vRoots );
484  return vObjs;
485 }
487 {
488  Vec_Int_t * vObjs;
489  int i;
490  abctime clk = Abc_Clock();
491  for ( i = 0; i < Gia_ManPoNum(p); i++ )
492  {
493  if ( i % 10000 == 0 )
494  printf( "%8d finished...\r", i );
495 
496  vObjs = Gia_ManCollectSeq( p, &i, 1 );
497 // printf( "%d ", Vec_IntSize(vObjs) );
498  Vec_IntFree( vObjs );
499  }
500  Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
501 
502 }
503 
504 ////////////////////////////////////////////////////////////////////////
505 /// END OF FILE ///
506 ////////////////////////////////////////////////////////////////////////
507 
508 
510 
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static void Vec_VecPush(Vec_Vec_t *p, int Level, void *Entry)
Definition: vecVec.h:456
#define Gia_ManForEachCo(p, pObj, i)
Definition: gia.h:1022
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.
Definition: vecVec.h:42
static int Gia_ManPoNum(Gia_Man_t *p)
Definition: gia.h:386
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
int Gia_ManConeSize(Gia_Man_t *p, int *pNodes, int nNodes)
Definition: giaDfs.c:351
static int Gia_ObjIsTravIdCurrent(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:533
static Gia_Obj_t * Gia_ManPo(Gia_Man_t *p, int v)
Definition: gia.h:406
static abctime Abc_Clock()
Definition: abc_global.h:279
static void Vec_VecFree(Vec_Vec_t *p)
Definition: vecVec.h:347
static Gia_Obj_t * Gia_ManObj(Gia_Man_t *p, int v)
Definition: gia.h:402
void Gia_ManCollectSeqTest(Gia_Man_t *p)
Definition: giaDfs.c:486
Definition: gia.h:75
void Gia_ManCollectAnds_rec(Gia_Man_t *p, Gia_Obj_t *pObj, Vec_Int_t *vNodes)
Definition: giaDfs.c:99
static void Abc_PrintTime(int level, const char *pStr, abctime time)
Definition: abc_global.h:367
static int Gia_ManAndNum(Gia_Man_t *p)
Definition: gia.h:389
static int Gia_ObjLevel(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:501
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
Definition: gia.h:454
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
void Gia_ManCollectSeq_rec(Gia_Man_t *p, int Id, Vec_Int_t *vRoots, Vec_Int_t *vObjs)
Definition: giaDfs.c:445
static int Gia_ObjIsRo(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:443
static Gia_Obj_t * Gia_ObjRoToRi(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:446
static void Gia_ObjSetTravIdCurrent(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:531
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Vec_Int_t * Gia_ManOrderReverse(Gia_Man_t *p)
Definition: giaDfs.c:407
#define Gia_ManForEachAnd(p, pObj, i)
Definition: gia.h:1002
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static int Gia_ObjId(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:410
static int Counter
static Vec_Vec_t * Vec_VecStart(int nSize)
Definition: vecVec.h:168
int Gia_ManSuppSize(Gia_Man_t *p, int *pNodes, int nNodes)
Definition: giaDfs.c:300
void Gia_ManCollectCis(Gia_Man_t *p, int *pNodes, int nNodes, Vec_Int_t *vSupp)
Definition: giaDfs.c:71
static int Gia_ObjIsTravIdCurrentId(Gia_Man_t *p, int Id)
Definition: gia.h:536
static int Gia_ObjIsCo(Gia_Obj_t *pObj)
Definition: gia.h:421
#define Vec_VecForEachLevelReverse(vGlob, vVec, i)
Definition: vecVec.h:63
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
int Gia_ManSuppSizeOne(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: giaDfs.c:259
Vec_Vec_t * Gia_ManLevelize(Gia_Man_t *p)
Definition: giaDfs.c:379
Definition: gia.h:95
#define ABC_PRT(a, t)
Definition: abc_global.h:220
static int Gia_ObjIsAnd(Gia_Obj_t *pObj)
Definition: gia.h:422
#define Gia_ManForEachObj(p, pObj, i)
MACRO DEFINITIONS ///.
Definition: gia.h:984
static Gia_Obj_t * Gia_ManConst0(Gia_Man_t *p)
Definition: gia.h:400
ABC_NAMESPACE_IMPL_START void Gia_ManCollectCis_rec(Gia_Man_t *p, Gia_Obj_t *pObj, Vec_Int_t *vSupp)
DECLARATIONS ///.
Definition: giaDfs.c:45
int Gia_ManSuppSize_rec(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: giaDfs.c:236
static Gia_Obj_t * Gia_ObjFanin1(Gia_Obj_t *pObj)
Definition: gia.h:455
Vec_Int_t * Gia_ManCollectNodesCis(Gia_Man_t *p, int *pNodes, int nNodes)
Definition: giaDfs.c:178
#define assert(ex)
Definition: util_old.h:213
int Gia_ManLevelNum(Gia_Man_t *p)
Definition: giaUtil.c:505
void Gia_ManCollectTest(Gia_Man_t *p)
Definition: giaDfs.c:208
void Gia_ManIncrementTravId(Gia_Man_t *p)
Definition: giaUtil.c:149
int Gia_ManConeSize_rec(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: giaDfs.c:328
void Gia_ManCollectAnds(Gia_Man_t *p, int *pNodes, int nNodes, Vec_Int_t *vNodes)
Definition: giaDfs.c:123
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
Vec_Int_t * Gia_ManCollectSeq(Gia_Man_t *p, int *pPos, int nPos)
Definition: giaDfs.c:467
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
ABC_INT64_T abctime
Definition: abc_global.h:278
static int Gia_ObjIsCi(Gia_Obj_t *pObj)
Definition: gia.h:420
static void Gia_ObjSetTravIdCurrentId(Gia_Man_t *p, int Id)
Definition: gia.h:535
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
static int Gia_ObjFaninId1(Gia_Obj_t *pObj, int ObjId)
Definition: gia.h:461
void Gia_ManCollectNodesCis_rec(Gia_Man_t *p, Gia_Obj_t *pObj, Vec_Int_t *vNodes)
Definition: giaDfs.c:151
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
int Gia_ManSuppSizeTest(Gia_Man_t *p)
Definition: giaDfs.c:276
static int Gia_ObjFaninId0(Gia_Obj_t *pObj, int ObjId)
Definition: gia.h:460