abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
darRefact.c File Reference
#include "darInt.h"
#include "bool/kit/kit.h"
#include "bool/bdc/bdc.h"
#include "bool/bdc/bdcInt.h"

Go to the source code of this file.

Data Structures

struct  Ref_Man_t_
 

Typedefs

typedef
typedefABC_NAMESPACE_IMPL_START
struct Ref_Man_t_ 
Ref_Man_t
 DECLARATIONS ///. More...
 

Functions

void Dar_ManDefaultRefParams (Dar_RefPar_t *pPars)
 FUNCTION DEFINITIONS ///. More...
 
Ref_Man_tDar_ManRefStart (Aig_Man_t *pAig, Dar_RefPar_t *pPars)
 
void Dar_ManRefPrintStats (Ref_Man_t *p)
 
void Dar_ManRefStop (Ref_Man_t *p)
 
void Ref_ObjComputeCuts (Aig_Man_t *pAig, Aig_Obj_t *pRoot, Vec_Vec_t *vCuts)
 
void Ref_ObjPrint (Aig_Obj_t *pObj)
 
int Dar_RefactTryGraph (Aig_Man_t *pAig, Aig_Obj_t *pRoot, Vec_Ptr_t *vCut, Kit_Graph_t *pGraph, int NodeMax, int LevelMax)
 
Aig_Obj_tDar_RefactBuildGraph (Aig_Man_t *pAig, Vec_Ptr_t *vCut, Kit_Graph_t *pGraph)
 
int Dar_ManRefactorTryCuts (Ref_Man_t *p, Aig_Obj_t *pObj, int nNodesSaved, int Required)
 
int Dar_ObjCutLevelAchieved (Vec_Ptr_t *vCut, int nLevelMin)
 
int Dar_ManRefactor (Aig_Man_t *pAig, Dar_RefPar_t *pPars)
 

Typedef Documentation

typedef typedefABC_NAMESPACE_IMPL_START struct Ref_Man_t_ Ref_Man_t

DECLARATIONS ///.

CFile****************************************************************

FileName [darRefact.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [DAG-aware AIG rewriting.]

Synopsis [Refactoring.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - April 28, 2007.]

Revision [

Id:
darRefact.c,v 1.00 2007/04/28 00:00:00 alanmi Exp

]

Definition at line 35 of file darRefact.c.

Function Documentation

void Dar_ManDefaultRefParams ( Dar_RefPar_t pPars)

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis [Returns the structure with default assignment of parameters.]

Description []

SideEffects []

SeeAlso []

Definition at line 85 of file darRefact.c.

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 }
char * memset()
int fUpdateLevel
Definition: dar.h:64
int fVeryVerbose
Definition: dar.h:67
int nCutsMax
Definition: dar.h:62
int nLeafMax
Definition: dar.h:61
int fVerbose
Definition: dar.h:66
int nMffcMin
Definition: dar.h:60
int fUseZeros
Definition: dar.h:65
int Dar_ManRefactor ( Aig_Man_t pAig,
Dar_RefPar_t pPars 
)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 496 of file darRefact.c.

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 }
void Dar_ManRefStop(Ref_Man_t *p)
Definition: darRefact.c:166
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
ABC_DLL int Aig_ManCheck(Aig_Man_t *p)
FUNCTION DECLARATIONS ///.
Definition: aigCheck.c:45
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static Aig_Obj_t * Aig_Regular(Aig_Obj_t *p)
Definition: aig.h:246
int Aig_ObjRequiredLevel(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: aigTiming.c:100
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
static int Aig_ManNodeNum(Aig_Man_t *p)
Definition: aig.h:256
Aig_Obj_t * Dar_RefactBuildGraph(Aig_Man_t *pAig, Vec_Ptr_t *vCut, Kit_Graph_t *pGraph)
Definition: darRefact.c:313
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
void Aig_ManStartReverseLevels(Aig_Man_t *p, int nMaxLevelIncrease)
Definition: aigTiming.c:142
void Aig_ManFanoutStop(Aig_Man_t *p)
Definition: aigFanout.c:89
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
void Aig_ManStopReverseLevels(Aig_Man_t *p)
Definition: aigTiming.c:175
void Kit_GraphFree(Kit_Graph_t *pGraph)
Definition: kitGraph.c:131
void Aig_ObjReplace(Aig_Man_t *p, Aig_Obj_t *pObjOld, Aig_Obj_t *pObjNew, int fUpdateLevel)
Definition: aigObj.c:467
Definition: aig.h:69
int nMffcMin
Definition: dar.h:60
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
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
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
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
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_ManCleanup(Aig_Man_t *p)
Definition: aigMan.c:265
int Dar_ManRefactorTryCuts ( Ref_Man_t p,
Aig_Obj_t pObj,
int  nNodesSaved,
int  Required 
)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 359 of file darRefact.c.

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 }
#define Vec_VecForEachLevel(vGlob, vVec, i)
MACRO DEFINITIONS ///.
Definition: vecVec.h:55
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
Aig_Man_t * pAig
Definition: llb3Image.c:49
static void Vec_PtrCopy(Vec_Ptr_t *pDest, Vec_Ptr_t *pSour)
Definition: vecPtr.h:587
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Kit_TruthIsConst0(unsigned *pIn, int nVars)
Definition: kit.h:315
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static int Kit_GraphIsConst(Kit_Graph_t *pGraph)
Definition: kit.h:202
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
int Aig_NodeMffcSupp(Aig_Man_t *p, Aig_Obj_t *pNode, int LevelMin, Vec_Ptr_t *vSupp)
Definition: aigMffc.c:179
static int Kit_TruthIsConst1(unsigned *pIn, int nVars)
Definition: kit.h:323
void Aig_ObjCollectCut(Aig_Obj_t *pRoot, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vNodes)
Definition: aigDfs.c:1017
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
Kit_Graph_t * Kit_GraphCreateConst1()
Definition: kitGraph.c:90
static void Kit_TruthNot(unsigned *pOut, unsigned *pIn, int nVars)
Definition: kit.h:373
Kit_Graph_t * Kit_GraphCreateConst0()
Definition: kitGraph.c:69
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
void Dar_ManRefPrintStats ( Ref_Man_t p)

Function*************************************************************

Synopsis [Prints out the statistics of the manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 142 of file darRefact.c.

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 }
Aig_Man_t * pAig
Definition: llb3Image.c:49
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Aig_ManNodeNum(Aig_Man_t *p)
Definition: aig.h:256
#define ABC_PRT(a, t)
Definition: abc_global.h:220
int Aig_ManLevels(Aig_Man_t *p)
Definition: aigUtil.c:102
Ref_Man_t* Dar_ManRefStart ( Aig_Man_t pAig,
Dar_RefPar_t pPars 
)

Function*************************************************************

Synopsis [Starts the rewriting manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 108 of file darRefact.c.

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 }
char * memset()
static int Kit_TruthWordNum(int nVars)
Definition: kit.h:224
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
int nCutsMax
Definition: dar.h:62
int nLeafMax
Definition: dar.h:61
static Vec_Ptr_t * Vec_PtrAllocTruthTables(int nVars)
Definition: vecPtr.h:1065
int fVerbose
Definition: dar.h:66
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static Vec_Vec_t * Vec_VecStart(int nSize)
Definition: vecVec.h:168
typedefABC_NAMESPACE_IMPL_START struct Ref_Man_t_ Ref_Man_t
DECLARATIONS ///.
Definition: darRefact.c:35
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
static Vec_Ptr_t * Vec_PtrAllocSimInfo(int nEntries, int nWords)
Definition: vecPtr.h:929
void Dar_ManRefStop ( Ref_Man_t p)

Function*************************************************************

Synopsis [Stops the rewriting manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 166 of file darRefact.c.

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 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void Dar_ManRefPrintStats(Ref_Man_t *p)
Definition: darRefact.c:142
static void Vec_VecFree(Vec_Vec_t *p)
Definition: vecVec.h:347
#define ABC_FREE(obj)
Definition: abc_global.h:232
void Bdc_ManFree(Bdc_Man_t *p)
Definition: bdcCore.c:113
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
int Dar_ObjCutLevelAchieved ( Vec_Ptr_t vCut,
int  nLevelMin 
)

Function*************************************************************

Synopsis [Returns 1 if a non-PI node has nLevelMin or below.]

Description []

SideEffects []

SeeAlso []

Definition at line 475 of file darRefact.c.

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 }
if(last==0)
Definition: sparse_int.h:34
Definition: aig.h:69
#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
Aig_Obj_t* Dar_RefactBuildGraph ( Aig_Man_t pAig,
Vec_Ptr_t vCut,
Kit_Graph_t pGraph 
)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 313 of file darRefact.c.

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 }
static Kit_Node_t * Kit_GraphNode(Kit_Graph_t *pGraph, int i)
Definition: kit.h:211
static int Kit_GraphIsComplement(Kit_Graph_t *pGraph)
Definition: kit.h:205
static int Kit_GraphIsVar(Kit_Graph_t *pGraph)
Definition: kit.h:206
#define Kit_GraphForEachLeaf(pGraph, pLeaf, i)
Definition: kit.h:502
void * pFunc
Definition: kit.h:73
Aig_Obj_t * Aig_And(Aig_Man_t *p, Aig_Obj_t *p0, Aig_Obj_t *p1)
Definition: aigOper.c:104
static int Kit_GraphIsConst(Kit_Graph_t *pGraph)
Definition: kit.h:202
#define Kit_GraphForEachNode(pGraph, pAnd, i)
Definition: kit.h:504
if(last==0)
Definition: sparse_int.h:34
Definition: aig.h:69
static Aig_Obj_t * Aig_ManConst1(Aig_Man_t *p)
Definition: aig.h:264
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
static Kit_Node_t * Kit_GraphVar(Kit_Graph_t *pGraph)
Definition: kit.h:215
static Aig_Obj_t * Aig_NotCond(Aig_Obj_t *p, int c)
Definition: aig.h:248
int Dar_RefactTryGraph ( Aig_Man_t pAig,
Aig_Obj_t pRoot,
Vec_Ptr_t vCut,
Kit_Graph_t pGraph,
int  NodeMax,
int  LevelMax 
)

Function*************************************************************

Synopsis [Counts the number of new nodes added when using this graph.]

Description [AIG nodes for the fanins should be assigned to pNode->pFunc of the leaves of the graph before calling this procedure. Returns -1 if the number of nodes and levels exceeded the given limit or the number of levels exceeded the maximum allowed level.]

SideEffects []

SeeAlso []

Definition at line 228 of file darRefact.c.

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 }
Kit_Edge_t eEdge0
Definition: kit.h:69
unsigned Level
Definition: aig.h:82
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
Kit_Edge_t eEdge1
Definition: kit.h:70
static Aig_Obj_t * Aig_Regular(Aig_Obj_t *p)
Definition: aig.h:246
static int Kit_GraphIsVar(Kit_Graph_t *pGraph)
Definition: kit.h:206
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
#define Kit_GraphForEachLeaf(pGraph, pLeaf, i)
Definition: kit.h:502
void * pFunc
Definition: kit.h:73
static int Kit_GraphIsConst(Kit_Graph_t *pGraph)
Definition: kit.h:202
unsigned fCompl
Definition: kit.h:62
#define Kit_GraphForEachNode(pGraph, pAnd, i)
Definition: kit.h:504
unsigned Node
Definition: kit.h:63
Definition: aig.h:69
static int Counter
Aig_Obj_t * Aig_TableLookupTwo(Aig_Man_t *p, Aig_Obj_t *pFanin0, Aig_Obj_t *pFanin1)
Definition: aigTable.c:146
unsigned Level
Definition: kit.h:74
static Aig_Obj_t * Aig_ManConst1(Aig_Man_t *p)
Definition: aig.h:264
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
#define assert(ex)
Definition: util_old.h:213
static Aig_Obj_t * Aig_NotCond(Aig_Obj_t *p, int c)
Definition: aig.h:248
void Ref_ObjComputeCuts ( Aig_Man_t pAig,
Aig_Obj_t pRoot,
Vec_Vec_t vCuts 
)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 192 of file darRefact.c.

193 {
194 }
void Ref_ObjPrint ( Aig_Obj_t pObj)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 207 of file darRefact.c.

208 {
209  printf( "%d", pObj? Aig_Regular(pObj)->Id : -1 );
210  if ( pObj )
211  printf( "(%d) ", Aig_IsComplement(pObj) );
212 }
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