ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
ifReduce.c
Go to the documentation of this file.
1
20
21#include "if.h"
22
24
25
29
30static void If_ManImproveExpand( If_Man_t * p, int nLimit );
31static 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 );
32static 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 );
33static void If_ManImproveNodeUpdate( If_Man_t * p, If_Obj_t * pObj, Vec_Ptr_t * vFront );
34static void If_ManImproveNodeFaninCompact( If_Man_t * p, If_Obj_t * pObj, int nLimit, Vec_Ptr_t * vFront, Vec_Ptr_t * vVisited );
35
39
52{
53 abctime clk;
54
55 clk = Abc_Clock();
56 If_ManImproveExpand( p, p->pPars->nLutSize );
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
80void 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
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
128void 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
182void 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
204void 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
236void If_ManImproveNodeUpdate( If_Man_t * p, If_Obj_t * pObj, Vec_Ptr_t * vFront )
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
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
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
313void 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
345int 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
375int 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
403int 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
431int 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
454void 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
463
464
466
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
Cube * p
Definition exorList.c:222
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
int If_ManImproveNodeWillGrow(If_Man_t *p, If_Obj_t *pObj)
Definition ifReduce.c:266
void If_ManImproveMark_rec(If_Man_t *p, If_Obj_t *pObj, Vec_Ptr_t *vVisited)
Definition ifReduce.c:182
int If_ManImproveNodeFaninCost(If_Man_t *p, If_Obj_t *pObj)
Definition ifReduce.c:286
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
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
void If_ManImproveNodeFaninUpdate(If_Man_t *p, If_Obj_t *pObj, Vec_Ptr_t *vFront, Vec_Ptr_t *vVisited)
Definition ifReduce.c:313
int If_ManImproveCutCost(If_Man_t *p, Vec_Ptr_t *vFront)
Definition ifReduce.c:107
void If_ManImproveMapping(If_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition ifReduce.c:51
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
float If_CutAreaDeref(If_Man_t *p, If_Cut_t *pCut)
Definition ifCut.c:1056
float If_CutDelay(If_Man_t *p, If_Obj_t *pObj, If_Cut_t *pCut)
Definition ifTime.c:91
struct If_Cut_t_ If_Cut_t
Definition if.h:80
float If_CutAreaRef(If_Man_t *p, If_Cut_t *pCut)
Definition ifCut.c:1083
#define If_CutForEachLeaf(p, pCut, pLeaf, i)
Definition if.h:503
void If_ManComputeRequired(If_Man_t *p)
Definition ifTime.c:313
void If_CutOrder(If_Cut_t *pCut)
Definition ifCut.c:805
float If_CutAreaRefed(If_Man_t *p, If_Cut_t *pCut)
Definition ifCut.c:1133
struct If_Man_t_ If_Man_t
BASIC TYPES ///.
Definition if.h:77
#define If_ManForEachNode(p, pObj, i)
Definition if.h:497
struct If_Obj_t_ If_Obj_t
Definition if.h:79
int pLeaves[0]
Definition if.h:318
unsigned nLeaves
Definition if.h:316
float Delay
Definition if.h:306
unsigned uSign
Definition if.h:309
unsigned fMark
Definition if.h:338
int nRefs
Definition if.h:346
float Required
Definition if.h:353
int Id
Definition if.h:344
#define assert(ex)
Definition util_old.h:213
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55