00001
00021 #include "cnf.h"
00022
00026
00030
00042 void Cnf_ManPostprocess_old( Cnf_Man_t * p )
00043 {
00044
00045 int nNew, Gain, nGain = 0, nVars = 0;
00046
00047 Aig_Obj_t * pObj, * pFan;
00048 Dar_Cut_t * pCutBest, * pCut;
00049 int i, k;
00050 Aig_ManForEachObj( p->pManAig, pObj, i )
00051 {
00052 if ( !Aig_ObjIsNode(pObj) )
00053 continue;
00054 if ( pObj->nRefs == 0 )
00055 continue;
00056
00057 pCutBest = NULL;
00058
00059 Dar_CutForEachLeaf( p->pManAig, pCutBest, pFan, k )
00060 {
00061 if ( !Aig_ObjIsNode(pFan) )
00062 continue;
00063 assert( pFan->nRefs != 0 );
00064 if ( pFan->nRefs != 1 )
00065 continue;
00066
00067 pCut = NULL;
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 nNew = 0;
00087
00088
00089
00090
00091
00092 Gain = pCutBest->Value + pCut->Value - nNew;
00093 if ( Gain > 0 )
00094 {
00095 nGain += Gain;
00096 nVars++;
00097 }
00098 }
00099 }
00100 printf( "Total gain = %d. Vars = %d.\n", nGain, nVars );
00101 }
00102
00114 void Cnf_ManTransferCuts( Cnf_Man_t * p )
00115 {
00116 Aig_Obj_t * pObj;
00117 int i;
00118 Aig_MmFlexRestart( p->pMemCuts );
00119 Aig_ManForEachObj( p->pManAig, pObj, i )
00120 {
00121 if ( Aig_ObjIsNode(pObj) && pObj->nRefs > 0 )
00122 pObj->pData = Cnf_CutCreate( p, pObj );
00123 else
00124 pObj->pData = NULL;
00125 }
00126 }
00127
00139 void Cnf_ManFreeCuts( Cnf_Man_t * p )
00140 {
00141 Aig_Obj_t * pObj;
00142 int i;
00143 Aig_ManForEachObj( p->pManAig, pObj, i )
00144 if ( pObj->pData )
00145 {
00146 Cnf_CutFree( pObj->pData );
00147 pObj->pData = NULL;
00148 }
00149 }
00150
00162 void Cnf_ManPostprocess( Cnf_Man_t * p )
00163 {
00164 Cnf_Cut_t * pCut, * pCutFan, * pCutRes;
00165 Aig_Obj_t * pObj, * pFan;
00166 int Order[16], Costs[16];
00167 int i, k, fChanges;
00168 Aig_ManForEachNode( p->pManAig, pObj, i )
00169 {
00170 if ( pObj->nRefs == 0 )
00171 continue;
00172 pCut = Cnf_ObjBestCut(pObj);
00173
00174
00175 Cnf_CutForEachLeaf( p->pManAig, pCut, pFan, k )
00176 {
00177 Order[k] = k;
00178 Costs[k] = Aig_ObjIsNode(pFan)? Cnf_ObjBestCut(pFan)->Cost : 0;
00179 }
00180
00181 do {
00182 int Temp;
00183 fChanges = 0;
00184 for ( k = 0; k < pCut->nFanins - 1; k++ )
00185 {
00186 if ( Costs[Order[k]] <= Costs[Order[k+1]] )
00187 continue;
00188 Temp = Order[k];
00189 Order[k] = Order[k+1];
00190 Order[k+1] = Temp;
00191 fChanges = 1;
00192 }
00193 } while ( fChanges );
00194
00195
00196
00197 for ( k = 0; (k < (int)(pCut)->nFanins) && ((pFan) = Aig_ManObj(p->pManAig, (pCut)->pFanins[Order[k]])); k++ )
00198 {
00199 if ( !Aig_ObjIsNode(pFan) )
00200 continue;
00201 assert( pFan->nRefs != 0 );
00202 if ( pFan->nRefs != 1 )
00203 continue;
00204 pCutFan = Cnf_ObjBestCut(pFan);
00205
00206
00207 pCutRes = Cnf_CutCompose( p, pCut, pCutFan, pFan->Id );
00208
00209
00210
00211 if ( pCutRes == NULL || pCutRes->Cost == 127 || pCutRes->Cost > pCut->Cost + pCutFan->Cost )
00212 {
00213 if ( pCutRes )
00214 Cnf_CutFree( pCutRes );
00215 continue;
00216 }
00217
00218 Cnf_ObjSetBestCut( pObj, pCutRes );
00219 Cnf_ObjSetBestCut( pFan, NULL );
00220 Cnf_CutUpdateRefs( p, pCut, pCutFan, pCutRes );
00221 assert( pFan->nRefs == 0 );
00222 Cnf_CutFree( pCut );
00223 Cnf_CutFree( pCutFan );
00224 break;
00225 }
00226 }
00227 }
00228
00232
00233