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
$Log: is_worth.c,v $
33
 * Revision 1.1.1.1  1998/01/17  15:56:02  release
34
 * First version to be checked into rolling release.
35
 *
36
 * Revision 1.2  1995/12/18  13:11:42  wfs
37
 * Put hppatrans uder cvs control. Major Changes made since last release
38
 * include:
39
 * (i) PIC code generation.
40
 * (ii) Profiling.
41
 * (iii) Dynamic Initialization.
42
 * (iv) Debugging of Exception Handling and Diagnostics.
43
 *
44
 * Revision 5.0  1995/08/25  13:42:58  wfs
45
 * Preperation for August 25 Glue release
46
 *
47
 * Revision 3.4  1995/08/25  13:33:36  wfs
48
 * *** empty log message ***
49
 *
50
 * Revision 3.4  1995/08/25  13:33:36  wfs
51
 * *** empty log message ***
52
 *
53
 * Revision 3.1  95/04/10  16:26:58  16:26:58  wfs (William Simmonds)
54
 * Apr95 tape version.
55
 * 
56
 * Revision 3.0  95/03/30  11:17:55  11:17:55  wfs (William Simmonds)
57
 * Mar95 tape version with CRCR95_178 bug fix.
58
 * 
59
 * Revision 2.0  95/03/15  15:27:42  15:27:42  wfs (William Simmonds)
60
 * spec 3.1 changes implemented, tests outstanding.
61
 * 
62
 * Revision 1.2  95/01/17  17:25:20  17:25:20  wfs (William Simmonds)
63
 * Changed name of an included header file
64
 * 
65
 * Revision 1.1  95/01/11  13:10:17  13:10:17  wfs (William Simmonds)
66
 * Initial revision
67
 * 
68
*/
69
 
70
 
71
#define HPPATRANS_CODE
72
#include "config.h"
73
#include "common_types.h"
74
#include "tags.h"
75
#include "expmacs.h"
76
#include "exp.h"
77
#include "shapemacs.h"
78
#include "hppains.h"
79
#include "is_worth.h"
80
 
81
/*
82
    BOOLEAN VALUES
83
*/
84
 
85
#define true 1
86
#define false 0
87
 
88
 
89
/*
90
    IS THE EXPRESSION c WORTH EXTRACTING FROM A LOOP?
91
 
92
    This is called from mc_list.
93
*/
94
 
95
int is_worth
96
    PROTO_N ( ( c ) )
97
    PROTO_T ( exp c )
98
{
99
    unsigned char cnam = name ( c ) ;
100
    bool isflt = ( bool ) is_floating ( name ( sh ( c ) ) ) ;
101
 
102
    if ( name ( sh ( c ) ) == ptrhd && al1 ( sh ( c ) ) == 1 ) {
103
	/* Pointers to bits aren't */
104
	return ( false ) ;
105
    }
106
 
107
#if 0
108
    if (cnam==name_tag && name(father(c))==addptr_tag && isglob(son(c)))
109
       return(true);
110
#endif
111
 
112
    if ( cnam == real_tag ) {
113
	/* Real constants are */
114
	return ( true ) ;
115
    }
116
 
117
    if ( cnam == goto_tag ) {
118
	/* Extracting gotos messes things up */
119
	return ( false ) ;
120
    }
121
 
122
    if ( cnam == cont_tag ) {
123
	exp s = son ( c ) ;
124
	if ( isflt && ( name ( s ) != name_tag || isglob ( son ( s ) ) ) ) {
125
	    return ( true ) ;
126
	}
127
	if ( name ( s ) == reff_tag && no ( s ) == 0 ) s = son ( s ) ;
128
	if ( name ( s ) == name_tag && isglob ( son ( s ) ) ) {
129
	    return ( true ) ;
130
	}
131
	if ( name ( s ) == cont_tag ) {
132
	   exp ss = son ( s ) ;
133
	   if ( name ( ss ) == reff_tag && no ( ss ) == 0 ) ss = son ( ss ) ;
134
	   if ( name ( ss ) == name_tag ) return ( true ) ;
135
	}
136
	return ( false ) ;
137
    }
138
 
139
#if 0
140
    if ( name ( sh ( c ) ) == ptrhd && isglob(son(c)) ) {
141
	return ( true ) ;
142
    }
143
#endif
144
 
145
    if ( cnam == val_tag ) {
146
	/* It is sometimes worth extracting large integer constants */
147
	exp dad ;
148
	long n = no ( c ) ;
149
	if ( n==0  )
150
	   return (false) ;
151
	if ( shape_size(sh(c))==64 )
152
	   return (false) ; /* Cannot put 64 bit integers in registers! */
153
	dad = father ( c ) ;
154
	if (dad==nilexp)
155
	{
156
	   if (SIMM13(n)) return (false);
157
	   return (true);
158
	}
159
 
160
	switch ( name ( dad ) ) {
161
 
162
	    case and_tag : {
163
		exp grandad = father ( dad ) ;
164
		if ( (name ( grandad ) == test_tag && ( n & ( n - 1 ) ) == 0
165
		     && ( props ( grandad ) == 5 || props ( grandad ) == 6 )
166
		     && ( name ( bro ( son ( grandad ) ) ) == val_tag
167
		     && no ( bro ( son ( grandad ) ) ) == 0 ))
168
		     || ( name ( son ( grandad ) ) == val_tag
169
		     && no ( son ( grandad ) ) == 0 ) ) {
170
			/* a & 2^n == 0 is transformed into a shift */
171
			return ( false ) ;
172
		}
173
		/* FALL THROUGH */
174
		if (((n+1)&n) ==0)
175
		   return false;
176
 
177
	    }
178
 
179
	    case or_tag :
180
	    case xor_tag :
181
	    case test_tag : {
182
		/* Large or negative constants are worth extracting */
183
		return ( ( bool ) ( n<0 || !SIMM5( n ) ) ) ;
184
	    }
185
 
186
	    case mult_tag :
187
	    case offset_mult_tag : {
188
#if 0
189
		/* Is this necessarily true? */
190
		if ( SIMM13( n ) ) return ( false ) ;
191
		return ( ( bool ) ( ( n & ( n - 1 ) ) != 0 &&
192
				    ( n & ( n + 1 ) ) != 0 &&
193
				    ( ( n - 1 ) & ( n - 2 ) ) != 0 ) ) ;
194
#endif
195
		return ( false ) ;
196
	    }
197
 
198
	    case div1_tag :
199
	    case div2_tag :
200
	    case rem2_tag : {
201
#if 0
202
		/* Is this necessarily true? */
203
		if ( SIMM13( n ) ) return ( false ) ;
204
#endif
205
		return ( ( bool ) ( ( n & ( n - 1 ) ) != 0 ) ) ; /* LINT */
206
	    }
207
 
208
	    default : {
209
		/* Extract large constants */
210
		if ( SIMM13( n ) ) return ( false ) ;
211
		return ( true ) ;
212
	    }
213
	}
214
    }
215
 
216
    if ( is_o ( cnam ) || cnam == clear_tag ) return ( false ) ;
217
    return ( true ) ;
218
}
219