source: vis_dev/vis-2.3/src/restr/restrCmd.c @ 93

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

vis2.3

File size: 30.6 KB
Line 
1/**CFile***********************************************************************
2
3  FileName    [restrCmd.c]
4
5  PackageName [restr]
6
7  Synopsis    [Command interface for the restr package.]
8
9  Author      [Balakrishna Kumthekar <kumtheka@colorado.edu>]
10
11  Copyright [This file was created at the University of Colorado at Boulder.
12  The University of Colorado at Boulder makes no warranty about the suitability
13  of this software for any purpose.  It is presented on an AS IS basis.]
14
15******************************************************************************/
16
17#include "restrInt.h"
18
19/*---------------------------------------------------------------------------*/
20/* Constant declarations                                                     */
21/*---------------------------------------------------------------------------*/
22
23
24/*---------------------------------------------------------------------------*/
25/* Type declarations                                                         */
26/*---------------------------------------------------------------------------*/
27
28
29/*---------------------------------------------------------------------------*/
30/* Structure declarations                                                    */
31/*---------------------------------------------------------------------------*/
32
33
34/*---------------------------------------------------------------------------*/
35/* Variable declarations                                                     */
36/*---------------------------------------------------------------------------*/
37
38static jmp_buf timeOutEnv;
39int restrCreatedPart;
40int restrCreatedFsm;
41boolean restrVerbose;
42
43/**AutomaticStart*************************************************************/
44
45/*---------------------------------------------------------------------------*/
46/* Static function prototypes                                                */
47/*---------------------------------------------------------------------------*/
48
49static int CommandRestructureFsm(Hrc_Manager_t **hmgr, int argc, char **argv);
50static void TimeOutHandle(void);
51static st_table * readInputProbabilities(Ntk_Network_t *network, FILE *fp);
52static void CleanUp(Ntk_Network_t *network1, st_table *inputProb, char *outOrderFileName, char *dumpFileName, char *prefix, int varOrdered, int restrCreatedPart, int restrCreatedFsm, char *probFile);
53static enum st_retval stCountFree(char *key, char *value, char *arg);
54static int IsPartitionValid(Ntk_Network_t *network, graph_t *partition);
55static int TestIsNetworkMultipleValued(Ntk_Network_t *network);
56
57/**AutomaticEnd***************************************************************/
58
59
60/*---------------------------------------------------------------------------*/
61/* Definition of exported functions                                          */
62/*---------------------------------------------------------------------------*/
63
64/**Function********************************************************************
65
66  Synopsis    [This function initializes the restr package.]
67
68  SideEffects [None]
69
70  SeeAlso     [Restr_End]
71
72******************************************************************************/
73void
74Restr_Init(void)
75{
76  Cmd_CommandAdd("restruct_fsm", CommandRestructureFsm, 0);
77}
78
79/**Function********************************************************************
80
81  Synopsis    [This function ends the restr package.]
82
83  SideEffects [None]
84
85  SeeAlso     [Restr_Init]
86
87******************************************************************************/
88void
89Restr_End(void)
90{
91
92} /* End of Restr_End */
93
94
95/*---------------------------------------------------------------------------*/
96/* Definition of internal functions                                          */
97/*---------------------------------------------------------------------------*/
98
99/*---------------------------------------------------------------------------*/
100/* Definition of static functions                                            */
101/*---------------------------------------------------------------------------*/
102
103
104/**Function********************************************************************
105
106  Synopsis [Implements the <tt>restruct_fsm</tt> command.]
107
108  Description [This command implements an State Transition Graph (STG)
109  restructuring algorithm that exploits the existence of equivalent
110  states to decrease power dissipation, not necessarily by collapsing
111  the equivalence states, but by redirecting transitions in the
112  graph. This algorithm is based on the monolithic transition relation. The
113  complexity of the algorithm in general increases with an increase in
114  the size of the state transition graph, which depends on the number
115  of state variables and primary inputs. For more details see, "A
116  Symbolic Algorithm for Low-Power Sequential Synthesis", ISLPED 97.]
117
118  SideEffects [None]
119
120  SeeAlso []
121
122  CommandName [restruct_fsm]
123
124  CommandSynopsis [Restructre the STG of a finite state machine to
125  reduce power dissipation.]
126
127  CommandArguments [\[-D &lt;fileHead&gt;\] \[-d &lt;divMethod&gt;\] \[-E\]
128  \[-F &lt;factMethod&gt;\] \[-f &lt;probFile&gt;\] \[-h\] \[-N\] \[-o
129  &lt;orderFile&gt;\] \[-p &lt;string&gt;\] \[-s &lt;restrMethod&gt;\] \[-t
130  &lt;seconds&gt;\] \[-v\]]
131
132  CommandDescription [This command implements an STG restructuring
133  algorithm that exploits the existence of equivalent states to
134  decrease power dissipation, not necessarily by collapsing the
135  equivalence states, but by redirecting transitions in the state
136  transition graph (STG). This algorithm is based on monolithic
137  transition relation. The complexity of the algorithm in general
138  increases with an increase in the size of the STG. The number of
139  states and edges in the STG are exponential in the number of state
140  variables and primary inputs. The memory utilization is not
141  necessarily exponential due to symbolic representation of the
142  STG. For more details see, "A Symbolic Algorithm for Low-Power
143  Sequential Synthesis", ISLPED 97.
144
145  This command works only if VIS is compiled with CUDD package. The
146  algorithm can handle circuits described in both BLIF and BLIF-MV
147  format. However, multi-valued variables are not supported. Also, the
148  final synthesized circuit (network implementation of the restructured
149  STG) is available only in BLIF format. The sequential circuit should
150  have a single initial state.
151
152  A network should have been created for the circuit and its primary
153  inputs and state variables assigned BDD ids prior to the invocation
154  of this command. A network can be created by the command
155  <tt>flatten_hierarchy</tt> and command <tt>static_order</tt> assigns
156  BDD ids to the input and state variables. The command proceeds by
157  creating BDDs for the outputs and next state functions. An FSM data
158  structure is then created on which subsequent operations are
159  performed. After the STG is restructured a new circuit is
160  synthesized by symbolic factorization based on Zero-Suppressed
161  Decision Diagrams (ZDDs). The final synthesized circuit is a file in
162  BLIF format with ".ml.blif" as the extension.
163
164  <p>
165  The typical command flow in vis is the following: <br><br>
166  <code>
167  vis> read_blif foo.blif <br>
168  vis> flatten_hierarchy <br>
169  vis> static_order <br>
170  vis> dynamic_var_ordering -e sift <br>
171  vis> restruct_fsm
172  </code>
173
174  <p>
175
176  In the above case example, the final synthesized circuit is
177  MODEL.ml.blif if the name of the design in foo.blif is MODEL.
178  <br><br>
179  <b> Command options: </b> <br>
180
181  <dl>
182
183  <dt> -A
184  <dd> Allow realignment (during symbolic factorization) of ZDDs
185  after BDD reordering and vice versa.  This option is effective
186  when only one of the BDD or ZDD variable reordering is enabled. <p>
187
188  <dt> -D &lt;fileHead&gt;
189  <dd> Specify the output file name for synthesized circuit. File extension
190  is not necessary. By default, the model name of the circuit is used. For
191  example, -D foobar, will result in foobar.ml.blif <p>
192
193  <dt> -d &lt;divMethod&gt;
194  <dd> Choose a divisor. See <tt>synthesize_network</tt> for more details.<p>
195
196  <dt> -E
197  <dd> Print the number of equivalence classes in the FSM. <p>
198
199  <dt> -F &lt;probFile&gt;
200  <dd> File with primary input probabilities, one per line.
201  <tt>input_name</tt> &lt;probability&gt; <p>
202
203  <dt> -f &lt;factMethod&gt;
204  <dd> Choose a method for factorization. See <tt>synthesize_network</tt> for
205  more details.<p>
206
207  <dt> -h
208  <dd> Print command usage. <p>
209
210  <dt> -i &lt;string&gt;
211  <dd> Specify the prefix to be used to generate names for internal
212  nodes during synthesis. By default, the prefix is "_n". <p>
213
214  <dt> -N
215  <dd> Expand the reachable set R to include those states which are equivalent
216  to R but not reachable. The default is not to include such states. <p>
217
218  <dt> -o &lt;orderFile&gt;
219  <dd> File to output BDD variable ordering after the restructured
220  circuit is synthesized. <p>
221
222  <dt> -R &lt;value&gt;
223  <dd> Allow reordering in BDD and/or ZDD variables during symbolic
224  factorization stage. <p>
225  0 : (default) No reordering neither in BDD nor in ZDD. <p>
226  1 : Allows reordering only in BDD, not in ZDD. <p>
227  2 : Allows reordering only in ZDD, not in BDD. <p>
228  3 : Allows reordering both in BDD and in ZDD. <p>
229
230  <dt> -s &lt;heuristic&gt;
231 
232  <dd> Heuristic to perform restructuring. Consider a fragment of an
233  STG containing states A,B and C and an edge from A to B. Let B and C
234  be equivalent. Since B and C are equivalent, it is possible to
235  change the transition between A and B to A and C. In the more
236  general case, the choice can be driven by different cost
237  constraints. The following are the heuristics: <br>
238
239  <dd> ham : Hamming distance based heuristic. An edge is chosen that reduces
240  the Hamming distance (or state bit transitions) between the states.<br>
241
242  <dd> fanin : Fanin oriented heuristic. A representative from the equivalence
243  class is chosen that reduces the total average state bit switching on the
244  incoming edges. <br>
245
246  <dd> faninout : Fanin-Fanout oriented heuristic. A representative from the
247  equivalence class is chosen that reduces the total average state bit
248  switching on the incoming as well as outgoing edges. <br>
249
250  <dd> cproj : A simple C-Projection. A representative from the
251  equivalence class is chosen which is closest to the initial
252  state. The distance d(x,y) is defined as:
253  <br><br>
254  \sum_{i=0}^{N-1}(|x_i - y_i| \cdot 2^{N-i-1}).<p>
255
256  <dt> -T
257  <dd> Try to share more nodes during symbolic factorization. Existing
258  divisors are checked for potential reuse before extracting divisors from the
259  current boolean function.<p>
260
261  <dt> -t &lt;seconds&gt;
262  <dd> Time in seconds allowed to complete the command. If the computation time
263  goes above that limit, the process is aborted.  The default is no limit.<p>
264
265  <dt> -v
266  <dd> Turn on verbosity. <p>
267
268  <dt> See also command : synthesize_network <p>
269
270  </dl>
271  ]
272
273  SideEffects [Package specific information is stored in the network and
274  cleared at the end.]
275
276  SeeAlso []
277
278******************************************************************************/
279static int
280CommandRestructureFsm(
281  Hrc_Manager_t **hmgr,
282  int argc,
283  char **argv)
284{
285  graph_t *partition = NIL(graph_t);
286  Fsm_Fsm_t *fsm = NIL(Fsm_Fsm_t);
287  Ntk_Network_t *network1 = NIL(Ntk_Network_t);
288  Hrc_Node_t *currentNode = NIL(Hrc_Node_t);
289  lsList dummy = (lsList) 0;
290  char *modelName,*str;
291  int timeOutPeriod;
292  boolean status;
293  int c;
294  long initialTime, finalTime;
295  RestructureHeuristic heuristic;
296  boolean equivClasses, nonReachEquiv;
297  boolean eqvMethod;
298  int varOrdered;
299  char *outOrderFileName,*blifName;
300  char *dumpFileName,*probFile;
301  int reorder,trySharing,realign;
302  FILE *fp;
303  st_table *inputProb = NULL;
304
305    /* Synthesis related options */
306  Synth_InfoData_t *synthInfo;
307  int factoring, divisor;
308  char *prefix;
309 
310  if (bdd_get_package_name() != CUDD) {
311    (void) fprintf(vis_stderr,
312                   "** restr error: The restr package can be used only with CUDD package\n");
313    (void) fprintf(vis_stderr,"** restr error: Please link with CUDD package\n");
314    return 0;
315  }
316       
317  /* These are the default values. */
318  timeOutPeriod   = 0; 
319  status          = FALSE;
320  restrVerbose    = 0;
321  equivClasses    = 0;
322  nonReachEquiv   = 0;
323  eqvMethod       = 0;
324  heuristic       = RestrHammingD_c;
325  fp              = NIL(FILE);
326  outOrderFileName = NIL(char);
327  dumpFileName = NIL(char);
328  probFile = NIL(char);
329  restrCreatedPart = 0;
330  restrCreatedFsm = 0;
331  varOrdered = 0;
332
333  /* Synthesis related default values */
334  factoring = 0;
335  divisor = 1;
336  prefix = NIL(char);
337  reorder = 0;
338  trySharing = 0;
339  realign = 0;
340
341  util_getopt_reset();
342
343  while((c = util_getopt(argc, argv, "f:d:i:EeNvD:o:t:s:F:R:TAh")) != EOF) {
344    switch(c) {
345    case 'f':
346      factoring = atoi(util_optarg);
347      break;
348    case 'd':
349      divisor = atoi(util_optarg);
350      break;
351    case 'i':
352      prefix = util_strsav(util_optarg);
353      break;
354    case 'E':
355      equivClasses = 1;
356      break;
357    case 'e':
358      eqvMethod = 1;
359      break;
360    case 'N':
361      nonReachEquiv = 1;
362      break;
363    case 'v':
364      restrVerbose = 1;
365      break;
366    case 'D':
367      dumpFileName = util_strsav(util_optarg);
368      break;
369    case 'o':
370      outOrderFileName = util_strsav(util_optarg);
371      /* Check if the file specified to dump variable order already exists */
372      fp = Cmd_FileOpen(outOrderFileName,"r",NIL(char *),1);
373      if (fp) {
374        (void) fprintf(vis_stderr,"** restr error: Output order file %s already exists.\n",
375                       outOrderFileName);
376        (void) fprintf(vis_stderr,"** restr error: Please specify another name.\n");
377        fclose(fp);
378        FREE(outOrderFileName);
379        goto endgame;
380      }
381      break;
382    case 't':
383      timeOutPeriod = atoi(util_optarg);
384      break;
385    case 's':
386      str = util_strsav(util_optarg);
387      if (strcmp(str,"ham") == 0) {
388        heuristic = RestrHammingD_c;
389      } else if (strcmp(str,"fanin") == 0) {
390        heuristic = RestrFanin_c;
391      } else if (strcmp(str,"faninout") == 0) {
392        heuristic = RestrFaninFanout_c;
393      } else if (strcmp(str,"cproj") == 0) {
394        heuristic = RestrCProjection_c;
395      } else {
396        (void) fprintf(vis_stderr,"** restr warning: Invalid option %s\n",str);
397        (void) fprintf(vis_stderr,"** restr warning: Using Hamming distance heuristic\n\n");
398        heuristic = RestrHammingD_c;
399      }
400      FREE(str);
401      break;
402    case 'F':
403      probFile = util_strsav(util_optarg);
404      fp = Cmd_FileOpen(probFile,"r",NIL(char *),1);
405      if (!fp) {
406        fprintf(vis_stderr,"** restr warning: Cannot open %s \n",probFile);
407        fprintf(vis_stderr,"** restr warning: Assuming equi probable primary inputs\n");
408        FREE(probFile);
409        probFile = NIL(char);
410      } else {
411        fclose(fp);
412      }
413      break;
414    case 'R':
415      /* Option to enable/disable reordering during synthesis
416         (factorization) stage */
417      reorder = atoi(util_optarg);
418      break;
419    case 'T':
420      /* During factorization maximize sharing of nodes */
421      trySharing = 1;
422      break;
423    case 'A':
424      /* Realign ZDD variables after BDD variable reordering and vice
425         versa */
426      realign = 1;
427      break;
428    case 'h':
429      goto usage;
430    default:
431      goto usage;
432    }
433  }
434
435  if(Hrc_ManagerReadCurrentNode(*hmgr) == NIL(Hrc_Node_t)) {
436    (void) fprintf(vis_stderr,"** restr error: The hierarchy manager is empty.");
437    (void) fprintf(vis_stderr," Read in design.\n");
438    goto endgame;
439  }
440
441  network1 = (Ntk_Network_t *) 
442    Hrc_NodeReadApplInfo(Hrc_ManagerReadCurrentNode(*hmgr), 
443                         NTK_HRC_NODE_APPL_KEY);
444
445  if(network1 == NIL(Ntk_Network_t)) {
446    (void) fprintf(vis_stderr,"** restr error: There is no network. ");
447    (void) fprintf(vis_stderr,"Use flatten_hierarchy.\n");
448    goto endgame;
449  }
450
451  if(!Ntk_NetworkReadNumLatches(network1)) {
452    (void) fprintf(vis_stderr,"**restr error: No latches present in the ");
453    (void) fprintf(vis_stderr,"current network.\n");
454    (void) fprintf(vis_stderr,"** restr error: This algorithm does not apply.\n");
455    goto endgame;
456  }
457
458  /* Check if the current network has signals with multiple values. */
459  if (TestIsNetworkMultipleValued(network1)) {
460    (void) fprintf(vis_stderr,"** restr error: Circuit has multiple valued variables.\n");
461    (void) fprintf(vis_stderr,"** restr error: This algorithm applies to boolean signals only.\n");
462    goto endgame;
463  }
464
465  if(Ntk_NetworkReadNumPrimaryInputs(network1) !=
466     Ntk_NetworkReadNumInputs(network1)) {
467    (void) fprintf(vis_stderr,"** restr error: Pseudo inputs present in the network.\n");
468    (void) fprintf(vis_stderr,"** restr error: This algorithm does not apply.\n");
469    goto endgame;
470  }
471
472  if (!dumpFileName)
473    dumpFileName = util_strsav(Ntk_NetworkReadName(network1));
474  /* Check if the output blif file already exists */
475  blifName = util_strcat3(dumpFileName,".ml.blif","");
476  fp = Cmd_FileOpen(blifName,"r",NIL(char *),1);
477  if (fp) {
478    (void) fprintf(vis_stderr,"** restr error: Output blif file %s already exists.\n",
479                   blifName);
480    (void) fprintf(vis_stderr,"** restr error: Please specify another name.\n");
481    fclose(fp);
482    FREE(blifName);
483    goto endgame;
484  }
485  FREE(blifName);
486
487
488  /* Check if the network has the variables ordered */
489  if (Ord_NetworkTestAreVariablesOrdered(network1, Ord_InputAndLatch_c) == 
490      FALSE) {
491    Ord_NetworkOrderVariables(network1,Ord_RootsByDefault_c,
492                              Ord_NodesByDefault_c, FALSE,
493                              Ord_InputAndLatch_c,Ord_Unassigned_c,
494                              dummy,0);
495    varOrdered = 1;
496  }
497
498  /* If primary input probabilities are specified, read them */
499  if (probFile) {
500    fp = Cmd_FileOpen(probFile,"r",NIL(char *),1);
501    inputProb = readInputProbabilities(network1,fp);
502    fclose(fp);
503    FREE(probFile);
504    fp = NIL(FILE);
505  }
506
507  /* Check if there is an FSM already attached to the network */
508  fsm = (Fsm_Fsm_t *) Ntk_NetworkReadApplInfo(network1, 
509                                              FSM_NETWORK_APPL_KEY);
510  if (fsm == NIL(Fsm_Fsm_t)) {
511    partition = (graph_t *) Ntk_NetworkReadApplInfo(network1,
512                                                    PART_NETWORK_APPL_KEY);
513    /* If there is none then create one. */
514    if (partition == NIL(graph_t) ||
515        (!IsPartitionValid(network1,partition))) {
516      currentNode = Hrc_ManagerReadCurrentNode(*hmgr);
517      modelName = Hrc_NodeReadModelName(currentNode);
518      partition = Part_NetworkCreatePartition(network1, currentNode,
519                                              modelName, (lsList) 0, 
520                                              (lsList) 0, NIL(mdd_t), 
521                                              Part_InOut_c, (lsList) 0, 
522                                              FALSE, FALSE, TRUE);
523 
524      Ntk_NetworkAddApplInfo(network1, RESTR_PART_NETWORK_APPL_KEY,
525                             (Ntk_ApplInfoFreeFn) Part_PartitionFreeCallback,
526                             (void *) partition);
527      restrCreatedPart = 1;
528    }
529    fsm = Fsm_FsmCreateFromNetworkWithPartition(network1, 
530                                                Part_PartitionDuplicate(partition));
531    if (fsm == NIL(Fsm_Fsm_t)) {
532      (void) fprintf(vis_stderr,"** restr error: Could not create ");
533      (void) fprintf(vis_stderr,"an Fsm\n");
534      goto endgame;
535    }
536    Ntk_NetworkAddApplInfo(network1, RESTR_FSM_NETWORK_APPL_KEY,
537                           (Ntk_ApplInfoFreeFn) Fsm_FsmFreeCallback,
538                           (void *) fsm);
539    restrCreatedFsm = 1;
540  } else {
541    partition = (graph_t *) Fsm_FsmReadPartition(fsm);
542
543    if (partition == NIL(graph_t) || 
544        (!IsPartitionValid(network1,partition))) {
545      currentNode = Hrc_ManagerReadCurrentNode(*hmgr);
546      modelName = Hrc_NodeReadModelName(currentNode);
547      partition = Part_NetworkCreatePartition(network1, currentNode,
548                                              modelName, (lsList) 0, 
549                                              (lsList) 0, NIL(mdd_t), 
550                                              Part_InOut_c, (lsList) 0, 
551                                              FALSE, FALSE, TRUE);
552      Ntk_NetworkAddApplInfo(network1, RESTR_PART_NETWORK_APPL_KEY,
553                             (Ntk_ApplInfoFreeFn) Part_PartitionFreeCallback,
554                             (void *) partition);
555      restrCreatedPart = 1;
556
557      fsm = Fsm_FsmCreateFromNetworkWithPartition(network1, 
558                                                  Part_PartitionDuplicate(partition));
559      if (fsm == NIL(Fsm_Fsm_t)) {
560        (void) fprintf(vis_stderr,"** restr error: Could not create ");
561        (void) fprintf(vis_stderr,"an Fsm\n");
562        goto endgame;
563      }
564      Ntk_NetworkAddApplInfo(network1, RESTR_FSM_NETWORK_APPL_KEY,
565                             (Ntk_ApplInfoFreeFn) Fsm_FsmFreeCallback,
566                             (void *) fsm);
567      restrCreatedFsm = 1;
568    }
569  }
570
571  /* Start the timer before calling restruct. */
572  if (timeOutPeriod > 0){
573    (void) signal(SIGALRM, (void(*)(int))TimeOutHandle);
574    (void) alarm(timeOutPeriod);
575    if (setjmp(timeOutEnv) > 0) {
576      (void) fprintf(vis_stderr, "** restr warning: Timeout occurred after ");
577      (void) fprintf(vis_stderr, "%d seconds.\n", timeOutPeriod);
578      alarm(0);
579      goto endgame;
580    }
581  }
582
583  /* Prepare the data structure for the synthesis package */
584  synthInfo = Synth_InitializeInfo(factoring,divisor,0,
585                                   reorder,trySharing,realign,
586                                   dumpFileName,prefix,0);
587
588  initialTime = util_cpu_time();
589  status = RestrCommandRestructureFsm(fsm, heuristic,outOrderFileName,
590                                      equivClasses,nonReachEquiv,
591                                      eqvMethod,inputProb,synthInfo);
592  finalTime = util_cpu_time();
593  if(status) {
594    (void) fprintf(vis_stdout, "%-20s%10ld\n", "RESTR: analysis time =",
595                   (finalTime-initialTime)/1000);
596
597  }
598  else {
599    (void) fprintf(vis_stdout, "** restr error: Could not restructure successfully.\n");
600  }
601   
602  if (synthInfo)
603    Synth_FreeInfo(synthInfo);
604
605    /* Clean up */
606  CleanUp(network1,inputProb,outOrderFileName,dumpFileName,prefix,
607          varOrdered,restrCreatedPart,restrCreatedFsm,probFile);
608
609  alarm(0);
610  return 0;  /* normal exit */
611
612endgame:
613  /* Clean up */
614  CleanUp(network1,inputProb,outOrderFileName,dumpFileName,prefix,
615          varOrdered,restrCreatedPart,restrCreatedFsm,probFile);
616   
617  return 1; /* Error exit */
618
619usage:
620  if (outOrderFileName)
621    FREE(outOrderFileName);
622  if (dumpFileName)
623    FREE(dumpFileName);
624  if (prefix)
625    FREE(prefix);
626  if (probFile)
627    FREE(probFile);
628
629  (void) fprintf(vis_stderr, "\nusage: Also see help restruct_fsm for more details.\n\n");
630  (void) fprintf(vis_stderr, "    -A      \t\tAllow realignment--during symbolic factorization--of BDD\n");
631  (void) fprintf(vis_stderr, "            \t\tand ZDD variables after reordering.\n\n");
632  (void) fprintf(vis_stderr, "    -D <fileHead>\tOutput file name for synthesized circuit.\n");
633  (void) fprintf(vis_stderr, "            \t\tDefault: model_name.ml.blif\n\n");
634  (void) fprintf(vis_stderr, "    -d <divMethod>\tChoose a divisor during synthesis. See\n");
635  (void) fprintf(vis_stderr, "            \t\tsynthesize_network command for more details.\n");
636  (void) fprintf(vis_stderr, "            \t\t0 : Fast divisor\n");
637  (void) fprintf(vis_stderr, "            \t\t1 : Least occuring literal divisor (default)\n");
638  (void) fprintf(vis_stderr, "            \t\t2 : Most occuring literal divisor\n");
639  (void) fprintf(vis_stderr, "            \t\t3 : Level-0 kernel divisor\n\n");
640  (void) fprintf(vis_stderr, "    -E      \t\tPrint the number of equivalence classes in the STG.\n\n");
641  (void) fprintf(vis_stderr, "    -F <probFile>\tInput file with PI probabilities, one per line.\n\n");
642  (void) fprintf(vis_stderr, "    -f <factMethod>\tChoose a factorization method. See synthesize_network\n");
643  (void) fprintf(vis_stderr, "            \t\tfor more details.\n");
644  (void) fprintf(vis_stderr, "            \t\t0 : Simple factoring (default)\n");
645  (void) fprintf(vis_stderr, "            \t\t1 : Generic factoring\n\n");
646  (void) fprintf(vis_stderr, "    -h      \t\tPrint command usage.\n\n");
647  (void) fprintf(vis_stderr, "    -i <name>\t\tPrefix to be used to generate names for internal\n");
648  (void) fprintf(vis_stderr, "            \t\tnodes during synthesis. Default: \"_n\"\n\n");
649  (void) fprintf(vis_stderr, "    -N      \t\tExpand the reachable set R to include those states\n");
650  (void) fprintf(vis_stderr, "            \t\twhich are equivalent to R but unreachable.\n");
651  (void) fprintf(vis_stderr, "            \t\tThe default is not to include.\n\n");
652  (void) fprintf(vis_stderr, "    -o <orderFile>\tFile to output BDD variable order at the end.\n\n");
653  (void) fprintf(vis_stderr, "    -R <value>\t\tSet reordering (0-3)\n");
654  (void) fprintf(vis_stderr, "            \t\t0 : no reordering (default)\n");
655  (void) fprintf(vis_stderr, "            \t\t1 : reordering in only BDD\n");
656  (void) fprintf(vis_stderr, "            \t\t2 : reordering on only ZDD\n");
657  (void) fprintf(vis_stderr, "            \t\t3 : reordering on both\n\n");
658  (void) fprintf(vis_stderr, "    -s <heuristic>\tHeuristic to perform restructuring.\n");
659  (void) fprintf(vis_stderr, "            \t\tType help restruct_fsm for more details on each option.\n");
660  (void) fprintf(vis_stderr, "            \t\tham : Hamming distance based heuristic. (Default)\n");
661  (void) fprintf(vis_stderr, "            \t\tfanin : Fanin oriented heuristic.\n");
662  (void) fprintf(vis_stderr, "            \t\tfaninout : Fanin-Fanout oriented heuristic.\n");
663  (void) fprintf(vis_stderr, "            \t\tcproj : C-Projection based heuristic.\n\n");
664  (void) fprintf(vis_stderr, "    -T      \t\tTry to share mode nodes during symbolic factorization.\n\n");
665  (void) fprintf(vis_stderr, "    -t <seconds>\tTime in seconds to complete the command. The command\n");
666  (void) fprintf(vis_stderr, "            \t\tis aborted if computation time goes above this limit.\n\n");
667  (void) fprintf(vis_stderr, "    -v      \t\tTurn on verbosity.\n");
668
669
670  return 1;    /* error exit */
671}
672
673/**Function********************************************************************
674
675  Synopsis    [Handle function for timeout.]
676
677  Description [This function is called when the time out occurs.]
678
679  SideEffects []
680
681******************************************************************************/
682static void
683TimeOutHandle(void)
684{
685  longjmp(timeOutEnv, 1);
686}
687
688
689/**Function********************************************************************
690
691  Synopsis    [Reads the input probabilities of primary inputs.]
692
693  Description [Reads the input probabilities of primary inputs.]
694
695  SideEffects [None]
696 
697  SeeAlso []
698
699******************************************************************************/
700static st_table *
701readInputProbabilities(
702  Ntk_Network_t *network,
703  FILE *fp)
704
705{
706  Ntk_Node_t *node;
707  char name[MAX_NAME_LEN];
708  double value;
709  double *valuePtr;
710  st_table *inputProb;
711
712  inputProb = st_init_table(st_numcmp,st_numhash);
713
714  while (fscanf(fp, "%s %lf\n", name, &value) != EOF) {
715    node = Ntk_NetworkFindNodeByName(network,name);
716    if (node == NIL(Ntk_Node_t)) {
717      (void) fprintf(vis_stderr,"** restr error: No node by name %s in the network\n",name);
718      (void) fprintf(vis_stderr,"** restr error: Aborting.\n");
719      st_foreach(inputProb,stCountFree,NIL(char));
720      st_free_table(inputProb);
721      return NULL;
722    }
723    if (!Ntk_NodeTestIsPrimaryInput(node)) {
724      fprintf(vis_stderr,"** restr warning: <%s> is not a primary input.\n",name);
725      fprintf(vis_stderr,"** restr warning: Assuming equiprobable primary inputs\n");
726      st_foreach(inputProb,stCountFree,NIL(char));
727      st_free_table(inputProb);
728      return NULL;
729    }
730    valuePtr = ALLOC(double,1);
731    if (value > 1.0) {
732      (void) fprintf(vis_stderr,"** restr warning: %s has prob. value greater than 1: %g\n",
733                     name,value);
734      (void) fprintf(vis_stderr,"** restr warning: Assuming a prob. value of 0.5\n");
735      *valuePtr = 0.5;
736    } else {
737      *valuePtr = value;
738    }
739    st_insert(inputProb,(char *)(long)Ntk_NodeReadMddId(node),(char *)valuePtr);
740  }
741
742  return inputProb;
743}
744
745/**Function********************************************************************
746
747  Synopsis    [Free memory at the end of the task.]
748
749  Description [Free memory at the end of the task.]
750
751  SideEffects [None]
752
753  SeeAlso []
754
755******************************************************************************/
756static void
757CleanUp(
758  Ntk_Network_t *network1,
759  st_table *inputProb,
760  char *outOrderFileName,
761  char *dumpFileName,
762  char *prefix,
763  int varOrdered,
764  int restrCreatedPart,
765  int restrCreatedFsm,
766  char *probFile)
767{
768  Ntk_Node_t *node;
769  lsGen gen;
770
771  if (inputProb) {
772    st_foreach(inputProb,stCountFree,NIL(char));
773    st_free_table(inputProb);
774  }
775   
776  if (outOrderFileName)
777    FREE(outOrderFileName);
778  if (dumpFileName)
779    FREE(dumpFileName);
780  if (prefix)
781    FREE(prefix);
782  if (probFile)
783    FREE(probFile);
784
785  /* Set the mdd id's for all the primary inputs, latches and next
786   * state nodes to UNASSIGNED if it was specifically set in this
787   * routine.
788   */
789  if (varOrdered) {
790    Ntk_NetworkForEachPrimaryInput(network1,gen,node) {
791      Ntk_NodeSetMddId(node,NTK_UNASSIGNED_MDD_ID);
792    }
793    Ntk_NetworkForEachLatch(network1,gen,node) {
794      Ntk_Node_t *shadow;
795      shadow = Ntk_NodeReadShadow(node);
796      Ntk_NodeSetMddId(node,NTK_UNASSIGNED_MDD_ID);   
797      Ntk_NodeSetMddId(shadow,NTK_UNASSIGNED_MDD_ID);   
798    }
799  }
800  /* Delete the partition hooked to the network if it was created in
801   * this routine.
802   */
803  if (restrCreatedPart) {
804    Ntk_NetworkFreeApplInfo(network1,RESTR_PART_NETWORK_APPL_KEY);
805  }
806  /* Delete the FSM hooked to the network if it was created in
807   * this routine.
808   */
809  if (restrCreatedFsm) {
810    Ntk_NetworkFreeApplInfo(network1,RESTR_FSM_NETWORK_APPL_KEY);
811  }
812}
813
814/**Function********************************************************************
815
816  Synopsis    [Procedure to delete values stored in an st_table.]
817
818  Description [Procedure to delete values stored in an st_table.]
819
820  SideEffects [None]
821
822  SeeAlso []
823
824******************************************************************************/
825static enum st_retval
826stCountFree(
827  char *key,
828  char *value,
829  char *arg)
830{
831  double        *d;
832 
833  d = (double *)value;
834  FREE(d);
835  return(ST_CONTINUE);
836 
837} /* end of stCountfree */
838
839
840/**Function********************************************************************
841
842  Synopsis    [Checks whether partition is valid.]
843
844  Description [Checks whether partition is valid. The condition is that the
845  given partition should have a vertex for each combinational output (PO and
846  NS) and combinational input (PI and PS) of the network.]
847
848  SideEffects [None]
849
850  SeeAlso []
851
852******************************************************************************/
853static int
854IsPartitionValid(Ntk_Network_t *network,
855                 graph_t *partition)
856{
857  Ntk_Node_t *node;
858  lsGen gen;
859  char *name;
860
861  Ntk_NetworkForEachCombOutput(network, gen, node) {
862    name = Ntk_NodeReadName(node);
863    if(Part_PartitionFindVertexByName(partition, name) == NIL(vertex_t)) {
864      return(0);
865    }
866  }
867  Ntk_NetworkForEachCombInput(network, gen, node) {
868    name = Ntk_NodeReadName(node);
869    if(Part_PartitionFindVertexByName(partition, name) == NIL(vertex_t)) {
870      return(0);
871    }
872  }
873
874  return 1;
875}
876
877/**Function********************************************************************
878
879  Synopsis    [Checks whether the network has multiple valued signals.]
880
881  Description [Checks whether the network has multiple valued
882  signals. Returns 1 if true, else 0.]
883
884  SideEffects [None]
885
886  SeeAlso []
887
888******************************************************************************/
889static int
890TestIsNetworkMultipleValued(Ntk_Network_t *network)
891{
892  Ntk_Node_t *node;
893  lsGen gen;
894  Var_Variable_t *var;
895  int numValues;
896
897  Ntk_NetworkForEachNode(network,gen,node) {
898    var = Ntk_NodeReadVariable(node);
899    numValues = Var_VariableReadNumValues(var);
900    if (numValues > 2)
901      return 1;
902  }
903  return 0;
904}
Note: See TracBrowser for help on using the repository browser.