abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
darRefact.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [darRefact.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [DAG-aware AIG rewriting.]
8 
9  Synopsis [Refactoring.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - April 28, 2007.]
16 
17  Revision [$Id: darRefact.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "darInt.h"
22 #include "bool/kit/kit.h"
23 
24 #include "bool/bdc/bdc.h"
25 #include "bool/bdc/bdcInt.h"
26 
28 
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// DECLARATIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 // the refactoring manager
35 typedef struct Ref_Man_t_ Ref_Man_t;
36 struct Ref_Man_t_
37 {
38  // input data
39  Dar_RefPar_t * pPars; // rewriting parameters
40  Aig_Man_t * pAig; // AIG manager
41  // computed cuts
42  Vec_Vec_t * vCuts; // the storage for cuts
43  // truth table and ISOP
44  Vec_Ptr_t * vTruthElem; // elementary truth tables
45  Vec_Ptr_t * vTruthStore; // storage for truth tables
46  Vec_Int_t * vMemory; // storage for ISOP
47  Vec_Ptr_t * vCutNodes; // storage for internal nodes of the cut
48  // various data members
49  Vec_Ptr_t * vLeavesBest; // the best set of leaves
50  Kit_Graph_t * pGraphBest; // the best factored form
51  int GainBest; // the best gain
52  int LevelBest; // the level of node with the best gain
53  // bi-decomposition
54  Bdc_Par_t DecPars; // decomposition parameters
55  Bdc_Man_t * pManDec; // decomposition manager
56  // node statistics
57  int nNodesInit; // the initial number of nodes
58  int nNodesTried; // the number of nodes tried
59  int nNodesBelow; // the number of nodes below the level limit
60  int nNodesExten; // the number of nodes with extended cut
61  int nCutsUsed; // the number of rewriting steps
62  int nCutsTried; // the number of cuts tries
63  // timing statistics
68 };
69 
70 ////////////////////////////////////////////////////////////////////////
71 /// FUNCTION DEFINITIONS ///
72 ////////////////////////////////////////////////////////////////////////
73 
74 /**Function*************************************************************
75 
76  Synopsis [Returns the structure with default assignment of parameters.]
77 
78  Description []
79 
80  SideEffects []
81 
82  SeeAlso []
83 
84 ***********************************************************************/
86 {
87  memset( pPars, 0, sizeof(Dar_RefPar_t) );
88  pPars->nMffcMin = 2; // the min MFFC size for which refactoring is used
89  pPars->nLeafMax = 12; // the max number of leaves of a cut
90  pPars->nCutsMax = 5; // the max number of cuts to consider
91  pPars->fUpdateLevel = 0;
92  pPars->fUseZeros = 0;
93  pPars->fVerbose = 0;
94  pPars->fVeryVerbose = 0;
95 }
96 
97 /**Function*************************************************************
98 
99  Synopsis [Starts the rewriting manager.]
100 
101  Description []
102 
103  SideEffects []
104 
105  SeeAlso []
106 
107 ***********************************************************************/
109 {
110  Ref_Man_t * p;
111  // start the manager
112  p = ABC_ALLOC( Ref_Man_t, 1 );
113  memset( p, 0, sizeof(Ref_Man_t) );
114  p->pAig = pAig;
115  p->pPars = pPars;
116  // other data
117  p->vCuts = Vec_VecStart( pPars->nCutsMax );
118  p->vTruthElem = Vec_PtrAllocTruthTables( pPars->nLeafMax );
119  p->vTruthStore = Vec_PtrAllocSimInfo( 1024, Kit_TruthWordNum(pPars->nLeafMax) );
120  p->vMemory = Vec_IntAlloc( 1 << 16 );
121  p->vCutNodes = Vec_PtrAlloc( 256 );
122  p->vLeavesBest = Vec_PtrAlloc( pPars->nLeafMax );
123  // alloc bi-decomposition manager
124  p->DecPars.nVarsMax = pPars->nLeafMax;
125  p->DecPars.fVerbose = pPars->fVerbose;
126  p->DecPars.fVeryVerbose = 0;
127 // p->pManDec = Bdc_ManAlloc( &p->DecPars );
128  return p;
129 }
130 
131 /**Function*************************************************************
132 
133  Synopsis [Prints out the statistics of the manager.]
134 
135  Description []
136 
137  SideEffects []
138 
139  SeeAlso []
140 
141 ***********************************************************************/
143 {
144  int Gain = p->nNodesInit - Aig_ManNodeNum(p->pAig);
145  printf( "NodesBeg = %8d. NodesEnd = %8d. Gain = %6d. (%6.2f %%).\n",
146  p->nNodesInit, Aig_ManNodeNum(p->pAig), Gain, 100.0*Gain/p->nNodesInit );
147  printf( "Tried = %6d. Below = %5d. Extended = %5d. Used = %5d. Levels = %4d.\n",
148  p->nNodesTried, p->nNodesBelow, p->nNodesExten, p->nCutsUsed, Aig_ManLevels(p->pAig) );
149  ABC_PRT( "Cuts ", p->timeCuts );
150  ABC_PRT( "Eval ", p->timeEval );
151  ABC_PRT( "Other ", p->timeOther );
152  ABC_PRT( "TOTAL ", p->timeTotal );
153 }
154 
155 /**Function*************************************************************
156 
157  Synopsis [Stops the rewriting manager.]
158 
159  Description []
160 
161  SideEffects []
162 
163  SeeAlso []
164 
165 ***********************************************************************/
167 {
168  if ( p->pManDec )
169  Bdc_ManFree( p->pManDec );
170  if ( p->pPars->fVerbose )
172  Vec_VecFree( p->vCuts );
173  Vec_PtrFree( p->vTruthElem );
174  Vec_PtrFree( p->vTruthStore );
175  Vec_PtrFree( p->vLeavesBest );
176  Vec_IntFree( p->vMemory );
177  Vec_PtrFree( p->vCutNodes );
178  ABC_FREE( p );
179 }
180 
181 /**Function*************************************************************
182 
183  Synopsis []
184 
185  Description []
186 
187  SideEffects []
188 
189  SeeAlso []
190 
191 ***********************************************************************/
192 void Ref_ObjComputeCuts( Aig_Man_t * pAig, Aig_Obj_t * pRoot, Vec_Vec_t * vCuts )
193 {
194 }
195 
196 /**Function*************************************************************
197 
198  Synopsis []
199 
200  Description []
201 
202  SideEffects []
203 
204  SeeAlso []
205 
206 ***********************************************************************/
207 void Ref_ObjPrint( Aig_Obj_t * pObj )
208 {
209  printf( "%d", pObj? Aig_Regular(pObj)->Id : -1 );
210  if ( pObj )
211  printf( "(%d) ", Aig_IsComplement(pObj) );
212 }
213 
214 /**Function*************************************************************
215 
216  Synopsis [Counts the number of new nodes added when using this graph.]
217 
218  Description [AIG nodes for the fanins should be assigned to pNode->pFunc
219  of the leaves of the graph before calling this procedure.
220  Returns -1 if the number of nodes and levels exceeded the given limit or
221  the number of levels exceeded the maximum allowed level.]
222 
223  SideEffects []
224 
225  SeeAlso []
226 
227 ***********************************************************************/
228 int Dar_RefactTryGraph( Aig_Man_t * pAig, Aig_Obj_t * pRoot, Vec_Ptr_t * vCut, Kit_Graph_t * pGraph, int NodeMax, int LevelMax )
229 {
230  Kit_Node_t * pNode, * pNode0, * pNode1;
231  Aig_Obj_t * pAnd, * pAnd0, * pAnd1;
232  int i, Counter, LevelNew, LevelOld;
233  // check for constant function or a literal
234  if ( Kit_GraphIsConst(pGraph) || Kit_GraphIsVar(pGraph) )
235  return 0;
236  // set the levels of the leaves
237  Kit_GraphForEachLeaf( pGraph, pNode, i )
238  {
239  pNode->pFunc = Vec_PtrEntry(vCut, i);
240  pNode->Level = Aig_Regular((Aig_Obj_t *)pNode->pFunc)->Level;
241  assert( Aig_Regular((Aig_Obj_t *)pNode->pFunc)->Level < (1<<24)-1 );
242  }
243 //printf( "Trying:\n" );
244  // compute the AIG size after adding the internal nodes
245  Counter = 0;
246  Kit_GraphForEachNode( pGraph, pNode, i )
247  {
248  // get the children of this node
249  pNode0 = Kit_GraphNode( pGraph, pNode->eEdge0.Node );
250  pNode1 = Kit_GraphNode( pGraph, pNode->eEdge1.Node );
251  // get the AIG nodes corresponding to the children
252  pAnd0 = (Aig_Obj_t *)pNode0->pFunc;
253  pAnd1 = (Aig_Obj_t *)pNode1->pFunc;
254  if ( pAnd0 && pAnd1 )
255  {
256  // if they are both present, find the resulting node
257  pAnd0 = Aig_NotCond( pAnd0, pNode->eEdge0.fCompl );
258  pAnd1 = Aig_NotCond( pAnd1, pNode->eEdge1.fCompl );
259  pAnd = Aig_TableLookupTwo( pAig, pAnd0, pAnd1 );
260  // return -1 if the node is the same as the original root
261  if ( Aig_Regular(pAnd) == pRoot )
262  return -1;
263  }
264  else
265  pAnd = NULL;
266  // count the number of added nodes
267  if ( pAnd == NULL || Aig_ObjIsTravIdCurrent(pAig, Aig_Regular(pAnd)) )
268  {
269  if ( ++Counter > NodeMax )
270  return -1;
271  }
272  // count the number of new levels
273  LevelNew = 1 + Abc_MaxInt( pNode0->Level, pNode1->Level );
274  if ( pAnd )
275  {
276  if ( Aig_Regular(pAnd) == Aig_ManConst1(pAig) )
277  LevelNew = 0;
278  else if ( Aig_Regular(pAnd) == Aig_Regular(pAnd0) )
279  LevelNew = (int)Aig_Regular(pAnd0)->Level;
280  else if ( Aig_Regular(pAnd) == Aig_Regular(pAnd1) )
281  LevelNew = (int)Aig_Regular(pAnd1)->Level;
282  LevelOld = (int)Aig_Regular(pAnd)->Level;
283 // assert( LevelNew == LevelOld );
284  }
285  if ( LevelNew > LevelMax )
286  return -1;
287  pNode->pFunc = pAnd;
288  pNode->Level = LevelNew;
289 /*
290 printf( "Checking " );
291 Ref_ObjPrint( pAnd0 );
292 printf( " and " );
293 Ref_ObjPrint( pAnd1 );
294 printf( " Result " );
295 Ref_ObjPrint( pNode->pFunc );
296 printf( "\n" );
297 */
298  }
299  return Counter;
300 }
301 
302 /**Function*************************************************************
303 
304  Synopsis []
305 
306  Description []
307 
308  SideEffects []
309 
310  SeeAlso []
311 
312 ***********************************************************************/
314 {
315  Aig_Obj_t * pAnd0, * pAnd1;
316  Kit_Node_t * pNode = NULL;
317  int i;
318  // check for constant function
319  if ( Kit_GraphIsConst(pGraph) )
320  return Aig_NotCond( Aig_ManConst1(pAig), Kit_GraphIsComplement(pGraph) );
321  // set the leaves
322  Kit_GraphForEachLeaf( pGraph, pNode, i )
323  pNode->pFunc = Vec_PtrEntry(vCut, i);
324  // check for a literal
325  if ( Kit_GraphIsVar(pGraph) )
326  return Aig_NotCond( (Aig_Obj_t *)Kit_GraphVar(pGraph)->pFunc, Kit_GraphIsComplement(pGraph) );
327  // build the AIG nodes corresponding to the AND gates of the graph
328 //printf( "Building (current number %d):\n", Aig_ManObjNumMax(pAig) );
329  Kit_GraphForEachNode( pGraph, pNode, i )
330  {
331  pAnd0 = Aig_NotCond( (Aig_Obj_t *)Kit_GraphNode(pGraph, pNode->eEdge0.Node)->pFunc, pNode->eEdge0.fCompl );
332  pAnd1 = Aig_NotCond( (Aig_Obj_t *)Kit_GraphNode(pGraph, pNode->eEdge1.Node)->pFunc, pNode->eEdge1.fCompl );
333  pNode->pFunc = Aig_And( pAig, pAnd0, pAnd1 );
334 /*
335 printf( "Checking " );
336 Ref_ObjPrint( pAnd0 );
337 printf( " and " );
338 Ref_ObjPrint( pAnd1 );
339 printf( " Result " );
340 Ref_ObjPrint( pNode->pFunc );
341 printf( "\n" );
342 */
343  }
344  // complement the result if necessary
345  return Aig_NotCond( (Aig_Obj_t *)pNode->pFunc, Kit_GraphIsComplement(pGraph) );
346 }
347 
348 /**Function*************************************************************
349 
350  Synopsis []
351 
352  Description []
353 
354  SideEffects []
355 
356  SeeAlso []
357 
358 ***********************************************************************/
359 int Dar_ManRefactorTryCuts( Ref_Man_t * p, Aig_Obj_t * pObj, int nNodesSaved, int Required )
360 {
361  Vec_Ptr_t * vCut;
362  Kit_Graph_t * pGraphCur;
363  int k, RetValue, GainCur, nNodesAdded;
364  unsigned * pTruth;
365 
366  p->GainBest = -1;
367  p->pGraphBest = NULL;
368  Vec_VecForEachLevel( p->vCuts, vCut, k )
369  {
370  if ( Vec_PtrSize(vCut) == 0 )
371  continue;
372 // if ( Vec_PtrSize(vCut) != 0 && Vec_PtrSize(Vec_VecEntry(p->vCuts, k+1)) != 0 )
373 // continue;
374 
375  p->nCutsTried++;
376  // get the cut nodes
377  Aig_ObjCollectCut( pObj, vCut, p->vCutNodes );
378  // get the truth table
379  pTruth = Aig_ManCutTruth( pObj, vCut, p->vCutNodes, p->vTruthElem, p->vTruthStore );
380  if ( Kit_TruthIsConst0(pTruth, Vec_PtrSize(vCut)) )
381  {
382  p->GainBest = Aig_NodeMffcSupp( p->pAig, pObj, 0, NULL );
383  p->pGraphBest = Kit_GraphCreateConst0();
384  Vec_PtrCopy( p->vLeavesBest, vCut );
385  return p->GainBest;
386  }
387  if ( Kit_TruthIsConst1(pTruth, Vec_PtrSize(vCut)) )
388  {
389  p->GainBest = Aig_NodeMffcSupp( p->pAig, pObj, 0, NULL );
390  p->pGraphBest = Kit_GraphCreateConst1();
391  Vec_PtrCopy( p->vLeavesBest, vCut );
392  return p->GainBest;
393  }
394 
395  // try the positive phase
396  RetValue = Kit_TruthIsop( pTruth, Vec_PtrSize(vCut), p->vMemory, 0 );
397  if ( RetValue > -1 )
398  {
399  pGraphCur = Kit_SopFactor( p->vMemory, 0, Vec_PtrSize(vCut), p->vMemory );
400 /*
401 {
402  int RetValue;
403  RetValue = Bdc_ManDecompose( p->pManDec, pTruth, NULL, Vec_PtrSize(vCut), NULL, 1000 );
404  printf( "Graph = %d. Bidec = %d.\n", Kit_GraphNodeNum(pGraphCur), RetValue );
405 }
406 */
407  nNodesAdded = Dar_RefactTryGraph( p->pAig, pObj, vCut, pGraphCur, nNodesSaved - !p->pPars->fUseZeros, Required );
408  if ( nNodesAdded > -1 )
409  {
410  GainCur = nNodesSaved - nNodesAdded;
411  if ( p->GainBest < GainCur || (p->GainBest == GainCur &&
412  (Kit_GraphIsConst(pGraphCur) || Kit_GraphRootLevel(pGraphCur) < Kit_GraphRootLevel(p->pGraphBest))) )
413  {
414  p->GainBest = GainCur;
415  if ( p->pGraphBest )
416  Kit_GraphFree( p->pGraphBest );
417  p->pGraphBest = pGraphCur;
418  Vec_PtrCopy( p->vLeavesBest, vCut );
419  }
420  else
421  Kit_GraphFree( pGraphCur );
422  }
423  else
424  Kit_GraphFree( pGraphCur );
425  }
426  // try negative phase
427  Kit_TruthNot( pTruth, pTruth, Vec_PtrSize(vCut) );
428  RetValue = Kit_TruthIsop( pTruth, Vec_PtrSize(vCut), p->vMemory, 0 );
429 // Kit_TruthNot( pTruth, pTruth, Vec_PtrSize(vCut) );
430  if ( RetValue > -1 )
431  {
432  pGraphCur = Kit_SopFactor( p->vMemory, 1, Vec_PtrSize(vCut), p->vMemory );
433 /*
434 {
435  int RetValue;
436  RetValue = Bdc_ManDecompose( p->pManDec, pTruth, NULL, Vec_PtrSize(vCut), NULL, 1000 );
437  printf( "Graph = %d. Bidec = %d.\n", Kit_GraphNodeNum(pGraphCur), RetValue );
438 }
439 */
440  nNodesAdded = Dar_RefactTryGraph( p->pAig, pObj, vCut, pGraphCur, nNodesSaved - !p->pPars->fUseZeros, Required );
441  if ( nNodesAdded > -1 )
442  {
443  GainCur = nNodesSaved - nNodesAdded;
444  if ( p->GainBest < GainCur || (p->GainBest == GainCur &&
445  (Kit_GraphIsConst(pGraphCur) || Kit_GraphRootLevel(pGraphCur) < Kit_GraphRootLevel(p->pGraphBest))) )
446  {
447  p->GainBest = GainCur;
448  if ( p->pGraphBest )
449  Kit_GraphFree( p->pGraphBest );
450  p->pGraphBest = pGraphCur;
451  Vec_PtrCopy( p->vLeavesBest, vCut );
452  }
453  else
454  Kit_GraphFree( pGraphCur );
455  }
456  else
457  Kit_GraphFree( pGraphCur );
458  }
459  }
460 
461  return p->GainBest;
462 }
463 
464 /**Function*************************************************************
465 
466  Synopsis [Returns 1 if a non-PI node has nLevelMin or below.]
467 
468  Description []
469 
470  SideEffects []
471 
472  SeeAlso []
473 
474 ***********************************************************************/
475 int Dar_ObjCutLevelAchieved( Vec_Ptr_t * vCut, int nLevelMin )
476 {
477  Aig_Obj_t * pObj;
478  int i;
479  Vec_PtrForEachEntry( Aig_Obj_t *, vCut, pObj, i )
480  if ( !Aig_ObjIsCi(pObj) && (int)pObj->Level <= nLevelMin )
481  return 1;
482  return 0;
483 }
484 
485 /**Function*************************************************************
486 
487  Synopsis []
488 
489  Description []
490 
491  SideEffects []
492 
493  SeeAlso []
494 
495 ***********************************************************************/
496 int Dar_ManRefactor( Aig_Man_t * pAig, Dar_RefPar_t * pPars )
497 {
498 // Bar_Progress_t * pProgress;
499  Ref_Man_t * p;
500  Vec_Ptr_t * vCut, * vCut2;
501  Aig_Obj_t * pObj, * pObjNew;
502  int nNodesOld, nNodeBefore, nNodeAfter, nNodesSaved, nNodesSaved2;
503  int i, Required, nLevelMin;
504  abctime clkStart, clk;
505 
506  // start the manager
507  p = Dar_ManRefStart( pAig, pPars );
508  // remove dangling nodes
509  Aig_ManCleanup( pAig );
510  // if updating levels is requested, start fanout and timing
511  Aig_ManFanoutStart( pAig );
512  if ( p->pPars->fUpdateLevel )
513  Aig_ManStartReverseLevels( pAig, 0 );
514 
515  // resynthesize each node once
516  clkStart = Abc_Clock();
517  vCut = Vec_VecEntry( p->vCuts, 0 );
518  vCut2 = Vec_VecEntry( p->vCuts, 1 );
519  p->nNodesInit = Aig_ManNodeNum(pAig);
520  nNodesOld = Vec_PtrSize( pAig->vObjs );
521 // pProgress = Bar_ProgressStart( stdout, nNodesOld );
522  Aig_ManForEachObj( pAig, pObj, i )
523  {
524 // Bar_ProgressUpdate( pProgress, i, NULL );
525  if ( !Aig_ObjIsNode(pObj) )
526  continue;
527  if ( i > nNodesOld )
528  break;
529  if ( pAig->Time2Quit && !(i & 256) && Abc_Clock() > pAig->Time2Quit )
530  break;
531  Vec_VecClear( p->vCuts );
532 
533 //printf( "\nConsidering node %d.\n", pObj->Id );
534  // get the bounded MFFC size
535 clk = Abc_Clock();
536  nLevelMin = Abc_MaxInt( 0, Aig_ObjLevel(pObj) - 10 );
537  nNodesSaved = Aig_NodeMffcSupp( pAig, pObj, nLevelMin, vCut );
538  if ( nNodesSaved < p->pPars->nMffcMin ) // too small to consider
539  {
540 p->timeCuts += Abc_Clock() - clk;
541  continue;
542  }
543  p->nNodesTried++;
544  if ( Vec_PtrSize(vCut) > p->pPars->nLeafMax ) // get one reconv-driven cut
545  {
546  Aig_ManFindCut( pObj, vCut, p->vCutNodes, p->pPars->nLeafMax, 50 );
547  nNodesSaved = Aig_NodeMffcLabelCut( p->pAig, pObj, vCut );
548  }
549  else if ( Vec_PtrSize(vCut) < p->pPars->nLeafMax - 2 && p->pPars->fExtend )
550  {
551  if ( !Dar_ObjCutLevelAchieved(vCut, nLevelMin) )
552  {
553  if ( Aig_NodeMffcExtendCut( pAig, pObj, vCut, vCut2 ) )
554  {
555  nNodesSaved2 = Aig_NodeMffcLabelCut( p->pAig, pObj, vCut );
556  assert( nNodesSaved2 == nNodesSaved );
557  }
558  if ( Vec_PtrSize(vCut2) > p->pPars->nLeafMax )
559  Vec_PtrClear(vCut2);
560  if ( Vec_PtrSize(vCut2) > 0 )
561  {
562  p->nNodesExten++;
563 // printf( "%d(%d) ", Vec_PtrSize(vCut), Vec_PtrSize(vCut2) );
564  }
565  }
566  else
567  p->nNodesBelow++;
568  }
569 p->timeCuts += Abc_Clock() - clk;
570 
571  // try the cuts
572 clk = Abc_Clock();
573  Required = pAig->vLevelR? Aig_ObjRequiredLevel(pAig, pObj) : ABC_INFINITY;
574  Dar_ManRefactorTryCuts( p, pObj, nNodesSaved, Required );
575 p->timeEval += Abc_Clock() - clk;
576 
577  // check the best gain
578  if ( !(p->GainBest > 0 || (p->GainBest == 0 && p->pPars->fUseZeros)) )
579  {
580  if ( p->pGraphBest )
581  Kit_GraphFree( p->pGraphBest );
582  continue;
583  }
584 //printf( "\n" );
585 
586  // if we end up here, a rewriting step is accepted
587  nNodeBefore = Aig_ManNodeNum( pAig );
588  pObjNew = Dar_RefactBuildGraph( pAig, p->vLeavesBest, p->pGraphBest );
589  assert( (int)Aig_Regular(pObjNew)->Level <= Required );
590  // replace the node
591  Aig_ObjReplace( pAig, pObj, pObjNew, p->pPars->fUpdateLevel );
592  // compare the gains
593  nNodeAfter = Aig_ManNodeNum( pAig );
594  assert( p->GainBest <= nNodeBefore - nNodeAfter );
595  Kit_GraphFree( p->pGraphBest );
596  p->nCutsUsed++;
597 // break;
598  }
599 p->timeTotal = Abc_Clock() - clkStart;
600 p->timeOther = p->timeTotal - p->timeCuts - p->timeEval;
601 
602 // Bar_ProgressStop( pProgress );
603  // put the nodes into the DFS order and reassign their IDs
604 // Aig_NtkReassignIds( p );
605  // fix the levels
606  Aig_ManFanoutStop( pAig );
607  if ( p->pPars->fUpdateLevel )
608  Aig_ManStopReverseLevels( pAig );
609 /*
610  Aig_ManForEachObj( p->pAig, pObj, i )
611  if ( Aig_ObjIsNode(pObj) && Aig_ObjRefs(pObj) == 0 )
612  {
613  printf( "Unreferenced " );
614  Aig_ObjPrintVerbose( pObj, 0 );
615  printf( "\n" );
616  }
617 */
618  // remove dangling nodes (they should not be here!)
619  Aig_ManCleanup( pAig );
620 
621  // stop the rewriting manager
622  Dar_ManRefStop( p );
623 // Aig_ManCheckPhase( pAig );
624  if ( !Aig_ManCheck( pAig ) )
625  {
626  printf( "Dar_ManRefactor: The network check has failed.\n" );
627  return 0;
628  }
629  return 1;
630 
631 }
632 
633 ////////////////////////////////////////////////////////////////////////
634 /// END OF FILE ///
635 ////////////////////////////////////////////////////////////////////////
636 
637 
639 
char * memset()
#define Vec_VecForEachLevel(vGlob, vVec, i)
MACRO DEFINITIONS ///.
Definition: vecVec.h:55
void Dar_ManRefStop(Ref_Man_t *p)
Definition: darRefact.c:166
Kit_Edge_t eEdge0
Definition: kit.h:69
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
Vec_Vec_t * vCuts
Definition: darRefact.c:42
ABC_DLL int Aig_ManCheck(Aig_Man_t *p)
FUNCTION DECLARATIONS ///.
Definition: aigCheck.c:45
unsigned Level
Definition: aig.h:82
static int Kit_TruthWordNum(int nVars)
Definition: kit.h:224
Dar_RefPar_t * pPars
Definition: darRefact.c:39
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.
Definition: vecVec.h:42
static void Vec_PtrCopy(Vec_Ptr_t *pDest, Vec_Ptr_t *pSour)
Definition: vecPtr.h:587
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static Kit_Node_t * Kit_GraphNode(Kit_Graph_t *pGraph, int i)
Definition: kit.h:211
static int Aig_ObjIsTravIdCurrent(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: aig.h:295
int nNodesBelow
Definition: darRefact.c:59
int nNodesExten
Definition: darRefact.c:60
Aig_Man_t * pAig
Definition: darRefact.c:40
Kit_Edge_t eEdge1
Definition: kit.h:70
int nNodesInit
Definition: darRefact.c:57
static int Kit_GraphIsComplement(Kit_Graph_t *pGraph)
Definition: kit.h:205
int fUpdateLevel
Definition: dar.h:64
int fVeryVerbose
Definition: dar.h:67
static int Aig_IsComplement(Aig_Obj_t *p)
Definition: aig.h:249
static Aig_Obj_t * Aig_Regular(Aig_Obj_t *p)
Definition: aig.h:246
void Dar_ManRefPrintStats(Ref_Man_t *p)
Definition: darRefact.c:142
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
int Aig_ObjRequiredLevel(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: aigTiming.c:100
int nCutsMax
Definition: dar.h:62
static int Kit_TruthIsConst0(unsigned *pIn, int nVars)
Definition: kit.h:315
static int Kit_GraphIsVar(Kit_Graph_t *pGraph)
Definition: kit.h:206
int Dar_ManRefactor(Aig_Man_t *pAig, Dar_RefPar_t *pPars)
Definition: darRefact.c:496
static abctime Abc_Clock()
Definition: abc_global.h:279
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
int Dar_ObjCutLevelAchieved(Vec_Ptr_t *vCut, int nLevelMin)
Definition: darRefact.c:475
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
#define Kit_GraphForEachLeaf(pGraph, pLeaf, i)
Definition: kit.h:502
static void Vec_VecFree(Vec_Vec_t *p)
Definition: vecVec.h:347
void Ref_ObjPrint(Aig_Obj_t *pObj)
Definition: darRefact.c:207
Bdc_Man_t * pManDec
Definition: darRefact.c:55
int nLeafMax
Definition: dar.h:61
void * pFunc
Definition: kit.h:73
static int Aig_ManNodeNum(Aig_Man_t *p)
Definition: aig.h:256
Bdc_Par_t DecPars
Definition: darRefact.c:54
Aig_Obj_t * Dar_RefactBuildGraph(Aig_Man_t *pAig, Vec_Ptr_t *vCut, Kit_Graph_t *pGraph)
Definition: darRefact.c:313
int nNodesTried
Definition: darRefact.c:58
int nCutsUsed
Definition: darRefact.c:61
Aig_Obj_t * Aig_And(Aig_Man_t *p, Aig_Obj_t *p0, Aig_Obj_t *p1)
Definition: aigOper.c:104
void Aig_ManFanoutStart(Aig_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition: aigFanout.c:56
static void Vec_VecClear(Vec_Vec_t *p)
Definition: vecVec.h:437
static int Kit_GraphIsConst(Kit_Graph_t *pGraph)
Definition: kit.h:202
void Aig_ManStartReverseLevels(Aig_Man_t *p, int nMaxLevelIncrease)
Definition: aigTiming.c:142
unsigned * Aig_ManCutTruth(Aig_Obj_t *pRoot, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vNodes, Vec_Ptr_t *vTruthElem, Vec_Ptr_t *vTruthStore)
Definition: aigTruth.c:80
Vec_Int_t * vMemory
Definition: darRefact.c:46
void Aig_ManFanoutStop(Aig_Man_t *p)
Definition: aigFanout.c:89
Vec_Ptr_t * vLeavesBest
Definition: darRefact.c:49
static Vec_Ptr_t * Vec_PtrAllocTruthTables(int nVars)
Definition: vecPtr.h:1065
int Aig_NodeMffcSupp(Aig_Man_t *p, Aig_Obj_t *pNode, int LevelMin, Vec_Ptr_t *vSupp)
Definition: aigMffc.c:179
static int Aig_ObjIsNode(Aig_Obj_t *pObj)
Definition: aig.h:280
abctime timeEval
Definition: darRefact.c:65
int fVerbose
Definition: dar.h:66
static int Kit_TruthIsConst1(unsigned *pIn, int nVars)
Definition: kit.h:323
void Aig_ManStopReverseLevels(Aig_Man_t *p)
Definition: aigTiming.c:175
void Aig_ObjCollectCut(Aig_Obj_t *pRoot, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vNodes)
Definition: aigDfs.c:1017
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
unsigned fCompl
Definition: kit.h:62
void Ref_ObjComputeCuts(Aig_Man_t *pAig, Aig_Obj_t *pRoot, Vec_Vec_t *vCuts)
Definition: darRefact.c:192
void Kit_GraphFree(Kit_Graph_t *pGraph)
Definition: kitGraph.c:131
int Kit_TruthIsop(unsigned *puTruth, int nVars, Vec_Int_t *vMemory, int fTryBoth)
FUNCTION DEFINITIONS ///.
Definition: kitIsop.c:55
int Dar_RefactTryGraph(Aig_Man_t *pAig, Aig_Obj_t *pRoot, Vec_Ptr_t *vCut, Kit_Graph_t *pGraph, int NodeMax, int LevelMax)
Definition: darRefact.c:228
#define Kit_GraphForEachNode(pGraph, pAnd, i)
Definition: kit.h:504
void Aig_ObjReplace(Aig_Man_t *p, Aig_Obj_t *pObjOld, Aig_Obj_t *pObjNew, int fUpdateLevel)
Definition: aigObj.c:467
int LevelBest
Definition: darRefact.c:52
unsigned Node
Definition: kit.h:63
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
abctime timeTotal
Definition: darRefact.c:67
Vec_Ptr_t * vCutNodes
Definition: darRefact.c:47
Definition: aig.h:69
static int Counter
Kit_Graph_t * Kit_GraphCreateConst1()
Definition: kitGraph.c:90
static Vec_Vec_t * Vec_VecStart(int nSize)
Definition: vecVec.h:168
int nMffcMin
Definition: dar.h:60
Aig_Obj_t * Aig_TableLookupTwo(Aig_Man_t *p, Aig_Obj_t *pFanin0, Aig_Obj_t *pFanin1)
Definition: aigTable.c:146
static void Kit_TruthNot(unsigned *pOut, unsigned *pIn, int nVars)
Definition: kit.h:373
unsigned Level
Definition: kit.h:74
Kit_Graph_t * Kit_GraphCreateConst0()
Definition: kitGraph.c:69
int fUseZeros
Definition: dar.h:65
static Aig_Obj_t * Aig_ManConst1(Aig_Man_t *p)
Definition: aig.h:264
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
void Dar_ManDefaultRefParams(Dar_RefPar_t *pPars)
FUNCTION DEFINITIONS ///.
Definition: darRefact.c:85
typedefABC_NAMESPACE_IMPL_START struct Ref_Man_t_ Ref_Man_t
DECLARATIONS ///.
Definition: darRefact.c:35
#define Aig_ManForEachObj(p, pObj, i)
Definition: aig.h:403
Vec_Ptr_t * vTruthElem
Definition: darRefact.c:44
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
abctime timeCuts
Definition: darRefact.c:64
Definition: bdc.h:45
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define ABC_PRT(a, t)
Definition: abc_global.h:220
int GainBest
Definition: darRefact.c:51
int Aig_NodeMffcExtendCut(Aig_Man_t *p, Aig_Obj_t *pNode, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vResult)
Definition: aigMffc.c:265
static int Aig_ObjLevel(Aig_Obj_t *pObj)
Definition: aig.h:323
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition: abc_global.h:216
static Kit_Node_t * Kit_GraphVar(Kit_Graph_t *pGraph)
Definition: kit.h:215
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
Kit_Graph_t * pGraphBest
Definition: darRefact.c:50
void Bdc_ManFree(Bdc_Man_t *p)
Definition: bdcCore.c:113
int Dar_ManRefactorTryCuts(Ref_Man_t *p, Aig_Obj_t *pObj, int nNodesSaved, int Required)
Definition: darRefact.c:359
int Aig_NodeMffcLabelCut(Aig_Man_t *p, Aig_Obj_t *pNode, Vec_Ptr_t *vLeaves)
Definition: aigMffc.c:236
static Vec_Ptr_t * Vec_VecEntry(Vec_Vec_t *p, int i)
Definition: vecVec.h:271
void Aig_ManFindCut(Aig_Obj_t *pRoot, Vec_Ptr_t *vFront, Vec_Ptr_t *vVisited, int nSizeLimit, int nFanoutLimit)
Definition: aigWin.c:145
Vec_Ptr_t * vTruthStore
Definition: darRefact.c:45
static Aig_Obj_t * Aig_NotCond(Aig_Obj_t *p, int c)
Definition: aig.h:248
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static int Aig_ObjIsCi(Aig_Obj_t *pObj)
Definition: aig.h:275
ABC_INT64_T abctime
Definition: abc_global.h:278
Ref_Man_t * Dar_ManRefStart(Aig_Man_t *pAig, Dar_RefPar_t *pPars)
Definition: darRefact.c:108
int Aig_ManLevels(Aig_Man_t *p)
Definition: aigUtil.c:102
int Aig_ManCleanup(Aig_Man_t *p)
Definition: aigMan.c:265
int nCutsTried
Definition: darRefact.c:62
abctime timeOther
Definition: darRefact.c:66
static Vec_Ptr_t * Vec_PtrAllocSimInfo(int nEntries, int nWords)
Definition: vecPtr.h:929
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
Kit_Graph_t * Kit_SopFactor(Vec_Int_t *vCover, int fCompl, int nVars, Vec_Int_t *vMemory)
FUNCTION DEFINITIONS ///.
Definition: kitFactor.c:55
static int Kit_GraphRootLevel(Kit_Graph_t *pGraph)
Definition: kit.h:219