VIS

src/part/partTotal.c

Go to the documentation of this file.
00001 
00024 #include "partInt.h"
00025 
00026 static char rcsid[] UNUSED = "$Id: partTotal.c,v 1.5 2005/04/16 06:14:54 fabio Exp $";
00027 
00028 /*---------------------------------------------------------------------------*/
00029 /* Constant declarations                                                     */
00030 /*---------------------------------------------------------------------------*/
00031 
00032 
00033 /*---------------------------------------------------------------------------*/
00034 /* Structure declarations                                                    */
00035 /*---------------------------------------------------------------------------*/
00036 
00037 
00038 /*---------------------------------------------------------------------------*/
00039 /* Type declarations                                                         */
00040 /*---------------------------------------------------------------------------*/
00041 
00042 
00043 /*---------------------------------------------------------------------------*/
00044 /* Variable declarations                                                     */
00045 /*---------------------------------------------------------------------------*/
00046 
00047 
00048 /*---------------------------------------------------------------------------*/
00049 /* Macro declarations                                                        */
00050 /*---------------------------------------------------------------------------*/
00051 
00052 
00055 /*---------------------------------------------------------------------------*/
00056 /* Static function prototypes                                                */
00057 /*---------------------------------------------------------------------------*/
00058 
00059 
00063 /*---------------------------------------------------------------------------*/
00064 /* Definition of exported functions                                          */
00065 /*---------------------------------------------------------------------------*/
00066 
00067 
00068 /*---------------------------------------------------------------------------*/
00069 /* Definition of internal functions                                          */
00070 /*---------------------------------------------------------------------------*/
00071 
00095 void
00096 PartPartitionTotal(
00097   Ntk_Network_t *network,
00098   graph_t       *partition,
00099   lsList        rootList,
00100   lsList        leaveList,
00101   mdd_t         *careSet,
00102   int           inTermsOfLeaves)
00103 {
00104   Ntk_Node_t    *nodePtr;           /* Pointer to iterate over nodes */
00105   lsList        nodeList;           /* list of network nodes */
00106   lsGen         gen;                /* To iterate over lists */
00107   array_t       *setOfFunctions;
00108   array_t       *rootArray;
00109   st_table      *tableOfLeaves;
00110   vertex_t      *toVertex;
00111   int           i;
00112 
00113   /* Obtain the table of leaves of the partition */
00114   tableOfLeaves = st_init_table(st_ptrcmp, st_ptrhash);
00115   if (leaveList == (lsList)0) {
00116     Ntk_NetworkForEachCombInput(network, gen, nodePtr) {
00117       st_insert(tableOfLeaves, (char *)nodePtr, (char *) (long) (-1));
00118     }
00119   } /* End of then */ 
00120   else {
00121     lsForEachItem(leaveList, gen, nodePtr) {
00122       st_insert(tableOfLeaves, (char *) nodePtr, (char *) (long) (-1));
00123     }
00124   } /* End of if-then-else */
00125   
00126   /* Obtain the list of nodes to obtain the partition from */
00127   if (rootList == (lsList)0) {
00128     nodeList = Ntk_NetworkReadNodes(network);
00129   } /* End of then */ 
00130   else {
00131     array_t *temporaryRootArray;
00132     st_table *resultTable;
00133     st_generator *stgen;
00134 
00135     /* Translate the root list to an array */
00136     temporaryRootArray = array_alloc(Ntk_Node_t *, lsLength(rootList));
00137     i = 0;
00138     lsForEachItem(rootList, gen, nodePtr) {
00139       array_insert(Ntk_Node_t *, temporaryRootArray, i++, nodePtr);
00140     }
00141 
00142     /* Obtain the intermediate nodes */
00143     resultTable = Ntk_RegionFindNodes(temporaryRootArray, tableOfLeaves);
00144     nodeList = lsCreate();
00145     st_foreach_item(resultTable, stgen, (&nodePtr), NULL) {
00146       lsNewBegin(nodeList, (lsGeneric)nodePtr, NIL(lsHandle));
00147     }
00148 
00149     /* Clean up */
00150     st_free_table(resultTable);
00151     array_free(temporaryRootArray);
00152   } /* End of if-then-else */
00153 
00154   rootArray = array_alloc(Ntk_Node_t *, 0);
00155 
00156   /* Make sure every network node has an mdd Id assigned to it */
00157   lsForEachItem(nodeList, gen, nodePtr) {
00158 
00159     /* No need to assign mddIds to the shadow nodes */
00160     if (Ntk_NodeTestIsShadow(nodePtr)) {
00161       continue;
00162     } /* End of if */
00163 
00164     if (!inTermsOfLeaves || st_is_member(tableOfLeaves, (char *) nodePtr)) {
00165       if (Ntk_NodeReadMddId(nodePtr) == NTK_UNASSIGNED_MDD_ID) {
00166         Ord_NetworkAssignMddIdForNode(network, nodePtr);
00167       } /* End of if */
00168     } /* End of if */
00169   } /* End of lsForEachItem */
00170 
00171   /* 
00172    * If the result has to be in terms of the combinational inputs, the
00173    * mdd array for each vertex will be build all at once by
00174    * specifying all the nodes are roots and the combinational inputs
00175    * as leaves 
00176    */
00177   if (inTermsOfLeaves) {
00178     lsForEachItem(nodeList, gen, nodePtr) {
00179 
00180       /* Skip the shadow nodes */
00181       if (Ntk_NodeTestIsShadow(nodePtr)) {
00182         continue;
00183       }
00184 
00185       /* Insert the node as root */
00186       array_insert_last(Ntk_Node_t *, rootArray, nodePtr);
00187     } /* End of lsForEachItem */
00188     
00189     setOfFunctions = Ntm_NetworkBuildMvfs(network, rootArray, 
00190                                           tableOfLeaves, careSet);
00191   } /* End of then */ 
00192   else {
00193     /* Compute every mdd array attached to the vertex in terms of its fanin */
00194 
00195     array_t *parameterArray;
00196     st_table *tmptableOfLeaves = st_init_table(st_ptrcmp, st_ptrhash);
00197 
00198     setOfFunctions = array_alloc(Mvf_Function_t *, 0);
00199 
00200     /* 
00201      * This array will hold one node pointer as the parameter to build
00202      * the mdd array for a node. The array rootArray will be used to
00203      * create an array of node pointers. Therefore, at the end of this
00204      * if-then-else, setOfFunctions will hold the array of mdd arrays
00205      * and rootArray will hold the array with all the node pointers
00206      * whose mdd array was computed.
00207      */
00208     parameterArray = array_alloc(Ntk_Node_t *, 1);
00209 
00210     lsForEachItem(nodeList, gen, nodePtr) {
00211 
00212       /* Skip the shadow nodes */
00213       if (!Ntk_NodeTestIsShadow(nodePtr)) {
00214         Ntk_Node_t *faninPtr;       /* Pointer to fanin node of current node */
00215         array_t    *temporaryArray;
00216 
00217         /* Create the array of nodes */
00218         array_insert_last(Ntk_Node_t *, rootArray, nodePtr);
00219         
00220         /* This table is needed empty every beginning of iteration */
00221         st_free_table(tmptableOfLeaves);
00222         tmptableOfLeaves = st_init_table(st_ptrcmp, st_ptrhash);
00223       
00224         /* Prepare parameters to build the mdd array for the node */
00225         array_insert(Ntk_Node_t *, parameterArray, 0, nodePtr);
00226         Ntk_NodeForEachFanin(nodePtr, i, faninPtr) {
00227           st_insert(tmptableOfLeaves, (char *)faninPtr, (char *)(-1));
00228         }
00229 
00230         /* 
00231          * If the node is a combinational inputs, it has no fanins but the node
00232          * must appear in the table of leaves, otherwise the function
00233          * Ntm_NetworkBuildMdds aborts.  
00234          */
00235         if (st_is_member(tableOfLeaves, (char *) nodePtr)) {
00236           st_insert(tmptableOfLeaves, (char *)nodePtr, (char *)(-1));
00237         } /* End of if */
00238         
00239         temporaryArray = Ntm_NetworkBuildMvfs(network, parameterArray, 
00240                                               tmptableOfLeaves, careSet);
00241         array_insert_last(Mvf_Function_t *, setOfFunctions, 
00242                           array_fetch(Mvf_Function_t *, temporaryArray, 0));
00243         
00244         array_free(temporaryArray);
00245       } /* End of if */
00246     } /* End of lsForEachItem */
00247     
00248     array_free(parameterArray);
00249     st_free_table(tmptableOfLeaves);
00250   } /* End of if-then-else */
00251 
00252   /* Partial Clean up */
00253   st_free_table(tableOfLeaves);
00254 
00255   assert(array_n(rootArray) == array_n(setOfFunctions));
00256   
00257   /* 
00258    * The computation now uses two steps, the first one creates all the
00259    * vertices of the partition and the second one all the edges of the
00260    * partition. 
00261    */
00262 
00263   /* Create vertices */
00264   arrayForEachItem(Ntk_Node_t *, rootArray, i, nodePtr) {
00265     Mvf_Function_t *mvf  = array_fetch(Mvf_Function_t *, setOfFunctions, i);
00266     char           *name = Ntk_NodeReadName(nodePtr);
00267     int            mddId = Ntk_NodeReadMddId(nodePtr);
00268 
00269     toVertex = g_add_vertex(partition);
00270 
00271     /* Update the look-up tables in the partition */
00272     st_insert(PartPartitionReadNameToVertex(partition),
00273               name, (char *)toVertex);
00274     st_insert(PartPartitionReadMddIdToVertex(partition),
00275               (char *)(long) mddId, (char *)toVertex);
00276 
00277     /* Create the information attached to the vertex */
00278     toVertex->user_data = (gGeneric)PartVertexInfoCreateSingle(name, 
00279                                                                mvf,
00280                                                                mddId);
00281   } /* End of arrayForEachItem */
00282 
00283   /* Create the edges */
00284   foreach_vertex(partition, gen, toVertex) {
00285     nodePtr = Ntk_NetworkFindNodeByActualName(network, PartVertexReadName(toVertex));
00286     if(!Ntk_NodeTestIsCombInput(nodePtr)) {
00287       PartPartitionCreateVertexFaninEdges(partition, toVertex);
00288     }
00289   } /* End of foreach_vertex */
00290 
00291   /* Clean up */
00292   array_free(rootArray);
00293   array_free(setOfFunctions);
00294   if (rootList != (lsList)0) {
00295     lsDestroy(nodeList, (void (*)(lsGeneric))0);
00296   }
00297 } /* End of PartPartitionTotal */
00298 
00299 /*---------------------------------------------------------------------------*/
00300 /* Definition of static functions                                            */
00301 /*---------------------------------------------------------------------------*/
00302