1 /* src/vm/jit/reg.c - register allocator setup
3 Copyright (C) 1996-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
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., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
27 Authors: Andreas Krall
35 $Id: reg.c 5231 2006-08-11 10:13:28Z twisti $
49 #include "mm/memory.h"
50 #include "vm/jit/abi.h"
51 #include "vm/jit/reg.h"
54 /* reg_setup *******************************************************************
58 *******************************************************************************/
60 void reg_setup(jitdata *jd)
67 /* get required compiler data */
72 /* setup the integer register table */
75 /* On ARM longs can be split across argument regs and stack. This is
76 * signed by setting the HIGH_REG to INT_ARG_CNT in md_param_alloc().
77 * Here we make sure it resolves to a special dummy reg (REG_SPLIT). */
78 rd->argintregs = DMNEW(s4, INT_ARG_CNT + 1);
79 rd->argintregs[INT_ARG_CNT] = REG_SPLIT;
81 rd->argintregs = DMNEW(s4, INT_ARG_CNT);
83 rd->tmpintregs = DMNEW(s4, INT_TMP_CNT);
84 rd->savintregs = DMNEW(s4, INT_SAV_CNT);
85 rd->freeargintregs = DMNEW(s4, INT_ARG_CNT);
86 rd->freetmpintregs = DMNEW(s4, INT_TMP_CNT);
87 rd->freesavintregs = DMNEW(s4, INT_SAV_CNT);
93 for (i = 0; i < INT_REG_CNT; i++) {
94 switch (nregdescint[i]) {
99 rd->savintregs[rd->savintreguse++] = i;
102 rd->tmpintregs[rd->tmpintreguse++] = i;
105 rd->argintregs[rd->argintreguse++] = i;
109 assert(rd->savintreguse == INT_SAV_CNT);
110 assert(rd->tmpintreguse == INT_TMP_CNT);
111 assert(rd->argintreguse == INT_ARG_CNT);
113 #if defined(__X86_64__)
115 * on x86_64 the argument registers are not in ascending order
116 * a00 (%rdi) <-> a03 (%rcx) and a01 (%rsi) <-> a02 (%rdx)
118 i = rd->argintregs[3];
119 rd->argintregs[3] = rd->argintregs[0];
120 rd->argintregs[0] = i;
122 i = rd->argintregs[2];
123 rd->argintregs[2] = rd->argintregs[1];
124 rd->argintregs[1] = i;
127 #ifdef HAS_ADDRESS_REGISTER_FILE
128 /* setup the address register table */
130 rd->argadrregs = DMNEW(s4, ADR_ARG_CNT);
131 rd->tmpadrregs = DMNEW(s4, ADR_TMP_CNT);
132 rd->savadrregs = DMNEW(s4, ADR_SAV_CNT);
133 rd->freeargadrregs = DMNEW(s4, ADR_ARG_CNT);
134 rd->freetmpadrregs = DMNEW(s4, ADR_TMP_CNT);
135 rd->freesavadrregs = DMNEW(s4, ADR_SAV_CNT);
137 rd->adrreg_argnum = 0;
138 rd->argadrreguse = 0;
139 rd->tmpadrreguse = 0;
140 rd->savadrreguse = 0;
142 for (i = 0; i < ADR_REG_CNT; i++) {
143 switch (nregdescadr[i]) {
148 rd->savadrregs[rd->savadrreguse++] = i;
151 rd->tmpadrregs[rd->tmpadrreguse++] = i;
154 rd->argadrregs[rd->argadrreguse++] = i;
158 assert(rd->savadrreguse == ADR_SAV_CNT);
159 assert(rd->tmpadrreguse == ADR_TMP_CNT);
160 assert(rd->argadrreguse == ADR_ARG_CNT);
163 /* setup the float register table */
165 rd->argfltregs = DMNEW(s4, FLT_ARG_CNT);
166 rd->tmpfltregs = DMNEW(s4, FLT_TMP_CNT);
167 rd->savfltregs = DMNEW(s4, FLT_SAV_CNT);
168 rd->freeargfltregs = DMNEW(s4, FLT_ARG_CNT);
169 rd->freetmpfltregs = DMNEW(s4, FLT_TMP_CNT);
170 rd->freesavfltregs = DMNEW(s4, FLT_SAV_CNT);
172 rd->argfltreguse = 0;
173 rd->tmpfltreguse = 0;
174 rd->savfltreguse = 0;
176 for (i = 0; i < FLT_REG_CNT; i++) {
177 switch (nregdescfloat[i]) {
182 rd->savfltregs[rd->savfltreguse++] = i;
185 rd->tmpfltregs[rd->tmpfltreguse++] = i;
188 rd->argfltregs[rd->argfltreguse++] = i;
192 assert(rd->savfltreguse == FLT_SAV_CNT);
193 assert(rd->tmpfltreguse == FLT_TMP_CNT);
194 assert(rd->argfltreguse == FLT_ARG_CNT);
197 rd->freemem = DMNEW(s4, m->maxstack);
198 #if defined(HAS_4BYTE_STACKSLOT)
199 rd->freemem_2 = DMNEW(s4, m->maxstack);
201 rd->locals = DMNEW(varinfo5, m->maxlocals);
202 rd->interfaces = DMNEW(varinfo5, m->maxstack);
203 for (v = rd->locals, i = m->maxlocals; i > 0; v++, i--) {
204 v[0][TYPE_INT].type = -1;
205 v[0][TYPE_LNG].type = -1;
206 v[0][TYPE_FLT].type = -1;
207 v[0][TYPE_DBL].type = -1;
208 v[0][TYPE_ADR].type = -1;
210 v[0][TYPE_INT].regoff = 0;
211 v[0][TYPE_LNG].regoff = 0;
212 v[0][TYPE_FLT].regoff = 0;
213 v[0][TYPE_DBL].regoff = 0;
214 v[0][TYPE_ADR].regoff = 0;
217 for (v = rd->interfaces, i = m->maxstack; i > 0; v++, i--) {
218 v[0][TYPE_INT].type = -1;
219 v[0][TYPE_INT].flags = 0;
220 v[0][TYPE_LNG].type = -1;
221 v[0][TYPE_LNG].flags = 0;
222 v[0][TYPE_FLT].type = -1;
223 v[0][TYPE_FLT].flags = 0;
224 v[0][TYPE_DBL].type = -1;
225 v[0][TYPE_DBL].flags = 0;
226 v[0][TYPE_ADR].type = -1;
227 v[0][TYPE_ADR].flags = 0;
229 v[0][TYPE_INT].regoff = 0;
230 v[0][TYPE_LNG].regoff = 0;
231 v[0][TYPE_FLT].regoff = 0;
232 v[0][TYPE_DBL].regoff = 0;
233 v[0][TYPE_ADR].regoff = 0;
236 #if defined(SPECIALMEMUSE)
237 # if defined(__DARWIN__)
238 /* 6*4=24 byte linkage area + 8*4=32 byte minimum parameter Area */
239 rd->memuse = LA_SIZE_IN_POINTERS + INT_ARG_CNT;
241 rd->memuse = LA_SIZE_IN_POINTERS;
244 rd->memuse = 0; /* init to zero -> analyse_stack will set it to a higher */
245 /* value, if appropriate */
248 /* Set rd->arg*reguse to *_ARG_CNBT to not use unused argument */
249 /* registers as temp registers */
250 #if defined(HAS_ADDRESS_REGISTER_FILE)
251 rd->argadrreguse = 0;
252 #endif /* defined(HAS_ADDRESS_REGISTER_FILE) */
253 rd->argintreguse = 0;
254 rd->argfltreguse = 0;
259 * These are local overrides for various environment variables in Emacs.
260 * Please do not remove this and leave it at the end of the file, where
261 * Emacs will automagically detect them.
262 * ---------------------------------------------------------------------
265 * indent-tabs-mode: t
269 * vim:noexpandtab:sw=4:ts=4: