1 /**CFile****************************************************************
2
3 FileName [rwrMan.c]
4
5 SystemName [ABC: Logic synthesis and verification system.]
6
7 PackageName [DAG-aware AIG rewriting package.]
8
9 Synopsis [Rewriting manager.]
10
11 Author [Alan Mishchenko]
12
13 Affiliation [UC Berkeley]
14
15 Date [Ver. 1.0. Started - June 20, 2005.]
16
17 Revision [$Id: rwrMan.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18
19 ***********************************************************************/
20
21 #include "rwr.h"
22 #include "base/main/main.h"
23 #include "bool/dec/dec.h"
24
25 ABC_NAMESPACE_IMPL_START
26
27
28 ////////////////////////////////////////////////////////////////////////
29 /// DECLARATIONS ///
30 ////////////////////////////////////////////////////////////////////////
31
32 ////////////////////////////////////////////////////////////////////////
33 /// FUNCTION DEFINITIONS ///
34 ////////////////////////////////////////////////////////////////////////
35
36 /**Function*************************************************************
37
38 Synopsis [Starts rewriting manager.]
39
40 Description []
41
42 SideEffects []
43
44 SeeAlso []
45
46 ***********************************************************************/
Rwr_ManStart(int fPrecompute)47 Rwr_Man_t * Rwr_ManStart( int fPrecompute )
48 {
49 Dec_Man_t * pManDec;
50 Rwr_Man_t * p;
51 abctime clk = Abc_Clock();
52 clk = Abc_Clock();
53 p = ABC_ALLOC( Rwr_Man_t, 1 );
54 memset( p, 0, sizeof(Rwr_Man_t) );
55 p->nFuncs = (1<<16);
56 pManDec = (Dec_Man_t *)Abc_FrameReadManDec();
57 p->puCanons = pManDec->puCanons;
58 p->pPhases = pManDec->pPhases;
59 p->pPerms = pManDec->pPerms;
60 p->pMap = pManDec->pMap;
61 // initialize practical NPN classes
62 p->pPractical = Rwr_ManGetPractical( p );
63 // create the table
64 p->pTable = ABC_ALLOC( Rwr_Node_t *, p->nFuncs );
65 memset( p->pTable, 0, sizeof(Rwr_Node_t *) * p->nFuncs );
66 // create the elementary nodes
67 p->pMmNode = Extra_MmFixedStart( sizeof(Rwr_Node_t) );
68 p->vForest = Vec_PtrAlloc( 100 );
69 Rwr_ManAddVar( p, 0x0000, fPrecompute ); // constant 0
70 Rwr_ManAddVar( p, 0xAAAA, fPrecompute ); // var A
71 Rwr_ManAddVar( p, 0xCCCC, fPrecompute ); // var B
72 Rwr_ManAddVar( p, 0xF0F0, fPrecompute ); // var C
73 Rwr_ManAddVar( p, 0xFF00, fPrecompute ); // var D
74 p->nClasses = 5;
75 // other stuff
76 p->nTravIds = 1;
77 p->pPerms4 = Extra_Permutations( 4 );
78 p->vLevNums = Vec_IntAlloc( 50 );
79 p->vFanins = Vec_PtrAlloc( 50 );
80 p->vFaninsCur = Vec_PtrAlloc( 50 );
81 p->vNodesTemp = Vec_PtrAlloc( 50 );
82 if ( fPrecompute )
83 { // precompute subgraphs
84 Rwr_ManPrecompute( p );
85 // Rwr_ManPrint( p );
86 Rwr_ManWriteToArray( p );
87 }
88 else
89 { // load saved subgraphs
90 Rwr_ManLoadFromArray( p, 0 );
91 // Rwr_ManPrint( p );
92 Rwr_ManPreprocess( p );
93 }
94 p->timeStart = Abc_Clock() - clk;
95 return p;
96 }
97
98 /**Function*************************************************************
99
100 Synopsis [Stops rewriting manager.]
101
102 Description []
103
104 SideEffects []
105
106 SeeAlso []
107
108 ***********************************************************************/
Rwr_ManStop(Rwr_Man_t * p)109 void Rwr_ManStop( Rwr_Man_t * p )
110 {
111 if ( p->vClasses )
112 {
113 Rwr_Node_t * pNode;
114 int i, k;
115 Vec_VecForEachEntry( Rwr_Node_t *, p->vClasses, pNode, i, k )
116 Dec_GraphFree( (Dec_Graph_t *)pNode->pNext );
117 }
118 if ( p->vClasses ) Vec_VecFree( p->vClasses );
119 Vec_PtrFree( p->vNodesTemp );
120 Vec_PtrFree( p->vForest );
121 Vec_IntFree( p->vLevNums );
122 Vec_PtrFree( p->vFanins );
123 Vec_PtrFree( p->vFaninsCur );
124 Extra_MmFixedStop( p->pMmNode );
125 ABC_FREE( p->pMapInv );
126 ABC_FREE( p->pTable );
127 ABC_FREE( p->pPractical );
128 ABC_FREE( p->pPerms4 );
129 ABC_FREE( p );
130 }
131
132 /**Function*************************************************************
133
134 Synopsis [Stops the resynthesis manager.]
135
136 Description []
137
138 SideEffects []
139
140 SeeAlso []
141
142 ***********************************************************************/
Rwr_ManPrintStats(Rwr_Man_t * p)143 void Rwr_ManPrintStats( Rwr_Man_t * p )
144 {
145 int i, Counter = 0;
146 for ( i = 0; i < 222; i++ )
147 Counter += (p->nScores[i] > 0);
148
149 printf( "Rewriting statistics:\n" );
150 printf( "Total cuts tries = %8d.\n", p->nCutsGood );
151 printf( "Bad cuts found = %8d.\n", p->nCutsBad );
152 printf( "Total subgraphs = %8d.\n", p->nSubgraphs );
153 printf( "Used NPN classes = %8d.\n", Counter );
154 printf( "Nodes considered = %8d.\n", p->nNodesConsidered );
155 printf( "Nodes rewritten = %8d.\n", p->nNodesRewritten );
156 printf( "Gain = %8d. (%6.2f %%).\n", p->nNodesBeg-p->nNodesEnd, 100.0*(p->nNodesBeg-p->nNodesEnd)/p->nNodesBeg );
157 ABC_PRT( "Start ", p->timeStart );
158 ABC_PRT( "Cuts ", p->timeCut );
159 ABC_PRT( "Resynthesis ", p->timeRes );
160 ABC_PRT( " Mffc ", p->timeMffc );
161 ABC_PRT( " Eval ", p->timeEval );
162 ABC_PRT( "Update ", p->timeUpdate );
163 ABC_PRT( "TOTAL ", p->timeTotal );
164
165 /*
166 printf( "The scores are:\n" );
167 for ( i = 0; i < 222; i++ )
168 if ( p->nScores[i] > 0 )
169 {
170 extern void Ivy_TruthDsdComputePrint( unsigned uTruth );
171 printf( "%3d = %8d canon = %5d ", i, p->nScores[i], p->pMapInv[i] );
172 Ivy_TruthDsdComputePrint( (unsigned)p->pMapInv[i] | ((unsigned)p->pMapInv[i] << 16) );
173 }
174 */
175 printf( "\n" );
176
177 }
178
179 /**Function*************************************************************
180
181 Synopsis [Stops the resynthesis manager.]
182
183 Description []
184
185 SideEffects []
186
187 SeeAlso []
188
189 ***********************************************************************/
Rwr_ManPrintStatsFile(Rwr_Man_t * p)190 void Rwr_ManPrintStatsFile( Rwr_Man_t * p )
191 {
192 FILE * pTable;
193 pTable = fopen( "stats.txt", "a+" );
194 fprintf( pTable, "%d ", p->nCutsGood );
195 fprintf( pTable, "%d ", p->nSubgraphs );
196 fprintf( pTable, "%d ", p->nNodesRewritten );
197 fprintf( pTable, "%d", p->nNodesGained );
198 fprintf( pTable, "\n" );
199 fclose( pTable );
200 }
201
202 /**Function*************************************************************
203
204 Synopsis [Stops the resynthesis manager.]
205
206 Description []
207
208 SideEffects []
209
210 SeeAlso []
211
212 ***********************************************************************/
Rwr_ManReadDecs(Rwr_Man_t * p)213 void * Rwr_ManReadDecs( Rwr_Man_t * p )
214 {
215 return p->pGraph;
216 }
217
218 /**Function*************************************************************
219
220 Synopsis [Stops the resynthesis manager.]
221
222 Description []
223
224 SideEffects []
225
226 SeeAlso []
227
228 ***********************************************************************/
Rwr_ManReadLeaves(Rwr_Man_t * p)229 Vec_Ptr_t * Rwr_ManReadLeaves( Rwr_Man_t * p )
230 {
231 return p->vFanins;
232 }
233
234 /**Function*************************************************************
235
236 Synopsis [Stops the resynthesis manager.]
237
238 Description []
239
240 SideEffects []
241
242 SeeAlso []
243
244 ***********************************************************************/
Rwr_ManReadCompl(Rwr_Man_t * p)245 int Rwr_ManReadCompl( Rwr_Man_t * p )
246 {
247 return p->fCompl;
248 }
249
250 /**Function*************************************************************
251
252 Synopsis [Stops the resynthesis manager.]
253
254 Description []
255
256 SideEffects []
257
258 SeeAlso []
259
260 ***********************************************************************/
Rwr_ManAddTimeCuts(Rwr_Man_t * p,abctime Time)261 void Rwr_ManAddTimeCuts( Rwr_Man_t * p, abctime Time )
262 {
263 p->timeCut += Time;
264 }
265
266 /**Function*************************************************************
267
268 Synopsis [Stops the resynthesis manager.]
269
270 Description []
271
272 SideEffects []
273
274 SeeAlso []
275
276 ***********************************************************************/
Rwr_ManAddTimeUpdate(Rwr_Man_t * p,abctime Time)277 void Rwr_ManAddTimeUpdate( Rwr_Man_t * p, abctime Time )
278 {
279 p->timeUpdate += Time;
280 }
281
282 /**Function*************************************************************
283
284 Synopsis [Stops the resynthesis manager.]
285
286 Description []
287
288 SideEffects []
289
290 SeeAlso []
291
292 ***********************************************************************/
Rwr_ManAddTimeTotal(Rwr_Man_t * p,abctime Time)293 void Rwr_ManAddTimeTotal( Rwr_Man_t * p, abctime Time )
294 {
295 p->timeTotal += Time;
296 }
297
298
299 /**Function*************************************************************
300
301 Synopsis [Precomputes AIG subgraphs.]
302
303 Description []
304
305 SideEffects []
306
307 SeeAlso []
308
309 ***********************************************************************/
Rwr_Precompute()310 void Rwr_Precompute()
311 {
312 Rwr_Man_t * p;
313 p = Rwr_ManStart( 1 );
314 Rwr_ManStop( p );
315 }
316
317 ////////////////////////////////////////////////////////////////////////
318 /// END OF FILE ///
319 ////////////////////////////////////////////////////////////////////////
320
321
322 ABC_NAMESPACE_IMPL_END
323
324