reg.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #ifndef NORCSID
  2. static char rcsid[] = "$Id$";
  3. #endif
  4. #include "assert.h"
  5. #include "param.h"
  6. #include "tables.h"
  7. #include "types.h"
  8. #include <cgg_cg.h>
  9. #include "data.h"
  10. #include "result.h"
  11. #include "extern.h"
  12. /*
  13. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  14. * See the copyright notice in the ACK home directory, in the file "Copyright".
  15. *
  16. * Author: Hans van Staveren
  17. */
  18. chrefcount(regno,amount,tflag) {
  19. register struct reginfo *rp;
  20. #if MAXMEMBERS != 0
  21. register i, tmp;
  22. #endif
  23. rp= &machregs[regno];
  24. #if MAXMEMBERS!=0
  25. if (rp->r_members[0]==0) {
  26. #endif
  27. rp->r_refcount += amount;
  28. if (tflag)
  29. rp->r_tcount += amount;
  30. assert(rp->r_refcount >= 0);
  31. #if MAXMEMBERS!=0
  32. } else
  33. for (i=0;i<MAXMEMBERS;i++)
  34. if ((tmp = rp->r_members[i])!=0)
  35. chrefcount(tmp,amount,tflag);
  36. #endif
  37. }
  38. getrefcount(regno, tflag) {
  39. register struct reginfo *rp;
  40. #if MAXMEMBERS != 0
  41. register i,maxcount, tmp;
  42. #endif
  43. rp= &machregs[regno];
  44. #if MAXMEMBERS!=0
  45. if (rp->r_members[0]==0)
  46. #endif
  47. return(rp->r_refcount - (tflag ? rp->r_tcount : 0));
  48. #if MAXMEMBERS!=0
  49. else {
  50. maxcount=0;
  51. for (i=0;i<MAXMEMBERS;i++)
  52. if ((tmp=rp->r_members[i])!=0) {
  53. tmp = getrefcount(tmp, tflag);
  54. if (tmp > maxcount) maxcount = tmp;
  55. }
  56. return(maxcount);
  57. }
  58. #endif
  59. }
  60. erasereg(regno) {
  61. register struct reginfo *rp = &machregs[regno];
  62. register int i;
  63. register byte *tdpb;
  64. #if MAXMEMBERS==0
  65. rp->r_contents.t_token = 0;
  66. for (i=TOKENSIZE-1;i>=0;i--)
  67. rp->r_contents.t_att[i].aw = 0;
  68. /* Now erase recursively all registers containing
  69. * something using this one
  70. */
  71. for (rp=machregs;rp<machregs+NREGS;rp++) {
  72. if (rp->r_contents.t_token == -1) {
  73. if (rp->r_contents.t_att[0].ar == regno) {
  74. /* erasereg(rp-machregs);
  75. replaced by the following three
  76. lines
  77. */
  78. rp->r_contents.t_token = 0;
  79. for (i=TOKENSIZE-1;i>=0;i--)
  80. rp->r_contents.t_att[i].aw = 0;
  81. }
  82. } else if (rp->r_contents.t_token > 0) {
  83. tdpb= & (tokens[rp->r_contents.t_token].t_type[0]);
  84. for (i=0;i<TOKENSIZE;i++)
  85. if (*tdpb++ == EV_REG &&
  86. rp->r_contents.t_att[i].ar == regno) {
  87. /* erasereg(rp-machregs);
  88. replaced by the following three
  89. lines
  90. */
  91. rp->r_contents.t_token = 0;
  92. for (i=TOKENSIZE-1;i>=0;i--)
  93. rp->r_contents.t_att[i].aw = 0;
  94. break;
  95. }
  96. }
  97. }
  98. #else
  99. extern short clashlist[];
  100. register short *sp = &clashlist[rp->r_iclash];
  101. rp->r_contents.t_token = 0;
  102. while (*sp) {
  103. rp = &machregs[*sp];
  104. rp->r_contents.t_token = 0;
  105. for (i=TOKENSIZE-1;i>=0;i--)
  106. rp->r_contents.t_att[i].aw = 0;
  107. regno = *sp++;
  108. /* Now erase recursively all registers containing
  109. * something using this one
  110. */
  111. for (rp=machregs;rp<machregs+NREGS;rp++) {
  112. if (rp->r_contents.t_token == -1) {
  113. if (rp->r_contents.t_att[0].ar == regno) {
  114. /* erasereg(rp-machregs);
  115. replaced by the following three
  116. lines
  117. */
  118. rp->r_contents.t_token = 0;
  119. for (i=TOKENSIZE-1;i>=0;i--)
  120. rp->r_contents.t_att[i].aw = 0;
  121. }
  122. } else if (rp->r_contents.t_token > 0) {
  123. tdpb= & (tokens[rp->r_contents.t_token].t_type[0]);
  124. for (i=0;i<TOKENSIZE;i++)
  125. if (*tdpb++ == EV_REG &&
  126. rp->r_contents.t_att[i].ar == regno) {
  127. /* erasereg(rp-machregs);
  128. replaced by the following three
  129. lines
  130. */
  131. rp->r_contents.t_token = 0;
  132. for (i=TOKENSIZE-1;i>=0;i--)
  133. rp->r_contents.t_att[i].aw = 0;
  134. break;
  135. }
  136. }
  137. }
  138. }
  139. #endif
  140. }
  141. cleanregs() {
  142. register struct reginfo *rp;
  143. register i;
  144. for (rp=machregs;rp<machregs+NREGS;rp++) {
  145. rp->r_contents.t_token = 0;
  146. for (i=TOKENSIZE-1;i>=0;i--)
  147. rp->r_contents.t_att[i].aw = 0;
  148. }
  149. }
  150. #ifndef NDEBUG
  151. inctcount(regno) {
  152. register struct reginfo *rp;
  153. register i;
  154. rp = &machregs[regno];
  155. #if MAXMEMBERS!=0
  156. if (rp->r_members[0] == 0) {
  157. #endif
  158. rp->r_tcount++;
  159. #if MAXMEMBERS!=0
  160. } else {
  161. for (i=0;i<MAXMEMBERS;i++)
  162. if (rp->r_members[i] != 0)
  163. inctcount(rp->r_members[i]);
  164. }
  165. #endif
  166. }
  167. chkregs() {
  168. register struct reginfo *rp;
  169. register token_p tp;
  170. register byte *tdpb;
  171. int i;
  172. for (rp=machregs+1;rp<machregs+NREGS;rp++) {
  173. assert(rp->r_tcount==0);
  174. }
  175. for (tp=fakestack;tp<fakestack+stackheight;tp++) {
  176. if (tp->t_token == -1)
  177. inctcount(tp->t_att[0].ar);
  178. else {
  179. tdpb = &(tokens[tp->t_token].t_type[0]);
  180. for (i=0;i<TOKENSIZE;i++)
  181. if (*tdpb++==EV_REG)
  182. inctcount(tp->t_att[i].ar);
  183. }
  184. }
  185. #ifdef REGVARS
  186. #include <em_reg.h>
  187. for(i=reg_any;i<=reg_float;i++) {
  188. int j;
  189. for(j=0;j<nregvar[i];j++)
  190. inctcount(rvnumbers[i][j]);
  191. }
  192. #endif /* REGVARS */
  193. for (rp=machregs+1;rp<machregs+NREGS;rp++) {
  194. assert(rp->r_refcount==rp->r_tcount);
  195. rp->r_tcount=0;
  196. }
  197. }
  198. #endif