* JAVA_ANEWARRAY, JAVA_MULTIANEWARRAY, JAVA_CHECKCAST, JAVA_INSTANCEOF: Use
[cacao.git] / src / vm / jit / lsra.h
1 /* src/vm/jit/lsra.h - linear scan register allocator header
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: Christian Ullrich
28
29    $Id: lsra.h 2297 2005-04-13 12:50:07Z christian $
30
31 */
32
33
34 #ifndef _LSRA_H
35 #define _LSRA_H
36
37 /* #define LSRA_DEBUG */
38 /* #define LSRA_SAVEDVAR */
39 /* #define LSRA_MEMORY */
40 /*  #define LSRA_PRINTLIFETIMES */
41 /* #define LSRA_USES_REG_RES */ /* is now in i386/codegen.h */
42 /*  #define LSRA_TESTLT */
43 /* #define LSRA_LEAF */
44 #define JOIN_DEST_STACK
45 #define JOIN_DUP_STACK
46 #define LSRA_DO_SR
47 #define LSRA_DO_EX
48
49
50 #define USAGE_COUNT        /* influence LSRA with usagecount */
51 #define USAGE_PER_INSTR    /* divide usagecount by lifetimelength */
52
53 #ifdef LSRA_DEBUG
54 #undef LSRA_LEAF
55 #endif
56
57 #ifdef LSRA_TESTLT
58 #define VS 999999
59 #endif
60
61
62 #ifdef LSRA_DEBUG
63 #define LSRA_PRINTLIFETIMES
64 #endif
65
66 #define LSRA_BB_IN 3
67 #define LSRA_BB_OUT 2
68 #define LSRA_STORE 1
69 #define LSRA_LOAD 0
70 #define LSRA_POP -1
71
72 /* join types and flags*/
73 #define JOIN     0           /* join that are not in any way dangerous */
74 #define JOIN_BB  1           /* join Stackslots over Basic Block Boundaries */
75 #define JOIN_DUP 2           /* join of two possibly concurring lifeteimes through DUP* */
76 #define JOIN_OP  4           /* join of src operand with dst operand on i386 and x86_64 architecture */
77                              /* JOIN_DUP and JOIN_OP is mutually exclusive as JOIN_OP and JOIN_BB    */
78 #define JOINING  8           /* set while joining for DUP or OP to prevent assignement to a */
79                              /* REG_RES before all involved lifetimes have been seen fully  */
80
81 #define min(a,b) ((a)<(b)?(a):(b))
82 #define max(a,b) ((a)<(b)?(b):(a))
83
84 struct _list {
85         int value;
86         struct _list *next;
87 };
88
89 struct _backedge {
90         int start;
91         int end;
92         struct _backedge *next;
93 };
94
95 struct lifetime {
96         int i_start; /* instruction number of first use */
97         int i_end; /* instruction number of last use */
98         int v_index; /* local variable index or negative for stackslots */
99         int type; /* TYPE_??? or -1 for unused lifetime */
100         long usagecount; /* number of references*/
101         int reg; /* regoffset durch lsra zugewiesen */
102         int savedvar;
103         int flags;
104         struct stackslot *local_ss; /* Stackslots for this Lifetime or NULL (=="pure" Local Var) */
105         int bb_last_use;
106         int i_last_use;
107         int bb_first_def;
108         int i_first_def;
109 /*      struct lifetime *next; */
110 };
111
112 struct active_lt {
113         struct lifetime *lt;
114         struct active_lt *next;
115 };
116
117 struct l_loop {
118         int b_first;
119         int b_last;
120         int nesting;
121 };
122
123 struct b_loop {
124         int loop;
125         int instr;
126 };
127
128
129 struct stackslot {
130         stackptr s;
131         int bb;
132         struct stackslot *next;
133 };
134
135 struct lsra_register {
136         int *sav_reg;
137         int *tmp_reg;
138         int *nregdesc;
139         int sav_top;
140         int tmp_top;
141 };
142
143 struct lsra_reg {
144         int reg_index;
145         int use;
146 };
147
148 struct _sbr {
149         int header;
150         struct _list *ret;
151         struct _sbr *next;
152 };
153
154 struct lsradata {
155 #if defined(LSRA_USES_REG_RES)
156         int reg_res_free[REG_RES_CNT];
157 #endif
158         struct _list **succ; /* CFG successors*/
159         struct _list **pred; /* CFG predecessors */
160         int *num_pred;       /* CFG number of predecessors */
161         int *sorted;         /* BB sorted in reverse post order */
162         int *sorted_rev;     /* BB reverse of sorted */
163         struct _backedge **backedge;
164         int backedge_count;
165
166         struct _sbr sbr;
167
168         long *nesting;
169
170         int maxlifetimes; /* copy from methodinfo to prevent passing methodinfo as parameter */
171         struct lifetime *lifetime; /* array of lifetimes */
172         int *lt_used; /* index to lifetimearray for used lifetimes */
173         int lifetimecount;
174         int *lt_int; /* index to lifetimearray for int lifetimes */
175         int lt_int_count;
176         int *lt_flt; /* index to lifetimearray for float lifetimes */
177         int lt_flt_count;
178         int *lt_rest; /* index to lifetimearray for all lifetimes not to be allocated in registers */
179         int lt_rest_count;
180
181         struct active_lt *active_tmp, *active_sav;
182
183         struct lsra_exceptiontable *ex;
184         int icount_max;
185         int end_bb;
186         int v_index;
187 };
188
189 struct freemem {
190         int off;
191         int end;
192         struct freemem *next;
193 };
194
195 typedef struct lsradata lsradata;
196
197 /* function prototypes */
198 bool lsra(methodinfo *, codegendata *, registerdata *,t_inlining_globals *);
199 bool lsra_test(methodinfo *, codegendata *);
200 void lsra_init(methodinfo *, codegendata *, t_inlining_globals *, lsradata *);
201 bool lsra_setup(methodinfo *, codegendata *, registerdata *, lsradata *);
202 void lsra_main(methodinfo *, lsradata *, registerdata *, codegendata *);
203 void lsra_clean_Graph( methodinfo *, codegendata *, lsradata *);
204
205 #ifdef LSRA_DEBUG 
206 void lsra_dump_stack(stackptr );
207 #endif
208 #ifdef LSRA_PRINTLIFETIMES
209 void print_lifetimes(registerdata *, lsradata *, int *, int);
210 #endif
211 #ifdef LSRA_TESTLT
212 void test_lifetimes( methodinfo *, lsradata *, registerdata *);
213 #endif
214
215 void lsra_reg_setup(methodinfo *m ,registerdata *,struct lsra_register *,struct lsra_register * );
216
217
218 void lsra_scan_registers_canditates(methodinfo *,  lsradata *, int);
219
220 void lsra_join_lifetimes( methodinfo *, lsradata *, int);
221 void lsra_calc_lifetime_length(methodinfo *, lsradata *, codegendata *);
222
223 void _lsra_new_stack( lsradata *, stackptr , int , int, int);
224 void _lsra_from_stack(lsradata *, stackptr , int , int, int);
225 void lsra_add_ss(struct lifetime *, stackptr );
226 void lsra_usage_local(lsradata *, s4 , int , int , int , int );
227
228 void _lsra_main( methodinfo *, lsradata *, int *, int, struct lsra_register *, int *);
229 void lsra_expire_old_intervalls(methodinfo *, lsradata *, struct lifetime *, struct lsra_register *);
230 void _lsra_expire_old_intervalls(methodinfo *, struct lifetime *, struct lsra_register *, struct active_lt **/* , int * */);
231 void spill_at_intervall(methodinfo *, lsradata *, struct lifetime *);
232 void _spill_at_intervall(struct lifetime *, struct active_lt **);
233 void lsra_add_active(struct lifetime *, struct active_lt **);
234 void lsra_alloc(methodinfo *, registerdata *, struct lsradata *, int *, int, int *);
235 int lsra_getmem(struct lifetime *, struct freemem *, int *);
236 struct freemem *lsra_getnewmem(int *);
237 void lsra_align_stackslots(struct lsradata *, stackptr, stackptr);
238 void lsra_setflags(int *, int);
239
240 #endif /* _LSRA_H */
241
242
243 /*
244  * These are local overrides for various environment variables in Emacs.
245  * Please do not remove this and leave it at the end of the file, where
246  * Emacs will automagically detect them.
247  * ---------------------------------------------------------------------
248  * Local variables:
249  * mode: c
250  * indent-tabs-mode: t
251  * c-basic-offset: 4
252  * tab-width: 4
253  * End:
254  */