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
38 #include "mm/memory.h"
40 #include "vm/builtin.h"
41 #include "vm/exceptions.h"
42 #include "vm/resolve.h"
43 #include "vm/stringlocal.h"
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"
50 #include "vmcore/method.h"
51 #include "vmcore/options.h"
55 # define LOG(args) printf args
61 /* function prototypes for this file ******************************************/
63 static void simplereg_allocate_interfaces(jitdata *jd);
64 static void simplereg_allocate_locals(jitdata *jd);
65 static void simplereg_allocate_temporaries(jitdata *jd);
68 /* size of a stackslot used by the internal ABI */
70 #if defined(HAS_4BYTE_STACKSLOT)
71 # define SIZE_OF_STACKSLOT 4
73 # define SIZE_OF_STACKSLOT 8
77 /* total number of registers */
79 #if defined(HAS_ADDRESS_REGISTER_FILE)
80 #define TOTAL_REG_CNT (INT_REG_CNT + FLT_REG_CNT + ADR_REG_CNT)
82 #define TOTAL_REG_CNT (INT_REG_CNT + FLT_REG_CNT)
86 /* macros for handling register stacks ****************************************/
88 #define AVAIL_FRONT(cnt, limit) ((cnt) < (limit))
89 #define AVAIL_BACK(cnt) ((cnt) > 0)
91 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
92 #define AVAIL_FRONT_INT(cnt, limit) ((cnt) < (limit) - intregsneeded)
93 #define AVAIL_BACK_INT(cnt) ((cnt) > intregsneeded)
95 #define AVAIL_FRONT_INT(cnt, limit) AVAIL_FRONT(cnt, limit)
96 #define AVAIL_BACK_INT(cnt) AVAIL_BACK(cnt)
99 #define POP_FRONT(stk, cnt, reg) do { reg = stk[cnt++]; } while (0)
100 #define POP_BACK(stk, cnt, reg) do { reg = stk[--cnt]; } while (0)
101 #define PUSH_FRONT(stk, cnt, reg) do { stk[--cnt] = (reg); } while (0)
102 #define PUSH_BACK(stk, cnt, reg) do { stk[cnt++] = (reg); } while (0)
104 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
105 #define POP_FRONT_INT(stk, cnt, reg) \
107 if (intregsneeded) { \
108 reg = PACK_REGS(stk[cnt], stk[cnt+1]); \
112 POP_FRONT(stk, cnt, reg); \
115 #define POP_FRONT_INT(stk, cnt, reg) POP_FRONT(stk, cnt, reg)
118 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
119 #define POP_BACK_INT(stk, cnt, reg) \
121 if (intregsneeded) { \
123 reg = PACK_REGS(stk[cnt], stk[cnt+1]); \
126 POP_BACK(stk, cnt, reg); \
129 #define POP_BACK_INT(stk, cnt, reg) POP_BACK(stk, cnt, reg)
132 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
133 #define PUSH_BACK_INT(stk, cnt, reg) \
135 if (intregsneeded) { \
136 stk[cnt] = GET_LOW_REG(reg); \
137 stk[cnt + 1] = GET_HIGH_REG(reg); \
141 PUSH_BACK(stk, cnt, reg); \
144 #define PUSH_BACK_INT(stk, cnt, reg) PUSH_BACK(stk, cnt, reg)
147 #define AVAIL_ARG_FLT AVAIL_FRONT(rd->argfltreguse, FLT_ARG_CNT)
148 #define AVAIL_TMP_FLT AVAIL_BACK(rd->tmpfltreguse)
149 #define AVAIL_SAV_FLT AVAIL_BACK(rd->savfltreguse)
151 #define AVAIL_ARG_ADR AVAIL_FRONT(rd->argadrreguse, ADR_ARG_CNT)
152 #define AVAIL_TMP_ADR AVAIL_BACK(rd->tmpadrreguse)
153 #define AVAIL_SAV_ADR AVAIL_BACK(rd->savadrreguse)
155 #define AVAIL_ARG_INT AVAIL_FRONT_INT(rd->argintreguse, INT_ARG_CNT)
156 #define AVAIL_TMP_INT AVAIL_BACK_INT(rd->tmpintreguse)
157 #define AVAIL_SAV_INT AVAIL_BACK_INT(rd->savintreguse)
159 #define AVAIL_FREE_ARG_FLT AVAIL_BACK(rd->freeargflttop)
160 #define AVAIL_FREE_TMP_FLT AVAIL_BACK(rd->freetmpflttop)
161 #define AVAIL_FREE_SAV_FLT AVAIL_BACK(rd->freesavflttop)
163 #define AVAIL_FREE_ARG_ADR AVAIL_BACK(rd->freeargadrtop)
164 #define AVAIL_FREE_TMP_ADR AVAIL_BACK(rd->freetmpadrtop)
165 #define AVAIL_FREE_SAV_ADR AVAIL_BACK(rd->freesavadrtop)
167 #define AVAIL_FREE_ARG_INT AVAIL_BACK_INT(rd->freearginttop)
168 #define AVAIL_FREE_TMP_INT AVAIL_BACK_INT(rd->freetmpinttop)
169 #define AVAIL_FREE_SAV_INT AVAIL_BACK_INT(rd->freesavinttop)
171 #define TAKE_ARG_FLT(r) POP_FRONT(abi_registers_float_argument, rd->argfltreguse, r)
172 #define TAKE_TMP_FLT(r) POP_BACK(rd->tmpfltregs, rd->tmpfltreguse, r)
173 #define TAKE_SAV_FLT(r) POP_BACK(rd->savfltregs, rd->savfltreguse, r)
175 #define TAKE_ARG_ADR(r) POP_FRONT(rd->argadrregs, rd->argadrreguse, r)
176 #define TAKE_TMP_ADR(r) POP_BACK(rd->tmpadrregs, rd->tmpadrreguse, r)
177 #define TAKE_SAV_ADR(r) POP_BACK(rd->savadrregs, rd->savadrreguse, r)
179 #define TAKE_ARG_INT(r) POP_FRONT_INT(abi_registers_integer_argument, rd->argintreguse, r)
180 #define TAKE_TMP_INT(r) POP_BACK_INT(rd->tmpintregs, rd->tmpintreguse, r)
181 #define TAKE_SAV_INT(r) POP_BACK_INT(rd->savintregs, rd->savintreguse, r)
183 #define TAKE_FREE_ARG_FLT(r) POP_BACK(rd->freeargfltregs, rd->freeargflttop, r)
184 #define TAKE_FREE_TMP_FLT(r) POP_BACK(rd->freetmpfltregs, rd->freetmpflttop, r)
185 #define TAKE_FREE_SAV_FLT(r) POP_BACK(rd->freesavfltregs, rd->freesavflttop, r)
187 #define TAKE_FREE_ARG_ADR(r) POP_BACK(rd->freeargadrregs, rd->freeargadrtop, r)
188 #define TAKE_FREE_TMP_ADR(r) POP_BACK(rd->freetmpadrregs, rd->freetmpadrtop, r)
189 #define TAKE_FREE_SAV_ADR(r) POP_BACK(rd->freesavadrregs, rd->freesavadrtop, r)
191 #define TAKE_FREE_ARG_INT(r) POP_BACK_INT(rd->freeargintregs, rd->freearginttop, r)
192 #define TAKE_FREE_TMP_INT(r) POP_BACK_INT(rd->freetmpintregs, rd->freetmpinttop, r)
193 #define TAKE_FREE_SAV_INT(r) POP_BACK_INT(rd->freesavintregs, rd->freesavinttop, r)
195 #define PUSH_FREE_ARG_FLT(r) PUSH_BACK(rd->freeargfltregs, rd->freeargflttop, r)
196 #define PUSH_FREE_TMP_FLT(r) PUSH_BACK(rd->freetmpfltregs, rd->freetmpflttop, r)
197 #define PUSH_FREE_SAV_FLT(r) PUSH_BACK(rd->freesavfltregs, rd->freesavflttop, r)
199 #define PUSH_FREE_ARG_ADR(r) PUSH_BACK(rd->freeargadrregs, rd->freeargadrtop, r)
200 #define PUSH_FREE_TMP_ADR(r) PUSH_BACK(rd->freetmpadrregs, rd->freetmpadrtop, r)
201 #define PUSH_FREE_SAV_ADR(r) PUSH_BACK(rd->freesavadrregs, rd->freesavadrtop, r)
203 #define PUSH_FREE_ARG_INT(r) PUSH_BACK_INT(rd->freeargintregs, rd->freearginttop, r)
204 #define PUSH_FREE_TMP_INT(r) PUSH_BACK_INT(rd->freetmpintregs, rd->freetmpinttop, r)
205 #define PUSH_FREE_SAV_INT(r) PUSH_BACK_INT(rd->freesavintregs, rd->freesavinttop, r)
208 /* macros for allocating memory slots ****************************************/
210 #define NEW_MEM_SLOT(r) \
212 (r) = rd->memuse * SIZE_OF_STACKSLOT; \
213 rd->memuse += memneeded + 1; \
216 #define NEW_MEM_SLOT_ALIGNED(r) \
218 if ( (memneeded) && (rd->memuse & 1)) \
220 (r) = rd->memuse * SIZE_OF_STACKSLOT; \
221 rd->memuse += memneeded + 1; \
224 #define NEW_MEM_SLOT_ALIGNED_REUSE_PADDING(r) \
226 if ( (memneeded) && (rd->memuse & 1)) { \
227 PUSH_BACK(rd->freemem, rd->freememtop, rd->memuse); \
230 (r) = rd->memuse * SIZE_OF_STACKSLOT; \
231 rd->memuse += memneeded + 1; \
234 #if defined(ALIGN_LONGS_IN_MEMORY)
235 #define NEW_MEM_SLOT_INT_LNG(r) NEW_MEM_SLOT_ALIGNED(r)
237 #define NEW_MEM_SLOT_INT_LNG(r) NEW_MEM_SLOT(r)
240 #if defined(ALIGN_DOUBLES_IN_MEMORY)
241 #define NEW_MEM_SLOT_FLT_DBL(r) NEW_MEM_SLOT_ALIGNED(r)
243 #define NEW_MEM_SLOT_FLT_DBL(r) NEW_MEM_SLOT(r)
246 #if defined(ALIGN_LONGS_IN_MEMORY) || defined(ALIGN_DOUBLES_IN_MEMORY)
247 #define NEW_MEM_SLOT_REUSE_PADDING(r) NEW_MEM_SLOT_ALIGNED_REUSE_PADDING(r)
249 #define NEW_MEM_SLOT_REUSE_PADDING(r) NEW_MEM_SLOT(r)
253 /* macros for creating/freeing temporary variables ***************************/
255 #define NEW_TEMP_REG(index) \
256 if ( ((index) >= jd->localcount) \
257 && (!(VAR(index)->flags & (INOUT | PREALLOC))) ) \
258 simplereg_new_temp(jd, (index))
261 #define FREE_TEMP_REG(index) \
262 if (((index) > jd->localcount) \
263 && (!(VAR(index)->flags & (PREALLOC)))) \
264 simplereg_free_temp(jd, (index))
267 /* macro for getting a unique register index *********************************/
269 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
270 #define REG_INDEX_NON_ADR(regoff, type) \
271 (IS_FLT_DBL_TYPE(type) ? (INT_REG_CNT + (regoff)) : (GET_LOW_REG(regoff)))
273 #define REG_INDEX_NON_ADR(regoff, type) \
274 (IS_FLT_DBL_TYPE(type) ? (INT_REG_CNT + (regoff)) : (regoff))
277 #if defined(HAS_ADDRESS_REGISTER_FILE)
278 #define REG_INDEX(regoff, type) \
279 (IS_ADR_TYPE(type) ? (regoff) : (ADR_REG_CNT + REG_INDEX_NON_ADR(regoff, type)))
281 #define REG_INDEX(regoff, type) REG_INDEX_NON_ADR(regoff, type)
285 /* regalloc ********************************************************************
287 Does a simple register allocation.
289 *******************************************************************************/
291 bool regalloc(jitdata *jd)
293 /* There is a problem with the use of unused float argument
294 registers in leafmethods for stackslots on c7 (2 * Dual Core
295 AMD Opteron(tm) Processor 270) - runtime for the jvm98 _mtrt
296 benchmark is heaviliy increased. This could be prevented by
297 setting rd->argfltreguse to FLT_ARG_CNT before calling
298 simplereg_allocate_temporaries and setting it back to the original
299 value before calling simplereg_allocate_locals. */
301 simplereg_allocate_interfaces(jd);
302 simplereg_allocate_temporaries(jd);
303 simplereg_allocate_locals(jd);
311 /* simplereg_allocate_interfaces ***********************************************
313 Allocates registers for all interface variables.
315 *******************************************************************************/
317 static void simplereg_allocate_interfaces(jitdata *jd)
324 int intalloc, fltalloc; /* Remember allocated Register/Memory offset */
325 /* in case more vars are packed into this interface slot */
327 /* Allocate LNG and DBL types first to ensure 2 memory slots or */
328 /* registers on HAS_4BYTE_STACKSLOT architectures. */
329 int typeloop[] = { TYPE_LNG, TYPE_DBL, TYPE_INT, TYPE_FLT, TYPE_ADR };
331 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
335 /* get required compiler data */
341 /* rd->memuse was already set in stack.c to allocate stack space
342 for passing arguments to called methods. */
344 #if defined(__I386__)
345 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
346 /* reserve 0(%esp) for Monitorenter/exit Argument on i386 */
352 if (jd->isleafmethod) {
353 /* Reserve argument register, which will be used for Locals acting */
355 if (rd->argintreguse < m->parseddesc->argintreguse)
356 rd->argintreguse = m->parseddesc->argintreguse;
357 if (rd->argfltreguse < m->parseddesc->argfltreguse)
358 rd->argfltreguse = m->parseddesc->argfltreguse;
359 #ifdef HAS_ADDRESS_REGISTER_FILE
360 if (rd->argadrreguse < m->parseddesc->argadrreguse)
361 rd->argadrreguse = m->parseddesc->argadrreguse;
365 for (s = 0; s < jd->maxinterfaces; s++) {
366 intalloc = -1; fltalloc = -1;
368 /* check if the interface at this stack depth must be a SAVEDVAR */
372 for (tt = 0; tt <=4; tt++) {
373 if ((t = jd->interface_map[s * 5 + tt].flags) != UNUSED) {
374 saved |= t & SAVEDVAR;
378 /* allocate reg/mem for each type the interface is used as */
380 for (tt = 0; tt <= 4; tt++) {
382 if (jd->interface_map[s * 5 + t].flags == UNUSED)
386 regoff = -1; /* initialize to invalid value */
388 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
389 intregsneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
392 #if defined(HAS_4BYTE_STACKSLOT)
393 memneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
397 #if defined(HAS_ADDRESS_REGISTER_FILE)
398 if (IS_ADR_TYPE(t)) {
399 if (!jd->isleafmethod && AVAIL_ARG_ADR) {
401 TAKE_ARG_ADR(regoff);
403 else if (AVAIL_TMP_ADR) {
404 TAKE_TMP_ADR(regoff);
406 else if (AVAIL_SAV_ADR) {
408 TAKE_SAV_ADR(regoff);
412 regoff = rd->memuse++ * SIZE_OF_STACKSLOT;
415 else /* !IS_ADR_TYPE */
416 #endif /* defined(HAS_ADDRESS_REGISTER_FILE) */
418 if (IS_FLT_DBL_TYPE(t)) {
420 /* Reuse memory slot(s)/register(s) for shared interface slots */
421 flags |= jd->interface_map[fltalloc].flags & ~SAVEDVAR;
422 regoff = jd->interface_map[fltalloc].regoff;
424 else if (AVAIL_ARG_FLT) {
426 TAKE_ARG_FLT(regoff);
428 else if (AVAIL_TMP_FLT) {
429 TAKE_TMP_FLT(regoff);
431 else if (AVAIL_SAV_FLT) {
433 TAKE_SAV_FLT(regoff);
437 NEW_MEM_SLOT_FLT_DBL(regoff);
439 fltalloc = s * 5 + t;
441 else { /* !IS_FLT_DBL_TYPE(t) */
442 #if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
444 * for i386 put all longs in memory
446 if (IS_2_WORD_TYPE(t)) {
448 NEW_MEM_SLOT_INT_LNG(regoff);
453 /* Reuse memory slot(s)/register(s) for shared interface slots */
454 flags |= jd->interface_map[intalloc].flags & ~SAVEDVAR;
455 regoff = jd->interface_map[intalloc].regoff;
456 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
457 /* reuse lower half */
458 if (!(flags & INMEMORY)
459 && IS_2_WORD_TYPE(intalloc % 5))
460 regoff = GET_LOW_REG(regoff);
466 TAKE_ARG_INT(regoff);
468 else if (AVAIL_TMP_INT) {
469 TAKE_TMP_INT(regoff);
471 else if (AVAIL_SAV_INT) {
473 TAKE_SAV_INT(regoff);
477 NEW_MEM_SLOT_INT_LNG(regoff);
481 intalloc = s * 5 + t;
482 } /* if (IS_FLT_DBL_TYPE(t)) */
486 /* now the same like above, but without a chance to take a temporary register */
487 #ifdef HAS_ADDRESS_REGISTER_FILE
488 if (IS_ADR_TYPE(t)) {
490 TAKE_SAV_ADR(regoff);
494 regoff = rd->memuse++ * SIZE_OF_STACKSLOT;
500 if (IS_FLT_DBL_TYPE(t)) {
502 flags |= jd->interface_map[fltalloc].flags & ~SAVEDVAR;
503 regoff = jd->interface_map[fltalloc].regoff;
507 TAKE_SAV_FLT(regoff);
511 NEW_MEM_SLOT_FLT_DBL(regoff);
514 fltalloc = s * 5 + t;
516 else { /* IS_INT_LNG */
517 #if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
519 * for i386 put all longs in memory
521 if (IS_2_WORD_TYPE(t)) {
523 NEW_MEM_SLOT_INT_LNG(regoff);
529 flags |= jd->interface_map[intalloc].flags & ~SAVEDVAR;
530 regoff = jd->interface_map[intalloc].regoff;
531 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
532 /* reuse lower half */
533 if (!(flags & INMEMORY)
534 && IS_2_WORD_TYPE(intalloc % 5))
535 regoff = GET_LOW_REG(regoff);
540 TAKE_SAV_INT(regoff);
544 NEW_MEM_SLOT_INT_LNG(regoff);
549 } /* if (IS_FLT_DBL_TYPE(t) else */
550 } /* if (IS_ADR_TYPE(t)) else */
551 } /* if (saved) else */
555 jd->interface_map[5*s + t].flags = flags | INOUT;
556 jd->interface_map[5*s + t].regoff = regoff;
562 /* simplereg_allocate_locals_leafmethod ****************************************
564 Allocates registers for all local variables of a leafmethod.
566 *******************************************************************************/
568 static void simplereg_allocate_locals_leafmethod(jitdata *jd)
575 int p, s, t, tt, varindex;
576 int intalloc, fltalloc;
578 int intregsneeded = 0;
580 int typeloop[] = { TYPE_LNG, TYPE_DBL, TYPE_INT, TYPE_FLT, TYPE_ADR };
581 int fargcnt, iargcnt;
582 #ifdef HAS_ADDRESS_REGISTER_FILE
586 /* get required compiler data */
594 iargcnt = rd->argintreguse;
595 fargcnt = rd->argfltreguse;
596 #ifdef HAS_ADDRESS_REGISTER_FILE
597 aargcnt = rd->argadrreguse;
599 for (p = 0, s = 0; s < jd->maxlocals; s++, p++) {
600 intalloc = -1; fltalloc = -1;
601 for (tt = 0; tt <= 4; tt++) {
603 varindex = jd->local_map[s * 5 + t];
604 if (varindex == UNUSED)
609 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
610 intregsneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
612 #if defined(HAS_4BYTE_STACKSLOT)
613 memneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
619 * #ifdef HAS_ADDRESS_REGISTER_FILE
626 * } else { / int & lng
630 * must not to be changed!
633 #ifdef HAS_ADDRESS_REGISTER_FILE
634 if (IS_ADR_TYPE(t)) {
635 if ((p < md->paramcount) && !md->params[p].inmemory) {
637 v->vv.regoff = rd->argadrregs[md->params[p].regoff];
639 else if (AVAIL_TMP_ADR) {
641 TAKE_TMP_ADR(v->vv.regoff);
643 /* use unused argument registers as local registers */
644 else if ((p >= md->paramcount) &&
645 (aargcnt < ADR_ARG_CNT))
648 POP_FRONT(rd->argadrregs, aargcnt, v->vv.regoff);
650 else if (AVAIL_SAV_ADR) {
652 TAKE_SAV_ADR(v->vv.regoff);
655 v->flags |= INMEMORY;
656 v->vv.regoff = rd->memuse++ * SIZE_OF_STACKSLOT;
661 if (IS_FLT_DBL_TYPE(t)) {
663 v->flags = VAR(fltalloc)->flags;
664 v->vv.regoff = VAR(fltalloc)->vv.regoff;
666 #if !defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
667 /* We can only use float arguments as local variables,
668 * if we do not pass them in integer registers. */
669 else if ((p < md->paramcount) && !md->params[p].inmemory) {
671 v->vv.regoff = md->params[p].regoff;
674 else if (AVAIL_TMP_FLT) {
676 TAKE_TMP_FLT(v->vv.regoff);
678 /* use unused argument registers as local registers */
679 else if ((p >= md->paramcount) && (fargcnt < FLT_ARG_CNT)) {
681 POP_FRONT(abi_registers_float_argument,
682 fargcnt, v->vv.regoff);
684 else if (AVAIL_SAV_FLT) {
686 TAKE_SAV_FLT(v->vv.regoff);
690 NEW_MEM_SLOT_FLT_DBL(v->vv.regoff);
692 fltalloc = jd->local_map[s * 5 + t];
696 #if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
698 * for i386 put all longs in memory
700 if (IS_2_WORD_TYPE(t)) {
702 NEW_MEM_SLOT_INT_LNG(v->vv.regoff);
708 v->flags = VAR(intalloc)->flags;
709 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
710 if (!(v->flags & INMEMORY)
711 && IS_2_WORD_TYPE(VAR(intalloc)->type))
712 v->vv.regoff = GET_LOW_REG(
713 VAR(intalloc)->vv.regoff);
716 v->vv.regoff = VAR(intalloc)->vv.regoff;
718 else if ((p < md->paramcount) &&
719 !md->params[p].inmemory)
722 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
723 if (IS_2_WORD_TYPE(t))
725 PACK_REGS(GET_LOW_REG(md->params[p].regoff),
726 GET_HIGH_REG(md->params[p].regoff));
729 v->vv.regoff = md->params[p].regoff;
731 else if (AVAIL_TMP_INT) {
733 TAKE_TMP_INT(v->vv.regoff);
736 * use unused argument registers as local registers
738 else if ((p >= m->parseddesc->paramcount) &&
739 (iargcnt + intregsneeded < INT_ARG_CNT))
742 POP_FRONT_INT(abi_registers_integer_argument,
743 iargcnt, v->vv.regoff);
745 else if (AVAIL_SAV_INT) {
747 TAKE_SAV_INT(v->vv.regoff);
751 NEW_MEM_SLOT_INT_LNG(v->vv.regoff);
754 intalloc = jd->local_map[s * 5 + t];
756 #ifdef HAS_ADDRESS_REGISTER_FILE
759 } /* for (tt=0;...) */
761 /* If the current parameter is a 2-word type, the next local slot */
764 if (p < md->paramcount)
765 if (IS_2_WORD_TYPE(md->paramtypes[p].type))
770 /* simplereg_allocate_locals ***************************************************
772 Allocates registers for all local variables.
774 *******************************************************************************/
776 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 */
795 if (jd->isleafmethod) {
796 simplereg_allocate_locals_leafmethod(jd);
800 for (s = 0; s < jd->maxlocals; s++) {
801 intalloc = -1; fltalloc = -1;
802 for (tt=0; tt<=4; tt++) {
805 varindex = jd->local_map[s * 5 + t];
806 if (varindex == UNUSED)
811 #ifdef SUPPORT_COMBINE_INTEGER_REGISTERS
812 intregsneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
815 #if defined(HAS_4BYTE_STACKSLOT)
816 memneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
819 #ifdef HAS_ADDRESS_REGISTER_FILE
820 if (IS_ADR_TYPE(t)) {
823 TAKE_SAV_ADR(v->vv.regoff);
827 v->vv.regoff = rd->memuse++ * SIZE_OF_STACKSLOT;
832 if (IS_FLT_DBL_TYPE(t)) {
834 v->flags = VAR(fltalloc)->flags;
835 v->vv.regoff = VAR(fltalloc)->vv.regoff;
837 else if (AVAIL_SAV_FLT) {
839 TAKE_SAV_FLT(v->vv.regoff);
843 NEW_MEM_SLOT_FLT_DBL(v->vv.regoff);
845 fltalloc = jd->local_map[s * 5 + t];
848 #if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
850 * for i386 put all longs in memory
852 if (IS_2_WORD_TYPE(t)) {
854 NEW_MEM_SLOT_INT_LNG(v->vv.regoff);
859 v->flags = VAR(intalloc)->flags;
860 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
861 if (!(v->flags & INMEMORY)
862 && IS_2_WORD_TYPE(VAR(intalloc)->type))
863 v->vv.regoff = GET_LOW_REG(
864 VAR(intalloc)->vv.regoff);
867 v->vv.regoff = VAR(intalloc)->vv.regoff;
869 else if (AVAIL_SAV_INT) {
871 TAKE_SAV_INT(v->vv.regoff);
875 NEW_MEM_SLOT_INT_LNG(v->vv.regoff);
877 #if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
880 intalloc = jd->local_map[s * 5 + t];
882 #ifdef HAS_ADDRESS_REGISTER_FILE
890 static void simplereg_init(jitdata *jd, registerdata *rd)
895 #if defined(HAS_4BYTE_STACKSLOT)
896 rd->freememtop_2 = 0;
899 rd->freetmpinttop = 0;
900 rd->freesavinttop = 0;
901 rd->freetmpflttop = 0;
902 rd->freesavflttop = 0;
903 #ifdef HAS_ADDRESS_REGISTER_FILE
904 rd->freetmpadrtop = 0;
905 rd->freesavadrtop = 0;
908 rd->freearginttop = 0;
909 rd->freeargflttop = 0;
910 #ifdef HAS_ADDRESS_REGISTER_FILE
911 rd->freeargadrtop = 0;
914 rd->regisoutvar = DMNEW(int, TOTAL_REG_CNT);
915 rd->regcopycount = DMNEW(int, TOTAL_REG_CNT);
916 MZERO(rd->regcopycount, int, TOTAL_REG_CNT);
918 /* memcopycount is dynamically allocated when needed */
920 rd->memcopycount = NULL;
921 rd->memcopycountsize = 0;
923 rd->intusedinout = DMNEW(int, INT_REG_CNT);
924 MZERO(rd->intusedinout, int, INT_REG_CNT);
925 rd->fltusedinout = DMNEW(int, FLT_REG_CNT);
926 MZERO(rd->fltusedinout, int, FLT_REG_CNT);
928 /* record the interface registers as used */
930 for (i=0; i<rd->argintreguse; ++i)
931 rd->intusedinout[abi_registers_integer_argument[i]] = 1;
932 for (i=rd->tmpintreguse; i<INT_TMP_CNT; ++i)
933 rd->intusedinout[rd->tmpintregs[i]] = 1;
934 for (i=rd->savintreguse; i<INT_SAV_CNT; ++i)
935 rd->intusedinout[rd->savintregs[i]] = 1;
937 for (i=0; i<rd->argfltreguse; ++i)
938 rd->fltusedinout[abi_registers_float_argument[i]] = 1;
939 for (i=rd->tmpfltreguse; i<FLT_TMP_CNT; ++i)
940 rd->fltusedinout[rd->tmpfltregs[i]] = 1;
941 for (i=rd->savfltreguse; i<FLT_SAV_CNT; ++i)
942 rd->fltusedinout[rd->savfltregs[i]] = 1;
944 #ifdef HAS_ADDRESS_REGISTER_FILE
945 rd->adrusedinout = DMNEW(int, ADR_REG_CNT);
946 MZERO(rd->adrusedinout, int, ADR_REG_CNT);
948 for (i=0; i<rd->argadrreguse; ++i)
949 rd->adrusedinout[rd->argadrregs[i]] = 1;
950 for (i=rd->tmpadrreguse; i<ADR_TMP_CNT; ++i)
951 rd->adrusedinout[rd->tmpadrregs[i]] = 1;
952 for (i=rd->savadrreguse; i<ADR_SAV_CNT; ++i)
953 rd->adrusedinout[rd->savadrregs[i]] = 1;
958 static void simplereg_init_block(registerdata *rd)
962 /* remove all interface registers from the free lists */
964 for (i=0; i<rd->freearginttop; ++i)
965 if (rd->intusedinout[rd->freeargintregs[i]]) {
966 rd->freeargintregs[i--] = rd->freeargintregs[--rd->freearginttop];
968 for (i=0; i<rd->freetmpinttop; ++i)
969 if (rd->intusedinout[rd->freetmpintregs[i]]) {
970 rd->freetmpintregs[i--] = rd->freetmpintregs[--rd->freetmpinttop];
972 for (i=0; i<rd->freesavinttop; ++i)
973 if (rd->intusedinout[rd->freesavintregs[i]]) {
974 rd->freesavintregs[i--] = rd->freesavintregs[--rd->freesavinttop];
977 for (i=0; i<rd->freeargflttop; ++i)
978 if (rd->fltusedinout[rd->freeargfltregs[i]]) {
979 rd->freeargfltregs[i--] = rd->freeargfltregs[--rd->freeargflttop];
981 for (i=0; i<rd->freetmpflttop; ++i)
982 if (rd->fltusedinout[rd->freetmpfltregs[i]]) {
983 rd->freetmpfltregs[i--] = rd->freetmpfltregs[--rd->freetmpflttop];
985 for (i=0; i<rd->freesavflttop; ++i)
986 if (rd->fltusedinout[rd->freesavfltregs[i]]) {
987 rd->freesavfltregs[i--] = rd->freesavfltregs[--rd->freesavflttop];
990 #ifdef HAS_ADDRESS_REGISTER_FILE
991 for (i=0; i<rd->freeargadrtop; ++i)
992 if (rd->adrusedinout[rd->freeargadrregs[i]]) {
993 rd->freeargadrregs[i--] = rd->freeargadrregs[--rd->freeargadrtop];
995 for (i=0; i<rd->freetmpadrtop; ++i)
996 if (rd->adrusedinout[rd->freetmpadrregs[i]]) {
997 rd->freetmpadrregs[i--] = rd->freetmpadrregs[--rd->freetmpadrtop];
999 for (i=0; i<rd->freesavadrtop; ++i)
1000 if (rd->adrusedinout[rd->freesavadrregs[i]]) {
1001 rd->freesavadrregs[i--] = rd->freesavadrregs[--rd->freesavadrtop];
1007 static void simplereg_new_temp(jitdata *jd, s4 index)
1009 #ifdef SUPPORT_COMBINE_INTEGER_REGISTERS
1020 /* assert that constants are not allocated */
1022 assert(v->type != TYPE_RET);
1024 /* Try to allocate a saved register if there is no temporary one */
1025 /* available. This is what happens during the second run. */
1026 tryagain = (v->flags & SAVEDVAR) ? 1 : 2;
1028 #ifdef SUPPORT_COMBINE_INTEGER_REGISTERS
1029 intregsneeded = (IS_2_WORD_TYPE(v->type)) ? 1 : 0;
1032 #if defined(HAS_4BYTE_STACKSLOT)
1033 memneeded = (IS_2_WORD_TYPE(v->type)) ? 1 : 0;
1038 for(; tryagain; --tryagain) {
1039 if (tryagain == 1) {
1040 if (!(v->flags & SAVEDVAR))
1042 #ifdef HAS_ADDRESS_REGISTER_FILE
1043 if (IS_ADR_TYPE(v->type)) {
1044 if (AVAIL_FREE_SAV_ADR) {
1045 TAKE_FREE_SAV_ADR(v->vv.regoff);
1048 else if (AVAIL_SAV_ADR) {
1049 TAKE_SAV_ADR(v->vv.regoff);
1056 if (IS_FLT_DBL_TYPE(v->type)) {
1057 if (AVAIL_FREE_SAV_FLT) {
1058 TAKE_FREE_SAV_FLT(v->vv.regoff);
1061 else if (AVAIL_SAV_FLT) {
1062 TAKE_SAV_FLT(v->vv.regoff);
1067 #if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1069 * for i386 put all longs in memory
1071 if (!IS_2_WORD_TYPE(v->type))
1074 if (AVAIL_FREE_SAV_INT) {
1075 TAKE_FREE_SAV_INT(v->vv.regoff);
1078 else if (AVAIL_SAV_INT) {
1079 TAKE_SAV_INT(v->vv.regoff);
1086 else { /* tryagain == 2 */
1087 #ifdef HAS_ADDRESS_REGISTER_FILE
1088 if (IS_ADR_TYPE(v->type)) {
1089 if (AVAIL_FREE_TMP_ADR) {
1090 TAKE_FREE_TMP_ADR(v->vv.regoff);
1093 else if (AVAIL_TMP_ADR) {
1094 TAKE_TMP_ADR(v->vv.regoff);
1101 if (IS_FLT_DBL_TYPE(v->type)) {
1102 if (AVAIL_FREE_ARG_FLT) {
1104 TAKE_FREE_ARG_FLT(v->vv.regoff);
1107 else if (AVAIL_ARG_FLT) {
1109 TAKE_ARG_FLT(v->vv.regoff);
1112 else if (AVAIL_FREE_TMP_FLT) {
1113 TAKE_FREE_TMP_FLT(v->vv.regoff);
1116 else if (AVAIL_TMP_FLT) {
1117 TAKE_TMP_FLT(v->vv.regoff);
1123 #if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1125 * for i386 put all longs in memory
1127 if (!IS_2_WORD_TYPE(v->type))
1130 if (AVAIL_FREE_ARG_INT) {
1132 TAKE_FREE_ARG_INT(v->vv.regoff);
1135 else if (AVAIL_ARG_INT) {
1137 TAKE_ARG_INT(v->vv.regoff);
1140 else if (AVAIL_FREE_TMP_INT) {
1141 TAKE_FREE_TMP_INT(v->vv.regoff);
1144 else if (AVAIL_TMP_INT) {
1145 TAKE_TMP_INT(v->vv.regoff);
1148 } /* if (!IS_2_WORD_TYPE(s->type)) */
1149 } /* if (IS_FLT_DBL_TYPE(s->type)) */
1150 } /* if (IS_ADR_TYPE(s->type)) */
1151 } /* if (tryagain == 1) else */
1152 } /* for(; tryagain; --tryagain) */
1154 /* spill to memory */
1156 v->flags |= INMEMORY;
1158 #if defined(HAS_4BYTE_STACKSLOT)
1159 if ((memneeded == 1) && (rd->freememtop_2 > 0))
1160 POP_BACK(rd->freemem_2, rd->freememtop_2, v->vv.regoff);
1162 #endif /*defined(HAS_4BYTE_STACKSLOT) */
1163 if ((memneeded == 0) && (rd->freememtop > 0))
1164 POP_BACK(rd->freemem, rd->freememtop, v->vv.regoff);
1166 NEW_MEM_SLOT_REUSE_PADDING(v->vv.regoff);
1170 static void simplereg_free(registerdata *rd, s4 flags, s4 regoff, s4 type)
1172 /* assert that constants are not freed */
1174 assert(type != TYPE_RET);
1176 /* if this is a copy of another variable, just decrement the copy counter */
1178 if (flags & INMEMORY) {
1184 memindex = regoff / SIZE_OF_STACKSLOT;
1186 if (memindex < rd->memcopycountsize && rd->memcopycount[memindex]) {
1187 rd->memcopycount[memindex]--;
1194 regindex = REG_INDEX(regoff, type);
1196 /* do not free interface registers that are needed as outvars */
1198 if (flags & INOUT) {
1199 if (rd->regisoutvar[regindex]) {
1200 LOG(("DONT FREE f=%02x r=%d t=%d\n", flags, regoff, type));
1204 LOG(("FREEING INVAR f=%02x r=%d t=%d\n", flags, regoff, type));
1207 if (rd->regcopycount[regindex]) {
1208 rd->regcopycount[regindex]--;
1213 if (flags & INMEMORY) {
1214 #if defined(HAS_4BYTE_STACKSLOT)
1215 if (IS_2_WORD_TYPE(type))
1216 PUSH_BACK(rd->freemem_2, rd->freememtop_2, regoff);
1219 PUSH_BACK(rd->freemem, rd->freememtop, regoff);
1224 /* freeing a register */
1226 #ifdef HAS_ADDRESS_REGISTER_FILE
1227 if (IS_ADR_TYPE(type)) {
1228 if (flags & (SAVEDVAR | SAVREG))
1229 PUSH_FREE_SAV_ADR(regoff);
1231 PUSH_FREE_TMP_ADR(regoff);
1234 else if (IS_FLT_DBL_TYPE(type)) {
1235 if (flags & (SAVEDVAR | SAVREG))
1236 PUSH_FREE_SAV_FLT(regoff);
1237 else if (flags & ARGREG)
1238 PUSH_FREE_ARG_FLT(regoff);
1240 PUSH_FREE_TMP_FLT(regoff);
1242 else { /* IS_INT_LNG_TYPE */
1243 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1244 s4 intregsneeded = (IS_2_WORD_TYPE(type)) ? 1 : 0;
1247 if (flags & (SAVEDVAR | SAVREG))
1248 PUSH_FREE_SAV_INT(regoff);
1249 else if (flags & ARGREG)
1250 PUSH_FREE_ARG_INT(regoff);
1252 PUSH_FREE_TMP_INT(regoff);
1257 static inline void simplereg_free_temp(jitdata *jd, s4 index)
1263 simplereg_free(jd->rd, v->flags, v->vv.regoff, v->type);
1267 static bool simplereg_alloc_dup(jitdata *jd, s4 srcindex, s4 dstindex)
1272 /* do not coalesce local variables here */
1274 if (srcindex <= jd->localcount || dstindex <= jd->localcount)
1280 /* do not coalesce in/out vars or preallocated variables here */
1282 if ((sv->flags | dv->flags) & (INOUT | PREALLOC))
1285 /* if the source is in memory, we can coalesce in any case */
1287 if (sv->flags & INMEMORY) {
1288 dv->flags |= INMEMORY;
1289 dv->vv.regoff = sv->vv.regoff;
1293 /* we do not allocate a REG_TMP to a REG_SAV variable */
1295 if ((sv->flags & SAVEDVAR) != (dv->flags & SAVEDVAR))
1299 dv->vv.regoff = sv->vv.regoff;
1300 dv->flags |= sv->flags & (SAVREG | ARGREG);
1306 /* simplereg_allocate_temporaries **********************************************
1308 Allocate temporary (non-interface, non-local) registers.
1310 *******************************************************************************/
1312 static void simplereg_allocate_temporaries(jitdata *jd)
1320 builtintable_entry *bte;
1329 /* get required compiler data */
1334 /* initialize temp registers */
1336 simplereg_init(jd, rd);
1338 bptr = jd->basicblocks;
1340 while (bptr != NULL) {
1341 if (bptr->flags >= BBREACHED) {
1343 LOG(("\nallocating block L%03d\n", bptr->nr));
1345 simplereg_init_block(rd);
1347 /* assert that all copy counts are zero */
1349 #if !defined(NDEBUG)
1350 for (i=0; i < TOTAL_REG_CNT; ++i)
1351 assert(rd->regcopycount[i] == 0);
1354 /* reset outvar flags */
1356 MZERO(rd->regisoutvar, int, TOTAL_REG_CNT);
1358 /* set allocation of invars */
1360 for (i=0; i<bptr->indepth; ++i)
1362 v = VAR(bptr->invars[i]);
1363 if (v->type == TYPE_RET)
1366 v->vv.regoff = jd->interface_map[5*i + v->type].regoff;
1367 v->flags = jd->interface_map[5*i + v->type].flags;
1369 if (!(v->flags & INMEMORY))
1370 rd->regcopycount[REG_INDEX(v->vv.regoff, v->type)] = 1;
1373 /* set allocation of outvars */
1375 for (i=0; i<bptr->outdepth; ++i)
1377 v = VAR(bptr->outvars[i]);
1378 if (v->type == TYPE_RET)
1381 v->vv.regoff = jd->interface_map[5*i + v->type].regoff;
1382 v->flags = jd->interface_map[5*i + v->type].flags;
1384 if (!(v->flags & INMEMORY)) {
1385 regindex = REG_INDEX(v->vv.regoff, v->type);
1386 rd->regcopycount[regindex] = 1;
1387 rd->regisoutvar[regindex] = 1;
1391 /* free interface registers not used in this block */
1393 for (i=0; i < 5 * jd->maxinterfaces; ++i) {
1395 regoff = jd->interface_map[i].regoff;
1396 flags = jd->interface_map[i].flags;
1398 if (!(flags & INMEMORY)) {
1399 if (!rd->regcopycount[REG_INDEX(regoff, type)]) {
1400 LOG(("MAY REUSE interface register f=%02x r=%d t=%d\n",
1401 flags, regoff, type));
1402 simplereg_free(rd, flags, regoff, type);
1404 /* mark it, so it is not freed again */
1405 rd->regcopycount[REG_INDEX(regoff, type)] = -1;
1410 /* reset copy counts */
1412 MZERO(rd->regcopycount, int, TOTAL_REG_CNT);
1414 /* iterate over ICMDS to allocate temporary variables */
1416 iptr = bptr->iinstr;
1419 while (--len >= 0) {
1421 switch (iptr->opc) {
1427 case ICMD_CHECKNULL:
1432 case ICMD_PUTSTATICCONST:
1433 case ICMD_INLINE_START:
1434 case ICMD_INLINE_END:
1435 case ICMD_INLINE_BODY:
1438 /* pop 0 push 1 const */
1446 /* pop 0 push 1 load */
1453 NEW_TEMP_REG(iptr->dst.varindex);
1467 FREE_TEMP_REG(iptr->sx.s23.s2.varindex);
1468 FREE_TEMP_REG(iptr->s1.varindex);
1469 NEW_TEMP_REG(iptr->dst.varindex);
1483 FREE_TEMP_REG(iptr->sx.s23.s3.varindex);
1484 FREE_TEMP_REG(iptr->sx.s23.s2.varindex);
1485 FREE_TEMP_REG(iptr->s1.varindex);
1488 /* pop 1 push 0 store */
1508 case ICMD_PUTSTATIC:
1509 case ICMD_PUTFIELDCONST:
1511 /* pop 1 push 0 branch */
1514 case ICMD_IFNONNULL:
1530 /* pop 1 push 0 table branch */
1532 case ICMD_TABLESWITCH:
1533 case ICMD_LOOKUPSWITCH:
1535 case ICMD_MONITORENTER:
1536 case ICMD_MONITOREXIT:
1537 FREE_TEMP_REG(iptr->s1.varindex);
1540 /* pop 2 push 0 branch */
1542 case ICMD_IF_ICMPEQ:
1543 case ICMD_IF_ICMPNE:
1544 case ICMD_IF_ICMPLT:
1545 case ICMD_IF_ICMPGE:
1546 case ICMD_IF_ICMPGT:
1547 case ICMD_IF_ICMPLE:
1549 case ICMD_IF_LCMPEQ:
1550 case ICMD_IF_LCMPNE:
1551 case ICMD_IF_LCMPLT:
1552 case ICMD_IF_LCMPGE:
1553 case ICMD_IF_LCMPGT:
1554 case ICMD_IF_LCMPLE:
1556 case ICMD_IF_FCMPEQ:
1557 case ICMD_IF_FCMPNE:
1559 case ICMD_IF_FCMPL_LT:
1560 case ICMD_IF_FCMPL_GE:
1561 case ICMD_IF_FCMPL_GT:
1562 case ICMD_IF_FCMPL_LE:
1564 case ICMD_IF_FCMPG_LT:
1565 case ICMD_IF_FCMPG_GE:
1566 case ICMD_IF_FCMPG_GT:
1567 case ICMD_IF_FCMPG_LE:
1569 case ICMD_IF_DCMPEQ:
1570 case ICMD_IF_DCMPNE:
1572 case ICMD_IF_DCMPL_LT:
1573 case ICMD_IF_DCMPL_GE:
1574 case ICMD_IF_DCMPL_GT:
1575 case ICMD_IF_DCMPL_LE:
1577 case ICMD_IF_DCMPG_LT:
1578 case ICMD_IF_DCMPG_GE:
1579 case ICMD_IF_DCMPG_GT:
1580 case ICMD_IF_DCMPG_LE:
1582 case ICMD_IF_ACMPEQ:
1583 case ICMD_IF_ACMPNE:
1591 case ICMD_IASTORECONST:
1592 case ICMD_LASTORECONST:
1593 case ICMD_AASTORECONST:
1594 case ICMD_BASTORECONST:
1595 case ICMD_CASTORECONST:
1596 case ICMD_SASTORECONST:
1597 FREE_TEMP_REG(iptr->sx.s23.s2.varindex);
1598 FREE_TEMP_REG(iptr->s1.varindex);
1601 /* pop 0 push 1 copy */
1604 /* src === dst->prev (identical Stackslot Element) */
1605 /* src --> dst (copied value, take same reg/mem) */
1607 if (!simplereg_alloc_dup(jd, iptr->s1.varindex, iptr->dst.varindex)) {
1608 NEW_TEMP_REG(iptr->dst.varindex);
1611 v = VAROP(iptr->dst);
1613 if (v->flags & INMEMORY) {
1614 int32_t memindex = v->vv.regoff / SIZE_OF_STACKSLOT;
1615 if (memindex >= rd->memcopycountsize) {
1616 int newsize = (memindex + 1) * 2;
1617 i = rd->memcopycountsize;
1618 rd->memcopycount = DMREALLOC(rd->memcopycount, int, i, newsize);
1619 MZERO(rd->memcopycount + i, int, newsize - i);
1620 rd->memcopycountsize = newsize;
1622 rd->memcopycount[memindex]++;
1625 /* XXX split reg/mem variables on arm may need special handling here */
1627 s4 regindex = REG_INDEX(v->vv.regoff, v->type);
1629 rd->regcopycount[regindex]++;
1634 /* pop 1 push 1 move */
1637 if (!simplereg_alloc_dup(jd, iptr->s1.varindex, iptr->dst.varindex)) {
1638 NEW_TEMP_REG(iptr->dst.varindex);
1639 FREE_TEMP_REG(iptr->s1.varindex);
1689 FREE_TEMP_REG(iptr->sx.s23.s2.varindex);
1690 FREE_TEMP_REG(iptr->s1.varindex);
1691 NEW_TEMP_REG(iptr->dst.varindex);
1696 case ICMD_IADDCONST:
1697 case ICMD_ISUBCONST:
1698 case ICMD_IMULCONST:
1702 case ICMD_IANDCONST:
1704 case ICMD_IXORCONST:
1705 case ICMD_ISHLCONST:
1706 case ICMD_ISHRCONST:
1707 case ICMD_IUSHRCONST:
1709 case ICMD_LADDCONST:
1710 case ICMD_LSUBCONST:
1711 case ICMD_LMULCONST:
1715 case ICMD_LANDCONST:
1717 case ICMD_LXORCONST:
1718 case ICMD_LSHLCONST:
1719 case ICMD_LSHRCONST:
1720 case ICMD_LUSHRCONST:
1725 case ICMD_INT2SHORT:
1743 case ICMD_CHECKCAST:
1745 case ICMD_ARRAYLENGTH:
1746 case ICMD_INSTANCEOF:
1749 case ICMD_ANEWARRAY:
1752 FREE_TEMP_REG(iptr->s1.varindex);
1753 NEW_TEMP_REG(iptr->dst.varindex);
1758 case ICMD_GETSTATIC:
1761 NEW_TEMP_REG(iptr->dst.varindex);
1764 /* pop many push any */
1766 case ICMD_INVOKESTATIC:
1767 case ICMD_INVOKESPECIAL:
1768 case ICMD_INVOKEVIRTUAL:
1769 case ICMD_INVOKEINTERFACE:
1770 INSTRUCTION_GET_METHODDESC(iptr,md);
1772 argp = iptr->sx.s23.s2.args;
1774 FREE_TEMP_REG(*argp);
1777 if (md->returntype.type != TYPE_VOID)
1778 NEW_TEMP_REG(iptr->dst.varindex);
1782 bte = iptr->sx.s23.s3.bte;
1785 argp = iptr->sx.s23.s2.args;
1787 FREE_TEMP_REG(*argp);
1790 if (md->returntype.type != TYPE_VOID)
1791 NEW_TEMP_REG(iptr->dst.varindex);
1794 case ICMD_MULTIANEWARRAY:
1795 i = iptr->s1.argcount;
1796 argp = iptr->sx.s23.s2.args;
1798 FREE_TEMP_REG(*argp);
1801 NEW_TEMP_REG(iptr->dst.varindex);
1805 exceptions_throw_internalerror("Unknown ICMD %d during register allocation",
1810 } /* while instructions */
1813 } /* while blocks */
1817 #if defined(ENABLE_STATISTICS)
1818 void simplereg_make_statistics(jitdata *jd)
1826 stackptr src, src_old;
1831 int size_interface; /* == maximum size of in/out stack at basic block boundaries */
1835 /* get required compiler data */
1845 /* count how many local variables are held in memory or register */
1846 for(i=0; i < jd->localcount; i++) {
1847 if (VAR(i)->flags & INMEMORY) {
1848 count_locals_spilled++;
1852 count_locals_register++;
1856 /* count how many stack slots are held in memory or register */
1858 bptr = jd->basicblocks;
1860 while (bptr != NULL) {
1861 if (bptr->flags >= BBREACHED) {
1863 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1866 /* check for memory moves from interface to BB instack */
1867 len = bptr->indepth;
1869 if (len > size_interface) size_interface = len;
1873 var = VAR(bptr->invars[len]);
1875 /* invars statistics (currently none) */
1878 /* check for memory moves from BB outstack to interface */
1879 len = bptr->outdepth;
1880 if (len > size_interface) size_interface = len;
1884 var = VAR(bptr->outvars[len]);
1886 /* outvars statistics (currently none) */
1888 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1894 dst = bptr->instack;
1895 iptr = bptr->iinstr;
1899 while (--len >= 0) {
1901 dst = iptr->dst.var;
1903 if ((src!= NULL) && (src != src_old)) { /* new stackslot */
1904 switch (src->varkind) {
1907 if (!(src->flags & INMEMORY))
1908 count_ss_register++;
1914 /* case LOCALVAR: */
1915 /* if (!(rd->locals[src->varnum][src->type].flags & INMEMORY)) */
1916 /* count_ss_register++; */
1918 /* count_ss_spilled++; */
1921 if (!(src->flags & INMEMORY))
1922 count_argument_mem_ss++;
1924 count_argument_reg_ss++;
1928 /* if (IS_FLT_DBL_TYPE(src->type)) { */
1929 /* if (src->varnum < FLT_ARG_CNT) { */
1930 /* count_ss_register++; */
1934 /* #if defined(__POWERPC__) */
1935 /* if (src->varnum < INT_ARG_CNT - (IS_2_WORD_TYPE(src->type) != 0)) { */
1937 /* if (src->varnum < INT_ARG_CNT) { */
1939 /* count_ss_register++; */
1943 /* count_ss_spilled++; */
1950 } /* while instructions */
1955 } /* while blocks */
1957 count_interface_size += size_interface; /* accummulate the size of the interface (between bb boundaries) */
1958 if (in_register) count_method_in_register++;
1960 /* printf("INREGISTER: %s%s%s\n",m->class->name->text, m->name->text, m->descriptor->text); */
1963 #endif /* defined(ENABLE_STATISTICS) */
1967 * These are local overrides for various environment variables in Emacs.
1968 * Please do not remove this and leave it at the end of the file, where
1969 * Emacs will automagically detect them.
1970 * ---------------------------------------------------------------------
1973 * indent-tabs-mode: t
1977 * vim:noexpandtab:sw=4:ts=4: