Subversion Repositories tendra.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
 
33
/*
34
			    VERSION INFORMATION
35
			    ===================
36
 
37
--------------------------------------------------------------------------
38
$Header: /u/g/release/CVSROOT/Source/src/installers/sparc/common/tempdecs.c,v 1.1.1.1 1998/01/17 15:55:55 release Exp $
39
--------------------------------------------------------------------------
40
$Log: tempdecs.c,v $
41
 * Revision 1.1.1.1  1998/01/17  15:55:55  release
42
 * First version to be checked into rolling release.
43
 *
44
 * Revision 1.5  1997/02/18  11:48:33  pwe
45
 * NEWDIAGS for debugging optimised code
46
 *
47
 * Revision 1.4  1995/10/27  10:52:20  john
48
 * Fix to general procs
49
 *
50
 * Revision 1.3  1995/09/29  09:23:20  john
51
 * Fixed APPLYLIKE
52
 *
53
 * Revision 1.2  1995/05/26  13:02:10  john
54
 * Reformatting
55
 *
56
 * Revision 1.1.1.1  1995/03/13  10:18:59  john
57
 * Entered into CVS
58
 *
59
 * Revision 1.3  1994/12/01  13:24:05  djch
60
 * Break id scan on env_offset_tag as well as name_tag
61
 * Add goto_lv and long_jump to set of transfer operations
62
 *
63
 * Revision 1.2  1994/07/07  16:11:33  djch
64
 * Jul94 tape
65
 *
66
 * Revision 1.1  1994/05/03  14:50:00  djch
67
 * Initial revision
68
 *
69
 * Revision 1.4  93/08/27  11:39:39  11:39:39  ra (Robert Andrews)
70
 * A couple of lint-like changes.  Use of pset etc to set properties.
71
 * 
72
 * Revision 1.3  93/08/13  14:48:00  14:48:00  ra (Robert Andrews)
73
 * Reformatted.
74
 * 
75
 * Revision 1.2  93/06/29  14:36:10  14:36:10  ra (Robert Andrews)
76
 * Have to include muldvrem.h.
77
 * 
78
 * Revision 1.1  93/06/24  14:59:33  14:59:33  ra (Robert Andrews)
79
 * Initial revision
80
 * 
81
--------------------------------------------------------------------------
82
*/
83
 
84
 
85
#define SPARCTRANS_CODE
86
#include "config.h"
87
#include "tags.h"
88
#include "common_types.h"
89
#include "exp.h"
90
#include "const.h"
91
#include "expmacs.h"
92
#include "bitsmacs.h"
93
#include "muldvrem.h"
94
#include "tempdecs.h"
95
 
96
 
97
/*
98
  IS THE EXPRESSION e A PROCEDURE APPLICATION?
99
*/
100
 
101
#define APPLYLIKE( e ) ( name ( e ) == apply_tag || \
102
			 name ( e ) == apply_general_tag || \
103
			 is_muldivrem_call ( e ) )
104
 
105
 
106
/*
107
  FLAG : APPLY TEMPDEF OPTIMISATION?
108
*/
109
 
110
bool tempdecopt ;
111
 
112
 
113
/*
114
  VARIABLES SET BY TRACE_USES
115
*/	
116
 
117
static int nouses ;
118
static bool useinpar ;
119
 
120
 
121
/*
122
  TRACE USES OF AN IDENTITY
123
  Reduces nouses for each non-assignment use of id encountered in e,
124
  sets useinpar if use in actual parameter (or function) position,
125
  terminates with 0 on applications or jumps, terminates with 2 on
126
  assignment to id, otherwise delivers 1.
127
*/
128
 
129
int trace_uses 
130
    PROTO_N ( ( e, id ) )
