source: vis_dev/vis-2.3/src/spfd/spfdClean.c @ 74

Last change on this file since 74 was 14, checked in by cecile, 13 years ago

vis2.3

File size: 9.9 KB
Line 
1/**CFile***********************************************************************
2
3  FileName    [spfdClean.c]
4
5  PackageName [spfd]
6
7  Synopsis [Routines to free memory when not needed.]
8
9  Description [Routines to free memory when not needed.]
10
11  SeeAlso     [spfdAPI.c spfdUtil.c]
12
13  Author      [Balakrishna Kumthekar]
14
15  Copyright [This file was created at the University of Colorado at Boulder.
16  The University of Colorado at Boulder makes no warranty about the suitability
17  of this software for any purpose.  It is presented on an AS IS basis.]
18
19******************************************************************************/
20
21#include "spfdInt.h"
22
23/*---------------------------------------------------------------------------*/
24/* Constant declarations                                                     */
25/*---------------------------------------------------------------------------*/
26
27
28/*---------------------------------------------------------------------------*/
29/* Type declarations                                                         */
30/*---------------------------------------------------------------------------*/
31
32
33/*---------------------------------------------------------------------------*/
34/* Structure declarations                                                    */
35/*---------------------------------------------------------------------------*/
36
37
38/*---------------------------------------------------------------------------*/
39/* Variable declarations                                                     */
40/*---------------------------------------------------------------------------*/
41
42extern int sfpdVerbose;
43extern float alpha;
44
45/*---------------------------------------------------------------------------*/
46/* Macro declarations                                                        */
47/*---------------------------------------------------------------------------*/
48
49
50/**AutomaticStart*************************************************************/
51
52/*---------------------------------------------------------------------------*/
53/* Static function prototypes                                                */
54/*---------------------------------------------------------------------------*/
55
56static enum st_retval NodeDataFree(char *key, char *value, char *arg);
57
58/**AutomaticEnd***************************************************************/
59
60
61/*---------------------------------------------------------------------------*/
62/* Definition of exported functions                                          */
63/*---------------------------------------------------------------------------*/
64
65/*---------------------------------------------------------------------------*/
66/* Definition of internal functions                                          */
67/*---------------------------------------------------------------------------*/
68
69/**Function********************************************************************
70
71  Synopsis [Routine to free the application data structure attached by
72  this package to network. Certain fields of the SpfdApplData_t are
73  freed earlier.]
74
75  SideEffects [None]
76
77******************************************************************************/
78void
79SpfdApplFreeCallback(void *data)
80{
81  SpfdApplData_t *applData = (SpfdApplData_t *)data;
82  st_table *nodeToData = applData->nodeToData;
83  bdd_manager *mgr = applData->ddManager;
84 
85  if (applData->currWireTable)
86    st_free_table(applData->currWireTable);
87 
88  if (applData->currReplaceTable)
89    st_free_table(applData->currReplaceTable);
90 
91  if (applData->wiresRemoved)
92    st_free_table(applData->wiresRemoved);
93
94  if (applData->nodesRemoved) {
95    st_free_table(applData->nodesRemoved);
96  }
97 
98  if (nodeToData) {
99    st_foreach(nodeToData,NodeDataFree,(char *)mgr);
100    st_free_table(nodeToData);
101  }
102
103  /* The data private to placeData is assumed to be deleted elsewhere */
104  if (applData->placeData)
105    FREE(applData->placeData);
106
107  /* The rest of the fields are deleted once elsewhere. */
108 
109  FREE(applData);
110 
111  return;
112
113} /* End of SpfdApplFreeCallback */
114
115
116/**Function********************************************************************
117
118  Synopsis           [Free BDDs stored in a st_table.]
119
120  SideEffects        [None]
121
122******************************************************************************/
123enum st_retval
124SpfdStBddFree(
125  char *key,
126  char *value,
127  char *arg)
128{
129  bdd_recursive_deref((bdd_manager *)arg,(bdd_node *)value);
130 
131  return (ST_CONTINUE);
132
133} /* End of SpfdStBddFree */
134
135
136/**Function********************************************************************
137
138  Synopsis [This function frees the table stored as 'value' in an st_table and
139  returns ST_DELETE so that memory allocated for 'key' is also freed. In the
140  end the table is 'cleaned' but not 'freed.]
141
142  SideEffects        [None]
143
144******************************************************************************/
145enum st_retval
146SpfdStTableClean(
147  char *key,
148  char *value,
149  char *arg)
150{
151  st_free_table((st_table *)value);
152
153  return (ST_DELETE);
154} /* End of SpfdStTableClean */
155
156
157/**Function********************************************************************
158
159  Synopsis [Release those ids that will no longer be necessary, also
160  delete global and local BDDs. After an alternate implementation at
161  'regNode' is found, BDDs (local function, global function, BDD
162  variable ID and auxillary BDD ID) at its fanin may no longer be
163  necessary. nodeTable stores the pair <node,count>. 'count'
164  indicates how may times the BDDs at that node will be accessed. Such
165  BDDs are freed when appropriate, i.e., 'count' = 0.]
166
167  SideEffects [None]
168
169******************************************************************************/
170void
171SpfdReleaseAndCleanNodeData(
172  SpfdApplData_t *applData,
173  Ntk_Node_t *regNode,
174  st_table *nodeTable)
175{
176  int k;
177  Ntk_Node_t *fanin;
178  st_table *inUseVars = applData->currInUseVars;
179  st_table *regionNodes = applData->currRegionNodes;
180  st_table *currBddReq = applData->currBddReq;
181  bdd_manager *ddManager = applData->ddManager;
182  char *dummy;
183
184  Ntk_NodeForEachFanin(regNode,k,fanin) {
185    int *count;
186    if (st_lookup(nodeTable,(char *)fanin,&count)) {
187      (*count)--;
188      if (*count == 0) {
189        int tempAuxId;
190        int dummyInt;
191       
192        /* Free the auxId */
193        tempAuxId = SpfdNodeReadAuxId(applData,fanin);
194        if (st_delete(inUseVars,&tempAuxId,&dummy))
195          SpfdNodeSetAuxId(applData,fanin,-1);
196           
197        if (st_lookup_int(regionNodes,(char *)fanin,&dummyInt)) {
198          /* If it is an internal node also delete the alternative function */
199          if (!dummyInt) 
200            SpfdNodeDeleteGlobalAlternative(applData,fanin);
201          /* If this is a region node delete the global Bdd */
202          if(st_delete(currBddReq,&fanin,&dummy))
203            bdd_recursive_deref(ddManager,(bdd_node *)dummy);
204        } else {
205          if(st_delete(currBddReq,&fanin,&dummy))
206            bdd_recursive_deref(ddManager,(bdd_node *)dummy);
207        }
208        if (st_delete(nodeTable, &fanin, &count))
209           FREE(count);
210      } /* End of *count == 0 */
211    } /* st_lookup  */
212  } /* Ntk_NodeForEachFanin */
213
214  return;
215 
216} /* End of SpfdReleaseAndCleanNodeData */
217
218
219/**Function********************************************************************
220
221  Synopsis [Release those alternate PI ids that are no longer
222  necessary. This is necessary as we resuse the BDD variable IDs.]
223
224  SideEffects [None]
225
226******************************************************************************/
227void
228SpfdReleaseAlternatePiIds(
229  SpfdApplData_t *applData,
230  Ntk_Node_t *regNode,
231  st_table *nodeTable)
232{
233  int k;
234  Ntk_Node_t *fanin;
235  st_table *inUseVars = applData->currInUseVars;
236  st_table *piAltVars = applData->currPiAltVars;
237       
238  Ntk_NodeForEachFanin(regNode,k,fanin) {
239    int *count;
240    if (st_lookup(nodeTable,(char *)fanin,&count)) {
241      /* Do not delete the count. It is done in the final clean up
242         in SpfdReleaseAndCleanNodeDate. */
243      if (*count == 1) {
244        long tempId, tempAltId;
245        tempId = Ntk_NodeReadMddId(fanin);
246        if (st_lookup(piAltVars,(char *)(long)tempId,&tempAltId)) {
247          st_delete(inUseVars,&tempAltId,NIL(char *));
248          st_delete(piAltVars,&tempId,NIL(char *));
249        }
250      }
251    }
252  }
253
254  return;
255 
256} /* End of SpfdReleaseAlternatePiIds */
257
258
259/**Function********************************************************************
260
261  Synopsis    [Return auxillay BDD ids to the pool.]
262
263  SideEffects [None]
264
265******************************************************************************/
266  void
267SpfdCleanUpAuxIds(SpfdApplData_t *applData)
268{
269  st_table *regionNodes = applData->currRegionNodes;
270  st_generator *stGen;
271  char *dummy;
272  Ntk_Node_t *regNode,*fanin;
273  int i;
274 
275  /* Release the auxIds */
276  st_foreach_item(regionNodes,stGen,&regNode,&dummy) {
277    Ntk_NodeForEachFanin(regNode,i,fanin) {
278      SpfdNodeSetAuxId(applData,fanin,-1);
279    }
280  }
281
282  /* Free the table storing the currently used BDD IDs for PI
283     auxillary variables. */
284  st_free_table(applData->currPiAltVars);
285  applData->currPiAltVars = NIL(st_table);
286 
287  return;
288} /* End of SpfdCleanUpAuxIds */
289
290
291/*---------------------------------------------------------------------------*/
292/* Definition of static functions                                            */
293/*---------------------------------------------------------------------------*/
294
295/**Function********************************************************************
296
297  Synopsis           [Free SpfdNodeData_t]
298
299  SideEffects        [None]
300
301******************************************************************************/
302static enum st_retval
303NodeDataFree(
304  char *key,
305  char *value,
306  char *arg)
307{
308  SpfdNodeData_t *data;
309  bdd_manager *ddManager = (bdd_manager *)arg;
310
311  data = (SpfdNodeData_t *)value;
312
313  if (data) {
314    if (data->spfd)
315      bdd_recursive_deref(ddManager,data->spfd);
316    if (data->alternative)
317      bdd_recursive_deref(ddManager,data->alternative);
318    if (data->faninOrder)
319      array_free(data->faninOrder);
320    if (data->parameters)
321      FREE(data->parameters);
322    if (data->localAlt)
323      bdd_recursive_deref(ddManager,data->localAlt);
324    FREE(data);
325  }
326   
327  return (ST_CONTINUE);
328
329} /* End of NodeDataFree */
330
Note: See TracBrowser for help on using the repository browser.