abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
amapGraph.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [amapGraph.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Technology mapper for standard cells.]
8 
9  Synopsis [Internal AIG manager.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: amapGraph.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "amapInt.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis [Creates object.]
37 
38  Description []
39 
40  SideEffects []
41 
42  SeeAlso []
43 
44 ***********************************************************************/
46 {
47  Amap_Obj_t * pObj;
49  memset( pObj, 0, sizeof(Amap_Obj_t) );
50  pObj->nFouts[0] = 1; // needed for flow to work in the first pass
51  pObj->Id = Vec_PtrSize(p->vObjs);
52  Vec_PtrPush( p->vObjs, pObj );
53  return pObj;
54 }
55 
56 /**Function*************************************************************
57 
58  Synopsis [Creates constant 1 node.]
59 
60  Description []
61 
62  SideEffects []
63 
64  SeeAlso []
65 
66 ***********************************************************************/
68 {
69  Amap_Obj_t * pObj;
70  pObj = Amap_ManSetupObj( p );
71  pObj->Type = AMAP_OBJ_CONST1;
72  pObj->fPhase = 1;
73  p->nObjs[AMAP_OBJ_CONST1]++;
74  return pObj;
75 }
76 
77 /**Function*************************************************************
78 
79  Synopsis [Creates primary input.]
80 
81  Description []
82 
83  SideEffects []
84 
85  SeeAlso []
86 
87 ***********************************************************************/
89 {
90  Amap_Obj_t * pObj;
91  pObj = Amap_ManSetupObj( p );
92  pObj->Type = AMAP_OBJ_PI;
93  pObj->IdPio = Vec_PtrSize( p->vPis );
94  Vec_PtrPush( p->vPis, pObj );
95  p->nObjs[AMAP_OBJ_PI]++;
96  return pObj;
97 }
98 
99 /**Function*************************************************************
100 
101  Synopsis [Creates primary output with the given driver.]
102 
103  Description []
104 
105  SideEffects []
106 
107  SeeAlso []
108 
109 ***********************************************************************/
111 {
112  Amap_Obj_t * pObj;
113  pObj = Amap_ManSetupObj( p );
114  pObj->IdPio = Vec_PtrSize( p->vPos );
115  Vec_PtrPush( p->vPos, pObj );
116  pObj->Type = AMAP_OBJ_PO;
117  pObj->Fan[0] = Amap_ObjToLit(pFan0); Amap_Regular(pFan0)->nRefs++;
118  pObj->Level = Amap_Regular(pFan0)->Level;
119  if ( p->nLevelMax < (int)pObj->Level )
120  p->nLevelMax = (int)pObj->Level;
121  assert( p->nLevelMax < 4094 ); // 2^12-2
122  p->nObjs[AMAP_OBJ_PO]++;
123  return pObj;
124 }
125 
126 /**Function*************************************************************
127 
128  Synopsis [Create the new node assuming it does not exist.]
129 
130  Description []
131 
132  SideEffects []
133 
134  SeeAlso []
135 
136 ***********************************************************************/
138 {
139  Amap_Obj_t * pObj;
140  pObj = Amap_ManSetupObj( p );
141  pObj->Type = AMAP_OBJ_AND;
142  pObj->Fan[0] = Amap_ObjToLit(pFan0); Amap_Regular(pFan0)->nRefs++;
143  pObj->Fan[1] = Amap_ObjToLit(pFan1); Amap_Regular(pFan1)->nRefs++;
144  assert( Abc_Lit2Var(pObj->Fan[0]) != Abc_Lit2Var(pObj->Fan[1]) );
145  pObj->fPhase = Amap_ObjPhaseReal(pFan0) & Amap_ObjPhaseReal(pFan1);
146  pObj->Level = 1 + Abc_MaxInt( Amap_Regular(pFan0)->Level, Amap_Regular(pFan1)->Level );
147  if ( p->nLevelMax < (int)pObj->Level )
148  p->nLevelMax = (int)pObj->Level;
149  assert( p->nLevelMax < 4094 ); // 2^12-2
150  p->nObjs[AMAP_OBJ_AND]++;
151  return pObj;
152 }
153 
154 /**Function*************************************************************
155 
156  Synopsis [Create the new node assuming it does not exist.]
157 
158  Description []
159 
160  SideEffects []
161 
162  SeeAlso []
163 
164 ***********************************************************************/
166 {
167  Amap_Obj_t * pObj;
168  pObj = Amap_ManSetupObj( p );
169  pObj->Type = AMAP_OBJ_XOR;
170  pObj->Fan[0] = Amap_ObjToLit(pFan0); Amap_Regular(pFan0)->nRefs++;
171  pObj->Fan[1] = Amap_ObjToLit(pFan1); Amap_Regular(pFan1)->nRefs++;
172  pObj->fPhase = Amap_ObjPhaseReal(pFan0) ^ Amap_ObjPhaseReal(pFan1);
173  pObj->Level = 2 + Abc_MaxInt( Amap_Regular(pFan0)->Level, Amap_Regular(pFan1)->Level );
174  if ( p->nLevelMax < (int)pObj->Level )
175  p->nLevelMax = (int)pObj->Level;
176  assert( p->nLevelMax < 4094 ); // 2^12-2
177  p->nObjs[AMAP_OBJ_XOR]++;
178  return pObj;
179 }
180 
181 /**Function*************************************************************
182 
183  Synopsis [Create the new node assuming it does not exist.]
184 
185  Description []
186 
187  SideEffects []
188 
189  SeeAlso []
190 
191 ***********************************************************************/
193 {
194  Amap_Obj_t * pObj;
195  pObj = Amap_ManSetupObj( p );
196  pObj->Type = AMAP_OBJ_MUX;
197  pObj->Fan[0] = Amap_ObjToLit(pFan0); Amap_Regular(pFan0)->nRefs++;
198  pObj->Fan[1] = Amap_ObjToLit(pFan1); Amap_Regular(pFan1)->nRefs++;
199  pObj->Fan[2] = Amap_ObjToLit(pFanC); Amap_Regular(pFanC)->nRefs++;
200  pObj->fPhase = (Amap_ObjPhaseReal(pFan1) & Amap_ObjPhaseReal(pFanC)) |
201  (Amap_ObjPhaseReal(pFan0) & ~Amap_ObjPhaseReal(pFanC));
202  pObj->Level = Abc_MaxInt( Amap_Regular(pFan0)->Level, Amap_Regular(pFan1)->Level );
203  pObj->Level = 2 + Abc_MaxInt( pObj->Level, Amap_Regular(pFanC)->Level );
204  if ( p->nLevelMax < (int)pObj->Level )
205  p->nLevelMax = (int)pObj->Level;
206  assert( p->nLevelMax < 4094 ); // 2^12-2
207  p->nObjs[AMAP_OBJ_MUX]++;
208  return pObj;
209 }
210 
211 /**Function*************************************************************
212 
213  Synopsis [Creates the choice node.]
214 
215  Description [Should be called after the equivalence class nodes are linked.]
216 
217  SideEffects []
218 
219  SeeAlso []
220 
221 ***********************************************************************/
223 {
224  Amap_Obj_t * pTemp;
225  // mark the node as a representative if its class
226 // assert( pObj->fRepr == 0 );
227  pObj->fRepr = 1;
228  // update the level of this node (needed for correct required time computation)
229  for ( pTemp = pObj; pTemp; pTemp = Amap_ObjChoice(p, pTemp) )
230  {
231  pObj->Level = Abc_MaxInt( pObj->Level, pTemp->Level );
232 // pTemp->nVisits++; pTemp->nVisitsCopy++;
233  }
234  // mark the largest level
235  if ( p->nLevelMax < (int)pObj->Level )
236  p->nLevelMax = (int)pObj->Level;
237  assert( p->nLevelMax < 4094 ); // 2^12-2
238 }
239 
240 /**Function*************************************************************
241 
242  Synopsis [Creates XOR/MUX choices for the node.]
243 
244  Description []
245 
246  SideEffects []
247 
248  SeeAlso []
249 
250 ***********************************************************************/
251 void Amap_ManCreateXorChoices( Amap_Man_t * p, Amap_Obj_t * pFan0, Amap_Obj_t * pFan1, Amap_Obj_t * pChoices[] )
252 {
253  pChoices[0] = Amap_ManCreateXor( p, pFan0, pFan1 );
254  pChoices[1] = Amap_ManCreateXor( p, Amap_Not(pFan0), pFan1 );
255  pChoices[2] = Amap_ManCreateXor( p, pFan0, Amap_Not(pFan1) );
256  pChoices[3] = Amap_ManCreateXor( p, Amap_Not(pFan0), Amap_Not(pFan1) );
257 }
258 
259 /**Function*************************************************************
260 
261  Synopsis [Creates XOR/MUX choices for the node.]
262 
263  Description []
264 
265  SideEffects []
266 
267  SeeAlso []
268 
269 ***********************************************************************/
270 void Amap_ManCreateMuxChoices( Amap_Man_t * p, Amap_Obj_t * pFan0, Amap_Obj_t * pFan1, Amap_Obj_t * pFanC, Amap_Obj_t * pChoices[] )
271 {
272  pChoices[0] = Amap_ManCreateMux( p, pFan0, pFan1, pFanC );
273  pChoices[1] = Amap_ManCreateMux( p, Amap_Not(pFan0), Amap_Not(pFan1), pFanC );
274  pChoices[2] = Amap_ManCreateMux( p, pFan1, pFan0, Amap_Not(pFanC) );
275  pChoices[3] = Amap_ManCreateMux( p, Amap_Not(pFan1), Amap_Not(pFan0), Amap_Not(pFanC) );
276 }
277 
278 /**Function*************************************************************
279 
280  Synopsis [Drags pointer out through the copy.]
281 
282  Description []
283 
284  SideEffects []
285 
286  SeeAlso []
287 
288 ***********************************************************************/
289 static inline Amap_Obj_t * Amap_AndToObj( Aig_Obj_t * pObj )
290 {
291  return Amap_NotCond( (Amap_Obj_t *)Aig_Regular(pObj)->pData, Aig_IsComplement(pObj) );
292 }
293 
294 /**Function*************************************************************
295 
296  Synopsis [Starts the AIG manager.]
297 
298  Description []
299 
300  SideEffects []
301 
302  SeeAlso []
303 
304 ***********************************************************************/
306 {
307  if ( pObj->Equiv == 0 )
308  return pObj;
309  return Amap_ManGetLast_rec( p, Amap_ObjChoice(p, pObj) );
310 }
311 
312 /**Function*************************************************************
313 
314  Synopsis [Starts the AIG manager.]
315 
316  Description []
317 
318  SideEffects []
319 
320  SeeAlso []
321 
322 ***********************************************************************/
324 {
325  Vec_Ptr_t * vNodes;
326  Amap_Obj_t * pChoices[4];
327  Aig_Obj_t * pObj, * pFanin, * pPrev, * pFan0, * pFan1, * pFanC;
328  int i, fChoices;
329  if ( pAig->pEquivs )
330  vNodes = Aig_ManDfsChoices( pAig );
331  else
332  vNodes = Aig_ManDfs( pAig, 1 );
333  p->pConst1 = Amap_ManCreateConst1( p );
334  // print warning about excessive memory usage
335  if ( p->pPars->fVerbose )
336  {
337  if ( 1.0 * Aig_ManObjNum(pAig) * sizeof(Amap_Obj_t) / (1<<30) > 0.1 )
338  printf( "Warning: Mapper allocates %.3f GB for subject graph with %d objects.\n",
339  1.0 * Aig_ManObjNum(pAig) * sizeof(Amap_Obj_t) / (1<<30), Aig_ManObjNum(pAig) );
340  }
341  // create PIs and remember them in the old nodes
342  Aig_ManCleanData(pAig);
343  Aig_ManConst1(pAig)->pData = Amap_ManConst1( p );
344  Aig_ManForEachCi( pAig, pObj, i )
345  pObj->pData = Amap_ManCreatePi( p );
346  // load the AIG into the mapper
347  Vec_PtrForEachEntry( Aig_Obj_t *, vNodes, pObj, i )
348  {
349  fChoices = 0;
350  if ( p->fUseXor && Aig_ObjRecognizeExor(pObj, &pFan0, &pFan1 ) )
351  {
352  Amap_ManCreateXorChoices( p, Amap_AndToObj(pFan0), Amap_AndToObj(pFan1), pChoices );
353  fChoices = 1;
354  }
355  else if ( p->fUseMux && Aig_ObjIsMuxType(pObj) )
356  {
357  pFanC = Aig_ObjRecognizeMux( pObj, &pFan1, &pFan0 );
358  Amap_ManCreateMuxChoices( p, Amap_AndToObj(pFan0), Amap_AndToObj(pFan1), Amap_AndToObj(pFanC), pChoices );
359  fChoices = 1;
360  }
362  if ( fChoices )
363  {
364  p->nChoicesAdded++;
365  Amap_ObjSetChoice( (Amap_Obj_t *)pObj->pData, pChoices[0] );
366  Amap_ObjSetChoice( pChoices[0], pChoices[1] );
367  Amap_ObjSetChoice( pChoices[1], pChoices[2] );
368  Amap_ObjSetChoice( pChoices[2], pChoices[3] );
369  Amap_ManCreateChoice( p, (Amap_Obj_t *)pObj->pData );
370  }
371  if ( Aig_ObjIsChoice( pAig, pObj ) )
372  {
373 // assert( !fChoices );
374  p->nChoicesGiven++;
375  for ( pPrev = pObj, pFanin = Aig_ObjEquiv(pAig, pObj); pFanin; pPrev = pFanin, pFanin = Aig_ObjEquiv(pAig, pFanin) )
376  {
377  ((Amap_Obj_t *)pFanin->pData)->fRepr = 0;
379  (Amap_Obj_t *)pFanin->pData );
380  }
381  Amap_ManCreateChoice( p, (Amap_Obj_t *)pObj->pData );
382  }
383  }
384  Vec_PtrFree( vNodes );
385  // set the primary outputs without copying the phase
386  Aig_ManForEachCo( pAig, pObj, i )
387  pObj->pData = Amap_ManCreatePo( p, (Amap_Obj_t *)Aig_ObjChild0Copy(pObj) );
388  if ( p->pPars->fVerbose )
389  printf( "Performing mapping with %d given and %d created choices.\n",
390  p->nChoicesGiven, p->nChoicesAdded );
391 }
392 
393 ////////////////////////////////////////////////////////////////////////
394 /// END OF FILE ///
395 ////////////////////////////////////////////////////////////////////////
396 
397 
399 
char * memset()
unsigned IdPio
Definition: amapInt.h:202
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
Amap_Obj_t * Amap_ManGetLast_rec(Amap_Man_t *p, Amap_Obj_t *pObj)
Definition: amapGraph.c:305
int nChoicesAdded
Definition: amapInt.h:97
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Aig_ManObjNum(Aig_Man_t *p)
Definition: aig.h:258
void * pData
Definition: aig.h:87
static int Amap_ObjPhaseReal(Amap_Obj_t *pObj)
Definition: amapInt.h:260
int nFouts[2]
Definition: amapInt.h:217
Vec_Ptr_t * Aig_ManDfsChoices(Aig_Man_t *p)
Definition: aigDfs.c:391
Amap_Obj_t * pConst1
Definition: amapInt.h:93
static void Amap_ObjSetChoice(Amap_Obj_t *pObj, Amap_Obj_t *pEqu)
Definition: amapInt.h:259
static int Aig_IsComplement(Aig_Obj_t *p)
Definition: aig.h:249
#define Aig_ManForEachCi(p, pObj, i)
ITERATORS ///.
Definition: aig.h:393
unsigned Level
Definition: amapInt.h:206
static Aig_Obj_t * Aig_Regular(Aig_Obj_t *p)
Definition: aig.h:246
unsigned Id
Definition: amapInt.h:201
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
#define Aig_ManForEachCo(p, pObj, i)
Definition: aig.h:398
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
Amap_Obj_t * Amap_ManCreatePi(Amap_Man_t *p)
FUNCTION DECLARATIONS ///.
Definition: amapGraph.c:88
Amap_Obj_t * Amap_ManCreatePo(Amap_Man_t *p, Amap_Obj_t *pFan0)
Definition: amapGraph.c:110
int fVerbose
Definition: amap.h:55
Vec_Ptr_t * vObjs
Definition: amapInt.h:88
void * pData
Definition: amapInt.h:212
static Amap_Obj_t * Amap_Regular(Amap_Obj_t *p)
Definition: amapInt.h:221
Aig_Obj_t * Aig_ObjRecognizeMux(Aig_Obj_t *pObj, Aig_Obj_t **ppObjT, Aig_Obj_t **ppObjE)
Definition: aigUtil.c:387
int nRefs
Definition: amapInt.h:208
static int Amap_ObjToLit(Amap_Obj_t *pObj)
Definition: amapInt.h:247
ABC_NAMESPACE_IMPL_START Amap_Obj_t * Amap_ManSetupObj(Amap_Man_t *p)
DECLARATIONS ///.
Definition: amapGraph.c:45
Amap_Obj_t * Amap_ManCreateConst1(Amap_Man_t *p)
Definition: amapGraph.c:67
Vec_Ptr_t * vPis
Definition: amapInt.h:86
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
unsigned Type
Definition: amapInt.h:200
Aig_MmFixed_t * pMemObj
Definition: amapInt.h:89
static Amap_Obj_t * Amap_ManConst1(Amap_Man_t *p)
Definition: amapInt.h:234
static Aig_Obj_t * Aig_ObjEquiv(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: aig.h:328
static Aig_Obj_t * Aig_ObjChild1Copy(Aig_Obj_t *pObj)
Definition: aig.h:313
int Aig_ObjRecognizeExor(Aig_Obj_t *pObj, Aig_Obj_t **ppFan0, Aig_Obj_t **ppFan1)
Definition: aigUtil.c:343
Vec_Ptr_t * Aig_ManDfs(Aig_Man_t *p, int fNodesOnly)
Definition: aigDfs.c:145
char * Aig_MmFixedEntryFetch(Aig_MmFixed_t *p)
Definition: aigMem.c:161
Definition: aig.h:69
unsigned fPhase
Definition: amapInt.h:203
static Amap_Obj_t * Amap_AndToObj(Aig_Obj_t *pObj)
Definition: amapGraph.c:289
static Aig_Obj_t * Aig_ObjChild0Copy(Aig_Obj_t *pObj)
Definition: aig.h:312
int Fan[3]
Definition: amapInt.h:210
void Amap_ManCreateChoice(Amap_Man_t *p, Amap_Obj_t *pObj)
Definition: amapGraph.c:222
int fUseMux
Definition: amapInt.h:84
unsigned fRepr
Definition: amapInt.h:204
static Amap_Obj_t * Amap_ObjChoice(Amap_Man_t *p, Amap_Obj_t *pObj)
Definition: amapInt.h:258
static Amap_Obj_t * Amap_NotCond(Amap_Obj_t *p, int c)
Definition: amapInt.h:223
int Equiv
Definition: amapInt.h:209
static Aig_Obj_t * Aig_ManConst1(Aig_Man_t *p)
Definition: aig.h:264
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
Amap_Obj_t * Amap_ManCreateMux(Amap_Man_t *p, Amap_Obj_t *pFan0, Amap_Obj_t *pFan1, Amap_Obj_t *pFanC)
Definition: amapGraph.c:192
void Amap_ManCreateMuxChoices(Amap_Man_t *p, Amap_Obj_t *pFan0, Amap_Obj_t *pFan1, Amap_Obj_t *pFanC, Amap_Obj_t *pChoices[])
Definition: amapGraph.c:270
int nObjs[AMAP_OBJ_VOID]
Definition: amapInt.h:94
void Amap_ManCreateXorChoices(Amap_Man_t *p, Amap_Obj_t *pFan0, Amap_Obj_t *pFan1, Amap_Obj_t *pChoices[])
Definition: amapGraph.c:251
Amap_Par_t * pPars
Definition: amapInt.h:78
Amap_Obj_t * Amap_ManCreateXor(Amap_Man_t *p, Amap_Obj_t *pFan0, Amap_Obj_t *pFan1)
Definition: amapGraph.c:165
void Amap_ManCreate(Amap_Man_t *p, Aig_Man_t *pAig)
Definition: amapGraph.c:323
int Aig_ObjIsMuxType(Aig_Obj_t *pObj)
Definition: aigUtil.c:307
static int Abc_Lit2Var(int Lit)
Definition: abc_global.h:264
Amap_Obj_t * Amap_ManCreateAnd(Amap_Man_t *p, Amap_Obj_t *pFan0, Amap_Obj_t *pFan1)
Definition: amapGraph.c:137
#define assert(ex)
Definition: util_old.h:213
static Amap_Obj_t * Amap_Not(Amap_Obj_t *p)
Definition: amapInt.h:222
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
int fUseXor
Definition: amapInt.h:83
void Aig_ManCleanData(Aig_Man_t *p)
Definition: aigUtil.c:205
static int Aig_ObjIsChoice(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: aig.h:283
int nChoicesGiven
Definition: amapInt.h:96
int nLevelMax
Definition: amapInt.h:95
Vec_Ptr_t * vPos
Definition: amapInt.h:87
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223