131
    PROTO_T ( exp e X exp id ){
132
  if ( APPLYLIKE ( e ) ) {
133
    int u = nouses ;
134
    int p = 1 ;
135
    exp l = son ( e ) ;
136
    while ( p == 1 ) {
137
      p = trace_uses ( l, id ) ;
138
      if ( u != nouses || p == 2 ) useinpar = 1 ;
139
      if ( p == 0 ) nouses = u ;
140
      if ( last ( l ) ) break ;
141
      l = bro ( l ) ;
142
    }
143
    return ( 0 ) ;
144
  }
145
  switch ( name ( e ) ) {
146
  case env_offset_tag :
147
  case name_tag : {
148
    nouses -= ( son ( e ) == id ? 1 : 0 ) ;
149
    return ( 1 ) ;
150
  }
151
  case ident_tag : {
152
    exp f = son ( e ) ;
153
    exp s = bro ( f ) ;
154
    int a ;
155
    if ( ( props ( e ) & defer_bit ) != 0 ) {
156
      exp t = f ;
157
      f = s ;
158
      s = t ;
159
    }
160
    a = trace_uses ( f, id ) ;
161
    if ( a != 1 ) return ( a ) ;
162
    return ( trace_uses ( s, id ) ) ;
163
  }
164
  case case_tag : {
165
    ( void ) trace_uses ( son ( e ), id ) ;
166
    return ( 0 ) ;
167
  }
168
  case current_env_tag :
169
  case labst_tag : {
170
    return ( 0 ) ;
171
  }
172
  case seq_tag : {
173
    exp s = son ( son ( e ) ) ;
174
    for ( ; ; ) {
175
      int el = trace_uses ( s, id ) ;
176
      if ( el != 1 ) return ( el ) ;
177
      if ( last ( s ) ) {
178
	return ( trace_uses ( bro ( son ( e ) ), id ) ) ;
179
      }
180
      s = bro ( s ) ;
181
    }
182
    /* NOT REACHED */
183
  }
184
  case ass_tag : {
185
    if ( isvar ( id ) && name ( son ( e ) ) == name_tag &&
186
	 son ( son ( e ) ) == id ) {
187
      ( void ) trace_uses ( bro ( son ( e ) ), id ) ;
188
      return ( 2 ) ;
189
    } else if ( APPLYLIKE ( bro ( son ( e ) ) ) ) {
190
      return ( trace_uses ( bro ( son ( e ) ), id ) ) ;
191
    }
192
    /* FALL THROUGH */
193
  }
194
  default : {
195
    exp s = son ( e ) ;
196
    int nu = nouses ;	 /* s list can be done in any order ... */
197
    if ( s == nilexp ) return ( 1 ) ;
198
    for ( ; ; ) {
199
      int el = trace_uses ( s, id ) ;
200
      if ( el != 1 ) {
201
	/* ... so reset nouses if any terminate */
202
	nouses = nu ;
203
	return el ;
204
      }
205
      if ( last ( s ) ) return ( 1 ) ;
206
      s = bro ( s ) ;
207
    }
208
    /* NOT REACHED */
209
  }
210
  }
211
    /* NOT REACHED */
212
}
213
 
214
 
215
/*
216
  APPLY TRACE_USES TO DYNAMIC SUCCESSORS OF a
217
*/
218
 
219
void after_a 
220
    PROTO_N ( ( a, id ) )
221
    PROTO_T ( exp a X exp id ){
222
  unsigned char n ;
223
  exp dad ;
224
  exp l ;
225
  tailrec : {
226
    dad = father ( a ) ;
227
    n = name ( dad ) ;
228
    if ( nouses == 0 ) return ;
229
    if ( n == cond_tag || n == rep_tag || n == solve_tag ||
230
	 n == labst_tag || n == case_tag || n == goto_tag ||
231
	 n == goto_lv_tag || n == long_jump_tag || /* new ones */
232
	 n == test_tag || APPLYLIKE ( dad ) ) {
233
      /* Don't try too hard! */
234
      while ( APPLYLIKE ( dad ) && dad != id ) dad = father ( dad ) ;
235
      if ( APPLYLIKE ( dad ) ) {
236
	useinpar = 1 ;
237
      }
238
      return ;
239
    }
240
    for ( l = a ; !last ( l ) ; l = bro ( l ) ){
241
      int u = trace_uses ( bro ( l ), id ) ;
242
      if ( u != 1 || nouses == 0 ) return ;
243
    }
244
    a = dad ;
245
  }
246
  if ( dad != id ) goto tailrec ;
247
  return ;
248
}	
249
 
