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