2 |
7u83 |
1 |
/*
|
6 |
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) 1997
|
|
|
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 |
|
|
|
61 |
/**********************************************************************
|
|
|
62 |
$Author: release $
|
|
|
63 |
$Date: 1998/01/17 15:56:05 $
|
|
|
64 |
$Revision: 1.1.1.1 $
|
|
|
65 |
$Log: inlinechoice.c,v $
|
|
|
66 |
* Revision 1.1.1.1 1998/01/17 15:56:05 release
|
|
|
67 |
* First version to be checked into rolling release.
|
|
|
68 |
*
|
|
|
69 |
* Revision 1.1 1995/04/13 09:08:06 currie
|
|
|
70 |
* Initial revision
|
|
|
71 |
*
|
|
|
72 |
***********************************************************************/
|
|
|
73 |
|
|
|
74 |
|
|
|
75 |
#include "config.h"
|
|
|
76 |
#include "common_types.h"
|
|
|
77 |
#include "installglob.h"
|
|
|
78 |
#include "exp.h"
|
|
|
79 |
#include "expmacs.h"
|
|
|
80 |
#include "tags.h"
|
|
|
81 |
#include "flags.h"
|
|
|
82 |
#include "shapemacs.h"
|
|
|
83 |
#include "inl_norm.h"
|
|
|
84 |
|
|
|
85 |
|
|
|
86 |
#define crit_inline 50
|
|
|
87 |
#define decs_allowed 4
|
|
|
88 |
#define decs_with_apply 0
|
|
|
89 |
|
6 |
7u83 |
90 |
static int complexity(exp e, int count, int newdecs);
|
2 |
7u83 |
91 |
|
|
|
92 |
/* applies complexity to the members of a list */
|
|
|
93 |
static int sbl
|
6 |
7u83 |
94 |
(exp e, int count, int newdecs)
|
2 |
7u83 |
95 |
{
|
6 |
7u83 |
96 |
int c = complexity(e, count,newdecs);
|
2 |
7u83 |
97 |
if (c < 0)
|
6 |
7u83 |
98 |
return(c);
|
|
|
99 |
if (last(e))
|
|
|
100 |
return(c);
|
|
|
101 |
return(sbl(bro(e), c, newdecs));
|
2 |
7u83 |
102 |
}
|
|
|
103 |
|
|
|
104 |
static int complexity
|
6 |
7u83 |
105 |
(exp e, int count, int newdecs)
|
2 |
7u83 |
106 |
{
|
6 |
7u83 |
107 |
unsigned char n = name(e);
|
2 |
7u83 |
108 |
if (count < 0 || newdecs >= decs_allowed)
|
6 |
7u83 |
109 |
return(-1);
|
2 |
7u83 |
110 |
if (son(e) == nilexp) return count;
|
|
|
111 |
switch (n) {
|
|
|
112 |
case apply_tag: {
|
|
|
113 |
if (newdecs > decs_with_apply)
|
|
|
114 |
return -1;
|
|
|
115 |
return(sbl(son(e), count-1, newdecs));
|
|
|
116 |
}
|
|
|
117 |
case res_tag: return complexity(son(e), count-1, newdecs);
|
|
|
118 |
case ident_tag:
|
|
|
119 |
if (isloadparam(son(e)))
|
|
|
120 |
return sbl(son(e), count-1, newdecs);
|
|
|
121 |
else
|
|
|
122 |
return sbl(son(e), count-1, newdecs+1);
|
|
|
123 |
case top_tag: case clear_tag: case prof_tag: return count;
|
6 |
7u83 |
124 |
case case_tag: return(complexity(son(e), count - 1, newdecs));
|
2 |
7u83 |
125 |
case name_tag: case string_tag: case env_offset_tag:
|
|
|
126 |
case general_env_offset_tag:
|
6 |
7u83 |
127 |
return(count - 1);
|
|
|
128 |
case labst_tag: return(complexity(bro(son(e)), count,
|
2 |
7u83 |
129 |
newdecs));
|
|
|
130 |
case solve_tag: case seq_tag: return sbl(son(e), count, newdecs);
|
6 |
7u83 |
131 |
default: return(sbl(son(e), count - 1, newdecs));
|
2 |
7u83 |
132 |
}
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
int inlinechoice
|
6 |
7u83 |
136 |
(exp t, exp def, int total)
|
2 |
7u83 |
137 |
{
|
|
|
138 |
/* delivers 0 if no uses of this proc can be inlined.
|
|
|
139 |
delivers 1 if this use cannot be inlined
|
|
|
140 |
delivers 2 if this use can be inlined.
|
|
|
141 |
*/
|
|
|
142 |
exp apars;
|
|
|
143 |
exp fpars;
|
|
|
144 |
int newdecs = 0;
|
|
|
145 |
shape shdef = pt(def) /* Oh, yes it is! */;
|
|
|
146 |
UNUSED(total);
|
|
|
147 |
|
6 |
7u83 |
148 |
if (!eq_shape(sh(father(t)), shdef)) {
|
2 |
7u83 |
149 |
/* shape required by application is different from definition */
|
|
|
150 |
return 1;
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
apars = t; /* only uses are applications */
|
|
|
154 |
fpars = son(def);
|
|
|
155 |
|
6 |
7u83 |
156 |
for (;;) {
|
2 |
7u83 |
157 |
if (name(fpars)!=ident_tag || !isparam(fpars)) {
|
|
|
158 |
if (!last(apars)) return 1;
|
|
|
159 |
break;
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
if (last(apars)) return 1;
|
|
|
163 |
apars = bro(apars);
|
|
|
164 |
|
|
|
165 |
switch (name(apars)) {
|
|
|
166 |
case val_tag: case real_tag: case string_tag: case name_tag:
|
|
|
167 |
break;
|
|
|
168 |
case cont_tag: {
|
6 |
7u83 |
169 |
if (name(son(apars)) ==name_tag && isvar(son(son(apars))) &&
|
|
|
170 |
!isvar(fpars))break;
|
2 |
7u83 |
171 |
} /* ... else continue */
|
|
|
172 |
default: newdecs++;
|
|
|
173 |
}
|
|
|
174 |
fpars = bro(son(fpars));
|
|
|
175 |
}
|
|
|
176 |
/* newdecs is now the number of declarations (which will not be
|
|
|
177 |
optimised out) arising from actual parameters */
|
|
|
178 |
|
|
|
179 |
|
|
|
180 |
|
|
|
181 |
if (complexity(fpars, crit_inline, newdecs) >= 0)
|
|
|
182 |
return 2;
|
|
|
183 |
else if (newdecs == 0)
|
|
|
184 |
return 0;
|
|
|
185 |
return 1;
|
|
|
186 |
}
|