abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
giaRetime.c File Reference
#include "gia.h"

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START int Gia_ManMarkAutonomous_rec (Gia_Man_t *p, Gia_Obj_t *pObj)
 DECLARATIONS ///. More...
 
void Gia_ManMarkAutonomous (Gia_Man_t *p)
 
void Gia_ManRetimeDup_rec (Gia_Man_t *pNew, Gia_Obj_t *pObj)
 
Gia_Man_tGia_ManRetimeDupForward (Gia_Man_t *p, Vec_Ptr_t *vCut)
 
Gia_Man_tGia_ManRetimeForwardOne (Gia_Man_t *p, int *pnRegFixed, int *pnRegMoves)
 
Gia_Man_tGia_ManRetimeForward (Gia_Man_t *p, int nMaxIters, int fVerbose)
 

Function Documentation

void Gia_ManMarkAutonomous ( Gia_Man_t p)

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

Synopsis [Marks with current trav ROs reachable from Const0 and PIs.]

Description []

SideEffects []

SeeAlso []

Definition at line 74 of file giaRetime.c.

75 {
76  Gia_Obj_t * pObj;
77  int i;
78  Gia_ManCleanMark0( p );
80  Gia_ManForEachRo( p, pObj, i )
81  Gia_ManMarkAutonomous_rec( p, pObj );
83  Gia_ManForEachRo( p, pObj, i )
84  if ( pObj->fMark0 )
85  Gia_ObjSetTravIdCurrent( p, pObj );
86  Gia_ManCleanMark0( p );
87 }
void Gia_ManCleanMark0(Gia_Man_t *p)
Definition: giaUtil.c:215
Definition: gia.h:75
static void Gia_ObjSetTravIdCurrent(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:531
if(last==0)
Definition: sparse_int.h:34
ABC_NAMESPACE_IMPL_START int Gia_ManMarkAutonomous_rec(Gia_Man_t *p, Gia_Obj_t *pObj)
DECLARATIONS ///.
Definition: giaRetime.c:45
#define Gia_ManForEachRo(p, pObj, i)
Definition: gia.h:1038
void Gia_ManIncrementTravId(Gia_Man_t *p)
Definition: giaUtil.c:149
ABC_NAMESPACE_IMPL_START int Gia_ManMarkAutonomous_rec ( Gia_Man_t p,
Gia_Obj_t pObj 
)

DECLARATIONS ///.

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

FileName [giaRetime.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Scalable AIG package.]

Synopsis [Performs most-forward retiming for AIG with flop classes.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id:
giaRetime.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis [Marks objects reachables from Const0 and PIs/

Description []

SideEffects []

SeeAlso []

Definition at line 45 of file giaRetime.c.

46 {
47  if ( Gia_ObjIsTravIdCurrent(p, pObj) )
48  return pObj->fMark0;
49  Gia_ObjSetTravIdCurrent(p, pObj);
50  assert( pObj->fMark0 == 0 );
51  if ( Gia_ObjIsPi(p, pObj) || Gia_ObjIsConst0(pObj) )
52  return pObj->fMark0 = 1;
53  if ( Gia_ObjIsCo(pObj) )
54  return pObj->fMark0 = Gia_ManMarkAutonomous_rec( p, Gia_ObjFanin0(pObj) );
55  if ( Gia_ObjIsCi(pObj) )
56  return pObj->fMark0 = Gia_ManMarkAutonomous_rec( p, Gia_ObjRoToRi(p, pObj) );
57  assert( Gia_ObjIsAnd(pObj) );
58  if ( Gia_ManMarkAutonomous_rec( p, Gia_ObjFanin0(pObj) ) )
59  return pObj->fMark0 = 1;
60  return pObj->fMark0 = Gia_ManMarkAutonomous_rec( p, Gia_ObjFanin1(pObj) );
61 }
static int Gia_ObjIsTravIdCurrent(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:533
static int Gia_ObjIsConst0(Gia_Obj_t *pObj)
Definition: gia.h:430
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
Definition: gia.h:454
static Gia_Obj_t * Gia_ObjRoToRi(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:446
static void Gia_ObjSetTravIdCurrent(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:531
static int Gia_ObjIsCo(Gia_Obj_t *pObj)
Definition: gia.h:421
unsigned fMark0
Definition: gia.h:79
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
ABC_NAMESPACE_IMPL_START int Gia_ManMarkAutonomous_rec(Gia_Man_t *p, Gia_Obj_t *pObj)
DECLARATIONS ///.
Definition: giaRetime.c:45
#define assert(ex)
Definition: util_old.h:213
static int Gia_ObjIsCi(Gia_Obj_t *pObj)
Definition: gia.h:420
static int Gia_ObjIsPi(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:441
void Gia_ManRetimeDup_rec ( Gia_Man_t pNew,
Gia_Obj_t pObj 
)

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

Synopsis [Duplicates the AIG recursively.]

Description []

SideEffects []

SeeAlso []

Definition at line 100 of file giaRetime.c.

101 {
102  if ( ~pObj->Value )
103  return;
104  assert( Gia_ObjIsAnd(pObj) );
105  Gia_ManRetimeDup_rec( pNew, Gia_ObjFanin0(pObj) );
106  Gia_ManRetimeDup_rec( pNew, Gia_ObjFanin1(pObj) );
107  pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
108 }
void Gia_ManRetimeDup_rec(Gia_Man_t *pNew, Gia_Obj_t *pObj)
Definition: giaRetime.c:100
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
Definition: gia.h:454
static int Gia_ObjFanin1Copy(Gia_Obj_t *pObj)
Definition: gia.h:482
static int Gia_ObjFanin0Copy(Gia_Obj_t *pObj)
Definition: gia.h:481
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
unsigned Value
Definition: gia.h:87
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition: giaHash.c:572
Gia_Man_t* Gia_ManRetimeDupForward ( Gia_Man_t p,
Vec_Ptr_t vCut 
)

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

Synopsis [Duplicates the AIG while retiming the registers to the cut.]

Description []

SideEffects []

SeeAlso []

Definition at line 121 of file giaRetime.c.

122 {
123  Gia_Man_t * pNew, * pTemp;
124  Gia_Obj_t * pObj, * pObjRi, * pObjRo;
125  int i;
126  // create the new manager
127  pNew = Gia_ManStart( Gia_ManObjNum(p) );
128  pNew->pName = Abc_UtilStrsav( p->pName );
129  pNew->pSpec = Abc_UtilStrsav( p->pSpec );
130  Gia_ManHashAlloc( pNew );
131  // create the true PIs
132  Gia_ManFillValue( p );
133  Gia_ManSetPhase( p );
134  Gia_ManConst0(p)->Value = 0;
135  Gia_ManForEachPi( p, pObj, i )
136  pObj->Value = Gia_ManAppendCi( pNew );
137  // create the registers
138  Vec_PtrForEachEntry( Gia_Obj_t *, vCut, pObj, i )
139  pObj->Value = Abc_LitNotCond( Gia_ManAppendCi(pNew), pObj->fPhase );
140  // duplicate logic above the cut
141  Gia_ManForEachCo( p, pObj, i )
142  Gia_ManRetimeDup_rec( pNew, Gia_ObjFanin0(pObj) );
143  // create the true POs
144  Gia_ManForEachPo( p, pObj, i )
145  Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
146  // remember value in LI
147  Gia_ManForEachRi( p, pObj, i )
148  pObj->Value = Gia_ObjFanin0Copy(pObj);
149  // transfer values from the LIs to the LOs
150  Gia_ManForEachRiRo( p, pObjRi, pObjRo, i )
151  pObjRo->Value = pObjRi->Value;
152  // erase the data values on the internal nodes of the cut
153  Vec_PtrForEachEntry( Gia_Obj_t *, vCut, pObj, i )
154  if ( Gia_ObjIsAnd(pObj) )
155  pObj->Value = ~0;
156  // duplicate logic below the cut
157  Vec_PtrForEachEntry( Gia_Obj_t *, vCut, pObj, i )
158  {
159  Gia_ManRetimeDup_rec( pNew, pObj );
160  Gia_ManAppendCo( pNew, Abc_LitNotCond( pObj->Value, pObj->fPhase ) );
161  }
162  Gia_ManHashStop( pNew );
163  Gia_ManSetRegNum( pNew, Vec_PtrSize(vCut) );
164  pNew = Gia_ManCleanup( pTemp = pNew );
165  Gia_ManStop( pTemp );
166  return pNew;
167 }
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
#define Gia_ManForEachCo(p, pObj, i)
Definition: gia.h:1022
static int Gia_ManAppendCo(Gia_Man_t *p, int iLit0)
Definition: gia.h:703
void Gia_ManRetimeDup_rec(Gia_Man_t *pNew, Gia_Obj_t *pObj)
Definition: giaRetime.c:100
static int Gia_ManAppendCi(Gia_Man_t *p)
Definition: gia.h:583
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
Definition: giaMan.c:628
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static int Abc_LitNotCond(int Lit, int c)
Definition: abc_global.h:267
Definition: gia.h:75
#define Gia_ManForEachRiRo(p, pObjRi, pObjRo, i)
Definition: gia.h:1042
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
Definition: gia.h:454
char * pName
Definition: gia.h:97
if(last==0)
Definition: sparse_int.h:34
char * pSpec
Definition: gia.h:98
Gia_Man_t * Gia_ManStart(int nObjsMax)
DECLARATIONS ///.
Definition: giaMan.c:52
void Gia_ManFillValue(Gia_Man_t *p)
Definition: giaUtil.c:328
#define Gia_ManForEachPi(p, pObj, i)
Definition: gia.h:1034
static int Gia_ObjFanin0Copy(Gia_Obj_t *pObj)
Definition: gia.h:481
Definition: gia.h:95
static int Gia_ObjIsAnd(Gia_Obj_t *pObj)
Definition: gia.h:422
static Gia_Obj_t * Gia_ManConst0(Gia_Man_t *p)
Definition: gia.h:400
void Gia_ManSetPhase(Gia_Man_t *p)
Definition: giaUtil.c:379
unsigned Value
Definition: gia.h:87
#define Gia_ManForEachRi(p, pObj, i)
Definition: gia.h:1040
void Gia_ManHashAlloc(Gia_Man_t *p)
Definition: giaHash.c:99
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
Definition: giaScl.c:84
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
#define Gia_ManForEachPo(p, pObj, i)
Definition: gia.h:1036
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
void Gia_ManHashStop(Gia_Man_t *p)
Definition: giaHash.c:142
Gia_Man_t* Gia_ManRetimeForward ( Gia_Man_t p,
int  nMaxIters,
int  fVerbose 
)

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

Synopsis [Derives the cut for forward retiming.]

Description [Assumes topological ordering of the nodes.]

SideEffects []

SeeAlso []

Definition at line 267 of file giaRetime.c.

268 {
269  Gia_Man_t * pNew, * pTemp;
270  int i, nRegFixed, nRegMoves = 1;
271  abctime clk;
272  pNew = p;
273  for ( i = 0; i < nMaxIters && nRegMoves > 0; i++ )
274  {
275  clk = Abc_Clock();
276  pNew = Gia_ManRetimeForwardOne( pTemp = pNew, &nRegFixed, &nRegMoves );
277  if ( fVerbose )
278  {
279  printf( "%2d : And = %6d. Reg = %5d. Unret = %5d. Move = %6d. ",
280  i + 1, Gia_ManAndNum(pTemp), Gia_ManRegNum(pTemp), nRegFixed, nRegMoves );
281  ABC_PRT( "Time", Abc_Clock() - clk );
282  }
283  if ( pTemp != p )
284  Gia_ManStop( pTemp );
285  }
286 /*
287  clk = Abc_Clock();
288  pNew = Gia_ManReduceLaches( pNew, fVerbose );
289  if ( fVerbose )
290  {
291  ABC_PRT( "Register sharing time", Abc_Clock() - clk );
292  }
293 */
294  return pNew;
295 }
Gia_Man_t * Gia_ManRetimeForwardOne(Gia_Man_t *p, int *pnRegFixed, int *pnRegMoves)
Definition: giaRetime.c:180
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static abctime Abc_Clock()
Definition: abc_global.h:279
static int Gia_ManAndNum(Gia_Man_t *p)
Definition: gia.h:389
Definition: gia.h:95
#define ABC_PRT(a, t)
Definition: abc_global.h:220
ABC_INT64_T abctime
Definition: abc_global.h:278
static int Gia_ManRegNum(Gia_Man_t *p)
Definition: gia.h:387
Gia_Man_t* Gia_ManRetimeForwardOne ( Gia_Man_t p,
int *  pnRegFixed,
int *  pnRegMoves 
)

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

Synopsis [Derives the cut for forward retiming.]

Description [Assumes topological ordering of the nodes.]

SideEffects []

SeeAlso []

Definition at line 180 of file giaRetime.c.

181 {
182  Vec_Int_t * vFlopClasses = NULL;
183  Vec_Int_t * vObjClasses = NULL;
184  Gia_Man_t * pNew;
185  Vec_Ptr_t * vCut;
186  Gia_Obj_t * pObj;
187  int i;
188  if ( p->vFlopClasses )
189  {
190 // printf( "Performing retiming with register classes.\n" );
191  vObjClasses = Vec_IntAlloc( Gia_ManObjNum(p) );
192  for ( i = 0; i < Gia_ManObjNum(p); i++ )
193  Vec_IntPush( vObjClasses, -1 );
194  Gia_ManForEachRo( p, pObj, i )
195  Vec_IntWriteEntry( vObjClasses, Gia_ObjId(p, pObj), Vec_IntEntry(p->vFlopClasses, i) );
196  vFlopClasses = Vec_IntAlloc( Gia_ManRegNum(p) );
197  }
198  // mark the retimable nodes
201  // mark the retimable registers with the fresh trav ID
203  *pnRegFixed = 0;
204  Gia_ManForEachRo( p, pObj, i )
205  if ( Gia_ObjIsTravIdPrevious(p, pObj) )
206  Gia_ObjSetTravIdCurrent(p, pObj);
207  else
208  (*pnRegFixed)++;
209  // mark all the nodes that can be retimed forward
210  *pnRegMoves = 0;
211  Gia_ManForEachAnd( p, pObj, i )
213  {
214  if ( vObjClasses && Vec_IntEntry(vObjClasses, Gia_ObjFaninId0(pObj, i)) != Vec_IntEntry(vObjClasses, Gia_ObjFaninId1(pObj, i)) )
215  continue;
216  if ( vObjClasses )
217  Vec_IntWriteEntry( vObjClasses, Gia_ObjId(p, pObj), Vec_IntEntry(vObjClasses, Gia_ObjFaninId0(pObj, i)) );
218  Gia_ObjSetTravIdCurrent(p, pObj);
219  (*pnRegMoves)++;
220  }
221  // mark the remaining registers
222  Gia_ManForEachRo( p, pObj, i )
223  Gia_ObjSetTravIdCurrent(p, pObj);
224  // find the cut (all such marked objects that fanout into unmarked nodes)
225  vCut = Vec_PtrAlloc( 1000 );
227  Gia_ManForEachObj( p, pObj, i )
228  {
229  if ( Gia_ObjIsTravIdPrevious(p, pObj) )
230  continue;
231  if ( (Gia_ObjIsCo(pObj) || Gia_ObjIsAnd(pObj)) && Gia_ObjIsTravIdPrevious(p, Gia_ObjFanin0(pObj)) )
232  {
233  if ( vFlopClasses )
234  Vec_IntPush( vFlopClasses, Vec_IntEntry(vObjClasses, Gia_ObjFaninId0(pObj, i)) );
235  Vec_PtrPush( vCut, Gia_ObjFanin0(pObj) );
237  }
238  if ( Gia_ObjIsAnd(pObj) && Gia_ObjIsTravIdPrevious(p, Gia_ObjFanin1(pObj)) )
239  {
240  if ( vFlopClasses )
241  Vec_IntPush( vFlopClasses, Vec_IntEntry(vObjClasses, Gia_ObjFaninId1(pObj, i)) );
242  Vec_PtrPush( vCut, Gia_ObjFanin1(pObj) );
244  }
245  }
246  assert( vFlopClasses == NULL || Vec_IntSize(vFlopClasses) == Vec_PtrSize(vCut) );
247  // finally derive the new manager
248  pNew = Gia_ManRetimeDupForward( p, vCut );
249  Vec_PtrFree( vCut );
250  if ( vObjClasses )
251  Vec_IntFree( vObjClasses );
252  pNew->vFlopClasses = vFlopClasses;
253  return pNew;
254 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static int Gia_ObjIsTravIdPrevious(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:534
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static int Gia_ObjIsTravIdCurrent(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:533
Vec_Int_t * vFlopClasses
Definition: gia.h:140
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
Definition: gia.h:75
Gia_Man_t * Gia_ManRetimeDupForward(Gia_Man_t *p, Vec_Ptr_t *vCut)
Definition: giaRetime.c:121
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
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
static void Gia_ObjSetTravIdCurrent(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:531
if(last==0)
Definition: sparse_int.h:34
else
Definition: sparse_int.h:55
#define Gia_ManForEachAnd(p, pObj, i)
Definition: gia.h:1002
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static int Gia_ObjId(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:410
static int Gia_ObjIsCo(Gia_Obj_t *pObj)
Definition: gia.h:421
void Gia_ManMarkAutonomous(Gia_Man_t *p)
Definition: giaRetime.c:74
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
Definition: gia.h:95
static int Gia_ObjIsAnd(Gia_Obj_t *pObj)
Definition: gia.h:422
#define Gia_ManForEachObj(p, pObj, i)
MACRO DEFINITIONS ///.
Definition: gia.h:984
static Gia_Obj_t * Gia_ObjFanin1(Gia_Obj_t *pObj)
Definition: gia.h:455
#define Gia_ManForEachRo(p, pObj, i)
Definition: gia.h:1038
#define assert(ex)
Definition: util_old.h:213
void Gia_ManIncrementTravId(Gia_Man_t *p)
Definition: giaUtil.c:149
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static int Gia_ObjFaninId1(Gia_Obj_t *pObj, int ObjId)
Definition: gia.h:461
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
static int Gia_ObjFaninId0(Gia_Obj_t *pObj, int ObjId)
Definition: gia.h:460
static int Gia_ManRegNum(Gia_Man_t *p)
Definition: gia.h:387