abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
saigRetFwd.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [saigRetFwd.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Sequential AIG package.]
8 
9  Synopsis [Most-forward retiming.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: saigRetFwd.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "saig.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 static inline Aig_Obj_t * Aig_ObjFanoutStatic( Aig_Obj_t * pObj, int i ) { return ((Aig_Obj_t **)pObj->pData)[i]; }
31 static inline void Aig_ObjSetFanoutStatic( Aig_Obj_t * pObj, Aig_Obj_t * pFan ) { ((Aig_Obj_t **)pObj->pData)[pObj->nRefs++] = pFan; }
32 
33 #define Aig_ObjForEachFanoutStatic( pObj, pFan, i ) \
34  for ( i = 0; (i < (int)(pObj)->nRefs) && ((pFan) = Aig_ObjFanoutStatic(pObj, i)); i++ )
35 
36 ////////////////////////////////////////////////////////////////////////
37 /// FUNCTION DEFINITIONS ///
38 ////////////////////////////////////////////////////////////////////////
39 
40 /**Function*************************************************************
41 
42  Synopsis [Allocate static fanout for all nodes in the AIG manager.]
43 
44  Description []
45 
46  SideEffects []
47 
48  SeeAlso []
49 
50 ***********************************************************************/
52 {
53  Aig_Obj_t ** ppFanouts, * pObj;
54  int i, nFanouts, nFanoutsAlloc;
55  // allocate fanouts
56  nFanoutsAlloc = 2 * Aig_ManObjNumMax(p) - Aig_ManCiNum(p) - Aig_ManCoNum(p);
57  ppFanouts = ABC_ALLOC( Aig_Obj_t *, nFanoutsAlloc );
58  // mark up storage
59  nFanouts = 0;
60  Aig_ManForEachObj( p, pObj, i )
61  {
62  pObj->pData = ppFanouts + nFanouts;
63  nFanouts += pObj->nRefs;
64  pObj->nRefs = 0;
65  }
66  assert( nFanouts < nFanoutsAlloc );
67  // add fanouts
68  Aig_ManForEachObj( p, pObj, i )
69  {
70  if ( Aig_ObjChild0(pObj) )
72  if ( Aig_ObjChild1(pObj) )
74  }
75  return ppFanouts;
76 }
77 
78 /**Function*************************************************************
79 
80  Synopsis [Marks the objects reachable from the given object.]
81 
82  Description []
83 
84  SideEffects []
85 
86  SeeAlso []
87 
88 ***********************************************************************/
90 {
91  Aig_Obj_t * pFanout;
92  int i;
93  if ( Aig_ObjIsTravIdCurrent(p, pObj) )
94  return;
95  Aig_ObjSetTravIdCurrent(p, pObj);
96  Aig_ObjForEachFanoutStatic( pObj, pFanout, i )
97  Aig_ManMarkAutonomous_rec( p, pFanout );
98 }
99 
100 /**Function*************************************************************
101 
102  Synopsis [Marks with current trav ID nodes reachable from Const1 and PIs.]
103 
104  Description [Returns the number of unreachable registers.]
105 
106  SideEffects []
107 
108  SeeAlso []
109 
110 ***********************************************************************/
112 {
113  Aig_Obj_t ** ppFanouts;
114  Aig_Obj_t * pObj, * pObjLi, * pObjLo;
115  int i;
116  // temporarily connect register outputs to register inputs
117  Saig_ManForEachLiLo( p, pObjLi, pObjLo, i )
118  {
119  pObjLo->pFanin0 = pObjLi;
120  pObjLi->nRefs = 1;
121  }
122  // mark nodes reachable from Const1 and PIs
124  ppFanouts = Aig_ManStaticFanoutStart( p );
126  Saig_ManForEachPi( p, pObj, i )
127  Aig_ManMarkAutonomous_rec( p, pObj );
128  ABC_FREE( ppFanouts );
129  // disconnect LIs/LOs and label unreachable registers
130  Saig_ManForEachLiLo( p, pObjLi, pObjLo, i )
131  {
132  assert( pObjLo->pFanin0 && pObjLi->nRefs == 1 );
133  pObjLo->pFanin0 = NULL;
134  pObjLi->nRefs = 0;
135  }
136 }
137 
138 /**Function*************************************************************
139 
140  Synopsis [Derives the cut for forward retiming.]
141 
142  Description [Assumes topological ordering of the nodes.]
143 
144  SideEffects []
145 
146  SeeAlso []
147 
148 ***********************************************************************/
149 Aig_Man_t * Saig_ManRetimeForwardOne( Aig_Man_t * p, int * pnRegFixed, int * pnRegMoves )
150 {
151  Aig_Man_t * pNew;
152  Vec_Ptr_t * vCut;
153  Aig_Obj_t * pObj, * pFanin;
154  int i;
155  // mark the retimable nodes
157  // mark the retimable registers with the fresh trav ID
159  *pnRegFixed = 0;
160  Saig_ManForEachLo( p, pObj, i )
161  if ( Aig_ObjIsTravIdPrevious(p, pObj) )
162  Aig_ObjSetTravIdCurrent(p, pObj);
163  else
164  (*pnRegFixed)++;
165  // mark all the nodes that can be retimed forward
166  *pnRegMoves = 0;
167  Aig_ManForEachNode( p, pObj, i )
169  {
170  Aig_ObjSetTravIdCurrent(p, pObj);
171  (*pnRegMoves)++;
172  }
173  // mark the remaining registers
174  Saig_ManForEachLo( p, pObj, i )
175  Aig_ObjSetTravIdCurrent(p, pObj);
176  // find the cut (all such marked objects that fanout into unmarked nodes)
177  vCut = Vec_PtrAlloc( 1000 );
179  Aig_ManForEachObj( p, pObj, i )
180  {
181  if ( Aig_ObjIsTravIdPrevious(p, pObj) )
182  continue;
183  pFanin = Aig_ObjFanin0(pObj);
184  if ( pFanin && Aig_ObjIsTravIdPrevious(p, pFanin) )
185  {
186  Vec_PtrPush( vCut, pFanin );
187  Aig_ObjSetTravIdCurrent( p, pFanin );
188  }
189  pFanin = Aig_ObjFanin1(pObj);
190  if ( pFanin && Aig_ObjIsTravIdPrevious(p, pFanin) )
191  {
192  Vec_PtrPush( vCut, pFanin );
193  Aig_ObjSetTravIdCurrent( p, pFanin );
194  }
195  }
196  // finally derive the new manager
197  pNew = Saig_ManRetimeDupForward( p, vCut );
198  Vec_PtrFree( vCut );
199  return pNew;
200 }
201 
202 /**Function*************************************************************
203 
204  Synopsis [Derives the cut for forward retiming.]
205 
206  Description [Assumes topological ordering of the nodes.]
207 
208  SideEffects []
209 
210  SeeAlso []
211 
212 ***********************************************************************/
213 Aig_Man_t * Saig_ManRetimeForward( Aig_Man_t * p, int nMaxIters, int fVerbose )
214 {
215  Aig_Man_t * pNew, * pTemp;
216  int i, nRegFixed, nRegMoves = 1;
217  abctime clk;
218  pNew = p;
219  for ( i = 0; i < nMaxIters && nRegMoves > 0; i++ )
220  {
221  clk = Abc_Clock();
222  pNew = Saig_ManRetimeForwardOne( pTemp = pNew, &nRegFixed, &nRegMoves );
223  if ( fVerbose )
224  {
225  printf( "%2d : And = %6d. Reg = %5d. Unret = %5d. Move = %6d. ",
226  i + 1, Aig_ManNodeNum(pTemp), Aig_ManRegNum(pTemp), nRegFixed, nRegMoves );
227  ABC_PRT( "Time", Abc_Clock() - clk );
228  }
229  if ( pTemp != p )
230  Aig_ManStop( pTemp );
231  }
232  clk = Abc_Clock();
233  pNew = Aig_ManReduceLaches( pNew, fVerbose );
234  if ( fVerbose )
235  {
236  ABC_PRT( "Register sharing time", Abc_Clock() - clk );
237  }
238  return pNew;
239 }
240 
241 
242 ////////////////////////////////////////////////////////////////////////
243 /// END OF FILE ///
244 ////////////////////////////////////////////////////////////////////////
245 
246 
248 
Aig_Man_t * Saig_ManRetimeForward(Aig_Man_t *p, int nMaxIters, int fVerbose)
Definition: saigRetFwd.c:213
static int Aig_ObjIsTravIdPrevious(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: aig.h:296
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
static Aig_Obj_t * Aig_ObjChild0(Aig_Obj_t *pObj)
Definition: aig.h:310
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void Aig_ManStop(Aig_Man_t *p)
Definition: aigMan.c:187
static int Aig_ObjIsTravIdCurrent(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: aig.h:295
#define Saig_ManForEachLiLo(p, pObjLi, pObjLo, i)
Definition: saig.h:101
void * pData
Definition: aig.h:87
static Aig_Obj_t * Aig_ObjFanin0(Aig_Obj_t *pObj)
Definition: aig.h:308
static ABC_NAMESPACE_IMPL_START Aig_Obj_t * Aig_ObjFanoutStatic(Aig_Obj_t *pObj, int i)
DECLARATIONS ///.
Definition: saigRetFwd.c:30
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
void Aig_ManMarkAutonomous_rec(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: saigRetFwd.c:89
static abctime Abc_Clock()
Definition: abc_global.h:279
static Aig_Obj_t * Aig_ObjFanin1(Aig_Obj_t *pObj)
Definition: aig.h:309
static void Aig_ObjSetTravIdCurrent(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: aig.h:293
static int Aig_ManNodeNum(Aig_Man_t *p)
Definition: aig.h:256
void Aig_ManIncrementTravId(Aig_Man_t *p)
DECLARATIONS ///.
Definition: aigUtil.c:44
static int Aig_ManCoNum(Aig_Man_t *p)
Definition: aig.h:252
#define Aig_ManForEachNode(p, pObj, i)
Definition: aig.h:413
Aig_Man_t * Aig_ManReduceLaches(Aig_Man_t *p, int fVerbose)
Definition: aigScl.c:455
Aig_Man_t * Saig_ManRetimeForwardOne(Aig_Man_t *p, int *pnRegFixed, int *pnRegMoves)
Definition: saigRetFwd.c:149
static int Aig_ManCiNum(Aig_Man_t *p)
Definition: aig.h:251
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static Aig_Obj_t * Aig_ObjChild1(Aig_Obj_t *pObj)
Definition: aig.h:311
Aig_Man_t * Saig_ManRetimeDupForward(Aig_Man_t *p, Vec_Ptr_t *vCut)
Definition: saigRetMin.c:281
Definition: aig.h:69
#define Saig_ManForEachLo(p, pObj, i)
Definition: saig.h:96
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
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 int Aig_ManRegNum(Aig_Man_t *p)
Definition: aig.h:260
static void Aig_ObjSetFanoutStatic(Aig_Obj_t *pObj, Aig_Obj_t *pFan)
Definition: saigRetFwd.c:31
#define Aig_ManForEachObj(p, pObj, i)
Definition: aig.h:403
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define ABC_PRT(a, t)
Definition: abc_global.h:220
#define assert(ex)
Definition: util_old.h:213
ABC_INT64_T abctime
Definition: abc_global.h:278
void Saig_ManMarkAutonomous(Aig_Man_t *p)
Definition: saigRetFwd.c:111
Aig_Obj_t * pFanin0
Definition: aig.h:75
#define Aig_ObjForEachFanoutStatic(pObj, pFan, i)
Definition: saigRetFwd.c:33
unsigned int nRefs
Definition: aig.h:81
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
Aig_Obj_t ** Aig_ManStaticFanoutStart(Aig_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition: saigRetFwd.c:51
#define Saig_ManForEachPi(p, pObj, i)
Definition: saig.h:91