Subversion Repositories tendra.SVN

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    Copyright (c) 1993 Open Software Foundation, Inc.
32
    Copyright (c) 1993 Open Software Foundation, Inc.
3
 
33
 
4
 
34
 
5
    All Rights Reserved
35
    All Rights Reserved
6
 
36
 
7
 
37
 
8
    Permission to use, copy, modify, and distribute this software
38
    Permission to use, copy, modify, and distribute this software
9
    and its documentation for any purpose and without fee is hereby
39
    and its documentation for any purpose and without fee is hereby
10
    granted, provided that the above copyright notice appears in all
40
    granted, provided that the above copyright notice appears in all
11
    copies and that both the copyright notice and this permission
41
    copies and that both the copyright notice and this permission
12
    notice appear in supporting documentation.
42
    notice appear in supporting documentation.
Line 14... Line 44...
14
 
44
 
15
    OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING
45
    OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING
16
    ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
46
    ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17
    PARTICULAR PURPOSE.
47
    PARTICULAR PURPOSE.
18
 
48
 
19
 
49
 
20
    IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
50
    IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
21
    CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
51
    CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
22
    LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
52
    LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
23
    NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
53
    NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
24
    WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
54
    WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25
*/
55
*/
26
 
56
 
27
/*
57
/*
28
    		 Crown Copyright (c) 1997
58
    		 Crown Copyright (c) 1997
29
    
59
 
30
    This TenDRA(r) Computer Program is subject to Copyright
60
    This TenDRA(r) Computer Program is subject to Copyright
31
    owned by the United Kingdom Secretary of State for Defence
61
    owned by the United Kingdom Secretary of State for Defence
32
    acting through the Defence Evaluation and Research Agency
62
    acting through the Defence Evaluation and Research Agency
33
    (DERA).  It is made available to Recipients with a
63
    (DERA).  It is made available to Recipients with a
34
    royalty-free licence for its use, reproduction, transfer
64
    royalty-free licence for its use, reproduction, transfer
35
    to other parties and amendment for any purpose not excluding
65
    to other parties and amendment for any purpose not excluding
36
    product development provided that any such use et cetera
66
    product development provided that any such use et cetera
37
    shall be deemed to be acceptance of the following conditions:-
67
    shall be deemed to be acceptance of the following conditions:-
38
    
68
 
39
        (1) Its Recipients shall ensure that this Notice is
69
        (1) Its Recipients shall ensure that this Notice is
40
        reproduced upon any copies or amended versions of it;
70
        reproduced upon any copies or amended versions of it;
41
    
71
 
42
        (2) Any amended version of it shall be clearly marked to
72
        (2) Any amended version of it shall be clearly marked to
43
        show both the nature of and the organisation responsible
73
        show both the nature of and the organisation responsible
44
        for the relevant amendment or amendments;
74
        for the relevant amendment or amendments;
45
    
75
 
46
        (3) Its onward transfer from a recipient to another
76
        (3) Its onward transfer from a recipient to another
47
        party shall be deemed to be that party's acceptance of
77
        party shall be deemed to be that party's acceptance of
48
        these conditions;
78
        these conditions;
49
    
79
 
50
        (4) DERA gives no warranty or assurance as to its
80
        (4) DERA gives no warranty or assurance as to its
51
        quality or suitability for any purpose and DERA accepts
81
        quality or suitability for any purpose and DERA accepts
52
        no liability whatsoever in relation to any use to which
82
        no liability whatsoever in relation to any use to which
53
        it may be put.
83
        it may be put.
54
*/
84
*/
Line 126... Line 156...
126
  { 0.0	/* , ... */ },
156
  { 0.0	/* , ... */ },
127
  { 0.0	/* , ... */ }
157
  { 0.0	/* , ... */ }
128
};
158
};
129
 
159
 
130
 
160
 
131
weights weightsv PROTO_S ((double, exp));
161
weights weightsv(double, exp);
132
 
162
 
133
 
163
 
