abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mapperRefs.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [mapperRefs.c]
4 
5  PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]
6 
7  Synopsis [Generic technology mapping engine.]
8 
9  Author [MVSIS Group]
10 
11  Affiliation [UC Berkeley]
12 
13  Date [Ver. 2.0. Started - June 1, 2004.]
14 
15  Revision [$Id: mapperRefs.h,v 1.0 2003/09/08 00:00:00 alanmi Exp $]
16 
17 ***********************************************************************/
18 
19 #include "mapperInt.h"
20 
22 
23 
24 ////////////////////////////////////////////////////////////////////////
25 /// DECLARATIONS ///
26 ////////////////////////////////////////////////////////////////////////
27 
28 ////////////////////////////////////////////////////////////////////////
29 /// FUNCTION DEFINITIONS ///
30 ////////////////////////////////////////////////////////////////////////
31 
32 /**Function*************************************************************
33 
34  Synopsis [Reads the actual reference counter of a phase.]
35 
36  Description []
37 
38  SideEffects []
39 
40  SeeAlso []
41 
42 ***********************************************************************/
43 int Map_NodeReadRefPhaseAct( Map_Node_t * pNode, int fPhase )
44 {
45  assert( !Map_IsComplement(pNode) );
46  if ( pNode->pCutBest[0] && pNode->pCutBest[1] ) // both assigned
47  return pNode->nRefAct[fPhase];
48  assert( pNode->pCutBest[0] || pNode->pCutBest[1] ); // at least one assigned
49  return pNode->nRefAct[2];
50 }
51 
52 /**Function*************************************************************
53 
54  Synopsis [Reads the estimated reference counter of a phase.]
55 
56  Description []
57 
58  SideEffects []
59 
60  SeeAlso []
61 
62 ***********************************************************************/
63 float Map_NodeReadRefPhaseEst( Map_Node_t * pNode, int fPhase )
64 {
65  assert( !Map_IsComplement(pNode) );
66  if ( pNode->pCutBest[0] && pNode->pCutBest[1] ) // both assigned
67  return pNode->nRefEst[fPhase];
68  assert( pNode->pCutBest[0] || pNode->pCutBest[1] ); // at least one assigned
69 // return pNode->nRefEst[0] + pNode->nRefEst[1];
70  return pNode->nRefEst[2];
71 }
72 
73 
74 /**Function*************************************************************
75 
76  Synopsis [Increments the actual reference counter of a phase.]
77 
78  Description [Returns the old reference counter.]
79 
80  SideEffects []
81 
82  SeeAlso []
83 
84 ***********************************************************************/
85 int Map_NodeIncRefPhaseAct( Map_Node_t * pNode, int fPhase )
86 {
87  assert( !Map_IsComplement(pNode) );
88  if ( pNode->pCutBest[0] && pNode->pCutBest[1] ) // both assigned
89  return pNode->nRefAct[fPhase]++;
90  assert( pNode->pCutBest[0] || pNode->pCutBest[1] ); // at least one assigned
91  return pNode->nRefAct[2]++;
92 }
93 
94 /**Function*************************************************************
95 
96  Synopsis [Decrements the actual reference counter of a phase.]
97 
98  Description [Returns the new reference counter.]
99 
100  SideEffects []
101 
102  SeeAlso []
103 
104 ***********************************************************************/
105 int Map_NodeDecRefPhaseAct( Map_Node_t * pNode, int fPhase )
106 {
107  assert( !Map_IsComplement(pNode) );
108  if ( pNode->pCutBest[0] && pNode->pCutBest[1] ) // both assigned
109  return --pNode->nRefAct[fPhase];
110  assert( pNode->pCutBest[0] || pNode->pCutBest[1] ); // at least one assigned
111  return --pNode->nRefAct[2];
112 }
113 
114 
115 /**Function*************************************************************
116 
117  Synopsis [Sets the estimated reference counter for the PIs.]
118 
119  Description []
120 
121  SideEffects []
122 
123  SeeAlso []
124 
125 ***********************************************************************/
127 {
128  Map_Node_t * pNode;
129  int i;
130  for ( i = 0; i < p->vMapObjs->nSize; i++ )
131  {
132  pNode = p->vMapObjs->pArray[i];
133 // pNode->nRefEst[0] = pNode->nRefEst[1] = ((float)pNode->nRefs)*(float)2.0;
134  pNode->nRefEst[0] = pNode->nRefEst[1] = pNode->nRefEst[2] = ((float)pNode->nRefs);
135  }
136 }
137 
138 /**Function*************************************************************
139 
140  Synopsis [Sets the estimated reference counter.]
141 
142  Description [When this procedure is called for the first time,
143  the reference counter is estimated from the AIG. Otherwise, it is
144  a linear combination of reference counters in the last two iterations.]
145 
146  SideEffects []
147 
148  SeeAlso []
149 
150 ***********************************************************************/
152 {
153  Map_Node_t * pNode;
154  int i;
155  for ( i = 0; i < p->vMapObjs->nSize; i++ )
156  {
157  pNode = p->vMapObjs->pArray[i];
158 // pNode->nRefEst[0] = (float)((2.0 * pNode->nRefEst[0] + 1.0 * pNode->nRefAct[0]) / 3.0);
159 // pNode->nRefEst[1] = (float)((2.0 * pNode->nRefEst[1] + 1.0 * pNode->nRefAct[1]) / 3.0);
160 // pNode->nRefEst[2] = (float)((2.0 * pNode->nRefEst[2] + 1.0 * pNode->nRefAct[2]) / 3.0);
161  pNode->nRefEst[0] = (float)((3.0 * pNode->nRefEst[0] + 1.0 * pNode->nRefAct[0]) / 4.0);
162  pNode->nRefEst[1] = (float)((3.0 * pNode->nRefEst[1] + 1.0 * pNode->nRefAct[1]) / 4.0);
163  pNode->nRefEst[2] = (float)((3.0 * pNode->nRefEst[2] + 1.0 * pNode->nRefAct[2]) / 4.0);
164  }
165 }
166 
167 /**function*************************************************************
168 
169  synopsis [Computes the area flow of the cut.]
170 
171  description [Computes the area flow of the cut if it is implemented using
172  the best supergate with the best phase.]
173 
174  sideeffects []
175 
176  seealso []
177 
178 ***********************************************************************/
179 float Map_CutGetAreaFlow( Map_Cut_t * pCut, int fPhase )
180 {
181  Map_Match_t * pM = pCut->M + fPhase;
182  Map_Super_t * pSuper = pM->pSuperBest;
183  unsigned uPhaseTot = pM->uPhaseBest;
184  Map_Cut_t * pCutFanin;
185  float aFlowRes, aFlowFanin, nRefs;
186  int i, fPinPhasePos;
187 
188  // start the resulting area flow
189  aFlowRes = pSuper->Area;
190  // iterate through the leaves
191  for ( i = 0; i < pCut->nLeaves; i++ )
192  {
193  // get the phase of this fanin
194  fPinPhasePos = ((uPhaseTot & (1 << i)) == 0);
195  // get the cut implementing this phase of the fanin
196  pCutFanin = pCut->ppLeaves[i]->pCutBest[fPinPhasePos];
197  // if the cut is not available, we have to use the opposite phase
198  if ( pCutFanin == NULL )
199  {
200  fPinPhasePos = !fPinPhasePos;
201  pCutFanin = pCut->ppLeaves[i]->pCutBest[fPinPhasePos];
202  }
203  aFlowFanin = pCutFanin->M[fPinPhasePos].AreaFlow; // ignores the area of the interter
204  // get the fanout count of the cut in the given phase
205  nRefs = Map_NodeReadRefPhaseEst( pCut->ppLeaves[i], fPinPhasePos );
206  // if the node does no fanout, assume fanout count equal to 1
207  if ( nRefs == (float)0.0 )
208  nRefs = (float)1.0;
209  // add the area flow due to the fanin
210  aFlowRes += aFlowFanin / nRefs;
211  }
212  pM->AreaFlow = aFlowRes;
213  return aFlowRes;
214 }
215 
216 
217 /**function*************************************************************
218 
219  synopsis [References or dereferences the cut.]
220 
221  description [This reference part is similar to Cudd_NodeReclaim().
222  The dereference part is similar to Cudd_RecursiveDeref().]
223 
224  sideeffects []
225 
226  seealso []
227 
228 ***********************************************************************/
229 float Map_CutRefDeref( Map_Cut_t * pCut, int fPhase, int fReference )
230 {
231  Map_Node_t * pNodeChild;
232  Map_Cut_t * pCutChild;
233  float aArea;
234  int i, fPhaseChild;
235 // int nRefs;
236 
237  // consider the elementary variable
238  if ( pCut->nLeaves == 1 )
239  return 0;
240  // start the area of this cut
241  aArea = Map_CutGetRootArea( pCut, fPhase );
242  // go through the children
243  for ( i = 0; i < pCut->nLeaves; i++ )
244  {
245  pNodeChild = pCut->ppLeaves[i];
246  fPhaseChild = Map_CutGetLeafPhase( pCut, fPhase, i );
247  // get the reference counter of the child
248 /*
249  // this code does not take inverters into account
250  // the quality of area recovery seems to always be a little worse
251  if ( fReference )
252  nRefs = Map_NodeIncRefPhaseAct( pNodeChild, fPhaseChild );
253  else
254  nRefs = Map_NodeDecRefPhaseAct( pNodeChild, fPhaseChild );
255  assert( nRefs >= 0 );
256  // skip if the child was already reference before
257  if ( nRefs > 0 )
258  continue;
259 */
260 
261  if ( fReference )
262  {
263  if ( pNodeChild->pCutBest[0] && pNodeChild->pCutBest[1] ) // both phases are present
264  {
265  // if this phase of the node is referenced, there is no recursive call
266  pNodeChild->nRefAct[2]++;
267  if ( pNodeChild->nRefAct[fPhaseChild]++ > 0 )
268  continue;
269  }
270  else // only one phase is present
271  {
272  // inverter should be added if the phase
273  // (a) has no reference and (b) is implemented using other phase
274  if ( pNodeChild->nRefAct[fPhaseChild]++ == 0 && pNodeChild->pCutBest[fPhaseChild] == NULL )
275  aArea += pNodeChild->p->pSuperLib->AreaInv;
276  // if the node is referenced, there is no recursive call
277  if ( pNodeChild->nRefAct[2]++ > 0 )
278  continue;
279  }
280  }
281  else
282  {
283  if ( pNodeChild->pCutBest[0] && pNodeChild->pCutBest[1] ) // both phases are present
284  {
285  // if this phase of the node is referenced, there is no recursive call
286  --pNodeChild->nRefAct[2];
287  if ( --pNodeChild->nRefAct[fPhaseChild] > 0 )
288  continue;
289  }
290  else // only one phase is present
291  {
292  // inverter should be added if the phase
293  // (a) has no reference and (b) is implemented using other phase
294  if ( --pNodeChild->nRefAct[fPhaseChild] == 0 && pNodeChild->pCutBest[fPhaseChild] == NULL )
295  aArea += pNodeChild->p->pSuperLib->AreaInv;
296  // if the node is referenced, there is no recursive call
297  if ( --pNodeChild->nRefAct[2] > 0 )
298  continue;
299  }
300  assert( pNodeChild->nRefAct[fPhaseChild] >= 0 );
301  }
302 
303  // get the child cut
304  pCutChild = pNodeChild->pCutBest[fPhaseChild];
305  // if the child does not have this phase mapped, take the opposite phase
306  if ( pCutChild == NULL )
307  {
308  fPhaseChild = !fPhaseChild;
309  pCutChild = pNodeChild->pCutBest[fPhaseChild];
310  }
311  // reference and compute area recursively
312  aArea += Map_CutRefDeref( pCutChild, fPhaseChild, fReference );
313  }
314  return aArea;
315 }
316 
317 /**function*************************************************************
318 
319  synopsis [Computes the exact area associated with the cut.]
320 
321  description [Assumes that the cut is referenced.]
322 
323  sideeffects []
324 
325  seealso []
326 
327 ***********************************************************************/
328 float Map_CutGetAreaRefed( Map_Cut_t * pCut, int fPhase )
329 {
330  float aResult, aResult2;
331  aResult2 = Map_CutRefDeref( pCut, fPhase, 0 ); // dereference
332  aResult = Map_CutRefDeref( pCut, fPhase, 1 ); // reference
333 // assert( aResult == aResult2 );
334  return aResult;
335 }
336 
337 /**function*************************************************************
338 
339  synopsis [Computes the exact area associated with the cut.]
340 
341  description []
342 
343  sideeffects []
344 
345  seealso []
346 
347 ***********************************************************************/
348 float Map_CutGetAreaDerefed( Map_Cut_t * pCut, int fPhase )
349 {
350  float aResult, aResult2;
351  aResult2 = Map_CutRefDeref( pCut, fPhase, 1 ); // reference
352  aResult = Map_CutRefDeref( pCut, fPhase, 0 ); // dereference
353 // assert( aResult == aResult2 );
354  return aResult;
355 }
356 
357 /**function*************************************************************
358 
359  synopsis [References the cut.]
360 
361  description []
362 
363  sideeffects []
364 
365  seealso []
366 
367 ***********************************************************************/
368 float Map_CutRef( Map_Cut_t * pCut, int fPhase )
369 {
370  return Map_CutRefDeref( pCut, fPhase, 1 ); // reference
371 }
372 
373 /**function*************************************************************
374 
375  synopsis [Dereferences the cut.]
376 
377  description []
378 
379  sideeffects []
380 
381  seealso []
382 
383 ***********************************************************************/
384 float Map_CutDeref( Map_Cut_t * pCut, int fPhase )
385 {
386  return Map_CutRefDeref( pCut, fPhase, 0 ); // dereference
387 }
388 
389 
390 /**Function*************************************************************
391 
392  Synopsis [Computes actual reference counters.]
393 
394  Description [Collects the nodes used in the mapping in array pMan->vMapping.
395  Nodes are collected in reverse topological order to facilitate the
396  computation of required times.]
397 
398  SideEffects []
399 
400  SeeAlso []
401 
402 ***********************************************************************/
404 {
405  Map_Cut_t * pCut;
406  Map_Node_t * pNodeR;
407  unsigned uPhase;
408  int i, fPhase, fInvPin;
409  // get the regular node and its phase
410  pNodeR = Map_Regular(pNode);
411  fPhase = !Map_IsComplement(pNode);
412  pNodeR->nRefAct[2]++;
413  // quit if the node was already visited in this phase
414  if ( pNodeR->nRefAct[fPhase]++ )
415  return;
416  // quit if this is a PI node
417  if ( Map_NodeIsVar(pNodeR) )
418  return;
419  // propagate through buffer
420  if ( Map_NodeIsBuf(pNodeR) )
421  {
422  Map_MappingSetRefs_rec( pMan, Map_NotCond(pNodeR->p1, Map_IsComplement(pNode)) );
423  return;
424  }
425  assert( Map_NodeIsAnd(pNode) );
426  // get the cut implementing this or opposite polarity
427  pCut = pNodeR->pCutBest[fPhase];
428  if ( pCut == NULL )
429  {
430  fPhase = !fPhase;
431  pCut = pNodeR->pCutBest[fPhase];
432  }
433  // visit the transitive fanin
434  uPhase = pCut->M[fPhase].uPhaseBest;
435  for ( i = 0; i < pCut->nLeaves; i++ )
436  {
437  fInvPin = ((uPhase & (1 << i)) > 0);
438  Map_MappingSetRefs_rec( pMan, Map_NotCond(pCut->ppLeaves[i], fInvPin) );
439  }
440 }
442 {
443  Map_Node_t * pNode;
444  int i;
445  // clean all references
446  for ( i = 0; i < pMan->vMapObjs->nSize; i++ )
447  {
448  pNode = pMan->vMapObjs->pArray[i];
449  pNode->nRefAct[0] = 0;
450  pNode->nRefAct[1] = 0;
451  pNode->nRefAct[2] = 0;
452  }
453  // visit nodes reachable from POs in the DFS order through the best cuts
454  for ( i = 0; i < pMan->nOutputs; i++ )
455  {
456  pNode = pMan->pOutputs[i];
457  if ( !Map_NodeIsConst(pNode) )
458  Map_MappingSetRefs_rec( pMan, pNode );
459  }
460 }
461 
462 
463 /**Function*************************************************************
464 
465  Synopsis [Computes the array of mapping.]
466 
467  Description []
468 
469  SideEffects []
470 
471  SeeAlso []
472 
473 ***********************************************************************/
475 {
476  Map_Node_t * pNode;
477  float Area = 0.0;
478  int i;
479  for ( i = 0; i < pMan->vMapObjs->nSize; i++ )
480  {
481  pNode = pMan->vMapObjs->pArray[i];
482  if ( pNode->nRefAct[2] == 0 )
483  continue;
484  if ( Map_NodeIsBuf(pNode) )
485  continue;
486  // at least one phase has the best cut assigned
487  assert( pNode->pCutBest[0] != NULL || pNode->pCutBest[1] != NULL );
488  // at least one phase is used in the mapping
489  assert( pNode->nRefAct[0] > 0 || pNode->nRefAct[1] > 0 );
490  // compute the array due to the supergate
491  if ( Map_NodeIsAnd(pNode) )
492  {
493  // count area of the negative phase
494  if ( pNode->pCutBest[0] && (pNode->nRefAct[0] > 0 || pNode->pCutBest[1] == NULL) )
495  Area += pNode->pCutBest[0]->M[0].pSuperBest->Area;
496  // count area of the positive phase
497  if ( pNode->pCutBest[1] && (pNode->nRefAct[1] > 0 || pNode->pCutBest[0] == NULL) )
498  Area += pNode->pCutBest[1]->M[1].pSuperBest->Area;
499  }
500  // count area of the interver if we need to implement one phase with another phase
501  if ( (pNode->pCutBest[0] == NULL && pNode->nRefAct[0] > 0) ||
502  (pNode->pCutBest[1] == NULL && pNode->nRefAct[1] > 0) )
503  Area += pMan->pSuperLib->AreaInv;
504  }
505  // add buffers for each CO driven by a CI
506  for ( i = 0; i < pMan->nOutputs; i++ )
507  if ( Map_NodeIsVar(pMan->pOutputs[i]) && !Map_IsComplement(pMan->pOutputs[i]) )
508  Area += pMan->pSuperLib->AreaBuf;
509  return Area;
510 }
511 
512 
513 ////////////////////////////////////////////////////////////////////////
514 /// END OF FILE ///
515 ////////////////////////////////////////////////////////////////////////
516 
517 
519 
#define Map_NotCond(p, c)
Definition: mapper.h:70
ABC_NAMESPACE_IMPL_START int Map_NodeReadRefPhaseAct(Map_Node_t *pNode, int fPhase)
DECLARATIONS ///.
Definition: mapperRefs.c:43
Map_Man_t * p
Definition: mapperInt.h:204
int Map_NodeIsAnd(Map_Node_t *p)
Definition: mapperCreate.c:115
float Map_CutGetAreaDerefed(Map_Cut_t *pCut, int fPhase)
Definition: mapperRefs.c:348
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Map_Cut_t * pCutBest[2]
Definition: mapperInt.h:239
unsigned uPhaseBest
Definition: mapperInt.h:252
float Map_NodeReadRefPhaseEst(Map_Node_t *pNode, int fPhase)
Definition: mapperRefs.c:63
int Map_NodeIsBuf(Map_Node_t *p)
Definition: mapperCreate.c:114
int Map_NodeDecRefPhaseAct(Map_Node_t *pNode, int fPhase)
Definition: mapperRefs.c:105
float Map_CutGetRootArea(Map_Cut_t *pCut, int fPhase)
int Map_NodeIsConst(Map_Node_t *p)
Definition: mapperCreate.c:112
#define Map_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: mapper.h:67
Map_Super_t * pSuperBest
Definition: mapperInt.h:253
void Map_MappingEstimateRefs(Map_Man_t *p)
Definition: mapperRefs.c:151
float Map_MappingGetArea(Map_Man_t *pMan)
Definition: mapperRefs.c:474
void Map_MappingEstimateRefsInit(Map_Man_t *p)
Definition: mapperRefs.c:126
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
float Map_CutRef(Map_Cut_t *pCut, int fPhase)
Definition: mapperRefs.c:368
int Map_NodeIsVar(Map_Node_t *p)
Definition: mapperCreate.c:113
void Map_MappingSetRefs(Map_Man_t *pMan)
Definition: mapperRefs.c:441
void Map_MappingSetRefs_rec(Map_Man_t *pMan, Map_Node_t *pNode)
Definition: mapperRefs.c:403
Map_Node_t * p1
Definition: mapperInt.h:221
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
float nRefEst[3]
Definition: mapperInt.h:217
#define Map_Regular(p)
Definition: mapper.h:68
typedefABC_NAMESPACE_HEADER_START struct Map_ManStruct_t_ Map_Man_t
INCLUDES ///.
Definition: mapper.h:40
int Map_CutGetLeafPhase(Map_Cut_t *pCut, int fPhase, int iLeaf)
float Map_CutDeref(Map_Cut_t *pCut, int fPhase)
Definition: mapperRefs.c:384
float Map_CutGetAreaRefed(Map_Cut_t *pCut, int fPhase)
Definition: mapperRefs.c:328
#define assert(ex)
Definition: util_old.h:213
float Map_CutRefDeref(Map_Cut_t *pCut, int fPhase, int fReference)
Definition: mapperRefs.c:229
int Map_NodeIncRefPhaseAct(Map_Node_t *pNode, int fPhase)
Definition: mapperRefs.c:85
Map_Match_t M[2]
Definition: mapperInt.h:271
Map_Node_t * ppLeaves[6]
Definition: mapperInt.h:265
float Map_CutGetAreaFlow(Map_Cut_t *pCut, int fPhase)
Definition: mapperRefs.c:179