reg.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 <cg_pattern.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. register i;
  21. rp= &machregs[regno];
  22. #if MAXMEMBERS!=0
  23. if (rp->r_members[0]==0) {
  24. #endif
  25. rp->r_refcount += amount;
  26. if (tflag)
  27. rp->r_tcount += amount;
  28. assert(rp->r_refcount >= 0);
  29. #if MAXMEMBERS!=0
  30. } else
  31. for (i=0;i<MAXMEMBERS;i++)
  32. if (rp->r_members[i]!=0)
  33. chrefcount(rp->r_members[i],amount,tflag);
  34. #endif
  35. }
  36. getrefcount(regno, tflag) {
  37. register struct reginfo *rp;
  38. register i,maxcount;
  39. rp= &machregs[regno];
  40. #if MAXMEMBERS!=0
  41. if (rp->r_members[0]==0)
  42. #endif
  43. return(rp->r_refcount - (tflag ? rp->r_tcount : 0));
  44. #if MAXMEMBERS!=0
  45. else {
  46. maxcount=0;
  47. for (i=0;i<MAXMEMBERS;i++)
  48. if (rp->r_members[i]!=0)
  49. maxcount=max(maxcount,getrefcount(rp->r_members[i], tflag));
  50. return(maxcount);
  51. }
  52. #endif
  53. }
  54. erasereg(regno) {
  55. register struct reginfo *rp;
  56. register int i;
  57. rp = &machregs[regno];
  58. rp->r_contents.t_token = 0;
  59. for (i=0;i<TOKENSIZE;i++)
  60. rp->r_contents.t_att[i].aw = 0;
  61. #if MAXMEMBERS == 0
  62. awayreg(regno);
  63. #else
  64. if (regno == 1) { /* condition codes */
  65. } else
  66. for (rp=machregs;rp<machregs+NREGS;rp++)
  67. if (rp->r_clash[regno>>4]&(1<<(regno&017))) {
  68. rp->r_contents.t_token = 0;
  69. for (i=0;i<TOKENSIZE;i++)
  70. rp->r_contents.t_att[i].aw = 0;
  71. awayreg((int)(rp-machregs));
  72. }
  73. #endif
  74. }
  75. awayreg(regno) {
  76. register struct reginfo *rp;
  77. register tkdef_p tdp;
  78. register i;
  79. /* Now erase recursively all registers containing
  80. * something using this one
  81. */
  82. for (rp=machregs;rp<machregs+NREGS;rp++) {
  83. if (rp->r_contents.t_token == -1) {
  84. if (rp->r_contents.t_att[0].ar == regno)
  85. erasereg((int)(rp-machregs));
  86. } else if (rp->r_contents.t_token > 0) {
  87. tdp= & tokens[rp->r_contents.t_token];
  88. for (i=0;i<TOKENSIZE;i++)
  89. if (tdp->t_type[i] == EV_REG &&
  90. rp->r_contents.t_att[i].ar == regno) {
  91. erasereg((int)(rp-machregs));
  92. break;
  93. }
  94. }
  95. }
  96. }
  97. cleanregs() {
  98. register struct reginfo *rp;
  99. register i;
  100. for (rp=machregs;rp<machregs+NREGS;rp++) {
  101. rp->r_contents.t_token = 0;
  102. for (i=0;i<TOKENSIZE;i++)
  103. rp->r_contents.t_att[i].aw = 0;
  104. }
  105. }
  106. #ifndef NDEBUG
  107. inctcount(regno) {
  108. register struct reginfo *rp;
  109. register i;
  110. rp = &machregs[regno];
  111. #if MAXMEMBERS!=0
  112. if (rp->r_members[0] == 0) {
  113. #endif
  114. rp->r_tcount++;
  115. #if MAXMEMBERS!=0
  116. } else {
  117. for (i=0;i<MAXMEMBERS;i++)
  118. if (rp->r_members[i] != 0)
  119. inctcount(rp->r_members[i]);
  120. }
  121. #endif
  122. }
  123. chkregs() {
  124. register struct reginfo *rp;
  125. register token_p tp;
  126. register tkdef_p tdp;
  127. int i;
  128. for (rp=machregs;rp<machregs+NREGS;rp++) {
  129. assert(rp->r_tcount==0);
  130. }
  131. for (tp=fakestack;tp<fakestack+stackheight;tp++) {
  132. if (tp->t_token == -1)
  133. inctcount(tp->t_att[0].ar);
  134. else {
  135. tdp = &tokens[tp->t_token];
  136. for (i=0;i<TOKENSIZE;i++)
  137. if (tdp->t_type[i]==EV_REG)
  138. inctcount(tp->t_att[i].ar);
  139. }
  140. }
  141. #ifdef REGVARS
  142. #include <em_reg.h>
  143. for(i=reg_any;i<=reg_float;i++) {
  144. int j;
  145. for(j=0;j<nregvar[i];j++)
  146. inctcount(rvnumbers[i][j]);
  147. }
  148. #endif /* REGVARS */
  149. for (rp=machregs;rp<machregs+NREGS;rp++) {
  150. assert(rp->r_refcount==rp->r_tcount);
  151. rp->r_tcount=0;
  152. }
  153. }
  154. #endif