e4b59d2d0da633c55c9051fe46a0a086486064b9
[cacao.git] / src / vm / jit / lsra.h
1 /* jit/lsra.inc - linear scan register allocator header
2
3    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
4    Institut f. Computersprachen, TU Wien
5    R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser, M. Probst,
6    S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich,
7    J. Wenninger, C. Ullrich
8
9    This file is part of CACAO.
10
11    This program is free software; you can redistribute it and/or
12    modify it under the terms of the GNU General Public License as
13    published by the Free Software Foundation; either version 2, or (at
14    your option) any later version.
15
16    This program is distributed in the hope that it will be useful, but
17    WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19    General Public License for more details.
20
21    You should have received a copy of the GNU General Public License
22    along with this program; if not, write to the Free Software
23    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24    02111-1307, USA.
25
26    Contact: cacao@complang.tuwien.ac.at
27
28    Authors: Christian Ullrich
29
30    $Id: lsra.h 1597 2004-11-28 16:37:23Z christian $
31
32 */
33
34
35 #ifndef _LSRA_H
36 #define _LSRA_H
37
38 #include "loop/loop.h"
39
40 #define LSRA_STORE 1
41 #define LSRA_LOAD 0
42 #define LSRA_POP -1
43
44 struct lifetime {
45         int i_start; /* instruction number of first use */
46         int i_end; /* instruction number of last use */
47         int v_index; /* local variable index or negative for stackslots */
48         int type;
49         int usagecount; /* number of references*/
50         int reg; /* regoffset durch lsra zugewiesen */
51         int savedvar;
52         struct stackslot *passthrough; /* List of Stackslots in Lifetime, which are passed through a Basic Block */
53         struct stackslot *local_ss; /* Stackslots for this Lifetime or NULL (=="pure" Local Var) */
54         struct _i_list *i_list; /* list of instructions with references to var */
55         struct lifetime *next;
56 };
57
58 struct active_lt {
59         struct lifetime *lt;
60         struct active_lt *next;
61 };
62
63 struct l_loop {
64         int b_first;
65         int b_last;
66         int nesting;
67 };
68
69 struct b_loop {
70         int loop;
71         int instr;
72 };
73
74 struct _i_list {
75         int b_index;
76         int instr;
77         int store;
78         struct _i_list *next;
79 };
80
81 struct stackslot {
82         stackptr s;
83         int bb;
84         struct stackslot *next;
85 };
86
87 struct lsra_reg {
88         int reg_index;
89         int use;
90 };
91
92 struct lsradata {
93         struct lifetime **ss_lifetimes;
94         struct lifetime **locals_lifetimes;
95         struct lifetime *lifetimes;
96         struct stackslot *stackslots;
97         struct active_lt *active_tmp, *active_sav;
98         int active_sav_count, active_tmp_count;
99         int var_index;
100         bool back_edge_panic;
101 };
102
103 struct freemem {
104         int off;
105         int end;
106         struct freemem *next;
107 };
108
109 struct dup {
110         struct stackslot *ss;
111         struct dup *next;
112 };
113
114 typedef struct lsradata lsradata;
115
116 /* function prototypes */
117 void lsra(methodinfo *, codegendata *, registerdata *, loopdata *, t_inlining_globals *);
118 void lsra_init(methodinfo *, codegendata *, t_inlining_globals *, lsradata *);
119 void lsra_setup(methodinfo *, codegendata *, registerdata *, lsradata *, loopdata *);
120 void lsra_clean_Graph( methodinfo *, codegendata *, lsradata *, loopdata *);
121
122 #ifdef LSRA_DEBUG
123 void lsra_dump_Graph(methodinfo *, struct depthElement **);
124 void lsra_dump_stack(stackptr );
125 #endif
126 #ifdef LSRA_PRINTLIFETIMES
127 void print_lifetimes(registerdata *, struct lifetime *);
128 #endif
129
130 int lsra_get_sbr_end(methodinfo *, loopdata *, int , int *);
131 void lsra_scan_registers_canditates(methodinfo *, lsradata *);
132 void lsra_join_lifetimes( methodinfo *, codegendata *, lsradata *, loopdata *);
133 int lsra_getmaxblock(methodinfo *, loopdata *, int );
134 void lsra_calc_lifetime_length(methodinfo *, lsradata *, codegendata *, loopdata *);
135
136 void lsra_merge_i_lists(struct lifetime *, struct lifetime *);
137 void lsra_merge_local_ss(struct lifetime *, struct lifetime *);
138
139 void _lsra_new_stack( lsradata *, stackptr , int , int, int);
140 void _lsra_from_stack(lsradata *, stackptr , int , int, int);
141 void lsra_add_ss(struct lifetime *, stackptr );
142 void lsra_usage_local(lsradata *, s4 , int , int , int , int );
143 void lsra_new_local(lsradata *, s4 , int );
144 struct _i_list *lsra_add_i_list(struct _i_list *, int, int ,int );
145
146 void lsra_sort_lt(struct lifetime **);
147 void lsra_main(methodinfo *, lsradata *, registerdata *);
148 void _lsra_main( methodinfo *, lsradata *, struct lifetime *, struct lsra_reg *, int , int , int *, int *);
149 void lsra_expire_old_intervalls(lsradata *, struct lifetime *, struct lsra_reg *);
150 void _lsra_expire_old_intervalls(struct lifetime *, struct lsra_reg *, struct active_lt **, int *);
151 void spill_at_intervall(lsradata *, struct lifetime *);
152 void _spill_at_intervall(struct lifetime *, struct active_lt **, int *);
153 void lsra_add_active(struct lifetime *, struct active_lt **, int *);
154 void lsra_alloc(methodinfo *, registerdata *, struct lifetime *, int *);
155 int lsra_getmem(struct lifetime *, struct freemem *, int *);
156 struct freemem *lsra_getnewmem(int *);
157 void lsra_align_stackslots(struct lsradata *, stackptr, stackptr);
158 void lsra_setflags(int *, int);
159 #endif /* _LSRA_H */
160
161
162 /*
163  * These are local overrides for various environment variables in Emacs.
164  * Please do not remove this and leave it at the end of the file, where
165  * Emacs will automagically detect them.
166  * ---------------------------------------------------------------------
167  * Local variables:
168  * mode: c
169  * indent-tabs-mode: t
170  * c-basic-offset: 4
171  * tab-width: 4
172  * End:
173  */