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 5244 2006-08-16 12:21:35Z christian $
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->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 /* XXX not for ICMD_BUILTIN */
2515 iptr->s1.argcount = stackdepth;
2516 iptr->sx.s23.s2.args = DMNEW(stackptr, stackdepth);
2519 for (i-- ; i >= 0; i--) {
2520 iptr->sx.s23.s2.args[i] = copy;
2522 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2523 /* If we pass float arguments in integer argument registers, we
2524 * are not allowed to precolor them here. Floats have to be moved
2525 * to this regs explicitly in codegen().
2526 * Only arguments that are passed by stack anyway can be precolored
2527 * (michi 2005/07/24) */
2528 if (!(copy->flags & SAVEDVAR) &&
2529 (!IS_FLT_DBL_TYPE(copy->type) || md->params[i].inmemory)) {
2531 if (!(copy->flags & SAVEDVAR)) {
2533 copy->varkind = ARGVAR;
2536 #if defined(ENABLE_INTRP)
2539 if (md->params[i].inmemory) {
2540 copy->flags = INMEMORY;
2541 copy->regoff = md->params[i].regoff;
2545 if (IS_FLT_DBL_TYPE(copy->type)) {
2546 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2547 assert(0); /* XXX is this assert ok? */
2550 rd->argfltregs[md->params[i].regoff];
2551 #endif /* SUPPORT_PASS_FLOATARGS_IN_INTREGS */
2554 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
2555 if (IS_2_WORD_TYPE(copy->type))
2556 copy->regoff = PACK_REGS(
2557 rd->argintregs[GET_LOW_REG(md->params[i].regoff)],
2558 rd->argintregs[GET_HIGH_REG(md->params[i].regoff)]);
2560 #endif /* SUPPORT_COMBINE_INTEGER_REGISTERS */
2562 rd->argintregs[md->params[i].regoff];
2565 #if defined(ENABLE_INTRP)
2566 } /* end if (!opt_intrp) */
2572 /* deal with live-through stack slots "under" the arguments */
2573 /* XXX not for ICMD_BUILTIN */
2578 iptr->sx.s23.s2.args[i++] = copy;
2579 copy->flags |= SAVEDVAR;
2583 /* pop the arguments */
2592 /* push the return value */
2594 if (md->returntype.type != TYPE_VOID) {
2595 NEW_DST(md->returntype.type, stackdepth);
2600 case ICMD_INLINE_START:
2601 case ICMD_INLINE_END:
2606 case ICMD_MULTIANEWARRAY:
2607 if (rd->argintreguse < 3)
2608 rd->argintreguse = 3;
2610 i = iptr->s1.argcount;
2614 iptr->sx.s23.s2.args = DMNEW(stackptr, i);
2616 #if defined(SPECIALMEMUSE)
2617 # if defined(__DARWIN__)
2618 if (rd->memuse < (i + INT_ARG_CNT + LA_SIZE_IN_POINTERS))
2619 rd->memuse = i + LA_SIZE_IN_POINTERS + INT_ARG_CNT;
2621 if (rd->memuse < (i + LA_SIZE_IN_POINTERS + 3))
2622 rd->memuse = i + LA_SIZE_IN_POINTERS + 3;
2625 # if defined(__I386__)
2626 if (rd->memuse < i + 3)
2627 rd->memuse = i + 3; /* n integer args spilled on stack */
2628 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
2629 if (rd->memuse < i + 2)
2630 rd->memuse = i + 2; /* 4*4 bytes callee save space */
2633 rd->memuse = i; /* n integer args spilled on stack */
2634 # endif /* defined(__I386__) */
2638 /* check INT type here? Currently typecheck does this. */
2639 iptr->sx.s23.s2.args[i] = copy;
2640 if (!(copy->flags & SAVEDVAR)) {
2641 copy->varkind = ARGVAR;
2642 copy->varnum = i + INT_ARG_CNT;
2643 copy->flags |= INMEMORY;
2644 #if defined(SPECIALMEMUSE)
2645 # if defined(__DARWIN__)
2646 copy->regoff = i + LA_SIZE_IN_POINTERS + INT_ARG_CNT;
2648 copy->regoff = i + LA_SIZE_IN_POINTERS + 3;
2651 # if defined(__I386__)
2652 copy->regoff = i + 3;
2653 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
2654 copy->regoff = i + 2;
2657 # endif /* defined(__I386__) */
2658 #endif /* defined(SPECIALMEMUSE) */
2663 copy->flags |= SAVEDVAR;
2667 i = iptr->s1.argcount;
2672 NEW_DST(TYPE_ADR, stackdepth);
2678 new_internalerror("Unknown ICMD %d", opcode);
2684 } /* while instructions */
2686 /* set out-stack of block */
2688 bptr->outstack = curstack;
2689 bptr->outdepth = stackdepth;
2691 /* stack slots at basic block end become interfaces */
2694 for (copy = curstack; copy; i--, copy = copy->prev) {
2695 if ((copy->varkind == STACKVAR) && (copy->varnum > i))
2696 copy->varkind = TEMPVAR;
2698 copy->varkind = STACKVAR;
2702 rd->interfaces[i][copy->type].type = copy->type;
2703 rd->interfaces[i][copy->type].flags |= copy->flags;
2707 /* check if interface slots at basic block begin must be saved */
2710 i = bptr->indepth - 1;
2711 for (copy = bptr->instack; copy; i--, copy = copy->prev) {
2712 rd->interfaces[i][copy->type].type = copy->type;
2713 if (copy->varkind == STACKVAR) {
2714 if (copy->flags & SAVEDVAR)
2715 rd->interfaces[i][copy->type].flags |= SAVEDVAR;
2722 superblockend = true;
2725 } /* while blocks */
2726 } while (repeat && !deadcode);
2728 /* gather statistics *****************************************************/
2730 #if defined(ENABLE_STATISTICS)
2732 if (jd->new_basicblockcount > count_max_basic_blocks)
2733 count_max_basic_blocks = jd->new_basicblockcount;
2734 count_basic_blocks += jd->new_basicblockcount;
2735 if (jd->new_instructioncount > count_max_javainstr)
2736 count_max_javainstr = jd->new_instructioncount;
2737 count_javainstr += jd->new_instructioncount;
2738 if (jd->new_stackcount > count_upper_bound_new_stack)
2739 count_upper_bound_new_stack = jd->new_stackcount;
2740 if ((new - jd->new_stack) > count_max_new_stack)
2741 count_max_new_stack = (new - jd->new_stack);
2743 b_count = jd->new_basicblockcount;
2744 bptr = jd->new_basicblocks;
2745 while (--b_count >= 0) {
2746 if (bptr->flags > BBREACHED) {
2747 if (bptr->indepth >= 10)
2748 count_block_stack[10]++;
2750 count_block_stack[bptr->indepth]++;
2753 count_block_size_distribution[len]++;
2755 count_block_size_distribution[10]++;
2757 count_block_size_distribution[11]++;
2759 count_block_size_distribution[12]++;
2761 count_block_size_distribution[13]++;
2763 count_block_size_distribution[14]++;
2765 count_block_size_distribution[15]++;
2767 count_block_size_distribution[16]++;
2769 count_block_size_distribution[17]++;
2774 if (iteration_count == 1)
2775 count_analyse_iterations[0]++;
2776 else if (iteration_count == 2)
2777 count_analyse_iterations[1]++;
2778 else if (iteration_count == 3)
2779 count_analyse_iterations[2]++;
2780 else if (iteration_count == 4)
2781 count_analyse_iterations[3]++;
2783 count_analyse_iterations[4]++;
2785 if (jd->new_basicblockcount <= 5)
2786 count_method_bb_distribution[0]++;
2787 else if (jd->new_basicblockcount <= 10)
2788 count_method_bb_distribution[1]++;
2789 else if (jd->new_basicblockcount <= 15)
2790 count_method_bb_distribution[2]++;
2791 else if (jd->new_basicblockcount <= 20)
2792 count_method_bb_distribution[3]++;
2793 else if (jd->new_basicblockcount <= 30)
2794 count_method_bb_distribution[4]++;
2795 else if (jd->new_basicblockcount <= 40)
2796 count_method_bb_distribution[5]++;
2797 else if (jd->new_basicblockcount <= 50)
2798 count_method_bb_distribution[6]++;
2799 else if (jd->new_basicblockcount <= 75)
2800 count_method_bb_distribution[7]++;
2802 count_method_bb_distribution[8]++;
2804 #endif /* defined(ENABLE_STATISTICS) */
2806 /* everything's ok *******************************************************/
2810 /* goto labels for throwing verifier exceptions **************************/
2812 #if defined(ENABLE_VERIFIER)
2814 throw_stack_underflow:
2815 exceptions_throw_verifyerror(m, "Unable to pop operand off an empty stack");
2818 throw_stack_overflow:
2819 exceptions_throw_verifyerror(m, "Stack size too large");
2822 throw_stack_depth_error:
2823 exceptions_throw_verifyerror(m,"Stack depth mismatch");
2826 throw_stack_type_error:
2827 exceptions_throw_verifyerror_for_stack(m, expectedtype);
2830 throw_stack_category_error:
2831 exceptions_throw_verifyerror(m, "Attempt to split long or double on the stack");
2837 bool stack_analyse(jitdata *jd)
2849 int opcode, i, j, len, loops;
2850 int superblockend, repeat, deadcode;
2856 s4 *last_store;/* instruction index of last XSTORE */
2857 /* [ local_index * 5 + type ] */
2858 s4 last_pei; /* instruction index of last possible exception */
2859 /* used for conflict resolution for copy */
2860 /* elimination (XLOAD, IINC, XSTORE) */
2862 #if defined(ENABLE_VERIFIER)
2863 int expectedtype; /* used by CHECK_BASIC_TYPE */
2866 builtintable_entry *bte;
2869 /* get required compiler data */
2876 last_store = DMNEW(s4 , cd->maxlocals * 5);
2880 m->basicblocks[0].flags = BBREACHED;
2881 m->basicblocks[0].instack = 0;
2882 m->basicblocks[0].indepth = 0;
2884 for (i = 0; i < cd->exceptiontablelength; i++) {
2885 bptr = &m->basicblocks[m->basicblockindex[cd->exceptiontable[i].handlerpc]];
2886 bptr->flags = BBREACHED;
2887 bptr->type = BBTYPE_EXH;
2888 bptr->instack = new;
2890 bptr->predecessorcount = CFG_UNKNOWN_PREDECESSORS;
2897 b_count = m->basicblockcount;
2898 bptr = m->basicblocks;
2899 superblockend = true;
2904 while (--b_count >= 0) {
2905 if (bptr->flags == BBDELETED) {
2908 else if (superblockend && (bptr->flags < BBREACHED)) {
2911 else if (bptr->flags <= BBREACHED) {
2912 if (superblockend) {
2913 stackdepth = bptr->indepth;
2915 else if (bptr->flags < BBREACHED) {
2917 bptr->instack = copy;
2918 bptr->indepth = stackdepth;
2921 CHECK_STACK_DEPTH(bptr->indepth, stackdepth);
2924 curstack = bptr->instack;
2926 superblockend = false;
2927 bptr->flags = BBFINISHED;
2929 iptr = bptr->iinstr;
2930 b_index = bptr - m->basicblocks;
2934 for( i = 0; i < cd->maxlocals; i++)
2935 for( j = 0; j < 5; j++)
2936 last_store[5 * i + j] = -1;
2940 while (--len >= 0) {
2943 /* check if ICMD opcode could throw an exception */
2944 /* and if so remember the instruction index in last_pei */
2946 if (op_data[opcode][PEI])
2947 last_pei = bptr->icount - len - 1;
2949 #if defined(USEBUILTINTABLE)
2950 # if defined(ENABLE_INTRP)
2953 bte = builtintable_get_automatic(opcode);
2955 if (bte && bte->opcode == opcode) {
2956 iptr->opc = ICMD_BUILTIN;
2957 iptr->op1 = false; /* don't check for exception */
2959 jd->isleafmethod = false;
2962 # if defined(ENABLE_INTRP)
2965 #endif /* defined(USEBUILTINTABLE) */
2967 /* this is the main switch */
2973 case ICMD_CHECKNULL:
2974 COUNT(count_check_null);
2980 #if defined(ENABLE_INTRP)
2983 rd->locals[iptr->op1][TYPE_ADR].type = TYPE_ADR;
2985 COUNT(count_pcmd_return);
2987 superblockend = true;
2990 /* pop 0 push 1 const */
2993 COUNT(count_pcmd_load);
2995 switch (iptr[1].opc) {
2997 iptr[0].opc = ICMD_IADDCONST;
2999 iptr[1].opc = ICMD_NOP;
3000 OP1_1(TYPE_INT, TYPE_INT);
3001 COUNT(count_pcmd_op);
3004 iptr[0].opc = ICMD_ISUBCONST;
3005 goto icmd_iconst_tail;
3006 #if SUPPORT_CONST_MUL
3008 iptr[0].opc = ICMD_IMULCONST;
3009 goto icmd_iconst_tail;
3010 #else /* SUPPORT_CONST_MUL */
3012 if (iptr[0].val.i == 0x00000002)
3014 else if (iptr[0].val.i == 0x00000004)
3016 else if (iptr[0].val.i == 0x00000008)
3018 else if (iptr[0].val.i == 0x00000010)
3020 else if (iptr[0].val.i == 0x00000020)
3022 else if (iptr[0].val.i == 0x00000040)
3024 else if (iptr[0].val.i == 0x00000080)
3026 else if (iptr[0].val.i == 0x00000100)
3028 else if (iptr[0].val.i == 0x00000200)
3030 else if (iptr[0].val.i == 0x00000400)
3032 else if (iptr[0].val.i == 0x00000800)
3034 else if (iptr[0].val.i == 0x00001000)
3036 else if (iptr[0].val.i == 0x00002000)
3038 else if (iptr[0].val.i == 0x00004000)
3040 else if (iptr[0].val.i == 0x00008000)
3042 else if (iptr[0].val.i == 0x00010000)
3044 else if (iptr[0].val.i == 0x00020000)
3046 else if (iptr[0].val.i == 0x00040000)
3048 else if (iptr[0].val.i == 0x00080000)
3050 else if (iptr[0].val.i == 0x00100000)
3052 else if (iptr[0].val.i == 0x00200000)
3054 else if (iptr[0].val.i == 0x00400000)
3056 else if (iptr[0].val.i == 0x00800000)
3058 else if (iptr[0].val.i == 0x01000000)
3060 else if (iptr[0].val.i == 0x02000000)
3062 else if (iptr[0].val.i == 0x04000000)
3064 else if (iptr[0].val.i == 0x08000000)
3066 else if (iptr[0].val.i == 0x10000000)
3068 else if (iptr[0].val.i == 0x20000000)
3070 else if (iptr[0].val.i == 0x40000000)
3072 else if (iptr[0].val.i == 0x80000000)
3075 PUSHCONST(TYPE_INT);
3078 iptr[0].opc = ICMD_IMULPOW2;
3079 goto icmd_iconst_tail;
3080 #endif /* SUPPORT_CONST_MUL */
3082 if (iptr[0].val.i == 0x00000002)
3084 else if (iptr[0].val.i == 0x00000004)
3086 else if (iptr[0].val.i == 0x00000008)
3088 else if (iptr[0].val.i == 0x00000010)
3090 else if (iptr[0].val.i == 0x00000020)
3092 else if (iptr[0].val.i == 0x00000040)
3094 else if (iptr[0].val.i == 0x00000080)
3096 else if (iptr[0].val.i == 0x00000100)
3098 else if (iptr[0].val.i == 0x00000200)
3100 else if (iptr[0].val.i == 0x00000400)
3102 else if (iptr[0].val.i == 0x00000800)
3104 else if (iptr[0].val.i == 0x00001000)
3106 else if (iptr[0].val.i == 0x00002000)
3108 else if (iptr[0].val.i == 0x00004000)
3110 else if (iptr[0].val.i == 0x00008000)
3112 else if (iptr[0].val.i == 0x00010000)
3114 else if (iptr[0].val.i == 0x00020000)
3116 else if (iptr[0].val.i == 0x00040000)
3118 else if (iptr[0].val.i == 0x00080000)
3120 else if (iptr[0].val.i == 0x00100000)
3122 else if (iptr[0].val.i == 0x00200000)
3124 else if (iptr[0].val.i == 0x00400000)
3126 else if (iptr[0].val.i == 0x00800000)
3128 else if (iptr[0].val.i == 0x01000000)
3130 else if (iptr[0].val.i == 0x02000000)
3132 else if (iptr[0].val.i == 0x04000000)
3134 else if (iptr[0].val.i == 0x08000000)
3136 else if (iptr[0].val.i == 0x10000000)
3138 else if (iptr[0].val.i == 0x20000000)
3140 else if (iptr[0].val.i == 0x40000000)
3142 else if (iptr[0].val.i == 0x80000000)
3145 PUSHCONST(TYPE_INT);
3148 iptr[0].opc = ICMD_IDIVPOW2;
3149 goto icmd_iconst_tail;
3151 /*log_text("stack.c: ICMD_ICONST/ICMD_IREM");*/
3152 if ((iptr[0].val.i == 0x00000002) ||
3153 (iptr[0].val.i == 0x00000004) ||
3154 (iptr[0].val.i == 0x00000008) ||
3155 (iptr[0].val.i == 0x00000010) ||
3156 (iptr[0].val.i == 0x00000020) ||
3157 (iptr[0].val.i == 0x00000040) ||
3158 (iptr[0].val.i == 0x00000080) ||
3159 (iptr[0].val.i == 0x00000100) ||
3160 (iptr[0].val.i == 0x00000200) ||
3161 (iptr[0].val.i == 0x00000400) ||
3162 (iptr[0].val.i == 0x00000800) ||
3163 (iptr[0].val.i == 0x00001000) ||
3164 (iptr[0].val.i == 0x00002000) ||
3165 (iptr[0].val.i == 0x00004000) ||
3166 (iptr[0].val.i == 0x00008000) ||
3167 (iptr[0].val.i == 0x00010000) ||
3168 (iptr[0].val.i == 0x00020000) ||
3169 (iptr[0].val.i == 0x00040000) ||
3170 (iptr[0].val.i == 0x00080000) ||
3171 (iptr[0].val.i == 0x00100000) ||
3172 (iptr[0].val.i == 0x00200000) ||
3173 (iptr[0].val.i == 0x00400000) ||
3174 (iptr[0].val.i == 0x00800000) ||
3175 (iptr[0].val.i == 0x01000000) ||
3176 (iptr[0].val.i == 0x02000000) ||
3177 (iptr[0].val.i == 0x04000000) ||
3178 (iptr[0].val.i == 0x08000000) ||
3179 (iptr[0].val.i == 0x10000000) ||
3180 (iptr[0].val.i == 0x20000000) ||
3181 (iptr[0].val.i == 0x40000000) ||
3182 (iptr[0].val.i == 0x80000000)) {
3183 iptr[0].opc = ICMD_IREMPOW2;
3185 goto icmd_iconst_tail;
3187 PUSHCONST(TYPE_INT);
3189 #if SUPPORT_CONST_LOGICAL
3191 iptr[0].opc = ICMD_IANDCONST;
3192 goto icmd_iconst_tail;
3194 iptr[0].opc = ICMD_IORCONST;
3195 goto icmd_iconst_tail;
3197 iptr[0].opc = ICMD_IXORCONST;
3198 goto icmd_iconst_tail;
3199 #endif /* SUPPORT_CONST_LOGICAL */
3201 iptr[0].opc = ICMD_ISHLCONST;
3202 goto icmd_iconst_tail;
3204 iptr[0].opc = ICMD_ISHRCONST;
3205 goto icmd_iconst_tail;
3207 iptr[0].opc = ICMD_IUSHRCONST;
3208 goto icmd_iconst_tail;
3209 #if SUPPORT_LONG_SHIFT
3211 iptr[0].opc = ICMD_LSHLCONST;
3212 goto icmd_lconst_tail;
3214 iptr[0].opc = ICMD_LSHRCONST;
3215 goto icmd_lconst_tail;
3217 iptr[0].opc = ICMD_LUSHRCONST;
3218 goto icmd_lconst_tail;
3219 #endif /* SUPPORT_LONG_SHIFT */
3220 case ICMD_IF_ICMPEQ:
3221 iptr[1].opc = ICMD_IFEQ;
3223 /* iptr[0].op1 = iptr[1].op1; */
3224 /* IF_ICMPxx is the last instruction in the
3225 basic block, just remove it. */
3226 iptr[0].opc = ICMD_NOP;
3227 iptr[1].val.i = iptr[0].val.i;
3229 /* bptr->icount--; */
3233 tbptr = m->basicblocks +
3234 m->basicblockindex[iptr[1].op1];
3236 iptr[1].target = (void *) tbptr;
3238 MARKREACHED(tbptr, copy);
3239 COUNT(count_pcmd_bra);
3242 case ICMD_IF_ICMPLT:
3243 iptr[1].opc = ICMD_IFLT;
3244 goto icmd_if_icmp_tail;
3245 case ICMD_IF_ICMPLE:
3246 iptr[1].opc = ICMD_IFLE;
3247 goto icmd_if_icmp_tail;
3248 case ICMD_IF_ICMPNE:
3249 iptr[1].opc = ICMD_IFNE;
3250 goto icmd_if_icmp_tail;
3251 case ICMD_IF_ICMPGT:
3252 iptr[1].opc = ICMD_IFGT;
3253 goto icmd_if_icmp_tail;
3254 case ICMD_IF_ICMPGE:
3255 iptr[1].opc = ICMD_IFGE;
3256 goto icmd_if_icmp_tail;
3258 #if SUPPORT_CONST_STORE
3263 # if defined(ENABLE_INTRP)
3266 # if SUPPORT_CONST_STORE_ZERO_ONLY
3267 if (iptr[0].val.i == 0) {
3269 switch (iptr[1].opc) {
3271 iptr[0].opc = ICMD_IASTORECONST;
3274 iptr[0].opc = ICMD_BASTORECONST;
3277 iptr[0].opc = ICMD_CASTORECONST;
3280 iptr[0].opc = ICMD_SASTORECONST;
3284 iptr[1].opc = ICMD_NOP;
3285 OPTT2_0(TYPE_INT, TYPE_ADR);
3286 COUNT(count_pcmd_op);
3287 # if SUPPORT_CONST_STORE_ZERO_ONLY
3290 PUSHCONST(TYPE_INT);
3292 # if defined(ENABLE_INTRP)
3295 PUSHCONST(TYPE_INT);
3299 case ICMD_PUTSTATIC:
3301 # if defined(ENABLE_INTRP)
3304 # if SUPPORT_CONST_STORE_ZERO_ONLY
3305 if (iptr[0].val.i == 0) {
3307 switch (iptr[1].opc) {
3308 case ICMD_PUTSTATIC:
3309 iptr[0].opc = ICMD_PUTSTATICCONST;
3313 iptr[0].opc = ICMD_PUTFIELDCONST;
3318 iptr[1].opc = ICMD_NOP;
3319 iptr[0].op1 = TYPE_INT;
3320 COUNT(count_pcmd_op);
3321 # if SUPPORT_CONST_STORE_ZERO_ONLY
3324 PUSHCONST(TYPE_INT);
3326 # if defined(ENABLE_INTRP)
3329 PUSHCONST(TYPE_INT);
3332 #endif /* SUPPORT_CONST_STORE */
3334 PUSHCONST(TYPE_INT);
3338 PUSHCONST(TYPE_INT);
3342 COUNT(count_pcmd_load);
3344 switch (iptr[1].opc) {
3345 #if SUPPORT_LONG_ADD
3347 iptr[0].opc = ICMD_LADDCONST;
3349 iptr[1].opc = ICMD_NOP;
3350 OP1_1(TYPE_LNG,TYPE_LNG);
3351 COUNT(count_pcmd_op);
3354 iptr[0].opc = ICMD_LSUBCONST;
3355 goto icmd_lconst_tail;
3356 #endif /* SUPPORT_LONG_ADD */
3357 #if SUPPORT_LONG_MUL && SUPPORT_CONST_MUL
3359 iptr[0].opc = ICMD_LMULCONST;
3360 goto icmd_lconst_tail;
3361 #else /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
3362 # if SUPPORT_LONG_SHIFT
3364 if (iptr[0].val.l == 0x00000002)
3366 else if (iptr[0].val.l == 0x00000004)
3368 else if (iptr[0].val.l == 0x00000008)
3370 else if (iptr[0].val.l == 0x00000010)
3372 else if (iptr[0].val.l == 0x00000020)
3374 else if (iptr[0].val.l == 0x00000040)
3376 else if (iptr[0].val.l == 0x00000080)
3378 else if (iptr[0].val.l == 0x00000100)
3380 else if (iptr[0].val.l == 0x00000200)
3382 else if (iptr[0].val.l == 0x00000400)
3384 else if (iptr[0].val.l == 0x00000800)
3386 else if (iptr[0].val.l == 0x00001000)
3388 else if (iptr[0].val.l == 0x00002000)
3390 else if (iptr[0].val.l == 0x00004000)
3392 else if (iptr[0].val.l == 0x00008000)
3394 else if (iptr[0].val.l == 0x00010000)
3396 else if (iptr[0].val.l == 0x00020000)
3398 else if (iptr[0].val.l == 0x00040000)
3400 else if (iptr[0].val.l == 0x00080000)
3402 else if (iptr[0].val.l == 0x00100000)
3404 else if (iptr[0].val.l == 0x00200000)
3406 else if (iptr[0].val.l == 0x00400000)
3408 else if (iptr[0].val.l == 0x00800000)
3410 else if (iptr[0].val.l == 0x01000000)
3412 else if (iptr[0].val.l == 0x02000000)
3414 else if (iptr[0].val.l == 0x04000000)
3416 else if (iptr[0].val.l == 0x08000000)
3418 else if (iptr[0].val.l == 0x10000000)
3420 else if (iptr[0].val.l == 0x20000000)
3422 else if (iptr[0].val.l == 0x40000000)
3424 else if (iptr[0].val.l == 0x80000000)
3427 PUSHCONST(TYPE_LNG);
3430 iptr[0].opc = ICMD_LMULPOW2;
3431 goto icmd_lconst_tail;
3432 # endif /* SUPPORT_LONG_SHIFT */
3433 #endif /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
3435 #if SUPPORT_LONG_DIV_POW2
3437 if (iptr[0].val.l == 0x00000002)
3439 else if (iptr[0].val.l == 0x00000004)
3441 else if (iptr[0].val.l == 0x00000008)
3443 else if (iptr[0].val.l == 0x00000010)
3445 else if (iptr[0].val.l == 0x00000020)
3447 else if (iptr[0].val.l == 0x00000040)
3449 else if (iptr[0].val.l == 0x00000080)
3451 else if (iptr[0].val.l == 0x00000100)
3453 else if (iptr[0].val.l == 0x00000200)
3455 else if (iptr[0].val.l == 0x00000400)
3457 else if (iptr[0].val.l == 0x00000800)
3459 else if (iptr[0].val.l == 0x00001000)
3461 else if (iptr[0].val.l == 0x00002000)
3463 else if (iptr[0].val.l == 0x00004000)
3465 else if (iptr[0].val.l == 0x00008000)
3467 else if (iptr[0].val.l == 0x00010000)
3469 else if (iptr[0].val.l == 0x00020000)
3471 else if (iptr[0].val.l == 0x00040000)
3473 else if (iptr[0].val.l == 0x00080000)
3475 else if (iptr[0].val.l == 0x00100000)
3477 else if (iptr[0].val.l == 0x00200000)
3479 else if (iptr[0].val.l == 0x00400000)
3481 else if (iptr[0].val.l == 0x00800000)
3483 else if (iptr[0].val.l == 0x01000000)
3485 else if (iptr[0].val.l == 0x02000000)
3487 else if (iptr[0].val.l == 0x04000000)
3489 else if (iptr[0].val.l == 0x08000000)
3491 else if (iptr[0].val.l == 0x10000000)
3493 else if (iptr[0].val.l == 0x20000000)
3495 else if (iptr[0].val.l == 0x40000000)
3497 else if (iptr[0].val.l == 0x80000000)
3500 PUSHCONST(TYPE_LNG);
3503 iptr[0].opc = ICMD_LDIVPOW2;
3504 goto icmd_lconst_tail;
3505 #endif /* SUPPORT_LONG_DIV_POW2 */
3507 #if SUPPORT_LONG_REM_POW2
3509 if ((iptr[0].val.l == 0x00000002) ||
3510 (iptr[0].val.l == 0x00000004) ||
3511 (iptr[0].val.l == 0x00000008) ||
3512 (iptr[0].val.l == 0x00000010) ||
3513 (iptr[0].val.l == 0x00000020) ||
3514 (iptr[0].val.l == 0x00000040) ||
3515 (iptr[0].val.l == 0x00000080) ||
3516 (iptr[0].val.l == 0x00000100) ||
3517 (iptr[0].val.l == 0x00000200) ||
3518 (iptr[0].val.l == 0x00000400) ||
3519 (iptr[0].val.l == 0x00000800) ||
3520 (iptr[0].val.l == 0x00001000) ||
3521 (iptr[0].val.l == 0x00002000) ||
3522 (iptr[0].val.l == 0x00004000) ||
3523 (iptr[0].val.l == 0x00008000) ||
3524 (iptr[0].val.l == 0x00010000) ||
3525 (iptr[0].val.l == 0x00020000) ||
3526 (iptr[0].val.l == 0x00040000) ||
3527 (iptr[0].val.l == 0x00080000) ||
3528 (iptr[0].val.l == 0x00100000) ||
3529 (iptr[0].val.l == 0x00200000) ||
3530 (iptr[0].val.l == 0x00400000) ||
3531 (iptr[0].val.l == 0x00800000) ||
3532 (iptr[0].val.l == 0x01000000) ||
3533 (iptr[0].val.l == 0x02000000) ||
3534 (iptr[0].val.l == 0x04000000) ||
3535 (iptr[0].val.l == 0x08000000) ||
3536 (iptr[0].val.l == 0x10000000) ||
3537 (iptr[0].val.l == 0x20000000) ||
3538 (iptr[0].val.l == 0x40000000) ||
3539 (iptr[0].val.l == 0x80000000)) {
3540 iptr[0].opc = ICMD_LREMPOW2;
3542 goto icmd_lconst_tail;
3544 PUSHCONST(TYPE_LNG);
3546 #endif /* SUPPORT_LONG_REM_POW2 */
3548 #if SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL
3551 iptr[0].opc = ICMD_LANDCONST;
3552 goto icmd_lconst_tail;
3554 iptr[0].opc = ICMD_LORCONST;
3555 goto icmd_lconst_tail;
3557 iptr[0].opc = ICMD_LXORCONST;
3558 goto icmd_lconst_tail;
3559 #endif /* SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL */
3561 #if SUPPORT_LONG_CMP_CONST
3563 if ((len > 1) && (iptr[2].val.i == 0)) {
3564 switch (iptr[2].opc) {
3566 iptr[0].opc = ICMD_IF_LEQ;
3567 icmd_lconst_lcmp_tail:
3568 iptr[0].op1 = iptr[2].op1;
3569 iptr[1].opc = ICMD_NOP;
3570 iptr[2].opc = ICMD_NOP;
3572 /* bptr->icount -= 2; */
3576 tbptr = m->basicblocks +
3577 m->basicblockindex[iptr[0].op1];
3579 iptr[0].target = (void *) tbptr;
3581 MARKREACHED(tbptr, copy);
3582 COUNT(count_pcmd_bra);
3583 COUNT(count_pcmd_op);
3586 iptr[0].opc = ICMD_IF_LNE;
3587 goto icmd_lconst_lcmp_tail;
3589 iptr[0].opc = ICMD_IF_LLT;
3590 goto icmd_lconst_lcmp_tail;
3592 iptr[0].opc = ICMD_IF_LGT;
3593 goto icmd_lconst_lcmp_tail;
3595 iptr[0].opc = ICMD_IF_LLE;
3596 goto icmd_lconst_lcmp_tail;
3598 iptr[0].opc = ICMD_IF_LGE;
3599 goto icmd_lconst_lcmp_tail;
3601 PUSHCONST(TYPE_LNG);
3602 } /* switch (iptr[2].opc) */
3603 } /* if (iptr[2].val.i == 0) */
3605 PUSHCONST(TYPE_LNG);
3607 #endif /* SUPPORT_LONG_CMP_CONST */
3609 #if SUPPORT_CONST_STORE
3611 # if defined(ENABLE_INTRP)
3614 # if SUPPORT_CONST_STORE_ZERO_ONLY
3615 if (iptr[0].val.l == 0) {
3617 iptr[0].opc = ICMD_LASTORECONST;
3618 iptr[1].opc = ICMD_NOP;
3619 OPTT2_0(TYPE_INT, TYPE_ADR);
3620 COUNT(count_pcmd_op);
3621 # if SUPPORT_CONST_STORE_ZERO_ONLY
3624 PUSHCONST(TYPE_LNG);
3626 # if defined(ENABLE_INTRP)
3629 PUSHCONST(TYPE_LNG);
3633 case ICMD_PUTSTATIC:
3635 # if defined(ENABLE_INTRP)
3638 # if SUPPORT_CONST_STORE_ZERO_ONLY
3639 if (iptr[0].val.l == 0) {
3641 switch (iptr[1].opc) {
3642 case ICMD_PUTSTATIC:
3643 iptr[0].opc = ICMD_PUTSTATICCONST;
3647 iptr[0].opc = ICMD_PUTFIELDCONST;
3652 iptr[1].opc = ICMD_NOP;
3653 iptr[0].op1 = TYPE_LNG;
3654 COUNT(count_pcmd_op);
3655 # if SUPPORT_CONST_STORE_ZERO_ONLY
3658 PUSHCONST(TYPE_LNG);
3660 # if defined(ENABLE_INTRP)
3663 PUSHCONST(TYPE_LNG);
3666 #endif /* SUPPORT_CONST_STORE */
3668 PUSHCONST(TYPE_LNG);
3672 PUSHCONST(TYPE_LNG);
3676 COUNT(count_pcmd_load);
3677 PUSHCONST(TYPE_FLT);
3681 COUNT(count_pcmd_load);
3682 PUSHCONST(TYPE_DBL);
3686 COUNT(count_pcmd_load);
3687 #if SUPPORT_CONST_STORE
3688 # if defined(ENABLE_INTRP)
3691 /* We can only optimize if the ACONST is resolved
3692 * and there is an instruction after it. */
3694 if ((len > 0) && INSTRUCTION_IS_RESOLVED(iptr))
3696 switch (iptr[1].opc) {
3698 /* We can only optimize for NULL values
3699 * here because otherwise a checkcast is
3701 if (iptr->val.a != NULL)
3702 goto aconst_no_transform;
3704 iptr[0].opc = ICMD_AASTORECONST;
3705 OPTT2_0(TYPE_INT, TYPE_ADR);
3707 iptr[1].opc = ICMD_NOP;
3708 COUNT(count_pcmd_op);
3711 case ICMD_PUTSTATIC:
3713 # if SUPPORT_CONST_STORE_ZERO_ONLY
3714 if (iptr->val.a == 0) {
3717 switch (iptr[1].opc) {
3718 case ICMD_PUTSTATIC:
3719 iptr[0].opc = ICMD_PUTSTATICCONST;
3720 iptr[0].op1 = TYPE_ADR;
3724 iptr[0].opc = ICMD_PUTFIELDCONST;
3725 iptr[0].op1 = TYPE_ADR;
3730 iptr[1].opc = ICMD_NOP;
3731 COUNT(count_pcmd_op);
3733 # if SUPPORT_CONST_STORE_ZERO_ONLY
3736 /* no transformation */
3737 PUSHCONST(TYPE_ADR);
3742 aconst_no_transform:
3743 /* no transformation */
3744 PUSHCONST(TYPE_ADR);
3748 /* no transformation */
3749 PUSHCONST(TYPE_ADR);
3751 # if defined(ENABLE_INTRP)
3754 PUSHCONST(TYPE_ADR);
3756 #else /* SUPPORT_CONST_STORE */
3757 PUSHCONST(TYPE_ADR);
3758 #endif /* SUPPORT_CONST_STORE */
3761 /* pop 0 push 1 load */
3768 COUNT(count_load_instruction);
3769 i = opcode - ICMD_ILOAD;
3770 #if defined(ENABLE_INTRP)
3773 rd->locals[iptr->op1][i].type = i;
3774 LOAD(i, LOCALVAR, iptr->op1);
3784 COUNT(count_check_null);
3785 COUNT(count_check_bound);
3786 COUNT(count_pcmd_mem);
3787 OP2IAT_1(opcode - ICMD_IALOAD);
3793 COUNT(count_check_null);
3794 COUNT(count_check_bound);
3795 COUNT(count_pcmd_mem);
3799 /* pop 0 push 0 iinc */
3802 #if defined(ENABLE_STATISTICS)
3806 count_store_depth[10]++;
3808 count_store_depth[i]++;
3811 last_store[5 * iptr->op1 + TYPE_INT] = bptr->icount - len - 1;
3816 if ((copy->varkind == LOCALVAR) &&
3817 (copy->varnum == iptr->op1)) {
3818 copy->varkind = TEMPVAR;
3828 /* pop 1 push 0 store */
3837 i = opcode - ICMD_ISTORE;
3838 #if defined(ENABLE_INTRP)
3841 rd->locals[iptr->op1][i].type = i;
3842 #if defined(ENABLE_STATISTICS)
3847 count_store_length[20]++;
3849 count_store_length[i]++;
3852 count_store_depth[10]++;
3854 count_store_depth[i]++;
3857 /* check for conflicts as described in Figure 5.2 */
3858 copy = curstack->prev;
3861 if ((copy->varkind == LOCALVAR) &&
3862 (copy->varnum == iptr->op1)) {
3863 copy->varkind = TEMPVAR;
3870 /* do not change instack Stackslots */
3871 /* it won't improve performance if we copy the interface */
3872 /* at the BB begin or here, and lsra relies that no */
3873 /* instack stackslot is marked LOCALVAR */
3874 if (curstack->varkind == STACKVAR)
3875 goto _possible_conflict;
3877 /* check for a DUPX,SWAP while the lifetime of curstack */
3878 /* and as creator curstack */
3879 if (last_dupx != -1) {
3880 /* we have to look at the dst stack of DUPX */
3881 /* == src Stack of PEI */
3882 copy = bptr->iinstr[last_dupx].dst;
3885 copy = bptr->instack;
3887 copy = bptr->iinstr[last_pei-1].dst;
3889 if ((copy != NULL) && (curstack <= copy)) {
3890 /* curstack alive at or created by DUPX */
3893 /* now look, if there is a LOCALVAR at anyone of */
3894 /* the src stacklots used by DUPX */
3896 goto _possible_conflict;
3900 /* check for a PEI while the lifetime of curstack */
3901 if (last_pei != -1) {
3902 /* && there are exception handler in this method */
3903 /* when this is checked prevent ARGVAR from */
3904 /* overwriting LOCALVAR!!! */
3906 /* we have to look at the stack _before_ the PEI! */
3907 /* == src Stack of PEI */
3909 copy = bptr->instack;
3911 copy = bptr->iinstr[last_pei-1].dst;
3912 if ((copy != NULL) && (curstack <= copy)) {
3913 /* curstack alive at PEI */
3914 goto _possible_conflict;
3918 /* check if there is a possible conflicting XSTORE */
3919 if (last_store[5 * iptr->op1 + opcode - ICMD_ISTORE] != -1) {
3920 /* we have to look at the stack _before_ the XSTORE! */
3921 /* == src Stack of XSTORE */
3922 if (last_store[5 * iptr->op1 + opcode - ICMD_ISTORE] == 0)
3923 copy = bptr->instack;
3925 copy = bptr->iinstr[last_store[5 * iptr->op1 + opcode - ICMD_ISTORE] - 1].dst;
3926 if ((copy != NULL) && (curstack <= copy)) {
3927 /* curstack alive at Last Store */
3928 goto _possible_conflict;
3932 /* check if there is a conflict with a XLOAD */
3933 /* this is done indirectly by looking if a Stackslot is */
3934 /* marked LOCALVAR and is live while curstack is live */
3935 /* see figure 5.3 */
3937 /* First check "above" stackslots of the instack */
3938 copy = curstack + 1;
3939 for(;(copy <= bptr->instack); copy++)
3940 if ((copy->varkind == LOCALVAR) && (copy->varnum == iptr->op1)) {
3941 goto _possible_conflict;
3944 /* "intra" Basic Block Stackslots are allocated above */
3945 /* bptr->stack (see doc/stack.txt), so if curstack + 1 */
3946 /* is an instack, copy could point now to the stackslots */
3947 /* of an inbetween analysed Basic Block */
3948 if (copy < bptr->stack)
3950 while (copy < new) {
3951 if ((copy->varkind == LOCALVAR) && (copy->varnum == iptr->op1)) {
3952 goto _possible_conflict;
3956 /* If Stackslot is already marked as LOCALVAR, do not */
3957 /* change it! Conflict resolution works only, if xLOAD */
3959 if (curstack->varkind == LOCALVAR)
3960 goto _possible_conflict;
3961 /* no conflict - mark the Stackslot as LOCALVAR */
3962 curstack->varkind = LOCALVAR;
3963 curstack->varnum = iptr->op1;
3967 if ((curstack->varkind == LOCALVAR)
3968 && (curstack->varnum == iptr->op1)) {
3969 curstack->varkind = TEMPVAR;
3970 curstack->varnum = stackdepth-1;
3973 last_store[5 * iptr->op1 + opcode - ICMD_ISTORE] = bptr->icount - len - 1;
3975 STORE(opcode - ICMD_ISTORE);
3981 COUNT(count_check_null);
3982 COUNT(count_check_bound);
3983 COUNT(count_pcmd_mem);
3985 bte = builtintable_get_internal(BUILTIN_canstore);
3988 if (md->memuse > rd->memuse)
3989 rd->memuse = md->memuse;
3990 if (md->argintreguse > rd->argintreguse)
3991 rd->argintreguse = md->argintreguse;
3993 /* make all stack variables saved */
3997 copy->flags |= SAVEDVAR;
4008 COUNT(count_check_null);
4009 COUNT(count_check_bound);
4010 COUNT(count_pcmd_mem);
4011 OP3TIA_0(opcode - ICMD_IASTORE);
4017 COUNT(count_check_null);
4018 COUNT(count_check_bound);
4019 COUNT(count_pcmd_mem);
4026 #ifdef ENABLE_VERIFIER
4029 if (IS_2_WORD_TYPE(curstack->type))
4030 goto throw_stack_category_error;
4041 #if defined(ENABLE_JIT)
4042 # if defined(ENABLE_INTRP)
4045 md_return_alloc(jd, curstack);
4047 COUNT(count_pcmd_return);
4048 OP1_0(opcode - ICMD_IRETURN);
4049 superblockend = true;
4053 COUNT(count_check_null);
4057 superblockend = true;
4060 case ICMD_PUTSTATIC:
4061 COUNT(count_pcmd_mem);
4065 /* pop 1 push 0 branch */
4068 case ICMD_IFNONNULL:
4069 COUNT(count_pcmd_bra);
4071 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
4073 iptr[0].target = (void *) tbptr;
4075 MARKREACHED(tbptr, copy);
4084 COUNT(count_pcmd_bra);
4086 /* iptr->val.i is set implicitly in parse by
4087 clearing the memory or from IF_ICMPxx
4091 /* iptr->val.i = 0; */
4092 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
4094 iptr[0].target = (void *) tbptr;
4096 MARKREACHED(tbptr, copy);
4099 /* pop 0 push 0 branch */
4102 COUNT(count_pcmd_bra);
4103 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
4105 iptr[0].target = (void *) tbptr;
4107 MARKREACHED(tbptr, copy);
4109 superblockend = true;
4112 /* pop 1 push 0 table branch */
4114 case ICMD_TABLESWITCH:
4115 COUNT(count_pcmd_table);
4117 s4ptr = iptr->val.a;
4118 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
4119 MARKREACHED(tbptr, copy);
4120 i = *s4ptr++; /* low */
4121 i = *s4ptr++ - i + 1; /* high */
4123 tptr = DMNEW(void*, i+1);
4124 iptr->target = (void *) tptr;
4126 tptr[0] = (void *) tbptr;
4130 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
4132 tptr[0] = (void *) tbptr;
4135 MARKREACHED(tbptr, copy);
4138 superblockend = true;
4141 /* pop 1 push 0 table branch */
4143 case ICMD_LOOKUPSWITCH:
4144 COUNT(count_pcmd_table);
4146 s4ptr = iptr->val.a;
4147 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
4148 MARKREACHED(tbptr, copy);
4149 i = *s4ptr++; /* count */
4151 tptr = DMNEW(void*, i+1);
4152 iptr->target = (void *) tptr;
4154 tptr[0] = (void *) tbptr;
4158 tbptr = m->basicblocks + m->basicblockindex[s4ptr[1]];
4160 tptr[0] = (void *) tbptr;
4163 MARKREACHED(tbptr, copy);
4167 superblockend = true;
4170 case ICMD_MONITORENTER:
4171 COUNT(count_check_null);
4172 case ICMD_MONITOREXIT:
4176 /* pop 2 push 0 branch */
4178 case ICMD_IF_ICMPEQ:
4179 case ICMD_IF_ICMPNE:
4180 case ICMD_IF_ICMPLT:
4181 case ICMD_IF_ICMPGE:
4182 case ICMD_IF_ICMPGT:
4183 case ICMD_IF_ICMPLE:
4184 COUNT(count_pcmd_bra);
4186 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
4188 iptr[0].target = (void *) tbptr;
4190 MARKREACHED(tbptr, copy);
4193 case ICMD_IF_ACMPEQ:
4194 case ICMD_IF_ACMPNE:
4195 COUNT(count_pcmd_bra);
4197 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
4199 iptr[0].target = (void *) tbptr;
4201 MARKREACHED(tbptr, copy);
4207 COUNT(count_check_null);
4208 COUNT(count_pcmd_mem);
4209 OPTT2_0(iptr->op1,TYPE_ADR);
4214 if (!IS_2_WORD_TYPE(curstack->type)) {
4216 #ifdef ENABLE_VERIFIER
4219 if (IS_2_WORD_TYPE(curstack->prev->type))
4220 goto throw_stack_category_error;
4223 OP1_0ANY; /* second pop */
4226 iptr->opc = ICMD_POP;
4230 /* pop 0 push 1 dup */
4233 #ifdef ENABLE_VERIFIER
4236 if (IS_2_WORD_TYPE(curstack->type))
4237 goto throw_stack_category_error;
4240 last_dupx = bptr->icount - len - 1;
4241 COUNT(count_dup_instruction);
4246 last_dupx = bptr->icount - len - 1;
4248 if (IS_2_WORD_TYPE(curstack->type)) {
4250 iptr->opc = ICMD_DUP;
4255 /* ..., ????, cat1 */
4256 #ifdef ENABLE_VERIFIER
4258 if (IS_2_WORD_TYPE(curstack->prev->type))
4259 goto throw_stack_category_error;
4263 NEWSTACK(copy->prev->type, copy->prev->varkind,
4264 copy->prev->varnum);
4265 NEWSTACK(copy->type, copy->varkind,
4272 /* pop 2 push 3 dup */
4275 #ifdef ENABLE_VERIFIER
4278 if (IS_2_WORD_TYPE(curstack->type) ||
4279 IS_2_WORD_TYPE(curstack->prev->type))
4280 goto throw_stack_category_error;
4283 last_dupx = bptr->icount - len - 1;
4288 last_dupx = bptr->icount - len - 1;
4290 if (IS_2_WORD_TYPE(curstack->type)) {
4291 /* ..., ????, cat2 */
4292 #ifdef ENABLE_VERIFIER
4294 if (IS_2_WORD_TYPE(curstack->prev->type))
4295 goto throw_stack_category_error;
4298 iptr->opc = ICMD_DUP_X1;
4302 /* ..., ????, cat1 */
4303 #ifdef ENABLE_VERIFIER
4306 if (IS_2_WORD_TYPE(curstack->prev->type)
4307 || IS_2_WORD_TYPE(curstack->prev->prev->type))
4308 goto throw_stack_category_error;
4315 /* pop 3 push 4 dup */
4318 last_dupx = bptr->icount - len - 1;
4320 if (IS_2_WORD_TYPE(curstack->prev->type)) {
4321 /* ..., cat2, ???? */
4322 #ifdef ENABLE_VERIFIER
4324 if (IS_2_WORD_TYPE(curstack->type))
4325 goto throw_stack_category_error;
4328 iptr->opc = ICMD_DUP_X1;
4332 /* ..., cat1, ???? */
4333 #ifdef ENABLE_VERIFIER
4336 if (IS_2_WORD_TYPE(curstack->type)
4337 || IS_2_WORD_TYPE(curstack->prev->prev->type))
4338 goto throw_stack_category_error;
4346 last_dupx = bptr->icount - len - 1;
4348 if (IS_2_WORD_TYPE(curstack->type)) {
4349 /* ..., ????, cat2 */
4350 if (IS_2_WORD_TYPE(curstack->prev->type)) {
4351 /* ..., cat2, cat2 */
4352 iptr->opc = ICMD_DUP_X1;
4356 /* ..., cat1, cat2 */
4357 #ifdef ENABLE_VERIFIER
4360 if (IS_2_WORD_TYPE(curstack->prev->prev->type))
4361 goto throw_stack_category_error;
4364 iptr->opc = ICMD_DUP_X2;
4370 /* ..., ????, ????, cat1 */
4371 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
4372 /* ..., cat2, ????, cat1 */
4373 #ifdef ENABLE_VERIFIER
4375 if (IS_2_WORD_TYPE(curstack->prev->type))
4376 goto throw_stack_category_error;
4379 iptr->opc = ICMD_DUP2_X1;
4383 /* ..., cat1, ????, cat1 */
4384 #ifdef ENABLE_VERIFIER
4387 if (IS_2_WORD_TYPE(curstack->prev->type)
4388 || IS_2_WORD_TYPE(curstack->prev->prev->prev->type))
4389 goto throw_stack_category_error;
4397 /* pop 2 push 2 swap */
4400 last_dupx = bptr->icount - len - 1;
4401 #ifdef ENABLE_VERIFIER
4404 if (IS_2_WORD_TYPE(curstack->type)
4405 || IS_2_WORD_TYPE(curstack->prev->type))
4406 goto throw_stack_category_error;
4416 #if !SUPPORT_DIVISION
4417 bte = (builtintable_entry *) iptr->val.a;
4421 if (md->memuse > rd->memuse)
4422 rd->memuse = md->memuse;
4423 if (md->argintreguse > rd->argintreguse)
4424 rd->argintreguse = md->argintreguse;
4426 /* make all stack variables saved */
4430 copy->flags |= SAVEDVAR;
4435 #endif /* !SUPPORT_DIVISION */
4446 COUNT(count_pcmd_op);
4452 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
4453 bte = (builtintable_entry *) iptr->val.a;
4457 if (md->memuse > rd->memuse)
4458 rd->memuse = md->memuse;
4459 if (md->argintreguse > rd->argintreguse)
4460 rd->argintreguse = md->argintreguse;
4462 /* make all stack variables saved */
4466 copy->flags |= SAVEDVAR;
4471 #endif /* !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV) */
4476 #if SUPPORT_LONG_LOGICAL
4480 #endif /* SUPPORT_LONG_LOGICAL */
4481 COUNT(count_pcmd_op);
4488 COUNT(count_pcmd_op);
4497 COUNT(count_pcmd_op);
4506 COUNT(count_pcmd_op);
4511 COUNT(count_pcmd_op);
4512 #if SUPPORT_LONG_CMP_CONST
4513 if ((len > 0) && (iptr[1].val.i == 0)) {
4514 switch (iptr[1].opc) {
4516 iptr[0].opc = ICMD_IF_LCMPEQ;
4518 iptr[0].op1 = iptr[1].op1;
4519 iptr[1].opc = ICMD_NOP;
4521 /* bptr->icount--; */
4524 tbptr = m->basicblocks +
4525 m->basicblockindex[iptr[0].op1];
4527 iptr[0].target = (void *) tbptr;
4529 MARKREACHED(tbptr, copy);
4530 COUNT(count_pcmd_bra);
4533 iptr[0].opc = ICMD_IF_LCMPNE;
4534 goto icmd_lcmp_if_tail;
4536 iptr[0].opc = ICMD_IF_LCMPLT;
4537 goto icmd_lcmp_if_tail;
4539 iptr[0].opc = ICMD_IF_LCMPGT;
4540 goto icmd_lcmp_if_tail;
4542 iptr[0].opc = ICMD_IF_LCMPLE;
4543 goto icmd_lcmp_if_tail;
4545 iptr[0].opc = ICMD_IF_LCMPGE;
4546 goto icmd_lcmp_if_tail;
4548 OPTT2_1(TYPE_LNG, TYPE_INT);
4552 #endif /* SUPPORT_LONG_CMP_CONST */
4553 OPTT2_1(TYPE_LNG, TYPE_INT);
4558 COUNT(count_pcmd_op);
4559 if ((len > 0) && (iptr[1].val.i == 0)) {
4560 switch (iptr[1].opc) {
4562 iptr[0].opc = ICMD_IF_FCMPEQ;
4564 iptr[0].op1 = iptr[1].op1;
4565 iptr[1].opc = ICMD_NOP;
4568 tbptr = m->basicblocks +
4569 m->basicblockindex[iptr[0].op1];
4571 iptr[0].target = (void *) tbptr;
4573 MARKREACHED(tbptr, copy);
4574 COUNT(count_pcmd_bra);
4577 iptr[0].opc = ICMD_IF_FCMPNE;
4578 goto icmd_if_fcmpl_tail;
4580 iptr[0].opc = ICMD_IF_FCMPL_LT;
4581 goto icmd_if_fcmpl_tail;
4583 iptr[0].opc = ICMD_IF_FCMPL_GT;
4584 goto icmd_if_fcmpl_tail;
4586 iptr[0].opc = ICMD_IF_FCMPL_LE;
4587 goto icmd_if_fcmpl_tail;
4589 iptr[0].opc = ICMD_IF_FCMPL_GE;
4590 goto icmd_if_fcmpl_tail;
4592 OPTT2_1(TYPE_FLT, TYPE_INT);
4596 OPTT2_1(TYPE_FLT, TYPE_INT);
4600 COUNT(count_pcmd_op);
4601 if ((len > 0) && (iptr[1].val.i == 0)) {
4602 switch (iptr[1].opc) {
4604 iptr[0].opc = ICMD_IF_FCMPEQ;
4606 iptr[0].op1 = iptr[1].op1;
4607 iptr[1].opc = ICMD_NOP;
4610 tbptr = m->basicblocks +
4611 m->basicblockindex[iptr[0].op1];
4613 iptr[0].target = (void *) tbptr;
4615 MARKREACHED(tbptr, copy);
4616 COUNT(count_pcmd_bra);
4619 iptr[0].opc = ICMD_IF_FCMPNE;
4620 goto icmd_if_fcmpg_tail;
4622 iptr[0].opc = ICMD_IF_FCMPG_LT;
4623 goto icmd_if_fcmpg_tail;
4625 iptr[0].opc = ICMD_IF_FCMPG_GT;
4626 goto icmd_if_fcmpg_tail;
4628 iptr[0].opc = ICMD_IF_FCMPG_LE;
4629 goto icmd_if_fcmpg_tail;
4631 iptr[0].opc = ICMD_IF_FCMPG_GE;
4632 goto icmd_if_fcmpg_tail;
4634 OPTT2_1(TYPE_FLT, TYPE_INT);
4638 OPTT2_1(TYPE_FLT, TYPE_INT);
4642 COUNT(count_pcmd_op);
4643 if ((len > 0) && (iptr[1].val.i == 0)) {
4644 switch (iptr[1].opc) {
4646 iptr[0].opc = ICMD_IF_DCMPEQ;
4648 iptr[0].op1 = iptr[1].op1;
4649 iptr[1].opc = ICMD_NOP;
4652 tbptr = m->basicblocks +
4653 m->basicblockindex[iptr[0].op1];
4655 iptr[0].target = (void *) tbptr;
4657 MARKREACHED(tbptr, copy);
4658 COUNT(count_pcmd_bra);
4661 iptr[0].opc = ICMD_IF_DCMPNE;
4662 goto icmd_if_dcmpl_tail;
4664 iptr[0].opc = ICMD_IF_DCMPL_LT;
4665 goto icmd_if_dcmpl_tail;
4667 iptr[0].opc = ICMD_IF_DCMPL_GT;
4668 goto icmd_if_dcmpl_tail;
4670 iptr[0].opc = ICMD_IF_DCMPL_LE;
4671 goto icmd_if_dcmpl_tail;
4673 iptr[0].opc = ICMD_IF_DCMPL_GE;
4674 goto icmd_if_dcmpl_tail;
4676 OPTT2_1(TYPE_DBL, TYPE_INT);
4680 OPTT2_1(TYPE_DBL, TYPE_INT);
4684 COUNT(count_pcmd_op);
4685 if ((len > 0) && (iptr[1].val.i == 0)) {
4686 switch (iptr[1].opc) {
4688 iptr[0].opc = ICMD_IF_DCMPEQ;
4690 iptr[0].op1 = iptr[1].op1;
4691 iptr[1].opc = ICMD_NOP;
4694 tbptr = m->basicblocks +
4695 m->basicblockindex[iptr[0].op1];
4697 iptr[0].target = (void *) tbptr;
4699 MARKREACHED(tbptr, copy);
4700 COUNT(count_pcmd_bra);
4703 iptr[0].opc = ICMD_IF_DCMPNE;
4704 goto icmd_if_dcmpg_tail;
4706 iptr[0].opc = ICMD_IF_DCMPG_LT;
4707 goto icmd_if_dcmpg_tail;
4709 iptr[0].opc = ICMD_IF_DCMPG_GT;
4710 goto icmd_if_dcmpg_tail;
4712 iptr[0].opc = ICMD_IF_DCMPG_LE;
4713 goto icmd_if_dcmpg_tail;
4715 iptr[0].opc = ICMD_IF_DCMPG_GE;
4716 goto icmd_if_dcmpg_tail;
4718 OPTT2_1(TYPE_DBL, TYPE_INT);
4722 OPTT2_1(TYPE_DBL, TYPE_INT);
4727 COUNT(count_pcmd_op);
4728 OPTT2_1(TYPE_FLT, TYPE_INT);
4733 COUNT(count_pcmd_op);
4734 OPTT2_1(TYPE_DBL, TYPE_INT);
4743 case ICMD_INT2SHORT:
4744 COUNT(count_pcmd_op);
4745 OP1_1(TYPE_INT, TYPE_INT);
4748 COUNT(count_pcmd_op);
4749 OP1_1(TYPE_LNG, TYPE_LNG);
4752 COUNT(count_pcmd_op);
4753 OP1_1(TYPE_FLT, TYPE_FLT);
4756 COUNT(count_pcmd_op);
4757 OP1_1(TYPE_DBL, TYPE_DBL);
4761 COUNT(count_pcmd_op);
4762 OP1_1(TYPE_INT, TYPE_LNG);
4765 COUNT(count_pcmd_op);
4766 OP1_1(TYPE_INT, TYPE_FLT);
4769 COUNT(count_pcmd_op);
4770 OP1_1(TYPE_INT, TYPE_DBL);
4773 COUNT(count_pcmd_op);
4774 OP1_1(TYPE_LNG, TYPE_INT);
4777 COUNT(count_pcmd_op);
4778 OP1_1(TYPE_LNG, TYPE_FLT);
4781 COUNT(count_pcmd_op);
4782 OP1_1(TYPE_LNG, TYPE_DBL);
4785 COUNT(count_pcmd_op);
4786 OP1_1(TYPE_FLT, TYPE_INT);
4789 COUNT(count_pcmd_op);
4790 OP1_1(TYPE_FLT, TYPE_LNG);
4793 COUNT(count_pcmd_op);
4794 OP1_1(TYPE_FLT, TYPE_DBL);
4797 COUNT(count_pcmd_op);
4798 OP1_1(TYPE_DBL, TYPE_INT);
4801 COUNT(count_pcmd_op);
4802 OP1_1(TYPE_DBL, TYPE_LNG);
4805 COUNT(count_pcmd_op);
4806 OP1_1(TYPE_DBL, TYPE_FLT);
4809 case ICMD_CHECKCAST:
4810 if (iptr->op1 == 0) {
4811 /* array type cast-check */
4813 bte = builtintable_get_internal(BUILTIN_arraycheckcast);
4816 if (md->memuse > rd->memuse)
4817 rd->memuse = md->memuse;
4818 if (md->argintreguse > rd->argintreguse)
4819 rd->argintreguse = md->argintreguse;
4821 /* make all stack variables saved */
4825 copy->flags |= SAVEDVAR;
4829 OP1_1(TYPE_ADR, TYPE_ADR);
4832 case ICMD_INSTANCEOF:
4833 case ICMD_ARRAYLENGTH:
4834 OP1_1(TYPE_ADR, TYPE_INT);
4838 case ICMD_ANEWARRAY:
4839 OP1_1(TYPE_INT, TYPE_ADR);
4843 COUNT(count_check_null);
4844 COUNT(count_pcmd_mem);
4845 OP1_1(TYPE_ADR, iptr->op1);
4850 case ICMD_GETSTATIC:
4851 COUNT(count_pcmd_mem);
4861 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
4863 iptr[0].target = (void *) tbptr;
4865 /* This is a dirty hack. The typechecker
4866 * needs it because the OP1_0ANY below
4867 * overwrites iptr->dst.
4869 iptr->val.a = (void *) iptr->dst;
4871 tbptr->type = BBTYPE_SBR;
4873 /* We need to check for overflow right here because
4874 * the pushed value is poped after MARKREACHED. */
4876 MARKREACHED(tbptr, copy);
4880 /* pop many push any */
4883 #if defined(USEBUILTINTABLE)
4886 bte = (builtintable_entry *) iptr->val.a;
4890 case ICMD_INVOKESTATIC:
4891 case ICMD_INVOKESPECIAL:
4892 case ICMD_INVOKEVIRTUAL:
4893 case ICMD_INVOKEINTERFACE:
4894 COUNT(count_pcmd_met);
4895 INSTRUCTION_GET_METHODDESC(iptr,md);
4896 /* if (lm->flags & ACC_STATIC) */
4897 /* {COUNT(count_check_null);} */
4901 /* last_pei = bptr->icount - len - 1; */
4905 if (md->memuse > rd->memuse)
4906 rd->memuse = md->memuse;
4907 if (md->argintreguse > rd->argintreguse)
4908 rd->argintreguse = md->argintreguse;
4909 if (md->argfltreguse > rd->argfltreguse)
4910 rd->argfltreguse = md->argfltreguse;
4915 for (i-- ; i >= 0; i--) {
4916 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
4917 /* If we pass float arguments in integer argument registers, we
4918 * are not allowed to precolor them here. Floats have to be moved
4919 * to this regs explicitly in codegen().
4920 * Only arguments that are passed by stack anyway can be precolored
4921 * (michi 2005/07/24) */
4922 if (!(copy->flags & SAVEDVAR) &&
4923 (!IS_FLT_DBL_TYPE(copy->type) || md->params[i].inmemory)) {
4925 if (!(copy->flags & SAVEDVAR)) {
4927 copy->varkind = ARGVAR;
4930 #if defined(ENABLE_INTRP)
4933 if (md->params[i].inmemory) {
4934 copy->flags = INMEMORY;
4935 copy->regoff = md->params[i].regoff;
4939 if (IS_FLT_DBL_TYPE(copy->type))
4940 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
4941 assert(0); /* XXX is this assert ok? */
4944 rd->argfltregs[md->params[i].regoff];
4947 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
4948 if (IS_2_WORD_TYPE(copy->type))
4949 copy->regoff = PACK_REGS(
4950 rd->argintregs[GET_LOW_REG(md->params[i].regoff)],
4951 rd->argintregs[GET_HIGH_REG(md->params[i].regoff)]);
4955 rd->argintregs[md->params[i].regoff];
4958 #if defined(ENABLE_INTRP)
4966 copy->flags |= SAVEDVAR;
4972 if (md->returntype.type != TYPE_VOID)
4973 OP0_1(md->returntype.type);
4976 case ICMD_INLINE_START:
4977 case ICMD_INLINE_END:
4981 case ICMD_MULTIANEWARRAY:
4982 if (rd->argintreguse < 3)
4983 rd->argintreguse = 3;
4988 #if defined(SPECIALMEMUSE)
4989 # if defined(__DARWIN__)
4990 if (rd->memuse < (i + INT_ARG_CNT + LA_SIZE_IN_POINTERS))
4991 rd->memuse = i + LA_SIZE_IN_POINTERS + INT_ARG_CNT;
4993 if (rd->memuse < (i + LA_SIZE_IN_POINTERS + 3))
4994 rd->memuse = i + LA_SIZE_IN_POINTERS + 3;
4997 # if defined(__I386__)
4998 if (rd->memuse < i + 3)
4999 rd->memuse = i + 3; /* n integer args spilled on stack */
5000 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
5001 if (rd->memuse < i + 2)
5002 rd->memuse = i + 2; /* 4*4 bytes callee save space */
5005 rd->memuse = i; /* n integer args spilled on stack */
5006 # endif /* defined(__I386__) */
5010 /* check INT type here? Currently typecheck does this. */
5011 if (!(copy->flags & SAVEDVAR)) {
5012 copy->varkind = ARGVAR;
5013 copy->varnum = i + INT_ARG_CNT;
5014 copy->flags |= INMEMORY;
5015 #if defined(SPECIALMEMUSE)
5016 # if defined(__DARWIN__)
5017 copy->regoff = i + LA_SIZE_IN_POINTERS + INT_ARG_CNT;
5019 copy->regoff = i + LA_SIZE_IN_POINTERS + 3;
5022 # if defined(__I386__)
5023 copy->regoff = i + 3;
5024 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
5025 copy->regoff = i + 2;
5028 # endif /* defined(__I386__) */
5029 #endif /* defined(SPECIALMEMUSE) */
5034 copy->flags |= SAVEDVAR;
5044 new_internalerror("Unknown ICMD %d", opcode);
5050 } /* while instructions */
5052 /* set out-stack of block */
5054 bptr->outstack = curstack;
5055 bptr->outdepth = stackdepth;
5057 /* stack slots at basic block end become interfaces */
5060 for (copy = curstack; copy; i--, copy = copy->prev) {
5061 if ((copy->varkind == STACKVAR) && (copy->varnum > i))
5062 copy->varkind = TEMPVAR;
5064 copy->varkind = STACKVAR;
5068 rd->interfaces[i][copy->type].type = copy->type;
5069 rd->interfaces[i][copy->type].flags |= copy->flags;
5073 /* check if interface slots at basic block begin must be saved */
5076 i = bptr->indepth - 1;
5077 for (copy = bptr->instack; copy; i--, copy = copy->prev) {
5078 rd->interfaces[i][copy->type].type = copy->type;
5079 if (copy->varkind == STACKVAR) {
5080 if (copy->flags & SAVEDVAR)
5081 rd->interfaces[i][copy->type].flags |= SAVEDVAR;
5088 superblockend = true;
5091 } /* while blocks */
5092 } while (repeat && !deadcode);
5094 #if defined(ENABLE_STATISTICS)
5096 if (m->basicblockcount > count_max_basic_blocks)
5097 count_max_basic_blocks = m->basicblockcount;
5098 count_basic_blocks += m->basicblockcount;
5099 if (m->instructioncount > count_max_javainstr) count_max_javainstr = m->instructioncount;
5100 count_javainstr += m->instructioncount;
5101 if (m->stackcount > count_upper_bound_new_stack)
5102 count_upper_bound_new_stack = m->stackcount;
5103 if ((new - m->stack) > count_max_new_stack)
5104 count_max_new_stack = (new - m->stack);
5106 b_count = m->basicblockcount;
5107 bptr = m->basicblocks;
5108 while (--b_count >= 0) {
5109 if (bptr->flags > BBREACHED) {
5110 if (bptr->indepth >= 10)
5111 count_block_stack[10]++;
5113 count_block_stack[bptr->indepth]++;
5116 count_block_size_distribution[len]++;
5118 count_block_size_distribution[10]++;
5120 count_block_size_distribution[11]++;
5122 count_block_size_distribution[12]++;
5124 count_block_size_distribution[13]++;
5126 count_block_size_distribution[14]++;
5128 count_block_size_distribution[15]++;
5130 count_block_size_distribution[16]++;
5132 count_block_size_distribution[17]++;
5138 count_analyse_iterations[0]++;
5139 else if (loops == 2)
5140 count_analyse_iterations[1]++;
5141 else if (loops == 3)
5142 count_analyse_iterations[2]++;
5143 else if (loops == 4)
5144 count_analyse_iterations[3]++;
5146 count_analyse_iterations[4]++;
5148 if (m->basicblockcount <= 5)
5149 count_method_bb_distribution[0]++;
5150 else if (m->basicblockcount <= 10)
5151 count_method_bb_distribution[1]++;
5152 else if (m->basicblockcount <= 15)
5153 count_method_bb_distribution[2]++;
5154 else if (m->basicblockcount <= 20)
5155 count_method_bb_distribution[3]++;
5156 else if (m->basicblockcount <= 30)
5157 count_method_bb_distribution[4]++;
5158 else if (m->basicblockcount <= 40)
5159 count_method_bb_distribution[5]++;
5160 else if (m->basicblockcount <= 50)
5161 count_method_bb_distribution[6]++;
5162 else if (m->basicblockcount <= 75)
5163 count_method_bb_distribution[7]++;
5165 count_method_bb_distribution[8]++;
5167 #endif /* defined(ENABLE_STATISTICS) */
5169 /* everything's ok */
5173 #if defined(ENABLE_VERIFIER)
5175 throw_stack_underflow:
5176 exceptions_throw_verifyerror(m, "Unable to pop operand off an empty stack");
5179 throw_stack_overflow:
5180 exceptions_throw_verifyerror(m, "Stack size too large");
5183 throw_stack_depth_error:
5184 exceptions_throw_verifyerror(m,"Stack depth mismatch");
5187 throw_stack_type_error:
5188 exceptions_throw_verifyerror_for_stack(m, expectedtype);
5191 throw_stack_category_error:
5192 exceptions_throw_verifyerror(m, "Attempt to split long or double on the stack");
5201 * These are local overrides for various environment variables in Emacs.
5202 * Please do not remove this and leave it at the end of the file, where
5203 * Emacs will automagically detect them.
5204 * ---------------------------------------------------------------------
5207 * indent-tabs-mode: t
5211 * vim:noexpandtab:sw=4:ts=4: