Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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