2 |
7u83 |
1 |
/*
|
|
|
2 |
Crown Copyright (c) 1997
|
|
|
3 |
|
|
|
4 |
This TenDRA(r) Computer Program is subject to Copyright
|
|
|
5 |
owned by the United Kingdom Secretary of State for Defence
|
|
|
6 |
acting through the Defence Evaluation and Research Agency
|
|
|
7 |
(DERA). It is made available to Recipients with a
|
|
|
8 |
royalty-free licence for its use, reproduction, transfer
|
|
|
9 |
to other parties and amendment for any purpose not excluding
|
|
|
10 |
product development provided that any such use et cetera
|
|
|
11 |
shall be deemed to be acceptance of the following conditions:-
|
|
|
12 |
|
|
|
13 |
(1) Its Recipients shall ensure that this Notice is
|
|
|
14 |
reproduced upon any copies or amended versions of it;
|
|
|
15 |
|
|
|
16 |
(2) Any amended version of it shall be clearly marked to
|
|
|
17 |
show both the nature of and the organisation responsible
|
|
|
18 |
for the relevant amendment or amendments;
|
|
|
19 |
|
|
|
20 |
(3) Its onward transfer from a recipient to another
|
|
|
21 |
party shall be deemed to be that party's acceptance of
|
|
|
22 |
these conditions;
|
|
|
23 |
|
|
|
24 |
(4) DERA gives no warranty or assurance as to its
|
|
|
25 |
quality or suitability for any purpose and DERA accepts
|
|
|
26 |
no liability whatsoever in relation to any use to which
|
|
|
27 |
it may be put.
|
|
|
28 |
*/
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
/**********************************************************************
|
|
|
32 |
$Author: release $
|
|
|
33 |
$Date: 1998/01/17 15:56:06 $
|
|
|
34 |
$Revision: 1.1.1.1 $
|
|
|
35 |
$Log: regalloc.c,v $
|
|
|
36 |
* Revision 1.1.1.1 1998/01/17 15:56:06 release
|
|
|
37 |
* First version to be checked into rolling release.
|
|
|
38 |
*
|
|
|
39 |
* Revision 1.2 1995/09/22 15:49:18 currie
|
|
|
40 |
* added outpar
|
|
|
41 |
*
|
|
|
42 |
* Revision 1.1 1995/04/13 09:08:06 currie
|
|
|
43 |
* Initial revision
|
|
|
44 |
*
|
|
|
45 |
***********************************************************************/
|
|
|
46 |
/****************************************************************
|
|
|
47 |
regalloc.c
|
|
|
48 |
|
|
|
49 |
The main procedure defined here is reg_alloc which
|
|
|
50 |
allocates registers and stack space for a proc exp. After the application of
|
|
|
51 |
weights to the body reg_alloc re-codes the number field of each ident within it. Paralloc in paralloc.c does the corresponding work for the
|
|
|
52 |
parameters.
|
|
|
53 |
At the end of reg_alloc:-
|
|
|
54 |
1) props of ident contains inreg_bits or infreg_bits and number = 0
|
|
|
55 |
then the value will be in a t reg to be chosen in make_code
|
|
|
56 |
2) if props contains the reg bits then number of ident is fixpt s reg
|
|
|
57 |
or floatpnt s reg (divided by 2)
|
|
|
58 |
3) value is on the stack and:
|
|
|
59 |
number of ident = (word displacement in locals)*64 + 29
|
|
|
60 |
|
|
|
61 |
*****************************************************************/
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
#include "config.h"
|
|
|
66 |
#include "expmacs.h"
|
|
|
67 |
#include "tags.h"
|
|
|
68 |
#include "procrectypes.h"
|
|
|
69 |
#include "bitsmacs.h"
|
|
|
70 |
#include "maxminmacs.h"
|
|
|
71 |
#include "regable.h"
|
|
|
72 |
#include "regmacs.h"
|
|
|
73 |
#include "common_types.h"
|
|
|
74 |
#include "frames.h"
|
|
|
75 |
#include "flags.h"
|
|
|
76 |
#include "regalloc.h"
|
|
|
77 |
|
|
|
78 |
spacereq zerospace = {
|
|
|
79 |
0, 0, 0
|
|
|
80 |
};
|
|
|
81 |
|
|
|
82 |
/*****************************************************************
|
|
|
83 |
maxspace
|
|
|
84 |
|
|
|
85 |
Procedure to find the total spacereq of two spacereqs. The bit
|
|
|
86 |
representations of the s regs used are simply 'or'ed so that the
|
|
|
87 |
resulting dump fields contain all the regs of the parameters.
|
|
|
88 |
The largest of the two stack sizes is returned as the stack of the result.
|
|
|
89 |
|
|
|
90 |
*****************************************************************/
|
|
|
91 |
|
|
|
92 |
spacereq maxspace
|
|
|
93 |
PROTO_N ( (a,b) )
|
|
|
94 |
PROTO_T ( spacereq a X spacereq b )
|
|
|
95 |
{
|
|
|
96 |
a.fixdump |= b.fixdump;
|
|
|
97 |
a.fltdump |= b.fltdump;
|
|
|
98 |
a.stack = max (a.stack, b.stack);
|
|
|
99 |
return a;
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
static int spareparregs = 0;
|
|
|
103 |
|
|
|
104 |
/******************************************************************
|
|
|
105 |
reg_alloc
|
|
|
106 |
|
|
|
107 |
Delivers a spacereq which gives the local stack bit requirement in the
|
|
|
108 |
stack field and the s regs used as bit positions in the fixdump, sdump and
|
|
|
109 |
ddump fields for fixed point, single and double floats respectively.
|
|
|
110 |
|
|
|
111 |
******************************************************************/
|
|
|
112 |
|
|
|
113 |
spacereq regalloc
|
|
|
114 |
PROTO_N ( ( e, freefixed, freefloat, stack) )
|
|
|
115 |
PROTO_T ( exp e X int freefixed X int freefloat X long stack )
|
|
|
116 |
{
|
|
|
117 |
/* e is a proc body . freefixed and
|
|
|
118 |
freefloat are the number of fixed and
|
|
|
119 |
floating s regs available. These are
|
|
|
120 |
initialised at the outer level but may
|
|
|
121 |
be reduced by usage in paralloc */
|
|
|
122 |
int n = name (e);
|
|
|
123 |
exp s = son (e);
|
|
|
124 |
spacereq def;
|
|
|
125 |
|
|
|
126 |
if (n == ident_tag) {
|
|
|
127 |
int ffix = freefixed;
|
|
|
128 |
int ffloat = freefloat;
|
|
|
129 |
long st = stack;
|
|
|
130 |
int old_spareparregs = spareparregs;
|
|
|
131 |
|
|
|
132 |
spacereq body;
|
|
|
133 |
ash a;
|
|
|
134 |
if (props (e) & defer_bit) {/* the tag declared is transparent to code
|
|
|
135 |
production */
|
|
|
136 |
def = zerospace;
|
|
|
137 |
}
|
|
|
138 |
else {
|
|
|
139 |
a = ashof (sh (s));
|
|
|
140 |
if (name(s) != compound_tag && name(s) != nof_tag
|
|
|
141 |
&& name(s) != concatnof_tag ) {
|
|
|
142 |
def = regalloc (s, freefixed, freefloat, stack);
|
|
|
143 |
}
|
|
|
144 |
else { /* elements of tuples are done separately so evaluate above dec */
|
|
|
145 |
if (a.ashalign <= 32 || (stack & 0x20) == 0) {
|
|
|
146 |
st = stack + ((a.ashsize + 31) & ~31);
|
|
|
147 |
}
|
|
|
148 |
else {
|
|
|
149 |
st = stack + 32 + ((a.ashsize + 31) & ~31);
|
|
|
150 |
}
|
|
|
151 |
def = regalloc (s, freefixed, freefloat, st);
|
|
|
152 |
}
|
|
|
153 |
if ((props (e) & inreg_bits) == 0 && fixregable (e) && no (e) < ffix) {
|
|
|
154 |
/* suitable for s reg , no(e) has been set
|
|
|
155 |
up by weights */
|
|
|
156 |
props (e) |= inreg_bits;
|
|
|
157 |
if( ffix == 9) {
|
|
|
158 |
no(e)=30;
|
|
|
159 |
def.fixdump |= (1 << 14);
|
|
|
160 |
}
|
|
|
161 |
else {
|
|
|
162 |
no (e) = ffix + 15; /* will be in s reg , note s0 = $16 */
|
|
|
163 |
def.fixdump |= (1 << (ffix-1));
|
|
|
164 |
}
|
|
|
165 |
ffix -= 1;
|
|
|
166 |
|
|
|
167 |
}
|
|
|
168 |
else
|
|
|
169 |
if ((props (e) & infreg_bits) == 0
|
|
|
170 |
&& floatregable (e) && no (e) < ffloat) {
|
|
|
171 |
/* suitable for float s reg , no(e) has
|
|
|
172 |
been set up by weights */
|
|
|
173 |
props (e) |= infreg_bits;
|
|
|
174 |
|
|
|
175 |
no (e) = ffloat + 9; /* will be in s reg , note start from $f20 */
|
|
|
176 |
ffloat -= 1;
|
|
|
177 |
def.fltdump |= (3 << (ffloat << 1));
|
|
|
178 |
}
|
|
|
179 |
else
|
|
|
180 |
if ((props (e) & inanyreg) == 0) {
|
|
|
181 |
if( fixregable(e) && PossParReg(e) && spareparregs > 0) {
|
|
|
182 |
props(e) |= inreg_bits;
|
|
|
183 |
no(e) = 0;
|
|
|
184 |
spareparregs--;
|
|
|
185 |
}
|
|
|
186 |
else
|
|
|
187 |
/* not suitable for reg allocation */
|
|
|
188 |
if (name (son (e)) == val_tag && !isvar (e) && !isvis(e)) {
|
|
|
189 |
/* must have been forced by const- replace
|
|
|
190 |
uses by the value */
|
|
|
191 |
exp t = pt (e);
|
|
|
192 |
for (; t != nilexp;) {
|
|
|
193 |
exp p = pt (t);
|
|
|
194 |
setname (t, val_tag);
|
|
|
195 |
son (t) = nilexp;
|
|
|
196 |
no (t) = no (son (e));
|
|
|
197 |
props (t) = 0;
|
|
|
198 |
pt (t) = nilexp;
|
|
|
199 |
t = p;
|
|
|
200 |
}
|
|
|
201 |
pt (e) = nilexp;
|
|
|
202 |
props (e) |= defer_bit;
|
|
|
203 |
def = zerospace;
|
|
|
204 |
}
|
|
|
205 |
else
|
|
|
206 |
if (name (son (e)) == name_tag && !isvar (e) && !isvis(e)) {
|
|
|
207 |
/* must have been forced - defer it */
|
|
|
208 |
props (e) |= defer_bit;
|
|
|
209 |
def = zerospace;
|
|
|
210 |
}
|
|
|
211 |
else
|
|
|
212 |
if (isparam(e)) {
|
|
|
213 |
if (props(son(e)) != 0) {
|
|
|
214 |
spareparregs++; /* can use this reg in PossParReg */
|
|
|
215 |
}
|
|
|
216 |
no(e) = 0;
|
|
|
217 |
/* don't know framesize yet; displacement in no(son(e)) */
|
|
|
218 |
|
|
|
219 |
}
|
|
|
220 |
else { /* allocate on stack */
|
|
|
221 |
int basereg = (Has_vcallees)?local_reg:((Has_fp)?30:29);
|
|
|
222 |
if (a.ashalign <= 32 || (stack & 0x20) == 0) {
|
|
|
223 |
st = stack + ((a.ashsize + 31) & ~31);
|
|
|
224 |
}
|
|
|
225 |
else {
|
|
|
226 |
stack += 32;
|
|
|
227 |
st = stack + ((a.ashsize + 31) & ~31);
|
|
|
228 |
}
|
|
|
229 |
def.stack = max (def.stack, st);
|
|
|
230 |
no (e) = stack * 2 + basereg;
|
|
|
231 |
}
|
|
|
232 |
}
|
|
|
233 |
else
|
|
|
234 |
if (no (e) == 101) {
|
|
|
235 |
no (e) = ((props (e) & inreg_bits) != 0) ? 2 : 16;
|
|
|
236 |
/* set up result of proc as declared id ($f16 = $f0 later)
|
|
|
237 |
*/
|
|
|
238 |
}
|
|
|
239 |
/* else allocation of stack like regs in make_code */
|
|
|
240 |
}
|
|
|
241 |
body = regalloc (bro (s), ffix, ffloat, st);
|
|
|
242 |
spareparregs = old_spareparregs;
|
|
|
243 |
return maxspace (body, def);
|
|
|
244 |
}
|
|
|
245 |
else /* recurse on all expressions in tree */
|
|
|
246 |
if (n == case_tag) {
|
|
|
247 |
return regalloc (s, freefixed, freefloat, stack);
|
|
|
248 |
}
|
|
|
249 |
else
|
|
|
250 |
if (n != name_tag && n!= env_offset_tag
|
|
|
251 |
&& n!= general_env_offset_tag && s != nilexp) {
|
|
|
252 |
def = regalloc (s, freefixed, freefloat, stack);
|
|
|
253 |
while (!last (s)) {
|
|
|
254 |
s = bro (s);
|
|
|
255 |
def = maxspace (def, regalloc (s, freefixed, freefloat, stack));
|
|
|
256 |
}
|
|
|
257 |
return def;
|
|
|
258 |
}
|
|
|
259 |
else {
|
|
|
260 |
def = zerospace;
|
|
|
261 |
def.stack = stack;
|
|
|
262 |
return def;
|
|
|
263 |
}
|
|
|
264 |
}
|