00001
00021 #include "if.h"
00022
00026
00027 static void If_ManImproveReduce( If_Man_t * p, int nLimit );
00028 static void If_ManImproveExpand( If_Man_t * p, int nLimit );
00029 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 );
00030 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 );
00031 static void If_ManImproveNodeUpdate( If_Man_t * p, If_Obj_t * pObj, Vec_Ptr_t * vFront );
00032 static void If_ManImproveNodeFaninCompact( If_Man_t * p, If_Obj_t * pObj, int nLimit, Vec_Ptr_t * vFront, Vec_Ptr_t * vVisited );
00033
00037
00049 void If_ManImproveMapping( If_Man_t * p )
00050 {
00051 int clk;
00052
00053 clk = clock();
00054 If_ManImproveExpand( p, p->pPars->nLutSize );
00055 If_ManComputeRequired( p );
00056 if ( p->pPars->fVerbose )
00057 {
00058 printf( "E: Del = %7.2f. Ar = %9.1f. Edge = %8d. Cut = %8d. ",
00059 p->RequiredGlo, p->AreaGlo, p->nNets, p->nCutsMerged );
00060 PRT( "T", clock() - clk );
00061 }
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 }
00086
00098 void If_ManImproveExpand( If_Man_t * p, int nLimit )
00099 {
00100 Vec_Ptr_t * vFront, * vFrontOld, * vVisited;
00101 If_Obj_t * pObj;
00102 int i;
00103 vFront = Vec_PtrAlloc( nLimit );
00104 vFrontOld = Vec_PtrAlloc( nLimit );
00105 vVisited = Vec_PtrAlloc( 100 );
00106
00107 If_ManForEachNode( p, pObj, i )
00108 If_ManImproveNodeExpand( p, pObj, nLimit, vFront, vFrontOld, vVisited );
00109 Vec_PtrFree( vFront );
00110 Vec_PtrFree( vFrontOld );
00111 Vec_PtrFree( vVisited );
00112 }
00113
00125 int If_ManImproveCutCost( If_Man_t * p, Vec_Ptr_t * vFront )
00126 {
00127 If_Obj_t * pFanin;
00128 int i, Counter = 0;
00129 Vec_PtrForEachEntry( vFront, pFanin, i )
00130 if ( pFanin->nRefs == 0 )
00131 Counter++;
00132 return Counter;
00133 }
00134
00146 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 )
00147 {
00148 If_Obj_t * pFanin;
00149 If_Cut_t * pCut;
00150 int CostBef, CostAft, i;
00151 float DelayOld, AreaBef, AreaAft;
00152 pCut = If_ObjCutBest(pObj);
00153 assert( pCut->Delay <= pObj->Required + p->fEpsilon );
00154 if ( pObj->nRefs == 0 )
00155 return;
00156
00157 DelayOld = pCut->Delay;
00158
00159 AreaBef = If_CutAreaRefed( p, pCut, IF_INFINITY );
00160
00161
00162
00163 If_ManImproveNodePrepare( p, pObj, nLimit, vFront, vFrontOld, vVisited );
00164
00165 If_CutDeref( p, pCut, IF_INFINITY );
00166 CostBef = If_ManImproveCutCost( p, vFront );
00167 If_ManImproveNodeFaninCompact( p, pObj, nLimit, vFront, vVisited );
00168 CostAft = If_ManImproveCutCost( p, vFront );
00169 If_CutRef( p, pCut, IF_INFINITY );
00170 assert( CostBef >= CostAft );
00171
00172 Vec_PtrForEachEntry( vVisited, pFanin, i )
00173 pFanin->fMark = 0;
00174
00175 If_ManImproveNodeUpdate( p, pObj, vFront );
00176 pCut->Delay = If_CutDelay( p, pCut );
00177
00178 AreaAft = If_CutAreaRefed( p, pCut, IF_INFINITY );
00179 if ( AreaAft > AreaBef || pCut->Delay > pObj->Required + p->fEpsilon )
00180 {
00181 If_ManImproveNodeUpdate( p, pObj, vFrontOld );
00182 AreaAft = If_CutAreaRefed( p, pCut, IF_INFINITY );
00183 assert( AreaAft == AreaBef );
00184 pCut->Delay = DelayOld;
00185 }
00186 }
00187
00199 void If_ManImproveMark_rec( If_Man_t * p, If_Obj_t * pObj, Vec_Ptr_t * vVisited )
00200 {
00201 if ( pObj->fMark )
00202 return;
00203 assert( If_ObjIsAnd(pObj) );
00204 If_ManImproveMark_rec( p, If_ObjFanin0(pObj), vVisited );
00205 If_ManImproveMark_rec( p, If_ObjFanin1(pObj), vVisited );
00206 Vec_PtrPush( vVisited, pObj );
00207 pObj->fMark = 1;
00208 }
00209
00221 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 )
00222 {
00223 If_Cut_t * pCut;
00224 If_Obj_t * pLeaf;
00225 int i;
00226 Vec_PtrClear( vFront );
00227 Vec_PtrClear( vFrontOld );
00228 Vec_PtrClear( vVisited );
00229
00230 pCut = If_ObjCutBest(pObj);
00231 If_CutForEachLeaf( p, pCut, pLeaf, i )
00232 {
00233 Vec_PtrPush( vFront, pLeaf );
00234 Vec_PtrPush( vFrontOld, pLeaf );
00235 Vec_PtrPush( vVisited, pLeaf );
00236 pLeaf->fMark = 1;
00237 }
00238
00239 If_ManImproveMark_rec( p, pObj, vVisited );
00240 }
00241
00253 void If_ManImproveNodeUpdate( If_Man_t * p, If_Obj_t * pObj, Vec_Ptr_t * vFront )
00254 {
00255 If_Cut_t * pCut;
00256 If_Obj_t * pFanin;
00257 int i;
00258 pCut = If_ObjCutBest(pObj);
00259
00260 If_CutDeref( p, pCut, IF_INFINITY );
00261
00262 pCut->nLeaves = Vec_PtrSize(vFront);
00263 Vec_PtrForEachEntry( vFront, pFanin, i )
00264 pCut->pLeaves[i] = pFanin->Id;
00265
00266 If_CutRef( p, pCut, IF_INFINITY );
00267 }
00268
00269
00281 int If_ManImproveNodeWillGrow( If_Man_t * p, If_Obj_t * pObj )
00282 {
00283 If_Obj_t * pFanin0, * pFanin1;
00284 assert( If_ObjIsAnd(pObj) );
00285 pFanin0 = If_ObjFanin0(pObj);
00286 pFanin1 = If_ObjFanin1(pObj);
00287 return !pFanin0->fMark && !pFanin1->fMark;
00288 }
00289
00301 int If_ManImproveNodeFaninCost( If_Man_t * p, If_Obj_t * pObj )
00302 {
00303 int Counter = 0;
00304 assert( If_ObjIsAnd(pObj) );
00305
00306 if ( pObj->nRefs == 0 )
00307 Counter--;
00308
00309 if ( !If_ObjFanin0(pObj)->fMark && If_ObjFanin0(pObj)->nRefs == 0 )
00310 Counter++;
00311
00312 if ( !If_ObjFanin1(pObj)->fMark && If_ObjFanin1(pObj)->nRefs == 0 )
00313 Counter++;
00314 return Counter;
00315 }
00316
00328 void If_ManImproveNodeFaninUpdate( If_Man_t * p, If_Obj_t * pObj, Vec_Ptr_t * vFront, Vec_Ptr_t * vVisited )
00329 {
00330 If_Obj_t * pFanin;
00331 assert( If_ObjIsAnd(pObj) );
00332 Vec_PtrRemove( vFront, pObj );
00333 pFanin = If_ObjFanin0(pObj);
00334 if ( !pFanin->fMark )
00335 {
00336 Vec_PtrPush( vFront, pFanin );
00337 Vec_PtrPush( vVisited, pFanin );
00338 pFanin->fMark = 1;
00339 }
00340 pFanin = If_ObjFanin1(pObj);
00341 if ( !pFanin->fMark )
00342 {
00343 Vec_PtrPush( vFront, pFanin );
00344 Vec_PtrPush( vVisited, pFanin );
00345 pFanin->fMark = 1;
00346 }
00347 }
00348
00360 int If_ManImproveNodeFaninCompact0( If_Man_t * p, If_Obj_t * pObj, int nLimit, Vec_Ptr_t * vFront, Vec_Ptr_t * vVisited )
00361 {
00362 If_Obj_t * pFanin;
00363 int i;
00364 Vec_PtrForEachEntry( vFront, pFanin, i )
00365 {
00366 if ( If_ObjIsCi(pFanin) )
00367 continue;
00368 if ( If_ManImproveNodeWillGrow(p, pFanin) )
00369 continue;
00370 if ( If_ManImproveNodeFaninCost(p, pFanin) <= 0 )
00371 {
00372 If_ManImproveNodeFaninUpdate( p, pFanin, vFront, vVisited );
00373 return 1;
00374 }
00375 }
00376 return 0;
00377 }
00378
00390 int If_ManImproveNodeFaninCompact1( If_Man_t * p, If_Obj_t * pObj, int nLimit, Vec_Ptr_t * vFront, Vec_Ptr_t * vVisited )
00391 {
00392 If_Obj_t * pFanin;
00393 int i;
00394 Vec_PtrForEachEntry( vFront, pFanin, i )
00395 {
00396 if ( If_ObjIsCi(pFanin) )
00397 continue;
00398 if ( If_ManImproveNodeFaninCost(p, pFanin) < 0 )
00399 {
00400 If_ManImproveNodeFaninUpdate( p, pFanin, vFront, vVisited );
00401 return 1;
00402 }
00403 }
00404 return 0;
00405 }
00406
00418 int If_ManImproveNodeFaninCompact2( If_Man_t * p, If_Obj_t * pObj, int nLimit, Vec_Ptr_t * vFront, Vec_Ptr_t * vVisited )
00419 {
00420 If_Obj_t * pFanin;
00421 int i;
00422 Vec_PtrForEachEntry( vFront, pFanin, i )
00423 {
00424 if ( If_ObjIsCi(pFanin) )
00425 continue;
00426 if ( If_ManImproveNodeFaninCost(p, pFanin) <= 0 )
00427 {
00428 If_ManImproveNodeFaninUpdate( p, pFanin, vFront, vVisited );
00429 return 1;
00430 }
00431 }
00432 return 0;
00433 }
00434
00446 int If_ManImproveNodeFaninCompact_int( If_Man_t * p, If_Obj_t * pObj, int nLimit, Vec_Ptr_t * vFront, Vec_Ptr_t * vVisited )
00447 {
00448 if ( If_ManImproveNodeFaninCompact0(p, pObj, nLimit, vFront, vVisited) )
00449 return 1;
00450 if ( Vec_PtrSize(vFront) < nLimit && If_ManImproveNodeFaninCompact1(p, pObj, nLimit, vFront, vVisited) )
00451 return 1;
00452 if ( Vec_PtrSize(vFront) < nLimit && If_ManImproveNodeFaninCompact2(p, pObj, nLimit, vFront, vVisited) )
00453 return 1;
00454 assert( Vec_PtrSize(vFront) <= nLimit );
00455 return 0;
00456 }
00457
00469 void If_ManImproveNodeFaninCompact( If_Man_t * p, If_Obj_t * pObj, int nLimit, Vec_Ptr_t * vFront, Vec_Ptr_t * vVisited )
00470 {
00471 while ( If_ManImproveNodeFaninCompact_int( p, pObj, nLimit, vFront, vVisited ) );
00472 }
00473
00474
00475
00476
00477
00489 void If_ManImproveNodeReduce( If_Man_t * p, If_Obj_t * pObj, int nLimit )
00490 {
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549 }
00550
00562 void If_ManImproveReduce( If_Man_t * p, int nLimit )
00563 {
00564 If_Obj_t * pObj;
00565 int i;
00566 If_ManForEachNode( p, pObj, i )
00567 If_ManImproveNodeReduce( p, pObj, nLimit );
00568 }
00569
00573
00574