134
weights add_weights PROTO_N ((w1,w2)) PROTO_T (weights * w1 X weights * w2)
164
weights add_weights(weights * w1, weights * w2)
135
{
165
{
136
  /* sum of weights */
166
  /* sum of weights */
137
  weights r;
167
  weights r;
138
  long i;
168
  long i;
139
 
169
 
140
  for (i = 0; i < wfixno; ++i)
170
  for (i = 0; i < wfixno; ++i)
141
  {
171
  {
142
    (r.fix)[i] = (w1->fix)[i] + (w2->fix)[i];
172
   (r.fix)[i] = (w1->fix)[i] + (w2->fix)[i];
143
  }
173
  }
144
  for (i = 0; i < wfloatno; ++i)
174
  for (i = 0; i < wfloatno; ++i)
145
  {
175
  {
146
    (r.floating)[i] = (w1->floating)[i] + (w2->floating)[i];
176
   (r.floating)[i] = (w1->floating)[i] + (w2->floating)[i];
147
  }
177
  }
148
  return (r);
178
  return(r);
149
}
179
}
150
 
180
 
151
 
181
 
152
wp max_weights PROTO_N ((loc,ws,fix)) PROTO_T (double loc X weights * ws X bool fix)
182
wp max_weights(double loc, weights * ws, bool fix)
153
{
183
{
154
  /*
184
  /*
155
   * loc is the usage count of a tag, ws is the weights computed for the scope
185
   * loc is the usage count of a tag, ws is the weights computed for the scope
156
   * of the tag and fix distinguishes between fix and float. This computes the
186
   * of the tag and fix distinguishes between fix and float. This computes the
157
   * weights for the declaration and a break point for register allocation
187
   * weights for the declaration and a break point for register allocation
Line 162... Line 192...
162
   */
192
   */
163
  long bk = wfixno + 1;
193
  long bk = wfixno + 1;
164
  long i;
194
  long i;
165
  float *w = (ws->fix);		/* w[i] = greatest usage of (i+1) inner fixed tags  */
195
  float *w = (ws->fix);		/* w[i] = greatest usage of (i+1) inner fixed tags  */
166
  wp res;
196
  wp res;
167
  float *pw = &(((res.wp_weights).fix)[0]);
197
  float *pw = & (((res.wp_weights).fix)[0]);
168
 
198
 
169
  if (fix)
199
  if (fix)
170
  {
200
  {
171
    for (i = 0; i < wfixno; ++i)
201
    for (i = 0; i < wfixno; ++i)
172
    {
202
    {
Line 216... Line 246...
216
 
246
 
217
  res.fix_break = bk;
247
  res.fix_break = bk;
218
 
248
 
219
  bk = wfloatno + 1;
249
  bk = wfloatno + 1;
220
  w = (ws->floating);
250
  w = (ws->floating);
221
  pw = &(((res.wp_weights).floating)[0]);
251
  pw = & (((res.wp_weights).floating)[0]);
222
  if (!fix)
252
  if (!fix)
223
  {				/* same algorithm for float regs as fixed regs */
253
  {				/* same algorithm for float regs as fixed regs */
224
    for (i = 0; i < wfloatno; ++i)
254
    for (i = 0; i < wfloatno; ++i)
225
    {
255
    {
226
      if (i == 0)
256
      if (i == 0)
Line 256... Line 286...
256
 
286
 
257
  res.float_break = bk;
287
  res.float_break = bk;
258
  return res;
288
  return res;
259
}
289
}
260
 
290
 
261
weights mult_weights PROTO_N ((m,ws)) PROTO_T (double m X weights * ws)
291
weights mult_weights(double m, weights * ws)
262
{
292
{
263
  /*
293
  /*
264
   * multiply weights by scalar - non overflowing
294
   * multiply weights by scalar - non overflowing
265
   */
295
   */
266
  weights res;
296
  weights res;
267
  float *r = &(res.fix)[0];
297
  float *r = & (res.fix)[0];
268
  float *w = ws->fix;
298
  float *w = ws->fix;
269
  long i;
299
  long i;
270
 
300
 
271
  for (i = 0; i < wfixno; ++i)
301
  for (i = 0; i < wfixno; ++i)
272
  {
302
  {
273
    r[i] = w[i] * m;
303
    r[i] = w[i]* m;
274
  }
304
  }
275
 
305
 
276
  r = &(res.floating)[0];
306
  r = & (res.floating)[0];
277
  w = ws->floating;
307
  w = ws->floating;
278
  for (i = 0; i < wfloatno; ++i)
308
  for (i = 0; i < wfloatno; ++i)
279
  {
309
  {
280
    r[i] = w[i] * m;
310
    r[i] = w[i]* m;
281
  }
311
  }
282
  return (res);
312
  return(res);
283
}
313
}
284
 
314
 
285
weights add_wlist PROTO_N ((scale,re)) PROTO_T (double scale X exp re)
315
weights add_wlist(double scale, exp re)
286
{				/* sum of  weights of list re */
316
{				/* sum of  weights of list re */
287
  weights w, w1;
317
  weights w, w1;
288
  exp r = re;
318
  exp r = re;
289
 
319
 
290
  if (r == nilexp)
320
  if (r == nilexp)
291
  {
321
  {
292
    return zeroweights;
322
    return zeroweights;
293
  }
323
  }
294
  else if (last(r))
324
  else if (last(r))
295
  {
325
  {
296
    return (weightsv(scale, r));
326
    return(weightsv(scale, r));
297
  }
327
  }
298
  else
328
  else
299
  {
329
  {
300
    w = weightsv(scale, r);
330
    w = weightsv(scale, r);
301
    do
331
    do
Line 319... Line 349...
319
inside 'for' loops for example. The procedure reg_alloc in reg_alloc.c
349
inside 'for' loops for example. The procedure reg_alloc in reg_alloc.c
320
finally determines the actual choice of s reg and recodes the number
350
finally determines the actual choice of s reg and recodes the number
321
field of an ident.
351
field of an ident.
322
 
352
 
323
******************************************************************/
353
******************************************************************/
324
weights weightsv PROTO_N ((scale,e)) PROTO_T (double scale X exp e)
354
weights weightsv(double scale, exp e)
325
{
355
{
326
 
356
 
327
tailrecurse:
357
tailrecurse:
328
 
358
 
329
  switch (name(e))
359
  switch (name(e))
Line 344... Line 374...
344
      return zeroweights;
374
      return zeroweights;
345
    }
375
    }
346
 
376
 
347
  case ident_tag:
377
  case ident_tag:
348
    {
378
    {
349
      if (son(e) != nilexp)
379
      if (son(e)!= nilexp)
350
      {
380
      {
351
	weights wdef;
381
	weights wdef;
352
	bool wdef_set;
382
	bool wdef_set;
353
	weights wbody;
383
	weights wbody;
354
	long noe = no(e) /* set by scan */ ;
384
	long noe = no(e) /* set by scan */ ;
Line 392... Line 422...
392
	  if (name(t) == val_tag || name(t) == real_tag)
422
	  if (name(t) == val_tag || name(t) == real_tag)
393
	  {
423
	  {
394
	    return wbody;
424
	    return wbody;
395
	  }
425
	  }
396
 
426
 
397
	  while (name(t) != name_tag)
427
	  while (name(t)!= name_tag)
398
	  {
428
	  {
399
	    t = son(t);
429
	    t = son(t);
400
	  }
430
	  }
401
 
431
 
402
	  s = son(t);
432
	  s = son(t);
Line 486... Line 516...
486
      return zeroweights;
516
      return zeroweights;
487
    }
517
    }
488
 
518
 
489
  case ncopies_tag:
519
  case ncopies_tag:
490
    {
520
    {
491
      scale = no(e) * scale;
521
      scale = no(e)* scale;
492
      e = son(e);
522
      e = son(e);
493
      goto tailrecurse;
523
      goto tailrecurse;
494
    }
524
    }
495
 
525
 
496
 
526
 
Line 505... Line 535...
505
      if (last(son(e)))
535
      if (last(son(e)))
506
      {
536
      {
507
	e = son(e);
537
	e = son(e);
508
	goto tailrecurse;
538
	goto tailrecurse;
509
      }
539
      }
510
      return (add_wlist(scale, son(e)));
540
      return(add_wlist(scale, son(e)));
511
    }
541
    }
512
  }
542
  }
513
}
543
}