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