Subversion Repositories tendra.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    Copyright (c) 1993 Open Software Foundation, Inc.
3
 
4
 
5
    All Rights Reserved
6
 
7
 
8
    Permission to use, copy, modify, and distribute this software
9
    and its documentation for any purpose and without fee is hereby
10
    granted, provided that the above copyright notice appears in all
11
    copies and that both the copyright notice and this permission
12
    notice appear in supporting documentation.
13
 
14
 
15
    OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING
16
    ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17
    PARTICULAR PURPOSE.
18
 
19
 
20
    IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
21
    CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
22
    LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
23
    NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
24
    WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25
*/
26
 
27
/*
28
    		 Crown Copyright (c) 1997
29
 
30
    This TenDRA(r) Computer Program is subject to Copyright
31
    owned by the United Kingdom Secretary of State for Defence
32
    acting through the Defence Evaluation and Research Agency
33
    (DERA).  It is made available to Recipients with a
34
    royalty-free licence for its use, reproduction, transfer
35
    to other parties and amendment for any purpose not excluding
36
    product development provided that any such use et cetera
37
    shall be deemed to be acceptance of the following conditions:-
38
 
39
        (1) Its Recipients shall ensure that this Notice is
40
        reproduced upon any copies or amended versions of it;
41
 
42
        (2) Any amended version of it shall be clearly marked to
43
        show both the nature of and the organisation responsible
44
        for the relevant amendment or amendments;
45
 
46
        (3) Its onward transfer from a recipient to another
47
        party shall be deemed to be that party's acceptance of
48
        these conditions;
49
 
50
        (4) DERA gives no warranty or assurance as to its
51
        quality or suitability for any purpose and DERA accepts
52
        no liability whatsoever in relation to any use to which
53
        it may be put.
54
*/
55
 
56
 
57
 
58
/**********************************************************************
59
$Author: release $
60
$Date: 1998/02/04 15:48:52 $
61
$Revision: 1.2 $
62
$Log: is_worth.c,v $
63
 * Revision 1.2  1998/02/04  15:48:52  release
64
 * Added OSF copyright message.
65
 *
66
 * Revision 1.1.1.1  1998/01/17  15:55:57  release
67
 * First version to be checked into rolling release.
68
 *
69
 * Revision 1.2  1996/10/04  16:01:38  pwe
70
 * add banners and mod for PWE ownership
71
 *
72
**********************************************************************/
73
 
74
 
75
#include "config.h"
76
#include "common_types.h"
77
#include "tags.h"
78
#include "expmacs.h"
79
#include "exp.h"
80
#include "shapemacs.h"
81
#include "instruct.h"	/* IMM_SIZE() */
82
#include "regable.h"
83
/* construct/is_worth.h defines the interface each installer must implement */
84
#include "is_worth.h"
85
 
86
 
87
#define true 1
88
#define false 0
89
 
90
 
91
/*
92
 * Will an ident exp be in memory?
93
 * We have to guess at this stage for non globals.
94
 */
95
#define INMEMIDENT(ident_exp)	(isvis(ident_exp) || isglob(ident_exp))
96
 
97
 
98
 
99
 
100
/*
101
 * is_worth() for a complicated cont_tag.
102
 * True for any combination of reff_tag, cont_tag and name_tag.
103
 * 'c' is the son of the top cont_tag.
104
 * Allowing anything causes a bug when compiling SPECINT92 085.gcc.
105
 */
106
static bool is_worth_cont_aux PROTO_N ((c)) PROTO_T (exp c)
107
{
108
  switch(name(c))
109
  {
110
  case reff_tag:
111
    if (no(c) != 0)
112
      return 0;			/* dont optimise non-zero offset */
113
    /*FALLTHROUGH*/
114
  case cont_tag:
115
    return is_worth_cont_aux(son(c));
116
 
117
  case name_tag:
118
    return 1;
119
 
120
  default:
121
    return 0;
122
  }
123
  /*NOTREACHED*/
124
}
125
 
126
 
127
/*
128
 * Decide if expression c is worth declaring separately over a range it's
129
 * value will not change over, eg outside loop.
130
 * We have to balance the value of this against likely register pressure
131
 * impact.
132
 */
133
int is_worth PROTO_N ((c)) PROTO_T (exp c) /* used only in mc_list */
134
{				/* decide if constant c is worth declaring
135
				 * separately */
136
  int cnam = name(c);
137
  shape s = sh(c);
138
 
139
  if (!is_floating(name(s)) && !valregable(s))
140
    return false;			/* cannot go inreg, and anyway
141
					 * too big to be worthwhile */
142
 
143
  if (name(s) == ptrhd && al1(s) == 1)
144
    return false;			/* ptr bits */
145
 
146
  if (cnam == real_tag)
147
    return true;			/* real const complex to load */
148
 
149
  if (cnam == goto_tag)
150
    return false;			/* never identify a goto (causes bad labels) */
151
 
152
  if (cnam == cont_tag && name(son(c)) == name_tag)
153
  {
154
    /* a simple load, most worthwile for globals to avoid TOC access */
155
    return INMEMIDENT(son(son(c)));
156
  }
157
 
158
  if (cnam == cont_tag)
159
  {
160
    /* complex load */
161
    return is_worth_cont_aux(son(c));
162
  }
163
 
164
  if (cnam == name_tag && isglob(son(c)) && name(s) != prokhd)
165
  {
166
    /* avoid load of TOC table entry in loops, except for params where there is no load delay */
167
    return name(father(c)) != apply_tag;
168
  }
169
 
170
  if (cnam == val_tag)
171
  {
172
    /* it is sometimes worthwhile extracting big constants from loops ... */
173
    long n = no(c);
174
    exp dad = father(c);
175
 
176
    switch (name(dad))
177
    {
178
    case and_tag:	/* +++ allow for rlimn instruction */
179
    case or_tag:
180
    case xor_tag:
181
      {
182
	return !(IMMLOGL_SIZE(n) || IMMLOGU_SIZE(n));	/* short literal operands */
183
      }
184
    case mult_tag:
185
    case offset_mult_tag:
186
      {
187
	/*
188
	 * a*2^n and a*2^(n+-1) are transformed later to shifts and adds
189
	 */
190
	return (!IMM_SIZE(n) && (n & (n - 1)) != 0 && (n & (n + 1)) != 0 && ((n - 1) & (n - 2)) != 0);
191
      }
192
    case div1_tag:
193
    case div2_tag:
194
    case rem2_tag:
195
      {
196
	/* a/2^n transformed later to shift */
197
	return (!IMM_SIZE(n) && (n & (n - 1)) != 0);
198
      }
199
 
200
    case ass_tag:
201
    case assvol_tag:
202
      {
203
	/* must load all constants before store */
204
	/* +++ better way of working out inmem lhs */
205
	exp lhs = son(dad);
206
 
207
	if (name(lhs) == name_tag)
208
	{
209
	  if (INMEMIDENT(son(lhs)))
210
	    return true;		/* inmem */
211
	  else
212
	    return (!IMM_SIZE(n) && !IMMLOGU_SIZE(n));
213
					/* big const */
214
	}
215
	else
216
	{
217
	  /* complicated inmem */
218
	  return true;
219
	}
220
      }
221
 
222
    default:
223
      {
224
	return (!IMM_SIZE(n)) /* short literal operands */ ;
225
      }
226
    }				/* end sw */
227
 
228
  }
229
 
230
  if (is_o(cnam) || cnam == clear_tag)
231
  {
232
    /* simple construct */
233
    return false;
234
  }
235
 
236
  /* something complicated */
237
  return true;
238
}