CACAO
lsra.hpp
Go to the documentation of this file.
1 /* src/vm/jit/optimizing/lsra.hpp - linear scan register allocator header
2 
3  Copyright (C) 2005-2013
4  CACAOVM - Verein zu Foerderung der freien virtuellen Machine CACAO
5 
6  This file is part of CACAO.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2, or (at
11  your option) any later version.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22 
23  Contact: cacao@complang.tuwien.ac.at
24 
25  Authors: Christian Ullrich
26 
27  $Id: lsra.h,v 1.17 2005/11/22 14:36:16 christian Exp $
28 
29 */
30 
31 
32 #ifndef LSRA_HPP_
33 #define LSRA_HPP_ 1
34 
35 #include "toolbox/bitvector.hpp"
36 
37 struct basicblock;
38 struct jitdata;
39 
40 #if !defined(NDEBUG)
41 # include <assert.h>
42 # define LSRA_DEBUG_CHECK
43 # define LSRA_DEBUG_VERBOSE
44 #endif
45 
46 #ifdef LSRA_DEBUG_CHECK
47 # define _LSRA_CHECK_BOUNDS(i,l,h) assert( ((i) >= (l)) && ((i) < (h)));
48 # define _LSRA_ASSERT(a) assert((a));
49 #else
50 # define _LSRA_CHECK_BOUNDS(i,l,h)
51 # define _LSRA_ASSERT(a)
52 #endif
53 
54 /* let LSRA allocate reserved registers (REG_ITMP[1|2|3]) */
55 #if defined(__I386__)
56 /* #define LSRA_USES_REG_RES */
57 /* # include "vm/jit/i386/icmd_uses_reg_res.inc.h" */
58 #endif
59 
60 /* #define LSRA_SAVEDVAR */
61 /* #define LSRA_MEMORY */
62 
63 #define USAGE_COUNT /* influence LSRA with usagecount */
64 /* #define USAGE_PER_INSTR */ /* divide usagecount by lifetimelength */
65 
66 
67 struct site {
68  int b_index;
69  int iindex;
70  struct site *next;
71 };
72 
73 struct lifetime {
74  int i_start; /* instruction number of first use */
75  int i_end; /* instruction number of last use */
76  int v_index; /* local variable index or negative for stackslots */
77  int type; /* TYPE_XXX or -1 for unused lifetime */
78  long usagecount; /* number of references*/
79  int regoff; /* regoffset allocated by lsra*/
80  int savedvar;
81  int flags;
82  /* struct stackslot *local_ss; */ /* Stackslots for this Lifetime or NULL ( == */
83  /* "pure" Local Var) */
84  int bb_last_use;
85  int i_last_use;
86  int bb_first_def;
87  int i_first_def;
88 
89  struct site *def;
90  struct site *use;
91  struct site *last_use;
92 };
93 
94 struct l_loop {
95  int b_first;
96  int b_last;
97  int nesting;
98 };
99 
100 struct lsra_register {
101  int *sav_reg;
102  int *tmp_reg;
103  int *nregdesc;
104  int sav_top;
105  int tmp_top;
106 };
107 
108 struct lsra_reg {
109  int reg_index;
110  int use;
111 };
112 
113 struct lsradata {
114  int varcount; /* size of vars array */
115  int ssavarcount; /* ls->vars[0..ssavarcount[ are all locals and iovars */
116  /* they are regarded for ssa renaming */
117  /* the rest (ls->vars[ssavarcount..varcount[ are */
118  /* TEMP or PREALLOC vars with just on definition and */
119  /* use within one basicblock -> not of interest for */
120  /* ssa renaming procedures */
121  int vartop; /* next free var */
123  int *new_varindex; /* new_varindex[0..jd->varcount[ points to the new */
124  /* unique index of ls->vars(maps jd->vars to ls->vars)*/
125 
126  int *var_0; /* [0..ls->varcount] */
127  /* var_0[a] with a in [0..ls->varcount[ holds the */
128  /* index of La,0 */
129  /* var_0[ls->varcount] holds the number of vars with */
130  /*indices */
131 
132  int *sorted; /* BB sorted in reverse post order */
133  int *sorted_rev; /* BB reverse lookup of sorted */
134 
135  long *nesting; /* Nesting level of BB*/
136 
137  struct lifetime *lifetime; /* array of lifetimes */
138  int lifetimecount; /* number of lifetimes */
139  int *lt_used; /* index to lifetimearray for used lifetimes */
140  int *lt_int; /* index to lifetimearray for int lifetimes */
141  int lt_int_count; /* number of int/[lng]/[adr] lifetimes */
142  int *lt_flt; /* index to lifetimearray for float lifetimes */
143  int lt_flt_count; /* number of float/double lifetimes */
144  int *lt_mem; /* index to lifetimearray for all lifetimes */
145  /* not to be allocated in registers */
146  int lt_mem_count; /* number of this other lifetimes */
147 
148  struct lifetime **active_tmp, **active_sav;
150 
151  struct lsra_exceptiontable *ex;
152 
153  /* SSA fields */
154  bitvector *var_def; /* LocalVar Definition Bitvector [0..ls->bbcount] */
155  /* Bitvector holds ls->max_vars Bits */
156  bitvector *use_sites; /* LocalVar Use Bitvector[0..ls->maxvars] */
157  int **num_var_use; /* count of var_use[bb][var_index] */
158  int **var; /* [0..cd->maxlocal+cd->maxstack[[0..4] */
159  /* ssa_set_local_def and ssa_set_interface (called from analyse_stack) */
160  /* set var[local_index][local_type] and var[jd->maxlocals+stack_depth] */
161  /* [stack_type] to a unique type independend index [0..ls->max_vars[ */
162  /* unused entries are set to -1 */
163  int max_vars;
165  int *num_defs; /* counts definitions of variables */
166  /* [0..jd->maxlocals*5+cd->maxstack*5[ */
167  /* valid for [0..ls->max_vars[ */
168 
169 
170  int *local_0; /* [0..ls->max_locals] */
171  /* local_0[a] with a in [0..ls->max_locals[ holds the */
172  /* index of La,0 */
173  /* local_0[ls->maxlocals] holds the number of local */
174  /* vars with indices */
175  int *interface_0; /* same here, just with interfaces */
176 
177  int *var_to_index; /* var index to interface (<0) or local (>=0) index */
178  /* [0..jd->maxlocals*5+cd->maxstack*5[ */
179  /* valid for [0..ls->max_vars[ */
180  /* holds var_index or the negative interface index */
181  /* in ssa_Rename_init the indices are changed to the */
182  /* index of the corresponding first Var with index;) */
183  /* (== local_0[] or interface_0[] */
186 
187  int uses;
190  /* [0..ls->basicblockcount[[0..ls->max_locals[[0..ls->num_pre[bb]] */
191  /* 3rd index represents the the var involved in the phi function */
192  /* a0 = phi(a1,a2,...,a(ls->num_pre[bb]-1)) */
193  int ***phi; /* [0..ls->basicblockcount[[0..ls->max_vars[[0,1] */
194  /* if no phi function for a Basic Block and var exists */
195  /* phi[bb][a] == NULL */
197  int ***phi_moves; /* phi_moves[block_index][0..num_phi_moves[bi][0..1] */
198  /* [][][0] target */
199  /* [][][1] source */
200 
201  int *count; /* Helpers for ssa_Rename */
202  int **stack;
203  int *stack_top;
204 
205 };
206 
207 
208 struct freemem {
209  int off;
210  int end;
211  struct freemem *next;
212 };
213 
214 typedef struct lsradata lsradata;
215 
216 /* function prototypes */
217 void lsra(jitdata *);
218 
219 #endif // LSRA_HPP_
220 
221 
222 /*
223  * These are local overrides for various environment variables in Emacs.
224  * Please do not remove this and leave it at the end of the file, where
225  * Emacs will automagically detect them.
226  * ---------------------------------------------------------------------
227  * Local variables:
228  * mode: c++
229  * indent-tabs-mode: t
230  * c-basic-offset: 4
231  * tab-width: 4
232  * End:
233  */
int ** num_var_use
Definition: lsra.hpp:157
int i_last_use
Definition: lsra.hpp:107
int end
Definition: lsra.hpp:190
struct freemem * next
Definition: lsra.hpp:191
int savedvar
Definition: lsra.hpp:101
int * bitvector
Definition: bitvector.hpp:34
int * local_0
Definition: lsra.hpp:170
int max_vars
Definition: lsra.hpp:163
int ** stack
Definition: lsra.hpp:202
int * lt_int
Definition: lsra.hpp:171
Definition: lsra.hpp:111
int bb_last_use
Definition: lsra.hpp:105
Definition: lsra.hpp:67
Definition: jit.hpp:126
int *** phi_moves
Definition: lsra.hpp:197
int bb_first_def
Definition: lsra.hpp:106
int lt_flt_count
Definition: lsra.hpp:174
int lifetimecount
Definition: lsra.hpp:169
bitvector * use_sites
Definition: lsra.hpp:156
bitvector * var_def
Definition: lsra.hpp:154
int basicblockcount
Definition: lsra.hpp:188
int max_interfaces
Definition: lsra.hpp:185
int sav_top
Definition: lsra.hpp:133
int nesting
Definition: lsra.hpp:114
int varcount_with_indices
Definition: lsra.hpp:122
struct site * use
Definition: lsra.hpp:90
int varcount
Definition: lsra.hpp:114
int v_index
Definition: lsra.hpp:97
int use
Definition: lsra.hpp:139
int * lt_flt
Definition: lsra.hpp:173
struct site * def
Definition: lsra.hpp:89
struct lifetime * lifetime
Definition: lsra.hpp:168
int * lt_mem
Definition: lsra.hpp:175
int i_start
Definition: lsra.hpp:95
int b_first
Definition: lsra.hpp:112
int * lt_used
Definition: lsra.hpp:170
int max_locals
Definition: lsra.hpp:184
int iindex
Definition: lsra.hpp:69
int * nregdesc
Definition: lsra.hpp:132
int ** var
Definition: lsra.hpp:158
int * stack_top
Definition: lsra.hpp:203
int * num_phi_moves
Definition: lsra.hpp:196
struct lifetime ** active_sav
Definition: lsra.hpp:179
int * new_varindex
Definition: lsra.hpp:123
long * nesting
Definition: lsra.hpp:163
int lt_int_count
Definition: lsra.hpp:172
int * var_0
Definition: lsra.hpp:126
int i_end
Definition: lsra.hpp:96
int ssavarcount
Definition: lsra.hpp:115
bool lsra(jitdata *jd)
Definition: lsra.cpp:101
struct site * last_use
Definition: lsra.hpp:91
int uses
Definition: lsra.hpp:187
int * count
Definition: lsra.hpp:201
int flags
Definition: lsra.hpp:102
int regoff
Definition: lsra.hpp:79
struct site * next
Definition: lsra.hpp:70
basicblock ** basicblocks
Definition: lsra.hpp:189
int * sorted
Definition: lsra.hpp:155
struct lsra_exceptiontable * ex
Definition: lsra.hpp:182
int * sav_reg
Definition: lsra.hpp:130
int type
Definition: lsra.hpp:98
int * interface_0
Definition: lsra.hpp:175
long usagecount
Definition: lsra.hpp:99
int * sorted_rev
Definition: lsra.hpp:156
int b_last
Definition: lsra.hpp:113
int b_index
Definition: lsra.hpp:68
int max_vars_with_indices
Definition: lsra.hpp:164
int tmp_top
Definition: lsra.hpp:134
int lt_mem_count
Definition: lsra.hpp:177
int * tmp_reg
Definition: lsra.hpp:131
int * var_to_index
Definition: lsra.hpp:177
int off
Definition: lsra.hpp:189
int * num_defs
Definition: lsra.hpp:165
struct lifetime ** active_tmp
Definition: lsra.hpp:179
int active_sav_top
Definition: lsra.hpp:180
int vartop
Definition: lsra.hpp:121
int reg_index
Definition: lsra.hpp:138
int *** phi
Definition: lsra.hpp:193
int active_tmp_top
Definition: lsra.hpp:180
int i_first_def
Definition: lsra.hpp:108