New source tree.
[cacao.git] / src / vm / jit / inline / inline.h
1 /* jit/inline.h - code inliner
2
3    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4    R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
5    M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
6    P. Tomsich, J. Wenninger
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Dieter Thuernbeck
28
29    $Id: inline.h 1621 2004-11-30 13:06:55Z twisti $
30
31 */
32
33
34 #ifndef _INLINE_H
35 #define _INLINE_H
36
37 /* resolve typedef cycles *****************************************************/
38
39 typedef struct t_inlining_globals t_inlining_globals;
40
41
42 #include "toolbox/list.h"
43 #include "vm/global.h"
44
45
46 #define INLINING_MAXDEPTH       2  /*1*/ 
47 #define INLINING_MAXCODESIZE    128 /*32*/
48 #define INLINING_MAXMETHODS     32 /*8*/
49
50
51 /*typedef struct {
52         listnode linkage;
53         instruction *iptr;
54         } t_patchlistnode;*/
55
56
57 typedef struct {
58     listnode linkage;
59
60     methodinfo *method;
61     int startgp;
62     int stopgp;
63     int firstlocal;
64
65     bool *readonly;
66     int  *label_index;
67         
68     list *inlinedmethods;
69 } inlining_methodinfo;
70
71
72 typedef struct {
73     listnode linkage;
74         
75     /* saved static compiler variables */
76         
77     methodinfo *method;
78         
79     /* restored through method */
80
81     /* int jcodelength; */
82     /* u1 *jcode; */
83         /* classinfo *class; */
84
85     /* descriptor never used */
86     /* maxstack used outside of main for loop */
87     /* maxlocals never used */
88         
89     /* exceptiontablelength */
90     /* raw_extable used outside of main for loop */
91     /* mreturntype used outside of main for loop */
92     /* mparamcount used outside of main for loop */
93     /* mparamtypes used outside of main for loop */
94
95     /* local variables used in parse() */
96
97     int  i;                     /* temporary for different uses (counters)*/
98     int  p;                     /* java instruction counter               */
99     int  nextp;                 /* start of next java instruction         */
100     int  opcode;                /* java opcode                            */
101     u2 lineindex;
102     u2 currentline;
103     u2 linepcchange;
104     inlining_methodinfo *inlinfo;
105
106 } t_inlining_stacknode;
107
108
109 struct t_inlining_globals {  /* try in parse.h with struct not include */
110         bool isinlinedmethod;
111         int cumjcodelength;   /* cumulative immediate intruction length */
112         int cummaxstack;
113         int cumextablelength;
114         int cumlocals;        /* was static */
115         int cummethods;       /* was static */
116         list *inlining_stack; /* was static */
117         inlining_methodinfo *inlining_rootinfo;
118         methodinfo *method;
119         classinfo *class;
120         int jcodelength;
121         u1 *jcode;
122         bool isleafmethod;
123 };
124
125
126 /* function prototypes*/
127
128 void inlining_setup(methodinfo *m, t_inlining_globals *inline_env);
129 void inlining_cleanup(t_inlining_globals *inline_env);
130 void inlining_push_compiler_variables(
131                                       int i, int p, int nextp, int opcode, 
132                                       u2 lineindex,u2 currentline,u2 linepcchange,
133                                       inlining_methodinfo* inlinfo,
134                                       t_inlining_globals *inline_env);
135 void inlining_pop_compiler_variables(
136                                     int *i, int *p, int *nextp, int *opcode,
137                                     u2 *lineindex,u2 *currentline,u2 *linepcchange,
138                                     inlining_methodinfo **inlinfo,
139                                     t_inlining_globals *inline_env);
140 void inlining_set_compiler_variables_fun(methodinfo *m, 
141                                          t_inlining_globals *inline_env);
142 classinfo *first_occurence(classinfo* class, utf* name, utf* desc);
143 bool is_unique_recOLD(classinfo *class, methodinfo *m, utf* name, utf* desc);
144 bool is_unique_methodOLD(classinfo *class, methodinfo *m, utf* name, utf* desc);
145 inlining_methodinfo *inlining_analyse_method(methodinfo *m, 
146                                           int level, int gp,
147                                           int firstlocal, int maxstackdepth,                                          t_inlining_globals *inline_env);
148
149 void print_t_inlining_globals (t_inlining_globals *g);
150 void print_inlining_stack     ( list                *s);
151 void print_inlining_methodinfo( inlining_methodinfo *r);
152
153 #define inlining_save_compiler_variables() \
154     inlining_push_compiler_variables(i,p,nextp,opcode, lineindex,currentline, \
155         linepcchange,inlinfo,inline_env)
156
157 #define inlining_restore_compiler_variables() \
158     inlining_pop_compiler_variables(&i, &p, &nextp, &opcode, \
159         &lineindex,&currentline,&linepcchange,&inlinfo, \
160         inline_env)
161
162 #define inlining_set_compiler_variables(i) \
163     do { \
164         p = nextp = 0; \
165         inlining_set_compiler_variables_fun(i->method, inline_env); \
166         inlinfo = i; \
167     } while (0)
168
169 #endif /* _INLINE_H */
170
171 /*
172  * These are local overrides for various environment variables in Emacs.
173  * Please do not remove this and leave it at the end of the file, where
174  * Emacs will automagically detect them.
175  * ---------------------------------------------------------------------
176  * Local variables:
177  * mode: c
178  * indent-tabs-mode: t
179  * c-basic-offset: 4
180  * tab-width: 4
181  * End:
182  */