1 /* src/vm/jit/optimizing/lsra.h - linear scan register allocator header
3 Copyright (C) 2005, 2006 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
8 This file is part of CACAO.
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.
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.
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
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Christian Ullrich
29 $Id: lsra.h,v 1.17 2005/11/22 14:36:16 christian Exp $
37 #include "toolbox/bitvector.h"
41 # define LSRA_DEBUG_CHECK
42 # define LSRA_DEBUG_VERBOSE
45 #ifdef LSRA_DEBUG_CHECK
46 # define _LSRA_CHECK_BOUNDS(i,l,h) assert( ((i) >= (l)) && ((i) < (h)));
47 # define _LSRA_ASSERT(a) assert((a));
49 # define _LSRA_CHECK_BOUNDS(i,l,h)
50 # define _LSRA_ASSERT(a)
53 /* let LSRA allocate reserved registers (REG_ITMP[1|2|3]) */
55 /* #define LSRA_USES_REG_RES */
56 /* # include "vm/jit/i386/icmd_uses_reg_res.inc.h" */
59 /* #define LSRA_SAVEDVAR */
60 /* #define LSRA_MEMORY */
62 #define USAGE_COUNT /* influence LSRA with usagecount */
63 /* #define USAGE_PER_INSTR */ /* divide usagecount by lifetimelength */
67 #define min(a,b) ((a)<(b)?(a):(b))
68 #define max(a,b) ((a)<(b)?(b):(a))
74 struct _backedge *next;
84 int i_start; /* instruction number of first use */
85 int i_end; /* instruction number of last use */
86 int v_index; /* local variable index or negative for stackslots */
87 int type; /* TYPE_XXX or -1 for unused lifetime */
88 long usagecount; /* number of references*/
89 int reg; /* regoffset allocated by lsra*/
92 struct stackslot *local_ss; /* Stackslots for this Lifetime or NULL ( == */
93 /* "pure" Local Var) */
101 struct site *last_use;
113 struct stackslot *next;
116 struct lsra_register {
129 struct igraph_lookup {
134 struct igraph_interference {
137 struct igraph_interference *next;
142 struct igraph_vars *next;
146 struct igraph_interference *inter;
147 struct igraph_vars *vars;
152 int *sorted; /* BB sorted in reverse post order */
153 int *sorted_rev; /* BB reverse lookup of sorted */
155 struct _backedge **backedge; /* backedge data structure */
156 int backedge_count; /* number of backedges */
158 long *nesting; /* Nesting level of BB*/
160 int maxlifetimes; /* copy from methodinfo to prevent passing methodinfo */
163 struct lifetime *lifetime; /* array of lifetimes */
164 int lifetimecount; /* number of lifetimes */
165 int *lt_used; /* index to lifetimearray for used lifetimes */
166 int *lt_int; /* index to lifetimearray for int lifetimes */
167 int lt_int_count; /* number of int/[lng]/[adr] lifetimes */
168 int *lt_flt; /* index to lifetimearray for float lifetimes */
169 int lt_flt_count; /* number of float/double lifetimes */
170 int *lt_mem; /* index to lifetimearray for all lifetimes */
171 /* not to be allocated in registers */
172 int lt_mem_count; /* number of this other lifetimes */
174 struct lifetime **active_tmp, **active_sav;
175 int active_tmp_top, active_sav_top;
177 struct lsra_exceptiontable *ex;
178 int v_index; /* next free index for stack slot lifetimes */
179 /* decrements from -1 */
182 bitvector *var_def; /* LocalVar Definition Bitvector [0..ls->bbcount] */
183 /* Bitvector holds ls->max_vars Bits */
184 bitvector *use_sites; /* LocalVar Use Bitvector[0..ls->maxvars] */
185 int **num_var_use; /* count of var_use[bb][var_index] */
186 int **var; /* [0..cd->maxlocal+cd->maxstack[[0..4] */
187 /* ssa_set_local_def and ssa_set_interface (called from analyse_stack) */
188 /* set var[local_index][local_type] and var[cd->maxlocals+stack_depth] */
189 /* [stack_type] to a unique type independend index [0..ls->max_vars[ */
190 /* unused entries are set to -1 */
192 int max_vars_with_indices;
193 int *num_defs; /* counts definitions of variables */
194 /* [0..cd->maxlocals*5+cd->maxstack*5[ */
195 /* valid for [0..ls->max_vars[ */
198 int *local_0; /* [0..ls->max_locals] */
199 /* local_0[a] with a in [0..ls->max_locals[ holds the */
201 /* local_0[ls->maxlocals] holds the number of local */
202 /* vars with indices */
203 int *interface_0; /* same here, just with interfaces */
205 int *var_to_index; /* var index to interface (<0) or local (>=0) index */
206 /* [0..cd->maxlocals*5+cd->maxstack*5[ */
207 /* valid for [0..ls->max_vars[ */
208 /* holds var_index or the negative interface index */
209 /* in ssa_Rename_init the indices are changed to the */
210 /* index of the corresponding first Var with index;) */
211 /* (== local_0[] or interface_0[] */
217 basicblock **basicblocks;
218 /* [0..ls->basicblockcount[[0..ls->max_locals[[0..ls->num_pre[bb]] */
219 /* 3rd index represents the the var involved in the phi function */
220 /* a0 = phi(a1,a2,...,a(ls->num_pre[bb]-1)) */
221 int ***phi; /* [0..ls->basicblockcount[[0..ls->max_vars[[0,1] */
222 /* if no phi function for a Basic Block and var exists */
223 /* phi[bb][a] == NULL */
225 int ***phi_moves; /* phi_moves[block_index][0..num_phi_moves[bi][0..1] */
229 int *count; /* Helpers for ssa_Rename */
233 /* structures for phi var interference graphs */
234 struct igraph_lookup **igraph_lookup; /* var to igraph index */
235 int igraph_lookup_top; /* number of entries in above table */
236 struct igraph *igraph; /* interference graphs */
244 struct freemem *next;
247 typedef struct lsradata lsradata;
249 /* function prototypes */
250 void lsra(jitdata *);
255 * These are local overrides for various environment variables in Emacs.
256 * Please do not remove this and leave it at the end of the file, where
257 * Emacs will automagically detect them.
258 * ---------------------------------------------------------------------
261 * indent-tabs-mode: t