VIS

src/spfd/spfdClean.c

Go to the documentation of this file.
00001 
00021 #include "spfdInt.h"
00022 
00023 /*---------------------------------------------------------------------------*/
00024 /* Constant declarations                                                     */
00025 /*---------------------------------------------------------------------------*/
00026 
00027 
00028 /*---------------------------------------------------------------------------*/
00029 /* Type declarations                                                         */
00030 /*---------------------------------------------------------------------------*/
00031 
00032 
00033 /*---------------------------------------------------------------------------*/
00034 /* Structure declarations                                                    */
00035 /*---------------------------------------------------------------------------*/
00036 
00037 
00038 /*---------------------------------------------------------------------------*/
00039 /* Variable declarations                                                     */
00040 /*---------------------------------------------------------------------------*/
00041 
00042 extern int sfpdVerbose;
00043 extern float alpha;
00044 
00045 /*---------------------------------------------------------------------------*/
00046 /* Macro declarations                                                        */
00047 /*---------------------------------------------------------------------------*/
00048 
00049 
00052 /*---------------------------------------------------------------------------*/
00053 /* Static function prototypes                                                */
00054 /*---------------------------------------------------------------------------*/
00055 
00056 static enum st_retval NodeDataFree(char *key, char *value, char *arg);
00057 
00061 /*---------------------------------------------------------------------------*/
00062 /* Definition of exported functions                                          */
00063 /*---------------------------------------------------------------------------*/
00064 
00065 /*---------------------------------------------------------------------------*/
00066 /* Definition of internal functions                                          */
00067 /*---------------------------------------------------------------------------*/
00068 
00078 void
00079 SpfdApplFreeCallback(void *data)
00080 {
00081   SpfdApplData_t *applData = (SpfdApplData_t *)data;
00082   st_table *nodeToData = applData->nodeToData;
00083   bdd_manager *mgr = applData->ddManager;
00084   
00085   if (applData->currWireTable)
00086     st_free_table(applData->currWireTable);
00087   
00088   if (applData->currReplaceTable)
00089     st_free_table(applData->currReplaceTable);
00090   
00091   if (applData->wiresRemoved)
00092     st_free_table(applData->wiresRemoved);
00093 
00094   if (applData->nodesRemoved) {
00095     st_free_table(applData->nodesRemoved);
00096   }
00097   
00098   if (nodeToData) {
00099     st_foreach(nodeToData,NodeDataFree,(char *)mgr);
00100     st_free_table(nodeToData);
00101   }
00102 
00103   /* The data private to placeData is assumed to be deleted elsewhere */
00104   if (applData->placeData)
00105     FREE(applData->placeData);
00106 
00107   /* The rest of the fields are deleted once elsewhere. */
00108   
00109   FREE(applData);
00110   
00111   return;
00112 
00113 } /* End of SpfdApplFreeCallback */
00114 
00115 
00123 enum st_retval
00124 SpfdStBddFree(
00125   char *key,
00126   char *value,
00127   char *arg)
00128 {
00129   bdd_recursive_deref((bdd_manager *)arg,(bdd_node *)value);
00130   
00131   return (ST_CONTINUE);
00132 
00133 } /* End of SpfdStBddFree */
00134 
00135 
00145 enum st_retval
00146 SpfdStTableClean(
00147   char *key,
00148   char *value,
00149   char *arg)
00150 {
00151   st_free_table((st_table *)value);
00152 
00153   return (ST_DELETE);
00154 } /* End of SpfdStTableClean */
00155 
00156 
00170 void
00171 SpfdReleaseAndCleanNodeData(
00172   SpfdApplData_t *applData,
00173   Ntk_Node_t *regNode,
00174   st_table *nodeTable)
00175 {
00176   int k;
00177   Ntk_Node_t *fanin;
00178   st_table *inUseVars = applData->currInUseVars;
00179   st_table *regionNodes = applData->currRegionNodes;
00180   st_table *currBddReq = applData->currBddReq;
00181   bdd_manager *ddManager = applData->ddManager;
00182   char *dummy;
00183 
00184   Ntk_NodeForEachFanin(regNode,k,fanin) {
00185     int *count;
00186     if (st_lookup(nodeTable,(char *)fanin,&count)) {
00187       (*count)--;
00188       if (*count == 0) {
00189         int tempAuxId;
00190         int dummyInt;
00191         
00192         /* Free the auxId */
00193         tempAuxId = SpfdNodeReadAuxId(applData,fanin);
00194         if (st_delete(inUseVars,&tempAuxId,&dummy))
00195           SpfdNodeSetAuxId(applData,fanin,-1);
00196             
00197         if (st_lookup_int(regionNodes,(char *)fanin,&dummyInt)) {
00198           /* If it is an internal node also delete the alternative function */
00199           if (!dummyInt) 
00200             SpfdNodeDeleteGlobalAlternative(applData,fanin);
00201           /* If this is a region node delete the global Bdd */
00202           if(st_delete(currBddReq,&fanin,&dummy))
00203             bdd_recursive_deref(ddManager,(bdd_node *)dummy);
00204         } else {
00205           if(st_delete(currBddReq,&fanin,&dummy))
00206             bdd_recursive_deref(ddManager,(bdd_node *)dummy);
00207         }
00208         if (st_delete(nodeTable, &fanin, &count))
00209            FREE(count);
00210       } /* End of *count == 0 */
00211     } /* st_lookup  */
00212   } /* Ntk_NodeForEachFanin */
00213 
00214   return;
00215   
00216 } /* End of SpfdReleaseAndCleanNodeData */
00217 
00218 
00227 void
00228 SpfdReleaseAlternatePiIds(
00229   SpfdApplData_t *applData,
00230   Ntk_Node_t *regNode,
00231   st_table *nodeTable)
00232 {
00233   int k;
00234   Ntk_Node_t *fanin;
00235   st_table *inUseVars = applData->currInUseVars;
00236   st_table *piAltVars = applData->currPiAltVars;
00237         
00238   Ntk_NodeForEachFanin(regNode,k,fanin) {
00239     int *count;
00240     if (st_lookup(nodeTable,(char *)fanin,&count)) {
00241       /* Do not delete the count. It is done in the final clean up
00242          in SpfdReleaseAndCleanNodeDate. */
00243       if (*count == 1) {
00244         long tempId, tempAltId;
00245         tempId = Ntk_NodeReadMddId(fanin);
00246         if (st_lookup(piAltVars,(char *)(long)tempId,&tempAltId)) {
00247           st_delete(inUseVars,&tempAltId,NIL(char *));
00248           st_delete(piAltVars,&tempId,NIL(char *));
00249         }
00250       }
00251     }
00252   }
00253 
00254   return;
00255   
00256 } /* End of SpfdReleaseAlternatePiIds */
00257 
00258 
00266   void
00267 SpfdCleanUpAuxIds(SpfdApplData_t *applData)
00268 {
00269   st_table *regionNodes = applData->currRegionNodes;
00270   st_generator *stGen;
00271   char *dummy;
00272   Ntk_Node_t *regNode,*fanin;
00273   int i;
00274   
00275   /* Release the auxIds */
00276   st_foreach_item(regionNodes,stGen,&regNode,&dummy) {
00277     Ntk_NodeForEachFanin(regNode,i,fanin) {
00278       SpfdNodeSetAuxId(applData,fanin,-1);
00279     }
00280   }
00281 
00282   /* Free the table storing the currently used BDD IDs for PI
00283      auxillary variables. */
00284   st_free_table(applData->currPiAltVars);
00285   applData->currPiAltVars = NIL(st_table);
00286   
00287   return;
00288 } /* End of SpfdCleanUpAuxIds */
00289 
00290 
00291 /*---------------------------------------------------------------------------*/
00292 /* Definition of static functions                                            */
00293 /*---------------------------------------------------------------------------*/
00294 
00302 static enum st_retval
00303 NodeDataFree(
00304   char *key,
00305   char *value,
00306   char *arg)
00307 {
00308   SpfdNodeData_t *data;
00309   bdd_manager *ddManager = (bdd_manager *)arg;
00310 
00311   data = (SpfdNodeData_t *)value;
00312 
00313   if (data) {
00314     if (data->spfd)
00315       bdd_recursive_deref(ddManager,data->spfd);
00316     if (data->alternative)
00317       bdd_recursive_deref(ddManager,data->alternative);
00318     if (data->faninOrder)
00319       array_free(data->faninOrder);
00320     if (data->parameters)
00321       FREE(data->parameters);
00322     if (data->localAlt)
00323       bdd_recursive_deref(ddManager,data->localAlt);
00324     FREE(data);
00325   }
00326     
00327   return (ST_CONTINUE);
00328 
00329 } /* End of NodeDataFree */
00330