* Removed all Id tags.
[cacao.git] / src / vm / jit / allocator / lsra.h
1 /* src/vm/jit/allocator/lsra.h - linear scan register allocator header
2
3    Copyright (C) 2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, 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., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    Contact: cacao@cacaojvm.org
26
27    Authors: Christian Ullrich
28
29    Changes: Edwin Steiner
30
31 */
32
33
34 #ifndef _LSRA_H
35 #define _LSRA_H
36
37 #include "config.h"
38
39 #if !defined(NDEBUG)
40 # include <assert.h>
41 # define LSRA_DEBUG_CHECK
42 # define LSRA_DEBUG_VERBOSE
43 #endif
44
45 #ifdef SSA_DEBUG_CHECK
46 # define _LSRA_CHECK_BOUNDS(i,l,h) assert( ((i) >= (l)) && ((i) < (h)));
47 # define _LSRA_ASSERT(a) assert((a));
48 #else
49 # define _LSRA_CHECK_BOUNDS(i,l,h)
50 # define _LSRA_ASSERT(a)
51 #endif
52
53 /* #define LSRA_DEBUG  */ /* lsra debug messages */
54 /* #define LSRA_SAVEDVAR */
55 /* #define LSRA_MEMORY */
56 #if defined(__I386__) || defined(__X86_64__)
57 #define JOIN_DEST_STACK           /* The destination stackslot gets the same  */
58         /* register as one of the src stackslots. Important for i386 & X86_64 */
59         /* since they do not have "3 operand" arithmetic instructions to      */
60         /* prevent usage of a reserved register (REG_ITMPX)                   */
61 #endif
62 #define JOIN_DUP_STACK         /* join "identical" stackslots created by dup* */
63
64 #define USAGE_COUNT        /* influence LSRA with usagecount */
65 #define USEAGE_COUNT_EXACT /* search all active lifetimes and regard */
66                            /* usage_count */
67 #define USAGE_PER_INSTR    /* divide usagecount by lifetimelength */
68
69 #define LSRA_BB_IN 3
70 #define LSRA_BB_OUT 2
71 #define LSRA_STORE 1
72 #define LSRA_LOAD 0
73 #define LSRA_POP -1
74
75 /* join types and flags*/
76 #define JOIN     0 /* joins that are not in any way dangerous                 */
77 #define JOIN_BB  1 /* join Stackslots over Basic Block Boundaries             */
78 #define JOIN_DUP 2 /* join of two possibly concurring lifeteimes through DUP* */
79 #define JOIN_OP  4 /* join of src operand with dst operand on i386 and x86_64 */
80                    /* architecture                                            */
81                    /* JOIN_DUP and JOIN_OP is mutually exclusive as JOIN_OP   */
82                    /* and JOIN_BB                                             */
83 #define JOINING  8 /* set while joining for DUP or OP to prevent assignement  */
84                    /* to a REG_RES before all involved lifetimes have been    */
85                    /* seen completely */
86
87 #define min(a,b) ((a)<(b)?(a):(b))
88 #define max(a,b) ((a)<(b)?(b):(a))
89
90 struct _list {
91         int value;
92         struct _list *next;
93 };
94
95 struct _backedge {
96         int start;
97         int end;
98         int nesting;
99         struct _backedge *next;
100 };
101
102 struct lifetime {
103         int i_start;                /* instruction number of first use */
104         int i_end;                  /* instruction number of last use */
105         int v_index;           /* local variable index or negative for stackslots */
106         int type;                   /* TYPE_* or -1 for unused lifetime */
107         long usagecount;            /* number of references*/
108         int reg;                    /* regoffset allocated by lsra*/
109         int savedvar;
110         int flags;
111         struct stackslot *local_ss; /* Stackslots for this Lifetime or NULL ( ==  */
112                                 /* "pure" Local Var) */
113         int bb_last_use;
114         int bb_first_def;
115         int i_last_use;
116         int i_first_def;
117 };
118
119 struct l_loop {
120         int b_first;
121         int b_last;
122         int nesting;
123 };
124
125 struct b_loop {
126         int loop;
127         int instr;
128 };
129
130
131 struct stackslot {
132         stackptr s;
133         int bb;
134         struct stackslot *next;
135 };
136
137 struct lsra_register {
138         int *sav_reg;
139         int *tmp_reg;
140         int *nregdesc;
141         int sav_top;
142         int tmp_top;
143 };
144
145 struct lsra_reg {
146         int reg_index;
147         int use;
148 };
149
150 struct _sbr {
151         int header;          /* BB Index of subroutine start (SBR_HEADER) */
152         struct _list *ret;   /* List of possible return BB indizes */
153         struct _sbr *next;
154 };
155
156 struct lsradata {
157 #if defined(LSRA_USES_REG_RES)
158         int reg_res_free[REG_RES_CNT];
159 #endif
160         struct _list **succ; /* CFG successors*/
161         struct _list **pred; /* CFG predecessors */
162         int *num_pred;       /* CFG number of predecessors */
163         int *sorted;         /* BB sorted in reverse post order */
164         int *sorted_rev;     /* BB reverse lookup of sorted */
165
166         struct _backedge **backedge; /* backedge data structure */
167         int backedge_count;          /* number of backedges */
168
169         struct _sbr sbr;     /* list of subroutines, sorted by header */
170
171         long *nesting;    /* Nesting level of BB*/
172
173         int maxlifetimes; /* copy from methodinfo to prevent passing methodinfo   */
174                       /* as parameter */
175
176         struct lifetime *lifetime; /* array of lifetimes */
177         int lifetimecount;         /* number of lifetimes */
178         int *lt_used;              /* index to lifetimearray for used lifetimes   */
179         int *lt_int;               /* index to lifetimearray for int lifetimes    */
180         int lt_int_count;          /* number of int/[lng]/[adr] lifetimes */
181         int *lt_flt;               /* index to lifetimearray for float lifetimes  */
182         int lt_flt_count;          /* number of float/double lifetimes */
183         int *lt_mem;               /* index to lifetimearray for all lifetimes    */
184                                /* not to be allocated in registers */
185         int lt_mem_count;          /* number of this other lifetimes */
186
187         struct lifetime **active_tmp, **active_sav;
188         int active_tmp_top, active_sav_top;
189
190         struct lsra_exceptiontable *ex;
191         int v_index;               /* next free index for stack slot lifetimes    */
192                                    /* decrements from -1 */
193         int *icount_block;
194 };
195
196 struct freemem {
197         int off;
198         int end;
199         struct freemem *next;
200 };
201
202 typedef struct lsradata lsradata;
203
204
205 /* function prototypes ********************************************************/
206
207 bool lsra(jitdata *jd);
208
209 #endif /* _LSRA_H */
210
211
212 /*
213  * These are local overrides for various environment variables in Emacs.
214  * Please do not remove this and leave it at the end of the file, where
215  * Emacs will automagically detect them.
216  * ---------------------------------------------------------------------
217  * Local variables:
218  * mode: c
219  * indent-tabs-mode: t
220  * c-basic-offset: 4
221  * tab-width: 4
222  * End:
223  * vim:noexpandtab:sw=4:ts=4:
224  */