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
    		 Crown Copyright (c) 1996
32
    		 Crown Copyright (c) 1996
3
 
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
Line 64... Line 94...
64
#include "expmacs.h"
94
#include "expmacs.h"
65
#include "tags.h"
95
#include "tags.h"
66
#include "flags.h"
96
#include "flags.h"
67
#include "shapemacs.h"
97
#include "shapemacs.h"
68
#include "inl_norm.h"
98
#include "inl_norm.h"
69
static int complexity PROTO_S ( ( exp e, int count, int newdecs ) ) ;
99
static int complexity(exp e, int count, int newdecs);
70
 
100
 
71
 
101
 
72
/*
102
/*
73
    PARAMETERS
103
    PARAMETERS
74
*/
104
*/
Line 81... Line 111...
81
/*
111
/*
82
    APPLY COMPLEXITY TO THE EXP e
112
    APPLY COMPLEXITY TO THE EXP e
83
*/
113
*/
84
 
114
 
85
static int sbl
115
static int sbl
86
    PROTO_N ( ( e, count, newdecs ) )
-
 
87
    PROTO_T ( exp e X int count X int newdecs )
116
(exp e, int count, int newdecs)
88
{
117
{
89
    int c = complexity ( e, count, newdecs ) ;
118
    int c = complexity(e, count, newdecs);
90
    if ( c < 0 ) return ( c ) ;
119
    if (c < 0) return(c);
91
    if ( last ( e ) ) return ( c ) ;
120
    if (last(e)) return(c);
92
    return ( sbl ( bro ( e ), c, newdecs ) ) ;
121
    return(sbl(bro(e), c, newdecs));
93
}
122
}
94
 
123
 
95
 
124
 
96
/*
125
/*
97
    FIND COMPLEXITY OF THE EXP e
126
    FIND COMPLEXITY OF THE EXP e
98
*/
127
*/
99
 
128
 
100
static int complexity
129
static int complexity
101
    PROTO_N ( ( e, count, newdecs ) )
-
 
102
    PROTO_T ( exp e X int count X int newdecs )
130
(exp e, int count, int newdecs)
103
{
131
{
104
    unsigned char n = name ( e ) ;
132
    unsigned char n = name(e);
105
    if ( count < 0 || newdecs >= decs_allowed ) return ( -1 ) ;
133
    if (count < 0 || newdecs >= decs_allowed) return(-1);
106
    if ( son ( e ) == nilexp ) return ( count ) ;
134
    if (son(e) == nilexp) return(count);
107
 
135
 
108
    switch ( n ) {
136
    switch (n) {
109
 
137
 
110
	case apply_tag : {
138
	case apply_tag: {
111
	    if ( newdecs > decs_with_apply ) return ( -1 ) ;
139
	    if (newdecs > decs_with_apply) return(-1);
112
	    return ( sbl ( son ( e ), count - 1, newdecs ) ) ;
140
	    return(sbl(son(e), count - 1, newdecs));
113
	}
141
	}
114
 
142
 
115
	case res_tag : {
143
	case res_tag: {
116
	    return ( complexity ( son ( e ), count - 1, newdecs ) ) ;
144
	    return(complexity(son(e), count - 1, newdecs));
117
	}
145
	}
118
 
146
 
119
	case ident_tag : {
147
	case ident_tag: {
120
	    if ( isloadparam ( son ( e ) ) ) {
148
	    if (isloadparam(son(e))) {
121
		return ( sbl ( son ( e ), count - 1, newdecs ) ) ;
149
		return(sbl(son(e), count - 1, newdecs));
122
	    } else {
150
	    } else {
123
		return ( sbl ( son ( e ), count - 1, newdecs + 1 ) ) ;
151
		return(sbl(son(e), count - 1, newdecs + 1));
124
	    }
152
	    }
125
	}
153
	}
126
 
154
 
127
	case top_tag :
155
	case top_tag:
128
	case clear_tag :
156
	case clear_tag:
129
	case prof_tag : {
157
	case prof_tag: {
130
	    return ( count ) ;
158
	    return(count);
131
	}
159
	}
132
 
160
 
133
	case case_tag : {
161
	case case_tag: {
134
	    return ( complexity ( son ( e ), count - 1, newdecs ) ) ;
162
	    return(complexity(son(e), count - 1, newdecs));
135
	}
163
	}
136
 
164
 
137
	case name_tag :
165
	case name_tag:
138
	case string_tag :
166
	case string_tag:
139
	case env_offset_tag : {
167
	case env_offset_tag: {
140
	    return ( count - 1 ) ;
168
	    return(count - 1);
141
	}
169
	}
142
 
170
 
143
	case labst_tag : {
171
	case labst_tag: {
144
	    return ( complexity ( bro ( son ( e ) ), count, newdecs ) ) ;
172
	    return(complexity(bro(son(e)), count, newdecs));
145
	}
173
	}
146
 
174
 
147
	case solve_tag :
175
	case solve_tag:
148
	case seq_tag : {
176
	case seq_tag: {
149
	    return ( sbl ( son ( e ), count, newdecs ) ) ;
177
	    return(sbl(son(e), count, newdecs));
150
	}
178
	}
151
 
179
 
152
	default : {
180
	default : {
153
	    return ( sbl ( son ( e ), count - 1, newdecs ) ) ;
181
	    return(sbl(son(e), count - 1, newdecs));
154
	}
182
	}
155
    }
183
    }
156
}
184
}
157
 
185
 
158
 
186
 
Line 162... Line 190...
162
    This delivers 0 if no uses of the procedure can be inlined, 1 if this
190
    This delivers 0 if no uses of the procedure can be inlined, 1 if this
163
    use cannot be inlined and 2 if this use can be inlined.
191
    use cannot be inlined and 2 if this use can be inlined.
164
*/
192
*/
165
 
193
 
166
int inlinechoice
194
int inlinechoice
167
    PROTO_N ( ( t, def, total_uses ) )
-
 
168
    PROTO_T ( exp t X exp def X int total_uses )
195
(exp t, exp def, int total_uses)
169
{
196
{
170
    exp apars ;
197
    exp apars;
171
    exp fpars ;
198
    exp fpars;
172
    int newdecs = 0 ;
199
    int newdecs = 0;
173
    UNUSED ( total_uses ) ;
200
    UNUSED(total_uses);
174
 
201
 
175
    /* only uses are applications */
202
    /* only uses are applications */
176
    apars = bro ( t ) ;
203
    apars = bro(t);
177
    fpars = son ( def ) ;
204
    fpars = son(def);
178
    for ( ; ; ) {
205
    for (; ;) {
179
	if ( name ( fpars ) != ident_tag || !isparam ( fpars ) ) {
206
	if (name(fpars)!= ident_tag || !isparam(fpars)) {
180
	    if ( name ( apars ) != top_tag ) newdecs = 10 ;
207
	    if (name(apars)!= top_tag)newdecs = 10;
181
	    break ;
208
	    break;
182
	}
209
	}
183
 
210
 
184
	switch ( name ( apars ) ) {
211
	switch (name(apars)) {
185
	    case val_tag :
212
	    case val_tag:
186
	    case real_tag :
213
	    case real_tag:
187
	    case string_tag :
214
	    case string_tag:
188
	    case name_tag : {
215
	    case name_tag: {
189
		break ;
216
		break;
190
	    }
217
	    }
191
	    case cont_tag : {
218
	    case cont_tag: {
192
		if ( name ( son ( apars ) ) == name_tag &&
219
		if (name(son(apars)) == name_tag &&
193
		     isvar ( son ( son ( apars ) ) ) &&
220
		     isvar(son(son(apars))) &&
194
		     !isvar ( fpars ) ) break ;
221
		     !isvar(fpars))break;
195
		/* ... else continue */
222
		/* ... else continue */
196
	    }
223
	    }
197
	    default : {
224
	    default : {
198
		newdecs++ ;
225
		newdecs++;
199
	    }
226
	    }
200
	}
227
	}
201
 
228
 
202
	fpars = bro ( son ( fpars ) ) ;
229
	fpars = bro(son(fpars));
203
	if ( last ( apars ) ) break ;
230
	if (last(apars))break;
204
	apars = bro ( apars ) ;
231
	apars = bro(apars);
205
    }
232
    }
206
 
233
 
207
    /* newdecs is now the number of declarations (which will not be
234
    /* newdecs is now the number of declarations (which will not be
208
       optimised out) arising from actual parameters */
235
       optimised out) arising from actual parameters */
209
#if is80x86
236
#if is80x86
210
    if ( !last ( bro ( t ) ) ) return ( 0 ) ;
237
    if (!last(bro(t))) return(0);
211
#endif
238
#endif
212
 
239
 
213
    if ( complexity ( fpars, crit_inline, newdecs ) >= 0 ) {
240
    if (complexity(fpars, crit_inline, newdecs) >= 0) {
214
	return ( 2 ) ;
241
	return(2);
215
    } else if ( newdecs == 0 ) {
242
    } else if (newdecs == 0) {
216
	return ( 0 ) ;
243
	return(0);
217
    }
244
    }
218
    return ( 1 ) ;
245
    return(1);
219
}
246
}