Subversion Repositories tendra.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1996
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
			    VERSION INFORMATION
31
			    ===================
32
 
33
--------------------------------------------------------------------------
34
$Header: /u/g/release/CVSROOT/Source/src/installers/680x0/common/inliner.c,v 1.1.1.1 1998/01/17 15:55:49 release Exp $
35
--------------------------------------------------------------------------
36
$Log: inliner.c,v $
37
 * Revision 1.1.1.1  1998/01/17  15:55:49  release
38
 * First version to be checked into rolling release.
39
 *
40
Revision 1.1.1.1  1997/10/13 12:42:53  ma
41
First version.
42
 
43
Revision 1.1.1.1  1997/03/14 07:50:13  ma
44
Imported from DRA
45
 
46
 * Revision 1.2  1996/09/20  13:51:35  john
47
 * *** empty log message ***
48
 *
49
 * Revision 1.1.1.1  1996/09/20  10:56:54  john
50
 *
51
 * Revision 1.1.1.1  1996/03/26  15:45:12  john
52
 *
53
 * Revision 1.1  94/06/29  14:22:10  14:22:10  ra (Robert Andrews)
54
 * Initial revision
55
 *
56
--------------------------------------------------------------------------
57
*/
58
 
59
 
60
#include "config.h"
61
#include "common_types.h"
62
#include "installglob.h"
63
#include "exp.h"
64
#include "expmacs.h"
65
#include "tags.h"
66
#include "flags.h"
67
#include "shapemacs.h"
68
#include "inl_norm.h"
69
static int complexity PROTO_S ( ( exp e, int count, int newdecs ) ) ;
70
 
71
 
72
/*
73
    PARAMETERS
74
*/
75
 
76
#define crit_inline	50
77
#define decs_allowed	4
78
#define decs_with_apply	0
79
 
80
 
81
/*
82
    APPLY COMPLEXITY TO THE EXP e
83
*/
84
 
85
static int sbl
86
    PROTO_N ( ( e, count, newdecs ) )
87
    PROTO_T ( exp e X int count X int newdecs )
88
{
89
    int c = complexity ( e, count, newdecs ) ;
90
    if ( c < 0 ) return ( c ) ;
91
    if ( last ( e ) ) return ( c ) ;
92
    return ( sbl ( bro ( e ), c, newdecs ) ) ;
93
}
94
 
95
 
96
/*
97
    FIND COMPLEXITY OF THE EXP e
98
*/
99
 
100
static int complexity
101
    PROTO_N ( ( e, count, newdecs ) )
102
    PROTO_T ( exp e X int count X int newdecs )
103
{
104
    unsigned char n = name ( e ) ;
105
    if ( count < 0 || newdecs >= decs_allowed ) return ( -1 ) ;
106
    if ( son ( e ) == nilexp ) return ( count ) ;
107
 
108
    switch ( n ) {
109
 
110
	case apply_tag : {
111
	    if ( newdecs > decs_with_apply ) return ( -1 ) ;
112
	    return ( sbl ( son ( e ), count - 1, newdecs ) ) ;
113
	}
114
 
115
	case res_tag : {
116
	    return ( complexity ( son ( e ), count - 1, newdecs ) ) ;
117
	}
118
 
119
	case ident_tag : {
120
	    if ( isloadparam ( son ( e ) ) ) {
121
		return ( sbl ( son ( e ), count - 1, newdecs ) ) ;
122
	    } else {
123
		return ( sbl ( son ( e ), count - 1, newdecs + 1 ) ) ;
124
	    }
125
	}
126
 
127
	case top_tag :
128
	case clear_tag :
129
	case prof_tag : {
130
	    return ( count ) ;
131
	}
132
 
133
	case case_tag : {
134
	    return ( complexity ( son ( e ), count - 1, newdecs ) ) ;
135
	}
136
 
137
	case name_tag :
138
	case string_tag :
139
	case env_offset_tag : {
140
	    return ( count - 1 ) ;
141
	}
142
 
143
	case labst_tag : {
144
	    return ( complexity ( bro ( son ( e ) ), count, newdecs ) ) ;
145
	}
146
 
147
	case solve_tag :
148
	case seq_tag : {
149
	    return ( sbl ( son ( e ), count, newdecs ) ) ;
150
	}
151
 
152
	default : {
153
	    return ( sbl ( son ( e ), count - 1, newdecs ) ) ;
154
	}
155
    }
156
}
157
 
158
 
159
/*
160
    FIND INLINING OPTIONS
161
 
162
    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.
164
*/
165
 
166
int inlinechoice
167
    PROTO_N ( ( t, def, total_uses ) )
168
    PROTO_T ( exp t X exp def X int total_uses )
169
{
170
    exp apars ;
171
    exp fpars ;
172
    int newdecs = 0 ;
173
    UNUSED ( total_uses ) ;
174
 
175
    /* only uses are applications */
176
    apars = bro ( t ) ;
177
    fpars = son ( def ) ;
178
    for ( ; ; ) {
179
	if ( name ( fpars ) != ident_tag || !isparam ( fpars ) ) {
180
	    if ( name ( apars ) != top_tag ) newdecs = 10 ;
181
	    break ;
182
	}
183
 
184
	switch ( name ( apars ) ) {
185
	    case val_tag :
186
	    case real_tag :
187
	    case string_tag :
188
	    case name_tag : {
189
		break ;
190
	    }
191
	    case cont_tag : {
192
		if ( name ( son ( apars ) ) == name_tag &&
193
		     isvar ( son ( son ( apars ) ) ) &&
194
		     !isvar ( fpars ) ) break ;
195
		/* ... else continue */
196
	    }
197
	    default : {
198
		newdecs++ ;
199
	    }
200
	}
201
 
202
	fpars = bro ( son ( fpars ) ) ;
203
	if ( last ( apars ) ) break ;
204
	apars = bro ( apars ) ;
205
    }
206
 
207
    /* newdecs is now the number of declarations (which will not be
208
       optimised out) arising from actual parameters */
209
#if is80x86
210
    if ( !last ( bro ( t ) ) ) return ( 0 ) ;
211
#endif
212
 
213
    if ( complexity ( fpars, crit_inline, newdecs ) >= 0 ) {
214
	return ( 2 ) ;
215
    } else if ( newdecs == 0 ) {
216
	return ( 0 ) ;
217
    }
218
    return ( 1 ) ;
219
}