abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ifReduce.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [ifExpand.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [FPGA mapping based on priority cuts.]
8 
9  Synopsis [Incremental improvement of current mapping.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - November 21, 2006.]
16 
17  Revision [$Id: ifExpand.c,v 1.00 2006/11/21 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "if.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 static void If_ManImproveExpand( If_Man_t * p, int nLimit );
31 static void If_ManImproveNodeExpand( If_Man_t * p, If_Obj_t * pObj, int nLimit, Vec_Ptr_t * vFront, Vec_Ptr_t * vFrontOld, Vec_Ptr_t * vVisited );
32 static void If_ManImproveNodePrepare( If_Man_t * p, If_Obj_t * pObj, int nLimit, Vec_Ptr_t * vFront, Vec_Ptr_t * vFrontOld, Vec_Ptr_t * vVisited );
33 static void If_ManImproveNodeUpdate( If_Man_t * p, If_Obj_t * pObj, Vec_Ptr_t * vFront );
34 static void If_ManImproveNodeFaninCompact( If_Man_t * p, If_Obj_t * pObj, int nLimit, Vec_Ptr_t * vFront, Vec_Ptr_t * vVisited );
35 
36 ////////////////////////////////////////////////////////////////////////
37 /// FUNCTION DEFINITIONS ///
38 ////////////////////////////////////////////////////////////////////////
39 
40 /**Function*************************************************************
41 
42  Synopsis [Improves current mapping using expand/Expand of one cut.]
43 
44  Description [Assumes current mapping assigned and required times computed.]
45 
46  SideEffects []
47 
48  SeeAlso []
49 
50 ***********************************************************************/
52 {
53  abctime clk;
54 
55  clk = Abc_Clock();
58  if ( p->pPars->fVerbose )
59  {
60  Abc_Print( 1, "E: Del = %7.2f. Ar = %9.1f. Edge = %8d. ",
61  p->RequiredGlo, p->AreaGlo, p->nNets );
62  if ( p->dPower )
63  Abc_Print( 1, "Switch = %7.2f. ", p->dPower );
64  Abc_Print( 1, "Cut = %8d. ", p->nCutsMerged );
65  Abc_PrintTime( 1, "T", Abc_Clock() - clk );
66  }
67 }
68 
69 /**Function*************************************************************
70 
71  Synopsis [Performs area recovery for each node.]
72 
73  Description []
74 
75  SideEffects []
76 
77  SeeAlso []
78 
79 ***********************************************************************/
80 void If_ManImproveExpand( If_Man_t * p, int nLimit )
81 {
82  Vec_Ptr_t * vFront, * vFrontOld, * vVisited;
83  If_Obj_t * pObj;
84  int i;
85  vFront = Vec_PtrAlloc( nLimit );
86  vFrontOld = Vec_PtrAlloc( nLimit );
87  vVisited = Vec_PtrAlloc( 100 );
88  // iterate through all nodes in the topological order
89  If_ManForEachNode( p, pObj, i )
90  If_ManImproveNodeExpand( p, pObj, nLimit, vFront, vFrontOld, vVisited );
91  Vec_PtrFree( vFront );
92  Vec_PtrFree( vFrontOld );
93  Vec_PtrFree( vVisited );
94 }
95 
96 /**Function*************************************************************
97 
98  Synopsis [Counts the number of nodes with no external fanout.]
99 
100  Description []
101 
102  SideEffects []
103 
104  SeeAlso []
105 
106 ***********************************************************************/
108 {
109  If_Obj_t * pFanin;
110  int i, Counter = 0;
111  Vec_PtrForEachEntry( If_Obj_t *, vFront, pFanin, i )
112  if ( pFanin->nRefs == 0 )
113  Counter++;
114  return Counter;
115 }
116 
117 /**Function*************************************************************
118 
119  Synopsis [Performs area recovery for each node.]
120 
121  Description []
122 
123  SideEffects []
124 
125  SeeAlso []
126 
127 ***********************************************************************/
128 void If_ManImproveNodeExpand( If_Man_t * p, If_Obj_t * pObj, int nLimit, Vec_Ptr_t * vFront, Vec_Ptr_t * vFrontOld, Vec_Ptr_t * vVisited )
129 {
130  If_Obj_t * pFanin;
131  If_Cut_t * pCut;
132  int CostBef, CostAft, i;
133  float DelayOld, AreaBef, AreaAft;
134  pCut = If_ObjCutBest(pObj);
135  pCut->Delay = If_CutDelay( p, pObj, pCut );
136  assert( pCut->Delay <= pObj->Required + p->fEpsilon );
137  if ( pObj->nRefs == 0 )
138  return;
139  // get the delay
140  DelayOld = pCut->Delay;
141  // get the area
142  AreaBef = If_CutAreaRefed( p, pCut );
143 // if ( AreaBef == 1 )
144 // return;
145  // the cut is non-trivial
146  If_ManImproveNodePrepare( p, pObj, nLimit, vFront, vFrontOld, vVisited );
147  // iteratively modify the cut
148  If_CutAreaDeref( p, pCut );
149  CostBef = If_ManImproveCutCost( p, vFront );
150  If_ManImproveNodeFaninCompact( p, pObj, nLimit, vFront, vVisited );
151  CostAft = If_ManImproveCutCost( p, vFront );
152  If_CutAreaRef( p, pCut );
153  assert( CostBef >= CostAft );
154  // clean up
155  Vec_PtrForEachEntry( If_Obj_t *, vVisited, pFanin, i )
156  pFanin->fMark = 0;
157  // update the node
158  If_ManImproveNodeUpdate( p, pObj, vFront );
159  pCut->Delay = If_CutDelay( p, pObj, pCut );
160  // get the new area
161  AreaAft = If_CutAreaRefed( p, pCut );
162  if ( AreaAft > AreaBef || pCut->Delay > pObj->Required + p->fEpsilon )
163  {
164  If_ManImproveNodeUpdate( p, pObj, vFrontOld );
165  AreaAft = If_CutAreaRefed( p, pCut );
166  assert( AreaAft == AreaBef );
167  pCut->Delay = DelayOld;
168  }
169 }
170 
171 /**Function*************************************************************
172 
173  Synopsis [Performs area recovery for each node.]
174 
175  Description []
176 
177  SideEffects []
178 
179  SeeAlso []
180 
181 ***********************************************************************/
182 void If_ManImproveMark_rec( If_Man_t * p, If_Obj_t * pObj, Vec_Ptr_t * vVisited )
183 {
184  if ( pObj->fMark )
185  return;
186  assert( If_ObjIsAnd(pObj) );
187  If_ManImproveMark_rec( p, If_ObjFanin0(pObj), vVisited );
188  If_ManImproveMark_rec( p, If_ObjFanin1(pObj), vVisited );
189  Vec_PtrPush( vVisited, pObj );
190  pObj->fMark = 1;
191 }
192 
193 /**Function*************************************************************
194 
195  Synopsis [Prepares node mapping.]
196 
197  Description []
198 
199  SideEffects []
200 
201  SeeAlso []
202 
203 ***********************************************************************/
204 void If_ManImproveNodePrepare( If_Man_t * p, If_Obj_t * pObj, int nLimit, Vec_Ptr_t * vFront, Vec_Ptr_t * vFrontOld, Vec_Ptr_t * vVisited )
205 {
206  If_Cut_t * pCut;
207  If_Obj_t * pLeaf;
208  int i;
209  Vec_PtrClear( vFront );
210  Vec_PtrClear( vFrontOld );
211  Vec_PtrClear( vVisited );
212  // expand the cut downwards from the given place
213  pCut = If_ObjCutBest(pObj);
214  If_CutForEachLeaf( p, pCut, pLeaf, i )
215  {
216  Vec_PtrPush( vFront, pLeaf );
217  Vec_PtrPush( vFrontOld, pLeaf );
218  Vec_PtrPush( vVisited, pLeaf );
219  pLeaf->fMark = 1;
220  }
221  // mark the nodes in the cone
222  If_ManImproveMark_rec( p, pObj, vVisited );
223 }
224 
225 /**Function*************************************************************
226 
227  Synopsis [Updates the frontier.]
228 
229  Description []
230 
231  SideEffects []
232 
233  SeeAlso []
234 
235 ***********************************************************************/
237 {
238  If_Cut_t * pCut;
239  If_Obj_t * pFanin;
240  int i;
241  pCut = If_ObjCutBest(pObj);
242  // deref node's cut
243  If_CutAreaDeref( p, pCut );
244  // update the node's cut
245  pCut->nLeaves = Vec_PtrSize(vFront);
246  Vec_PtrForEachEntry( If_Obj_t *, vFront, pFanin, i )
247  pCut->pLeaves[i] = pFanin->Id;
248  If_CutOrder( pCut );
249  pCut->uSign = If_ObjCutSignCompute(pCut);
250  // ref the new cut
251  If_CutAreaRef( p, pCut );
252 }
253 
254 
255 /**Function*************************************************************
256 
257  Synopsis [Returns 1 if the number of fanins will grow.]
258 
259  Description []
260 
261  SideEffects []
262 
263  SeeAlso []
264 
265 ***********************************************************************/
267 {
268  If_Obj_t * pFanin0, * pFanin1;
269  assert( If_ObjIsAnd(pObj) );
270  pFanin0 = If_ObjFanin0(pObj);
271  pFanin1 = If_ObjFanin1(pObj);
272  return !pFanin0->fMark && !pFanin1->fMark;
273 }
274 
275 /**Function*************************************************************
276 
277  Synopsis [Returns the increase in the number of fanins with no external refs.]
278 
279  Description []
280 
281  SideEffects []
282 
283  SeeAlso []
284 
285 ***********************************************************************/
287 {
288  int Counter = 0;
289  assert( If_ObjIsAnd(pObj) );
290  // check if the node has external refs
291  if ( pObj->nRefs == 0 )
292  Counter--;
293  // increment the number of fanins without external refs
294  if ( !If_ObjFanin0(pObj)->fMark && If_ObjFanin0(pObj)->nRefs == 0 )
295  Counter++;
296  // increment the number of fanins without external refs
297  if ( !If_ObjFanin1(pObj)->fMark && If_ObjFanin1(pObj)->nRefs == 0 )
298  Counter++;
299  return Counter;
300 }
301 
302 /**Function*************************************************************
303 
304  Synopsis [Updates the frontier.]
305 
306  Description []
307 
308  SideEffects []
309 
310  SeeAlso []
311 
312 ***********************************************************************/
313 void If_ManImproveNodeFaninUpdate( If_Man_t * p, If_Obj_t * pObj, Vec_Ptr_t * vFront, Vec_Ptr_t * vVisited )
314 {
315  If_Obj_t * pFanin;
316  assert( If_ObjIsAnd(pObj) );
317  Vec_PtrRemove( vFront, pObj );
318  pFanin = If_ObjFanin0(pObj);
319  if ( !pFanin->fMark )
320  {
321  Vec_PtrPush( vFront, pFanin );
322  Vec_PtrPush( vVisited, pFanin );
323  pFanin->fMark = 1;
324  }
325  pFanin = If_ObjFanin1(pObj);
326  if ( !pFanin->fMark )
327  {
328  Vec_PtrPush( vFront, pFanin );
329  Vec_PtrPush( vVisited, pFanin );
330  pFanin->fMark = 1;
331  }
332 }
333 
334 /**Function*************************************************************
335 
336  Synopsis [Compacts the number of external refs.]
337 
338  Description []
339 
340  SideEffects []
341 
342  SeeAlso []
343 
344 ***********************************************************************/
345 int If_ManImproveNodeFaninCompact0( If_Man_t * p, If_Obj_t * pObj, int nLimit, Vec_Ptr_t * vFront, Vec_Ptr_t * vVisited )
346 {
347  If_Obj_t * pFanin;
348  int i;
349  Vec_PtrForEachEntry( If_Obj_t *, vFront, pFanin, i )
350  {
351  if ( If_ObjIsCi(pFanin) )
352  continue;
353  if ( If_ManImproveNodeWillGrow(p, pFanin) )
354  continue;
355  if ( If_ManImproveNodeFaninCost(p, pFanin) <= 0 )
356  {
357  If_ManImproveNodeFaninUpdate( p, pFanin, vFront, vVisited );
358  return 1;
359  }
360  }
361  return 0;
362 }
363 
364 /**Function*************************************************************
365 
366  Synopsis [Compacts the number of external refs.]
367 
368  Description []
369 
370  SideEffects []
371 
372  SeeAlso []
373 
374 ***********************************************************************/
375 int If_ManImproveNodeFaninCompact1( If_Man_t * p, If_Obj_t * pObj, int nLimit, Vec_Ptr_t * vFront, Vec_Ptr_t * vVisited )
376 {
377  If_Obj_t * pFanin;
378  int i;
379  Vec_PtrForEachEntry( If_Obj_t *, vFront, pFanin, i )
380  {
381  if ( If_ObjIsCi(pFanin) )
382  continue;
383  if ( If_ManImproveNodeFaninCost(p, pFanin) < 0 )
384  {
385  If_ManImproveNodeFaninUpdate( p, pFanin, vFront, vVisited );
386  return 1;
387  }
388  }
389  return 0;
390 }
391 
392 /**Function*************************************************************
393 
394  Synopsis [Compacts the number of external refs.]
395 
396  Description []
397 
398  SideEffects []
399 
400  SeeAlso []
401 
402 ***********************************************************************/
403 int If_ManImproveNodeFaninCompact2( If_Man_t * p, If_Obj_t * pObj, int nLimit, Vec_Ptr_t * vFront, Vec_Ptr_t * vVisited )
404 {
405  If_Obj_t * pFanin;
406  int i;
407  Vec_PtrForEachEntry( If_Obj_t *, vFront, pFanin, i )
408  {
409  if ( If_ObjIsCi(pFanin) )
410  continue;
411  if ( If_ManImproveNodeFaninCost(p, pFanin) <= 0 )
412  {
413  If_ManImproveNodeFaninUpdate( p, pFanin, vFront, vVisited );
414  return 1;
415  }
416  }
417  return 0;
418 }
419 
420 /**Function*************************************************************
421 
422  Synopsis [Compacts the number of external refs.]
423 
424  Description []
425 
426  SideEffects []
427 
428  SeeAlso []
429 
430 ***********************************************************************/
431 int If_ManImproveNodeFaninCompact_int( If_Man_t * p, If_Obj_t * pObj, int nLimit, Vec_Ptr_t * vFront, Vec_Ptr_t * vVisited )
432 {
433  if ( If_ManImproveNodeFaninCompact0(p, pObj, nLimit, vFront, vVisited) )
434  return 1;
435  if ( Vec_PtrSize(vFront) < nLimit && If_ManImproveNodeFaninCompact1(p, pObj, nLimit, vFront, vVisited) )
436  return 1;
437 // if ( Vec_PtrSize(vFront) < nLimit && If_ManImproveNodeFaninCompact2(p, pObj, nLimit, vFront, vVisited) )
438 // return 1;
439  assert( Vec_PtrSize(vFront) <= nLimit );
440  return 0;
441 }
442 
443 /**Function*************************************************************
444 
445  Synopsis [Compacts the number of external refs.]
446 
447  Description []
448 
449  SideEffects []
450 
451  SeeAlso []
452 
453 ***********************************************************************/
454 void If_ManImproveNodeFaninCompact( If_Man_t * p, If_Obj_t * pObj, int nLimit, Vec_Ptr_t * vFront, Vec_Ptr_t * vVisited )
455 {
456  while ( If_ManImproveNodeFaninCompact_int( p, pObj, nLimit, vFront, vVisited ) );
457 }
458 
459 
460 ////////////////////////////////////////////////////////////////////////
461 /// END OF FILE ///
462 ////////////////////////////////////////////////////////////////////////
463 
464 
466 
unsigned nLeaves
Definition: if.h:289
int Id
Definition: if.h:316
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
float dPower
Definition: if.h:200
static void If_ManImproveNodeUpdate(If_Man_t *p, If_Obj_t *pObj, Vec_Ptr_t *vFront)
Definition: ifReduce.c:236
#define If_ManForEachNode(p, pObj, i)
Definition: if.h:468
int nLutSize
Definition: if.h:103
int If_ManImproveNodeWillGrow(If_Man_t *p, If_Obj_t *pObj)
Definition: ifReduce.c:266
float If_CutAreaDeref(If_Man_t *p, If_Cut_t *pCut)
Definition: ifCut.c:1032
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void If_ManImproveNodePrepare(If_Man_t *p, If_Obj_t *pObj, int nLimit, Vec_Ptr_t *vFront, Vec_Ptr_t *vFrontOld, Vec_Ptr_t *vVisited)
Definition: ifReduce.c:204
Definition: if.h:303
static int If_ObjIsAnd(If_Obj_t *pObj)
Definition: if.h:377
Definition: if.h:275
#define If_CutForEachLeaf(p, pCut, pLeaf, i)
Definition: if.h:474
float Required
Definition: if.h:325
int fVerbose
Definition: if.h:140
static void If_ManImproveNodeExpand(If_Man_t *p, If_Obj_t *pObj, int nLimit, Vec_Ptr_t *vFront, Vec_Ptr_t *vFrontOld, Vec_Ptr_t *vVisited)
Definition: ifReduce.c:128
void If_ManComputeRequired(If_Man_t *p)
Definition: ifTime.c:294
void If_ManImproveMark_rec(If_Man_t *p, If_Obj_t *pObj, Vec_Ptr_t *vVisited)
Definition: ifReduce.c:182
void If_ManImproveMapping(If_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition: ifReduce.c:51
int nCutsMerged
Definition: if.h:202
int If_ManImproveNodeFaninCompact0(If_Man_t *p, If_Obj_t *pObj, int nLimit, Vec_Ptr_t *vFront, Vec_Ptr_t *vVisited)
Definition: ifReduce.c:345
static If_Obj_t * If_ObjFanin0(If_Obj_t *pObj)
Definition: if.h:380
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
int If_ManImproveNodeFaninCompact2(If_Man_t *p, If_Obj_t *pObj, int nLimit, Vec_Ptr_t *vFront, Vec_Ptr_t *vVisited)
Definition: ifReduce.c:403
static int If_ObjIsCi(If_Obj_t *pObj)
Definition: if.h:373
static If_Cut_t * If_ObjCutBest(If_Obj_t *pObj)
Definition: if.h:401
static abctime Abc_Clock()
Definition: abc_global.h:279
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
void If_CutOrder(If_Cut_t *pCut)
Definition: ifCut.c:797
int nRefs
Definition: if.h:318
static void Vec_PtrRemove(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:714
void If_ManImproveNodeFaninUpdate(If_Man_t *p, If_Obj_t *pObj, Vec_Ptr_t *vFront, Vec_Ptr_t *vVisited)
Definition: ifReduce.c:313
static void Abc_PrintTime(int level, const char *pStr, abctime time)
Definition: abc_global.h:367
float AreaGlo
Definition: if.h:198
int pLeaves[0]
Definition: if.h:290
static unsigned If_ObjCutSignCompute(If_Cut_t *p)
Definition: if.h:403
float RequiredGlo
Definition: if.h:196
Definition: if.h:180
int If_ManImproveNodeFaninCost(If_Man_t *p, If_Obj_t *pObj)
Definition: ifReduce.c:286
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static If_Obj_t * If_ObjFanin1(If_Obj_t *pObj)
Definition: if.h:381
static int Counter
int If_ManImproveNodeFaninCompact1(If_Man_t *p, If_Obj_t *pObj, int nLimit, Vec_Ptr_t *vFront, Vec_Ptr_t *vVisited)
Definition: ifReduce.c:375
static void Abc_Print(int level, const char *format,...)
Definition: abc_global.h:313
float fEpsilon
Definition: if.h:195
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
int If_ManImproveCutCost(If_Man_t *p, Vec_Ptr_t *vFront)
Definition: ifReduce.c:107
static void If_ManImproveNodeFaninCompact(If_Man_t *p, If_Obj_t *pObj, int nLimit, Vec_Ptr_t *vFront, Vec_Ptr_t *vVisited)
Definition: ifReduce.c:454
If_Par_t * pPars
Definition: if.h:184
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
float If_CutDelay(If_Man_t *p, If_Obj_t *pObj, If_Cut_t *pCut)
Definition: ifTime.c:91
static ABC_NAMESPACE_IMPL_START void If_ManImproveExpand(If_Man_t *p, int nLimit)
DECLARATIONS ///.
Definition: ifReduce.c:80
int If_ManImproveNodeFaninCompact_int(If_Man_t *p, If_Obj_t *pObj, int nLimit, Vec_Ptr_t *vFront, Vec_Ptr_t *vVisited)
Definition: ifReduce.c:431
unsigned uSign
Definition: if.h:283
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
int nNets
Definition: if.h:199
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
float If_CutAreaRefed(If_Man_t *p, If_Cut_t *pCut)
Definition: ifCut.c:1109
ABC_INT64_T abctime
Definition: abc_global.h:278
float If_CutAreaRef(If_Man_t *p, If_Cut_t *pCut)
Definition: ifCut.c:1059
float Delay
Definition: if.h:280
unsigned fMark
Definition: if.h:310
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223