Subversion Repositories tendra.SVN

Rev

Rev 2 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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