Subversion Repositories tendra.SVN

Rev

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

Rev Author Line No. Line
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
    Copyright (c) 1993 Open Software Foundation, Inc.
33
 
34
 
35
    All Rights Reserved
36
 
37
 
38
    Permission to use, copy, modify, and distribute this software
39
    and its documentation for any purpose and without fee is hereby
40
    granted, provided that the above copyright notice appears in all
41
    copies and that both the copyright notice and this permission
42
    notice appear in supporting documentation.
43
 
44
 
45
    OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING
46
    ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
47
    PARTICULAR PURPOSE.
48
 
49
 
50
    IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
51
    CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
52
    LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
53
    NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
54
    WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
55
*/
56
 
57
/*
58
    		 Crown Copyright (c) 1997
6 7u83 59
 
2 7u83 60
    This TenDRA(r) Computer Program is subject to Copyright
61
    owned by the United Kingdom Secretary of State for Defence
62
    acting through the Defence Evaluation and Research Agency
63
    (DERA).  It is made available to Recipients with a
64
    royalty-free licence for its use, reproduction, transfer
65
    to other parties and amendment for any purpose not excluding
66
    product development provided that any such use et cetera
67
    shall be deemed to be acceptance of the following conditions:-
6 7u83 68
 
2 7u83 69
        (1) Its Recipients shall ensure that this Notice is
70
        reproduced upon any copies or amended versions of it;
6 7u83 71
 
2 7u83 72
        (2) Any amended version of it shall be clearly marked to
73
        show both the nature of and the organisation responsible
74
        for the relevant amendment or amendments;
6 7u83 75
 
2 7u83 76
        (3) Its onward transfer from a recipient to another
77
        party shall be deemed to be that party's acceptance of
78
        these conditions;
6 7u83 79
 
2 7u83 80
        (4) DERA gives no warranty or assurance as to its
81
        quality or suitability for any purpose and DERA accepts
82
        no liability whatsoever in relation to any use to which
83
        it may be put.
84
*/
85
 
86
 
87
 
88
/**********************************************************************
89
$Author: release $
90
$Date: 1998/02/04 15:48:50 $
91
$Revision: 1.2 $
92
$Log: inlinechoice.c,v $
93
 * Revision 1.2  1998/02/04  15:48:50  release
94
 * Added OSF copyright message.
95
 *
96
 * Revision 1.1.1.1  1998/01/17  15:55:57  release
97
 * First version to be checked into rolling release.
98
 *
99
 * Revision 1.2  1996/10/04  16:01:21  pwe
100
 * add banners and mod for PWE ownership
101
 *
102
**********************************************************************/
103
 
104
 
105
#include "config.h"
106
#include "common_types.h"
107
#include "installglob.h"
108
#include "exp.h"
109
#include "expmacs.h"
110
#include "tags.h"
111
#include "flags.h"
112
#include "shapemacs.h"
113
#include "inl_norm.h"
114
 
115
 
116
#define crit_inline 100
117
#define decs_allowed 4
118
#define decs_with_apply 0
119
 
6 7u83 120
static int  complexity(exp, int, int);
2 7u83 121
 
6 7u83 122
static int sbl(exp e, int count, int newdecs)
2 7u83 123
/* applies complexity to the members of a list */
124
{
6 7u83 125
  int  c = complexity(e, count,newdecs);
2 7u83 126
  if (c < 0)
6 7u83 127
    return(c);
128
  if (last(e))
129
    return(c);
130
  return(sbl(bro(e), c, newdecs));
2 7u83 131
}
132
 
6 7u83 133
static int complexity(exp e, int count, int newdecs)
2 7u83 134
{
6 7u83 135
  unsigned char  n = name(e);
2 7u83 136
  if (count < 0 || newdecs >= decs_allowed)
6 7u83 137
    return(-1);
2 7u83 138
  if (son(e) == nilexp) return count;
139
  switch (n) {
140
  	case apply_tag: {
141
  	   if (newdecs > decs_with_apply)
142
		 return -1;
143
  	   return(sbl(son(e), count-1, newdecs));
144
  	}
145
  	case res_tag: return complexity(son(e), count-1, newdecs);
146
        case ident_tag:
6 7u83 147
	  if (isloadparam(son(e)))
2 7u83 148
	    return sbl(son(e), count-1, newdecs);
149
	  else
150
	    return sbl(son(e), count-1, newdecs+1);
151
        case top_tag: case clear_tag: case prof_tag: return count;
6 7u83 152
	case case_tag: return(complexity(son(e), count - 1, newdecs));
2 7u83 153
	case name_tag: case string_tag: case env_offset_tag:
6 7u83 154
               return(count - 1);
155
	case labst_tag: return(complexity(bro(son(e)), count,
2 7u83 156
                        newdecs));
157
	case solve_tag: case seq_tag: return sbl(son(e), count, newdecs);
6 7u83 158
	default: return(sbl(son(e), count - 1, newdecs));
2 7u83 159
  }
160
}
161
 
6 7u83 162
int inlinechoice(exp t, exp def, int total)
2 7u83 163
	/* delivers 0 if no uses of this proc can be inlined.
164
	   delivers 1 if this use cannot be inlined
165
	   delivers 2 if this use can be inlined.
166
	*/
167
{
168
  exp apars;
169
  exp fpars;
170
  int newdecs = 0;
171
  shape shdef = pt(def);
6 7u83 172
  UNUSED(total);
173
 
174
  if (!eq_shape(sh(father(t)), shdef))
2 7u83 175
  {
176
    /* shape required by application is different from definition */
177
    return 1;
178
  }
179
  apars = t; /* only uses are applications */
180
  fpars = son(def);
6 7u83 181
 
182
  for (;;) {
2 7u83 183
     if (name(fpars)!=ident_tag || !isparam(fpars)) {
184
	if (!last(apars)) return 1;
185
      	break;
186
     }
187
 
188
     if (last(apars)) return 1;
189
     apars = bro(apars);
6 7u83 190
 
2 7u83 191
     switch (name(apars)) {
6 7u83 192
      case val_tag: case real_tag: case string_tag: case name_tag:
2 7u83 193
      	   break;
194
      case cont_tag: {
6 7u83 195
      	   if (name(son(apars)) ==name_tag && isvar(son(son(apars))) &&
196
      	        		!isvar(fpars))break;
2 7u83 197
      	   } /* ... else continue */
198
      default: newdecs++;
199
     }
200
     fpars = bro(son(fpars));
201
  }
202
        /* newdecs is now the number of declarations (which will not be
203
      	     optimised out) arising from actual parameters */
204
 
205
 
6 7u83 206
 
207
  if (complexity(fpars, crit_inline, newdecs) >= 0)
2 7u83 208
    return 2;
209
  else if (newdecs == 0)
210
    return 0;
211
  return 1;
212
}