VIS

src/spfd/spfdReg.c

Go to the documentation of this file.
00001 
00021 #include "spfdInt.h"
00022 
00023 /*---------------------------------------------------------------------------*/
00024 /* Constant declarations                                                     */
00025 /*---------------------------------------------------------------------------*/
00026 
00027 /*---------------------------------------------------------------------------*/
00028 /* Type declarations                                                         */
00029 /*---------------------------------------------------------------------------*/
00030 
00031 
00032 /*---------------------------------------------------------------------------*/
00033 /* Structure declarations                                                    */
00034 /*---------------------------------------------------------------------------*/
00035 
00036 
00037 /*---------------------------------------------------------------------------*/
00038 /* Variable declarations                                                     */
00039 /*---------------------------------------------------------------------------*/
00040 
00041 
00042 /*---------------------------------------------------------------------------*/
00043 /* Macro declarations                                                        */
00044 /*---------------------------------------------------------------------------*/
00045 
00046 
00049 /*---------------------------------------------------------------------------*/
00050 /* Static function prototypes                                                */
00051 /*---------------------------------------------------------------------------*/
00052 
00053 
00057 /*---------------------------------------------------------------------------*/
00058 /* Definition of exported functions                                          */
00059 /*---------------------------------------------------------------------------*/
00060 
00061 
00062 /*---------------------------------------------------------------------------*/
00063 /* Definition of internal functions                                          */
00064 /*---------------------------------------------------------------------------*/
00073 array_t *
00074 SpfdNodeComputeFanoutRegion(
00075   SpfdApplData_t *applData,
00076   Ntk_Node_t *startNode,
00077   int regionDepth)
00078 {
00079   Ntk_Node_t *fanout,*ntkNode;
00080   st_table *reached;
00081   st_generator *stGen;
00082   array_t *regionArray,*from,*new_;
00083   int bound,i,j,k;
00084 
00085   reached = st_init_table(st_ptrcmp,st_ptrhash);
00086   if (Ntk_NodeTestIsPrimaryOutput(startNode)) {
00087     st_insert(reached,(char *)startNode,(char *)1);
00088   } else {
00089     /* Sort the fanout array of startNode according to depth */
00090     from = array_dup(Ntk_NodeReadFanouts(startNode));
00091     array_sort(from,SpfdDepthCompare);
00092     /* Put fanoutArray into reached */
00093     arrayForEachItem(Ntk_Node_t *,from,i,fanout) {
00094       if (!Ntk_NodeTestIsPrimaryOutput(fanout)) {
00095         bound = 0;
00096       } else {
00097         bound = 1;
00098       }
00099       st_insert(reached,(char *)fanout,(char *)(long)bound);
00100     }
00101 
00102     /* Proceed for depth regionDepth */
00103     for (i = 0; i < regionDepth; i++) {
00104       new_ = array_alloc(Ntk_Node_t *,0);
00105       arrayForEachItem(Ntk_Node_t *,from,j,ntkNode) {
00106         st_lookup(reached,(char *)ntkNode,&bound);
00107         if (!bound) {
00108           Ntk_NodeForEachFanout(ntkNode,k,fanout) {
00109             if (!st_lookup(reached,(char *)fanout,&bound)) {
00110               if (Ntk_NodeTestIsPrimaryOutput(fanout) ||
00111                   Ntk_NodeReadNumFanouts(fanout) < 1 || /* Just to be safe */
00112                   i == regionDepth - 1) {
00113                 bound = 1;
00114               } else {
00115                 bound = 0;
00116               }
00117               st_insert(reached,(char *)fanout,(char *)(long)bound);
00118               array_insert_last(Ntk_Node_t *,new_,fanout);
00119             }
00120           }
00121         }
00122       }
00123       array_free(from);
00124       from = new_;
00125       array_sort(from,SpfdDepthCompare);
00126     }
00127     array_free(from);
00128   
00129     /* Finally make the startNode an internal node */
00130     st_insert(reached,(char *)startNode,(char *)0);
00131   }  
00132 
00133   /* Put the nodes in reached according to their depth */
00134   regionArray = array_alloc(Ntk_Node_t *,0);
00135   st_foreach_item_int(reached,stGen,&fanout,&bound) {
00136     array_insert_last(Ntk_Node_t *,regionArray,fanout);
00137   }
00138   array_sort(regionArray,SpfdDepthCompare);
00139 
00140   if (applData->currRegionNodes) {
00141     (void) fprintf(vis_stdout,
00142                    "** spfd warning: Possible memory leak.\n");
00143   }
00144   applData->currRegionNodes = reached;
00145   
00146   return regionArray;
00147   
00148 } /* End of SpfdNodeComputeFanoutRegion */
00149 
00150 
00159 array_t *
00160 SpfdNodeComputeTFIUntilDepth(
00161   Ntk_Node_t *startNode,
00162   int regionDepth)
00163 {
00164   Ntk_Node_t *fanin,*ntkNode;
00165   st_table *reached,*faninTable;
00166   st_generator *stGen;
00167   array_t *regionArray,*from,*new_;
00168   char *dummy;
00169   int i,j,k;
00170 
00171   /* Make sure that startNode is not a PI to start with. */
00172 
00173   if (Ntk_NodeTestIsPrimaryInput(startNode))
00174     return NIL(array_t);
00175 
00176   reached = st_init_table(st_ptrcmp,st_ptrhash);
00177   faninTable = st_init_table(st_ptrcmp,st_ptrhash);
00178   
00179   /* Put the fanin array of startNode in faninTable */
00180   from = array_dup(Ntk_NodeReadFanins(startNode));
00181   arrayForEachItem(Ntk_Node_t *,from,i,ntkNode) {
00182     st_insert(faninTable,(char *)ntkNode,(char *)1);
00183   }
00184 
00185   /* Proceed for depth regionDepth */
00186   for (i = 0; i < regionDepth; i++) {
00187     new_ = array_alloc(Ntk_Node_t *,0);
00188     arrayForEachItem(Ntk_Node_t *,from,j,ntkNode) {
00189       Ntk_NodeForEachFanin(ntkNode,k,fanin) {
00190         if (!st_lookup(reached,(char *)fanin,&dummy) &&
00191             !st_lookup(faninTable,(char *)fanin,&dummy)) {
00192           st_insert(reached,(char *)fanin,(char *)1);
00193           array_insert_last(Ntk_Node_t *,new_,fanin);
00194         }
00195       }
00196     }
00197     array_free(from);
00198     from = new_;
00199   }
00200   array_free(from);
00201   st_free_table(faninTable);
00202   
00203   /* Put the nodes in reached according to their depth */
00204   regionArray = array_alloc(Ntk_Node_t *,0);
00205   st_foreach_item(reached,stGen,&ntkNode,&dummy) {
00206     array_insert_last(Ntk_Node_t *,regionArray,ntkNode);
00207   }
00208   array_sort(regionArray,SpfdDepthCompare);
00209 
00210   st_free_table(reached);
00211   return regionArray;
00212   
00213 } /* End of SpfdNodeComputeTFIUntilDepth */
00214 
00215 
00224 void
00225 SpfdNodesInTFO(
00226   Ntk_Network_t *network,
00227   Ntk_Node_t *node,
00228   st_table *tfoNodes)
00229 {
00230   int i;
00231   Ntk_Node_t *fanout;
00232   
00233   st_insert(tfoNodes,(char *)node,(char *)0);
00234   Ntk_NodeForEachFanout(node,i,fanout) {
00235     SpfdNodesInTFO(network,fanout,tfoNodes);
00236   }
00237 
00238   return;
00239 } /* End of SpfdNodesInTFO */
00240 
00241 
00242 /*---------------------------------------------------------------------------*/
00243 /* Definition of static functions                                            */
00244 /*---------------------------------------------------------------------------*/