250
 
251
/*
252
  CHECK SIMPLE SEQUENCES
253
*/
254
 
255
bool simple_seq 
256
    PROTO_N ( ( e, id ) )
257
    PROTO_T ( exp e X exp id ){
258
  exp dad = father ( e ) ;
259
  for ( ; ; ) {
260
    if ( dad == id ) return ( 1 ) ;
261
    if ( name ( dad ) == seq_tag || name ( dad ) == 0 ||
262
	 name ( dad ) == ident_tag ) {
263
      dad = father ( dad ) ;
264
    } 
265
    else {
266
      return ( 0 ) ;
267
    }
268
  }
269
    /* NOT REACHED */
270
}
271
 
272
 
273
/*
274
  CAN e BE ALLOCATED INTO A T-REGISTER?
275
  e contains a local declaration.  enoughs is true to indicate that
276
  there are t-registers available.  The routine delivers 1 if e can
277
  be allocated into a t-register or parameter register.
278
*/
279
 
280
bool tempdec 
281
    PROTO_N ( ( e, enoughs ) )
282
    PROTO_T ( exp e X bool enoughs ){
283
  exp p ;
284
  if ( !tempdecopt ) return ( 0 ) ;
285
  nouses = 0 ;
286
  useinpar = 0 ;
287
  if ( isvar ( e ) ) {
288
    for ( p = pt ( e ) ; p != nilexp ; p = pt ( p ) ) {
289
      /* find no of uses which are not assignments to id ... */
290
#ifdef NEWDIAGS
291
      if (isdiaginfo(p))
292
	continue ;
293
#endif
294
      if ( !last ( p ) && last ( bro ( p ) ) &&
295
	   name ( bro ( bro ( p ) ) ) == ass_tag ) {
296
	if ( !simple_seq ( bro ( bro ( p ) ), e ) ) return  ( 0 ) ;
297
	/* ... in simple sequence */
298
	continue ;
299
      }
300
      nouses++ ;
301
    }
302
  } 
303
  else {
304
    nouses = no ( e ) ;
305
  }
306
  /* trace simple successors to assignmnets or initialisations to 
307
     id to find if all uses occur before unpredictable change of 
308
     control (or another assignment to id ) */
309
 
310
  if ( name ( son ( e ) ) != clear_tag || isparam ( e ) ) {
311
    after_a ( son ( e ), e ) ;
312
  }
313
  if ( isvar ( e ) ) {
314
    for ( p = pt ( e ) ; p != nilexp ; p = pt ( p ) ) {
315
#ifdef NEWDIAGS
316
      if (isdiaginfo(p))
317
	continue ;
318
#endif
319
      if ( !last ( p ) && last ( bro ( p ) ) &&
320
	   name ( bro ( bro ( p ) ) ) == ass_tag ) {
321
	after_a ( bro ( bro ( p ) ), e ) ;
322
      }
323
    }
324
  }
325
  if ( nouses == 0 && ( enoughs || !useinpar ) ) {
326
#if 0
327
    /* temporary circumvention */
328
    if ( useinpar ) return ( 0 ) ;
329
#else
330
    /* don't allocate this into a parameter register */
331
    if ( useinpar ){
332
      return 0;
333
      pset ( e, notparreg ) ;
334
    }
335
#endif
336
    return ( 1 ) ;
337
  }
338
  return ( 0 ) ;
339
}
340
 
341
 
342
 
343
 
344
 
345