034c1a70f302bfedbeef9a15be370ae72cb343cd
[cacao.git] / src / vm / jit / inline / inline.h
1 /* jit/inline.h - code inliner
2
3    Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    Institut f. Computersprachen - TU Wien
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 1735 2004-12-07 14:33:27Z 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       3  /*1*/ 
47 #define INLINING_MAXCODESIZE    128 /*32*/
48 #define INLINING_MAXMETHODS     32 /*8*/
49
50 typedef struct {
51     listnode linkage;
52
53     methodinfo *method;
54     int level;
55     int startgp;
56     int stopgp;
57     int firstlocal;
58
59     bool *readonly;
60     int  *label_index;
61         
62     list *inlinedmethods;
63 } inlining_methodinfo;
64
65
66 typedef struct {
67     listnode linkage;
68         
69     /* saved static compiler variables */
70         
71     methodinfo *method;
72         
73     /* restored through method */
74
75     /* int jcodelength; */
76     /* u1 *jcode; */
77         /* classinfo *class; */
78
79     /* descriptor never used */
80     /* maxstack used outside of main for loop */
81     /* maxlocals never used */
82         
83     /* exceptiontablelength */
84     /* raw_extable used outside of main for loop */
85     /* mreturntype used outside of main for loop */
86     /* mparamcount used outside of main for loop */
87     /* mparamtypes used outside of main for loop */
88
89     /* local variables used in parse() */
90
91     int  i;                     /* temporary for different uses (counters)*/
92     int  p;                     /* java instruction counter               */
93     int  nextp;                 /* start of next java instruction         */
94     int  opcode;                /* java opcode                            */
95     u2 lineindex;
96     u2 currentline;
97     u2 linepcchange;
98     inlining_methodinfo *inlinfo;
99
100 } t_inlining_stacknode;
101
102
103 struct t_inlining_globals {  /* try in parse.h with struct not include */
104         bool isinlinedmethod;
105         int cumjcodelength;   /* cumulative immediate intruction length */
106         int cummaxstack;
107         int cumextablelength;
108         int cumlocals;        /* was static */
109         int cummethods;       /* was static */
110         list *inlining_stack; /* was static */
111         inlining_methodinfo *inlining_rootinfo;
112         methodinfo *method;
113         classinfo *class;
114         int jcodelength;
115         u1 *jcode;
116         bool isleafmethod;
117 };
118
119
120 /* function prototypes*/
121
122 void inlining_setup(methodinfo *m, t_inlining_globals *inline_env);
123 void inlining_cleanup(t_inlining_globals *inline_env);
124 void inlining_push_compiler_variables(
125                                       int i, int p, int nextp, int opcode, 
126                                       u2 lineindex,u2 currentline,u2 linepcchange,
127                                       inlining_methodinfo* inlinfo,
128                                       t_inlining_globals *inline_env);
129 void inlining_pop_compiler_variables(
130                                     int *i, int *p, int *nextp, int *opcode,
131                                     u2 *lineindex,u2 *currentline,u2 *linepcchange,
132                                     inlining_methodinfo **inlinfo,
133                                     t_inlining_globals *inline_env);
134 void inlining_set_compiler_variables_fun(methodinfo *m, 
135                                          t_inlining_globals *inline_env);
136 classinfo *first_occurence(classinfo* class, utf* name, utf* desc);
137 bool is_unique_recOLD(classinfo *class, methodinfo *m, utf* name, utf* desc);
138 bool is_unique_methodOLD(classinfo *class, methodinfo *m, utf* name, utf* desc);
139 inlining_methodinfo *inlining_analyse_method(methodinfo *m, 
140                                           int level, int gp,
141                                           int firstlocal, int maxstackdepth,                                          t_inlining_globals *inline_env);
142
143 void print_t_inlining_globals (t_inlining_globals *g);
144 void print_inlining_stack     ( list                *s);
145 void print_inlining_methodinfo( inlining_methodinfo *r);
146
147 #define inlining_save_compiler_variables() \
148     inlining_push_compiler_variables(i,p,nextp,opcode, lineindex,currentline, \
149         linepcchange,inlinfo,inline_env)
150
151 #define inlining_restore_compiler_variables() \
152     inlining_pop_compiler_variables(&i, &p, &nextp, &opcode, \
153         &lineindex,&currentline,&linepcchange,&inlinfo, \
154         inline_env)
155
156 #define inlining_set_compiler_variables(i) \
157     do { \
158         p = nextp = 0; \
159         inlining_set_compiler_variables_fun(i->method, inline_env); \
160         inlinfo = i; \
161     } while (0)
162
163 #endif /* _INLINE_H */
164
165 /*
166  * These are local overrides for various environment variables in Emacs.
167  * Please do not remove this and leave it at the end of the file, where
168  * Emacs will automagically detect them.
169  * ---------------------------------------------------------------------
170  * Local variables:
171  * mode: c
172  * indent-tabs-mode: t
173  * c-basic-offset: 4
174  * tab-width: 4
175  * End:
176  */