1 /* src/vm/jit/stack.c - stack analysis
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
27 Authors: Andreas Krall
29 Changes: Edwin Steiner
33 $Id: stack.c 5216 2006-08-08 12:45:31Z twisti $
49 #include "mm/memory.h"
50 #include "native/native.h"
51 #include "toolbox/logging.h"
52 #include "vm/global.h"
53 #include "vm/builtin.h"
54 #include "vm/options.h"
55 #include "vm/resolve.h"
56 #include "vm/statistics.h"
57 #include "vm/stringlocal.h"
58 #include "vm/jit/cfg.h"
59 #include "vm/jit/codegen-common.h"
60 #include "vm/jit/abi.h"
61 #include "vm/jit/show.h"
63 #if defined(ENABLE_DISASSEMBLER)
64 # include "vm/jit/disass.h"
67 #include "vm/jit/jit.h"
68 #include "vm/jit/stack.h"
70 #if defined(ENABLE_LSRA)
71 # include "vm/jit/allocator/lsra.h"
74 /*#define STACK_VERBOSE*/
77 /* macro for saving #ifdefs ***************************************************/
79 #if defined(ENABLE_INTRP)
80 #define IF_INTRP(x) if (opt_intrp) { x }
81 #define IF_NO_INTRP(x) if (!opt_intrp) { x }
84 #define IF_NO_INTRP(x) { x }
87 #if defined(ENABLE_INTRP)
88 #if defined(ENABLE_JIT)
89 #define IF_JIT(x) if (!opt_intrp) { x }
93 #else /* !defined(ENABLE_INTRP) */
94 #define IF_JIT(x) { x }
95 #endif /* defined(ENABLE_INTRP) */
97 #if defined(ENABLE_STATISTICS)
98 #define STATISTICS_STACKDEPTH_DISTRIBUTION(distr) \
101 if (stackdepth >= 10) \
102 count_store_depth[10]++; \
104 count_store_depth[stackdepth]++; \
107 #else /* !defined(ENABLE_STATISTICS) */
108 #define STATISTICS_STACKDEPTH_DISTRIBUTION(distr)
111 /* stack_init ******************************************************************
113 Initialized the stack analysis subsystem (called by jit_init).
115 *******************************************************************************/
117 bool stack_init(void)
123 /* stack_analyse ***************************************************************
125 Analyse_stack uses the intermediate code created by parse.c to
126 build a model of the JVM operand stack for the current method.
128 The following checks are performed:
129 - check for operand stack underflow (before each instruction)
130 - check for operand stack overflow (after[1] each instruction)
131 - check for matching stack depth at merging points
132 - check for matching basic types[2] at merging points
133 - check basic types for instruction input (except for BUILTIN*
134 opcodes, INVOKE* opcodes and MULTIANEWARRAY)
136 [1]) Checking this after the instruction should be ok. parse.c
137 counts the number of required stack slots in such a way that it is
138 only vital that we don't exceed `maxstack` at basic block
141 [2]) 'basic types' means the distinction between INT, LONG, FLOAT,
142 DOUBLE and ADDRESS types. Subtypes of INT and different ADDRESS
143 types are not discerned.
145 *******************************************************************************/
147 #define BLOCK_OF(index) \
148 (jd->new_basicblocks + jd->new_basicblockindex[index])
151 (iptr->s1.var = NULL)
153 #define USE_S1_LOCAL(type1)
155 #define USE_S1(type1) \
158 CHECK_BASIC_TYPE(type1, curstack->type); \
159 iptr->s1.var = curstack; \
165 iptr->s1.var = curstack; \
168 #define USE_S1_S2(type1, type2) \
171 CHECK_BASIC_TYPE(type1, curstack->prev->type); \
172 CHECK_BASIC_TYPE(type2, curstack->type); \
173 iptr->sx.s23.s2.var = curstack; \
174 iptr->s1.var = curstack->prev; \
177 #define USE_S1_S2_ANY_ANY \
180 iptr->sx.s23.s2.var = curstack; \
181 iptr->s1.var = curstack->prev; \
184 #define USE_S1_S2_S3(type1, type2, type3) \
187 CHECK_BASIC_TYPE(type1, curstack->prev->prev->type); \
188 CHECK_BASIC_TYPE(type2, curstack->prev->type); \
189 CHECK_BASIC_TYPE(type3, curstack->type); \
190 iptr->sx.s23.s3.var = curstack; \
191 iptr->sx.s23.s2.var = curstack->prev; \
192 iptr->s1.var = curstack->prev->prev; \
195 #define POP_S1(type1) \
198 if (curstack->varkind == UNDEFVAR) \
199 curstack->varkind = TEMPVAR; \
200 curstack = curstack->prev; \
206 if (curstack->varkind == UNDEFVAR) \
207 curstack->varkind = TEMPVAR; \
208 curstack = curstack->prev; \
211 #define POP_S1_S2(type1, type2) \
213 USE_S1_S2(type1, type2); \
214 if (curstack->varkind == UNDEFVAR) \
215 curstack->varkind = TEMPVAR; \
216 if (curstack->prev->varkind == UNDEFVAR) \
217 curstack->prev->varkind = TEMPVAR; \
218 curstack = curstack->prev->prev; \
221 #define POP_S1_S2_ANY_ANY \
224 if (curstack->varkind == UNDEFVAR) \
225 curstack->varkind = TEMPVAR; \
226 if (curstack->prev->varkind == UNDEFVAR) \
227 curstack->prev->varkind = TEMPVAR; \
228 curstack = curstack->prev->prev; \
231 #define POP_S1_S2_S3(type1, type2, type3) \
233 USE_S1_S2_S3(type1, type2, type3); \
234 if (curstack->varkind == UNDEFVAR) \
235 curstack->varkind = TEMPVAR; \
236 if (curstack->prev->varkind == UNDEFVAR) \
237 curstack->prev->varkind = TEMPVAR; \
238 if (curstack->prev->prev->varkind == UNDEFVAR) \
239 curstack->prev->prev->varkind = TEMPVAR; \
240 curstack = curstack->prev->prev->prev; \
247 (iptr->dst.var = NULL)
249 #define NEW_DST(typed, depth) \
251 NEWSTACKn(typed, (depth)); \
252 iptr->dst.var = curstack; \
255 #define NEW_DST_LOCALVAR(typed, index) \
257 NEWSTACK(typed, LOCALVAR, (index)); \
258 iptr->dst.var = curstack; \
267 #define NEW_OP0_BRANCH \
272 #define NEW_OP0_1(typed) \
275 NEW_DST(typed, stackdepth); \
279 #define NEW_OP1_0(type1) \
286 #define NEW_OP1_0_ANY \
293 #define NEW_OP1_BRANCH(type1) \
299 #define NEW_OP1_1(type1, typed) \
302 NEW_DST(typed, stackdepth - 1); \
305 #define NEW_OP2_0(type1, type2) \
307 POP_S1_S2(type1, type2); \
312 #define NEW_OP2_BRANCH(type1, type2) \
314 POP_S1_S2(type1, type2); \
318 #define NEW_OP2_0_ANY_ANY \
325 #define NEW_OP2_1(type1, type2, typed) \
327 POP_S1_S2(type1, type2); \
328 NEW_DST(typed, stackdepth - 2); \
332 #define NEW_OP3_0(type1, type2, type3) \
334 POP_S1_S2_S3(type1, type2, type3); \
339 #define NEW_LOAD(type1, index) \
341 NEW_DST_LOCALVAR(type1, index); \
345 #define NEW_STORE(type1, index) \
351 #define BRANCH_TARGET(bt, tempbptr, tempsp) \
353 (bt).block = tempbptr = BLOCK_OF((bt).insindex); \
354 MARKREACHED(tempbptr, tempsp); \
357 #define BRANCH(tempbptr, tempsp) \
359 iptr->dst.block = tempbptr = BLOCK_OF(iptr->dst.insindex); \
360 MARKREACHED(tempbptr, tempsp); \
363 #define DUP_SLOT(sp) \
365 if ((sp)->varkind != TEMPVAR) \
366 NEWSTACK((sp)->type, TEMPVAR, stackdepth); \
368 NEWSTACK((sp)->type, (sp)->varkind, (sp)->varnum); \
371 bool new_stack_analyse(jitdata *jd)
373 methodinfo *m; /* method being analyzed */
377 int b_count; /* basic block counter */
378 int b_index; /* basic block index */
380 stackptr curstack; /* current stack top */
383 int opcode; /* opcode of current instruction */
385 int len; /* # of instructions after the current one */
386 bool superblockend; /* if true, no fallthrough to next block */
387 bool repeat; /* if true, outermost loop must run again */
388 bool deadcode; /* true if no live code has been reached */
389 new_instruction *iptr; /* the current instruction */
390 basicblock *bptr; /* the current basic block */
392 s4 *last_store; /* instruction index of last XSTORE */
393 /* [ local_index * 5 + type ] */
394 s4 last_pei; /* ins. index of last possible exception */
395 /* used for conflict resolution for copy */
396 /* elimination (XLOAD, IINC, XSTORE) */
398 branch_target_t *table;
399 lookup_target_t *lookup;
400 #if defined(ENABLE_VERIFIER)
401 int expectedtype; /* used by CHECK_BASIC_TYPE */
403 builtintable_entry *bte;
405 constant_FMIref *fmiref;
406 #if defined(ENABLE_STATISTICS)
407 int iteration_count; /* number of iterations of analysis */
410 #if defined(STACK_VERBOSE)
411 new_show_method(jd, SHOW_PARSE);
414 /* get required compiler data - initialization */
421 #if defined(ENABLE_LSRA)
425 #if defined(ENABLE_STATISTICS)
429 last_store = DMNEW(s4 , cd->maxlocals * 5);
431 /* initialize in-stack of first block */
434 jd->new_basicblocks[0].flags = BBREACHED;
435 jd->new_basicblocks[0].instack = 0;
436 jd->new_basicblocks[0].indepth = 0;
438 /* initialize in-stack of exception handlers */
440 for (i = 0; i < cd->exceptiontablelength; i++) {
441 bptr = BLOCK_OF(cd->exceptiontable[i].handlerpc);
442 bptr->flags = BBREACHED;
443 bptr->type = BBTYPE_EXH;
446 bptr->predecessorcount = CFG_UNKNOWN_PREDECESSORS;
451 /* count predecessors of each block ***************************************/
453 #if CONDITIONAL_LOADCONST
454 /* XXX move this to a separate function */
456 b_count = jd->new_basicblockcount;
457 bptr = jd->new_basicblocks;
458 for (; --b_count >= 0; bptr++) {
459 if (bptr->icount == 0)
462 /* get the last instruction of the block */
464 iptr = /* XXX */ (new_instruction *) bptr->iinstr + (bptr->icount - 1);
467 /* instruction stopping control flow */
478 /* conditional branches */
495 /* XXX add missing conditional branches */
496 bptr[1].predecessorcount++;
499 /* unconditional branch */
501 BLOCK_OF(iptr->dst.insindex)->predecessorcount++;
505 case ICMD_TABLESWITCH:
506 table = iptr->dst.table;
507 BLOCK_OF((table++)->insindex)->predecessorcount++;
508 i = iptr->sx.s23.s3.tablehigh
509 - iptr->sx.s23.s2.tablelow + 1;
511 BLOCK_OF((table++)->insindex)->predecessorcount++;
515 case ICMD_LOOKUPSWITCH:
516 lookup = iptr->dst.lookup;
517 BLOCK_OF(iptr->sx.s23.s3.lookupdefault.insindex)->predecessorcount++;
518 i = iptr->sx.s23.s2.lookupcount;
520 BLOCK_OF((lookup++)->target.insindex)->predecessorcount++;
524 /* default - fall into next block */
526 bptr[1].predecessorcount++;
529 } /* end basic block loop */
531 #endif /* CONDITIONAL_LOADCONST */
533 /* stack analysis loop (until fixpoint reached) **************************/
536 #if defined(ENABLE_STATISTICS)
540 /* initialize loop over basic blocks */
542 b_count = jd->new_basicblockcount;
543 bptr = jd->new_basicblocks;
544 superblockend = true;
549 /* iterate over basic blocks *****************************************/
551 while (--b_count >= 0) {
552 #if defined(STACK_VERBOSE)
553 printf("ANALYZING BLOCK L%03d\n", bptr->debug_nr);
556 if (bptr->flags == BBDELETED) {
557 /* This block has been deleted - do nothing. */
559 else if (superblockend && (bptr->flags < BBREACHED)) {
560 /* This block has not been reached so far, and we */
561 /* don't fall into it, so we'll have to iterate again. */
564 else if (bptr->flags <= BBREACHED) {
566 /* We know that bptr->flags == BBREACHED. */
567 /* This block has been reached before. */
568 stackdepth = bptr->indepth;
570 else if (bptr->flags < BBREACHED) {
571 /* This block is reached for the first time now */
572 /* by falling through from the previous block. */
574 bptr->instack = copy;
575 bptr->indepth = stackdepth;
578 /* This block has been reached before. now we are */
579 /* falling into it from the previous block. */
580 /* Check that stack depth is well-defined. */
581 CHECK_STACK_DEPTH(bptr->indepth, stackdepth);
584 /* set up local variables for analyzing this block */
586 curstack = bptr->instack;
588 superblockend = false;
589 bptr->flags = BBFINISHED;
591 iptr = /* XXX */ (new_instruction *) bptr->iinstr;
592 b_index = bptr - jd->new_basicblocks;
594 /* reset variables for dependency checking */
598 for( i = 0; i < cd->maxlocals; i++)
599 for( j = 0; j < 5; j++)
600 last_store[5 * i + j] = -1;
602 /* XXX store the start of the block's stack representation */
606 /* iterate over ICMDs ****************************************/
609 #if defined(STACK_VERBOSE)
610 new_show_icmd(jd, iptr, false, SHOW_PARSE); printf("\n");
611 for( copy = curstack; copy; copy = copy->prev ) {
612 printf("%d ", copy->type);
617 /* fetch the current opcode */
621 /* automatically replace some ICMDs with builtins */
623 #if defined(USEBUILTINTABLE)
625 bte = builtintable_get_automatic(opcode);
627 if (bte && bte->opcode == opcode) {
628 iptr->opc = ICMD_BUILTIN;
629 iptr->flags.bits = INS_FLAG_NOCHECK;
630 iptr->sx.s23.s3.bte = bte;
631 /* iptr->line is already set */
632 jd->isleafmethod = false;
636 #endif /* defined(USEBUILTINTABLE) */
638 /* main opcode switch *************************************/
651 COUNT(count_check_null);
654 CLR_DST; /* XXX live through? */
658 USE_S1_LOCAL(TYPE_ADR);
661 IF_NO_INTRP( rd->locals[iptr->s1.localindex][TYPE_ADR].type = TYPE_ADR; );
662 superblockend = true;
666 COUNT(count_pcmd_return);
669 superblockend = true;
673 /* pop 0 push 1 const */
675 /************************** ICONST OPTIMIZATIONS **************************/
678 COUNT(count_pcmd_load);
682 switch (iptr[1].opc) {
684 iptr->opc = ICMD_IADDCONST;
688 iptr[1].opc = ICMD_NOP;
689 NEW_OP1_1(TYPE_INT, TYPE_INT);
690 COUNT(count_pcmd_op);
694 iptr->opc = ICMD_ISUBCONST;
695 goto icmd_iconst_tail;
696 #if SUPPORT_CONST_MUL
698 iptr->opc = ICMD_IMULCONST;
699 goto icmd_iconst_tail;
700 #else /* SUPPORT_CONST_MUL */
702 if (iptr->sx.val.i == 0x00000002)
704 else if (iptr->sx.val.i == 0x00000004)
706 else if (iptr->sx.val.i == 0x00000008)
708 else if (iptr->sx.val.i == 0x00000010)
710 else if (iptr->sx.val.i == 0x00000020)
712 else if (iptr->sx.val.i == 0x00000040)
714 else if (iptr->sx.val.i == 0x00000080)
716 else if (iptr->sx.val.i == 0x00000100)
718 else if (iptr->sx.val.i == 0x00000200)
720 else if (iptr->sx.val.i == 0x00000400)
722 else if (iptr->sx.val.i == 0x00000800)
724 else if (iptr->sx.val.i == 0x00001000)
726 else if (iptr->sx.val.i == 0x00002000)
728 else if (iptr->sx.val.i == 0x00004000)
730 else if (iptr->sx.val.i == 0x00008000)
732 else if (iptr->sx.val.i == 0x00010000)
734 else if (iptr->sx.val.i == 0x00020000)
736 else if (iptr->sx.val.i == 0x00040000)
738 else if (iptr->sx.val.i == 0x00080000)
740 else if (iptr->sx.val.i == 0x00100000)
742 else if (iptr->sx.val.i == 0x00200000)
744 else if (iptr->sx.val.i == 0x00400000)
746 else if (iptr->sx.val.i == 0x00800000)
748 else if (iptr->sx.val.i == 0x01000000)
750 else if (iptr->sx.val.i == 0x02000000)
752 else if (iptr->sx.val.i == 0x04000000)
754 else if (iptr->sx.val.i == 0x08000000)
756 else if (iptr->sx.val.i == 0x10000000)
758 else if (iptr->sx.val.i == 0x20000000)
760 else if (iptr->sx.val.i == 0x40000000)
762 else if (iptr->sx.val.i == 0x80000000)
767 iptr->opc = ICMD_IMULPOW2;
768 goto icmd_iconst_tail;
769 #endif /* SUPPORT_CONST_MUL */
771 if (iptr->sx.val.i == 0x00000002)
773 else if (iptr->sx.val.i == 0x00000004)
775 else if (iptr->sx.val.i == 0x00000008)
777 else if (iptr->sx.val.i == 0x00000010)
779 else if (iptr->sx.val.i == 0x00000020)
781 else if (iptr->sx.val.i == 0x00000040)
783 else if (iptr->sx.val.i == 0x00000080)
785 else if (iptr->sx.val.i == 0x00000100)
787 else if (iptr->sx.val.i == 0x00000200)
789 else if (iptr->sx.val.i == 0x00000400)
791 else if (iptr->sx.val.i == 0x00000800)
793 else if (iptr->sx.val.i == 0x00001000)
795 else if (iptr->sx.val.i == 0x00002000)
797 else if (iptr->sx.val.i == 0x00004000)
799 else if (iptr->sx.val.i == 0x00008000)
801 else if (iptr->sx.val.i == 0x00010000)
803 else if (iptr->sx.val.i == 0x00020000)
805 else if (iptr->sx.val.i == 0x00040000)
807 else if (iptr->sx.val.i == 0x00080000)
809 else if (iptr->sx.val.i == 0x00100000)
811 else if (iptr->sx.val.i == 0x00200000)
813 else if (iptr->sx.val.i == 0x00400000)
815 else if (iptr->sx.val.i == 0x00800000)
817 else if (iptr->sx.val.i == 0x01000000)
819 else if (iptr->sx.val.i == 0x02000000)
821 else if (iptr->sx.val.i == 0x04000000)
823 else if (iptr->sx.val.i == 0x08000000)
825 else if (iptr->sx.val.i == 0x10000000)
827 else if (iptr->sx.val.i == 0x20000000)
829 else if (iptr->sx.val.i == 0x40000000)
831 else if (iptr->sx.val.i == 0x80000000)
836 iptr->opc = ICMD_IDIVPOW2;
837 goto icmd_iconst_tail;
840 /*log_text("stack.c: ICMD_ICONST/ICMD_IREM");*/
841 if ((iptr->sx.val.i == 0x00000002) ||
842 (iptr->sx.val.i == 0x00000004) ||
843 (iptr->sx.val.i == 0x00000008) ||
844 (iptr->sx.val.i == 0x00000010) ||
845 (iptr->sx.val.i == 0x00000020) ||
846 (iptr->sx.val.i == 0x00000040) ||
847 (iptr->sx.val.i == 0x00000080) ||
848 (iptr->sx.val.i == 0x00000100) ||
849 (iptr->sx.val.i == 0x00000200) ||
850 (iptr->sx.val.i == 0x00000400) ||
851 (iptr->sx.val.i == 0x00000800) ||
852 (iptr->sx.val.i == 0x00001000) ||
853 (iptr->sx.val.i == 0x00002000) ||
854 (iptr->sx.val.i == 0x00004000) ||
855 (iptr->sx.val.i == 0x00008000) ||
856 (iptr->sx.val.i == 0x00010000) ||
857 (iptr->sx.val.i == 0x00020000) ||
858 (iptr->sx.val.i == 0x00040000) ||
859 (iptr->sx.val.i == 0x00080000) ||
860 (iptr->sx.val.i == 0x00100000) ||
861 (iptr->sx.val.i == 0x00200000) ||
862 (iptr->sx.val.i == 0x00400000) ||
863 (iptr->sx.val.i == 0x00800000) ||
864 (iptr->sx.val.i == 0x01000000) ||
865 (iptr->sx.val.i == 0x02000000) ||
866 (iptr->sx.val.i == 0x04000000) ||
867 (iptr->sx.val.i == 0x08000000) ||
868 (iptr->sx.val.i == 0x10000000) ||
869 (iptr->sx.val.i == 0x20000000) ||
870 (iptr->sx.val.i == 0x40000000) ||
871 (iptr->sx.val.i == 0x80000000))
873 iptr->opc = ICMD_IREMPOW2;
875 goto icmd_iconst_tail;
878 #if SUPPORT_CONST_LOGICAL
880 iptr->opc = ICMD_IANDCONST;
881 goto icmd_iconst_tail;
884 iptr->opc = ICMD_IORCONST;
885 goto icmd_iconst_tail;
888 iptr->opc = ICMD_IXORCONST;
889 goto icmd_iconst_tail;
891 #endif /* SUPPORT_CONST_LOGICAL */
893 iptr->opc = ICMD_ISHLCONST;
894 goto icmd_iconst_tail;
897 iptr->opc = ICMD_ISHRCONST;
898 goto icmd_iconst_tail;
901 iptr->opc = ICMD_IUSHRCONST;
902 goto icmd_iconst_tail;
903 #if SUPPORT_LONG_SHIFT
905 iptr->opc = ICMD_LSHLCONST;
906 goto icmd_lconst_tail;
909 iptr->opc = ICMD_LSHRCONST;
910 goto icmd_lconst_tail;
913 iptr->opc = ICMD_LUSHRCONST;
914 goto icmd_lconst_tail;
915 #endif /* SUPPORT_LONG_SHIFT */
917 iptr[1].opc = ICMD_IFEQ;
921 /* set the constant for the following icmd */
922 iptr[1].sx.val.i = iptr->sx.val.i;
924 /* this instruction becomes a nop */
925 iptr->opc = ICMD_NOP;
929 iptr[1].opc = ICMD_IFLT;
930 goto icmd_if_icmp_tail;
933 iptr[1].opc = ICMD_IFLE;
934 goto icmd_if_icmp_tail;
937 iptr[1].opc = ICMD_IFNE;
938 goto icmd_if_icmp_tail;
941 iptr[1].opc = ICMD_IFGT;
942 goto icmd_if_icmp_tail;
945 iptr[1].opc = ICMD_IFGE;
946 goto icmd_if_icmp_tail;
948 #if SUPPORT_CONST_STORE
953 IF_INTRP( goto normal_ICONST; )
954 # if SUPPORT_CONST_STORE_ZERO_ONLY
955 if (iptr->sx.val.i != 0)
958 switch (iptr[1].opc) {
960 iptr->opc = ICMD_IASTORECONST;
963 iptr->opc = ICMD_BASTORECONST;
966 iptr->opc = ICMD_CASTORECONST;
969 iptr->opc = ICMD_SASTORECONST;
973 iptr[1].opc = ICMD_NOP;
975 /* copy the constant to s3 */
976 /* XXX constval -> astoreconstval? */
977 iptr->sx.s23.s3.constval = iptr->sx.val.i;
978 NEW_OP2_0(TYPE_ADR, TYPE_INT);
979 COUNT(count_pcmd_op);
984 IF_INTRP( goto normal_ICONST; )
985 # if SUPPORT_CONST_STORE_ZERO_ONLY
986 if (iptr->sx.val.i != 0)
989 /* XXX check field type? */
991 /* copy the constant to s2 */
992 /* XXX constval -> fieldconstval? */
993 iptr->sx.s23.s2.constval = iptr->sx.val.i;
996 /* set the field reference (s3) */
997 if (iptr[1].flags.bits & INS_FLAG_UNRESOLVED) {
998 iptr->sx.s23.s3.uf = iptr[1].sx.s23.s3.uf;
999 iptr->flags.bits |= INS_FLAG_UNRESOLVED;
1002 iptr->sx.s23.s3.fmiref = iptr[1].sx.s23.s3.fmiref;
1005 switch (iptr[1].opc) {
1006 case ICMD_PUTSTATIC:
1007 iptr->opc = ICMD_PUTSTATICCONST;
1011 iptr->opc = ICMD_PUTFIELDCONST;
1012 NEW_OP1_0(TYPE_ADR);
1016 iptr[1].opc = ICMD_NOP;
1017 COUNT(count_pcmd_op);
1019 #endif /* SUPPORT_CONST_STORE */
1025 /* if we get here, the ICONST has been optimized */
1029 /* normal case of an unoptimized ICONST */
1030 NEW_OP0_1(TYPE_INT);
1033 /************************** LCONST OPTIMIZATIONS **************************/
1036 COUNT(count_pcmd_load);
1040 /* switch depending on the following instruction */
1042 switch (iptr[1].opc) {
1043 #if SUPPORT_LONG_ADD
1045 iptr->opc = ICMD_LADDCONST;
1049 /* instruction of type LONG -> LONG */
1050 iptr[1].opc = ICMD_NOP;
1051 NEW_OP1_1(TYPE_LNG, TYPE_LNG);
1052 COUNT(count_pcmd_op);
1056 iptr->opc = ICMD_LSUBCONST;
1057 goto icmd_lconst_tail;
1059 #endif /* SUPPORT_LONG_ADD */
1060 #if SUPPORT_LONG_MUL && SUPPORT_CONST_MUL
1062 iptr->opc = ICMD_LMULCONST;
1063 goto icmd_lconst_tail;
1064 #else /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
1065 # if SUPPORT_LONG_SHIFT
1067 if (iptr->sx.val.l == 0x00000002)
1069 else if (iptr->sx.val.l == 0x00000004)
1071 else if (iptr->sx.val.l == 0x00000008)
1073 else if (iptr->sx.val.l == 0x00000010)
1075 else if (iptr->sx.val.l == 0x00000020)
1077 else if (iptr->sx.val.l == 0x00000040)
1079 else if (iptr->sx.val.l == 0x00000080)
1081 else if (iptr->sx.val.l == 0x00000100)
1083 else if (iptr->sx.val.l == 0x00000200)
1085 else if (iptr->sx.val.l == 0x00000400)
1086 iptr->sx.val.i = 10;
1087 else if (iptr->sx.val.l == 0x00000800)
1088 iptr->sx.val.i = 11;
1089 else if (iptr->sx.val.l == 0x00001000)
1090 iptr->sx.val.i = 12;
1091 else if (iptr->sx.val.l == 0x00002000)
1092 iptr->sx.val.i = 13;
1093 else if (iptr->sx.val.l == 0x00004000)
1094 iptr->sx.val.i = 14;
1095 else if (iptr->sx.val.l == 0x00008000)
1096 iptr->sx.val.i = 15;
1097 else if (iptr->sx.val.l == 0x00010000)
1098 iptr->sx.val.i = 16;
1099 else if (iptr->sx.val.l == 0x00020000)
1100 iptr->sx.val.i = 17;
1101 else if (iptr->sx.val.l == 0x00040000)
1102 iptr->sx.val.i = 18;
1103 else if (iptr->sx.val.l == 0x00080000)
1104 iptr->sx.val.i = 19;
1105 else if (iptr->sx.val.l == 0x00100000)
1106 iptr->sx.val.i = 20;
1107 else if (iptr->sx.val.l == 0x00200000)
1108 iptr->sx.val.i = 21;
1109 else if (iptr->sx.val.l == 0x00400000)
1110 iptr->sx.val.i = 22;
1111 else if (iptr->sx.val.l == 0x00800000)
1112 iptr->sx.val.i = 23;
1113 else if (iptr->sx.val.l == 0x01000000)
1114 iptr->sx.val.i = 24;
1115 else if (iptr->sx.val.l == 0x02000000)
1116 iptr->sx.val.i = 25;
1117 else if (iptr->sx.val.l == 0x04000000)
1118 iptr->sx.val.i = 26;
1119 else if (iptr->sx.val.l == 0x08000000)
1120 iptr->sx.val.i = 27;
1121 else if (iptr->sx.val.l == 0x10000000)
1122 iptr->sx.val.i = 28;
1123 else if (iptr->sx.val.l == 0x20000000)
1124 iptr->sx.val.i = 29;
1125 else if (iptr->sx.val.l == 0x40000000)
1126 iptr->sx.val.i = 30;
1127 else if (iptr->sx.val.l == 0x80000000)
1128 iptr->sx.val.i = 31;
1132 iptr->opc = ICMD_LMULPOW2;
1133 goto icmd_lconst_tail;
1134 # endif /* SUPPORT_LONG_SHIFT */
1135 #endif /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
1136 #if SUPPORT_LONG_DIV_POW2
1138 if (iptr->sx.val.l == 0x00000002)
1140 else if (iptr->sx.val.l == 0x00000004)
1142 else if (iptr->sx.val.l == 0x00000008)
1144 else if (iptr->sx.val.l == 0x00000010)
1146 else if (iptr->sx.val.l == 0x00000020)
1148 else if (iptr->sx.val.l == 0x00000040)
1150 else if (iptr->sx.val.l == 0x00000080)
1152 else if (iptr->sx.val.l == 0x00000100)
1154 else if (iptr->sx.val.l == 0x00000200)
1156 else if (iptr->sx.val.l == 0x00000400)
1157 iptr->sx.val.i = 10;
1158 else if (iptr->sx.val.l == 0x00000800)
1159 iptr->sx.val.i = 11;
1160 else if (iptr->sx.val.l == 0x00001000)
1161 iptr->sx.val.i = 12;
1162 else if (iptr->sx.val.l == 0x00002000)
1163 iptr->sx.val.i = 13;
1164 else if (iptr->sx.val.l == 0x00004000)
1165 iptr->sx.val.i = 14;
1166 else if (iptr->sx.val.l == 0x00008000)
1167 iptr->sx.val.i = 15;
1168 else if (iptr->sx.val.l == 0x00010000)
1169 iptr->sx.val.i = 16;
1170 else if (iptr->sx.val.l == 0x00020000)
1171 iptr->sx.val.i = 17;
1172 else if (iptr->sx.val.l == 0x00040000)
1173 iptr->sx.val.i = 18;
1174 else if (iptr->sx.val.l == 0x00080000)
1175 iptr->sx.val.i = 19;
1176 else if (iptr->sx.val.l == 0x00100000)
1177 iptr->sx.val.i = 20;
1178 else if (iptr->sx.val.l == 0x00200000)
1179 iptr->sx.val.i = 21;
1180 else if (iptr->sx.val.l == 0x00400000)
1181 iptr->sx.val.i = 22;
1182 else if (iptr->sx.val.l == 0x00800000)
1183 iptr->sx.val.i = 23;
1184 else if (iptr->sx.val.l == 0x01000000)
1185 iptr->sx.val.i = 24;
1186 else if (iptr->sx.val.l == 0x02000000)
1187 iptr->sx.val.i = 25;
1188 else if (iptr->sx.val.l == 0x04000000)
1189 iptr->sx.val.i = 26;
1190 else if (iptr->sx.val.l == 0x08000000)
1191 iptr->sx.val.i = 27;
1192 else if (iptr->sx.val.l == 0x10000000)
1193 iptr->sx.val.i = 28;
1194 else if (iptr->sx.val.l == 0x20000000)
1195 iptr->sx.val.i = 29;
1196 else if (iptr->sx.val.l == 0x40000000)
1197 iptr->sx.val.i = 30;
1198 else if (iptr->sx.val.l == 0x80000000)
1199 iptr->sx.val.i = 31;
1203 iptr->opc = ICMD_LDIVPOW2;
1204 goto icmd_lconst_tail;
1205 #endif /* SUPPORT_LONG_DIV_POW2 */
1207 #if SUPPORT_LONG_REM_POW2
1209 if ((iptr->sx.val.l == 0x00000002) ||
1210 (iptr->sx.val.l == 0x00000004) ||
1211 (iptr->sx.val.l == 0x00000008) ||
1212 (iptr->sx.val.l == 0x00000010) ||
1213 (iptr->sx.val.l == 0x00000020) ||
1214 (iptr->sx.val.l == 0x00000040) ||
1215 (iptr->sx.val.l == 0x00000080) ||
1216 (iptr->sx.val.l == 0x00000100) ||
1217 (iptr->sx.val.l == 0x00000200) ||
1218 (iptr->sx.val.l == 0x00000400) ||
1219 (iptr->sx.val.l == 0x00000800) ||
1220 (iptr->sx.val.l == 0x00001000) ||
1221 (iptr->sx.val.l == 0x00002000) ||
1222 (iptr->sx.val.l == 0x00004000) ||
1223 (iptr->sx.val.l == 0x00008000) ||
1224 (iptr->sx.val.l == 0x00010000) ||
1225 (iptr->sx.val.l == 0x00020000) ||
1226 (iptr->sx.val.l == 0x00040000) ||
1227 (iptr->sx.val.l == 0x00080000) ||
1228 (iptr->sx.val.l == 0x00100000) ||
1229 (iptr->sx.val.l == 0x00200000) ||
1230 (iptr->sx.val.l == 0x00400000) ||
1231 (iptr->sx.val.l == 0x00800000) ||
1232 (iptr->sx.val.l == 0x01000000) ||
1233 (iptr->sx.val.l == 0x02000000) ||
1234 (iptr->sx.val.l == 0x04000000) ||
1235 (iptr->sx.val.l == 0x08000000) ||
1236 (iptr->sx.val.l == 0x10000000) ||
1237 (iptr->sx.val.l == 0x20000000) ||
1238 (iptr->sx.val.l == 0x40000000) ||
1239 (iptr->sx.val.l == 0x80000000))
1241 iptr->opc = ICMD_LREMPOW2;
1242 iptr->sx.val.l -= 1;
1243 goto icmd_lconst_tail;
1246 #endif /* SUPPORT_LONG_REM_POW2 */
1248 #if SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL
1251 iptr->opc = ICMD_LANDCONST;
1252 goto icmd_lconst_tail;
1255 iptr->opc = ICMD_LORCONST;
1256 goto icmd_lconst_tail;
1259 iptr->opc = ICMD_LXORCONST;
1260 goto icmd_lconst_tail;
1261 #endif /* SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL */
1263 #if SUPPORT_LONG_CMP_CONST
1265 if ((len <= 1) || (iptr[2].sx.val.i != 0))
1268 /* switch on the instruction after LCONST - LCMP */
1270 switch (iptr[2].opc) {
1272 iptr->opc = ICMD_IF_LEQ;
1275 icmd_lconst_lcmp_tail:
1276 /* convert LCONST, LCMP, IFXX to IF_LXX */
1277 iptr->dst.insindex = iptr[2].dst.insindex;
1278 iptr[1].opc = ICMD_NOP;
1279 iptr[2].opc = ICMD_NOP;
1281 NEW_OP1_BRANCH(TYPE_LNG);
1282 BRANCH(tbptr, copy);
1283 COUNT(count_pcmd_bra);
1284 COUNT(count_pcmd_op);
1288 iptr->opc = ICMD_IF_LNE;
1289 goto icmd_lconst_lcmp_tail;
1292 iptr->opc = ICMD_IF_LLT;
1293 goto icmd_lconst_lcmp_tail;
1296 iptr->opc = ICMD_IF_LGT;
1297 goto icmd_lconst_lcmp_tail;
1300 iptr->opc = ICMD_IF_LLE;
1301 goto icmd_lconst_lcmp_tail;
1304 iptr->opc = ICMD_IF_LGE;
1305 goto icmd_lconst_lcmp_tail;
1309 } /* end switch on opcode after LCONST - LCMP */
1311 #endif /* SUPPORT_LONG_CMP_CONST */
1313 #if SUPPORT_CONST_STORE
1315 IF_INTRP( goto normal_LCONST; )
1316 # if SUPPORT_CONST_STORE_ZERO_ONLY
1317 if (iptr->sx.val.l != 0)
1320 #if SIZEOF_VOID_P == 4
1321 /* the constant must fit into a ptrint */
1322 if (iptr->sx.val.l < -0x80000000L || iptr->sx.val.l >= 0x80000000L)
1325 /* move the constant to s3 */
1326 iptr->sx.s23.s3.constval = iptr->sx.val.l;
1328 iptr->opc = ICMD_LASTORECONST;
1329 NEW_OP2_0(TYPE_ADR, TYPE_INT);
1331 iptr[1].opc = ICMD_NOP;
1332 COUNT(count_pcmd_op);
1335 case ICMD_PUTSTATIC:
1337 IF_INTRP( goto normal_LCONST; )
1338 # if SUPPORT_CONST_STORE_ZERO_ONLY
1339 if (iptr->sx.val.l != 0)
1342 #if SIZEOF_VOID_P == 4
1343 /* the constant must fit into a ptrint */
1344 if (iptr->sx.val.l < -0x80000000L || iptr->sx.val.l >= 0x80000000L)
1347 /* XXX check field type? */
1349 /* copy the constant to s2 */
1350 /* XXX constval -> fieldconstval? */
1351 iptr->sx.s23.s2.constval = iptr->sx.val.l;
1355 #endif /* SUPPORT_CONST_STORE */
1359 } /* end switch opcode after LCONST */
1361 /* if we get here, the LCONST has been optimized */
1365 /* the normal case of an unoptimized LCONST */
1366 NEW_OP0_1(TYPE_LNG);
1369 /************************ END OF LCONST OPTIMIZATIONS *********************/
1372 COUNT(count_pcmd_load);
1373 NEW_OP0_1(TYPE_FLT);
1377 COUNT(count_pcmd_load);
1378 NEW_OP0_1(TYPE_DBL);
1381 /************************** ACONST OPTIMIZATIONS **************************/
1384 COUNT(count_pcmd_load);
1385 #if SUPPORT_CONST_STORE
1386 IF_INTRP( goto normal_ACONST; )
1388 /* We can only optimize if the ACONST is resolved
1389 * and there is an instruction after it. */
1391 if ((len == 0) || (iptr->flags.bits & INS_FLAG_UNRESOLVED))
1394 switch (iptr[1].opc) {
1396 /* We can only optimize for NULL values
1397 * here because otherwise a checkcast is
1399 if (iptr->sx.val.anyptr != NULL)
1402 /* copy the constant (NULL) to s3 */
1403 iptr->sx.s23.s3.constval = 0;
1404 iptr->opc = ICMD_AASTORECONST;
1405 NEW_OP2_0(TYPE_ADR, TYPE_INT);
1407 iptr[1].opc = ICMD_NOP;
1408 COUNT(count_pcmd_op);
1411 case ICMD_PUTSTATIC:
1413 # if SUPPORT_CONST_STORE_ZERO_ONLY
1414 if (iptr->sx.val.anyptr != NULL)
1417 /* XXX check field type? */
1418 /* copy the constant to s2 */
1419 /* XXX constval -> fieldconstval? */
1420 iptr->sx.s23.s2.constval = (ptrint) iptr->sx.val.anyptr;
1428 /* if we get here the ACONST has been optimized */
1432 #endif /* SUPPORT_CONST_STORE */
1433 NEW_OP0_1(TYPE_ADR);
1437 /* pop 0 push 1 load */
1444 COUNT(count_load_instruction);
1445 i = opcode - ICMD_ILOAD;
1446 IF_NO_INTRP( rd->locals[iptr->s1.localindex][i].type = i; )
1447 NEW_LOAD(i, iptr->s1.localindex);
1456 COUNT(count_check_null);
1457 COUNT(count_check_bound);
1458 COUNT(count_pcmd_mem);
1459 NEW_OP2_1(TYPE_ADR, TYPE_INT, opcode - ICMD_IALOAD);
1466 COUNT(count_check_null);
1467 COUNT(count_check_bound);
1468 COUNT(count_pcmd_mem);
1469 NEW_OP2_1(TYPE_ADR, TYPE_INT, TYPE_INT);
1472 /* pop 0 push 0 iinc */
1475 STATISTICS_STACKDEPTH_DISTRIBUTION(count_store_depth);
1477 last_store[5 * iptr->s1.localindex + TYPE_INT] = bptr->icount - len - 1;
1482 if ((copy->varkind == LOCALVAR) &&
1483 (copy->varnum == iptr->s1.localindex))
1485 copy->varkind = TEMPVAR;
1492 iptr->dst.localindex = iptr->s1.localindex;
1495 /* pop 1 push 0 store */
1504 i = opcode - ICMD_ISTORE; /* type */
1505 IF_NO_INTRP( rd->locals[iptr->dst.localindex][i].type = i; )
1507 #if defined(ENABLE_STATISTICS)
1512 count_store_length[20]++;
1514 count_store_length[i]++;
1517 count_store_depth[10]++;
1519 count_store_depth[i]++;
1522 /* check for conflicts as described in Figure 5.2 */
1523 copy = curstack->prev;
1526 if ((copy->varkind == LOCALVAR) &&
1527 (copy->varnum == iptr->dst.localindex))
1529 copy->varkind = TEMPVAR;
1536 if ((curstack->varkind == LOCALVAR)
1537 && (curstack->varnum == iptr->dst.localindex))
1539 curstack->varkind = TEMPVAR;
1540 curstack->varnum = stackdepth-1;
1543 last_store[5 * iptr->dst.localindex + (opcode - ICMD_ISTORE)] = bptr->icount - len - 1;
1545 NEW_STORE(opcode - ICMD_ISTORE, iptr->dst.localindex);
1551 COUNT(count_check_null);
1552 COUNT(count_check_bound);
1553 COUNT(count_pcmd_mem);
1555 bte = builtintable_get_internal(BUILTIN_canstore);
1558 if (md->memuse > rd->memuse)
1559 rd->memuse = md->memuse;
1560 if (md->argintreguse > rd->argintreguse)
1561 rd->argintreguse = md->argintreguse;
1562 /* XXX non-leaf method? */
1564 /* make all stack variables saved */
1568 copy->flags |= SAVEDVAR;
1572 NEW_OP3_0(TYPE_ADR, TYPE_INT, TYPE_ADR);
1579 COUNT(count_check_null);
1580 COUNT(count_check_bound);
1581 COUNT(count_pcmd_mem);
1582 NEW_OP3_0(TYPE_ADR, TYPE_INT, opcode - ICMD_IASTORE);
1589 COUNT(count_check_null);
1590 COUNT(count_check_bound);
1591 COUNT(count_pcmd_mem);
1592 NEW_OP3_0(TYPE_ADR, TYPE_INT, TYPE_INT);
1598 #ifdef ENABLE_VERIFIER
1601 if (IS_2_WORD_TYPE(curstack->type))
1602 goto throw_stack_category_error;
1613 IF_JIT( md_return_alloc(jd, curstack); )
1614 COUNT(count_pcmd_return);
1615 NEW_OP1_0(opcode - ICMD_IRETURN);
1616 superblockend = true;
1620 COUNT(count_check_null);
1621 NEW_OP1_0(TYPE_ADR);
1623 superblockend = true;
1626 case ICMD_PUTSTATIC:
1627 COUNT(count_pcmd_mem);
1628 NEW_INSTRUCTION_GET_FIELDREF(iptr, fmiref);
1629 NEW_OP1_0(fmiref->parseddesc.fd->type);
1632 /* pop 1 push 0 branch */
1635 case ICMD_IFNONNULL:
1636 COUNT(count_pcmd_bra);
1637 NEW_OP1_BRANCH(TYPE_ADR);
1638 BRANCH(tbptr, copy);
1647 COUNT(count_pcmd_bra);
1648 /* iptr->sx.val.i is set implicitly in parse by
1649 clearing the memory or from IF_ICMPxx
1652 NEW_OP1_BRANCH(TYPE_INT);
1653 /* iptr->sx.val.i = 0; */
1654 BRANCH(tbptr, copy);
1657 /* pop 0 push 0 branch */
1660 COUNT(count_pcmd_bra);
1662 BRANCH(tbptr, copy);
1663 superblockend = true;
1666 /* pop 1 push 0 table branch */
1668 case ICMD_TABLESWITCH:
1669 COUNT(count_pcmd_table);
1670 NEW_OP1_BRANCH(TYPE_INT);
1672 table = iptr->dst.table;
1673 BRANCH_TARGET(*table, tbptr, copy);
1676 i = iptr->sx.s23.s3.tablehigh
1677 - iptr->sx.s23.s2.tablelow + 1;
1680 BRANCH_TARGET(*table, tbptr, copy);
1683 superblockend = true;
1686 /* pop 1 push 0 table branch */
1688 case ICMD_LOOKUPSWITCH:
1689 COUNT(count_pcmd_table);
1690 NEW_OP1_BRANCH(TYPE_INT);
1692 BRANCH_TARGET(iptr->sx.s23.s3.lookupdefault, tbptr, copy);
1694 lookup = iptr->dst.lookup;
1696 i = iptr->sx.s23.s2.lookupcount;
1699 BRANCH_TARGET(lookup->target, tbptr, copy);
1702 superblockend = true;
1705 case ICMD_MONITORENTER:
1706 case ICMD_MONITOREXIT:
1707 COUNT(count_check_null);
1708 NEW_OP1_0(TYPE_ADR);
1711 /* pop 2 push 0 branch */
1713 case ICMD_IF_ICMPEQ:
1714 case ICMD_IF_ICMPNE:
1715 case ICMD_IF_ICMPLT:
1716 case ICMD_IF_ICMPGE:
1717 case ICMD_IF_ICMPGT:
1718 case ICMD_IF_ICMPLE:
1719 COUNT(count_pcmd_bra);
1720 NEW_OP2_BRANCH(TYPE_INT, TYPE_INT);
1721 BRANCH(tbptr, copy);
1724 case ICMD_IF_ACMPEQ:
1725 case ICMD_IF_ACMPNE:
1726 COUNT(count_pcmd_bra);
1727 NEW_OP2_BRANCH(TYPE_ADR, TYPE_ADR);
1728 BRANCH(tbptr, copy);
1734 COUNT(count_check_null);
1735 COUNT(count_pcmd_mem);
1736 NEW_INSTRUCTION_GET_FIELDREF(iptr, fmiref);
1737 NEW_OP2_0(TYPE_ADR, fmiref->parseddesc.fd->type);
1742 if (!IS_2_WORD_TYPE(curstack->type)) {
1744 #ifdef ENABLE_VERIFIER
1747 if (IS_2_WORD_TYPE(curstack->prev->type))
1748 goto throw_stack_category_error;
1751 NEW_OP2_0_ANY_ANY; /* pop two slots */
1754 iptr->opc = ICMD_POP;
1755 NEW_OP1_0_ANY; /* pop one (two-word) slot */
1759 /* pop 0 push 1 dup */
1762 #ifdef ENABLE_VERIFIER
1765 if (IS_2_WORD_TYPE(curstack->type))
1766 goto throw_stack_category_error;
1769 last_dupx = bptr->icount - len - 1;
1770 COUNT(count_dup_instruction);
1773 USE_S1_ANY; /* XXX live through */
1774 DUP_SLOT(iptr->s1.var);
1775 iptr->dst.var = curstack;
1780 last_dupx = bptr->icount - len - 1;
1782 if (IS_2_WORD_TYPE(curstack->type)) {
1784 iptr->opc = ICMD_DUP;
1789 /* ..., ????, cat1 */
1790 #ifdef ENABLE_VERIFIER
1792 if (IS_2_WORD_TYPE(curstack->prev->type))
1793 goto throw_stack_category_error;
1796 iptr->dst.dupslots = DMNEW(stackptr, 2 + 2);
1797 iptr->dst.dupslots[0] = curstack->prev; /* XXX live through */
1798 iptr->dst.dupslots[1] = curstack; /* XXX live through */
1800 DUP_SLOT(iptr->dst.dupslots[0]);
1801 iptr->dst.dupslots[2+0] = curstack;
1802 DUP_SLOT(iptr->dst.dupslots[1]);
1803 iptr->dst.dupslots[2+1] = curstack;
1808 /* pop 2 push 3 dup */
1811 #ifdef ENABLE_VERIFIER
1814 if (IS_2_WORD_TYPE(curstack->type) ||
1815 IS_2_WORD_TYPE(curstack->prev->type))
1816 goto throw_stack_category_error;
1819 last_dupx = bptr->icount - len - 1;
1822 iptr->dst.dupslots = DMNEW(stackptr, 2 + 3);
1823 iptr->dst.dupslots[0] = curstack->prev;
1824 iptr->dst.dupslots[1] = curstack;
1827 DUP_SLOT(iptr->dst.dupslots[1]);
1828 iptr->dst.dupslots[2+0] = curstack;
1829 DUP_SLOT(iptr->dst.dupslots[0]);
1830 iptr->dst.dupslots[2+1] = curstack;
1831 DUP_SLOT(iptr->dst.dupslots[1]);
1832 iptr->dst.dupslots[2+2] = curstack;
1837 last_dupx = bptr->icount - len - 1;
1839 if (IS_2_WORD_TYPE(curstack->type)) {
1840 /* ..., ????, cat2 */
1841 #ifdef ENABLE_VERIFIER
1843 if (IS_2_WORD_TYPE(curstack->prev->type))
1844 goto throw_stack_category_error;
1847 iptr->opc = ICMD_DUP_X1;
1851 /* ..., ????, cat1 */
1852 #ifdef ENABLE_VERIFIER
1855 if (IS_2_WORD_TYPE(curstack->prev->type)
1856 || IS_2_WORD_TYPE(curstack->prev->prev->type))
1857 goto throw_stack_category_error;
1862 iptr->dst.dupslots = DMNEW(stackptr, 3 + 5);
1863 iptr->dst.dupslots[0] = curstack->prev->prev;
1864 iptr->dst.dupslots[1] = curstack->prev;
1865 iptr->dst.dupslots[2] = curstack;
1866 POPANY; POPANY; POPANY;
1868 DUP_SLOT(iptr->dst.dupslots[1]);
1869 iptr->dst.dupslots[3+0] = curstack;
1870 DUP_SLOT(iptr->dst.dupslots[2]);
1871 iptr->dst.dupslots[3+1] = curstack;
1872 DUP_SLOT(iptr->dst.dupslots[0]);
1873 iptr->dst.dupslots[3+2] = curstack;
1874 DUP_SLOT(iptr->dst.dupslots[1]);
1875 iptr->dst.dupslots[3+3] = curstack;
1876 DUP_SLOT(iptr->dst.dupslots[2]);
1877 iptr->dst.dupslots[3+4] = curstack;
1882 /* pop 3 push 4 dup */
1885 last_dupx = bptr->icount - len - 1;
1887 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1888 /* ..., cat2, ???? */
1889 #ifdef ENABLE_VERIFIER
1891 if (IS_2_WORD_TYPE(curstack->type))
1892 goto throw_stack_category_error;
1895 iptr->opc = ICMD_DUP_X1;
1899 /* ..., cat1, ???? */
1900 #ifdef ENABLE_VERIFIER
1903 if (IS_2_WORD_TYPE(curstack->type)
1904 || IS_2_WORD_TYPE(curstack->prev->prev->type))
1905 goto throw_stack_category_error;
1909 iptr->dst.dupslots = DMNEW(stackptr, 3 + 4);
1910 iptr->dst.dupslots[0] = curstack->prev->prev;
1911 iptr->dst.dupslots[1] = curstack->prev;
1912 iptr->dst.dupslots[2] = curstack;
1913 POPANY; POPANY; POPANY;
1915 DUP_SLOT(iptr->dst.dupslots[2]);
1916 iptr->dst.dupslots[3+0] = curstack;
1917 DUP_SLOT(iptr->dst.dupslots[0]);
1918 iptr->dst.dupslots[3+1] = curstack;
1919 DUP_SLOT(iptr->dst.dupslots[1]);
1920 iptr->dst.dupslots[3+2] = curstack;
1921 DUP_SLOT(iptr->dst.dupslots[2]);
1922 iptr->dst.dupslots[3+3] = curstack;
1928 last_dupx = bptr->icount - len - 1;
1930 if (IS_2_WORD_TYPE(curstack->type)) {
1931 /* ..., ????, cat2 */
1932 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1933 /* ..., cat2, cat2 */
1934 iptr->opc = ICMD_DUP_X1;
1938 /* ..., cat1, cat2 */
1939 #ifdef ENABLE_VERIFIER
1942 if (IS_2_WORD_TYPE(curstack->prev->prev->type))
1943 goto throw_stack_category_error;
1946 iptr->opc = ICMD_DUP_X2;
1952 /* ..., ????, ????, cat1 */
1954 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1955 /* ..., cat2, ????, cat1 */
1956 #ifdef ENABLE_VERIFIER
1958 if (IS_2_WORD_TYPE(curstack->prev->type))
1959 goto throw_stack_category_error;
1962 iptr->opc = ICMD_DUP2_X1;
1966 /* ..., cat1, ????, cat1 */
1967 #ifdef ENABLE_VERIFIER
1970 if (IS_2_WORD_TYPE(curstack->prev->type)
1971 || IS_2_WORD_TYPE(curstack->prev->prev->prev->type))
1972 goto throw_stack_category_error;
1975 iptr->dst.dupslots = DMNEW(stackptr, 4 + 6);
1976 iptr->dst.dupslots[0] = curstack->prev->prev->prev;
1977 iptr->dst.dupslots[1] = curstack->prev->prev;
1978 iptr->dst.dupslots[2] = curstack->prev;
1979 iptr->dst.dupslots[3] = curstack;
1980 POPANY; POPANY; POPANY; POPANY;
1982 DUP_SLOT(iptr->dst.dupslots[2]);
1983 iptr->dst.dupslots[4+0] = curstack;
1984 DUP_SLOT(iptr->dst.dupslots[3]);
1985 iptr->dst.dupslots[4+1] = curstack;
1986 DUP_SLOT(iptr->dst.dupslots[0]);
1987 iptr->dst.dupslots[4+2] = curstack;
1988 DUP_SLOT(iptr->dst.dupslots[1]);
1989 iptr->dst.dupslots[4+3] = curstack;
1990 DUP_SLOT(iptr->dst.dupslots[2]);
1991 iptr->dst.dupslots[4+4] = curstack;
1992 DUP_SLOT(iptr->dst.dupslots[3]);
1993 iptr->dst.dupslots[4+5] = curstack;
1998 /* pop 2 push 2 swap */
2001 last_dupx = bptr->icount - len - 1;
2002 #ifdef ENABLE_VERIFIER
2005 if (IS_2_WORD_TYPE(curstack->type)
2006 || IS_2_WORD_TYPE(curstack->prev->type))
2007 goto throw_stack_category_error;
2010 iptr->dst.dupslots = DMNEW(stackptr, 2 + 2);
2011 iptr->dst.dupslots[0] = curstack->prev;
2012 iptr->dst.dupslots[1] = curstack;
2015 DUP_SLOT(iptr->dst.dupslots[1]);
2016 iptr->dst.dupslots[2+0] = curstack;
2017 DUP_SLOT(iptr->dst.dupslots[0]);
2018 iptr->dst.dupslots[2+1] = curstack;
2025 #if !SUPPORT_DIVISION
2026 bte = iptr->sx.s23.s3.bte;
2029 if (md->memuse > rd->memuse)
2030 rd->memuse = md->memuse;
2031 if (md->argintreguse > rd->argintreguse)
2032 rd->argintreguse = md->argintreguse;
2034 /* make all stack variables saved */
2038 copy->flags |= SAVEDVAR;
2043 #endif /* !SUPPORT_DIVISION */
2054 COUNT(count_pcmd_op);
2055 NEW_OP2_1(TYPE_INT, TYPE_INT, TYPE_INT);
2060 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
2061 bte = iptr->sx.s23.s3.bte;
2064 if (md->memuse > rd->memuse)
2065 rd->memuse = md->memuse;
2066 if (md->argintreguse > rd->argintreguse)
2067 rd->argintreguse = md->argintreguse;
2068 /* XXX non-leaf method? */
2070 /* make all stack variables saved */
2074 copy->flags |= SAVEDVAR;
2079 #endif /* !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV) */
2084 #if SUPPORT_LONG_LOGICAL
2088 #endif /* SUPPORT_LONG_LOGICAL */
2089 COUNT(count_pcmd_op);
2090 NEW_OP2_1(TYPE_LNG, TYPE_LNG, TYPE_LNG);
2096 COUNT(count_pcmd_op);
2097 NEW_OP2_1(TYPE_LNG, TYPE_INT, TYPE_LNG);
2105 COUNT(count_pcmd_op);
2106 NEW_OP2_1(TYPE_FLT, TYPE_FLT, TYPE_FLT);
2114 COUNT(count_pcmd_op);
2115 NEW_OP2_1(TYPE_DBL, TYPE_DBL, TYPE_DBL);
2119 COUNT(count_pcmd_op);
2120 #if SUPPORT_LONG_CMP_CONST
2121 if ((len == 0) || (iptr[1].sx.val.i != 0))
2124 switch (iptr[1].opc) {
2126 iptr->opc = ICMD_IF_LCMPEQ;
2128 iptr->dst.insindex = iptr[1].dst.insindex;
2129 iptr[1].opc = ICMD_NOP;
2131 NEW_OP2_BRANCH(TYPE_LNG, TYPE_LNG);
2132 BRANCH(tbptr, copy);
2134 COUNT(count_pcmd_bra);
2137 iptr->opc = ICMD_IF_LCMPNE;
2138 goto icmd_lcmp_if_tail;
2140 iptr->opc = ICMD_IF_LCMPLT;
2141 goto icmd_lcmp_if_tail;
2143 iptr->opc = ICMD_IF_LCMPGT;
2144 goto icmd_lcmp_if_tail;
2146 iptr->opc = ICMD_IF_LCMPLE;
2147 goto icmd_lcmp_if_tail;
2149 iptr->opc = ICMD_IF_LCMPGE;
2150 goto icmd_lcmp_if_tail;
2156 #endif /* SUPPORT_LONG_CMP_CONST */
2157 NEW_OP2_1(TYPE_LNG, TYPE_LNG, TYPE_INT);
2160 /* XXX why is this deactivated? */
2163 COUNT(count_pcmd_op);
2164 if ((len == 0) || (iptr[1].sx.val.i != 0))
2167 switch (iptr[1].opc) {
2169 iptr->opc = ICMD_IF_FCMPEQ;
2171 iptr->dst.insindex = iptr[1].dst.insindex;
2172 iptr[1].opc = ICMD_NOP;
2174 NEW_OP2_BRANCH(TYPE_FLT, TYPE_FLT);
2175 BRANCH(tbptr, copy);
2177 COUNT(count_pcmd_bra);
2180 iptr->opc = ICMD_IF_FCMPNE;
2181 goto icmd_if_fcmpl_tail;
2183 iptr->opc = ICMD_IF_FCMPL_LT;
2184 goto icmd_if_fcmpl_tail;
2186 iptr->opc = ICMD_IF_FCMPL_GT;
2187 goto icmd_if_fcmpl_tail;
2189 iptr->opc = ICMD_IF_FCMPL_LE;
2190 goto icmd_if_fcmpl_tail;
2192 iptr->opc = ICMD_IF_FCMPL_GE;
2193 goto icmd_if_fcmpl_tail;
2200 OPTT2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
2204 COUNT(count_pcmd_op);
2205 if ((len == 0) || (iptr[1].sx.val.i != 0))
2208 switch (iptr[1].opc) {
2210 iptr->opc = ICMD_IF_FCMPEQ;
2212 iptr->dst.insindex = iptr[1].dst.insindex;
2213 iptr[1].opc = ICMD_NOP;
2215 NEW_OP2_BRANCH(TYPE_FLT, TYPE_FLT);
2216 BRANCH(tbptr, copy);
2218 COUNT(count_pcmd_bra);
2221 iptr->opc = ICMD_IF_FCMPNE;
2222 goto icmd_if_fcmpg_tail;
2224 iptr->opc = ICMD_IF_FCMPG_LT;
2225 goto icmd_if_fcmpg_tail;
2227 iptr->opc = ICMD_IF_FCMPG_GT;
2228 goto icmd_if_fcmpg_tail;
2230 iptr->opc = ICMD_IF_FCMPG_LE;
2231 goto icmd_if_fcmpg_tail;
2233 iptr->opc = ICMD_IF_FCMPG_GE;
2234 goto icmd_if_fcmpg_tail;
2241 NEW_OP2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
2245 COUNT(count_pcmd_op);
2246 if ((len == 0) || (iptr[1].sx.val.i != 0))
2249 switch (iptr[1].opc) {
2251 iptr->opc = ICMD_IF_DCMPEQ;
2253 iptr->dst.insindex = iptr[1].dst.insindex;
2254 iptr[1].opc = ICMD_NOP;
2256 NEW_OP2_BRANCH(TYPE_DBL, TYPE_DBL);
2257 BRANCH(tbptr, copy);
2259 COUNT(count_pcmd_bra);
2262 iptr->opc = ICMD_IF_DCMPNE;
2263 goto icmd_if_dcmpl_tail;
2265 iptr->opc = ICMD_IF_DCMPL_LT;
2266 goto icmd_if_dcmpl_tail;
2268 iptr->opc = ICMD_IF_DCMPL_GT;
2269 goto icmd_if_dcmpl_tail;
2271 iptr->opc = ICMD_IF_DCMPL_LE;
2272 goto icmd_if_dcmpl_tail;
2274 iptr->opc = ICMD_IF_DCMPL_GE;
2275 goto icmd_if_dcmpl_tail;
2282 OPTT2_1(TYPE_DBL, TYPE_INT);
2286 COUNT(count_pcmd_op);
2287 if ((len == 0) || (iptr[1].sx.val.i != 0))
2290 switch (iptr[1].opc) {
2292 iptr->opc = ICMD_IF_DCMPEQ;
2294 iptr->dst.insindex = iptr[1].dst.insindex;
2295 iptr[1].opc = ICMD_NOP;
2297 NEW_OP2_BRANCH(TYPE_DBL, TYPE_DBL);
2298 BRANCH(tbptr, copy);
2300 COUNT(count_pcmd_bra);
2303 iptr->opc = ICMD_IF_DCMPNE;
2304 goto icmd_if_dcmpg_tail;
2306 iptr->opc = ICMD_IF_DCMPG_LT;
2307 goto icmd_if_dcmpg_tail;
2309 iptr->opc = ICMD_IF_DCMPG_GT;
2310 goto icmd_if_dcmpg_tail;
2312 iptr->opc = ICMD_IF_DCMPG_LE;
2313 goto icmd_if_dcmpg_tail;
2315 iptr->opc = ICMD_IF_DCMPG_GE;
2316 goto icmd_if_dcmpg_tail;
2323 NEW_OP2_1(TYPE_DBL, TYPE_DBL, TYPE_INT);
2328 COUNT(count_pcmd_op);
2329 NEW_OP2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
2334 COUNT(count_pcmd_op);
2335 NEW_OP2_1(TYPE_DBL, TYPE_DBL, TYPE_INT);
2344 case ICMD_INT2SHORT:
2345 COUNT(count_pcmd_op);
2346 NEW_OP1_1(TYPE_INT, TYPE_INT);
2349 COUNT(count_pcmd_op);
2350 NEW_OP1_1(TYPE_LNG, TYPE_LNG);
2353 COUNT(count_pcmd_op);
2354 NEW_OP1_1(TYPE_FLT, TYPE_FLT);
2357 COUNT(count_pcmd_op);
2358 NEW_OP1_1(TYPE_DBL, TYPE_DBL);
2362 COUNT(count_pcmd_op);
2363 NEW_OP1_1(TYPE_INT, TYPE_LNG);
2366 COUNT(count_pcmd_op);
2367 NEW_OP1_1(TYPE_INT, TYPE_FLT);
2370 COUNT(count_pcmd_op);
2371 NEW_OP1_1(TYPE_INT, TYPE_DBL);
2374 COUNT(count_pcmd_op);
2375 NEW_OP1_1(TYPE_LNG, TYPE_INT);
2378 COUNT(count_pcmd_op);
2379 NEW_OP1_1(TYPE_LNG, TYPE_FLT);
2382 COUNT(count_pcmd_op);
2383 NEW_OP1_1(TYPE_LNG, TYPE_DBL);
2386 COUNT(count_pcmd_op);
2387 NEW_OP1_1(TYPE_FLT, TYPE_INT);
2390 COUNT(count_pcmd_op);
2391 NEW_OP1_1(TYPE_FLT, TYPE_LNG);
2394 COUNT(count_pcmd_op);
2395 NEW_OP1_1(TYPE_FLT, TYPE_DBL);
2398 COUNT(count_pcmd_op);
2399 NEW_OP1_1(TYPE_DBL, TYPE_INT);
2402 COUNT(count_pcmd_op);
2403 NEW_OP1_1(TYPE_DBL, TYPE_LNG);
2406 COUNT(count_pcmd_op);
2407 NEW_OP1_1(TYPE_DBL, TYPE_FLT);
2410 case ICMD_CHECKCAST:
2411 if (iptr->flags.bits & INS_FLAG_ARRAY) {
2412 /* array type cast-check */
2414 bte = builtintable_get_internal(BUILTIN_arraycheckcast);
2417 if (md->memuse > rd->memuse)
2418 rd->memuse = md->memuse;
2419 if (md->argintreguse > rd->argintreguse)
2420 rd->argintreguse = md->argintreguse;
2422 /* make all stack variables saved */
2426 copy->flags |= SAVEDVAR;
2430 NEW_OP1_1(TYPE_ADR, TYPE_ADR);
2433 case ICMD_INSTANCEOF:
2434 case ICMD_ARRAYLENGTH:
2435 NEW_OP1_1(TYPE_ADR, TYPE_INT);
2439 case ICMD_ANEWARRAY:
2440 NEW_OP1_1(TYPE_INT, TYPE_ADR);
2444 COUNT(count_check_null);
2445 COUNT(count_pcmd_mem);
2446 NEW_INSTRUCTION_GET_FIELDREF(iptr, fmiref);
2447 NEW_OP1_1(TYPE_ADR, fmiref->parseddesc.fd->type);
2452 case ICMD_GETSTATIC:
2453 COUNT(count_pcmd_mem);
2454 NEW_INSTRUCTION_GET_FIELDREF(iptr, fmiref);
2455 NEW_OP0_1(fmiref->parseddesc.fd->type);
2459 NEW_OP0_1(TYPE_ADR);
2463 NEW_OP0_1(TYPE_ADR);
2465 BRANCH_TARGET(iptr->sx.s23.s3.jsrtarget, tbptr, copy);
2467 tbptr->type = BBTYPE_SBR;
2469 /* We need to check for overflow right here because
2470 * the pushed value is poped afterwards */
2473 /* calculate stack after return */
2478 /* pop many push any */
2481 #if defined(USEBUILTINTABLE)
2484 bte = iptr->sx.s23.s3.bte;
2488 case ICMD_INVOKESTATIC:
2489 case ICMD_INVOKESPECIAL:
2490 case ICMD_INVOKEVIRTUAL:
2491 case ICMD_INVOKEINTERFACE:
2492 COUNT(count_pcmd_met);
2493 NEW_INSTRUCTION_GET_METHODDESC(iptr, md);
2494 /* XXX resurrect this COUNT? */
2495 /* if (lm->flags & ACC_STATIC) */
2496 /* {COUNT(count_check_null);} */
2500 last_pei = bptr->icount - len - 1;
2504 if (md->memuse > rd->memuse)
2505 rd->memuse = md->memuse;
2506 if (md->argintreguse > rd->argintreguse)
2507 rd->argintreguse = md->argintreguse;
2508 if (md->argfltreguse > rd->argfltreguse)
2509 rd->argfltreguse = md->argfltreguse;
2513 /* XXX optimize for <= 2 args */
2514 iptr->s1.argcount = i;
2515 iptr->sx.s23.s2.args = DMNEW(stackptr, i);
2518 for (i-- ; i >= 0; i--) {
2519 iptr->sx.s23.s2.args[i] = copy;
2521 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2522 /* If we pass float arguments in integer argument registers, we
2523 * are not allowed to precolor them here. Floats have to be moved
2524 * to this regs explicitly in codegen().
2525 * Only arguments that are passed by stack anyway can be precolored
2526 * (michi 2005/07/24) */
2527 if (!(copy->flags & SAVEDVAR) &&
2528 (!IS_FLT_DBL_TYPE(copy->type) || md->params[i].inmemory)) {
2530 if (!(copy->flags & SAVEDVAR)) {
2532 copy->varkind = ARGVAR;
2535 #if defined(ENABLE_INTRP)
2538 if (md->params[i].inmemory) {
2539 copy->flags = INMEMORY;
2540 copy->regoff = md->params[i].regoff;
2544 if (IS_FLT_DBL_TYPE(copy->type)) {
2545 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2546 assert(0); /* XXX is this assert ok? */
2549 rd->argfltregs[md->params[i].regoff];
2550 #endif /* SUPPORT_PASS_FLOATARGS_IN_INTREGS */
2553 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
2554 if (IS_2_WORD_TYPE(copy->type))
2555 copy->regoff = PACK_REGS(
2556 rd->argintregs[GET_LOW_REG(md->params[i].regoff)],
2557 rd->argintregs[GET_HIGH_REG(md->params[i].regoff)]);
2559 #endif /* SUPPORT_COMBINE_INTEGER_REGISTERS */
2561 rd->argintregs[md->params[i].regoff];
2564 #if defined(ENABLE_INTRP)
2565 } /* end if (!opt_intrp) */
2572 copy->flags |= SAVEDVAR;
2583 if (md->returntype.type != TYPE_VOID) {
2584 NEW_DST(md->returntype.type, stackdepth);
2589 case ICMD_INLINE_START:
2590 case ICMD_INLINE_END:
2595 case ICMD_MULTIANEWARRAY:
2596 if (rd->argintreguse < 3)
2597 rd->argintreguse = 3;
2599 i = iptr->s1.argcount;
2603 iptr->sx.s23.s2.args = DMNEW(stackptr, i);
2605 #if defined(SPECIALMEMUSE)
2606 # if defined(__DARWIN__)
2607 if (rd->memuse < (i + INT_ARG_CNT + LA_WORD_SIZE))
2608 rd->memuse = i + LA_WORD_SIZE + INT_ARG_CNT;
2610 if (rd->memuse < (i + LA_WORD_SIZE + 3))
2611 rd->memuse = i + LA_WORD_SIZE + 3;
2614 # if defined(__I386__)
2615 if (rd->memuse < i + 3)
2616 rd->memuse = i + 3; /* n integer args spilled on stack */
2617 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
2618 if (rd->memuse < i + 2)
2619 rd->memuse = i + 2; /* 4*4 bytes callee save space */
2622 rd->memuse = i; /* n integer args spilled on stack */
2623 # endif /* defined(__I386__) */
2627 /* check INT type here? Currently typecheck does this. */
2628 iptr->sx.s23.s2.args[i] = copy;
2629 if (!(copy->flags & SAVEDVAR)) {
2630 copy->varkind = ARGVAR;
2631 copy->varnum = i + INT_ARG_CNT;
2632 copy->flags |= INMEMORY;
2633 #if defined(SPECIALMEMUSE)
2634 # if defined(__DARWIN__)
2635 copy->regoff = i + LA_WORD_SIZE + INT_ARG_CNT;
2637 copy->regoff = i + LA_WORD_SIZE + 3;
2640 # if defined(__I386__)
2641 copy->regoff = i + 3;
2642 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
2643 copy->regoff = i + 2;
2646 # endif /* defined(__I386__) */
2647 #endif /* defined(SPECIALMEMUSE) */
2652 copy->flags |= SAVEDVAR;
2656 i = iptr->s1.argcount;
2661 NEW_DST(TYPE_ADR, stackdepth);
2667 new_internalerror("Unknown ICMD %d", opcode);
2673 } /* while instructions */
2675 /* set out-stack of block */
2677 bptr->outstack = curstack;
2678 bptr->outdepth = stackdepth;
2680 /* stack slots at basic block end become interfaces */
2683 for (copy = curstack; copy; i--, copy = copy->prev) {
2684 if ((copy->varkind == STACKVAR) && (copy->varnum > i))
2685 copy->varkind = TEMPVAR;
2687 copy->varkind = STACKVAR;
2691 rd->interfaces[i][copy->type].type = copy->type;
2692 rd->interfaces[i][copy->type].flags |= copy->flags;
2696 /* check if interface slots at basic block begin must be saved */
2699 i = bptr->indepth - 1;
2700 for (copy = bptr->instack; copy; i--, copy = copy->prev) {
2701 rd->interfaces[i][copy->type].type = copy->type;
2702 if (copy->varkind == STACKVAR) {
2703 if (copy->flags & SAVEDVAR)
2704 rd->interfaces[i][copy->type].flags |= SAVEDVAR;
2711 superblockend = true;
2714 } /* while blocks */
2715 } while (repeat && !deadcode);
2717 /* gather statistics *****************************************************/
2719 #if defined(ENABLE_STATISTICS)
2721 if (jd->new_basicblockcount > count_max_basic_blocks)
2722 count_max_basic_blocks = jd->new_basicblockcount;
2723 count_basic_blocks += jd->new_basicblockcount;
2724 if (jd->new_instructioncount > count_max_javainstr)
2725 count_max_javainstr = jd->new_instructioncount;
2726 count_javainstr += jd->new_instructioncount;
2727 if (jd->new_stackcount > count_upper_bound_new_stack)
2728 count_upper_bound_new_stack = jd->new_stackcount;
2729 if ((new - jd->new_stack) > count_max_new_stack)
2730 count_max_new_stack = (new - jd->new_stack);
2732 b_count = jd->new_basicblockcount;
2733 bptr = jd->new_basicblocks;
2734 while (--b_count >= 0) {
2735 if (bptr->flags > BBREACHED) {
2736 if (bptr->indepth >= 10)
2737 count_block_stack[10]++;
2739 count_block_stack[bptr->indepth]++;
2742 count_block_size_distribution[len]++;
2744 count_block_size_distribution[10]++;
2746 count_block_size_distribution[11]++;
2748 count_block_size_distribution[12]++;
2750 count_block_size_distribution[13]++;
2752 count_block_size_distribution[14]++;
2754 count_block_size_distribution[15]++;
2756 count_block_size_distribution[16]++;
2758 count_block_size_distribution[17]++;
2763 if (iteration_count == 1)
2764 count_analyse_iterations[0]++;
2765 else if (iteration_count == 2)
2766 count_analyse_iterations[1]++;
2767 else if (iteration_count == 3)
2768 count_analyse_iterations[2]++;
2769 else if (iteration_count == 4)
2770 count_analyse_iterations[3]++;
2772 count_analyse_iterations[4]++;
2774 if (jd->new_basicblockcount <= 5)
2775 count_method_bb_distribution[0]++;
2776 else if (jd->new_basicblockcount <= 10)
2777 count_method_bb_distribution[1]++;
2778 else if (jd->new_basicblockcount <= 15)
2779 count_method_bb_distribution[2]++;
2780 else if (jd->new_basicblockcount <= 20)
2781 count_method_bb_distribution[3]++;
2782 else if (jd->new_basicblockcount <= 30)
2783 count_method_bb_distribution[4]++;
2784 else if (jd->new_basicblockcount <= 40)
2785 count_method_bb_distribution[5]++;
2786 else if (jd->new_basicblockcount <= 50)
2787 count_method_bb_distribution[6]++;
2788 else if (jd->new_basicblockcount <= 75)
2789 count_method_bb_distribution[7]++;
2791 count_method_bb_distribution[8]++;
2793 #endif /* defined(ENABLE_STATISTICS) */
2795 /* everything's ok *******************************************************/
2799 /* goto labels for throwing verifier exceptions **************************/
2801 #if defined(ENABLE_VERIFIER)
2803 throw_stack_underflow:
2804 exceptions_throw_verifyerror(m, "Unable to pop operand off an empty stack");
2807 throw_stack_overflow:
2808 exceptions_throw_verifyerror(m, "Stack size too large");
2811 throw_stack_depth_error:
2812 exceptions_throw_verifyerror(m,"Stack depth mismatch");
2815 throw_stack_type_error:
2816 exceptions_throw_verifyerror_for_stack(m, expectedtype);
2819 throw_stack_category_error:
2820 exceptions_throw_verifyerror(m, "Attempt to split long or double on the stack");
2826 bool stack_analyse(jitdata *jd)
2838 int opcode, i, j, len, loops;
2839 int superblockend, repeat, deadcode;
2845 s4 *last_store;/* instruction index of last XSTORE */
2846 /* [ local_index * 5 + type ] */
2847 s4 last_pei; /* instruction index of last possible exception */
2848 /* used for conflict resolution for copy */
2849 /* elimination (XLOAD, IINC, XSTORE) */
2851 #if defined(ENABLE_VERIFIER)
2852 int expectedtype; /* used by CHECK_BASIC_TYPE */
2855 builtintable_entry *bte;
2858 /* get required compiler data */
2865 #if defined(ENABLE_LSRA)
2866 m->maxlifetimes = 0;
2869 last_store = DMNEW(s4 , cd->maxlocals * 5);
2873 m->basicblocks[0].flags = BBREACHED;
2874 m->basicblocks[0].instack = 0;
2875 m->basicblocks[0].indepth = 0;
2877 for (i = 0; i < cd->exceptiontablelength; i++) {
2878 bptr = &m->basicblocks[m->basicblockindex[cd->exceptiontable[i].handlerpc]];
2879 bptr->flags = BBREACHED;
2880 bptr->type = BBTYPE_EXH;
2881 bptr->instack = new;
2883 bptr->predecessorcount = CFG_UNKNOWN_PREDECESSORS;
2890 b_count = m->basicblockcount;
2891 bptr = m->basicblocks;
2892 superblockend = true;
2897 while (--b_count >= 0) {
2898 if (bptr->flags == BBDELETED) {
2901 else if (superblockend && (bptr->flags < BBREACHED)) {
2904 else if (bptr->flags <= BBREACHED) {
2905 if (superblockend) {
2906 stackdepth = bptr->indepth;
2908 else if (bptr->flags < BBREACHED) {
2910 bptr->instack = copy;
2911 bptr->indepth = stackdepth;
2914 CHECK_STACK_DEPTH(bptr->indepth, stackdepth);
2917 curstack = bptr->instack;
2919 superblockend = false;
2920 bptr->flags = BBFINISHED;
2922 iptr = bptr->iinstr;
2923 b_index = bptr - m->basicblocks;
2927 for( i = 0; i < cd->maxlocals; i++)
2928 for( j = 0; j < 5; j++)
2929 last_store[5 * i + j] = -1;
2933 while (--len >= 0) {
2936 #if defined(USEBUILTINTABLE)
2937 # if defined(ENABLE_INTRP)
2940 bte = builtintable_get_automatic(opcode);
2942 if (bte && bte->opcode == opcode) {
2943 iptr->opc = ICMD_BUILTIN;
2944 iptr->op1 = false; /* don't check for exception */
2946 jd->isleafmethod = false;
2949 # if defined(ENABLE_INTRP)
2952 #endif /* defined(USEBUILTINTABLE) */
2954 /* this is the main switch */
2960 case ICMD_CHECKNULL:
2961 COUNT(count_check_null);
2967 #if defined(ENABLE_INTRP)
2970 rd->locals[iptr->op1][TYPE_ADR].type = TYPE_ADR;
2972 COUNT(count_pcmd_return);
2974 superblockend = true;
2977 /* pop 0 push 1 const */
2980 COUNT(count_pcmd_load);
2982 switch (iptr[1].opc) {
2984 iptr[0].opc = ICMD_IADDCONST;
2986 iptr[1].opc = ICMD_NOP;
2987 OP1_1(TYPE_INT, TYPE_INT);
2988 COUNT(count_pcmd_op);
2991 iptr[0].opc = ICMD_ISUBCONST;
2992 goto icmd_iconst_tail;
2993 #if SUPPORT_CONST_MUL
2995 iptr[0].opc = ICMD_IMULCONST;
2996 goto icmd_iconst_tail;
2997 #else /* SUPPORT_CONST_MUL */
2999 if (iptr[0].val.i == 0x00000002)
3001 else if (iptr[0].val.i == 0x00000004)
3003 else if (iptr[0].val.i == 0x00000008)
3005 else if (iptr[0].val.i == 0x00000010)
3007 else if (iptr[0].val.i == 0x00000020)
3009 else if (iptr[0].val.i == 0x00000040)
3011 else if (iptr[0].val.i == 0x00000080)
3013 else if (iptr[0].val.i == 0x00000100)
3015 else if (iptr[0].val.i == 0x00000200)
3017 else if (iptr[0].val.i == 0x00000400)
3019 else if (iptr[0].val.i == 0x00000800)
3021 else if (iptr[0].val.i == 0x00001000)
3023 else if (iptr[0].val.i == 0x00002000)
3025 else if (iptr[0].val.i == 0x00004000)
3027 else if (iptr[0].val.i == 0x00008000)
3029 else if (iptr[0].val.i == 0x00010000)
3031 else if (iptr[0].val.i == 0x00020000)
3033 else if (iptr[0].val.i == 0x00040000)
3035 else if (iptr[0].val.i == 0x00080000)
3037 else if (iptr[0].val.i == 0x00100000)
3039 else if (iptr[0].val.i == 0x00200000)
3041 else if (iptr[0].val.i == 0x00400000)
3043 else if (iptr[0].val.i == 0x00800000)
3045 else if (iptr[0].val.i == 0x01000000)
3047 else if (iptr[0].val.i == 0x02000000)
3049 else if (iptr[0].val.i == 0x04000000)
3051 else if (iptr[0].val.i == 0x08000000)
3053 else if (iptr[0].val.i == 0x10000000)
3055 else if (iptr[0].val.i == 0x20000000)
3057 else if (iptr[0].val.i == 0x40000000)
3059 else if (iptr[0].val.i == 0x80000000)
3062 PUSHCONST(TYPE_INT);
3065 iptr[0].opc = ICMD_IMULPOW2;
3066 goto icmd_iconst_tail;
3067 #endif /* SUPPORT_CONST_MUL */
3069 if (iptr[0].val.i == 0x00000002)
3071 else if (iptr[0].val.i == 0x00000004)
3073 else if (iptr[0].val.i == 0x00000008)
3075 else if (iptr[0].val.i == 0x00000010)
3077 else if (iptr[0].val.i == 0x00000020)
3079 else if (iptr[0].val.i == 0x00000040)
3081 else if (iptr[0].val.i == 0x00000080)
3083 else if (iptr[0].val.i == 0x00000100)
3085 else if (iptr[0].val.i == 0x00000200)
3087 else if (iptr[0].val.i == 0x00000400)
3089 else if (iptr[0].val.i == 0x00000800)
3091 else if (iptr[0].val.i == 0x00001000)
3093 else if (iptr[0].val.i == 0x00002000)
3095 else if (iptr[0].val.i == 0x00004000)
3097 else if (iptr[0].val.i == 0x00008000)
3099 else if (iptr[0].val.i == 0x00010000)
3101 else if (iptr[0].val.i == 0x00020000)
3103 else if (iptr[0].val.i == 0x00040000)
3105 else if (iptr[0].val.i == 0x00080000)
3107 else if (iptr[0].val.i == 0x00100000)
3109 else if (iptr[0].val.i == 0x00200000)
3111 else if (iptr[0].val.i == 0x00400000)
3113 else if (iptr[0].val.i == 0x00800000)
3115 else if (iptr[0].val.i == 0x01000000)
3117 else if (iptr[0].val.i == 0x02000000)
3119 else if (iptr[0].val.i == 0x04000000)
3121 else if (iptr[0].val.i == 0x08000000)
3123 else if (iptr[0].val.i == 0x10000000)
3125 else if (iptr[0].val.i == 0x20000000)
3127 else if (iptr[0].val.i == 0x40000000)
3129 else if (iptr[0].val.i == 0x80000000)
3132 PUSHCONST(TYPE_INT);
3135 iptr[0].opc = ICMD_IDIVPOW2;
3136 goto icmd_iconst_tail;
3138 /*log_text("stack.c: ICMD_ICONST/ICMD_IREM");*/
3139 if ((iptr[0].val.i == 0x00000002) ||
3140 (iptr[0].val.i == 0x00000004) ||
3141 (iptr[0].val.i == 0x00000008) ||
3142 (iptr[0].val.i == 0x00000010) ||
3143 (iptr[0].val.i == 0x00000020) ||
3144 (iptr[0].val.i == 0x00000040) ||
3145 (iptr[0].val.i == 0x00000080) ||
3146 (iptr[0].val.i == 0x00000100) ||
3147 (iptr[0].val.i == 0x00000200) ||
3148 (iptr[0].val.i == 0x00000400) ||
3149 (iptr[0].val.i == 0x00000800) ||
3150 (iptr[0].val.i == 0x00001000) ||
3151 (iptr[0].val.i == 0x00002000) ||
3152 (iptr[0].val.i == 0x00004000) ||
3153 (iptr[0].val.i == 0x00008000) ||
3154 (iptr[0].val.i == 0x00010000) ||
3155 (iptr[0].val.i == 0x00020000) ||
3156 (iptr[0].val.i == 0x00040000) ||
3157 (iptr[0].val.i == 0x00080000) ||
3158 (iptr[0].val.i == 0x00100000) ||
3159 (iptr[0].val.i == 0x00200000) ||
3160 (iptr[0].val.i == 0x00400000) ||
3161 (iptr[0].val.i == 0x00800000) ||
3162 (iptr[0].val.i == 0x01000000) ||
3163 (iptr[0].val.i == 0x02000000) ||
3164 (iptr[0].val.i == 0x04000000) ||
3165 (iptr[0].val.i == 0x08000000) ||
3166 (iptr[0].val.i == 0x10000000) ||
3167 (iptr[0].val.i == 0x20000000) ||
3168 (iptr[0].val.i == 0x40000000) ||
3169 (iptr[0].val.i == 0x80000000)) {
3170 iptr[0].opc = ICMD_IREMPOW2;
3172 goto icmd_iconst_tail;
3174 PUSHCONST(TYPE_INT);
3176 #if SUPPORT_CONST_LOGICAL
3178 iptr[0].opc = ICMD_IANDCONST;
3179 goto icmd_iconst_tail;
3181 iptr[0].opc = ICMD_IORCONST;
3182 goto icmd_iconst_tail;
3184 iptr[0].opc = ICMD_IXORCONST;
3185 goto icmd_iconst_tail;
3186 #endif /* SUPPORT_CONST_LOGICAL */
3188 iptr[0].opc = ICMD_ISHLCONST;
3189 goto icmd_iconst_tail;
3191 iptr[0].opc = ICMD_ISHRCONST;
3192 goto icmd_iconst_tail;
3194 iptr[0].opc = ICMD_IUSHRCONST;
3195 goto icmd_iconst_tail;
3196 #if SUPPORT_LONG_SHIFT
3198 iptr[0].opc = ICMD_LSHLCONST;
3199 goto icmd_lconst_tail;
3201 iptr[0].opc = ICMD_LSHRCONST;
3202 goto icmd_lconst_tail;
3204 iptr[0].opc = ICMD_LUSHRCONST;
3205 goto icmd_lconst_tail;
3206 #endif /* SUPPORT_LONG_SHIFT */
3207 case ICMD_IF_ICMPEQ:
3208 iptr[1].opc = ICMD_IFEQ;
3210 /* iptr[0].op1 = iptr[1].op1; */
3211 /* IF_ICMPxx is the last instruction in the
3212 basic block, just remove it. */
3213 iptr[0].opc = ICMD_NOP;
3214 iptr[1].val.i = iptr[0].val.i;
3216 /* bptr->icount--; */
3220 tbptr = m->basicblocks +
3221 m->basicblockindex[iptr[1].op1];
3223 iptr[1].target = (void *) tbptr;
3225 MARKREACHED(tbptr, copy);
3226 COUNT(count_pcmd_bra);
3229 case ICMD_IF_ICMPLT:
3230 iptr[1].opc = ICMD_IFLT;
3231 goto icmd_if_icmp_tail;
3232 case ICMD_IF_ICMPLE:
3233 iptr[1].opc = ICMD_IFLE;
3234 goto icmd_if_icmp_tail;
3235 case ICMD_IF_ICMPNE:
3236 iptr[1].opc = ICMD_IFNE;
3237 goto icmd_if_icmp_tail;
3238 case ICMD_IF_ICMPGT:
3239 iptr[1].opc = ICMD_IFGT;
3240 goto icmd_if_icmp_tail;
3241 case ICMD_IF_ICMPGE:
3242 iptr[1].opc = ICMD_IFGE;
3243 goto icmd_if_icmp_tail;
3245 #if SUPPORT_CONST_STORE
3250 # if defined(ENABLE_INTRP)
3253 # if SUPPORT_CONST_STORE_ZERO_ONLY
3254 if (iptr[0].val.i == 0) {
3256 switch (iptr[1].opc) {
3258 iptr[0].opc = ICMD_IASTORECONST;
3261 iptr[0].opc = ICMD_BASTORECONST;
3264 iptr[0].opc = ICMD_CASTORECONST;
3267 iptr[0].opc = ICMD_SASTORECONST;
3271 iptr[1].opc = ICMD_NOP;
3272 OPTT2_0(TYPE_INT, TYPE_ADR);
3273 COUNT(count_pcmd_op);
3274 # if SUPPORT_CONST_STORE_ZERO_ONLY
3277 PUSHCONST(TYPE_INT);
3279 # if defined(ENABLE_INTRP)
3282 PUSHCONST(TYPE_INT);
3286 case ICMD_PUTSTATIC:
3288 # if defined(ENABLE_INTRP)
3291 # if SUPPORT_CONST_STORE_ZERO_ONLY
3292 if (iptr[0].val.i == 0) {
3294 switch (iptr[1].opc) {
3295 case ICMD_PUTSTATIC:
3296 iptr[0].opc = ICMD_PUTSTATICCONST;
3300 iptr[0].opc = ICMD_PUTFIELDCONST;
3305 iptr[1].opc = ICMD_NOP;
3306 iptr[0].op1 = TYPE_INT;
3307 COUNT(count_pcmd_op);
3308 # if SUPPORT_CONST_STORE_ZERO_ONLY
3311 PUSHCONST(TYPE_INT);
3313 # if defined(ENABLE_INTRP)
3316 PUSHCONST(TYPE_INT);
3319 #endif /* SUPPORT_CONST_STORE */
3321 PUSHCONST(TYPE_INT);
3325 PUSHCONST(TYPE_INT);
3329 COUNT(count_pcmd_load);
3331 switch (iptr[1].opc) {
3332 #if SUPPORT_LONG_ADD
3334 iptr[0].opc = ICMD_LADDCONST;
3336 iptr[1].opc = ICMD_NOP;
3337 OP1_1(TYPE_LNG,TYPE_LNG);
3338 COUNT(count_pcmd_op);
3341 iptr[0].opc = ICMD_LSUBCONST;
3342 goto icmd_lconst_tail;
3343 #endif /* SUPPORT_LONG_ADD */
3344 #if SUPPORT_LONG_MUL && SUPPORT_CONST_MUL
3346 iptr[0].opc = ICMD_LMULCONST;
3347 goto icmd_lconst_tail;
3348 #else /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
3349 # if SUPPORT_LONG_SHIFT
3351 if (iptr[0].val.l == 0x00000002)
3353 else if (iptr[0].val.l == 0x00000004)
3355 else if (iptr[0].val.l == 0x00000008)
3357 else if (iptr[0].val.l == 0x00000010)
3359 else if (iptr[0].val.l == 0x00000020)
3361 else if (iptr[0].val.l == 0x00000040)
3363 else if (iptr[0].val.l == 0x00000080)
3365 else if (iptr[0].val.l == 0x00000100)
3367 else if (iptr[0].val.l == 0x00000200)
3369 else if (iptr[0].val.l == 0x00000400)
3371 else if (iptr[0].val.l == 0x00000800)
3373 else if (iptr[0].val.l == 0x00001000)
3375 else if (iptr[0].val.l == 0x00002000)
3377 else if (iptr[0].val.l == 0x00004000)
3379 else if (iptr[0].val.l == 0x00008000)
3381 else if (iptr[0].val.l == 0x00010000)
3383 else if (iptr[0].val.l == 0x00020000)
3385 else if (iptr[0].val.l == 0x00040000)
3387 else if (iptr[0].val.l == 0x00080000)
3389 else if (iptr[0].val.l == 0x00100000)
3391 else if (iptr[0].val.l == 0x00200000)
3393 else if (iptr[0].val.l == 0x00400000)
3395 else if (iptr[0].val.l == 0x00800000)
3397 else if (iptr[0].val.l == 0x01000000)
3399 else if (iptr[0].val.l == 0x02000000)
3401 else if (iptr[0].val.l == 0x04000000)
3403 else if (iptr[0].val.l == 0x08000000)
3405 else if (iptr[0].val.l == 0x10000000)
3407 else if (iptr[0].val.l == 0x20000000)
3409 else if (iptr[0].val.l == 0x40000000)
3411 else if (iptr[0].val.l == 0x80000000)
3414 PUSHCONST(TYPE_LNG);
3417 iptr[0].opc = ICMD_LMULPOW2;
3418 goto icmd_lconst_tail;
3419 # endif /* SUPPORT_LONG_SHIFT */
3420 #endif /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
3422 #if SUPPORT_LONG_DIV_POW2
3424 if (iptr[0].val.l == 0x00000002)
3426 else if (iptr[0].val.l == 0x00000004)
3428 else if (iptr[0].val.l == 0x00000008)
3430 else if (iptr[0].val.l == 0x00000010)
3432 else if (iptr[0].val.l == 0x00000020)
3434 else if (iptr[0].val.l == 0x00000040)
3436 else if (iptr[0].val.l == 0x00000080)
3438 else if (iptr[0].val.l == 0x00000100)
3440 else if (iptr[0].val.l == 0x00000200)
3442 else if (iptr[0].val.l == 0x00000400)
3444 else if (iptr[0].val.l == 0x00000800)
3446 else if (iptr[0].val.l == 0x00001000)
3448 else if (iptr[0].val.l == 0x00002000)
3450 else if (iptr[0].val.l == 0x00004000)
3452 else if (iptr[0].val.l == 0x00008000)
3454 else if (iptr[0].val.l == 0x00010000)
3456 else if (iptr[0].val.l == 0x00020000)
3458 else if (iptr[0].val.l == 0x00040000)
3460 else if (iptr[0].val.l == 0x00080000)
3462 else if (iptr[0].val.l == 0x00100000)
3464 else if (iptr[0].val.l == 0x00200000)
3466 else if (iptr[0].val.l == 0x00400000)
3468 else if (iptr[0].val.l == 0x00800000)
3470 else if (iptr[0].val.l == 0x01000000)
3472 else if (iptr[0].val.l == 0x02000000)
3474 else if (iptr[0].val.l == 0x04000000)
3476 else if (iptr[0].val.l == 0x08000000)
3478 else if (iptr[0].val.l == 0x10000000)
3480 else if (iptr[0].val.l == 0x20000000)
3482 else if (iptr[0].val.l == 0x40000000)
3484 else if (iptr[0].val.l == 0x80000000)
3487 PUSHCONST(TYPE_LNG);
3490 iptr[0].opc = ICMD_LDIVPOW2;
3491 goto icmd_lconst_tail;
3492 #endif /* SUPPORT_LONG_DIV_POW2 */
3494 #if SUPPORT_LONG_REM_POW2
3496 if ((iptr[0].val.l == 0x00000002) ||
3497 (iptr[0].val.l == 0x00000004) ||
3498 (iptr[0].val.l == 0x00000008) ||
3499 (iptr[0].val.l == 0x00000010) ||
3500 (iptr[0].val.l == 0x00000020) ||
3501 (iptr[0].val.l == 0x00000040) ||
3502 (iptr[0].val.l == 0x00000080) ||
3503 (iptr[0].val.l == 0x00000100) ||
3504 (iptr[0].val.l == 0x00000200) ||
3505 (iptr[0].val.l == 0x00000400) ||
3506 (iptr[0].val.l == 0x00000800) ||
3507 (iptr[0].val.l == 0x00001000) ||
3508 (iptr[0].val.l == 0x00002000) ||
3509 (iptr[0].val.l == 0x00004000) ||
3510 (iptr[0].val.l == 0x00008000) ||
3511 (iptr[0].val.l == 0x00010000) ||
3512 (iptr[0].val.l == 0x00020000) ||
3513 (iptr[0].val.l == 0x00040000) ||
3514 (iptr[0].val.l == 0x00080000) ||
3515 (iptr[0].val.l == 0x00100000) ||
3516 (iptr[0].val.l == 0x00200000) ||
3517 (iptr[0].val.l == 0x00400000) ||
3518 (iptr[0].val.l == 0x00800000) ||
3519 (iptr[0].val.l == 0x01000000) ||
3520 (iptr[0].val.l == 0x02000000) ||
3521 (iptr[0].val.l == 0x04000000) ||
3522 (iptr[0].val.l == 0x08000000) ||
3523 (iptr[0].val.l == 0x10000000) ||
3524 (iptr[0].val.l == 0x20000000) ||
3525 (iptr[0].val.l == 0x40000000) ||
3526 (iptr[0].val.l == 0x80000000)) {
3527 iptr[0].opc = ICMD_LREMPOW2;
3529 goto icmd_lconst_tail;
3531 PUSHCONST(TYPE_LNG);
3533 #endif /* SUPPORT_LONG_REM_POW2 */
3535 #if SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL
3538 iptr[0].opc = ICMD_LANDCONST;
3539 goto icmd_lconst_tail;
3541 iptr[0].opc = ICMD_LORCONST;
3542 goto icmd_lconst_tail;
3544 iptr[0].opc = ICMD_LXORCONST;
3545 goto icmd_lconst_tail;
3546 #endif /* SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL */
3548 #if SUPPORT_LONG_CMP_CONST
3550 if ((len > 1) && (iptr[2].val.i == 0)) {
3551 switch (iptr[2].opc) {
3553 iptr[0].opc = ICMD_IF_LEQ;
3554 icmd_lconst_lcmp_tail:
3555 iptr[0].op1 = iptr[2].op1;
3556 iptr[1].opc = ICMD_NOP;
3557 iptr[2].opc = ICMD_NOP;
3559 /* bptr->icount -= 2; */
3563 tbptr = m->basicblocks +
3564 m->basicblockindex[iptr[0].op1];
3566 iptr[0].target = (void *) tbptr;
3568 MARKREACHED(tbptr, copy);
3569 COUNT(count_pcmd_bra);
3570 COUNT(count_pcmd_op);
3573 iptr[0].opc = ICMD_IF_LNE;
3574 goto icmd_lconst_lcmp_tail;
3576 iptr[0].opc = ICMD_IF_LLT;
3577 goto icmd_lconst_lcmp_tail;
3579 iptr[0].opc = ICMD_IF_LGT;
3580 goto icmd_lconst_lcmp_tail;
3582 iptr[0].opc = ICMD_IF_LLE;
3583 goto icmd_lconst_lcmp_tail;
3585 iptr[0].opc = ICMD_IF_LGE;
3586 goto icmd_lconst_lcmp_tail;
3588 PUSHCONST(TYPE_LNG);
3589 } /* switch (iptr[2].opc) */
3590 } /* if (iptr[2].val.i == 0) */
3592 PUSHCONST(TYPE_LNG);
3594 #endif /* SUPPORT_LONG_CMP_CONST */
3596 #if SUPPORT_CONST_STORE
3598 # if defined(ENABLE_INTRP)
3601 # if SUPPORT_CONST_STORE_ZERO_ONLY
3602 if (iptr[0].val.l == 0) {
3604 iptr[0].opc = ICMD_LASTORECONST;
3605 iptr[1].opc = ICMD_NOP;
3606 OPTT2_0(TYPE_INT, TYPE_ADR);
3607 COUNT(count_pcmd_op);
3608 # if SUPPORT_CONST_STORE_ZERO_ONLY
3611 PUSHCONST(TYPE_LNG);
3613 # if defined(ENABLE_INTRP)
3616 PUSHCONST(TYPE_LNG);
3620 case ICMD_PUTSTATIC:
3622 # if defined(ENABLE_INTRP)
3625 # if SUPPORT_CONST_STORE_ZERO_ONLY
3626 if (iptr[0].val.l == 0) {
3628 switch (iptr[1].opc) {
3629 case ICMD_PUTSTATIC:
3630 iptr[0].opc = ICMD_PUTSTATICCONST;
3634 iptr[0].opc = ICMD_PUTFIELDCONST;
3639 iptr[1].opc = ICMD_NOP;
3640 iptr[0].op1 = TYPE_LNG;
3641 COUNT(count_pcmd_op);
3642 # if SUPPORT_CONST_STORE_ZERO_ONLY
3645 PUSHCONST(TYPE_LNG);
3647 # if defined(ENABLE_INTRP)
3650 PUSHCONST(TYPE_LNG);
3653 #endif /* SUPPORT_CONST_STORE */
3655 PUSHCONST(TYPE_LNG);
3659 PUSHCONST(TYPE_LNG);
3663 COUNT(count_pcmd_load);
3664 PUSHCONST(TYPE_FLT);
3668 COUNT(count_pcmd_load);
3669 PUSHCONST(TYPE_DBL);
3673 COUNT(count_pcmd_load);
3674 #if SUPPORT_CONST_STORE
3675 # if defined(ENABLE_INTRP)
3678 /* We can only optimize if the ACONST is resolved
3679 * and there is an instruction after it. */
3681 if ((len > 0) && INSTRUCTION_IS_RESOLVED(iptr))
3683 switch (iptr[1].opc) {
3685 /* We can only optimize for NULL values
3686 * here because otherwise a checkcast is
3688 if (iptr->val.a != NULL)
3689 goto aconst_no_transform;
3691 iptr[0].opc = ICMD_AASTORECONST;
3692 OPTT2_0(TYPE_INT, TYPE_ADR);
3694 iptr[1].opc = ICMD_NOP;
3695 COUNT(count_pcmd_op);
3698 case ICMD_PUTSTATIC:
3700 # if SUPPORT_CONST_STORE_ZERO_ONLY
3701 if (iptr->val.a == 0) {
3704 switch (iptr[1].opc) {
3705 case ICMD_PUTSTATIC:
3706 iptr[0].opc = ICMD_PUTSTATICCONST;
3707 iptr[0].op1 = TYPE_ADR;
3711 iptr[0].opc = ICMD_PUTFIELDCONST;
3712 iptr[0].op1 = TYPE_ADR;
3717 iptr[1].opc = ICMD_NOP;
3718 COUNT(count_pcmd_op);
3720 # if SUPPORT_CONST_STORE_ZERO_ONLY
3723 /* no transformation */
3724 PUSHCONST(TYPE_ADR);
3729 aconst_no_transform:
3730 /* no transformation */
3731 PUSHCONST(TYPE_ADR);
3735 /* no transformation */
3736 PUSHCONST(TYPE_ADR);
3738 # if defined(ENABLE_INTRP)
3741 PUSHCONST(TYPE_ADR);
3743 #else /* SUPPORT_CONST_STORE */
3744 PUSHCONST(TYPE_ADR);
3745 #endif /* SUPPORT_CONST_STORE */
3748 /* pop 0 push 1 load */
3755 COUNT(count_load_instruction);
3756 i = opcode - ICMD_ILOAD;
3757 #if defined(ENABLE_INTRP)
3760 rd->locals[iptr->op1][i].type = i;
3761 LOAD(i, LOCALVAR, iptr->op1);
3771 COUNT(count_check_null);
3772 COUNT(count_check_bound);
3773 COUNT(count_pcmd_mem);
3774 OP2IAT_1(opcode - ICMD_IALOAD);
3780 COUNT(count_check_null);
3781 COUNT(count_check_bound);
3782 COUNT(count_pcmd_mem);
3786 /* pop 0 push 0 iinc */
3789 #if defined(ENABLE_STATISTICS)
3793 count_store_depth[10]++;
3795 count_store_depth[i]++;
3798 last_store[5 * iptr->op1 + TYPE_INT] = bptr->icount - len - 1;
3803 if ((copy->varkind == LOCALVAR) &&
3804 (copy->varnum == iptr->op1)) {
3805 copy->varkind = TEMPVAR;
3815 /* pop 1 push 0 store */
3824 i = opcode - ICMD_ISTORE;
3825 #if defined(ENABLE_INTRP)
3828 rd->locals[iptr->op1][i].type = i;
3829 #if defined(ENABLE_STATISTICS)
3834 count_store_length[20]++;
3836 count_store_length[i]++;
3839 count_store_depth[10]++;
3841 count_store_depth[i]++;
3844 /* check for conflicts as described in Figure 5.2 */
3845 copy = curstack->prev;
3848 if ((copy->varkind == LOCALVAR) &&
3849 (copy->varnum == iptr->op1)) {
3850 copy->varkind = TEMPVAR;
3857 /* do not change instack Stackslots */
3858 /* it won't improve performance if we copy the interface */
3859 /* at the BB begin or here, and lsra relies that no */
3860 /* instack stackslot is marked LOCALVAR */
3861 if (curstack->varkind == STACKVAR)
3862 goto _possible_conflict;
3864 /* check for a DUPX,SWAP while the lifetime of curstack */
3865 /* and as creator curstack */
3866 if (last_dupx != -1) {
3867 /* we have to look at the dst stack of DUPX */
3868 /* == src Stack of PEI */
3869 copy = bptr->iinstr[last_dupx].dst;
3872 copy = bptr->instack;
3874 copy = bptr->iinstr[last_pei-1].dst;
3876 if ((copy != NULL) && (curstack <= copy)) {
3877 /* curstack alive at or created by DUPX */
3880 /* now look, if there is a LOCALVAR at anyone of */
3881 /* the src stacklots used by DUPX */
3883 goto _possible_conflict;
3887 /* check for a PEI while the lifetime of curstack */
3888 if (last_pei != -1) {
3889 /* && there are exception handler in this method */
3890 /* when this is checked prevent ARGVAR from */
3891 /* overwriting LOCALVAR!!! */
3893 /* we have to look at the stack _before_ the PEI! */
3894 /* == src Stack of PEI */
3896 copy = bptr->instack;
3898 copy = bptr->iinstr[last_pei-1].dst;
3899 if ((copy != NULL) && (curstack <= copy)) {
3900 /* curstack alive at PEI */
3901 goto _possible_conflict;
3905 /* check if there is a possible conflicting XSTORE */
3906 if (last_store[5 * iptr->op1 + opcode - ICMD_ISTORE] != -1) {
3907 /* we have to look at the stack _before_ the XSTORE! */
3908 /* == src Stack of XSTORE */
3909 if (last_store[5 * iptr->op1 + opcode - ICMD_ISTORE] == 0)
3910 copy = bptr->instack;
3912 copy = bptr->iinstr[last_store[5 * iptr->op1 + opcode - ICMD_ISTORE] - 1].dst;
3913 if ((copy != NULL) && (curstack <= copy)) {
3914 /* curstack alive at Last Store */
3915 goto _possible_conflict;
3919 /* check if there is a conflict with a XLOAD */
3920 /* this is done indirectly by looking if a Stackslot is */
3921 /* marked LOCALVAR and is live while curstack is live */
3922 /* see figure 5.3 */
3924 /* First check "above" stackslots of the instack */
3925 copy = curstack + 1;
3926 for(;(copy <= bptr->instack); copy++)
3927 if ((copy->varkind == LOCALVAR) && (copy->varnum == iptr->op1)) {
3928 goto _possible_conflict;
3931 /* "intra" Basic Block Stackslots are allocated above */
3932 /* bptr->stack (see doc/stack.txt), so if curstack + 1 */
3933 /* is an instack, copy could point now to the stackslots */
3934 /* of an inbetween analysed Basic Block */
3935 if (copy < bptr->stack)
3937 while (copy < new) {
3938 if ((copy->varkind == LOCALVAR) && (copy->varnum == iptr->op1)) {
3939 goto _possible_conflict;
3943 /* If Stackslot is already marked as LOCALVAR, do not */
3944 /* change it! Conflict resolution works only, if xLOAD */
3946 if (curstack->varkind == LOCALVAR)
3947 goto _possible_conflict;
3948 /* no conflict - mark the Stackslot as LOCALVAR */
3949 curstack->varkind = LOCALVAR;
3950 curstack->varnum = iptr->op1;
3954 if ((curstack->varkind == LOCALVAR)
3955 && (curstack->varnum == iptr->op1)) {
3956 curstack->varkind = TEMPVAR;
3957 curstack->varnum = stackdepth-1;
3960 last_store[5 * iptr->op1 + opcode - ICMD_ISTORE] = bptr->icount - len - 1;
3962 STORE(opcode - ICMD_ISTORE);
3968 COUNT(count_check_null);
3969 COUNT(count_check_bound);
3970 COUNT(count_pcmd_mem);
3972 bte = builtintable_get_internal(BUILTIN_canstore);
3975 if (md->memuse > rd->memuse)
3976 rd->memuse = md->memuse;
3977 if (md->argintreguse > rd->argintreguse)
3978 rd->argintreguse = md->argintreguse;
3980 /* make all stack variables saved */
3984 copy->flags |= SAVEDVAR;
3995 COUNT(count_check_null);
3996 COUNT(count_check_bound);
3997 COUNT(count_pcmd_mem);
3998 OP3TIA_0(opcode - ICMD_IASTORE);
4004 COUNT(count_check_null);
4005 COUNT(count_check_bound);
4006 COUNT(count_pcmd_mem);
4013 #ifdef ENABLE_VERIFIER
4016 if (IS_2_WORD_TYPE(curstack->type))
4017 goto throw_stack_category_error;
4028 #if defined(ENABLE_JIT)
4029 # if defined(ENABLE_INTRP)
4032 md_return_alloc(jd, curstack);
4034 COUNT(count_pcmd_return);
4035 OP1_0(opcode - ICMD_IRETURN);
4036 superblockend = true;
4040 COUNT(count_check_null);
4044 superblockend = true;
4047 case ICMD_PUTSTATIC:
4048 COUNT(count_pcmd_mem);
4052 /* pop 1 push 0 branch */
4055 case ICMD_IFNONNULL:
4056 COUNT(count_pcmd_bra);
4058 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
4060 iptr[0].target = (void *) tbptr;
4062 MARKREACHED(tbptr, copy);
4071 COUNT(count_pcmd_bra);
4073 /* iptr->val.i is set implicitly in parse by
4074 clearing the memory or from IF_ICMPxx
4078 /* iptr->val.i = 0; */
4079 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
4081 iptr[0].target = (void *) tbptr;
4083 MARKREACHED(tbptr, copy);
4086 /* pop 0 push 0 branch */
4089 COUNT(count_pcmd_bra);
4090 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
4092 iptr[0].target = (void *) tbptr;
4094 MARKREACHED(tbptr, copy);
4096 superblockend = true;
4099 /* pop 1 push 0 table branch */
4101 case ICMD_TABLESWITCH:
4102 COUNT(count_pcmd_table);
4104 s4ptr = iptr->val.a;
4105 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
4106 MARKREACHED(tbptr, copy);
4107 i = *s4ptr++; /* low */
4108 i = *s4ptr++ - i + 1; /* high */
4110 tptr = DMNEW(void*, i+1);
4111 iptr->target = (void *) tptr;
4113 tptr[0] = (void *) tbptr;
4117 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
4119 tptr[0] = (void *) tbptr;
4122 MARKREACHED(tbptr, copy);
4125 superblockend = true;
4128 /* pop 1 push 0 table branch */
4130 case ICMD_LOOKUPSWITCH:
4131 COUNT(count_pcmd_table);
4133 s4ptr = iptr->val.a;
4134 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
4135 MARKREACHED(tbptr, copy);
4136 i = *s4ptr++; /* count */
4138 tptr = DMNEW(void*, i+1);
4139 iptr->target = (void *) tptr;
4141 tptr[0] = (void *) tbptr;
4145 tbptr = m->basicblocks + m->basicblockindex[s4ptr[1]];
4147 tptr[0] = (void *) tbptr;
4150 MARKREACHED(tbptr, copy);
4154 superblockend = true;
4157 case ICMD_MONITORENTER:
4158 COUNT(count_check_null);
4159 case ICMD_MONITOREXIT:
4163 /* pop 2 push 0 branch */
4165 case ICMD_IF_ICMPEQ:
4166 case ICMD_IF_ICMPNE:
4167 case ICMD_IF_ICMPLT:
4168 case ICMD_IF_ICMPGE:
4169 case ICMD_IF_ICMPGT:
4170 case ICMD_IF_ICMPLE:
4171 COUNT(count_pcmd_bra);
4173 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
4175 iptr[0].target = (void *) tbptr;
4177 MARKREACHED(tbptr, copy);
4180 case ICMD_IF_ACMPEQ:
4181 case ICMD_IF_ACMPNE:
4182 COUNT(count_pcmd_bra);
4184 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
4186 iptr[0].target = (void *) tbptr;
4188 MARKREACHED(tbptr, copy);
4194 COUNT(count_check_null);
4195 COUNT(count_pcmd_mem);
4196 OPTT2_0(iptr->op1,TYPE_ADR);
4201 if (!IS_2_WORD_TYPE(curstack->type)) {
4203 #ifdef ENABLE_VERIFIER
4206 if (IS_2_WORD_TYPE(curstack->prev->type))
4207 goto throw_stack_category_error;
4210 OP1_0ANY; /* second pop */
4213 iptr->opc = ICMD_POP;
4217 /* pop 0 push 1 dup */
4220 #ifdef ENABLE_VERIFIER
4223 if (IS_2_WORD_TYPE(curstack->type))
4224 goto throw_stack_category_error;
4227 last_dupx = bptr->icount - len - 1;
4228 COUNT(count_dup_instruction);
4233 last_dupx = bptr->icount - len - 1;
4235 if (IS_2_WORD_TYPE(curstack->type)) {
4237 iptr->opc = ICMD_DUP;
4242 /* ..., ????, cat1 */
4243 #ifdef ENABLE_VERIFIER
4245 if (IS_2_WORD_TYPE(curstack->prev->type))
4246 goto throw_stack_category_error;
4250 NEWSTACK(copy->prev->type, copy->prev->varkind,
4251 copy->prev->varnum);
4252 NEWSTACK(copy->type, copy->varkind,
4259 /* pop 2 push 3 dup */
4262 #ifdef ENABLE_VERIFIER
4265 if (IS_2_WORD_TYPE(curstack->type) ||
4266 IS_2_WORD_TYPE(curstack->prev->type))
4267 goto throw_stack_category_error;
4270 last_dupx = bptr->icount - len - 1;
4275 last_dupx = bptr->icount - len - 1;
4277 if (IS_2_WORD_TYPE(curstack->type)) {
4278 /* ..., ????, cat2 */
4279 #ifdef ENABLE_VERIFIER
4281 if (IS_2_WORD_TYPE(curstack->prev->type))
4282 goto throw_stack_category_error;
4285 iptr->opc = ICMD_DUP_X1;
4289 /* ..., ????, cat1 */
4290 #ifdef ENABLE_VERIFIER
4293 if (IS_2_WORD_TYPE(curstack->prev->type)
4294 || IS_2_WORD_TYPE(curstack->prev->prev->type))
4295 goto throw_stack_category_error;
4302 /* pop 3 push 4 dup */
4305 last_dupx = bptr->icount - len - 1;
4307 if (IS_2_WORD_TYPE(curstack->prev->type)) {
4308 /* ..., cat2, ???? */
4309 #ifdef ENABLE_VERIFIER
4311 if (IS_2_WORD_TYPE(curstack->type))
4312 goto throw_stack_category_error;
4315 iptr->opc = ICMD_DUP_X1;
4319 /* ..., cat1, ???? */
4320 #ifdef ENABLE_VERIFIER
4323 if (IS_2_WORD_TYPE(curstack->type)
4324 || IS_2_WORD_TYPE(curstack->prev->prev->type))
4325 goto throw_stack_category_error;
4333 last_dupx = bptr->icount - len - 1;
4335 if (IS_2_WORD_TYPE(curstack->type)) {
4336 /* ..., ????, cat2 */
4337 if (IS_2_WORD_TYPE(curstack->prev->type)) {
4338 /* ..., cat2, cat2 */
4339 iptr->opc = ICMD_DUP_X1;
4343 /* ..., cat1, cat2 */
4344 #ifdef ENABLE_VERIFIER
4347 if (IS_2_WORD_TYPE(curstack->prev->prev->type))
4348 goto throw_stack_category_error;
4351 iptr->opc = ICMD_DUP_X2;
4357 /* ..., ????, ????, cat1 */
4358 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
4359 /* ..., cat2, ????, cat1 */
4360 #ifdef ENABLE_VERIFIER
4362 if (IS_2_WORD_TYPE(curstack->prev->type))
4363 goto throw_stack_category_error;
4366 iptr->opc = ICMD_DUP2_X1;
4370 /* ..., cat1, ????, cat1 */
4371 #ifdef ENABLE_VERIFIER
4374 if (IS_2_WORD_TYPE(curstack->prev->type)
4375 || IS_2_WORD_TYPE(curstack->prev->prev->prev->type))
4376 goto throw_stack_category_error;
4384 /* pop 2 push 2 swap */
4387 last_dupx = bptr->icount - len - 1;
4388 #ifdef ENABLE_VERIFIER
4391 if (IS_2_WORD_TYPE(curstack->type)
4392 || IS_2_WORD_TYPE(curstack->prev->type))
4393 goto throw_stack_category_error;
4403 #if !SUPPORT_DIVISION
4404 bte = (builtintable_entry *) iptr->val.a;
4408 if (md->memuse > rd->memuse)
4409 rd->memuse = md->memuse;
4410 if (md->argintreguse > rd->argintreguse)
4411 rd->argintreguse = md->argintreguse;
4413 /* make all stack variables saved */
4417 copy->flags |= SAVEDVAR;
4422 #endif /* !SUPPORT_DIVISION */
4433 COUNT(count_pcmd_op);
4439 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
4440 bte = (builtintable_entry *) iptr->val.a;
4444 if (md->memuse > rd->memuse)
4445 rd->memuse = md->memuse;
4446 if (md->argintreguse > rd->argintreguse)
4447 rd->argintreguse = md->argintreguse;
4449 /* make all stack variables saved */
4453 copy->flags |= SAVEDVAR;
4458 #endif /* !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV) */
4463 #if SUPPORT_LONG_LOGICAL
4467 #endif /* SUPPORT_LONG_LOGICAL */
4468 COUNT(count_pcmd_op);
4475 COUNT(count_pcmd_op);
4484 COUNT(count_pcmd_op);
4493 COUNT(count_pcmd_op);
4498 COUNT(count_pcmd_op);
4499 #if SUPPORT_LONG_CMP_CONST
4500 if ((len > 0) && (iptr[1].val.i == 0)) {
4501 switch (iptr[1].opc) {
4503 iptr[0].opc = ICMD_IF_LCMPEQ;
4505 iptr[0].op1 = iptr[1].op1;
4506 iptr[1].opc = ICMD_NOP;
4508 /* bptr->icount--; */
4511 tbptr = m->basicblocks +
4512 m->basicblockindex[iptr[0].op1];
4514 iptr[0].target = (void *) tbptr;
4516 MARKREACHED(tbptr, copy);
4517 COUNT(count_pcmd_bra);
4520 iptr[0].opc = ICMD_IF_LCMPNE;
4521 goto icmd_lcmp_if_tail;
4523 iptr[0].opc = ICMD_IF_LCMPLT;
4524 goto icmd_lcmp_if_tail;
4526 iptr[0].opc = ICMD_IF_LCMPGT;
4527 goto icmd_lcmp_if_tail;
4529 iptr[0].opc = ICMD_IF_LCMPLE;
4530 goto icmd_lcmp_if_tail;
4532 iptr[0].opc = ICMD_IF_LCMPGE;
4533 goto icmd_lcmp_if_tail;
4535 OPTT2_1(TYPE_LNG, TYPE_INT);
4539 #endif /* SUPPORT_LONG_CMP_CONST */
4540 OPTT2_1(TYPE_LNG, TYPE_INT);
4545 COUNT(count_pcmd_op);
4546 if ((len > 0) && (iptr[1].val.i == 0)) {
4547 switch (iptr[1].opc) {
4549 iptr[0].opc = ICMD_IF_FCMPEQ;
4551 iptr[0].op1 = iptr[1].op1;
4552 iptr[1].opc = ICMD_NOP;
4555 tbptr = m->basicblocks +
4556 m->basicblockindex[iptr[0].op1];
4558 iptr[0].target = (void *) tbptr;
4560 MARKREACHED(tbptr, copy);
4561 COUNT(count_pcmd_bra);
4564 iptr[0].opc = ICMD_IF_FCMPNE;
4565 goto icmd_if_fcmpl_tail;
4567 iptr[0].opc = ICMD_IF_FCMPL_LT;
4568 goto icmd_if_fcmpl_tail;
4570 iptr[0].opc = ICMD_IF_FCMPL_GT;
4571 goto icmd_if_fcmpl_tail;
4573 iptr[0].opc = ICMD_IF_FCMPL_LE;
4574 goto icmd_if_fcmpl_tail;
4576 iptr[0].opc = ICMD_IF_FCMPL_GE;
4577 goto icmd_if_fcmpl_tail;
4579 OPTT2_1(TYPE_FLT, TYPE_INT);
4583 OPTT2_1(TYPE_FLT, TYPE_INT);
4587 COUNT(count_pcmd_op);
4588 if ((len > 0) && (iptr[1].val.i == 0)) {
4589 switch (iptr[1].opc) {
4591 iptr[0].opc = ICMD_IF_FCMPEQ;
4593 iptr[0].op1 = iptr[1].op1;
4594 iptr[1].opc = ICMD_NOP;
4597 tbptr = m->basicblocks +
4598 m->basicblockindex[iptr[0].op1];
4600 iptr[0].target = (void *) tbptr;
4602 MARKREACHED(tbptr, copy);
4603 COUNT(count_pcmd_bra);
4606 iptr[0].opc = ICMD_IF_FCMPNE;
4607 goto icmd_if_fcmpg_tail;
4609 iptr[0].opc = ICMD_IF_FCMPG_LT;
4610 goto icmd_if_fcmpg_tail;
4612 iptr[0].opc = ICMD_IF_FCMPG_GT;
4613 goto icmd_if_fcmpg_tail;
4615 iptr[0].opc = ICMD_IF_FCMPG_LE;
4616 goto icmd_if_fcmpg_tail;
4618 iptr[0].opc = ICMD_IF_FCMPG_GE;
4619 goto icmd_if_fcmpg_tail;
4621 OPTT2_1(TYPE_FLT, TYPE_INT);
4625 OPTT2_1(TYPE_FLT, TYPE_INT);
4629 COUNT(count_pcmd_op);
4630 if ((len > 0) && (iptr[1].val.i == 0)) {
4631 switch (iptr[1].opc) {
4633 iptr[0].opc = ICMD_IF_DCMPEQ;
4635 iptr[0].op1 = iptr[1].op1;
4636 iptr[1].opc = ICMD_NOP;
4639 tbptr = m->basicblocks +
4640 m->basicblockindex[iptr[0].op1];
4642 iptr[0].target = (void *) tbptr;
4644 MARKREACHED(tbptr, copy);
4645 COUNT(count_pcmd_bra);
4648 iptr[0].opc = ICMD_IF_DCMPNE;
4649 goto icmd_if_dcmpl_tail;
4651 iptr[0].opc = ICMD_IF_DCMPL_LT;
4652 goto icmd_if_dcmpl_tail;
4654 iptr[0].opc = ICMD_IF_DCMPL_GT;
4655 goto icmd_if_dcmpl_tail;
4657 iptr[0].opc = ICMD_IF_DCMPL_LE;
4658 goto icmd_if_dcmpl_tail;
4660 iptr[0].opc = ICMD_IF_DCMPL_GE;
4661 goto icmd_if_dcmpl_tail;
4663 OPTT2_1(TYPE_DBL, TYPE_INT);
4667 OPTT2_1(TYPE_DBL, TYPE_INT);
4671 COUNT(count_pcmd_op);
4672 if ((len > 0) && (iptr[1].val.i == 0)) {
4673 switch (iptr[1].opc) {
4675 iptr[0].opc = ICMD_IF_DCMPEQ;
4677 iptr[0].op1 = iptr[1].op1;
4678 iptr[1].opc = ICMD_NOP;
4681 tbptr = m->basicblocks +
4682 m->basicblockindex[iptr[0].op1];
4684 iptr[0].target = (void *) tbptr;
4686 MARKREACHED(tbptr, copy);
4687 COUNT(count_pcmd_bra);
4690 iptr[0].opc = ICMD_IF_DCMPNE;
4691 goto icmd_if_dcmpg_tail;
4693 iptr[0].opc = ICMD_IF_DCMPG_LT;
4694 goto icmd_if_dcmpg_tail;
4696 iptr[0].opc = ICMD_IF_DCMPG_GT;
4697 goto icmd_if_dcmpg_tail;
4699 iptr[0].opc = ICMD_IF_DCMPG_LE;
4700 goto icmd_if_dcmpg_tail;
4702 iptr[0].opc = ICMD_IF_DCMPG_GE;
4703 goto icmd_if_dcmpg_tail;
4705 OPTT2_1(TYPE_DBL, TYPE_INT);
4709 OPTT2_1(TYPE_DBL, TYPE_INT);
4714 COUNT(count_pcmd_op);
4715 OPTT2_1(TYPE_FLT, TYPE_INT);
4720 COUNT(count_pcmd_op);
4721 OPTT2_1(TYPE_DBL, TYPE_INT);
4730 case ICMD_INT2SHORT:
4731 COUNT(count_pcmd_op);
4732 OP1_1(TYPE_INT, TYPE_INT);
4735 COUNT(count_pcmd_op);
4736 OP1_1(TYPE_LNG, TYPE_LNG);
4739 COUNT(count_pcmd_op);
4740 OP1_1(TYPE_FLT, TYPE_FLT);
4743 COUNT(count_pcmd_op);
4744 OP1_1(TYPE_DBL, TYPE_DBL);
4748 COUNT(count_pcmd_op);
4749 OP1_1(TYPE_INT, TYPE_LNG);
4752 COUNT(count_pcmd_op);
4753 OP1_1(TYPE_INT, TYPE_FLT);
4756 COUNT(count_pcmd_op);
4757 OP1_1(TYPE_INT, TYPE_DBL);
4760 COUNT(count_pcmd_op);
4761 OP1_1(TYPE_LNG, TYPE_INT);
4764 COUNT(count_pcmd_op);
4765 OP1_1(TYPE_LNG, TYPE_FLT);
4768 COUNT(count_pcmd_op);
4769 OP1_1(TYPE_LNG, TYPE_DBL);
4772 COUNT(count_pcmd_op);
4773 OP1_1(TYPE_FLT, TYPE_INT);
4776 COUNT(count_pcmd_op);
4777 OP1_1(TYPE_FLT, TYPE_LNG);
4780 COUNT(count_pcmd_op);
4781 OP1_1(TYPE_FLT, TYPE_DBL);
4784 COUNT(count_pcmd_op);
4785 OP1_1(TYPE_DBL, TYPE_INT);
4788 COUNT(count_pcmd_op);
4789 OP1_1(TYPE_DBL, TYPE_LNG);
4792 COUNT(count_pcmd_op);
4793 OP1_1(TYPE_DBL, TYPE_FLT);
4796 case ICMD_CHECKCAST:
4797 if (iptr->op1 == 0) {
4798 /* array type cast-check */
4800 bte = builtintable_get_internal(BUILTIN_arraycheckcast);
4803 if (md->memuse > rd->memuse)
4804 rd->memuse = md->memuse;
4805 if (md->argintreguse > rd->argintreguse)
4806 rd->argintreguse = md->argintreguse;
4808 /* make all stack variables saved */
4812 copy->flags |= SAVEDVAR;
4816 OP1_1(TYPE_ADR, TYPE_ADR);
4819 case ICMD_INSTANCEOF:
4820 case ICMD_ARRAYLENGTH:
4821 OP1_1(TYPE_ADR, TYPE_INT);
4825 case ICMD_ANEWARRAY:
4826 OP1_1(TYPE_INT, TYPE_ADR);
4830 COUNT(count_check_null);
4831 COUNT(count_pcmd_mem);
4832 OP1_1(TYPE_ADR, iptr->op1);
4837 case ICMD_GETSTATIC:
4838 COUNT(count_pcmd_mem);
4848 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
4850 iptr[0].target = (void *) tbptr;
4852 /* This is a dirty hack. The typechecker
4853 * needs it because the OP1_0ANY below
4854 * overwrites iptr->dst.
4856 iptr->val.a = (void *) iptr->dst;
4858 tbptr->type = BBTYPE_SBR;
4860 /* We need to check for overflow right here because
4861 * the pushed value is poped after MARKREACHED. */
4863 MARKREACHED(tbptr, copy);
4867 /* pop many push any */
4870 #if defined(USEBUILTINTABLE)
4873 bte = (builtintable_entry *) iptr->val.a;
4877 case ICMD_INVOKESTATIC:
4878 case ICMD_INVOKESPECIAL:
4879 case ICMD_INVOKEVIRTUAL:
4880 case ICMD_INVOKEINTERFACE:
4881 COUNT(count_pcmd_met);
4882 INSTRUCTION_GET_METHODDESC(iptr,md);
4883 /* if (lm->flags & ACC_STATIC) */
4884 /* {COUNT(count_check_null);} */
4888 last_pei = bptr->icount - len - 1;
4892 if (md->memuse > rd->memuse)
4893 rd->memuse = md->memuse;
4894 if (md->argintreguse > rd->argintreguse)
4895 rd->argintreguse = md->argintreguse;
4896 if (md->argfltreguse > rd->argfltreguse)
4897 rd->argfltreguse = md->argfltreguse;
4902 for (i-- ; i >= 0; i--) {
4903 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
4904 /* If we pass float arguments in integer argument registers, we
4905 * are not allowed to precolor them here. Floats have to be moved
4906 * to this regs explicitly in codegen().
4907 * Only arguments that are passed by stack anyway can be precolored
4908 * (michi 2005/07/24) */
4909 if (!(copy->flags & SAVEDVAR) &&
4910 (!IS_FLT_DBL_TYPE(copy->type) || md->params[i].inmemory)) {
4912 if (!(copy->flags & SAVEDVAR)) {
4914 copy->varkind = ARGVAR;
4917 #if defined(ENABLE_INTRP)
4920 if (md->params[i].inmemory) {
4921 copy->flags = INMEMORY;
4922 copy->regoff = md->params[i].regoff;
4926 if (IS_FLT_DBL_TYPE(copy->type))
4927 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
4928 assert(0); /* XXX is this assert ok? */
4931 rd->argfltregs[md->params[i].regoff];
4934 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
4935 if (IS_2_WORD_TYPE(copy->type))
4936 copy->regoff = PACK_REGS(
4937 rd->argintregs[GET_LOW_REG(md->params[i].regoff)],
4938 rd->argintregs[GET_HIGH_REG(md->params[i].regoff)]);
4942 rd->argintregs[md->params[i].regoff];
4945 #if defined(ENABLE_INTRP)
4953 copy->flags |= SAVEDVAR;
4959 if (md->returntype.type != TYPE_VOID)
4960 OP0_1(md->returntype.type);
4963 case ICMD_INLINE_START:
4964 case ICMD_INLINE_END:
4968 case ICMD_MULTIANEWARRAY:
4969 if (rd->argintreguse < 3)
4970 rd->argintreguse = 3;
4975 #if defined(SPECIALMEMUSE)
4976 # if defined(__DARWIN__)
4977 if (rd->memuse < (i + INT_ARG_CNT + LA_WORD_SIZE))
4978 rd->memuse = i + LA_WORD_SIZE + INT_ARG_CNT;
4980 if (rd->memuse < (i + LA_WORD_SIZE + 3))
4981 rd->memuse = i + LA_WORD_SIZE + 3;
4984 # if defined(__I386__)
4985 if (rd->memuse < i + 3)
4986 rd->memuse = i + 3; /* n integer args spilled on stack */
4987 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
4988 if (rd->memuse < i + 2)
4989 rd->memuse = i + 2; /* 4*4 bytes callee save space */
4992 rd->memuse = i; /* n integer args spilled on stack */
4993 # endif /* defined(__I386__) */
4997 /* check INT type here? Currently typecheck does this. */
4998 if (!(copy->flags & SAVEDVAR)) {
4999 copy->varkind = ARGVAR;
5000 copy->varnum = i + INT_ARG_CNT;
5001 copy->flags |= INMEMORY;
5002 #if defined(SPECIALMEMUSE)
5003 # if defined(__DARWIN__)
5004 copy->regoff = i + LA_WORD_SIZE + INT_ARG_CNT;
5006 copy->regoff = i + LA_WORD_SIZE + 3;
5009 # if defined(__I386__)
5010 copy->regoff = i + 3;
5011 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
5012 copy->regoff = i + 2;
5015 # endif /* defined(__I386__) */
5016 #endif /* defined(SPECIALMEMUSE) */
5021 copy->flags |= SAVEDVAR;
5031 new_internalerror("Unknown ICMD %d", opcode);
5037 } /* while instructions */
5039 /* set out-stack of block */
5041 bptr->outstack = curstack;
5042 bptr->outdepth = stackdepth;
5044 /* stack slots at basic block end become interfaces */
5047 for (copy = curstack; copy; i--, copy = copy->prev) {
5048 if ((copy->varkind == STACKVAR) && (copy->varnum > i))
5049 copy->varkind = TEMPVAR;
5051 copy->varkind = STACKVAR;
5055 rd->interfaces[i][copy->type].type = copy->type;
5056 rd->interfaces[i][copy->type].flags |= copy->flags;
5060 /* check if interface slots at basic block begin must be saved */
5063 i = bptr->indepth - 1;
5064 for (copy = bptr->instack; copy; i--, copy = copy->prev) {
5065 rd->interfaces[i][copy->type].type = copy->type;
5066 if (copy->varkind == STACKVAR) {
5067 if (copy->flags & SAVEDVAR)
5068 rd->interfaces[i][copy->type].flags |= SAVEDVAR;
5075 superblockend = true;
5078 } /* while blocks */
5079 } while (repeat && !deadcode);
5081 #if defined(ENABLE_STATISTICS)
5083 if (m->basicblockcount > count_max_basic_blocks)
5084 count_max_basic_blocks = m->basicblockcount;
5085 count_basic_blocks += m->basicblockcount;
5086 if (m->instructioncount > count_max_javainstr) count_max_javainstr = m->instructioncount;
5087 count_javainstr += m->instructioncount;
5088 if (m->stackcount > count_upper_bound_new_stack)
5089 count_upper_bound_new_stack = m->stackcount;
5090 if ((new - m->stack) > count_max_new_stack)
5091 count_max_new_stack = (new - m->stack);
5093 b_count = m->basicblockcount;
5094 bptr = m->basicblocks;
5095 while (--b_count >= 0) {
5096 if (bptr->flags > BBREACHED) {
5097 if (bptr->indepth >= 10)
5098 count_block_stack[10]++;
5100 count_block_stack[bptr->indepth]++;
5103 count_block_size_distribution[len]++;
5105 count_block_size_distribution[10]++;
5107 count_block_size_distribution[11]++;
5109 count_block_size_distribution[12]++;
5111 count_block_size_distribution[13]++;
5113 count_block_size_distribution[14]++;
5115 count_block_size_distribution[15]++;
5117 count_block_size_distribution[16]++;
5119 count_block_size_distribution[17]++;
5125 count_analyse_iterations[0]++;
5126 else if (loops == 2)
5127 count_analyse_iterations[1]++;
5128 else if (loops == 3)
5129 count_analyse_iterations[2]++;
5130 else if (loops == 4)
5131 count_analyse_iterations[3]++;
5133 count_analyse_iterations[4]++;
5135 if (m->basicblockcount <= 5)
5136 count_method_bb_distribution[0]++;
5137 else if (m->basicblockcount <= 10)
5138 count_method_bb_distribution[1]++;
5139 else if (m->basicblockcount <= 15)
5140 count_method_bb_distribution[2]++;
5141 else if (m->basicblockcount <= 20)
5142 count_method_bb_distribution[3]++;
5143 else if (m->basicblockcount <= 30)
5144 count_method_bb_distribution[4]++;
5145 else if (m->basicblockcount <= 40)
5146 count_method_bb_distribution[5]++;
5147 else if (m->basicblockcount <= 50)
5148 count_method_bb_distribution[6]++;
5149 else if (m->basicblockcount <= 75)
5150 count_method_bb_distribution[7]++;
5152 count_method_bb_distribution[8]++;
5154 #endif /* defined(ENABLE_STATISTICS) */
5156 /* everything's ok */
5160 #if defined(ENABLE_VERIFIER)
5162 throw_stack_underflow:
5163 exceptions_throw_verifyerror(m, "Unable to pop operand off an empty stack");
5166 throw_stack_overflow:
5167 exceptions_throw_verifyerror(m, "Stack size too large");
5170 throw_stack_depth_error:
5171 exceptions_throw_verifyerror(m,"Stack depth mismatch");
5174 throw_stack_type_error:
5175 exceptions_throw_verifyerror_for_stack(m, expectedtype);
5178 throw_stack_category_error:
5179 exceptions_throw_verifyerror(m, "Attempt to split long or double on the stack");
5188 * These are local overrides for various environment variables in Emacs.
5189 * Please do not remove this and leave it at the end of the file, where
5190 * Emacs will automagically detect them.
5191 * ---------------------------------------------------------------------
5194 * indent-tabs-mode: t
5198 * vim:noexpandtab:sw=4:ts=4: