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 7766 2007-04-19 13:24:48Z michi $
39 #include "mm/memory.h"
41 #include "vm/builtin.h"
42 #include "vm/exceptions.h"
43 #include "vm/resolve.h"
44 #include "vm/stringlocal.h"
46 #include "vm/jit/abi.h"
47 #include "vm/jit/reg.h"
48 #include "vm/jit/show.h"
49 #include "vm/jit/allocator/simplereg.h"
51 #include "vmcore/method.h"
52 #include "vmcore/options.h"
56 # define LOG(args) printf args
62 /* function prototypes for this file ******************************************/
64 static void simplereg_allocate_interfaces(jitdata *jd);
65 static void simplereg_allocate_locals(jitdata *jd);
66 static void simplereg_allocate_temporaries(jitdata *jd);
69 /* total number of registers */
71 #if defined(HAS_ADDRESS_REGISTER_FILE)
72 #define TOTAL_REG_CNT (INT_REG_CNT + FLT_REG_CNT + ADR_REG_CNT)
74 #define TOTAL_REG_CNT (INT_REG_CNT + FLT_REG_CNT)
78 /* macros for handling register stacks ****************************************/
80 #define AVAIL_FRONT(cnt, limit) ((cnt) < (limit))
81 #define AVAIL_BACK(cnt) ((cnt) > 0)
83 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
84 #define AVAIL_FRONT_INT(cnt, limit) ((cnt) < (limit) - intregsneeded)
85 #define AVAIL_BACK_INT(cnt) ((cnt) > intregsneeded)
87 #define AVAIL_FRONT_INT(cnt, limit) AVAIL_FRONT(cnt, limit)
88 #define AVAIL_BACK_INT(cnt) AVAIL_BACK(cnt)
91 #define POP_FRONT(stk, cnt, reg) do { reg = stk[cnt++]; } while (0)
92 #define POP_BACK(stk, cnt, reg) do { reg = stk[--cnt]; } while (0)
93 #define PUSH_FRONT(stk, cnt, reg) do { stk[--cnt] = (reg); } while (0)
94 #define PUSH_BACK(stk, cnt, reg) do { stk[cnt++] = (reg); } while (0)
96 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
97 #define POP_FRONT_INT(stk, cnt, reg) \
99 if (intregsneeded) { \
100 reg = PACK_REGS(stk[cnt], stk[cnt+1]); \
104 POP_FRONT(stk, cnt, reg); \
107 #define POP_FRONT_INT(stk, cnt, reg) POP_FRONT(stk, cnt, reg)
110 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
111 #define POP_BACK_INT(stk, cnt, reg) \
113 if (intregsneeded) { \
115 reg = PACK_REGS(stk[cnt], stk[cnt+1]); \
118 POP_BACK(stk, cnt, reg); \
121 #define POP_BACK_INT(stk, cnt, reg) POP_BACK(stk, cnt, reg)
124 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
125 #define PUSH_BACK_INT(stk, cnt, reg) \
127 if (intregsneeded) { \
128 stk[cnt] = GET_LOW_REG(reg); \
129 stk[cnt + 1] = GET_HIGH_REG(reg); \
133 PUSH_BACK(stk, cnt, reg); \
136 #define PUSH_BACK_INT(stk, cnt, reg) PUSH_BACK(stk, cnt, reg)
139 #define AVAIL_ARG_FLT AVAIL_FRONT(rd->argfltreguse, FLT_ARG_CNT)
140 #define AVAIL_TMP_FLT AVAIL_BACK(rd->tmpfltreguse)
141 #define AVAIL_SAV_FLT AVAIL_BACK(rd->savfltreguse)
143 #define AVAIL_ARG_ADR AVAIL_FRONT(rd->argadrreguse, ADR_ARG_CNT)
144 #define AVAIL_TMP_ADR AVAIL_BACK(rd->tmpadrreguse)
145 #define AVAIL_SAV_ADR AVAIL_BACK(rd->savadrreguse)
147 #define AVAIL_ARG_INT AVAIL_FRONT_INT(rd->argintreguse, INT_ARG_CNT)
148 #define AVAIL_TMP_INT AVAIL_BACK_INT(rd->tmpintreguse)
149 #define AVAIL_SAV_INT AVAIL_BACK_INT(rd->savintreguse)
151 #define AVAIL_FREE_ARG_FLT AVAIL_BACK(rd->freeargflttop)
152 #define AVAIL_FREE_TMP_FLT AVAIL_BACK(rd->freetmpflttop)
153 #define AVAIL_FREE_SAV_FLT AVAIL_BACK(rd->freesavflttop)
155 #define AVAIL_FREE_ARG_ADR AVAIL_BACK(rd->freeargadrtop)
156 #define AVAIL_FREE_TMP_ADR AVAIL_BACK(rd->freetmpadrtop)
157 #define AVAIL_FREE_SAV_ADR AVAIL_BACK(rd->freesavadrtop)
159 #define AVAIL_FREE_ARG_INT AVAIL_BACK_INT(rd->freearginttop)
160 #define AVAIL_FREE_TMP_INT AVAIL_BACK_INT(rd->freetmpinttop)
161 #define AVAIL_FREE_SAV_INT AVAIL_BACK_INT(rd->freesavinttop)
163 #define TAKE_ARG_FLT(r) POP_FRONT(abi_registers_float_argument, rd->argfltreguse, r)
164 #define TAKE_TMP_FLT(r) POP_BACK(rd->tmpfltregs, rd->tmpfltreguse, r)
165 #define TAKE_SAV_FLT(r) POP_BACK(rd->savfltregs, rd->savfltreguse, r)
167 #define TAKE_ARG_ADR(r) POP_FRONT(rd->argadrregs, rd->argadrreguse, r)
168 #define TAKE_TMP_ADR(r) POP_BACK(rd->tmpadrregs, rd->tmpadrreguse, r)
169 #define TAKE_SAV_ADR(r) POP_BACK(rd->savadrregs, rd->savadrreguse, r)
171 #define TAKE_ARG_INT(r) POP_FRONT_INT(abi_registers_integer_argument, rd->argintreguse, r)
172 #define TAKE_TMP_INT(r) POP_BACK_INT(rd->tmpintregs, rd->tmpintreguse, r)
173 #define TAKE_SAV_INT(r) POP_BACK_INT(rd->savintregs, rd->savintreguse, r)
175 #define TAKE_FREE_ARG_FLT(r) POP_BACK(rd->freeargfltregs, rd->freeargflttop, r)
176 #define TAKE_FREE_TMP_FLT(r) POP_BACK(rd->freetmpfltregs, rd->freetmpflttop, r)
177 #define TAKE_FREE_SAV_FLT(r) POP_BACK(rd->freesavfltregs, rd->freesavflttop, r)
179 #define TAKE_FREE_ARG_ADR(r) POP_BACK(rd->freeargadrregs, rd->freeargadrtop, r)
180 #define TAKE_FREE_TMP_ADR(r) POP_BACK(rd->freetmpadrregs, rd->freetmpadrtop, r)
181 #define TAKE_FREE_SAV_ADR(r) POP_BACK(rd->freesavadrregs, rd->freesavadrtop, r)
183 #define TAKE_FREE_ARG_INT(r) POP_BACK_INT(rd->freeargintregs, rd->freearginttop, r)
184 #define TAKE_FREE_TMP_INT(r) POP_BACK_INT(rd->freetmpintregs, rd->freetmpinttop, r)
185 #define TAKE_FREE_SAV_INT(r) POP_BACK_INT(rd->freesavintregs, rd->freesavinttop, r)
187 #define PUSH_FREE_ARG_FLT(r) PUSH_BACK(rd->freeargfltregs, rd->freeargflttop, r)
188 #define PUSH_FREE_TMP_FLT(r) PUSH_BACK(rd->freetmpfltregs, rd->freetmpflttop, r)
189 #define PUSH_FREE_SAV_FLT(r) PUSH_BACK(rd->freesavfltregs, rd->freesavflttop, r)
191 #define PUSH_FREE_ARG_ADR(r) PUSH_BACK(rd->freeargadrregs, rd->freeargadrtop, r)
192 #define PUSH_FREE_TMP_ADR(r) PUSH_BACK(rd->freetmpadrregs, rd->freetmpadrtop, r)
193 #define PUSH_FREE_SAV_ADR(r) PUSH_BACK(rd->freesavadrregs, rd->freesavadrtop, r)
195 #define PUSH_FREE_ARG_INT(r) PUSH_BACK_INT(rd->freeargintregs, rd->freearginttop, r)
196 #define PUSH_FREE_TMP_INT(r) PUSH_BACK_INT(rd->freetmpintregs, rd->freetmpinttop, r)
197 #define PUSH_FREE_SAV_INT(r) PUSH_BACK_INT(rd->freesavintregs, rd->freesavinttop, r)
200 /* macros for allocating memory slots ****************************************/
202 #define NEW_MEM_SLOT(r) \
205 rd->memuse += memneeded + 1; \
208 #define NEW_MEM_SLOT_ALIGNED(r) \
210 if ( (memneeded) && (rd->memuse & 1)) \
213 rd->memuse += memneeded + 1; \
216 #define NEW_MEM_SLOT_ALIGNED_REUSE_PADDING(r) \
218 if ( (memneeded) && (rd->memuse & 1)) { \
219 PUSH_BACK(rd->freemem, rd->freememtop, rd->memuse); \
223 rd->memuse += memneeded + 1; \
226 #if defined(ALIGN_LONGS_IN_MEMORY)
227 #define NEW_MEM_SLOT_INT_LNG(r) NEW_MEM_SLOT_ALIGNED(r)
229 #define NEW_MEM_SLOT_INT_LNG(r) NEW_MEM_SLOT(r)
232 #if defined(ALIGN_DOUBLES_IN_MEMORY)
233 #define NEW_MEM_SLOT_FLT_DBL(r) NEW_MEM_SLOT_ALIGNED(r)
235 #define NEW_MEM_SLOT_FLT_DBL(r) NEW_MEM_SLOT(r)
238 #if defined(ALIGN_LONGS_IN_MEMORY) || defined(ALIGN_DOUBLES_IN_MEMORY)
239 #define NEW_MEM_SLOT_REUSE_PADDING(r) NEW_MEM_SLOT_ALIGNED_REUSE_PADDING(r)
241 #define NEW_MEM_SLOT_REUSE_PADDING(r) NEW_MEM_SLOT(r)
245 /* macros for creating/freeing temporary variables ***************************/
247 #define NEW_TEMP_REG(index) \
248 if ( ((index) >= jd->localcount) \
249 && (!(VAR(index)->flags & (INOUT | PREALLOC))) ) \
250 simplereg_new_temp(jd, (index))
253 #define FREE_TEMP_REG(index) \
254 if (((index) > jd->localcount) \
255 && (!(VAR(index)->flags & (PREALLOC)))) \
256 simplereg_free_temp(jd, (index))
259 /* macro for getting a unique register index *********************************/
261 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
262 #define REG_INDEX_NON_ADR(regoff, type) \
263 (IS_FLT_DBL_TYPE(type) ? (INT_REG_CNT + (regoff)) : (GET_LOW_REG(regoff)))
265 #define REG_INDEX_NON_ADR(regoff, type) \
266 (IS_FLT_DBL_TYPE(type) ? (INT_REG_CNT + (regoff)) : (regoff))
269 #if defined(HAS_ADDRESS_REGISTER_FILE)
270 #define REG_INDEX(regoff, type) \
271 (IS_ADR_TYPE(type) ? (regoff) : (ADR_REG_CNT + REG_INDEX_NON_ADR(regoff, type)))
273 #define REG_INDEX(regoff, type) REG_INDEX_NON_ADR(regoff, type)
277 /* regalloc ********************************************************************
279 Does a simple register allocation.
281 *******************************************************************************/
283 bool regalloc(jitdata *jd)
285 /* There is a problem with the use of unused float argument
286 registers in leafmethods for stackslots on c7 (2 * Dual Core
287 AMD Opteron(tm) Processor 270) - runtime for the jvm98 _mtrt
288 benchmark is heaviliy increased. This could be prevented by
289 setting rd->argfltreguse to FLT_ARG_CNT before calling
290 simplereg_allocate_temporaries and setting it back to the original
291 value before calling simplereg_allocate_locals. */
293 simplereg_allocate_interfaces(jd);
294 simplereg_allocate_temporaries(jd);
295 simplereg_allocate_locals(jd);
303 /* simplereg_allocate_interfaces ***********************************************
305 Allocates registers for all interface variables.
307 *******************************************************************************/
309 static void simplereg_allocate_interfaces(jitdata *jd)
316 int intalloc, fltalloc; /* Remember allocated Register/Memory offset */
317 /* in case more vars are packed into this interface slot */
319 /* Allocate LNG and DBL types first to ensure 2 memory slots or */
320 /* registers on HAS_4BYTE_STACKSLOT architectures. */
321 int typeloop[] = { TYPE_LNG, TYPE_DBL, TYPE_INT, TYPE_FLT, TYPE_ADR };
323 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
327 /* get required compiler data */
333 /* rd->memuse was already set in stack.c to allocate stack space
334 for passing arguments to called methods. */
336 #if defined(__I386__)
337 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
338 /* reserve 0(%esp) for Monitorenter/exit Argument on i386 */
344 if (jd->isleafmethod) {
345 /* Reserve argument register, which will be used for Locals acting */
347 if (rd->argintreguse < m->parseddesc->argintreguse)
348 rd->argintreguse = m->parseddesc->argintreguse;
349 if (rd->argfltreguse < m->parseddesc->argfltreguse)
350 rd->argfltreguse = m->parseddesc->argfltreguse;
351 #ifdef HAS_ADDRESS_REGISTER_FILE
352 if (rd->argadrreguse < m->parseddesc->argadrreguse)
353 rd->argadrreguse = m->parseddesc->argadrreguse;
357 for (s = 0; s < jd->maxinterfaces; s++) {
358 intalloc = -1; fltalloc = -1;
360 /* check if the interface at this stack depth must be a SAVEDVAR */
364 for (tt = 0; tt <=4; tt++) {
365 if ((t = jd->interface_map[s * 5 + tt].flags) != UNUSED) {
366 saved |= t & SAVEDVAR;
370 /* allocate reg/mem for each type the interface is used as */
372 for (tt = 0; tt <= 4; tt++) {
374 if (jd->interface_map[s * 5 + t].flags == UNUSED)
378 regoff = -1; /* initialize to invalid value */
380 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
381 intregsneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
384 #if defined(HAS_4BYTE_STACKSLOT)
385 memneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
389 #if defined(HAS_ADDRESS_REGISTER_FILE)
390 if (IS_ADR_TYPE(t)) {
391 if (!jd->isleafmethod && AVAIL_ARG_ADR) {
393 TAKE_ARG_ADR(regoff);
395 else if (AVAIL_TMP_ADR) {
396 TAKE_TMP_ADR(regoff);
398 else if (AVAIL_SAV_ADR) {
400 TAKE_SAV_ADR(regoff);
404 regoff = rd->memuse++;
407 else /* !IS_ADR_TYPE */
408 #endif /* defined(HAS_ADDRESS_REGISTER_FILE) */
410 if (IS_FLT_DBL_TYPE(t)) {
412 /* Reuse memory slot(s)/register(s) for shared interface slots */
413 flags |= jd->interface_map[fltalloc].flags & ~SAVEDVAR;
414 regoff = jd->interface_map[fltalloc].regoff;
416 else if (AVAIL_ARG_FLT) {
418 TAKE_ARG_FLT(regoff);
420 else if (AVAIL_TMP_FLT) {
421 TAKE_TMP_FLT(regoff);
423 else if (AVAIL_SAV_FLT) {
425 TAKE_SAV_FLT(regoff);
429 NEW_MEM_SLOT_FLT_DBL(regoff);
431 fltalloc = s * 5 + t;
433 else { /* !IS_FLT_DBL_TYPE(t) */
434 #if defined(HAS_4BYTE_STACKSLOT) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
436 * for i386 put all longs in memory
438 if (IS_2_WORD_TYPE(t)) {
440 NEW_MEM_SLOT_INT_LNG(regoff);
443 #endif /* defined(HAS_4BYTE_STACKSLOT) && !defined(SUPPORT_COMBINE...GISTERS) */
445 /* Reuse memory slot(s)/register(s) for shared interface slots */
446 flags |= jd->interface_map[intalloc].flags & ~SAVEDVAR;
447 regoff = jd->interface_map[intalloc].regoff;
448 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
449 /* reuse lower half */
450 if (!(flags & INMEMORY)
451 && IS_2_WORD_TYPE(intalloc % 5))
452 regoff = GET_LOW_REG(regoff);
458 TAKE_ARG_INT(regoff);
460 else if (AVAIL_TMP_INT) {
461 TAKE_TMP_INT(regoff);
463 else if (AVAIL_SAV_INT) {
465 TAKE_SAV_INT(regoff);
469 NEW_MEM_SLOT_INT_LNG(regoff);
473 intalloc = s * 5 + t;
474 } /* if (IS_FLT_DBL_TYPE(t)) */
478 /* now the same like above, but without a chance to take a temporary register */
479 #ifdef HAS_ADDRESS_REGISTER_FILE
480 if (IS_ADR_TYPE(t)) {
482 TAKE_SAV_ADR(regoff);
486 regoff = rd->memuse++;
492 if (IS_FLT_DBL_TYPE(t)) {
494 flags |= jd->interface_map[fltalloc].flags & ~SAVEDVAR;
495 regoff = jd->interface_map[fltalloc].regoff;
499 TAKE_SAV_FLT(regoff);
503 NEW_MEM_SLOT_FLT_DBL(regoff);
506 fltalloc = s * 5 + t;
508 else { /* IS_INT_LNG */
509 #if defined(HAS_4BYTE_STACKSLOT) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
511 * for i386 put all longs in memory
513 if (IS_2_WORD_TYPE(t)) {
515 NEW_MEM_SLOT_INT_LNG(regoff);
521 flags |= jd->interface_map[intalloc].flags & ~SAVEDVAR;
522 regoff = jd->interface_map[intalloc].regoff;
523 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
524 /* reuse lower half */
525 if (!(flags & INMEMORY)
526 && IS_2_WORD_TYPE(intalloc % 5))
527 regoff = GET_LOW_REG(regoff);
532 TAKE_SAV_INT(regoff);
536 NEW_MEM_SLOT_INT_LNG(regoff);
541 } /* if (IS_FLT_DBL_TYPE(t) else */
542 } /* if (IS_ADR_TYPE(t)) else */
543 } /* if (saved) else */
547 jd->interface_map[5*s + t].flags = flags | INOUT;
548 jd->interface_map[5*s + t].regoff = regoff;
554 /* simplereg_allocate_locals_leafmethod ****************************************
556 Allocates registers for all local variables of a leafmethod.
558 *******************************************************************************/
560 static void simplereg_allocate_locals_leafmethod(jitdata *jd)
567 int p, s, t, tt, varindex;
568 int intalloc, fltalloc;
570 int intregsneeded = 0;
572 int typeloop[] = { TYPE_LNG, TYPE_DBL, TYPE_INT, TYPE_FLT, TYPE_ADR };
573 int fargcnt, iargcnt;
574 #ifdef HAS_ADDRESS_REGISTER_FILE
578 /* get required compiler data */
586 iargcnt = rd->argintreguse;
587 fargcnt = rd->argfltreguse;
588 #ifdef HAS_ADDRESS_REGISTER_FILE
589 aargcnt = rd->argadrreguse;
591 for (p = 0, s = 0; s < jd->maxlocals; s++, p++) {
592 intalloc = -1; fltalloc = -1;
593 for (tt = 0; tt <= 4; tt++) {
595 varindex = jd->local_map[s * 5 + t];
596 if (varindex == UNUSED)
601 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
602 intregsneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
604 #if defined(HAS_4BYTE_STACKSLOT)
605 memneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
611 * #ifdef HAS_ADDRESS_REGISTER_FILE
618 * } else { / int & lng
622 * must not to be changed!
625 #ifdef HAS_ADDRESS_REGISTER_FILE
626 if (IS_ADR_TYPE(t)) {
627 if ((p < md->paramcount) && !md->params[p].inmemory) {
629 v->vv.regoff = rd->argadrregs[md->params[p].regoff];
631 else if (AVAIL_TMP_ADR) {
633 TAKE_TMP_ADR(v->vv.regoff);
635 /* use unused argument registers as local registers */
636 else if ((p >= md->paramcount) &&
637 (aargcnt < ADR_ARG_CNT))
640 POP_FRONT(rd->argadrregs, aargcnt, v->vv.regoff);
642 else if (AVAIL_SAV_ADR) {
644 TAKE_SAV_ADR(v->vv.regoff);
647 v->flags |= INMEMORY;
648 v->vv.regoff = rd->memuse++;
653 if (IS_FLT_DBL_TYPE(t)) {
655 v->flags = VAR(fltalloc)->flags;
656 v->vv.regoff = VAR(fltalloc)->vv.regoff;
658 #if !defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
659 /* We can only use float arguments as local variables,
660 * if we do not pass them in integer registers. */
661 else if ((p < md->paramcount) && !md->params[p].inmemory) {
663 v->vv.regoff = md->params[p].regoff;
666 else if (AVAIL_TMP_FLT) {
668 TAKE_TMP_FLT(v->vv.regoff);
670 /* use unused argument registers as local registers */
671 else if ((p >= md->paramcount) && (fargcnt < FLT_ARG_CNT)) {
673 POP_FRONT(abi_registers_float_argument,
674 fargcnt, v->vv.regoff);
676 else if (AVAIL_SAV_FLT) {
678 TAKE_SAV_FLT(v->vv.regoff);
682 NEW_MEM_SLOT_FLT_DBL(v->vv.regoff);
684 fltalloc = jd->local_map[s * 5 + t];
688 #if defined(HAS_4BYTE_STACKSLOT) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
690 * for i386 put all longs in memory
692 if (IS_2_WORD_TYPE(t)) {
694 NEW_MEM_SLOT_INT_LNG(v->vv.regoff);
700 v->flags = VAR(intalloc)->flags;
701 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
702 if (!(v->flags & INMEMORY)
703 && IS_2_WORD_TYPE(VAR(intalloc)->type))
704 v->vv.regoff = GET_LOW_REG(
705 VAR(intalloc)->vv.regoff);
708 v->vv.regoff = VAR(intalloc)->vv.regoff;
710 else if ((p < md->paramcount) &&
711 !md->params[p].inmemory)
714 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
715 if (IS_2_WORD_TYPE(t))
717 PACK_REGS(GET_LOW_REG(md->params[p].regoff),
718 GET_HIGH_REG(md->params[p].regoff));
721 v->vv.regoff = md->params[p].regoff;
723 else if (AVAIL_TMP_INT) {
725 TAKE_TMP_INT(v->vv.regoff);
728 * use unused argument registers as local registers
730 else if ((p >= m->parseddesc->paramcount) &&
731 (iargcnt + intregsneeded < INT_ARG_CNT))
734 POP_FRONT_INT(abi_registers_integer_argument,
735 iargcnt, v->vv.regoff);
737 else if (AVAIL_SAV_INT) {
739 TAKE_SAV_INT(v->vv.regoff);
743 NEW_MEM_SLOT_INT_LNG(v->vv.regoff);
746 intalloc = jd->local_map[s * 5 + t];
748 #ifdef HAS_ADDRESS_REGISTER_FILE
751 } /* for (tt=0;...) */
753 /* If the current parameter is a 2-word type, the next local slot */
756 if (p < md->paramcount)
757 if (IS_2_WORD_TYPE(md->paramtypes[p].type))
762 /* simplereg_allocate_locals ***************************************************
764 Allocates registers for all local variables.
766 *******************************************************************************/
768 static void simplereg_allocate_locals(jitdata *jd)
773 int s, t, tt, varindex;
774 int intalloc, fltalloc;
777 int typeloop[] = { TYPE_LNG, TYPE_DBL, TYPE_INT, TYPE_FLT, TYPE_ADR };
778 #ifdef SUPPORT_COMBINE_INTEGER_REGISTERS
782 /* get required compiler data */
787 if (jd->isleafmethod) {
788 simplereg_allocate_locals_leafmethod(jd);
792 for (s = 0; s < jd->maxlocals; s++) {
793 intalloc = -1; fltalloc = -1;
794 for (tt=0; tt<=4; tt++) {
797 varindex = jd->local_map[s * 5 + t];
798 if (varindex == UNUSED)
803 #ifdef SUPPORT_COMBINE_INTEGER_REGISTERS
804 intregsneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
807 #if defined(HAS_4BYTE_STACKSLOT)
808 memneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
811 #ifdef HAS_ADDRESS_REGISTER_FILE
812 if (IS_ADR_TYPE(t)) {
815 TAKE_SAV_ADR(v->vv.regoff);
819 v->vv.regoff = rd->memuse++;
824 if (IS_FLT_DBL_TYPE(t)) {
826 v->flags = VAR(fltalloc)->flags;
827 v->vv.regoff = VAR(fltalloc)->vv.regoff;
829 else if (AVAIL_SAV_FLT) {
831 TAKE_SAV_FLT(v->vv.regoff);
835 NEW_MEM_SLOT_FLT_DBL(v->vv.regoff);
837 fltalloc = jd->local_map[s * 5 + t];
840 #if defined(HAS_4BYTE_STACKSLOT) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
842 * for i386 put all longs in memory
844 if (IS_2_WORD_TYPE(t)) {
846 NEW_MEM_SLOT_INT_LNG(v->vv.regoff);
851 v->flags = VAR(intalloc)->flags;
852 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
853 if (!(v->flags & INMEMORY)
854 && IS_2_WORD_TYPE(VAR(intalloc)->type))
855 v->vv.regoff = GET_LOW_REG(
856 VAR(intalloc)->vv.regoff);
859 v->vv.regoff = VAR(intalloc)->vv.regoff;
861 else if (AVAIL_SAV_INT) {
863 TAKE_SAV_INT(v->vv.regoff);
867 NEW_MEM_SLOT_INT_LNG(v->vv.regoff);
869 #if defined(HAS_4BYTE_STACKSLOT) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
872 intalloc = jd->local_map[s * 5 + t];
874 #ifdef HAS_ADDRESS_REGISTER_FILE
882 static void simplereg_init(jitdata *jd, registerdata *rd)
887 #if defined(HAS_4BYTE_STACKSLOT)
888 rd->freememtop_2 = 0;
891 rd->freetmpinttop = 0;
892 rd->freesavinttop = 0;
893 rd->freetmpflttop = 0;
894 rd->freesavflttop = 0;
895 #ifdef HAS_ADDRESS_REGISTER_FILE
896 rd->freetmpadrtop = 0;
897 rd->freesavadrtop = 0;
900 rd->freearginttop = 0;
901 rd->freeargflttop = 0;
902 #ifdef HAS_ADDRESS_REGISTER_FILE
903 rd->freeargadrtop = 0;
906 rd->regisoutvar = DMNEW(int, TOTAL_REG_CNT);
907 rd->regcopycount = DMNEW(int, TOTAL_REG_CNT);
908 MZERO(rd->regcopycount, int, TOTAL_REG_CNT);
910 /* memcopycount is dynamically allocated when needed */
912 rd->memcopycount = NULL;
913 rd->memcopycountsize = 0;
915 rd->intusedinout = DMNEW(int, INT_REG_CNT);
916 MZERO(rd->intusedinout, int, INT_REG_CNT);
917 rd->fltusedinout = DMNEW(int, FLT_REG_CNT);
918 MZERO(rd->fltusedinout, int, FLT_REG_CNT);
920 /* record the interface registers as used */
922 for (i=0; i<rd->argintreguse; ++i)
923 rd->intusedinout[abi_registers_integer_argument[i]] = 1;
924 for (i=rd->tmpintreguse; i<INT_TMP_CNT; ++i)
925 rd->intusedinout[rd->tmpintregs[i]] = 1;
926 for (i=rd->savintreguse; i<INT_SAV_CNT; ++i)
927 rd->intusedinout[rd->savintregs[i]] = 1;
929 for (i=0; i<rd->argfltreguse; ++i)
930 rd->fltusedinout[abi_registers_float_argument[i]] = 1;
931 for (i=rd->tmpfltreguse; i<FLT_TMP_CNT; ++i)
932 rd->fltusedinout[rd->tmpfltregs[i]] = 1;
933 for (i=rd->savfltreguse; i<FLT_SAV_CNT; ++i)
934 rd->fltusedinout[rd->savfltregs[i]] = 1;
936 #ifdef HAS_ADDRESS_REGISTER_FILE
937 rd->adrusedinout = DMNEW(int, ADR_REG_CNT);
938 MZERO(rd->adrusedinout, int, ADR_REG_CNT);
940 for (i=0; i<rd->argadrreguse; ++i)
941 rd->adrusedinout[rd->argadrregs[i]] = 1;
942 for (i=rd->tmpadrreguse; i<ADR_TMP_CNT; ++i)
943 rd->adrusedinout[rd->tmpadrregs[i]] = 1;
944 for (i=rd->savadrreguse; i<ADR_SAV_CNT; ++i)
945 rd->adrusedinout[rd->savadrregs[i]] = 1;
950 static void simplereg_init_block(registerdata *rd)
954 /* remove all interface registers from the free lists */
956 for (i=0; i<rd->freearginttop; ++i)
957 if (rd->intusedinout[rd->freeargintregs[i]]) {
958 rd->freeargintregs[i--] = rd->freeargintregs[--rd->freearginttop];
960 for (i=0; i<rd->freetmpinttop; ++i)
961 if (rd->intusedinout[rd->freetmpintregs[i]]) {
962 rd->freetmpintregs[i--] = rd->freetmpintregs[--rd->freetmpinttop];
964 for (i=0; i<rd->freesavinttop; ++i)
965 if (rd->intusedinout[rd->freesavintregs[i]]) {
966 rd->freesavintregs[i--] = rd->freesavintregs[--rd->freesavinttop];
969 for (i=0; i<rd->freeargflttop; ++i)
970 if (rd->fltusedinout[rd->freeargfltregs[i]]) {
971 rd->freeargfltregs[i--] = rd->freeargfltregs[--rd->freeargflttop];
973 for (i=0; i<rd->freetmpflttop; ++i)
974 if (rd->fltusedinout[rd->freetmpfltregs[i]]) {
975 rd->freetmpfltregs[i--] = rd->freetmpfltregs[--rd->freetmpflttop];
977 for (i=0; i<rd->freesavflttop; ++i)
978 if (rd->fltusedinout[rd->freesavfltregs[i]]) {
979 rd->freesavfltregs[i--] = rd->freesavfltregs[--rd->freesavflttop];
982 #ifdef HAS_ADDRESS_REGISTER_FILE
983 for (i=0; i<rd->freeargadrtop; ++i)
984 if (rd->adrusedinout[rd->freeargadrregs[i]]) {
985 rd->freeargadrregs[i--] = rd->freeargadrregs[--rd->freeargadrtop];
987 for (i=0; i<rd->freetmpadrtop; ++i)
988 if (rd->adrusedinout[rd->freetmpadrregs[i]]) {
989 rd->freetmpadrregs[i--] = rd->freetmpadrregs[--rd->freetmpadrtop];
991 for (i=0; i<rd->freesavadrtop; ++i)
992 if (rd->adrusedinout[rd->freesavadrregs[i]]) {
993 rd->freesavadrregs[i--] = rd->freesavadrregs[--rd->freesavadrtop];
999 static void simplereg_new_temp(jitdata *jd, s4 index)
1001 #ifdef SUPPORT_COMBINE_INTEGER_REGISTERS
1012 /* assert that constants are not allocated */
1014 assert(v->type != TYPE_RET);
1016 /* Try to allocate a saved register if there is no temporary one */
1017 /* available. This is what happens during the second run. */
1018 tryagain = (v->flags & SAVEDVAR) ? 1 : 2;
1020 #ifdef SUPPORT_COMBINE_INTEGER_REGISTERS
1021 intregsneeded = (IS_2_WORD_TYPE(v->type)) ? 1 : 0;
1024 #if defined(HAS_4BYTE_STACKSLOT)
1025 memneeded = (IS_2_WORD_TYPE(v->type)) ? 1 : 0;
1030 for(; tryagain; --tryagain) {
1031 if (tryagain == 1) {
1032 if (!(v->flags & SAVEDVAR))
1034 #ifdef HAS_ADDRESS_REGISTER_FILE
1035 if (IS_ADR_TYPE(v->type)) {
1036 if (AVAIL_FREE_SAV_ADR) {
1037 TAKE_FREE_SAV_ADR(v->vv.regoff);
1040 else if (AVAIL_SAV_ADR) {
1041 TAKE_SAV_ADR(v->vv.regoff);
1048 if (IS_FLT_DBL_TYPE(v->type)) {
1049 if (AVAIL_FREE_SAV_FLT) {
1050 TAKE_FREE_SAV_FLT(v->vv.regoff);
1053 else if (AVAIL_SAV_FLT) {
1054 TAKE_SAV_FLT(v->vv.regoff);
1059 #if defined(HAS_4BYTE_STACKSLOT) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1061 * for i386 put all longs in memory
1063 if (!IS_2_WORD_TYPE(v->type))
1066 if (AVAIL_FREE_SAV_INT) {
1067 TAKE_FREE_SAV_INT(v->vv.regoff);
1070 else if (AVAIL_SAV_INT) {
1071 TAKE_SAV_INT(v->vv.regoff);
1078 else { /* tryagain == 2 */
1079 #ifdef HAS_ADDRESS_REGISTER_FILE
1080 if (IS_ADR_TYPE(v->type)) {
1081 if (AVAIL_FREE_TMP_ADR) {
1082 TAKE_FREE_TMP_ADR(v->vv.regoff);
1085 else if (AVAIL_TMP_ADR) {
1086 TAKE_TMP_ADR(v->vv.regoff);
1093 if (IS_FLT_DBL_TYPE(v->type)) {
1094 if (AVAIL_FREE_ARG_FLT) {
1096 TAKE_FREE_ARG_FLT(v->vv.regoff);
1099 else if (AVAIL_ARG_FLT) {
1101 TAKE_ARG_FLT(v->vv.regoff);
1104 else if (AVAIL_FREE_TMP_FLT) {
1105 TAKE_FREE_TMP_FLT(v->vv.regoff);
1108 else if (AVAIL_TMP_FLT) {
1109 TAKE_TMP_FLT(v->vv.regoff);
1115 #if defined(HAS_4BYTE_STACKSLOT) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1117 * for i386 put all longs in memory
1119 if (!IS_2_WORD_TYPE(v->type))
1122 if (AVAIL_FREE_ARG_INT) {
1124 TAKE_FREE_ARG_INT(v->vv.regoff);
1127 else if (AVAIL_ARG_INT) {
1129 TAKE_ARG_INT(v->vv.regoff);
1132 else if (AVAIL_FREE_TMP_INT) {
1133 TAKE_FREE_TMP_INT(v->vv.regoff);
1136 else if (AVAIL_TMP_INT) {
1137 TAKE_TMP_INT(v->vv.regoff);
1140 } /* if (!IS_2_WORD_TYPE(s->type)) */
1141 } /* if (IS_FLT_DBL_TYPE(s->type)) */
1142 } /* if (IS_ADR_TYPE(s->type)) */
1143 } /* if (tryagain == 1) else */
1144 } /* for(; tryagain; --tryagain) */
1146 /* spill to memory */
1148 v->flags |= INMEMORY;
1150 #if defined(HAS_4BYTE_STACKSLOT)
1151 if ((memneeded == 1) && (rd->freememtop_2 > 0))
1152 POP_BACK(rd->freemem_2, rd->freememtop_2, v->vv.regoff);
1154 #endif /*defined(HAS_4BYTE_STACKSLOT) */
1155 if ((memneeded == 0) && (rd->freememtop > 0))
1156 POP_BACK(rd->freemem, rd->freememtop, v->vv.regoff);
1158 NEW_MEM_SLOT_REUSE_PADDING(v->vv.regoff);
1162 static void simplereg_free(registerdata *rd, s4 flags, s4 regoff, s4 type)
1164 /* assert that constants are not freed */
1166 assert(type != TYPE_RET);
1168 /* if this is a copy of another variable, just decrement the copy counter */
1170 /* XXX split reg/mem variables on arm may need special handling here */
1172 if (flags & INMEMORY) {
1176 if (regoff < rd->memcopycountsize && rd->memcopycount[regoff]) {
1177 rd->memcopycount[regoff]--;
1184 regindex = REG_INDEX(regoff, type);
1186 /* do not free interface registers that are needed as outvars */
1188 if (flags & INOUT) {
1189 if (rd->regisoutvar[regindex]) {
1190 LOG(("DONT FREE f=%02x r=%d t=%d\n", flags, regoff, type));
1194 LOG(("FREEING INVAR f=%02x r=%d t=%d\n", flags, regoff, type));
1197 if (rd->regcopycount[regindex]) {
1198 rd->regcopycount[regindex]--;
1203 if (flags & INMEMORY) {
1204 #if defined(HAS_4BYTE_STACKSLOT)
1205 if (IS_2_WORD_TYPE(type))
1206 PUSH_BACK(rd->freemem_2, rd->freememtop_2, regoff);
1209 PUSH_BACK(rd->freemem, rd->freememtop, regoff);
1214 /* freeing a register */
1216 #ifdef HAS_ADDRESS_REGISTER_FILE
1217 if (IS_ADR_TYPE(type)) {
1218 if (flags & (SAVEDVAR | SAVREG))
1219 PUSH_FREE_SAV_ADR(regoff);
1221 PUSH_FREE_TMP_ADR(regoff);
1224 else if (IS_FLT_DBL_TYPE(type)) {
1225 if (flags & (SAVEDVAR | SAVREG))
1226 PUSH_FREE_SAV_FLT(regoff);
1227 else if (flags & ARGREG)
1228 PUSH_FREE_ARG_FLT(regoff);
1230 PUSH_FREE_TMP_FLT(regoff);
1232 else { /* IS_INT_LNG_TYPE */
1233 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1234 s4 intregsneeded = (IS_2_WORD_TYPE(type)) ? 1 : 0;
1237 if (flags & (SAVEDVAR | SAVREG))
1238 PUSH_FREE_SAV_INT(regoff);
1239 else if (flags & ARGREG)
1240 PUSH_FREE_ARG_INT(regoff);
1242 PUSH_FREE_TMP_INT(regoff);
1247 static inline void simplereg_free_temp(jitdata *jd, s4 index)
1253 simplereg_free(jd->rd, v->flags, v->vv.regoff, v->type);
1257 static bool simplereg_alloc_dup(jitdata *jd, s4 srcindex, s4 dstindex)
1262 /* do not coalesce local variables here */
1264 if (srcindex <= jd->localcount || dstindex <= jd->localcount)
1270 /* do not coalesce in/out vars or preallocated variables here */
1272 if ((sv->flags | dv->flags) & (INOUT | PREALLOC))
1275 /* if the source is in memory, we can coalesce in any case */
1277 if (sv->flags & INMEMORY) {
1278 dv->flags |= INMEMORY;
1279 dv->vv.regoff = sv->vv.regoff;
1283 /* we do not allocate a REG_TMP to a REG_SAV variable */
1285 if ((sv->flags & SAVEDVAR) != (dv->flags & SAVEDVAR))
1289 dv->vv.regoff = sv->vv.regoff;
1290 dv->flags |= sv->flags & (SAVREG | ARGREG);
1296 /* simplereg_allocate_temporaries **********************************************
1298 Allocate temporary (non-interface, non-local) registers.
1300 *******************************************************************************/
1302 static void simplereg_allocate_temporaries(jitdata *jd)
1310 builtintable_entry *bte;
1319 /* get required compiler data */
1324 /* initialize temp registers */
1326 simplereg_init(jd, rd);
1328 bptr = jd->basicblocks;
1330 while (bptr != NULL) {
1331 if (bptr->flags >= BBREACHED) {
1333 LOG(("\nallocating block L%03d\n", bptr->nr));
1335 simplereg_init_block(rd);
1337 /* assert that all copy counts are zero */
1339 #if !defined(NDEBUG)
1340 for (i=0; i < TOTAL_REG_CNT; ++i)
1341 assert(rd->regcopycount[i] == 0);
1344 /* reset outvar flags */
1346 MZERO(rd->regisoutvar, int, TOTAL_REG_CNT);
1348 /* set allocation of invars */
1350 for (i=0; i<bptr->indepth; ++i)
1352 v = VAR(bptr->invars[i]);
1353 if (v->type == TYPE_RET)
1356 v->vv.regoff = jd->interface_map[5*i + v->type].regoff;
1357 v->flags = jd->interface_map[5*i + v->type].flags;
1359 if (!(v->flags & INMEMORY))
1360 rd->regcopycount[REG_INDEX(v->vv.regoff, v->type)] = 1;
1363 /* set allocation of outvars */
1365 for (i=0; i<bptr->outdepth; ++i)
1367 v = VAR(bptr->outvars[i]);
1368 if (v->type == TYPE_RET)
1371 v->vv.regoff = jd->interface_map[5*i + v->type].regoff;
1372 v->flags = jd->interface_map[5*i + v->type].flags;
1374 if (!(v->flags & INMEMORY)) {
1375 regindex = REG_INDEX(v->vv.regoff, v->type);
1376 rd->regcopycount[regindex] = 1;
1377 rd->regisoutvar[regindex] = 1;
1381 /* free interface registers not used in this block */
1383 for (i=0; i < 5 * jd->maxinterfaces; ++i) {
1385 regoff = jd->interface_map[i].regoff;
1386 flags = jd->interface_map[i].flags;
1388 if (!(flags & INMEMORY)) {
1389 if (!rd->regcopycount[REG_INDEX(regoff, type)]) {
1390 LOG(("MAY REUSE interface register f=%02x r=%d t=%d\n",
1391 flags, regoff, type));
1392 simplereg_free(rd, flags, regoff, type);
1394 /* mark it, so it is not freed again */
1395 rd->regcopycount[REG_INDEX(regoff, type)] = -1;
1400 /* reset copy counts */
1402 MZERO(rd->regcopycount, int, TOTAL_REG_CNT);
1404 /* iterate over ICMDS to allocate temporary variables */
1406 iptr = bptr->iinstr;
1409 while (--len >= 0) {
1411 switch (iptr->opc) {
1417 case ICMD_CHECKNULL:
1422 case ICMD_PUTSTATICCONST:
1423 case ICMD_INLINE_START:
1424 case ICMD_INLINE_END:
1425 case ICMD_INLINE_BODY:
1428 /* pop 0 push 1 const */
1436 /* pop 0 push 1 load */
1443 NEW_TEMP_REG(iptr->dst.varindex);
1457 FREE_TEMP_REG(iptr->sx.s23.s2.varindex);
1458 FREE_TEMP_REG(iptr->s1.varindex);
1459 NEW_TEMP_REG(iptr->dst.varindex);
1473 FREE_TEMP_REG(iptr->sx.s23.s3.varindex);
1474 FREE_TEMP_REG(iptr->sx.s23.s2.varindex);
1475 FREE_TEMP_REG(iptr->s1.varindex);
1478 /* pop 1 push 0 store */
1498 case ICMD_PUTSTATIC:
1499 case ICMD_PUTFIELDCONST:
1501 /* pop 1 push 0 branch */
1504 case ICMD_IFNONNULL:
1520 /* pop 1 push 0 table branch */
1522 case ICMD_TABLESWITCH:
1523 case ICMD_LOOKUPSWITCH:
1525 case ICMD_MONITORENTER:
1526 case ICMD_MONITOREXIT:
1527 FREE_TEMP_REG(iptr->s1.varindex);
1530 /* pop 2 push 0 branch */
1532 case ICMD_IF_ICMPEQ:
1533 case ICMD_IF_ICMPNE:
1534 case ICMD_IF_ICMPLT:
1535 case ICMD_IF_ICMPGE:
1536 case ICMD_IF_ICMPGT:
1537 case ICMD_IF_ICMPLE:
1539 case ICMD_IF_LCMPEQ:
1540 case ICMD_IF_LCMPNE:
1541 case ICMD_IF_LCMPLT:
1542 case ICMD_IF_LCMPGE:
1543 case ICMD_IF_LCMPGT:
1544 case ICMD_IF_LCMPLE:
1546 case ICMD_IF_FCMPEQ:
1547 case ICMD_IF_FCMPNE:
1549 case ICMD_IF_FCMPL_LT:
1550 case ICMD_IF_FCMPL_GE:
1551 case ICMD_IF_FCMPL_GT:
1552 case ICMD_IF_FCMPL_LE:
1554 case ICMD_IF_FCMPG_LT:
1555 case ICMD_IF_FCMPG_GE:
1556 case ICMD_IF_FCMPG_GT:
1557 case ICMD_IF_FCMPG_LE:
1559 case ICMD_IF_DCMPEQ:
1560 case ICMD_IF_DCMPNE:
1562 case ICMD_IF_DCMPL_LT:
1563 case ICMD_IF_DCMPL_GE:
1564 case ICMD_IF_DCMPL_GT:
1565 case ICMD_IF_DCMPL_LE:
1567 case ICMD_IF_DCMPG_LT:
1568 case ICMD_IF_DCMPG_GE:
1569 case ICMD_IF_DCMPG_GT:
1570 case ICMD_IF_DCMPG_LE:
1572 case ICMD_IF_ACMPEQ:
1573 case ICMD_IF_ACMPNE:
1581 case ICMD_IASTORECONST:
1582 case ICMD_LASTORECONST:
1583 case ICMD_AASTORECONST:
1584 case ICMD_BASTORECONST:
1585 case ICMD_CASTORECONST:
1586 case ICMD_SASTORECONST:
1587 FREE_TEMP_REG(iptr->sx.s23.s2.varindex);
1588 FREE_TEMP_REG(iptr->s1.varindex);
1591 /* pop 0 push 1 copy */
1594 /* src === dst->prev (identical Stackslot Element) */
1595 /* src --> dst (copied value, take same reg/mem) */
1597 if (!simplereg_alloc_dup(jd, iptr->s1.varindex, iptr->dst.varindex)) {
1598 NEW_TEMP_REG(iptr->dst.varindex);
1601 v = VAROP(iptr->dst);
1603 if (v->flags & INMEMORY) {
1604 if (v->vv.regoff >= rd->memcopycountsize) {
1605 int newsize = (v->vv.regoff + 1) * 2;
1606 i = rd->memcopycountsize;
1607 rd->memcopycount = DMREALLOC(rd->memcopycount, int, i, newsize);
1608 MZERO(rd->memcopycount + i, int, newsize - i);
1609 rd->memcopycountsize = newsize;
1611 rd->memcopycount[v->vv.regoff]++;
1614 /* XXX split reg/mem variables on arm may need special handling here */
1616 s4 regindex = REG_INDEX(v->vv.regoff, v->type);
1618 rd->regcopycount[regindex]++;
1623 /* pop 1 push 1 move */
1626 if (!simplereg_alloc_dup(jd, iptr->s1.varindex, iptr->dst.varindex)) {
1627 NEW_TEMP_REG(iptr->dst.varindex);
1628 FREE_TEMP_REG(iptr->s1.varindex);
1678 FREE_TEMP_REG(iptr->sx.s23.s2.varindex);
1679 FREE_TEMP_REG(iptr->s1.varindex);
1680 NEW_TEMP_REG(iptr->dst.varindex);
1685 case ICMD_IADDCONST:
1686 case ICMD_ISUBCONST:
1687 case ICMD_IMULCONST:
1691 case ICMD_IANDCONST:
1693 case ICMD_IXORCONST:
1694 case ICMD_ISHLCONST:
1695 case ICMD_ISHRCONST:
1696 case ICMD_IUSHRCONST:
1698 case ICMD_LADDCONST:
1699 case ICMD_LSUBCONST:
1700 case ICMD_LMULCONST:
1704 case ICMD_LANDCONST:
1706 case ICMD_LXORCONST:
1707 case ICMD_LSHLCONST:
1708 case ICMD_LSHRCONST:
1709 case ICMD_LUSHRCONST:
1714 case ICMD_INT2SHORT:
1732 case ICMD_CHECKCAST:
1734 case ICMD_ARRAYLENGTH:
1735 case ICMD_INSTANCEOF:
1738 case ICMD_ANEWARRAY:
1741 FREE_TEMP_REG(iptr->s1.varindex);
1742 NEW_TEMP_REG(iptr->dst.varindex);
1747 case ICMD_GETSTATIC:
1750 NEW_TEMP_REG(iptr->dst.varindex);
1753 /* pop many push any */
1755 case ICMD_INVOKESTATIC:
1756 case ICMD_INVOKESPECIAL:
1757 case ICMD_INVOKEVIRTUAL:
1758 case ICMD_INVOKEINTERFACE:
1759 INSTRUCTION_GET_METHODDESC(iptr,md);
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);
1771 bte = iptr->sx.s23.s3.bte;
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);
1783 case ICMD_MULTIANEWARRAY:
1784 i = iptr->s1.argcount;
1785 argp = iptr->sx.s23.s2.args;
1787 FREE_TEMP_REG(*argp);
1790 NEW_TEMP_REG(iptr->dst.varindex);
1794 exceptions_throw_internalerror("Unknown ICMD %d during register allocation",
1799 } /* while instructions */
1802 } /* while blocks */
1806 #if defined(ENABLE_STATISTICS)
1807 void simplereg_make_statistics(jitdata *jd)
1815 stackptr src, src_old;
1820 int size_interface; /* == maximum size of in/out stack at basic block boundaries */
1824 /* get required compiler data */
1834 /* count how many local variables are held in memory or register */
1835 for(i=0; i < jd->localcount; i++) {
1836 if (VAR(i)->flags & INMEMORY) {
1837 count_locals_spilled++;
1841 count_locals_register++;
1845 /* count how many stack slots are held in memory or register */
1847 bptr = jd->basicblocks;
1849 while (bptr != NULL) {
1850 if (bptr->flags >= BBREACHED) {
1852 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1855 /* check for memory moves from interface to BB instack */
1856 len = bptr->indepth;
1858 if (len > size_interface) size_interface = len;
1862 var = VAR(bptr->invars[len]);
1864 /* invars statistics (currently none) */
1867 /* check for memory moves from BB outstack to interface */
1868 len = bptr->outdepth;
1869 if (len > size_interface) size_interface = len;
1873 var = VAR(bptr->outvars[len]);
1875 /* outvars statistics (currently none) */
1877 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
1883 dst = bptr->instack;
1884 iptr = bptr->iinstr;
1888 while (--len >= 0) {
1890 dst = iptr->dst.var;
1892 if ((src!= NULL) && (src != src_old)) { /* new stackslot */
1893 switch (src->varkind) {
1896 if (!(src->flags & INMEMORY))
1897 count_ss_register++;
1903 /* case LOCALVAR: */
1904 /* if (!(rd->locals[src->varnum][src->type].flags & INMEMORY)) */
1905 /* count_ss_register++; */
1907 /* count_ss_spilled++; */
1910 if (!(src->flags & INMEMORY))
1911 count_argument_mem_ss++;
1913 count_argument_reg_ss++;
1917 /* if (IS_FLT_DBL_TYPE(src->type)) { */
1918 /* if (src->varnum < FLT_ARG_CNT) { */
1919 /* count_ss_register++; */
1923 /* #if defined(__POWERPC__) */
1924 /* if (src->varnum < INT_ARG_CNT - (IS_2_WORD_TYPE(src->type) != 0)) { */
1926 /* if (src->varnum < INT_ARG_CNT) { */
1928 /* count_ss_register++; */
1932 /* count_ss_spilled++; */
1939 } /* while instructions */
1944 } /* while blocks */
1946 count_interface_size += size_interface; /* accummulate the size of the interface (between bb boundaries) */
1947 if (in_register) count_method_in_register++;
1949 /* printf("INREGISTER: %s%s%s\n",m->class->name->text, m->name->text, m->descriptor->text); */
1952 #endif /* defined(ENABLE_STATISTICS) */
1956 * These are local overrides for various environment variables in Emacs.
1957 * Please do not remove this and leave it at the end of the file, where
1958 * Emacs will automagically detect them.
1959 * ---------------------------------------------------------------------
1962 * indent-tabs-mode: t
1966 * vim:noexpandtab:sw=4:ts=4: