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
/*
7 7u83 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
 */
31
/*
2 7u83 32
    		 Crown Copyright (c) 1996
33
 
34
    This TenDRA(r) Computer Program is subject to Copyright
35
    owned by the United Kingdom Secretary of State for Defence
36
    acting through the Defence Evaluation and Research Agency
37
    (DERA).  It is made available to Recipients with a
38
    royalty-free licence for its use, reproduction, transfer
39
    to other parties and amendment for any purpose not excluding
40
    product development provided that any such use et cetera
41
    shall be deemed to be acceptance of the following conditions:-
42
 
43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
45
 
46
        (2) Any amended version of it shall be clearly marked to
47
        show both the nature of and the organisation responsible
48
        for the relevant amendment or amendments;
49
 
50
        (3) Its onward transfer from a recipient to another
51
        party shall be deemed to be that party's acceptance of
52
        these conditions;
53
 
54
        (4) DERA gives no warranty or assurance as to its
55
        quality or suitability for any purpose and DERA accepts
56
        no liability whatsoever in relation to any use to which
57
        it may be put.
58
*/
59
/*
60
			    VERSION INFORMATION
61
			    ===================
62
 
63
--------------------------------------------------------------------------
64
$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 $
65
--------------------------------------------------------------------------
66
$Log: inliner.c,v $
67
 * Revision 1.1.1.1  1998/01/17  15:55:49  release
68
 * First version to be checked into rolling release.
69
 *
70
Revision 1.1.1.1  1997/10/13 12:42:53  ma
71
First version.
72
 
73
Revision 1.1.1.1  1997/03/14 07:50:13  ma
74
Imported from DRA
75
 
76
 * Revision 1.2  1996/09/20  13:51:35  john
77
 * *** empty log message ***
78
 *
79
 * Revision 1.1.1.1  1996/09/20  10:56:54  john
80
 *
81
 * Revision 1.1.1.1  1996/03/26  15:45:12  john
82
 *
83
 * Revision 1.1  94/06/29  14:22:10  14:22:10  ra (Robert Andrews)
84
 * Initial revision
85
 *
86
--------------------------------------------------------------------------
87
*/
88
 
89
 
90
#include "config.h"
91
#include "common_types.h"
92
#include "installglob.h"
93
#include "exp.h"
94
#include "expmacs.h"
95
#include "tags.h"
96
#include "flags.h"
97
#include "shapemacs.h"
98
#include "inl_norm.h"
7 7u83 99
static int complexity(exp e, int count, int newdecs);
2 7u83 100
 
101
 
102
/*
103
    PARAMETERS
104
*/
105
 
106
#define crit_inline	50
107
#define decs_allowed	4
108
#define decs_with_apply	0
109
 
110
 
111
/*
112
    APPLY COMPLEXITY TO THE EXP e
113
*/
114
 
115
static int sbl
7 7u83 116
(exp e, int count, int newdecs)
2 7u83 117
{
7 7u83 118
    int c = complexity(e, count, newdecs);
119
    if (c < 0) return(c);
120
    if (last(e)) return(c);
121
    return(sbl(bro(e), c, newdecs));
2 7u83 122
}
123
 
124
 
125
/*
126
    FIND COMPLEXITY OF THE EXP e
127
*/
128
 
129
static int complexity
7 7u83 130
(exp e, int count, int newdecs)
2 7u83 131
{
7 7u83 132
    unsigned char n = name(e);
133
    if (count < 0 || newdecs >= decs_allowed) return(-1);
134
    if (son(e) == nilexp) return(count);
2 7u83 135
 
7 7u83 136
    switch (n) {
2 7u83 137
 
7 7u83 138
	case apply_tag: {
139
	    if (newdecs > decs_with_apply) return(-1);
140
	    return(sbl(son(e), count - 1, newdecs));
2 7u83 141
	}
142
 
7 7u83 143
	case res_tag: {
144
	    return(complexity(son(e), count - 1, newdecs));
2 7u83 145
	}
146
 
7 7u83 147
	case ident_tag: {
148
	    if (isloadparam(son(e))) {
149
		return(sbl(son(e), count - 1, newdecs));
2 7u83 150
	    } else {
7 7u83 151
		return(sbl(son(e), count - 1, newdecs + 1));
2 7u83 152
	    }
153
	}
154
 
7 7u83 155
	case top_tag:
156
	case clear_tag:
157
	case prof_tag: {
158
	    return(count);
2 7u83 159
	}
160
 
7 7u83 161
	case case_tag: {
162
	    return(complexity(son(e), count - 1, newdecs));
2 7u83 163
	}
164
 
7 7u83 165
	case name_tag:
166
	case string_tag:
167
	case env_offset_tag: {
168
	    return(count - 1);
2 7u83 169
	}
170
 
7 7u83 171
	case labst_tag: {
172
	    return(complexity(bro(son(e)), count, newdecs));
2 7u83 173
	}
174
 
7 7u83 175
	case solve_tag:
176
	case seq_tag: {
177
	    return(sbl(son(e), count, newdecs));
2 7u83 178
	}
179
 
180
	default : {
7 7u83 181
	    return(sbl(son(e), count - 1, newdecs));
2 7u83 182
	}
183
    }
184
}
185
 
186
 
187
/*
188
    FIND INLINING OPTIONS
189
 
190
    This delivers 0 if no uses of the procedure can be inlined, 1 if this
191
    use cannot be inlined and 2 if this use can be inlined.
192
*/
193
 
194
int inlinechoice
7 7u83 195
(exp t, exp def, int total_uses)
2 7u83 196
{
7 7u83 197
    exp apars;
198
    exp fpars;
199
    int newdecs = 0;
200
    UNUSED(total_uses);
2 7u83 201
 
202
    /* only uses are applications */
7 7u83 203
    apars = bro(t);
204
    fpars = son(def);
205
    for (; ;) {
206
	if (name(fpars)!= ident_tag || !isparam(fpars)) {
207
	    if (name(apars)!= top_tag)newdecs = 10;
208
	    break;
2 7u83 209
	}
210
 
7 7u83 211
	switch (name(apars)) {
212
	    case val_tag:
213
	    case real_tag:
214
	    case string_tag:
215
	    case name_tag: {
216
		break;
2 7u83 217
	    }
7 7u83 218
	    case cont_tag: {
219
		if (name(son(apars)) == name_tag &&
220
		     isvar(son(son(apars))) &&
221
		     !isvar(fpars))break;
2 7u83 222
		/* ... else continue */
223
	    }
224
	    default : {
7 7u83 225
		newdecs++;
2 7u83 226
	    }
227
	}
228
 
7 7u83 229
	fpars = bro(son(fpars));
230
	if (last(apars))break;
231
	apars = bro(apars);
2 7u83 232
    }
233
 
234
    /* newdecs is now the number of declarations (which will not be
235
       optimised out) arising from actual parameters */
236
#if is80x86
7 7u83 237
    if (!last(bro(t))) return(0);
2 7u83 238
#endif
239
 
7 7u83 240
    if (complexity(fpars, crit_inline, newdecs) >= 0) {
241
	return(2);
242
    } else if (newdecs == 0) {
243
	return(0);
2 7u83 244
    }
7 7u83 245
    return(1);
2 7u83 246
}