1 /* src/vm/jit/allocator/simplereg.c - register allocator
3 Copyright (C) 1996-2005, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
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.
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.
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
36 #include "mm/memory.h"
38 #include "vm/jit/builtin.hpp"
39 #include "vm/exceptions.hpp"
40 #include "vm/method.h"
41 #include "vm/options.h"
42 #include "vm/resolve.h"
43 #include "vm/string.hpp"
45 #include "vm/jit/abi.h"
46 #include "vm/jit/reg.h"
47 #include "vm/jit/show.h"
48 #include "vm/jit/allocator/simplereg.h"
52 # define LOG(args) printf args
58 /* function prototypes for this file ******************************************/
60 static void simplereg_allocate_interfaces(jitdata *jd);
61 static void simplereg_allocate_locals(jitdata *jd);
62 static void simplereg_allocate_temporaries(jitdata *jd);
65 /* size of a stackslot used by the internal ABI */
67 #if defined(HAS_4BYTE_STACKSLOT)
68 # define SIZE_OF_STACKSLOT 4
70 # define SIZE_OF_STACKSLOT 8
74 /* total number of registers */
76 #if defined(HAS_ADDRESS_REGISTER_FILE)
77 #define TOTAL_REG_CNT (INT_REG_CNT + FLT_REG_CNT + ADR_REG_CNT)
79 #define TOTAL_REG_CNT (INT_REG_CNT + FLT_REG_CNT)
83 /* macros for handling register stacks ****************************************/
85 #define AVAIL_FRONT(cnt, limit) ((cnt) < (limit))
86 #define AVAIL_BACK(cnt) ((cnt) > 0)
88 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
89 #define AVAIL_FRONT_INT(cnt, limit) ((cnt) < (limit) - intregsneeded)
90 #define AVAIL_BACK_INT(cnt) ((cnt) > intregsneeded)
92 #define AVAIL_FRONT_INT(cnt, limit) AVAIL_FRONT(cnt, limit)
93 #define AVAIL_BACK_INT(cnt) AVAIL_BACK(cnt)
96 #define POP_FRONT(stk, cnt, reg) do { reg = stk[cnt++]; } while (0)
97 #define POP_BACK(stk, cnt, reg) do { reg = stk[--cnt]; } while (0)
98 #define PUSH_FRONT(stk, cnt, reg) do { stk[--cnt] = (reg); } while (0)
99 #define PUSH_BACK(stk, cnt, reg) do { stk[cnt++] = (reg); } while (0)
101 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
102 #define POP_FRONT_INT(stk, cnt, reg) \
104 if (intregsneeded) { \
105 reg = PACK_REGS(stk[cnt], stk[cnt+1]); \
109 POP_FRONT(stk, cnt, reg); \
112 #define POP_FRONT_INT(stk, cnt, reg) POP_FRONT(stk, cnt, reg)
115 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
116 #define POP_BACK_INT(stk, cnt, reg) \
118 if (intregsneeded) { \
120 reg = PACK_REGS(stk[cnt], stk[cnt+1]); \
123 POP_BACK(stk, cnt, reg); \
126 #define POP_BACK_INT(stk, cnt, reg) POP_BACK(stk, cnt, reg)
129 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
130 #define PUSH_BACK_INT(stk, cnt, reg) \
132 if (intregsneeded) { \
133 stk[cnt] = GET_LOW_REG(reg); \
134 stk[cnt + 1] = GET_HIGH_REG(reg); \
138 PUSH_BACK(stk, cnt, reg); \
141 #define PUSH_BACK_INT(stk, cnt, reg) PUSH_BACK(stk, cnt, reg)
144 #define AVAIL_ARG_FLT AVAIL_FRONT(rd->argfltreguse, FLT_ARG_CNT)
145 #define AVAIL_TMP_FLT AVAIL_BACK(rd->tmpfltreguse)
146 #define AVAIL_SAV_FLT AVAIL_BACK(rd->savfltreguse)
148 #define AVAIL_ARG_ADR AVAIL_FRONT(rd->argadrreguse, ADR_ARG_CNT)
149 #define AVAIL_TMP_ADR AVAIL_BACK(rd->tmpadrreguse)
150 #define AVAIL_SAV_ADR AVAIL_BACK(rd->savadrreguse)
152 #define AVAIL_ARG_INT AVAIL_FRONT_INT(rd->argintreguse, INT_ARG_CNT)
153 #define AVAIL_TMP_INT AVAIL_BACK_INT(rd->tmpintreguse)
154 #define AVAIL_SAV_INT AVAIL_BACK_INT(rd->savintreguse)
156 #define AVAIL_FREE_ARG_FLT AVAIL_BACK(rd->freeargflttop)
157 #define AVAIL_FREE_TMP_FLT AVAIL_BACK(rd->freetmpflttop)
158 #define AVAIL_FREE_SAV_FLT AVAIL_BACK(rd->freesavflttop)
160 #define AVAIL_FREE_ARG_ADR AVAIL_BACK(rd->freeargadrtop)
161 #define AVAIL_FREE_TMP_ADR AVAIL_BACK(rd->freetmpadrtop)
162 #define AVAIL_FREE_SAV_ADR AVAIL_BACK(rd->freesavadrtop)
164 #define AVAIL_FREE_ARG_INT AVAIL_BACK_INT(rd->freearginttop)
165 #define AVAIL_FREE_TMP_INT AVAIL_BACK_INT(rd->freetmpinttop)
166 #define AVAIL_FREE_SAV_INT AVAIL_BACK_INT(rd->freesavinttop)
168 #define TAKE_ARG_FLT(r) POP_FRONT(abi_registers_float_argument, rd->argfltreguse, r)
169 #define TAKE_TMP_FLT(r) POP_BACK(rd->tmpfltregs, rd->tmpfltreguse, r)
170 #define TAKE_SAV_FLT(r) POP_BACK(rd->savfltregs, rd->savfltreguse, r)
172 #define TAKE_ARG_ADR(r) POP_FRONT(rd->argadrregs, rd->argadrreguse, r)
173 #define TAKE_TMP_ADR(r) POP_BACK(rd->tmpadrregs, rd->tmpadrreguse, r)
174 #define TAKE_SAV_ADR(r) POP_BACK(rd->savadrregs, rd->savadrreguse, r)
176 #define TAKE_ARG_INT(r) POP_FRONT_INT(abi_registers_integer_argument, rd->argintreguse, r)
177 #define TAKE_TMP_INT(r) POP_BACK_INT(rd->tmpintregs, rd->tmpintreguse, r)
178 #define TAKE_SAV_INT(r) POP_BACK_INT(rd->savintregs, rd->savintreguse, r)
180 #define TAKE_FREE_ARG_FLT(r) POP_BACK(rd->freeargfltregs, rd->freeargflttop, r)
181 #define TAKE_FREE_TMP_FLT(r) POP_BACK(rd->freetmpfltregs, rd->freetmpflttop, r)
182 #define TAKE_FREE_SAV_FLT(r) POP_BACK(rd->freesavfltregs, rd->freesavflttop, r)
184 #define TAKE_FREE_ARG_ADR(r) POP_BACK(rd->freeargadrregs, rd->freeargadrtop, r)
185 #define TAKE_FREE_TMP_ADR(r) POP_BACK(rd->freetmpadrregs, rd->freetmpadrtop, r)
186 #define TAKE_FREE_SAV_ADR(r) POP_BACK(rd->freesavadrregs, rd->freesavadrtop, r)
188 #define TAKE_FREE_ARG_INT(r) POP_BACK_INT(rd->freeargintregs, rd->freearginttop, r)
189 #define TAKE_FREE_TMP_INT(r) POP_BACK_INT(rd->freetmpintregs, rd->freetmpinttop, r)
190 #define TAKE_FREE_SAV_INT(r) POP_BACK_INT(rd->freesavintregs, rd->freesavinttop, r)
192 #define PUSH_FREE_ARG_FLT(r) PUSH_BACK(rd->freeargfltregs, rd->freeargflttop, r)
193 #define PUSH_FREE_TMP_FLT(r) PUSH_BACK(rd->freetmpfltregs, rd->freetmpflttop, r)
194 #define PUSH_FREE_SAV_FLT(r) PUSH_BACK(rd->freesavfltregs, rd->freesavflttop, r)
196 #define PUSH_FREE_ARG_ADR(r) PUSH_BACK(rd->freeargadrregs, rd->freeargadrtop, r)
197 #define PUSH_FREE_TMP_ADR(r) PUSH_BACK(rd->freetmpadrregs, rd->freetmpadrtop, r)
198 #define PUSH_FREE_SAV_ADR(r) PUSH_BACK(rd->freesavadrregs, rd->freesavadrtop, r)
200 #define PUSH_FREE_ARG_INT(r) PUSH_BACK_INT(rd->freeargintregs, rd->freearginttop, r)
201 #define PUSH_FREE_TMP_INT(r) PUSH_BACK_INT(rd->freetmpintregs, rd->freetmpinttop, r)
202 #define PUSH_FREE_SAV_INT(r) PUSH_BACK_INT(rd->freesavintregs, rd->freesavinttop, r)
205 /* macros for allocating memory slots ****************************************/
207 #define NEW_MEM_SLOT(r) \
209 (r) = rd->memuse * SIZE_OF_STACKSLOT; \
210 rd->memuse += memneeded + 1; \
213 #define NEW_MEM_SLOT_ALIGNED(r) \
215 if ( (memneeded) && (rd->memuse & 1)) \
217 (r) = rd->memuse * SIZE_OF_STACKSLOT; \
218 rd->memuse += memneeded + 1; \
221 #define NEW_MEM_SLOT_ALIGNED_REUSE_PADDING(r) \
223 if ( (memneeded) && (rd->memuse & 1)) { \
224 PUSH_BACK(rd->freemem, rd->freememtop, rd->memuse); \
227 (r) = rd->memuse * SIZE_OF_STACKSLOT; \
228 rd->memuse += memneeded + 1; \
231 #if defined(ALIGN_LONGS_IN_MEMORY)
232 #define NEW_MEM_SLOT_INT_LNG(r) NEW_MEM_SLOT_ALIGNED(r)
234 #define NEW_MEM_SLOT_INT_LNG(r) NEW_MEM_SLOT(r)
237 #if defined(ALIGN_DOUBLES_IN_MEMORY)
238 #define NEW_MEM_SLOT_FLT_DBL(r) NEW_MEM_SLOT_ALIGNED(r)
240 #define NEW_MEM_SLOT_FLT_DBL(r) NEW_MEM_SLOT(r)
243 #if defined(ALIGN_LONGS_IN_MEMORY) || defined(ALIGN_DOUBLES_IN_MEMORY)
244 #define NEW_MEM_SLOT_REUSE_PADDING(r) NEW_MEM_SLOT_ALIGNED_REUSE_PADDING(r)
246 #define NEW_MEM_SLOT_REUSE_PADDING(r) NEW_MEM_SLOT(r)
250 /* macros for creating/freeing temporary variables ***************************/
252 #define NEW_TEMP_REG(index) \
253 if ( ((index) >= jd->localcount) \
254 && (!(VAR(index)->flags & (INOUT | PREALLOC))) ) \
255 simplereg_new_temp(jd, (index))
258 #define FREE_TEMP_REG(index) \
259 if (((index) > jd->localcount) \
260 && (!(VAR(index)->flags & (PREALLOC)))) \
261 simplereg_free_temp(jd, (index))
264 /* macro for getting a unique register index *********************************/
266 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
267 #define REG_INDEX_NON_ADR(regoff, type) \
268 (IS_FLT_DBL_TYPE(type) ? (INT_REG_CNT + (regoff)) : (GET_LOW_REG(regoff)))
270 #define REG_INDEX_NON_ADR(regoff, type) \
271 (IS_FLT_DBL_TYPE(type) ? (INT_REG_CNT + (regoff)) : (regoff))
274 #if defined(HAS_ADDRESS_REGISTER_FILE)
275 #define REG_INDEX(regoff, type) \
276 (IS_ADR_TYPE(type) ? (regoff) : (ADR_REG_CNT + REG_INDEX_NON_ADR(regoff, type)))
278 #define REG_INDEX(regoff, type) REG_INDEX_NON_ADR(regoff, type)
282 /* regalloc ********************************************************************
284 Does a simple register allocation.
286 *******************************************************************************/
288 bool regalloc(jitdata *jd)
290 /* There is a problem with the use of unused float argument
291 registers in leafmethods for stackslots on c7 (2 * Dual Core
292 AMD Opteron(tm) Processor 270) - runtime for the jvm98 _mtrt
293 benchmark is heaviliy increased. This could be prevented by
294 setting rd->argfltreguse to FLT_ARG_CNT before calling
295 simplereg_allocate_temporaries and setting it back to the original
296 value before calling simplereg_allocate_locals. */
298 simplereg_allocate_interfaces(jd);
299 simplereg_allocate_temporaries(jd);
300 simplereg_allocate_locals(jd);
308 /* simplereg_allocate_interfaces ***********************************************
310 Allocates registers for all interface variables.
312 *******************************************************************************/
314 static void simplereg_allocate_interfaces(jitdata *jd)
322 int intalloc, fltalloc; /* Remember allocated Register/Memory offset */
323 /* in case more vars are packed into this interface slot */
325 /* Allocate LNG and DBL types first to ensure 2 memory slots or */
326 /* registers on HAS_4BYTE_STACKSLOT architectures. */
327 int typeloop[] = { TYPE_LNG, TYPE_DBL, TYPE_INT, TYPE_FLT, TYPE_ADR };
329 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
333 /* get required compiler data */
340 /* rd->memuse was already set in stack.c to allocate stack space
341 for passing arguments to called methods. */
343 #if defined(__I386__)
344 if (checksync && code_is_synchronized(code)) {
345 /* reserve 0(%esp) for Monitorenter/exit Argument on i386 */
351 if (code_is_leafmethod(code)) {
352 /* Reserve argument register, which will be used for Locals acting */
354 if (rd->argintreguse < m->parseddesc->argintreguse)
355 rd->argintreguse = m->parseddesc->argintreguse;
356 if (rd->argfltreguse < m->parseddesc->argfltreguse)
357 rd->argfltreguse = m->parseddesc->argfltreguse;
358 #ifdef HAS_ADDRESS_REGISTER_FILE
359 if (rd->argadrreguse < m->parseddesc->argadrreguse)
360 rd->argadrreguse = m->parseddesc->argadrreguse;
364 for (s = 0; s < jd->maxinterfaces; s++) {
365 intalloc = -1; fltalloc = -1;
367 /* check if the interface at this stack depth must be a SAVEDVAR */
371 for (tt = 0; tt <=4; tt++) {
372 if ((t = jd->interface_map[s * 5 + tt].flags) != UNUSED) {
373 saved |= t & SAVEDVAR;
377 /* allocate reg/mem for each type the interface is used as */
379 for (tt = 0; tt <= 4; tt++) {
381 if (jd->interface_map[s * 5 + t].flags == UNUSED)
385 regoff = -1; /* initialize to invalid value */
387 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
388 intregsneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
391 #if defined(HAS_4BYTE_STACKSLOT)
392 memneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
396 #if defined(HAS_ADDRESS_REGISTER_FILE)
397 if (IS_ADR_TYPE(t)) {
398 if (!code_is_leafmethod(code) && AVAIL_ARG_ADR) {
400 TAKE_ARG_ADR(regoff);
402 else if (AVAIL_TMP_ADR) {
403 TAKE_TMP_ADR(regoff);
405 else if (AVAIL_SAV_ADR) {
407 TAKE_SAV_ADR(regoff);
411 regoff = rd->memuse++ * SIZE_OF_STACKSLOT;
414 else /* !IS_ADR_TYPE */
415 #endif /* defined(HAS_ADDRESS_REGISTER_FILE) */
417 if (IS_FLT_DBL_TYPE(t)) {
419 /* Reuse memory slot(s)/register(s) for shared interface slots */
420 flags |= jd->interface_map[fltalloc].flags & ~SAVEDVAR;
421 regoff = jd->interface_map[fltalloc].regoff;
423 else if (AVAIL_ARG_FLT) {
425 TAKE_ARG_FLT(regoff);
427 else if (AVAIL_TMP_FLT) {
428 TAKE_TMP_FLT(regoff);
430 else if (AVAIL_SAV_FLT) {
432 TAKE_SAV_FLT(regoff);
436 NEW_MEM_SLOT_FLT_DBL(regoff);
438 fltalloc = s * 5 + t;
440 else { /* !IS_FLT_DBL_TYPE(t) */
441 #if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
443 * for i386 put all longs in memory
445 if (IS_2_WORD_TYPE(t)) {
447 NEW_MEM_SLOT_INT_LNG(regoff);
452 /* Reuse memory slot(s)/register(s) for shared interface slots */
453 flags |= jd->interface_map[intalloc].flags & ~SAVEDVAR;
454 regoff = jd->interface_map[intalloc].regoff;
455 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
456 /* reuse lower half */
457 if (!(flags & INMEMORY)
458 && IS_2_WORD_TYPE(intalloc % 5))
459 regoff = GET_LOW_REG(regoff);
465 TAKE_ARG_INT(regoff);
467 else if (AVAIL_TMP_INT) {
468 TAKE_TMP_INT(regoff);
470 else if (AVAIL_SAV_INT) {
472 TAKE_SAV_INT(regoff);
476 NEW_MEM_SLOT_INT_LNG(regoff);
480 intalloc = s * 5 + t;
481 } /* if (IS_FLT_DBL_TYPE(t)) */
485 /* now the same like above, but without a chance to take a temporary register */
486 #ifdef HAS_ADDRESS_REGISTER_FILE
487 if (IS_ADR_TYPE(t)) {
489 TAKE_SAV_ADR(regoff);
493 regoff = rd->memuse++ * SIZE_OF_STACKSLOT;
499 if (IS_FLT_DBL_TYPE(t)) {
501 flags |= jd->interface_map[fltalloc].flags & ~SAVEDVAR;
502 regoff = jd->interface_map[fltalloc].regoff;
506 TAKE_SAV_FLT(regoff);
510 NEW_MEM_SLOT_FLT_DBL(regoff);
513 fltalloc = s * 5 + t;
515 else { /* IS_INT_LNG */
516 #if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
518 * for i386 put all longs in memory
520 if (IS_2_WORD_TYPE(t)) {
522 NEW_MEM_SLOT_INT_LNG(regoff);
528 flags |= jd->interface_map[intalloc].flags & ~SAVEDVAR;
529 regoff = jd->interface_map[intalloc].regoff;
530 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
531 /* reuse lower half */
532 if (!(flags & INMEMORY)
533 && IS_2_WORD_TYPE(intalloc % 5))
534 regoff = GET_LOW_REG(regoff);
539 TAKE_SAV_INT(regoff);
543 NEW_MEM_SLOT_INT_LNG(regoff);
548 } /* if (IS_FLT_DBL_TYPE(t) else */
549 } /* if (IS_ADR_TYPE(t)) else */
550 } /* if (saved) else */
554 jd->interface_map[5*s + t].flags = flags | INOUT;
555 jd->interface_map[5*s + t].regoff = regoff;
561 /* simplereg_allocate_locals_leafmethod ****************************************
563 Allocates registers for all local variables of a leafmethod.
565 *******************************************************************************/
567 static void simplereg_allocate_locals_leafmethod(jitdata *jd)
574 int p, s, t, tt, varindex;
575 int intalloc, fltalloc;
577 int intregsneeded = 0;
579 int typeloop[] = { TYPE_LNG, TYPE_DBL, TYPE_INT, TYPE_FLT, TYPE_ADR };
580 int fargcnt, iargcnt;
581 #ifdef HAS_ADDRESS_REGISTER_FILE
585 /* get required compiler data */
593 iargcnt = rd->argintreguse;
594 fargcnt = rd->argfltreguse;
595 #ifdef HAS_ADDRESS_REGISTER_FILE
596 aargcnt = rd->argadrreguse;
598 for (p = 0, s = 0; s < jd->maxlocals; s++, p++) {
599 intalloc = -1; fltalloc = -1;
600 for (tt = 0; tt <= 4; tt++) {
602 varindex = jd->local_map[s * 5 + t];
603 if (varindex == UNUSED)
608 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
609 intregsneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
611 #if defined(HAS_4BYTE_STACKSLOT)
612 memneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
618 * #ifdef HAS_ADDRESS_REGISTER_FILE
625 * } else { / int & lng
629 * must not to be changed!
632 #ifdef HAS_ADDRESS_REGISTER_FILE
633 if (IS_ADR_TYPE(t)) {
634 if ((p < md->paramcount) && !md->params[p].inmemory) {
636 v->vv.regoff = rd->argadrregs[md->params[p].regoff];
638 else if (AVAIL_TMP_ADR) {
640 TAKE_TMP_ADR(v->vv.regoff);
642 /* use unused argument registers as local registers */
643 else if ((p >= md->paramcount) &&
644 (aargcnt < ADR_ARG_CNT))
647 POP_FRONT(rd->argadrregs, aargcnt, v->vv.regoff);
649 else if (AVAIL_SAV_ADR) {
651 TAKE_SAV_ADR(v->vv.regoff);
654 v->flags |= INMEMORY;
655 v->vv.regoff = rd->memuse++ * SIZE_OF_STACKSLOT;
660 if (IS_FLT_DBL_TYPE(t)) {
662 v->flags = VAR(fltalloc)->flags;
663 v->vv.regoff = VAR(fltalloc)->vv.regoff;
665 #if !defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
666 /* We can only use float arguments as local variables,
667 * if we do not pass them in integer registers. */
668 else if ((p < md->paramcount) && !md->params[p].inmemory) {
670 v->vv.regoff = md->params[p].regoff;
673 else if (AVAIL_TMP_FLT) {
675 TAKE_TMP_FLT(v->vv.regoff);
677 /* use unused argument registers as local registers */
678 else if ((p >= md->paramcount) && (fargcnt < FLT_ARG_CNT)) {
680 POP_FRONT(abi_registers_float_argument,
681 fargcnt, v->vv.regoff);
683 else if (AVAIL_SAV_FLT) {
685 TAKE_SAV_FLT(v->vv.regoff);
689 NEW_MEM_SLOT_FLT_DBL(v->vv.regoff);
691 fltalloc = jd->local_map[s * 5 + t];
695 #if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
697 * for i386 put all longs in memory
699 if (IS_2_WORD_TYPE(t)) {
701 NEW_MEM_SLOT_INT_LNG(v->vv.regoff);
707 v->flags = VAR(intalloc)->flags;
708 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
709 if (!(v->flags & INMEMORY)
710 && IS_2_WORD_TYPE(VAR(intalloc)->type))
711 v->vv.regoff = GET_LOW_REG(
712 VAR(intalloc)->vv.regoff);
715 v->vv.regoff = VAR(intalloc)->vv.regoff;
717 else if ((p < md->paramcount) &&
718 !md->params[p].inmemory)
721 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
722 if (IS_2_WORD_TYPE(t))
724 PACK_REGS(GET_LOW_REG(md->params[p].regoff),
725 GET_HIGH_REG(md->params[p].regoff));
728 v->vv.regoff = md->params[p].regoff;
730 else if (AVAIL_TMP_INT) {
732 TAKE_TMP_INT(v->vv.regoff);
735 * use unused argument registers as local registers
737 else if ((p >= m->parseddesc->paramcount) &&
738 (iargcnt + intregsneeded < INT_ARG_CNT))
741 POP_FRONT_INT(abi_registers_integer_argument,
742 iargcnt, v->vv.regoff);
744 else if (AVAIL_SAV_INT) {
746 TAKE_SAV_INT(v->vv.regoff);
750 NEW_MEM_SLOT_INT_LNG(v->vv.regoff);
753 intalloc = jd->local_map[s * 5 + t];
755 #ifdef HAS_ADDRESS_REGISTER_FILE
758 } /* for (tt=0;...) */
760 /* If the current parameter is a 2-word type, the next local slot */
763 if (p < md->paramcount)
764 if (IS_2_WORD_TYPE(md->paramtypes[p].type))
769 /* simplereg_allocate_locals ***************************************************
771 Allocates registers for all local variables.
773 *******************************************************************************/
775 static void simplereg_allocate_locals(jitdata *jd)
781 int s, t, tt, varindex;
782 int intalloc, fltalloc;
785 int typeloop[] = { TYPE_LNG, TYPE_DBL, TYPE_INT, TYPE_FLT, TYPE_ADR };
786 #ifdef SUPPORT_COMBINE_INTEGER_REGISTERS
790 /* get required compiler data */
796 if (code_is_leafmethod(code)) {
797 simplereg_allocate_locals_leafmethod(jd);
801 for (s = 0; s < jd->maxlocals; s++) {
802 intalloc = -1; fltalloc = -1;
803 for (tt=0; tt<=4; tt++) {
806 varindex = jd->local_map[s * 5 + t];
807 if (varindex == UNUSED)
812 #ifdef SUPPORT_COMBINE_INTEGER_REGISTERS
813 intregsneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
816 #if defined(HAS_4BYTE_STACKSLOT)
817 memneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
820 #ifdef HAS_ADDRESS_REGISTER_FILE
821 if (IS_ADR_TYPE(t)) {
824 TAKE_SAV_ADR(v->vv.regoff);
828 v->vv.regoff = rd->memuse++ * SIZE_OF_STACKSLOT;
833 if (IS_FLT_DBL_TYPE(t)) {
835 v->flags = VAR(fltalloc)->flags;
836 v->vv.regoff = VAR(fltalloc)->vv.regoff;
838 else if (AVAIL_SAV_FLT) {
840 TAKE_SAV_FLT(v->vv.regoff);
844 NEW_MEM_SLOT_FLT_DBL(v->vv.regoff);
846 fltalloc = jd->local_map[s * 5 + t];
849 #if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
851 * for i386 put all longs in memory
853 if (IS_2_WORD_TYPE(t)) {
855 NEW_MEM_SLOT_INT_LNG(v->vv.regoff);
860 v->flags = VAR(intalloc)->flags;
861 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
862 if (!(v->flags & INMEMORY)
863 && IS_2_WORD_TYPE(VAR(intalloc)->type))
864 v->vv.regoff = GET_LOW_REG(
865 VAR(intalloc)->vv.regoff);
868 v->vv.regoff = VAR(intalloc)->vv.regoff;
870 else if (AVAIL_SAV_INT) {
872 TAKE_SAV_INT(v->vv.regoff);
876 NEW_MEM_SLOT_INT_LNG(v->vv.regoff);
878 #if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
881 intalloc = jd->local_map[s * 5 + t];
883 #ifdef HAS_ADDRESS_REGISTER_FILE
891 static void simplereg_init(jitdata *jd, registerdata *rd)
896 #if defined(HAS_4BYTE_STACKSLOT)
897 rd->freememtop_2 = 0;
900 rd->freetmpinttop = 0;
901 rd->freesavinttop = 0;
902 rd->freetmpflttop = 0;
903 rd->freesavflttop = 0;
904 #ifdef HAS_ADDRESS_REGISTER_FILE
905 rd->freetmpadrtop = 0;
906 rd->freesavadrtop = 0;
909 rd->freearginttop = 0;
910 rd->freeargflttop = 0;
911 #ifdef HAS_ADDRESS_REGISTER_FILE
912 rd->freeargadrtop = 0;
915 rd->regisoutvar = DMNEW(int, TOTAL_REG_CNT);
916 rd->regcopycount = DMNEW(int, TOTAL_REG_CNT);
917 MZERO(rd->regcopycount, int, TOTAL_REG_CNT);
919 /* memcopycount is dynamically allocated when needed */
921 rd->memcopycount = NULL;
922 rd->memcopycountsize = 0;
924 rd->intusedinout = DMNEW(int, INT_REG_CNT);
925 MZERO(rd->intusedinout, int, INT_REG_CNT);
926 rd->fltusedinout = DMNEW(int, FLT_REG_CNT);
927 MZERO(rd->fltusedinout, int, FLT_REG_CNT);
929 /* record the interface registers as used */
931 for (i=0; i<rd->argintreguse; ++i)
932 rd->intusedinout[abi_registers_integer_argument[i]] = 1;
933 for (i=rd->tmpintreguse; i<INT_TMP_CNT; ++i)
934 rd->intusedinout[rd->tmpintregs[i]] = 1;
935 for (i=rd->savintreguse; i<INT_SAV_CNT; ++i)
936 rd->intusedinout[rd->savintregs[i]] = 1;
938 for (i=0; i<rd->argfltreguse; ++i)
939 rd->fltusedinout[abi_registers_float_argument[i]] = 1;
940 for (i=rd->tmpfltreguse; i<FLT_TMP_CNT; ++i)
941 rd->fltusedinout[rd->tmpfltregs[i]] = 1;
942 for (i=rd->savfltreguse; i<FLT_SAV_CNT; ++i)
943 rd->fltusedinout[rd->savfltregs[i]] = 1;
945 #ifdef HAS_ADDRESS_REGISTER_FILE
946 rd->adrusedinout = DMNEW(int, ADR_REG_CNT);
947 MZERO(rd->adrusedinout, int, ADR_REG_CNT);
949 for (i=0; i<rd->argadrreguse; ++i)
950 rd->adrusedinout[rd->argadrregs[i]] = 1;
951 for (i=rd->tmpadrreguse; i<ADR_TMP_CNT; ++i)
952 rd->adrusedinout[rd->tmpadrregs[i]] = 1;
953 for (i=rd->savadrreguse; i<ADR_SAV_CNT; ++i)
954 rd->adrusedinout[rd->savadrregs[i]] = 1;
959 static void simplereg_init_block(registerdata *rd)
963 /* remove all interface registers from the free lists */
965 for (i=0; i<rd->freearginttop; ++i)
966 if (rd->intusedinout[rd->freeargintregs[i]]) {
967 rd->freeargintregs[i--] = rd->freeargintregs[--rd->freearginttop];
969 for (i=0; i<rd->freetmpinttop; ++i)
970 if (rd->intusedinout[rd->freetmpintregs[i]]) {
971 rd->freetmpintregs[i--] = rd->freetmpintregs[--rd->freetmpinttop];
973 for (i=0; i<rd->freesavinttop; ++i)
974 if (rd->intusedinout[rd->freesavintregs[i]]) {
975 rd->freesavintregs[i--] = rd->freesavintregs[--rd->freesavinttop];
978 for (i=0; i<rd->freeargflttop; ++i)
979 if (rd->fltusedinout[rd->freeargfltregs[i]]) {
980 rd->freeargfltregs[i--] = rd->freeargfltregs[--rd->freeargflttop];
982 for (i=0; i<rd->freetmpflttop; ++i)
983 if (rd->fltusedinout[rd->freetmpfltregs[i]]) {
984 rd->freetmpfltregs[i--] = rd->freetmpfltregs[--rd->freetmpflttop];
986 for (i=0; i<rd->freesavflttop; ++i)
987 if (rd->fltusedinout[rd->freesavfltregs[i]]) {
988 rd->freesavfltregs[i--] = rd->freesavfltregs[--rd->freesavflttop];
991 #ifdef HAS_ADDRESS_REGISTER_FILE
992 for (i=0; i<rd->freeargadrtop; ++i)
993 if (rd->adrusedinout[rd->freeargadrregs[i]]) {
994 rd->freeargadrregs[i--] = rd->freeargadrregs[--rd->freeargadrtop];
996 for (i=0; i<rd->freetmpadrtop; ++i)
997 if (rd->adrusedinout[rd->freetmpadrregs[i]]) {
998 rd->freetmpadrregs[i--] = rd->freetmpadrregs[--rd->freetmpadrtop];
1000 for (i=0; i<rd->freesavadrtop; ++i)
1001 if (rd->adrusedinout[rd->freesavadrregs[i]]) {
1002 rd->freesavadrregs[i--] = rd->freesavadrregs[--rd->freesavadrtop];
1008 static void simplereg_new_temp(jitdata *jd, s4 index)
1010 #ifdef SUPPORT_COMBINE_INTEGER_REGISTERS
1021 /* assert that constants are not allocated */
1023 assert(v->type != TYPE_RET);
1025 /* Try to allocate a saved register if there is no temporary one */
1026 /* available. This is what happens during the second run. */
1027 tryagain = (v->flags & SAVEDVAR) ? 1 : 2;
1029 #ifdef SUPPORT_COMBINE_INTEGER_REGISTERS
1030 intregsneeded = (IS_2_WORD_TYPE(v->type)) ? 1 : 0;
1033 #if defined(HAS_4BYTE_STACKSLOT)
1034 memneeded = (IS_2_WORD_TYPE(v->type)) ? 1 : 0;
1039 for(; tryagain; --tryagain) {
1040 if (tryagain == 1) {
1041 if (!(v->flags & SAVEDVAR))
1043 #ifdef HAS_ADDRESS_REGISTER_FILE
1044 if (IS_ADR_TYPE(v->type)) {
1045 if (AVAIL_FREE_SAV_ADR) {
1046 TAKE_FREE_SAV_ADR(v->vv.regoff);
1049 else if (AVAIL_SAV_ADR) {
1050 TAKE_SAV_ADR(v->vv.regoff);
1057 if (IS_FLT_DBL_TYPE(v->type)) {
1058 if (AVAIL_FREE_SAV_FLT) {
1059 TAKE_FREE_SAV_FLT(v->vv.regoff);
1062 else if (AVAIL_SAV_FLT) {
1063 TAKE_SAV_FLT(v->vv.regoff);
1068 #if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1070 * for i386 put all longs in memory
1072 if (!IS_2_WORD_TYPE(v->type))
1075 if (AVAIL_FREE_SAV_INT) {
1076 TAKE_FREE_SAV_INT(v->vv.regoff);
1079 else if (AVAIL_SAV_INT) {
1080 TAKE_SAV_INT(v->vv.regoff);
1087 else { /* tryagain == 2 */
1088 #ifdef HAS_ADDRESS_REGISTER_FILE
1089 if (IS_ADR_TYPE(v->type)) {
1090 if (AVAIL_FREE_TMP_ADR) {
1091 TAKE_FREE_TMP_ADR(v->vv.regoff);
1094 else if (AVAIL_TMP_ADR) {
1095 TAKE_TMP_ADR(v->vv.regoff);
1102 if (IS_FLT_DBL_TYPE(v->type)) {
1103 if (AVAIL_FREE_ARG_FLT) {
1105 TAKE_FREE_ARG_FLT(v->vv.regoff);
1108 else if (AVAIL_ARG_FLT) {
1110 TAKE_ARG_FLT(v->vv.regoff);
1113 else if (AVAIL_FREE_TMP_FLT) {
1114 TAKE_FREE_TMP_FLT(v->vv.regoff);
1117 else if (AVAIL_TMP_FLT) {
1118 TAKE_TMP_FLT(v->vv.regoff);
1124 #if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1126 * for i386 put all longs in memory
1128 if (!IS_2_WORD_TYPE(v->type))
1131 if (AVAIL_FREE_ARG_INT) {
1133 TAKE_FREE_ARG_INT(v->vv.regoff);
1136 else if (AVAIL_ARG_INT) {
1138 TAKE_ARG_INT(v->vv.regoff);
1141 else if (AVAIL_FREE_TMP_INT) {
1142 TAKE_FREE_TMP_INT(v->vv.regoff);
1145 else if (AVAIL_TMP_INT) {
1146 TAKE_TMP_INT(v->vv.regoff);
1149 } /* if (!IS_2_WORD_TYPE(s->type)) */
1150 } /* if (IS_FLT_DBL_TYPE(s->type)) */
1151 } /* if (IS_ADR_TYPE(s->type)) */
1152 } /* if (tryagain == 1) else */
1153 } /* for(; tryagain; --tryagain) */
1155 /* spill to memory */
1157 v->flags |= INMEMORY;
1159 #if defined(HAS_4BYTE_STACKSLOT)
1160 if ((memneeded == 1) && (rd->freememtop_2 > 0))
1161 POP_BACK(rd->freemem_2, rd->freememtop_2, v->vv.regoff);
1163 #endif /*defined(HAS_4BYTE_STACKSLOT) */
1164 if ((memneeded == 0) && (rd->freememtop > 0))
1165 POP_BACK(rd->freemem, rd->freememtop, v->vv.regoff);
1167 NEW_MEM_SLOT_REUSE_PADDING(v->vv.regoff);
1171 static void simplereg_free(registerdata *rd, s4 flags, s4 regoff, s4 type)
1173 /* assert that constants are not freed */
1175 assert(type != TYPE_RET);
1177 /* if this is a copy of another variable, just decrement the copy counter */
1179 if (flags & INMEMORY) {
1185 memindex = regoff / SIZE_OF_STACKSLOT;
1187 if (memindex < rd->memcopycountsize && rd->memcopycount[memindex]) {
1188 rd->memcopycount[memindex]--;
1195 regindex = REG_INDEX(regoff, type);
1197 /* do not free interface registers that are needed as outvars */
1199 if (flags & INOUT) {
1200 if (rd->regisoutvar[regindex]) {
1201 LOG(("DONT FREE f=%02x r=%d t=%d\n", flags, regoff, type));
1205 LOG(("FREEING INVAR f=%02x r=%d t=%d\n", flags, regoff, type));
1208 if (rd->regcopycount[regindex]) {
1209 rd->regcopycount[regindex]--;
1214 if (flags & INMEMORY) {
1215 #if defined(HAS_4BYTE_STACKSLOT)
1216 if (IS_2_WORD_TYPE(type))
1217 PUSH_BACK(rd->freemem_2, rd->freememtop_2, regoff);
1220 PUSH_BACK(rd->freemem, rd->freememtop, regoff);
1225 /* freeing a register */
1227 #ifdef HAS_ADDRESS_REGISTER_FILE
1228 if (IS_ADR_TYPE(type)) {
1229 if (flags & (SAVEDVAR | SAVREG))
1230 PUSH_FREE_SAV_ADR(regoff);
1232 PUSH_FREE_TMP_ADR(regoff);
1235 else if (IS_FLT_DBL_TYPE(type)) {
1236 if (flags & (SAVEDVAR | SAVREG))
1237 PUSH_FREE_SAV_FLT(regoff);
1238 else if (flags & ARGREG)
1239 PUSH_FREE_ARG_FLT(regoff);
1241 PUSH_FREE_TMP_FLT(regoff);
1243 else { /* IS_INT_LNG_TYPE */
1244 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1245 s4 intregsneeded = (IS_2_WORD_TYPE(type)) ? 1 : 0;
1248 if (flags & (SAVEDVAR | SAVREG))
1249 PUSH_FREE_SAV_INT(regoff);
1250 else if (flags & ARGREG)
1251 PUSH_FREE_ARG_INT(regoff);
1253 PUSH_FREE_TMP_INT(regoff);
1258 static inline void simplereg_free_temp(jitdata *jd, s4 index)
1264 simplereg_free(jd->rd, v->flags, v->vv.regoff, v->type);
1268 static bool simplereg_alloc_dup(jitdata *jd, s4 srcindex, s4 dstindex)
1273 /* do not coalesce local variables here */
1275 if (srcindex <= jd->localcount || dstindex <= jd->localcount)
1281 /* do not coalesce in/out vars or preallocated variables here */
1283 if ((sv->flags | dv->flags) & (INOUT | PREALLOC))
1286 /* if the source is in memory, we can coalesce in any case */
1288 if (sv->flags & INMEMORY) {
1289 dv->flags |= INMEMORY;
1290 dv->vv.regoff = sv->vv.regoff;
1294 /* we do not allocate a REG_TMP to a REG_SAV variable */
1296 if ((sv->flags & SAVEDVAR) != (dv->flags & SAVEDVAR))
1300 dv->vv.regoff = sv->vv.regoff;
1301 dv->flags |= sv->flags & (SAVREG | ARGREG);
1307 /* simplereg_allocate_temporaries **********************************************
1309 Allocate temporary (non-interface, non-local) registers.
1311 *******************************************************************************/
1313 static void simplereg_allocate_temporaries(jitdata *jd)
1321 builtintable_entry *bte;
1330 /* get required compiler data */
1335 /* initialize temp registers */
1337 simplereg_init(jd, rd);
1339 bptr = jd->basicblocks;
1341 while (bptr != NULL) {
1342 if (bptr->flags >= BBREACHED) {
1344 LOG(("\nallocating block L%03d\n", bptr->nr));
1346 simplereg_init_block(rd);
1348 /* assert that all copy counts are zero */
1350 #if !defined(NDEBUG) && !defined(ENABLE_SSA)
1351 for (i=0; i < TOTAL_REG_CNT; ++i)
1352 assert(rd->regcopycount[i] == 0);
1355 /* reset outvar flags */
1357 MZERO(rd->regisoutvar, int, TOTAL_REG_CNT);
1359 /* set allocation of invars */
1361 for (i=0; i<bptr->indepth; ++i)
1363 v = VAR(bptr->invars[i]);
1364 if (v->type == TYPE_RET)
1367 v->vv.regoff = jd->interface_map[5*i + v->type].regoff;
1368 v->flags = jd->interface_map[5*i + v->type].flags;
1370 if (!(v->flags & INMEMORY))
1371 rd->regcopycount[REG_INDEX(v->vv.regoff, v->type)] = 1;
1374 /* set allocation of outvars */
1376 for (i=0; i<bptr->outdepth; ++i)
1378 v = VAR(bptr->outvars[i]);
1379 if (v->type == TYPE_RET)
1382 v->vv.regoff = jd->interface_map[5*i + v->type].regoff;
1383 v->flags = jd->interface_map[5*i + v->type].flags;
1385 if (!(v->flags & INMEMORY)) {
1386 regindex = REG_INDEX(v->vv.regoff, v->type);
1387 rd->regcopycount[regindex] = 1;
1388 rd->regisoutvar[regindex] = 1;
1392 /* free interface registers not used in this block */
1394 for (i=0; i < 5 * jd->maxinterfaces; ++i) {
1396 regoff = jd->interface_map[i].regoff;
1397 flags = jd->interface_map[i].flags;
1399 if (!(flags & INMEMORY)) {
1400 if (!rd->regcopycount[REG_INDEX(regoff, type)]) {
1401 LOG(("MAY REUSE interface register f=%02x r=%d t=%d\n",
1402 flags, regoff, type));
1403 simplereg_free(rd, flags, regoff, type);
1405 /* mark it, so it is not freed again */
1406 rd->regcopycount[REG_INDEX(regoff, type)] = -1;
1411 /* reset copy counts */
1413 MZERO(rd->regcopycount, int, TOTAL_REG_CNT);
1415 /* iterate over ICMDS to allocate temporary variables */
1417 iptr = bptr->iinstr;
1420 while (--len >= 0) {
1422 switch (iptr->opc) {
1428 case ICMD_CHECKNULL:
1433 case ICMD_PUTSTATICCONST:
1434 case ICMD_INLINE_START:
1435 case ICMD_INLINE_END:
1436 case ICMD_INLINE_BODY:
1439 /* pop 0 push 1 const */
1446 case ICMD_GETEXCEPTION:
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_ACMPEQ:
1559 case ICMD_IF_ACMPNE:
1567 case ICMD_IASTORECONST:
1568 case ICMD_LASTORECONST:
1569 case ICMD_AASTORECONST:
1570 case ICMD_BASTORECONST:
1571 case ICMD_CASTORECONST:
1572 case ICMD_SASTORECONST:
1573 FREE_TEMP_REG(iptr->sx.s23.s2.varindex);
1574 FREE_TEMP_REG(iptr->s1.varindex);
1577 /* pop 0 push 1 copy */
1580 /* src === dst->prev (identical Stackslot Element) */
1581 /* src --> dst (copied value, take same reg/mem) */
1583 if (!simplereg_alloc_dup(jd, iptr->s1.varindex, iptr->dst.varindex)) {
1584 NEW_TEMP_REG(iptr->dst.varindex);
1587 v = VAROP(iptr->dst);
1589 if (v->flags & INMEMORY) {
1590 int32_t memindex = v->vv.regoff / SIZE_OF_STACKSLOT;
1591 if (memindex >= rd->memcopycountsize) {
1592 int newsize = (memindex + 1) * 2;
1593 i = rd->memcopycountsize;
1594 rd->memcopycount = DMREALLOC(rd->memcopycount, int, i, newsize);
1595 MZERO(rd->memcopycount + i, int, newsize - i);
1596 rd->memcopycountsize = newsize;
1598 rd->memcopycount[memindex]++;
1601 /* XXX split reg/mem variables on arm may need special handling here */
1603 s4 regindex = REG_INDEX(v->vv.regoff, v->type);
1605 rd->regcopycount[regindex]++;
1610 /* pop 1 push 1 move */
1613 if (!simplereg_alloc_dup(jd, iptr->s1.varindex, iptr->dst.varindex)) {
1614 NEW_TEMP_REG(iptr->dst.varindex);
1615 FREE_TEMP_REG(iptr->s1.varindex);
1665 FREE_TEMP_REG(iptr->sx.s23.s2.varindex);
1666 FREE_TEMP_REG(iptr->s1.varindex);
1667 NEW_TEMP_REG(iptr->dst.varindex);
1672 case ICMD_IADDCONST:
1673 case ICMD_ISUBCONST:
1674 case ICMD_IMULCONST:
1678 case ICMD_IANDCONST:
1680 case ICMD_IXORCONST:
1681 case ICMD_ISHLCONST:
1682 case ICMD_ISHRCONST:
1683 case ICMD_IUSHRCONST:
1685 case ICMD_LADDCONST:
1686 case ICMD_LSUBCONST:
1687 case ICMD_LMULCONST:
1691 case ICMD_LANDCONST:
1693 case ICMD_LXORCONST:
1694 case ICMD_LSHLCONST:
1695 case ICMD_LSHRCONST:
1696 case ICMD_LUSHRCONST:
1701 case ICMD_INT2SHORT:
1719 case ICMD_CHECKCAST:
1721 case ICMD_ARRAYLENGTH:
1722 case ICMD_INSTANCEOF:
1725 case ICMD_ANEWARRAY:
1728 FREE_TEMP_REG(iptr->s1.varindex);
1729 NEW_TEMP_REG(iptr->dst.varindex);
1734 case ICMD_GETSTATIC:
1737 NEW_TEMP_REG(iptr->dst.varindex);
1740 /* pop many push any */
1742 case ICMD_INVOKESTATIC:
1743 case ICMD_INVOKESPECIAL:
1744 case ICMD_INVOKEVIRTUAL:
1745 case ICMD_INVOKEINTERFACE:
1746 INSTRUCTION_GET_METHODDESC(iptr,md);
1748 argp = iptr->sx.s23.s2.args;
1750 FREE_TEMP_REG(*argp);
1753 if (md->returntype.type != TYPE_VOID)
1754 NEW_TEMP_REG(iptr->dst.varindex);
1758 bte = iptr->sx.s23.s3.bte;
1761 argp = iptr->sx.s23.s2.args;
1763 FREE_TEMP_REG(*argp);
1766 if (md->returntype.type != TYPE_VOID)
1767 NEW_TEMP_REG(iptr->dst.varindex);
1770 case ICMD_MULTIANEWARRAY:
1771 i = iptr->s1.argcount;
1772 argp = iptr->sx.s23.s2.args;
1774 FREE_TEMP_REG(*argp);
1777 NEW_TEMP_REG(iptr->dst.varindex);
1781 exceptions_throw_internalerror("Unknown ICMD %d during register allocation",
1786 } /* while instructions */
1789 } /* while blocks */
1793 #if defined(ENABLE_STATISTICS)
1794 void simplereg_make_statistics(jitdata *jd)
1802 stackelement_t* src, src_old;
1803 stackelement_t* dst;
1807 int size_interface; /* == maximum size of in/out stack at basic block boundaries */
1811 /* get required compiler data */
1821 /* count how many local variables are held in memory or register */
1822 for(i=0; i < jd->localcount; i++) {
1823 if (VAR(i)->flags & INMEMORY) {
1824 count_locals_spilled++;
1828 count_locals_register++;
1832 /* count how many stack slots are held in memory or register */
1834 bptr = jd->basicblocks;
1836 while (bptr != NULL) {
1837 if (bptr->flags >= BBREACHED) {
1839 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1842 /* check for memory moves from interface to BB instack */
1843 len = bptr->indepth;
1845 if (len > size_interface) size_interface = len;
1849 var = VAR(bptr->invars[len]);
1851 /* invars statistics (currently none) */
1854 /* check for memory moves from BB outstack to interface */
1855 len = bptr->outdepth;
1856 if (len > size_interface) size_interface = len;
1860 var = VAR(bptr->outvars[len]);
1862 /* outvars statistics (currently none) */
1864 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1870 dst = bptr->instack;
1871 iptr = bptr->iinstr;
1875 while (--len >= 0) {
1877 dst = iptr->dst.var;
1879 if ((src!= NULL) && (src != src_old)) { /* new stackslot */
1880 switch (src->varkind) {
1883 if (!(src->flags & INMEMORY))
1884 count_ss_register++;
1890 /* case LOCALVAR: */
1891 /* if (!(rd->locals[src->varnum][src->type].flags & INMEMORY)) */
1892 /* count_ss_register++; */
1894 /* count_ss_spilled++; */
1897 if (!(src->flags & INMEMORY))
1898 count_argument_mem_ss++;
1900 count_argument_reg_ss++;
1904 /* if (IS_FLT_DBL_TYPE(src->type)) { */
1905 /* if (src->varnum < FLT_ARG_CNT) { */
1906 /* count_ss_register++; */
1910 /* #if defined(__POWERPC__) */
1911 /* if (src->varnum < INT_ARG_CNT - (IS_2_WORD_TYPE(src->type) != 0)) { */
1913 /* if (src->varnum < INT_ARG_CNT) { */
1915 /* count_ss_register++; */
1919 /* count_ss_spilled++; */
1926 } /* while instructions */
1931 } /* while blocks */
1933 count_interface_size += size_interface; /* accummulate the size of the interface (between bb boundaries) */
1934 if (in_register) count_method_in_register++;
1936 /* printf("INREGISTER: %s%s%s\n",m->class->name->text, m->name->text, m->descriptor->text); */
1939 #endif /* defined(ENABLE_STATISTICS) */
1943 * These are local overrides for various environment variables in Emacs.
1944 * Please do not remove this and leave it at the end of the file, where
1945 * Emacs will automagically detect them.
1946 * ---------------------------------------------------------------------
1949 * indent-tabs-mode: t
1953 * vim:noexpandtab:sw=4:ts=4: