abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
absIter.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [absIter.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Abstraction package.]
8 
9  Synopsis [Iterative improvement of abstraction.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: absIter.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "abs.h"
22 #include "sat/bmc/bmc.h"
23 
25 
26 
27 ////////////////////////////////////////////////////////////////////////
28 /// DECLARATIONS ///
29 ////////////////////////////////////////////////////////////////////////
30 
31 static inline int Gia_ObjIsInGla( Gia_Man_t * p, Gia_Obj_t * pObj ) { return Vec_IntEntry(p->vGateClasses, Gia_ObjId(p, pObj)); }
32 static inline void Gia_ObjAddToGla( Gia_Man_t * p, Gia_Obj_t * pObj ) { Vec_IntWriteEntry(p->vGateClasses, Gia_ObjId(p, pObj), 1); }
33 static inline void Gia_ObjRemFromGla( Gia_Man_t * p, Gia_Obj_t * pObj ) { Vec_IntWriteEntry(p->vGateClasses, Gia_ObjId(p, pObj), 0); }
34 
35 ////////////////////////////////////////////////////////////////////////
36 /// FUNCTION DEFINITIONS ///
37 ////////////////////////////////////////////////////////////////////////
38 
39 /**Function*************************************************************
40 
41  Synopsis []
42 
43  Description []
44 
45  SideEffects []
46 
47  SeeAlso []
48 
49 ***********************************************************************/
50 int Gia_IterTryImprove( Gia_Man_t * p, int nTimeOut, int iFrame0 )
51 {
52  Gia_Man_t * pAbs = Gia_ManDupAbsGates( p, p->vGateClasses );
53  Aig_Man_t * pAig = Gia_ManToAigSimple( pAbs );
54  int nStart = 0;
55  int nFrames = iFrame0 ? iFrame0 + 1 : 10000000;
56  int nNodeDelta = 2000;
57  int nBTLimit = 0;
58  int nBTLimitAll = 0;
59  int fVerbose = 0;
60  int RetValue, iFrame;
61  RetValue = Saig_BmcPerform( pAig, nStart, nFrames, nNodeDelta, nTimeOut, nBTLimit, nBTLimitAll, fVerbose, 0, &iFrame, 1 );
62  assert( RetValue == 0 || RetValue == -1 );
63  Aig_ManStop( pAig );
64  Gia_ManStop( pAbs );
65  return iFrame;
66 }
67 Gia_Man_t * Gia_ManShrinkGla( Gia_Man_t * p, int nFrameMax, int nTimeOut, int fUsePdr, int fUseSat, int fUseBdd, int fVerbose )
68 {
69  Gia_Obj_t * pObj;
70  int i, iFrame0, iFrame;
71  int nTotal = 0, nRemoved = 0;
72  Vec_Int_t * vGScopy;
73  abctime clk, clkTotal = Abc_Clock();
74  assert( Gia_ManPoNum(p) == 1 );
75  assert( p->vGateClasses != NULL );
76  vGScopy = Vec_IntDup( p->vGateClasses );
77  if ( nFrameMax == 0 )
78  iFrame0 = Gia_IterTryImprove( p, 0, 0 );
79  else
80  iFrame0 = nFrameMax - 1;
81  while ( 1 )
82  {
83  int fChanges = 0;
84  Gia_ManForEachObj1( p, pObj, i )
85  {
86  if ( pObj->fMark0 )
87  continue;
88  if ( !Gia_ObjIsInGla(p, pObj) )
89  continue;
90  if ( pObj == Gia_ObjFanin0( Gia_ManPo(p, 0) ) )
91  continue;
92  if ( Gia_ObjIsAnd(pObj) )
93  {
94  if ( Gia_ObjIsInGla(p, Gia_ObjFanin0(pObj)) && Gia_ObjIsInGla(p, Gia_ObjFanin1(pObj)) )
95  continue;
96  }
97  if ( Gia_ObjIsRo(p, pObj) )
98  {
99  if ( Gia_ObjIsInGla(p, Gia_ObjFanin0(Gia_ObjRoToRi(p, pObj))) )
100  continue;
101  }
102  clk = Abc_Clock();
103  printf( "%5d : ", nTotal );
104  printf( "Obj =%7d ", i );
105  Gia_ObjRemFromGla( p, pObj );
106  iFrame = Gia_IterTryImprove( p, nTimeOut, iFrame0 );
107  if ( nFrameMax )
108  assert( iFrame <= nFrameMax );
109  else
110  assert( iFrame <= iFrame0 );
111  printf( "Frame =%6d ", iFrame );
112  if ( iFrame < iFrame0 )
113  {
114  pObj->fMark0 = 1;
115  Gia_ObjAddToGla( p, pObj );
116  printf( " " );
117  }
118  else
119  {
120  fChanges = 1;
121  nRemoved++;
122  printf( "Removing " );
123  Vec_IntWriteEntry( vGScopy, Gia_ObjId(p, pObj), 0 );
124  }
125  Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
126  nTotal++;
127  // update the classes
128  Vec_IntFreeP( &p->vGateClasses );
129  p->vGateClasses = Vec_IntDup(vGScopy);
130  }
131  if ( !fChanges )
132  break;
133  }
135  Vec_IntFree( vGScopy );
136  printf( "Tried = %d. ", nTotal );
137  printf( "Removed = %d. (%.2f %%) ", nRemoved, 100.0 * nRemoved / Vec_IntCountPositive(p->vGateClasses) );
138  Abc_PrintTime( 1, "Time", Abc_Clock() - clkTotal );
139  return NULL;
140 }
141 
142 ////////////////////////////////////////////////////////////////////////
143 /// END OF FILE ///
144 ////////////////////////////////////////////////////////////////////////
145 
146 
148 
static int Vec_IntCountPositive(Vec_Int_t *p)
Definition: vecInt.h:1175
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
Aig_Man_t * Gia_ManToAigSimple(Gia_Man_t *p)
Definition: giaAig.c:367
static Vec_Int_t * Vec_IntDup(Vec_Int_t *pVec)
Definition: vecInt.h:214
static int Gia_ManPoNum(Gia_Man_t *p)
Definition: gia.h:386
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
static void Gia_ObjAddToGla(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: absIter.c:32
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
void Aig_ManStop(Aig_Man_t *p)
Definition: aigMan.c:187
static Gia_Obj_t * Gia_ManPo(Gia_Man_t *p, int v)
Definition: gia.h:406
void Gia_ManCleanMark0(Gia_Man_t *p)
Definition: giaUtil.c:215
Gia_Man_t * Gia_ManDupAbsGates(Gia_Man_t *p, Vec_Int_t *vGateClasses)
Definition: absDup.c:220
int Saig_BmcPerform(Aig_Man_t *pAig, int nStart, int nFramesMax, int nNodesMax, int nTimeOut, int nConfMaxOne, int nConfMaxAll, int fVerbose, int fVerbOverwrite, int *piFrames, int fSilent)
Definition: bmcBmc2.c:761
static abctime Abc_Clock()
Definition: abc_global.h:279
Definition: gia.h:75
int Gia_IterTryImprove(Gia_Man_t *p, int nTimeOut, int iFrame0)
FUNCTION DEFINITIONS ///.
Definition: absIter.c:50
static ABC_NAMESPACE_IMPL_START int Gia_ObjIsInGla(Gia_Man_t *p, Gia_Obj_t *pObj)
DECLARATIONS ///.
Definition: absIter.c:31
static void Abc_PrintTime(int level, const char *pStr, abctime time)
Definition: abc_global.h:367
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
Definition: gia.h:454
Gia_Man_t * Gia_ManShrinkGla(Gia_Man_t *p, int nFrameMax, int nTimeOut, int fUsePdr, int fUseSat, int fUseBdd, int fVerbose)
Definition: absIter.c:67
static int Gia_ObjIsRo(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:443
Vec_Int_t * vGateClasses
Definition: gia.h:141
static Gia_Obj_t * Gia_ObjRoToRi(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:446
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static int Gia_ObjId(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:410
static void Vec_IntFreeP(Vec_Int_t **p)
Definition: vecInt.h:289
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static void Gia_ObjRemFromGla(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: absIter.c:33
unsigned fMark0
Definition: gia.h:79
Definition: gia.h:95
static int Gia_ObjIsAnd(Gia_Obj_t *pObj)
Definition: gia.h:422
static Gia_Obj_t * Gia_ObjFanin1(Gia_Obj_t *pObj)
Definition: gia.h:455
#define assert(ex)
Definition: util_old.h:213
#define Gia_ManForEachObj1(p, pObj, i)
Definition: gia.h:986
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
ABC_INT64_T abctime
Definition: abc_global.h:278
int nTotal
DECLARATIONS ///.
Definition: cutTruth.c:37