1 /* src/vm/jit/allocator/simplereg.c - register allocator
3 Copyright (C) 1996-2005, 2007 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 $Id: simplereg.c 8320 2007-08-16 11:35:14Z michi $
40 #include "mm/memory.h"
42 #include "vm/builtin.h"
43 #include "vm/exceptions.h"
44 #include "vm/resolve.h"
45 #include "vm/stringlocal.h"
47 #include "vm/jit/abi.h"
48 #include "vm/jit/reg.h"
49 #include "vm/jit/show.h"
50 #include "vm/jit/allocator/simplereg.h"
52 #include "vmcore/method.h"
53 #include "vmcore/options.h"
57 # define LOG(args) printf args
63 /* function prototypes for this file ******************************************/
65 static void simplereg_allocate_interfaces(jitdata *jd);
66 static void simplereg_allocate_locals(jitdata *jd);
67 static void simplereg_allocate_temporaries(jitdata *jd);
70 /* size of a stackslot used by the internal ABI */
72 #if defined(HAS_4BYTE_STACKSLOT)
73 # define SIZE_OF_STACKSLOT 4
75 # define SIZE_OF_STACKSLOT 8
79 /* total number of registers */
81 #if defined(HAS_ADDRESS_REGISTER_FILE)
82 #define TOTAL_REG_CNT (INT_REG_CNT + FLT_REG_CNT + ADR_REG_CNT)
84 #define TOTAL_REG_CNT (INT_REG_CNT + FLT_REG_CNT)
88 /* macros for handling register stacks ****************************************/
90 #define AVAIL_FRONT(cnt, limit) ((cnt) < (limit))
91 #define AVAIL_BACK(cnt) ((cnt) > 0)
93 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
94 #define AVAIL_FRONT_INT(cnt, limit) ((cnt) < (limit) - intregsneeded)
95 #define AVAIL_BACK_INT(cnt) ((cnt) > intregsneeded)
97 #define AVAIL_FRONT_INT(cnt, limit) AVAIL_FRONT(cnt, limit)
98 #define AVAIL_BACK_INT(cnt) AVAIL_BACK(cnt)
101 #define POP_FRONT(stk, cnt, reg) do { reg = stk[cnt++]; } while (0)
102 #define POP_BACK(stk, cnt, reg) do { reg = stk[--cnt]; } while (0)
103 #define PUSH_FRONT(stk, cnt, reg) do { stk[--cnt] = (reg); } while (0)
104 #define PUSH_BACK(stk, cnt, reg) do { stk[cnt++] = (reg); } while (0)
106 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
107 #define POP_FRONT_INT(stk, cnt, reg) \
109 if (intregsneeded) { \
110 reg = PACK_REGS(stk[cnt], stk[cnt+1]); \
114 POP_FRONT(stk, cnt, reg); \
117 #define POP_FRONT_INT(stk, cnt, reg) POP_FRONT(stk, cnt, reg)
120 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
121 #define POP_BACK_INT(stk, cnt, reg) \
123 if (intregsneeded) { \
125 reg = PACK_REGS(stk[cnt], stk[cnt+1]); \
128 POP_BACK(stk, cnt, reg); \
131 #define POP_BACK_INT(stk, cnt, reg) POP_BACK(stk, cnt, reg)
134 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
135 #define PUSH_BACK_INT(stk, cnt, reg) \
137 if (intregsneeded) { \
138 stk[cnt] = GET_LOW_REG(reg); \
139 stk[cnt + 1] = GET_HIGH_REG(reg); \
143 PUSH_BACK(stk, cnt, reg); \
146 #define PUSH_BACK_INT(stk, cnt, reg) PUSH_BACK(stk, cnt, reg)
149 #define AVAIL_ARG_FLT AVAIL_FRONT(rd->argfltreguse, FLT_ARG_CNT)
150 #define AVAIL_TMP_FLT AVAIL_BACK(rd->tmpfltreguse)
151 #define AVAIL_SAV_FLT AVAIL_BACK(rd->savfltreguse)
153 #define AVAIL_ARG_ADR AVAIL_FRONT(rd->argadrreguse, ADR_ARG_CNT)
154 #define AVAIL_TMP_ADR AVAIL_BACK(rd->tmpadrreguse)
155 #define AVAIL_SAV_ADR AVAIL_BACK(rd->savadrreguse)
157 #define AVAIL_ARG_INT AVAIL_FRONT_INT(rd->argintreguse, INT_ARG_CNT)
158 #define AVAIL_TMP_INT AVAIL_BACK_INT(rd->tmpintreguse)
159 #define AVAIL_SAV_INT AVAIL_BACK_INT(rd->savintreguse)
161 #define AVAIL_FREE_ARG_FLT AVAIL_BACK(rd->freeargflttop)
162 #define AVAIL_FREE_TMP_FLT AVAIL_BACK(rd->freetmpflttop)
163 #define AVAIL_FREE_SAV_FLT AVAIL_BACK(rd->freesavflttop)
165 #define AVAIL_FREE_ARG_ADR AVAIL_BACK(rd->freeargadrtop)
166 #define AVAIL_FREE_TMP_ADR AVAIL_BACK(rd->freetmpadrtop)
167 #define AVAIL_FREE_SAV_ADR AVAIL_BACK(rd->freesavadrtop)
169 #define AVAIL_FREE_ARG_INT AVAIL_BACK_INT(rd->freearginttop)
170 #define AVAIL_FREE_TMP_INT AVAIL_BACK_INT(rd->freetmpinttop)
171 #define AVAIL_FREE_SAV_INT AVAIL_BACK_INT(rd->freesavinttop)
173 #define TAKE_ARG_FLT(r) POP_FRONT(abi_registers_float_argument, rd->argfltreguse, r)
174 #define TAKE_TMP_FLT(r) POP_BACK(rd->tmpfltregs, rd->tmpfltreguse, r)
175 #define TAKE_SAV_FLT(r) POP_BACK(rd->savfltregs, rd->savfltreguse, r)
177 #define TAKE_ARG_ADR(r) POP_FRONT(rd->argadrregs, rd->argadrreguse, r)
178 #define TAKE_TMP_ADR(r) POP_BACK(rd->tmpadrregs, rd->tmpadrreguse, r)
179 #define TAKE_SAV_ADR(r) POP_BACK(rd->savadrregs, rd->savadrreguse, r)
181 #define TAKE_ARG_INT(r) POP_FRONT_INT(abi_registers_integer_argument, rd->argintreguse, r)
182 #define TAKE_TMP_INT(r) POP_BACK_INT(rd->tmpintregs, rd->tmpintreguse, r)
183 #define TAKE_SAV_INT(r) POP_BACK_INT(rd->savintregs, rd->savintreguse, r)
185 #define TAKE_FREE_ARG_FLT(r) POP_BACK(rd->freeargfltregs, rd->freeargflttop, r)
186 #define TAKE_FREE_TMP_FLT(r) POP_BACK(rd->freetmpfltregs, rd->freetmpflttop, r)
187 #define TAKE_FREE_SAV_FLT(r) POP_BACK(rd->freesavfltregs, rd->freesavflttop, r)
189 #define TAKE_FREE_ARG_ADR(r) POP_BACK(rd->freeargadrregs, rd->freeargadrtop, r)
190 #define TAKE_FREE_TMP_ADR(r) POP_BACK(rd->freetmpadrregs, rd->freetmpadrtop, r)
191 #define TAKE_FREE_SAV_ADR(r) POP_BACK(rd->freesavadrregs, rd->freesavadrtop, r)
193 #define TAKE_FREE_ARG_INT(r) POP_BACK_INT(rd->freeargintregs, rd->freearginttop, r)
194 #define TAKE_FREE_TMP_INT(r) POP_BACK_INT(rd->freetmpintregs, rd->freetmpinttop, r)
195 #define TAKE_FREE_SAV_INT(r) POP_BACK_INT(rd->freesavintregs, rd->freesavinttop, r)
197 #define PUSH_FREE_ARG_FLT(r) PUSH_BACK(rd->freeargfltregs, rd->freeargflttop, r)
198 #define PUSH_FREE_TMP_FLT(r) PUSH_BACK(rd->freetmpfltregs, rd->freetmpflttop, r)
199 #define PUSH_FREE_SAV_FLT(r) PUSH_BACK(rd->freesavfltregs, rd->freesavflttop, r)
201 #define PUSH_FREE_ARG_ADR(r) PUSH_BACK(rd->freeargadrregs, rd->freeargadrtop, r)
202 #define PUSH_FREE_TMP_ADR(r) PUSH_BACK(rd->freetmpadrregs, rd->freetmpadrtop, r)
203 #define PUSH_FREE_SAV_ADR(r) PUSH_BACK(rd->freesavadrregs, rd->freesavadrtop, r)
205 #define PUSH_FREE_ARG_INT(r) PUSH_BACK_INT(rd->freeargintregs, rd->freearginttop, r)
206 #define PUSH_FREE_TMP_INT(r) PUSH_BACK_INT(rd->freetmpintregs, rd->freetmpinttop, r)
207 #define PUSH_FREE_SAV_INT(r) PUSH_BACK_INT(rd->freesavintregs, rd->freesavinttop, r)
210 /* macros for allocating memory slots ****************************************/
212 #define NEW_MEM_SLOT(r) \
214 (r) = rd->memuse * SIZE_OF_STACKSLOT; \
215 rd->memuse += memneeded + 1; \
218 #define NEW_MEM_SLOT_ALIGNED(r) \
220 if ( (memneeded) && (rd->memuse & 1)) \
222 (r) = rd->memuse * SIZE_OF_STACKSLOT; \
223 rd->memuse += memneeded + 1; \
226 #define NEW_MEM_SLOT_ALIGNED_REUSE_PADDING(r) \
228 if ( (memneeded) && (rd->memuse & 1)) { \
229 PUSH_BACK(rd->freemem, rd->freememtop, rd->memuse); \
232 (r) = rd->memuse * SIZE_OF_STACKSLOT; \
233 rd->memuse += memneeded + 1; \
236 #if defined(ALIGN_LONGS_IN_MEMORY)
237 #define NEW_MEM_SLOT_INT_LNG(r) NEW_MEM_SLOT_ALIGNED(r)
239 #define NEW_MEM_SLOT_INT_LNG(r) NEW_MEM_SLOT(r)
242 #if defined(ALIGN_DOUBLES_IN_MEMORY)
243 #define NEW_MEM_SLOT_FLT_DBL(r) NEW_MEM_SLOT_ALIGNED(r)
245 #define NEW_MEM_SLOT_FLT_DBL(r) NEW_MEM_SLOT(r)
248 #if defined(ALIGN_LONGS_IN_MEMORY) || defined(ALIGN_DOUBLES_IN_MEMORY)
249 #define NEW_MEM_SLOT_REUSE_PADDING(r) NEW_MEM_SLOT_ALIGNED_REUSE_PADDING(r)
251 #define NEW_MEM_SLOT_REUSE_PADDING(r) NEW_MEM_SLOT(r)
255 /* macros for creating/freeing temporary variables ***************************/
257 #define NEW_TEMP_REG(index) \
258 if ( ((index) >= jd->localcount) \
259 && (!(VAR(index)->flags & (INOUT | PREALLOC))) ) \
260 simplereg_new_temp(jd, (index))
263 #define FREE_TEMP_REG(index) \
264 if (((index) > jd->localcount) \
265 && (!(VAR(index)->flags & (PREALLOC)))) \
266 simplereg_free_temp(jd, (index))
269 /* macro for getting a unique register index *********************************/
271 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
272 #define REG_INDEX_NON_ADR(regoff, type) \
273 (IS_FLT_DBL_TYPE(type) ? (INT_REG_CNT + (regoff)) : (GET_LOW_REG(regoff)))
275 #define REG_INDEX_NON_ADR(regoff, type) \
276 (IS_FLT_DBL_TYPE(type) ? (INT_REG_CNT + (regoff)) : (regoff))
279 #if defined(HAS_ADDRESS_REGISTER_FILE)
280 #define REG_INDEX(regoff, type) \
281 (IS_ADR_TYPE(type) ? (regoff) : (ADR_REG_CNT + REG_INDEX_NON_ADR(regoff, type)))
283 #define REG_INDEX(regoff, type) REG_INDEX_NON_ADR(regoff, type)
287 /* regalloc ********************************************************************
289 Does a simple register allocation.
291 *******************************************************************************/
293 bool regalloc(jitdata *jd)
295 /* There is a problem with the use of unused float argument
296 registers in leafmethods for stackslots on c7 (2 * Dual Core
297 AMD Opteron(tm) Processor 270) - runtime for the jvm98 _mtrt
298 benchmark is heaviliy increased. This could be prevented by
299 setting rd->argfltreguse to FLT_ARG_CNT before calling
300 simplereg_allocate_temporaries and setting it back to the original
301 value before calling simplereg_allocate_locals. */
303 simplereg_allocate_interfaces(jd);
304 simplereg_allocate_temporaries(jd);
305 simplereg_allocate_locals(jd);
313 /* simplereg_allocate_interfaces ***********************************************
315 Allocates registers for all interface variables.
317 *******************************************************************************/
319 static void simplereg_allocate_interfaces(jitdata *jd)
326 int intalloc, fltalloc; /* Remember allocated Register/Memory offset */
327 /* in case more vars are packed into this interface slot */
329 /* Allocate LNG and DBL types first to ensure 2 memory slots or */
330 /* registers on HAS_4BYTE_STACKSLOT architectures. */
331 int typeloop[] = { TYPE_LNG, TYPE_DBL, TYPE_INT, TYPE_FLT, TYPE_ADR };
333 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
337 /* get required compiler data */
343 /* rd->memuse was already set in stack.c to allocate stack space
344 for passing arguments to called methods. */
346 #if defined(__I386__)
347 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
348 /* reserve 0(%esp) for Monitorenter/exit Argument on i386 */
354 if (jd->isleafmethod) {
355 /* Reserve argument register, which will be used for Locals acting */
357 if (rd->argintreguse < m->parseddesc->argintreguse)
358 rd->argintreguse = m->parseddesc->argintreguse;
359 if (rd->argfltreguse < m->parseddesc->argfltreguse)
360 rd->argfltreguse = m->parseddesc->argfltreguse;
361 #ifdef HAS_ADDRESS_REGISTER_FILE
362 if (rd->argadrreguse < m->parseddesc->argadrreguse)
363 rd->argadrreguse = m->parseddesc->argadrreguse;
367 for (s = 0; s < jd->maxinterfaces; s++) {
368 intalloc = -1; fltalloc = -1;
370 /* check if the interface at this stack depth must be a SAVEDVAR */
374 for (tt = 0; tt <=4; tt++) {
375 if ((t = jd->interface_map[s * 5 + tt].flags) != UNUSED) {
376 saved |= t & SAVEDVAR;
380 /* allocate reg/mem for each type the interface is used as */
382 for (tt = 0; tt <= 4; tt++) {
384 if (jd->interface_map[s * 5 + t].flags == UNUSED)
388 regoff = -1; /* initialize to invalid value */
390 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
391 intregsneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
394 #if defined(HAS_4BYTE_STACKSLOT)
395 memneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
399 #if defined(HAS_ADDRESS_REGISTER_FILE)
400 if (IS_ADR_TYPE(t)) {
401 if (!jd->isleafmethod && AVAIL_ARG_ADR) {
403 TAKE_ARG_ADR(regoff);
405 else if (AVAIL_TMP_ADR) {
406 TAKE_TMP_ADR(regoff);
408 else if (AVAIL_SAV_ADR) {
410 TAKE_SAV_ADR(regoff);
414 regoff = rd->memuse++ * SIZE_OF_STACKSLOT;
417 else /* !IS_ADR_TYPE */
418 #endif /* defined(HAS_ADDRESS_REGISTER_FILE) */
420 if (IS_FLT_DBL_TYPE(t)) {
422 /* Reuse memory slot(s)/register(s) for shared interface slots */
423 flags |= jd->interface_map[fltalloc].flags & ~SAVEDVAR;
424 regoff = jd->interface_map[fltalloc].regoff;
426 else if (AVAIL_ARG_FLT) {
428 TAKE_ARG_FLT(regoff);
430 else if (AVAIL_TMP_FLT) {
431 TAKE_TMP_FLT(regoff);
433 else if (AVAIL_SAV_FLT) {
435 TAKE_SAV_FLT(regoff);
439 NEW_MEM_SLOT_FLT_DBL(regoff);
441 fltalloc = s * 5 + t;
443 else { /* !IS_FLT_DBL_TYPE(t) */
444 #if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
446 * for i386 put all longs in memory
448 if (IS_2_WORD_TYPE(t)) {
450 NEW_MEM_SLOT_INT_LNG(regoff);
455 /* Reuse memory slot(s)/register(s) for shared interface slots */
456 flags |= jd->interface_map[intalloc].flags & ~SAVEDVAR;
457 regoff = jd->interface_map[intalloc].regoff;
458 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
459 /* reuse lower half */
460 if (!(flags & INMEMORY)
461 && IS_2_WORD_TYPE(intalloc % 5))
462 regoff = GET_LOW_REG(regoff);
468 TAKE_ARG_INT(regoff);
470 else if (AVAIL_TMP_INT) {
471 TAKE_TMP_INT(regoff);
473 else if (AVAIL_SAV_INT) {
475 TAKE_SAV_INT(regoff);
479 NEW_MEM_SLOT_INT_LNG(regoff);
483 intalloc = s * 5 + t;
484 } /* if (IS_FLT_DBL_TYPE(t)) */
488 /* now the same like above, but without a chance to take a temporary register */
489 #ifdef HAS_ADDRESS_REGISTER_FILE
490 if (IS_ADR_TYPE(t)) {
492 TAKE_SAV_ADR(regoff);
496 regoff = rd->memuse++ * SIZE_OF_STACKSLOT;
502 if (IS_FLT_DBL_TYPE(t)) {
504 flags |= jd->interface_map[fltalloc].flags & ~SAVEDVAR;
505 regoff = jd->interface_map[fltalloc].regoff;
509 TAKE_SAV_FLT(regoff);
513 NEW_MEM_SLOT_FLT_DBL(regoff);
516 fltalloc = s * 5 + t;
518 else { /* IS_INT_LNG */
519 #if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
521 * for i386 put all longs in memory
523 if (IS_2_WORD_TYPE(t)) {
525 NEW_MEM_SLOT_INT_LNG(regoff);
531 flags |= jd->interface_map[intalloc].flags & ~SAVEDVAR;
532 regoff = jd->interface_map[intalloc].regoff;
533 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
534 /* reuse lower half */
535 if (!(flags & INMEMORY)
536 && IS_2_WORD_TYPE(intalloc % 5))
537 regoff = GET_LOW_REG(regoff);
542 TAKE_SAV_INT(regoff);
546 NEW_MEM_SLOT_INT_LNG(regoff);
551 } /* if (IS_FLT_DBL_TYPE(t) else */
552 } /* if (IS_ADR_TYPE(t)) else */
553 } /* if (saved) else */
557 jd->interface_map[5*s + t].flags = flags | INOUT;
558 jd->interface_map[5*s + t].regoff = regoff;
564 /* simplereg_allocate_locals_leafmethod ****************************************
566 Allocates registers for all local variables of a leafmethod.
568 *******************************************************************************/
570 static void simplereg_allocate_locals_leafmethod(jitdata *jd)
577 int p, s, t, tt, varindex;
578 int intalloc, fltalloc;
580 int intregsneeded = 0;
582 int typeloop[] = { TYPE_LNG, TYPE_DBL, TYPE_INT, TYPE_FLT, TYPE_ADR };
583 int fargcnt, iargcnt;
584 #ifdef HAS_ADDRESS_REGISTER_FILE
588 /* get required compiler data */
596 iargcnt = rd->argintreguse;
597 fargcnt = rd->argfltreguse;
598 #ifdef HAS_ADDRESS_REGISTER_FILE
599 aargcnt = rd->argadrreguse;
601 for (p = 0, s = 0; s < jd->maxlocals; s++, p++) {
602 intalloc = -1; fltalloc = -1;
603 for (tt = 0; tt <= 4; tt++) {
605 varindex = jd->local_map[s * 5 + t];
606 if (varindex == UNUSED)
611 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
612 intregsneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
614 #if defined(HAS_4BYTE_STACKSLOT)
615 memneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
621 * #ifdef HAS_ADDRESS_REGISTER_FILE
628 * } else { / int & lng
632 * must not to be changed!
635 #ifdef HAS_ADDRESS_REGISTER_FILE
636 if (IS_ADR_TYPE(t)) {
637 if ((p < md->paramcount) && !md->params[p].inmemory) {
639 v->vv.regoff = rd->argadrregs[md->params[p].regoff];
641 else if (AVAIL_TMP_ADR) {
643 TAKE_TMP_ADR(v->vv.regoff);
645 /* use unused argument registers as local registers */
646 else if ((p >= md->paramcount) &&
647 (aargcnt < ADR_ARG_CNT))
650 POP_FRONT(rd->argadrregs, aargcnt, v->vv.regoff);
652 else if (AVAIL_SAV_ADR) {
654 TAKE_SAV_ADR(v->vv.regoff);
657 v->flags |= INMEMORY;
658 v->vv.regoff = rd->memuse++ * SIZE_OF_STACKSLOT;
663 if (IS_FLT_DBL_TYPE(t)) {
665 v->flags = VAR(fltalloc)->flags;
666 v->vv.regoff = VAR(fltalloc)->vv.regoff;
668 #if !defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
669 /* We can only use float arguments as local variables,
670 * if we do not pass them in integer registers. */
671 else if ((p < md->paramcount) && !md->params[p].inmemory) {
673 v->vv.regoff = md->params[p].regoff;
676 else if (AVAIL_TMP_FLT) {
678 TAKE_TMP_FLT(v->vv.regoff);
680 /* use unused argument registers as local registers */
681 else if ((p >= md->paramcount) && (fargcnt < FLT_ARG_CNT)) {
683 POP_FRONT(abi_registers_float_argument,
684 fargcnt, v->vv.regoff);
686 else if (AVAIL_SAV_FLT) {
688 TAKE_SAV_FLT(v->vv.regoff);
692 NEW_MEM_SLOT_FLT_DBL(v->vv.regoff);
694 fltalloc = jd->local_map[s * 5 + t];
698 #if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
700 * for i386 put all longs in memory
702 if (IS_2_WORD_TYPE(t)) {
704 NEW_MEM_SLOT_INT_LNG(v->vv.regoff);
710 v->flags = VAR(intalloc)->flags;
711 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
712 if (!(v->flags & INMEMORY)
713 && IS_2_WORD_TYPE(VAR(intalloc)->type))
714 v->vv.regoff = GET_LOW_REG(
715 VAR(intalloc)->vv.regoff);
718 v->vv.regoff = VAR(intalloc)->vv.regoff;
720 else if ((p < md->paramcount) &&
721 !md->params[p].inmemory)
724 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
725 if (IS_2_WORD_TYPE(t))
727 PACK_REGS(GET_LOW_REG(md->params[p].regoff),
728 GET_HIGH_REG(md->params[p].regoff));
731 v->vv.regoff = md->params[p].regoff;
733 else if (AVAIL_TMP_INT) {
735 TAKE_TMP_INT(v->vv.regoff);
738 * use unused argument registers as local registers
740 else if ((p >= m->parseddesc->paramcount) &&
741 (iargcnt + intregsneeded < INT_ARG_CNT))
744 POP_FRONT_INT(abi_registers_integer_argument,
745 iargcnt, v->vv.regoff);
747 else if (AVAIL_SAV_INT) {
749 TAKE_SAV_INT(v->vv.regoff);
753 NEW_MEM_SLOT_INT_LNG(v->vv.regoff);
756 intalloc = jd->local_map[s * 5 + t];
758 #ifdef HAS_ADDRESS_REGISTER_FILE
761 } /* for (tt=0;...) */
763 /* If the current parameter is a 2-word type, the next local slot */
766 if (p < md->paramcount)
767 if (IS_2_WORD_TYPE(md->paramtypes[p].type))
772 /* simplereg_allocate_locals ***************************************************
774 Allocates registers for all local variables.
776 *******************************************************************************/
778 static void simplereg_allocate_locals(jitdata *jd)
783 int s, t, tt, varindex;
784 int intalloc, fltalloc;
787 int typeloop[] = { TYPE_LNG, TYPE_DBL, TYPE_INT, TYPE_FLT, TYPE_ADR };
788 #ifdef SUPPORT_COMBINE_INTEGER_REGISTERS
792 /* get required compiler data */
797 if (jd->isleafmethod) {
798 simplereg_allocate_locals_leafmethod(jd);
802 for (s = 0; s < jd->maxlocals; s++) {
803 intalloc = -1; fltalloc = -1;
804 for (tt=0; tt<=4; tt++) {
807 varindex = jd->local_map[s * 5 + t];
808 if (varindex == UNUSED)
813 #ifdef SUPPORT_COMBINE_INTEGER_REGISTERS
814 intregsneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
817 #if defined(HAS_4BYTE_STACKSLOT)
818 memneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
821 #ifdef HAS_ADDRESS_REGISTER_FILE
822 if (IS_ADR_TYPE(t)) {
825 TAKE_SAV_ADR(v->vv.regoff);
829 v->vv.regoff = rd->memuse++ * SIZE_OF_STACKSLOT;
834 if (IS_FLT_DBL_TYPE(t)) {
836 v->flags = VAR(fltalloc)->flags;
837 v->vv.regoff = VAR(fltalloc)->vv.regoff;
839 else if (AVAIL_SAV_FLT) {
841 TAKE_SAV_FLT(v->vv.regoff);
845 NEW_MEM_SLOT_FLT_DBL(v->vv.regoff);
847 fltalloc = jd->local_map[s * 5 + t];
850 #if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
852 * for i386 put all longs in memory
854 if (IS_2_WORD_TYPE(t)) {
856 NEW_MEM_SLOT_INT_LNG(v->vv.regoff);
861 v->flags = VAR(intalloc)->flags;
862 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
863 if (!(v->flags & INMEMORY)
864 && IS_2_WORD_TYPE(VAR(intalloc)->type))
865 v->vv.regoff = GET_LOW_REG(
866 VAR(intalloc)->vv.regoff);
869 v->vv.regoff = VAR(intalloc)->vv.regoff;
871 else if (AVAIL_SAV_INT) {
873 TAKE_SAV_INT(v->vv.regoff);
877 NEW_MEM_SLOT_INT_LNG(v->vv.regoff);
879 #if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
882 intalloc = jd->local_map[s * 5 + t];
884 #ifdef HAS_ADDRESS_REGISTER_FILE
892 static void simplereg_init(jitdata *jd, registerdata *rd)
897 #if defined(HAS_4BYTE_STACKSLOT)
898 rd->freememtop_2 = 0;
901 rd->freetmpinttop = 0;
902 rd->freesavinttop = 0;
903 rd->freetmpflttop = 0;
904 rd->freesavflttop = 0;
905 #ifdef HAS_ADDRESS_REGISTER_FILE
906 rd->freetmpadrtop = 0;
907 rd->freesavadrtop = 0;
910 rd->freearginttop = 0;
911 rd->freeargflttop = 0;
912 #ifdef HAS_ADDRESS_REGISTER_FILE
913 rd->freeargadrtop = 0;
916 rd->regisoutvar = DMNEW(int, TOTAL_REG_CNT);
917 rd->regcopycount = DMNEW(int, TOTAL_REG_CNT);
918 MZERO(rd->regcopycount, int, TOTAL_REG_CNT);
920 /* memcopycount is dynamically allocated when needed */
922 rd->memcopycount = NULL;
923 rd->memcopycountsize = 0;
925 rd->intusedinout = DMNEW(int, INT_REG_CNT);
926 MZERO(rd->intusedinout, int, INT_REG_CNT);
927 rd->fltusedinout = DMNEW(int, FLT_REG_CNT);
928 MZERO(rd->fltusedinout, int, FLT_REG_CNT);
930 /* record the interface registers as used */
932 for (i=0; i<rd->argintreguse; ++i)
933 rd->intusedinout[abi_registers_integer_argument[i]] = 1;
934 for (i=rd->tmpintreguse; i<INT_TMP_CNT; ++i)
935 rd->intusedinout[rd->tmpintregs[i]] = 1;
936 for (i=rd->savintreguse; i<INT_SAV_CNT; ++i)
937 rd->intusedinout[rd->savintregs[i]] = 1;
939 for (i=0; i<rd->argfltreguse; ++i)
940 rd->fltusedinout[abi_registers_float_argument[i]] = 1;
941 for (i=rd->tmpfltreguse; i<FLT_TMP_CNT; ++i)
942 rd->fltusedinout[rd->tmpfltregs[i]] = 1;
943 for (i=rd->savfltreguse; i<FLT_SAV_CNT; ++i)
944 rd->fltusedinout[rd->savfltregs[i]] = 1;
946 #ifdef HAS_ADDRESS_REGISTER_FILE
947 rd->adrusedinout = DMNEW(int, ADR_REG_CNT);
948 MZERO(rd->adrusedinout, int, ADR_REG_CNT);
950 for (i=0; i<rd->argadrreguse; ++i)
951 rd->adrusedinout[rd->argadrregs[i]] = 1;
952 for (i=rd->tmpadrreguse; i<ADR_TMP_CNT; ++i)
953 rd->adrusedinout[rd->tmpadrregs[i]] = 1;
954 for (i=rd->savadrreguse; i<ADR_SAV_CNT; ++i)
955 rd->adrusedinout[rd->savadrregs[i]] = 1;
960 static void simplereg_init_block(registerdata *rd)
964 /* remove all interface registers from the free lists */
966 for (i=0; i<rd->freearginttop; ++i)
967 if (rd->intusedinout[rd->freeargintregs[i]]) {
968 rd->freeargintregs[i--] = rd->freeargintregs[--rd->freearginttop];
970 for (i=0; i<rd->freetmpinttop; ++i)
971 if (rd->intusedinout[rd->freetmpintregs[i]]) {
972 rd->freetmpintregs[i--] = rd->freetmpintregs[--rd->freetmpinttop];
974 for (i=0; i<rd->freesavinttop; ++i)
975 if (rd->intusedinout[rd->freesavintregs[i]]) {
976 rd->freesavintregs[i--] = rd->freesavintregs[--rd->freesavinttop];
979 for (i=0; i<rd->freeargflttop; ++i)
980 if (rd->fltusedinout[rd->freeargfltregs[i]]) {
981 rd->freeargfltregs[i--] = rd->freeargfltregs[--rd->freeargflttop];
983 for (i=0; i<rd->freetmpflttop; ++i)
984 if (rd->fltusedinout[rd->freetmpfltregs[i]]) {
985 rd->freetmpfltregs[i--] = rd->freetmpfltregs[--rd->freetmpflttop];
987 for (i=0; i<rd->freesavflttop; ++i)
988 if (rd->fltusedinout[rd->freesavfltregs[i]]) {
989 rd->freesavfltregs[i--] = rd->freesavfltregs[--rd->freesavflttop];
992 #ifdef HAS_ADDRESS_REGISTER_FILE
993 for (i=0; i<rd->freeargadrtop; ++i)
994 if (rd->adrusedinout[rd->freeargadrregs[i]]) {
995 rd->freeargadrregs[i--] = rd->freeargadrregs[--rd->freeargadrtop];
997 for (i=0; i<rd->freetmpadrtop; ++i)
998 if (rd->adrusedinout[rd->freetmpadrregs[i]]) {
999 rd->freetmpadrregs[i--] = rd->freetmpadrregs[--rd->freetmpadrtop];
1001 for (i=0; i<rd->freesavadrtop; ++i)
1002 if (rd->adrusedinout[rd->freesavadrregs[i]]) {
1003 rd->freesavadrregs[i--] = rd->freesavadrregs[--rd->freesavadrtop];
1009 static void simplereg_new_temp(jitdata *jd, s4 index)
1011 #ifdef SUPPORT_COMBINE_INTEGER_REGISTERS
1022 /* assert that constants are not allocated */
1024 assert(v->type != TYPE_RET);
1026 /* Try to allocate a saved register if there is no temporary one */
1027 /* available. This is what happens during the second run. */
1028 tryagain = (v->flags & SAVEDVAR) ? 1 : 2;
1030 #ifdef SUPPORT_COMBINE_INTEGER_REGISTERS
1031 intregsneeded = (IS_2_WORD_TYPE(v->type)) ? 1 : 0;
1034 #if defined(HAS_4BYTE_STACKSLOT)
1035 memneeded = (IS_2_WORD_TYPE(v->type)) ? 1 : 0;
1040 for(; tryagain; --tryagain) {
1041 if (tryagain == 1) {
1042 if (!(v->flags & SAVEDVAR))
1044 #ifdef HAS_ADDRESS_REGISTER_FILE
1045 if (IS_ADR_TYPE(v->type)) {
1046 if (AVAIL_FREE_SAV_ADR) {
1047 TAKE_FREE_SAV_ADR(v->vv.regoff);
1050 else if (AVAIL_SAV_ADR) {
1051 TAKE_SAV_ADR(v->vv.regoff);
1058 if (IS_FLT_DBL_TYPE(v->type)) {
1059 if (AVAIL_FREE_SAV_FLT) {
1060 TAKE_FREE_SAV_FLT(v->vv.regoff);
1063 else if (AVAIL_SAV_FLT) {
1064 TAKE_SAV_FLT(v->vv.regoff);
1069 #if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1071 * for i386 put all longs in memory
1073 if (!IS_2_WORD_TYPE(v->type))
1076 if (AVAIL_FREE_SAV_INT) {
1077 TAKE_FREE_SAV_INT(v->vv.regoff);
1080 else if (AVAIL_SAV_INT) {
1081 TAKE_SAV_INT(v->vv.regoff);
1088 else { /* tryagain == 2 */
1089 #ifdef HAS_ADDRESS_REGISTER_FILE
1090 if (IS_ADR_TYPE(v->type)) {
1091 if (AVAIL_FREE_TMP_ADR) {
1092 TAKE_FREE_TMP_ADR(v->vv.regoff);
1095 else if (AVAIL_TMP_ADR) {
1096 TAKE_TMP_ADR(v->vv.regoff);
1103 if (IS_FLT_DBL_TYPE(v->type)) {
1104 if (AVAIL_FREE_ARG_FLT) {
1106 TAKE_FREE_ARG_FLT(v->vv.regoff);
1109 else if (AVAIL_ARG_FLT) {
1111 TAKE_ARG_FLT(v->vv.regoff);
1114 else if (AVAIL_FREE_TMP_FLT) {
1115 TAKE_FREE_TMP_FLT(v->vv.regoff);
1118 else if (AVAIL_TMP_FLT) {
1119 TAKE_TMP_FLT(v->vv.regoff);
1125 #if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1127 * for i386 put all longs in memory
1129 if (!IS_2_WORD_TYPE(v->type))
1132 if (AVAIL_FREE_ARG_INT) {
1134 TAKE_FREE_ARG_INT(v->vv.regoff);
1137 else if (AVAIL_ARG_INT) {
1139 TAKE_ARG_INT(v->vv.regoff);
1142 else if (AVAIL_FREE_TMP_INT) {
1143 TAKE_FREE_TMP_INT(v->vv.regoff);
1146 else if (AVAIL_TMP_INT) {
1147 TAKE_TMP_INT(v->vv.regoff);
1150 } /* if (!IS_2_WORD_TYPE(s->type)) */
1151 } /* if (IS_FLT_DBL_TYPE(s->type)) */
1152 } /* if (IS_ADR_TYPE(s->type)) */
1153 } /* if (tryagain == 1) else */
1154 } /* for(; tryagain; --tryagain) */
1156 /* spill to memory */
1158 v->flags |= INMEMORY;
1160 #if defined(HAS_4BYTE_STACKSLOT)
1161 if ((memneeded == 1) && (rd->freememtop_2 > 0))
1162 POP_BACK(rd->freemem_2, rd->freememtop_2, v->vv.regoff);
1164 #endif /*defined(HAS_4BYTE_STACKSLOT) */
1165 if ((memneeded == 0) && (rd->freememtop > 0))
1166 POP_BACK(rd->freemem, rd->freememtop, v->vv.regoff);
1168 NEW_MEM_SLOT_REUSE_PADDING(v->vv.regoff);
1172 static void simplereg_free(registerdata *rd, s4 flags, s4 regoff, s4 type)
1174 /* assert that constants are not freed */
1176 assert(type != TYPE_RET);
1178 /* if this is a copy of another variable, just decrement the copy counter */
1180 if (flags & INMEMORY) {
1186 memindex = regoff / SIZE_OF_STACKSLOT;
1188 if (memindex < rd->memcopycountsize && rd->memcopycount[memindex]) {
1189 rd->memcopycount[memindex]--;
1196 regindex = REG_INDEX(regoff, type);
1198 /* do not free interface registers that are needed as outvars */
1200 if (flags & INOUT) {
1201 if (rd->regisoutvar[regindex]) {
1202 LOG(("DONT FREE f=%02x r=%d t=%d\n", flags, regoff, type));
1206 LOG(("FREEING INVAR f=%02x r=%d t=%d\n", flags, regoff, type));
1209 if (rd->regcopycount[regindex]) {
1210 rd->regcopycount[regindex]--;
1215 if (flags & INMEMORY) {
1216 #if defined(HAS_4BYTE_STACKSLOT)
1217 if (IS_2_WORD_TYPE(type))
1218 PUSH_BACK(rd->freemem_2, rd->freememtop_2, regoff);
1221 PUSH_BACK(rd->freemem, rd->freememtop, regoff);
1226 /* freeing a register */
1228 #ifdef HAS_ADDRESS_REGISTER_FILE
1229 if (IS_ADR_TYPE(type)) {
1230 if (flags & (SAVEDVAR | SAVREG))
1231 PUSH_FREE_SAV_ADR(regoff);
1233 PUSH_FREE_TMP_ADR(regoff);
1236 else if (IS_FLT_DBL_TYPE(type)) {
1237 if (flags & (SAVEDVAR | SAVREG))
1238 PUSH_FREE_SAV_FLT(regoff);
1239 else if (flags & ARGREG)
1240 PUSH_FREE_ARG_FLT(regoff);
1242 PUSH_FREE_TMP_FLT(regoff);
1244 else { /* IS_INT_LNG_TYPE */
1245 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1246 s4 intregsneeded = (IS_2_WORD_TYPE(type)) ? 1 : 0;
1249 if (flags & (SAVEDVAR | SAVREG))
1250 PUSH_FREE_SAV_INT(regoff);
1251 else if (flags & ARGREG)
1252 PUSH_FREE_ARG_INT(regoff);
1254 PUSH_FREE_TMP_INT(regoff);
1259 static inline void simplereg_free_temp(jitdata *jd, s4 index)
1265 simplereg_free(jd->rd, v->flags, v->vv.regoff, v->type);
1269 static bool simplereg_alloc_dup(jitdata *jd, s4 srcindex, s4 dstindex)
1274 /* do not coalesce local variables here */
1276 if (srcindex <= jd->localcount || dstindex <= jd->localcount)
1282 /* do not coalesce in/out vars or preallocated variables here */
1284 if ((sv->flags | dv->flags) & (INOUT | PREALLOC))
1287 /* if the source is in memory, we can coalesce in any case */
1289 if (sv->flags & INMEMORY) {
1290 dv->flags |= INMEMORY;
1291 dv->vv.regoff = sv->vv.regoff;
1295 /* we do not allocate a REG_TMP to a REG_SAV variable */
1297 if ((sv->flags & SAVEDVAR) != (dv->flags & SAVEDVAR))
1301 dv->vv.regoff = sv->vv.regoff;
1302 dv->flags |= sv->flags & (SAVREG | ARGREG);
1308 /* simplereg_allocate_temporaries **********************************************
1310 Allocate temporary (non-interface, non-local) registers.
1312 *******************************************************************************/
1314 static void simplereg_allocate_temporaries(jitdata *jd)
1322 builtintable_entry *bte;
1331 /* get required compiler data */
1336 /* initialize temp registers */
1338 simplereg_init(jd, rd);
1340 bptr = jd->basicblocks;
1342 while (bptr != NULL) {
1343 if (bptr->flags >= BBREACHED) {
1345 LOG(("\nallocating block L%03d\n", bptr->nr));
1347 simplereg_init_block(rd);
1349 /* assert that all copy counts are zero */
1351 #if !defined(NDEBUG)
1352 for (i=0; i < TOTAL_REG_CNT; ++i)
1353 assert(rd->regcopycount[i] == 0);
1356 /* reset outvar flags */
1358 MZERO(rd->regisoutvar, int, TOTAL_REG_CNT);
1360 /* set allocation of invars */
1362 for (i=0; i<bptr->indepth; ++i)
1364 v = VAR(bptr->invars[i]);
1365 if (v->type == TYPE_RET)
1368 v->vv.regoff = jd->interface_map[5*i + v->type].regoff;
1369 v->flags = jd->interface_map[5*i + v->type].flags;
1371 if (!(v->flags & INMEMORY))
1372 rd->regcopycount[REG_INDEX(v->vv.regoff, v->type)] = 1;
1375 /* set allocation of outvars */
1377 for (i=0; i<bptr->outdepth; ++i)
1379 v = VAR(bptr->outvars[i]);
1380 if (v->type == TYPE_RET)
1383 v->vv.regoff = jd->interface_map[5*i + v->type].regoff;
1384 v->flags = jd->interface_map[5*i + v->type].flags;
1386 if (!(v->flags & INMEMORY)) {
1387 regindex = REG_INDEX(v->vv.regoff, v->type);
1388 rd->regcopycount[regindex] = 1;
1389 rd->regisoutvar[regindex] = 1;
1393 /* free interface registers not used in this block */
1395 for (i=0; i < 5 * jd->maxinterfaces; ++i) {
1397 regoff = jd->interface_map[i].regoff;
1398 flags = jd->interface_map[i].flags;
1400 if (!(flags & INMEMORY)) {
1401 if (!rd->regcopycount[REG_INDEX(regoff, type)]) {
1402 LOG(("MAY REUSE interface register f=%02x r=%d t=%d\n",
1403 flags, regoff, type));
1404 simplereg_free(rd, flags, regoff, type);
1406 /* mark it, so it is not freed again */
1407 rd->regcopycount[REG_INDEX(regoff, type)] = -1;
1412 /* reset copy counts */
1414 MZERO(rd->regcopycount, int, TOTAL_REG_CNT);
1416 /* iterate over ICMDS to allocate temporary variables */
1418 iptr = bptr->iinstr;
1421 while (--len >= 0) {
1423 switch (iptr->opc) {
1429 case ICMD_CHECKNULL:
1434 case ICMD_PUTSTATICCONST:
1435 case ICMD_INLINE_START:
1436 case ICMD_INLINE_END:
1437 case ICMD_INLINE_BODY:
1440 /* pop 0 push 1 const */
1448 /* pop 0 push 1 load */
1455 NEW_TEMP_REG(iptr->dst.varindex);
1469 FREE_TEMP_REG(iptr->sx.s23.s2.varindex);
1470 FREE_TEMP_REG(iptr->s1.varindex);
1471 NEW_TEMP_REG(iptr->dst.varindex);
1485 FREE_TEMP_REG(iptr->sx.s23.s3.varindex);
1486 FREE_TEMP_REG(iptr->sx.s23.s2.varindex);
1487 FREE_TEMP_REG(iptr->s1.varindex);
1490 /* pop 1 push 0 store */
1510 case ICMD_PUTSTATIC:
1511 case ICMD_PUTFIELDCONST:
1513 /* pop 1 push 0 branch */
1516 case ICMD_IFNONNULL:
1532 /* pop 1 push 0 table branch */
1534 case ICMD_TABLESWITCH:
1535 case ICMD_LOOKUPSWITCH:
1537 case ICMD_MONITORENTER:
1538 case ICMD_MONITOREXIT:
1539 FREE_TEMP_REG(iptr->s1.varindex);
1542 /* pop 2 push 0 branch */
1544 case ICMD_IF_ICMPEQ:
1545 case ICMD_IF_ICMPNE:
1546 case ICMD_IF_ICMPLT:
1547 case ICMD_IF_ICMPGE:
1548 case ICMD_IF_ICMPGT:
1549 case ICMD_IF_ICMPLE:
1551 case ICMD_IF_LCMPEQ:
1552 case ICMD_IF_LCMPNE:
1553 case ICMD_IF_LCMPLT:
1554 case ICMD_IF_LCMPGE:
1555 case ICMD_IF_LCMPGT:
1556 case ICMD_IF_LCMPLE:
1558 case ICMD_IF_FCMPEQ:
1559 case ICMD_IF_FCMPNE:
1561 case ICMD_IF_FCMPL_LT:
1562 case ICMD_IF_FCMPL_GE:
1563 case ICMD_IF_FCMPL_GT:
1564 case ICMD_IF_FCMPL_LE:
1566 case ICMD_IF_FCMPG_LT:
1567 case ICMD_IF_FCMPG_GE:
1568 case ICMD_IF_FCMPG_GT:
1569 case ICMD_IF_FCMPG_LE:
1571 case ICMD_IF_DCMPEQ:
1572 case ICMD_IF_DCMPNE:
1574 case ICMD_IF_DCMPL_LT:
1575 case ICMD_IF_DCMPL_GE:
1576 case ICMD_IF_DCMPL_GT:
1577 case ICMD_IF_DCMPL_LE:
1579 case ICMD_IF_DCMPG_LT:
1580 case ICMD_IF_DCMPG_GE:
1581 case ICMD_IF_DCMPG_GT:
1582 case ICMD_IF_DCMPG_LE:
1584 case ICMD_IF_ACMPEQ:
1585 case ICMD_IF_ACMPNE:
1593 case ICMD_IASTORECONST:
1594 case ICMD_LASTORECONST:
1595 case ICMD_AASTORECONST:
1596 case ICMD_BASTORECONST:
1597 case ICMD_CASTORECONST:
1598 case ICMD_SASTORECONST:
1599 FREE_TEMP_REG(iptr->sx.s23.s2.varindex);
1600 FREE_TEMP_REG(iptr->s1.varindex);
1603 /* pop 0 push 1 copy */
1606 /* src === dst->prev (identical Stackslot Element) */
1607 /* src --> dst (copied value, take same reg/mem) */
1609 if (!simplereg_alloc_dup(jd, iptr->s1.varindex, iptr->dst.varindex)) {
1610 NEW_TEMP_REG(iptr->dst.varindex);
1613 v = VAROP(iptr->dst);
1615 if (v->flags & INMEMORY) {
1616 int32_t memindex = v->vv.regoff / SIZE_OF_STACKSLOT;
1617 if (memindex >= rd->memcopycountsize) {
1618 int newsize = (memindex + 1) * 2;
1619 i = rd->memcopycountsize;
1620 rd->memcopycount = DMREALLOC(rd->memcopycount, int, i, newsize);
1621 MZERO(rd->memcopycount + i, int, newsize - i);
1622 rd->memcopycountsize = newsize;
1624 rd->memcopycount[memindex]++;
1627 /* XXX split reg/mem variables on arm may need special handling here */
1629 s4 regindex = REG_INDEX(v->vv.regoff, v->type);
1631 rd->regcopycount[regindex]++;
1636 /* pop 1 push 1 move */
1639 if (!simplereg_alloc_dup(jd, iptr->s1.varindex, iptr->dst.varindex)) {
1640 NEW_TEMP_REG(iptr->dst.varindex);
1641 FREE_TEMP_REG(iptr->s1.varindex);
1691 FREE_TEMP_REG(iptr->sx.s23.s2.varindex);
1692 FREE_TEMP_REG(iptr->s1.varindex);
1693 NEW_TEMP_REG(iptr->dst.varindex);
1698 case ICMD_IADDCONST:
1699 case ICMD_ISUBCONST:
1700 case ICMD_IMULCONST:
1704 case ICMD_IANDCONST:
1706 case ICMD_IXORCONST:
1707 case ICMD_ISHLCONST:
1708 case ICMD_ISHRCONST:
1709 case ICMD_IUSHRCONST:
1711 case ICMD_LADDCONST:
1712 case ICMD_LSUBCONST:
1713 case ICMD_LMULCONST:
1717 case ICMD_LANDCONST:
1719 case ICMD_LXORCONST:
1720 case ICMD_LSHLCONST:
1721 case ICMD_LSHRCONST:
1722 case ICMD_LUSHRCONST:
1727 case ICMD_INT2SHORT:
1745 case ICMD_CHECKCAST:
1747 case ICMD_ARRAYLENGTH:
1748 case ICMD_INSTANCEOF:
1751 case ICMD_ANEWARRAY:
1754 FREE_TEMP_REG(iptr->s1.varindex);
1755 NEW_TEMP_REG(iptr->dst.varindex);
1760 case ICMD_GETSTATIC:
1763 NEW_TEMP_REG(iptr->dst.varindex);
1766 /* pop many push any */
1768 case ICMD_INVOKESTATIC:
1769 case ICMD_INVOKESPECIAL:
1770 case ICMD_INVOKEVIRTUAL:
1771 case ICMD_INVOKEINTERFACE:
1772 INSTRUCTION_GET_METHODDESC(iptr,md);
1774 argp = iptr->sx.s23.s2.args;
1776 FREE_TEMP_REG(*argp);
1779 if (md->returntype.type != TYPE_VOID)
1780 NEW_TEMP_REG(iptr->dst.varindex);
1784 bte = iptr->sx.s23.s3.bte;
1787 argp = iptr->sx.s23.s2.args;
1789 FREE_TEMP_REG(*argp);
1792 if (md->returntype.type != TYPE_VOID)
1793 NEW_TEMP_REG(iptr->dst.varindex);
1796 case ICMD_MULTIANEWARRAY:
1797 i = iptr->s1.argcount;
1798 argp = iptr->sx.s23.s2.args;
1800 FREE_TEMP_REG(*argp);
1803 NEW_TEMP_REG(iptr->dst.varindex);
1807 exceptions_throw_internalerror("Unknown ICMD %d during register allocation",
1812 } /* while instructions */
1815 } /* while blocks */
1819 #if defined(ENABLE_STATISTICS)
1820 void simplereg_make_statistics(jitdata *jd)
1828 stackptr src, src_old;
1833 int size_interface; /* == maximum size of in/out stack at basic block boundaries */
1837 /* get required compiler data */
1847 /* count how many local variables are held in memory or register */
1848 for(i=0; i < jd->localcount; i++) {
1849 if (VAR(i)->flags & INMEMORY) {
1850 count_locals_spilled++;
1854 count_locals_register++;
1858 /* count how many stack slots are held in memory or register */
1860 bptr = jd->basicblocks;
1862 while (bptr != NULL) {
1863 if (bptr->flags >= BBREACHED) {
1865 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1868 /* check for memory moves from interface to BB instack */
1869 len = bptr->indepth;
1871 if (len > size_interface) size_interface = len;
1875 var = VAR(bptr->invars[len]);
1877 /* invars statistics (currently none) */
1880 /* check for memory moves from BB outstack to interface */
1881 len = bptr->outdepth;
1882 if (len > size_interface) size_interface = len;
1886 var = VAR(bptr->outvars[len]);
1888 /* outvars statistics (currently none) */
1890 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1896 dst = bptr->instack;
1897 iptr = bptr->iinstr;
1901 while (--len >= 0) {
1903 dst = iptr->dst.var;
1905 if ((src!= NULL) && (src != src_old)) { /* new stackslot */
1906 switch (src->varkind) {
1909 if (!(src->flags & INMEMORY))
1910 count_ss_register++;
1916 /* case LOCALVAR: */
1917 /* if (!(rd->locals[src->varnum][src->type].flags & INMEMORY)) */
1918 /* count_ss_register++; */
1920 /* count_ss_spilled++; */
1923 if (!(src->flags & INMEMORY))
1924 count_argument_mem_ss++;
1926 count_argument_reg_ss++;
1930 /* if (IS_FLT_DBL_TYPE(src->type)) { */
1931 /* if (src->varnum < FLT_ARG_CNT) { */
1932 /* count_ss_register++; */
1936 /* #if defined(__POWERPC__) */
1937 /* if (src->varnum < INT_ARG_CNT - (IS_2_WORD_TYPE(src->type) != 0)) { */
1939 /* if (src->varnum < INT_ARG_CNT) { */
1941 /* count_ss_register++; */
1945 /* count_ss_spilled++; */
1952 } /* while instructions */
1957 } /* while blocks */
1959 count_interface_size += size_interface; /* accummulate the size of the interface (between bb boundaries) */
1960 if (in_register) count_method_in_register++;
1962 /* printf("INREGISTER: %s%s%s\n",m->class->name->text, m->name->text, m->descriptor->text); */
1965 #endif /* defined(ENABLE_STATISTICS) */
1969 * These are local overrides for various environment variables in Emacs.
1970 * Please do not remove this and leave it at the end of the file, where
1971 * Emacs will automagically detect them.
1972 * ---------------------------------------------------------------------
1975 * indent-tabs-mode: t
1979 * vim:noexpandtab:sw=4:ts=4: