go.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* $Id$ */
  2. /*
  3. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. * See the copyright notice in the ACK home directory, in the file "Copyright".
  5. */
  6. /* S H A R E D F I L E
  7. *
  8. * G O . C
  9. *
  10. */
  11. #include <stdio.h>
  12. #include "types.h"
  13. #include "debug.h"
  14. #include "global.h"
  15. #include "files.h"
  16. #include "get.h"
  17. #include "put.h"
  18. #include "lset.h"
  19. #include "map.h"
  20. #include "alloc.h"
  21. #include "go.h"
  22. STATIC bool report_flag = FALSE; /* report #optimizations found? */
  23. #ifdef DEBUG
  24. STATIC bool core_flag = FALSE; /* report core usage? */
  25. #endif
  26. STATIC mach_init(machfile,phase_machinit)
  27. char *machfile;
  28. int (*phase_machinit)();
  29. {
  30. /* Read target machine dependent information */
  31. FILE *f;
  32. f = openfile(machfile,"r");
  33. fscanf(f,"%d",&ws);
  34. fscanf(f,"%d",&ps);
  35. if (ws != ps && ps != 2*ws) error("illegal pointer size");
  36. (*phase_machinit)(f);
  37. fclose(f);
  38. }
  39. go(argc,argv,initialize,optimize,phase_machinit,proc_flag)
  40. int argc;
  41. char *argv[];
  42. int (*initialize)();
  43. int (*optimize)();
  44. int (*phase_machinit)();
  45. int (*proc_flag)();
  46. {
  47. FILE *f, *gf, *f2, *gf2; /* The EM input and output and
  48. * the basic block graphs input and output
  49. */
  50. bblock_p g;
  51. line_p l;
  52. short kind;
  53. int i;
  54. char *p;
  55. bool time_opt = TRUE;
  56. linecount = 0;
  57. for (i = ARGSTART; i < argc; i++) {
  58. p = argv[i];
  59. if (*p++ != '-') error("illegal argument");
  60. switch(*p) {
  61. case 'S':
  62. time_opt = FALSE;
  63. break;
  64. case 'T':
  65. time_opt = TRUE;
  66. break;
  67. case 'M':
  68. p++;
  69. mach_init(p,phase_machinit);
  70. break;
  71. case 'C':
  72. #ifdef DEBUG
  73. core_flag = TRUE;
  74. #endif
  75. break;
  76. case 'Q':
  77. report_flag = TRUE;
  78. break;
  79. case 'V':
  80. verbose_flag = TRUE;
  81. break;
  82. default:
  83. (*proc_flag)(p);
  84. break;
  85. }
  86. }
  87. time_space_ratio = (time_opt ? 100 : 0);
  88. fproc = getptable(pname); /* proc table */
  89. fdblock = getdtable(dname); /* data block table */
  90. (*initialize)();
  91. if (optimize == no_action) return;
  92. f = openfile(lname,"r");
  93. gf = openfile(bname,"r");
  94. f2 = openfile(lname2,"w");
  95. gf2 = openfile(bname2,"w");
  96. mesregs = Lempty_set();
  97. while (getunit(gf,f,&kind,&g,&l,&curproc,TRUE)) {
  98. /* Read the control flow graph and EM text of
  99. * one procedure and optimize it.
  100. */
  101. if (kind == LDATA) {
  102. putunit(LDATA, (proc_p) 0, l, gf2, f2);
  103. continue;
  104. }
  105. OUTTRACE("flow graph of proc %d read",curproc->p_id);
  106. curproc->p_start = g;
  107. /* The global variable curproc points to the
  108. * current procedure. It is set by getgraph
  109. */
  110. (*optimize)(curproc);
  111. putunit(LTEXT,curproc,(line_p) 0,gf2,f2);
  112. /* output control flow graph + text */
  113. OUTTRACE("graph of proc %d outputted",curproc->p_id);
  114. Ldeleteset(mesregs);
  115. mesregs = Lempty_set();
  116. }
  117. fclose(f);
  118. fclose(f2);
  119. fclose(gf);
  120. fclose(gf2);
  121. f = openfile(dname2,"w");
  122. putdtable(fdblock,f);
  123. /* fclose(f); done by putdtable */
  124. f = openfile(pname2,"w");
  125. putptable(fproc,f,TRUE);
  126. /* fclose(f); done by putptable */
  127. core_usage();
  128. }
  129. no_action() { }
  130. core_usage()
  131. {
  132. #ifdef DEBUG
  133. if (core_flag) {
  134. coreusage();
  135. }
  136. #endif
  137. }
  138. report(s,n)
  139. char *s;
  140. int n;
  141. {
  142. /* Report number of optimizations found, if report_flag is set */
  143. if (report_flag) {
  144. fprintf(stderr,"%s: %d\n",s,n);
  145. }
  146. }