abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ivyRwr.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [ivyRwt.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [And-Inverter Graph package.]
8 
9  Synopsis [Rewriting based on precomputation.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - May 11, 2006.]
16 
17  Revision [$Id: ivyRwt.c,v 1.00 2006/05/11 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "ivy.h"
22 #include "bool/deco/deco.h"
23 #include "opt/rwt/rwt.h"
24 
26 
27 
28 ////////////////////////////////////////////////////////////////////////
29 /// DECLARATIONS ///
30 ////////////////////////////////////////////////////////////////////////
31 
32 static unsigned Ivy_NodeGetTruth( Ivy_Obj_t * pObj, int * pNums, int nNums );
33 static int Ivy_NodeRewrite( Ivy_Man_t * pMan, Rwt_Man_t * p, Ivy_Obj_t * pNode, int fUpdateLevel, int fUseZeroCost );
34 static Dec_Graph_t * Rwt_CutEvaluate( Ivy_Man_t * pMan, Rwt_Man_t * p, Ivy_Obj_t * pRoot,
35  Vec_Ptr_t * vFaninsCur, int nNodesSaved, int LevelMax, int * pGainBest, unsigned uTruth );
36 
37 static int Ivy_GraphToNetworkCount( Ivy_Man_t * p, Ivy_Obj_t * pRoot, Dec_Graph_t * pGraph, int NodeMax, int LevelMax );
38 static void Ivy_GraphUpdateNetwork( Ivy_Man_t * p, Ivy_Obj_t * pRoot, Dec_Graph_t * pGraph, int fUpdateLevel, int nGain );
39 
40 ////////////////////////////////////////////////////////////////////////
41 /// FUNCTION DEFINITIONS ///
42 ////////////////////////////////////////////////////////////////////////
43 
44 /**Function*************************************************************
45 
46  Synopsis [Performs incremental rewriting of the AIG.]
47 
48  Description []
49 
50  SideEffects []
51 
52  SeeAlso []
53 
54 ***********************************************************************/
55 int Ivy_ManRewritePre( Ivy_Man_t * p, int fUpdateLevel, int fUseZeroCost, int fVerbose )
56 {
57  Rwt_Man_t * pManRwt;
58  Ivy_Obj_t * pNode;
59  int i, nNodes, nGain;
60  abctime clk, clkStart = Abc_Clock();
61  // start the rewriting manager
62  pManRwt = Rwt_ManStart( 0 );
63  p->pData = pManRwt;
64  if ( pManRwt == NULL )
65  return 0;
66  // create fanouts
67  if ( fUpdateLevel && p->fFanout == 0 )
68  Ivy_ManStartFanout( p );
69  // compute the reverse levels if level update is requested
70  if ( fUpdateLevel )
72  // set the number of levels
73 // p->nLevelMax = Ivy_ManLevels( p );
74  // resynthesize each node once
75  nNodes = Ivy_ManObjIdMax(p);
76  Ivy_ManForEachNode( p, pNode, i )
77  {
78  // fix the fanin buffer problem
79  Ivy_NodeFixBufferFanins( p, pNode, 1 );
80  if ( Ivy_ObjIsBuf(pNode) )
81  continue;
82  // stop if all nodes have been tried once
83  if ( i > nNodes )
84  break;
85  // for each cut, try to resynthesize it
86  nGain = Ivy_NodeRewrite( p, pManRwt, pNode, fUpdateLevel, fUseZeroCost );
87  if ( nGain > 0 || (nGain == 0 && fUseZeroCost) )
88  {
89  Dec_Graph_t * pGraph = (Dec_Graph_t *)Rwt_ManReadDecs(pManRwt);
90  int fCompl = Rwt_ManReadCompl(pManRwt);
91 /*
92  {
93  Ivy_Obj_t * pObj;
94  int i;
95  printf( "USING: (" );
96  Vec_PtrForEachEntry( Ivy_Obj_t *, Rwt_ManReadLeaves(pManRwt), pObj, i )
97  printf( "%d ", Ivy_ObjFanoutNum(Ivy_Regular(pObj)) );
98  printf( ") Gain = %d.\n", nGain );
99  }
100  if ( nGain > 0 )
101  { // print stats on the MFFC
102  extern void Ivy_NodeMffcConeSuppPrint( Ivy_Obj_t * pNode );
103  printf( "Node %6d : Gain = %4d ", pNode->Id, nGain );
104  Ivy_NodeMffcConeSuppPrint( pNode );
105  }
106 */
107  // complement the FF if needed
108 clk = Abc_Clock();
109  if ( fCompl ) Dec_GraphComplement( pGraph );
110  Ivy_GraphUpdateNetwork( p, pNode, pGraph, fUpdateLevel, nGain );
111  if ( fCompl ) Dec_GraphComplement( pGraph );
112 Rwt_ManAddTimeUpdate( pManRwt, Abc_Clock() - clk );
113  }
114  }
115 Rwt_ManAddTimeTotal( pManRwt, Abc_Clock() - clkStart );
116  // print stats
117  if ( fVerbose )
118  Rwt_ManPrintStats( pManRwt );
119  // delete the managers
120  Rwt_ManStop( pManRwt );
121  p->pData = NULL;
122  // fix the levels
123  if ( fUpdateLevel )
124  Vec_IntFree( p->vRequired ), p->vRequired = NULL;
125  else
126  Ivy_ManResetLevels( p );
127  // check
128  if ( (i = Ivy_ManCleanup(p)) )
129  printf( "Cleanup after rewriting removed %d dangling nodes.\n", i );
130  if ( !Ivy_ManCheck(p) )
131  printf( "Ivy_ManRewritePre(): The check has failed.\n" );
132  return 1;
133 }
134 
135 /**Function*************************************************************
136 
137  Synopsis [Performs rewriting for one node.]
138 
139  Description [This procedure considers all the cuts computed for the node
140  and tries to rewrite each of them using the "forest" of different AIG
141  structures precomputed and stored in the RWR manager.
142  Determines the best rewriting and computes the gain in the number of AIG
143  nodes in the final network. In the end, p->vFanins contains information
144  about the best cut that can be used for rewriting, while p->pGraph gives
145  the decomposition dag (represented using decomposition graph data structure).
146  Returns gain in the number of nodes or -1 if node cannot be rewritten.]
147 
148  SideEffects []
149 
150  SeeAlso []
151 
152 ***********************************************************************/
153 int Ivy_NodeRewrite( Ivy_Man_t * pMan, Rwt_Man_t * p, Ivy_Obj_t * pNode, int fUpdateLevel, int fUseZeroCost )
154 {
155  int fVeryVerbose = 0;
156  Dec_Graph_t * pGraph;
157  Ivy_Store_t * pStore;
158  Ivy_Cut_t * pCut;
159  Ivy_Obj_t * pFanin;
160  unsigned uPhase;
161  unsigned uTruthBest = 0; // Suppress "might be used uninitialized"
162  unsigned uTruth;
163  char * pPerm;
164  int Required, nNodesSaved;
165  int nNodesSaveCur = -1; // Suppress "might be used uninitialized"
166  int i, c, GainCur = -1, GainBest = -1;
167  abctime clk, clk2;
168 
169  p->nNodesConsidered++;
170  // get the required times
171  Required = fUpdateLevel? Vec_IntEntry( pMan->vRequired, pNode->Id ) : 1000000;
172  // get the node's cuts
173 clk = Abc_Clock();
174  pStore = Ivy_NodeFindCutsAll( pMan, pNode, 5 );
175 p->timeCut += Abc_Clock() - clk;
176 
177  // go through the cuts
178 clk = Abc_Clock();
179  for ( c = 1; c < pStore->nCuts; c++ )
180  {
181  pCut = pStore->pCuts + c;
182  // consider only 4-input cuts
183  if ( pCut->nSize != 4 )
184  continue;
185  // skip the cuts with buffers
186  for ( i = 0; i < (int)pCut->nSize; i++ )
187  if ( Ivy_ObjIsBuf( Ivy_ManObj(pMan, pCut->pArray[i]) ) )
188  break;
189  if ( i != pCut->nSize )
190  {
191  p->nCutsBad++;
192  continue;
193  }
194  p->nCutsGood++;
195  // get the fanin permutation
196 clk2 = Abc_Clock();
197  uTruth = 0xFFFF & Ivy_NodeGetTruth( pNode, pCut->pArray, pCut->nSize ); // truth table
198 p->timeTruth += Abc_Clock() - clk2;
199  pPerm = p->pPerms4[ (int) p->pPerms[uTruth] ];
200  uPhase = p->pPhases[uTruth];
201  // collect fanins with the corresponding permutation/phase
202  Vec_PtrClear( p->vFaninsCur );
203  Vec_PtrFill( p->vFaninsCur, (int)pCut->nSize, 0 );
204  for ( i = 0; i < (int)pCut->nSize; i++ )
205  {
206  pFanin = Ivy_ManObj( pMan, pCut->pArray[(int)pPerm[i]] );
207  assert( Ivy_ObjIsNode(pFanin) || Ivy_ObjIsCi(pFanin) );
208  pFanin = Ivy_NotCond(pFanin, ((uPhase & (1<<i)) > 0) );
209  Vec_PtrWriteEntry( p->vFaninsCur, i, pFanin );
210  }
211 clk2 = Abc_Clock();
212 /*
213  printf( "Considering: (" );
214  Vec_PtrForEachEntry( Ivy_Obj_t *, p->vFaninsCur, pFanin, i )
215  printf( "%d ", Ivy_ObjFanoutNum(Ivy_Regular(pFanin)) );
216  printf( ")\n" );
217 */
218  // mark the fanin boundary
219  Vec_PtrForEachEntry( Ivy_Obj_t *, p->vFaninsCur, pFanin, i )
220  Ivy_ObjRefsInc( Ivy_Regular(pFanin) );
221  // label MFFC with current ID
222  Ivy_ManIncrementTravId( pMan );
223  nNodesSaved = Ivy_ObjMffcLabel( pMan, pNode );
224  // unmark the fanin boundary
225  Vec_PtrForEachEntry( Ivy_Obj_t *, p->vFaninsCur, pFanin, i )
226  Ivy_ObjRefsDec( Ivy_Regular(pFanin) );
227 p->timeMffc += Abc_Clock() - clk2;
228 
229  // evaluate the cut
230 clk2 = Abc_Clock();
231  pGraph = Rwt_CutEvaluate( pMan, p, pNode, p->vFaninsCur, nNodesSaved, Required, &GainCur, uTruth );
232 p->timeEval += Abc_Clock() - clk2;
233 
234  // check if the cut is better than the current best one
235  if ( pGraph != NULL && GainBest < GainCur )
236  {
237  // save this form
238  nNodesSaveCur = nNodesSaved;
239  GainBest = GainCur;
240  p->pGraph = pGraph;
241  p->fCompl = ((uPhase & (1<<4)) > 0);
242  uTruthBest = uTruth;
243  // collect fanins in the
244  Vec_PtrClear( p->vFanins );
245  Vec_PtrForEachEntry( Ivy_Obj_t *, p->vFaninsCur, pFanin, i )
246  Vec_PtrPush( p->vFanins, pFanin );
247  }
248  }
249 p->timeRes += Abc_Clock() - clk;
250 
251  if ( GainBest == -1 )
252  return -1;
253 
254 // printf( "%d", nNodesSaveCur - GainBest );
255 /*
256  if ( GainBest > 0 )
257  {
258  if ( Rwt_CutIsintean( pNode, p->vFanins ) )
259  printf( "b" );
260  else
261  {
262  printf( "Node %d : ", pNode->Id );
263  Vec_PtrForEachEntry( Ivy_Obj_t *, p->vFanins, pFanin, i )
264  printf( "%d ", Ivy_Regular(pFanin)->Id );
265  printf( "a" );
266  }
267  }
268 */
269 /*
270  if ( GainBest > 0 )
271  if ( p->fCompl )
272  printf( "c" );
273  else
274  printf( "." );
275 */
276 
277  // copy the leaves
278  Vec_PtrForEachEntry( Ivy_Obj_t *, p->vFanins, pFanin, i )
279  Dec_GraphNode((Dec_Graph_t *)p->pGraph, i)->pFunc = pFanin;
280 
281  p->nScores[p->pMap[uTruthBest]]++;
282  p->nNodesGained += GainBest;
283  if ( fUseZeroCost || GainBest > 0 )
284  p->nNodesRewritten++;
285 
286  // report the progress
287  if ( fVeryVerbose && GainBest > 0 )
288  {
289  printf( "Node %6d : ", Ivy_ObjId(pNode) );
290  printf( "Fanins = %d. ", p->vFanins->nSize );
291  printf( "Save = %d. ", nNodesSaveCur );
292  printf( "Add = %d. ", nNodesSaveCur-GainBest );
293  printf( "GAIN = %d. ", GainBest );
294  printf( "Cone = %d. ", p->pGraph? Dec_GraphNodeNum((Dec_Graph_t *)p->pGraph) : 0 );
295  printf( "Class = %d. ", p->pMap[uTruthBest] );
296  printf( "\n" );
297  }
298  return GainBest;
299 }
300 
301 /**Function*************************************************************
302 
303  Synopsis [Computes the truth table.]
304 
305  Description []
306 
307  SideEffects []
308 
309  SeeAlso []
310 
311 ***********************************************************************/
312 unsigned Ivy_NodeGetTruth_rec( Ivy_Obj_t * pObj, int * pNums, int nNums )
313 {
314  static unsigned uMasks[5] = { 0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0, 0xFF00FF00, 0xFFFF0000 };
315  unsigned uTruth0, uTruth1;
316  int i;
317  for ( i = 0; i < nNums; i++ )
318  if ( pObj->Id == pNums[i] )
319  return uMasks[i];
320  assert( Ivy_ObjIsNode(pObj) || Ivy_ObjIsBuf(pObj) );
321  uTruth0 = Ivy_NodeGetTruth_rec( Ivy_ObjFanin0(pObj), pNums, nNums );
322  if ( Ivy_ObjFaninC0(pObj) )
323  uTruth0 = ~uTruth0;
324  if ( Ivy_ObjIsBuf(pObj) )
325  return uTruth0;
326  uTruth1 = Ivy_NodeGetTruth_rec( Ivy_ObjFanin1(pObj), pNums, nNums );
327  if ( Ivy_ObjFaninC1(pObj) )
328  uTruth1 = ~uTruth1;
329  return uTruth0 & uTruth1;
330 }
331 
332 
333 /**Function*************************************************************
334 
335  Synopsis [Computes the truth table.]
336 
337  Description []
338 
339  SideEffects []
340 
341  SeeAlso []
342 
343 ***********************************************************************/
344 unsigned Ivy_NodeGetTruth( Ivy_Obj_t * pObj, int * pNums, int nNums )
345 {
346  assert( nNums < 6 );
347  return Ivy_NodeGetTruth_rec( pObj, pNums, nNums );
348 }
349 
350 /**Function*************************************************************
351 
352  Synopsis [Evaluates the cut.]
353 
354  Description []
355 
356  SideEffects []
357 
358  SeeAlso []
359 
360 ***********************************************************************/
361 Dec_Graph_t * Rwt_CutEvaluate( Ivy_Man_t * pMan, Rwt_Man_t * p, Ivy_Obj_t * pRoot, Vec_Ptr_t * vFaninsCur, int nNodesSaved, int LevelMax, int * pGainBest, unsigned uTruth )
362 {
363  Vec_Ptr_t * vSubgraphs;
364  Dec_Graph_t * pGraphBest = NULL; // Suppress "might be used uninitialized"
365  Dec_Graph_t * pGraphCur;
366  Rwt_Node_t * pNode, * pFanin;
367  int nNodesAdded, GainBest, i, k;
368  // find the matching class of subgraphs
369  vSubgraphs = Vec_VecEntry( p->vClasses, p->pMap[uTruth] );
370  p->nSubgraphs += vSubgraphs->nSize;
371  // determine the best subgraph
372  GainBest = -1;
373  Vec_PtrForEachEntry( Rwt_Node_t *, vSubgraphs, pNode, i )
374  {
375  // get the current graph
376  pGraphCur = (Dec_Graph_t *)pNode->pNext;
377  // copy the leaves
378  Vec_PtrForEachEntry( Rwt_Node_t *, vFaninsCur, pFanin, k )
379  Dec_GraphNode(pGraphCur, k)->pFunc = pFanin;
380  // detect how many unlabeled nodes will be reused
381  nNodesAdded = Ivy_GraphToNetworkCount( pMan, pRoot, pGraphCur, nNodesSaved, LevelMax );
382  if ( nNodesAdded == -1 )
383  continue;
384  assert( nNodesSaved >= nNodesAdded );
385  // count the gain at this node
386  if ( GainBest < nNodesSaved - nNodesAdded )
387  {
388  GainBest = nNodesSaved - nNodesAdded;
389  pGraphBest = pGraphCur;
390  }
391  }
392  if ( GainBest == -1 )
393  return NULL;
394  *pGainBest = GainBest;
395  return pGraphBest;
396 }
397 
398 
399 /**Function*************************************************************
400 
401  Synopsis [Counts the number of new nodes added when using this graph.]
402 
403  Description [AIG nodes for the fanins should be assigned to pNode->pFunc
404  of the leaves of the graph before calling this procedure.
405  Returns -1 if the number of nodes and levels exceeded the given limit or
406  the number of levels exceeded the maximum allowed level.]
407 
408  SideEffects []
409 
410  SeeAlso []
411 
412 ***********************************************************************/
413 int Ivy_GraphToNetworkCount( Ivy_Man_t * p, Ivy_Obj_t * pRoot, Dec_Graph_t * pGraph, int NodeMax, int LevelMax )
414 {
415  Dec_Node_t * pNode, * pNode0, * pNode1;
416  Ivy_Obj_t * pAnd, * pAnd0, * pAnd1;
417  int i, Counter, LevelNew, LevelOld;
418  // check for constant function or a literal
419  if ( Dec_GraphIsConst(pGraph) || Dec_GraphIsVar(pGraph) )
420  return 0;
421  // set the levels of the leaves
422  Dec_GraphForEachLeaf( pGraph, pNode, i )
423  pNode->Level = Ivy_Regular((Ivy_Obj_t *)pNode->pFunc)->Level;
424  // compute the AIG size after adding the internal nodes
425  Counter = 0;
426  Dec_GraphForEachNode( pGraph, pNode, i )
427  {
428  // get the children of this node
429  pNode0 = Dec_GraphNode( pGraph, pNode->eEdge0.Node );
430  pNode1 = Dec_GraphNode( pGraph, pNode->eEdge1.Node );
431  // get the AIG nodes corresponding to the children
432  pAnd0 = (Ivy_Obj_t *)pNode0->pFunc;
433  pAnd1 = (Ivy_Obj_t *)pNode1->pFunc;
434  if ( pAnd0 && pAnd1 )
435  {
436  // if they are both present, find the resulting node
437  pAnd0 = Ivy_NotCond( pAnd0, pNode->eEdge0.fCompl );
438  pAnd1 = Ivy_NotCond( pAnd1, pNode->eEdge1.fCompl );
439  pAnd = Ivy_TableLookup( p, Ivy_ObjCreateGhost(p, pAnd0, pAnd1, IVY_AND, IVY_INIT_NONE) );
440  // return -1 if the node is the same as the original root
441  if ( Ivy_Regular(pAnd) == pRoot )
442  return -1;
443  }
444  else
445  pAnd = NULL;
446  // count the number of added nodes
447  if ( pAnd == NULL || Ivy_ObjIsTravIdCurrent(p, Ivy_Regular(pAnd)) )
448  {
449  if ( ++Counter > NodeMax )
450  return -1;
451  }
452  // count the number of new levels
453  LevelNew = 1 + RWT_MAX( pNode0->Level, pNode1->Level );
454  if ( pAnd )
455  {
456  if ( Ivy_Regular(pAnd) == p->pConst1 )
457  LevelNew = 0;
458  else if ( Ivy_Regular(pAnd) == Ivy_Regular(pAnd0) )
459  LevelNew = (int)Ivy_Regular(pAnd0)->Level;
460  else if ( Ivy_Regular(pAnd) == Ivy_Regular(pAnd1) )
461  LevelNew = (int)Ivy_Regular(pAnd1)->Level;
462  LevelOld = (int)Ivy_Regular(pAnd)->Level;
463 // assert( LevelNew == LevelOld );
464  }
465  if ( LevelNew > LevelMax )
466  return -1;
467  pNode->pFunc = pAnd;
468  pNode->Level = LevelNew;
469  }
470  return Counter;
471 }
472 
473 /**Function*************************************************************
474 
475  Synopsis [Transforms the decomposition graph into the AIG.]
476 
477  Description [AIG nodes for the fanins should be assigned to pNode->pFunc
478  of the leaves of the graph before calling this procedure.]
479 
480  SideEffects []
481 
482  SeeAlso []
483 
484 ***********************************************************************/
486 {
487  Ivy_Obj_t * pAnd0, * pAnd1;
488  Dec_Node_t * pNode = NULL; // Suppress "might be used uninitialized"
489  int i;
490  // check for constant function
491  if ( Dec_GraphIsConst(pGraph) )
492  return Ivy_NotCond( Ivy_ManConst1(p), Dec_GraphIsComplement(pGraph) );
493  // check for a literal
494  if ( Dec_GraphIsVar(pGraph) )
495  return Ivy_NotCond( (Ivy_Obj_t *)Dec_GraphVar(pGraph)->pFunc, Dec_GraphIsComplement(pGraph) );
496  // build the AIG nodes corresponding to the AND gates of the graph
497  Dec_GraphForEachNode( pGraph, pNode, i )
498  {
499  pAnd0 = Ivy_NotCond( (Ivy_Obj_t *)Dec_GraphNode(pGraph, pNode->eEdge0.Node)->pFunc, pNode->eEdge0.fCompl );
500  pAnd1 = Ivy_NotCond( (Ivy_Obj_t *)Dec_GraphNode(pGraph, pNode->eEdge1.Node)->pFunc, pNode->eEdge1.fCompl );
501  pNode->pFunc = Ivy_And( p, pAnd0, pAnd1 );
502  }
503  // complement the result if necessary
504  return Ivy_NotCond( (Ivy_Obj_t *)pNode->pFunc, Dec_GraphIsComplement(pGraph) );
505 }
506 
507 /**Function*************************************************************
508 
509  Synopsis [Replaces MFFC of the node by the new factored form.]
510 
511  Description []
512 
513  SideEffects []
514 
515  SeeAlso []
516 
517 ***********************************************************************/
518 void Ivy_GraphUpdateNetwork( Ivy_Man_t * p, Ivy_Obj_t * pRoot, Dec_Graph_t * pGraph, int fUpdateLevel, int nGain )
519 {
520  Ivy_Obj_t * pRootNew;
521  int nNodesNew, nNodesOld, Required;
522  Required = fUpdateLevel? Vec_IntEntry( p->vRequired, pRoot->Id ) : 1000000;
523  nNodesOld = Ivy_ManNodeNum(p);
524  // create the new structure of nodes
525  pRootNew = Ivy_GraphToNetwork( p, pGraph );
526  assert( (int)Ivy_Regular(pRootNew)->Level <= Required );
527 // if ( Ivy_Regular(pRootNew)->Level == Required )
528 // printf( "Difference %d.\n", Ivy_Regular(pRootNew)->Level - Required );
529  // remove the old nodes
530 // Ivy_AigReplace( pMan->pManFunc, pRoot, pRootNew, fUpdateLevel );
531 /*
532  if ( Ivy_IsComplement(pRootNew) )
533  printf( "c" );
534  else
535  printf( "d" );
536  if ( Ivy_ObjRefs(Ivy_Regular(pRootNew)) > 0 )
537  printf( "%d", Ivy_ObjRefs(Ivy_Regular(pRootNew)) );
538  printf( " " );
539 */
540  Ivy_ObjReplace( p, pRoot, pRootNew, 1, 0, 1 );
541  // compare the gains
542  nNodesNew = Ivy_ManNodeNum(p);
543  assert( nGain <= nNodesOld - nNodesNew );
544  // propagate the buffer
545  Ivy_ManPropagateBuffers( p, 1 );
546 }
547 
548 /**Function*************************************************************
549 
550  Synopsis [Replaces MFFC of the node by the new factored form.]
551 
552  Description []
553 
554  SideEffects []
555 
556  SeeAlso []
557 
558 ***********************************************************************/
559 void Ivy_GraphUpdateNetwork3( Ivy_Man_t * p, Ivy_Obj_t * pRoot, Dec_Graph_t * pGraph, int fUpdateLevel, int nGain )
560 {
561  Ivy_Obj_t * pRootNew, * pFanin;
562  int nNodesNew, nNodesOld, i, nRefsOld;
563  nNodesOld = Ivy_ManNodeNum(p);
564 
565 //printf( "Before = %d. ", Ivy_ManNodeNum(p) );
566  // mark the cut
567  Vec_PtrForEachEntry( Ivy_Obj_t *, ((Rwt_Man_t *)p->pData)->vFanins, pFanin, i )
568  Ivy_ObjRefsInc( Ivy_Regular(pFanin) );
569  // deref the old cone
570  nRefsOld = pRoot->nRefs;
571  pRoot->nRefs = 0;
572  Ivy_ObjDelete_rec( p, pRoot, 0 );
573  pRoot->nRefs = nRefsOld;
574  // unmark the cut
575  Vec_PtrForEachEntry( Ivy_Obj_t *, ((Rwt_Man_t *)p->pData)->vFanins, pFanin, i )
576  Ivy_ObjRefsDec( Ivy_Regular(pFanin) );
577 //printf( "Deref = %d. ", Ivy_ManNodeNum(p) );
578 
579  // create the new structure of nodes
580  pRootNew = Ivy_GraphToNetwork( p, pGraph );
581 //printf( "Create = %d. ", Ivy_ManNodeNum(p) );
582  // remove the old nodes
583 // Ivy_AigReplace( pMan->pManFunc, pRoot, pRootNew, fUpdateLevel );
584 /*
585  if ( Ivy_IsComplement(pRootNew) )
586  printf( "c" );
587  else
588  printf( "d" );
589  if ( Ivy_ObjRefs(Ivy_Regular(pRootNew)) > 0 )
590  printf( "%d", Ivy_ObjRefs(Ivy_Regular(pRootNew)) );
591  printf( " " );
592 */
593  Ivy_ObjReplace( p, pRoot, pRootNew, 0, 0, 1 );
594 //printf( "Replace = %d. ", Ivy_ManNodeNum(p) );
595 
596  // delete remaining dangling nodes
597  Vec_PtrForEachEntry( Ivy_Obj_t *, ((Rwt_Man_t *)p->pData)->vFanins, pFanin, i )
598  {
599  pFanin = Ivy_Regular(pFanin);
600  if ( !Ivy_ObjIsNone(pFanin) && Ivy_ObjRefs(pFanin) == 0 )
601  Ivy_ObjDelete_rec( p, pFanin, 1 );
602  }
603 //printf( "Deref = %d. ", Ivy_ManNodeNum(p) );
604 //printf( "\n" );
605 
606  // compare the gains
607  nNodesNew = Ivy_ManNodeNum(p);
608  assert( nGain <= nNodesOld - nNodesNew );
609 }
610 
611 
612 ////////////////////////////////////////////////////////////////////////
613 /// END OF FILE ///
614 ////////////////////////////////////////////////////////////////////////
615 
616 
618 
void Rwt_ManStop(Rwt_Man_t *p)
Definition: rwtMan.c:149
unsigned Level
Definition: ivy.h:84
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
void Rwt_ManAddTimeTotal(Rwt_Man_t *p, abctime Time)
Definition: rwtMan.c:333
Rwt_Node_t * pNext
Definition: rwt.h:118
void Ivy_ObjReplace(Ivy_Man_t *p, Ivy_Obj_t *pObjOld, Ivy_Obj_t *pObjNew, int fDeleteOld, int fFreeTop, int fUpdateLevel)
Definition: ivyObj.c:328
static Ivy_Obj_t * Ivy_ManConst1(Ivy_Man_t *p)
Definition: ivy.h:199
#define RWT_MAX(a, b)
Definition: rwt.h:53
Definition: ivy.h:58
static int Dec_GraphNodeNum(Dec_Graph_t *pGraph)
Definition: dec.h:421
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Vec_PtrFill(Vec_Ptr_t *p, int nSize, void *Entry)
Definition: vecPtr.h:449
char ** pPerms4
Definition: rwt.h:68
Ivy_Cut_t pCuts[IVY_CUT_LIMIT]
Definition: ivy.h:172
abctime timeMffc
Definition: rwt.h:102
int Ivy_ObjMffcLabel(Ivy_Man_t *p, Ivy_Obj_t *pObj)
Definition: ivyUtil.c:359
static int Dec_GraphIsConst(Dec_Graph_t *pGraph)
Definition: dec.h:324
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static int Ivy_ObjIsNone(Ivy_Obj_t *pObj)
Definition: ivy.h:235
int Id
Definition: ivy.h:75
Rwt_Man_t * Rwt_ManStart(int fPrecompute)
Definition: rwtMan.c:87
#define Ivy_ManForEachNode(p, pObj, i)
Definition: ivy.h:402
void Ivy_GraphUpdateNetwork3(Ivy_Man_t *p, Ivy_Obj_t *pRoot, Dec_Graph_t *pGraph, int fUpdateLevel, int nGain)
Definition: ivyRwr.c:559
Ivy_Store_t * Ivy_NodeFindCutsAll(Ivy_Man_t *p, Ivy_Obj_t *pObj, int nLeaves)
Definition: ivyCut.c:892
static abctime Abc_Clock()
Definition: abc_global.h:279
static void Ivy_ObjRefsInc(Ivy_Obj_t *pObj)
Definition: ivy.h:265
int fCompl
Definition: rwt.h:80
void Rwt_ManPrintStats(Rwt_Man_t *p)
Definition: rwtMan.c:183
static Ivy_Obj_t * Ivy_ObjFanin1(Ivy_Obj_t *pObj)
Definition: ivy.h:272
int Ivy_ManPropagateBuffers(Ivy_Man_t *p, int fUpdateLevel)
Definition: ivyMan.c:414
static int Ivy_NodeRewrite(Ivy_Man_t *pMan, Rwt_Man_t *p, Ivy_Obj_t *pNode, int fUpdateLevel, int fUseZeroCost)
Definition: ivyRwr.c:153
void Ivy_ManResetLevels(Ivy_Man_t *p)
Definition: ivyUtil.c:292
static Ivy_Obj_t * Ivy_ObjFanin0(Ivy_Obj_t *pObj)
Definition: ivy.h:271
int Rwt_ManReadCompl(Rwt_Man_t *p)
Definition: rwtMan.c:285
static int Dec_GraphIsComplement(Dec_Graph_t *pGraph)
Definition: dec.h:372
static int Ivy_ManObjIdMax(Ivy_Man_t *p)
Definition: ivy.h:226
Ivy_Obj_t * Ivy_TableLookup(Ivy_Man_t *p, Ivy_Obj_t *pObj)
FUNCTION DEFINITIONS ///.
Definition: ivyTable.c:71
char * pPerms
Definition: rwt.h:64
void Ivy_NodeFixBufferFanins(Ivy_Man_t *p, Ivy_Obj_t *pNode, int fUpdateLevel)
Definition: ivyObj.c:442
void Ivy_ManIncrementTravId(Ivy_Man_t *p)
DECLARATIONS ///.
Definition: ivyUtil.c:45
static Dec_Node_t * Dec_GraphVar(Dec_Graph_t *pGraph)
Definition: dec.h:517
Ivy_Obj_t * Ivy_GraphToNetwork(Ivy_Man_t *p, Dec_Graph_t *pGraph)
Definition: ivyRwr.c:485
Vec_Ptr_t * vFaninsCur
Definition: rwt.h:85
int nNodesGained
Definition: rwt.h:91
void * Rwt_ManReadDecs(Rwt_Man_t *p)
Definition: rwtMan.c:253
int nCuts
Definition: ivy.h:168
static int Ivy_ObjFaninC1(Ivy_Obj_t *pObj)
Definition: ivy.h:270
static Ivy_Obj_t * Ivy_ManObj(Ivy_Man_t *p, int i)
Definition: ivy.h:203
static Dec_Graph_t * Rwt_CutEvaluate(Ivy_Man_t *pMan, Rwt_Man_t *p, Ivy_Obj_t *pRoot, Vec_Ptr_t *vFaninsCur, int nNodesSaved, int LevelMax, int *pGainBest, unsigned uTruth)
Definition: ivyRwr.c:361
abctime timeEval
Definition: rwt.h:101
short nSize
Definition: ivy.h:159
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
static int Ivy_ObjRefs(Ivy_Obj_t *pObj)
Definition: ivy.h:264
static void Ivy_ObjRefsDec(Ivy_Obj_t *pObj)
Definition: ivy.h:266
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
int nNodesRewritten
Definition: rwt.h:90
int pArray[IVY_CUT_INPUT]
Definition: ivy.h:161
Definition: ivy.h:73
static Ivy_Obj_t * Ivy_Regular(Ivy_Obj_t *p)
Definition: ivy.h:193
static int Counter
static int Ivy_ObjIsTravIdCurrent(Ivy_Man_t *p, Ivy_Obj_t *pObj)
Definition: ivy.h:257
Dec_Edge_t eEdge0
Definition: dec.h:52
static int Ivy_ObjIsNode(Ivy_Obj_t *pObj)
Definition: ivy.h:245
int nNodesConsidered
Definition: rwt.h:89
static ABC_NAMESPACE_IMPL_START unsigned Ivy_NodeGetTruth(Ivy_Obj_t *pObj, int *pNums, int nNums)
DECLARATIONS ///.
Definition: ivyRwr.c:344
abctime timeTruth
Definition: rwt.h:98
char * pPhases
Definition: rwt.h:63
static int pPerm[13719]
Definition: rwrTemp.c:32
unsigned Ivy_NodeGetTruth_rec(Ivy_Obj_t *pObj, int *pNums, int nNums)
Definition: ivyRwr.c:312
Vec_Vec_t * vClasses
Definition: rwt.h:72
void Ivy_ManStartFanout(Ivy_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition: ivyFanout.c:136
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
Vec_Int_t * Ivy_ManRequiredLevels(Ivy_Man_t *p)
Definition: ivyDfs.c:250
typedefABC_NAMESPACE_HEADER_START struct Ivy_Man_t_ Ivy_Man_t
INCLUDES ///.
Definition: ivy.h:46
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
#define Dec_GraphForEachNode(pGraph, pAnd, i)
Definition: dec.h:101
void Ivy_ObjDelete_rec(Ivy_Man_t *p, Ivy_Obj_t *pObj, int fFreeTop)
Definition: ivyObj.c:299
static Ivy_Obj_t * Ivy_ObjCreateGhost(Ivy_Man_t *p, Ivy_Obj_t *p0, Ivy_Obj_t *p1, Ivy_Type_t Type, Ivy_Init_t Init)
Definition: ivy.h:308
void * pFunc
Definition: dec.h:56
static int Ivy_GraphToNetworkCount(Ivy_Man_t *p, Ivy_Obj_t *pRoot, Dec_Graph_t *pGraph, int NodeMax, int LevelMax)
Definition: ivyRwr.c:413
int nSubgraphs
Definition: rwt.h:95
#define Dec_GraphForEachLeaf(pGraph, pLeaf, i)
ITERATORS ///.
Definition: dec.h:98
Definition: rwt.h:58
static Ivy_Obj_t * Ivy_NotCond(Ivy_Obj_t *p, int c)
Definition: ivy.h:195
int nScores[222]
Definition: rwt.h:92
static int Ivy_ObjIsBuf(Ivy_Obj_t *pObj)
Definition: ivy.h:244
void Rwt_ManAddTimeUpdate(Rwt_Man_t *p, abctime Time)
Definition: rwtMan.c:317
unsigned char * pMap
Definition: rwt.h:65
static int Dec_GraphIsVar(Dec_Graph_t *pGraph)
Definition: dec.h:485
Vec_Ptr_t * vFanins
Definition: rwt.h:84
#define assert(ex)
Definition: util_old.h:213
abctime timeCut
Definition: rwt.h:99
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
static Dec_Node_t * Dec_GraphNode(Dec_Graph_t *pGraph, int i)
Definition: dec.h:437
static int Ivy_ObjIsCi(Ivy_Obj_t *pObj)
Definition: ivy.h:238
int Ivy_ManRewritePre(Ivy_Man_t *p, int fUpdateLevel, int fUseZeroCost, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition: ivyRwr.c:55
static int Ivy_ManNodeNum(Ivy_Man_t *p)
Definition: ivy.h:227
static Vec_Ptr_t * Vec_VecEntry(Vec_Vec_t *p, int i)
Definition: vecVec.h:271
void * pGraph
Definition: rwt.h:82
int nCutsBad
Definition: rwt.h:94
int nCutsGood
Definition: rwt.h:93
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 void Ivy_GraphUpdateNetwork(Ivy_Man_t *p, Ivy_Obj_t *pRoot, Dec_Graph_t *pGraph, int fUpdateLevel, int nGain)
Definition: ivyRwr.c:518
Dec_Edge_t eEdge1
Definition: dec.h:53
ABC_INT64_T abctime
Definition: abc_global.h:278
static int Ivy_ObjFaninC0(Ivy_Obj_t *pObj)
Definition: ivy.h:269
int nRefs
Definition: ivy.h:85
Ivy_Obj_t * Ivy_And(Ivy_Man_t *p, Ivy_Obj_t *p0, Ivy_Obj_t *p1)
Definition: ivyOper.c:84
int Ivy_ManCheck(Ivy_Man_t *p)
DECLARATIONS ///.
Definition: ivyCheck.c:45
int Ivy_ManCleanup(Ivy_Man_t *p)
Definition: ivyMan.c:265
static int Ivy_ObjId(Ivy_Obj_t *pObj)
Definition: ivy.h:260
abctime timeRes
Definition: rwt.h:100
static void Dec_GraphComplement(Dec_Graph_t *pGraph)
Definition: dec.h:388
unsigned Level
Definition: dec.h:57