1 /* src/vm/jit/jit.h - code generation header
3 Copyright (C) 1996-2005, 2006, 2007 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
31 /* forward typedefs ***********************************************************/
33 typedef struct jitdata jitdata;
34 typedef struct stackelement stackelement;
35 typedef stackelement *stackptr;
36 typedef struct basicblock basicblock;
37 typedef struct instruction instruction;
38 typedef struct insinfo_inline insinfo_inline;
39 typedef struct exception_entry exception_entry;
45 #include "toolbox/chain.h"
47 #include "vm/global.h"
48 #include "vm/resolve.h"
50 #include "vm/jit/codegen-common.h"
51 #include "vm/jit/reg.h"
52 #include "vm/jit/replace.h"
53 #include "vm/jit/stacktrace.h"
55 #if defined(ENABLE_INLINING)
56 # include "vm/jit/inline/inline.h"
59 #include "vm/jit/ir/bytecode.h"
61 #if defined(ENABLE_LOOP)
62 # include "vm/jit/loop/loop.h"
64 #if defined(ENABLE_SSA)
65 # include "vm/jit/optimizing/lsra.h"
67 #if defined(ENABLE_LSRA)
68 # include "vm/jit/allocator/lsra.h"
71 #include "vm/jit/verify/typeinfo.h"
73 #include "vmcore/descriptor.h"
74 #include "vmcore/method.h"
75 #include "vmcore/references.h"
77 #if defined(ENABLE_STATISTICS)
78 # include "vmcore/statistics.h"
82 /* common jit/codegen macros **************************************************/
84 #if defined(ENABLE_STATISTICS)
85 # define COUNT(x) (x)++
86 # define COUNT_SPILLS /* use COUNT_(READ|WRITE)_SPILLS instead */
87 # define COUNT_READ_SPILLS(var) \
89 case TYPE_FLT: count_spills_read_flt++; break; \
90 case TYPE_DBL: count_spills_read_dbl++; break; \
91 default: count_spills_read_ila++; break; \
94 # define COUNT_WRITE_SPILLS(var) \
96 case TYPE_FLT: count_spills_write_flt++; break; \
97 case TYPE_DBL: count_spills_write_dbl++; break; \
98 default: count_spills_write_ila++; break; \
102 # define COUNT(x) /* nothing */
103 # define COUNT_SPILLS /* nothing */
104 # define COUNT_READ_SPILLS(x) /* nothing */
105 # define COUNT_WRITE_SPILLS(x) /* nothing */
108 typedef struct interface_info interface_info;
110 struct interface_info {
116 /* jitdata ********************************************************************/
119 methodinfo *m; /* methodinfo of the method compiled */
123 #if defined(ENABLE_LOOP)
126 #if defined(ENABLE_SSA) || defined(ENABLE_LSRA)
130 u4 flags; /* contains JIT compiler flags */
132 instruction *instructions; /* ICMDs, valid between parse and stack */
133 basicblock *basicblocks; /* start of basic block list */
134 stackelement *stack; /* XXX should become stack.c internal */
135 s4 instructioncount;/* XXX remove this? */
136 s4 basicblockcount; /* number of basic blocks */
137 s4 stackcount; /* number of stackelements to allocate */
138 /* (passed from parse to stack) */
140 varinfo *var; /* array of variables */
141 s4 vartop; /* next free index in var array */
143 s4 varcount; /* number of variables in var array */
144 s4 localcount; /* number of locals at start of var ar. */
145 s4 *local_map; /* map for renaming (de-coallescing) */
146 /* locals and keeping the coalescing info for simplereg. */
147 /* local_map[javaindex * 5 + type] = */
148 /* >= 0......index into jd->var, or */
149 /* UNUSED....this (javaindex,type) pair is not used */
151 s4 *reverselocalmap; /* map from CACAO varindex to javaindex */
152 /* (varindex must be < localcount) */
154 s4 maxlocals; /* max. number of javalocals */
156 interface_info *interface_map; /* interface variables (for simplereg) */
157 s4 maxinterfaces; /* max. number of interface variables */
159 s4 exceptiontablelength; /* exceptiontable length */
160 exception_entry *exceptiontable; /* the exceptiontable */
162 basicblock *returnblock; /* block containing the *RETURN */
163 /* (only use if returncount==1) */
164 s4 returncount; /* number of return instructions */
165 bool branchtoentry; /* true if first block is a target */
166 bool branchtoend; /* true if end dummy is a target */
169 #define FOR_EACH_BASICBLOCK(jd, it) \
170 for ((it) = (jd)->basicblocks; (it) != NULL; (it) = (it)->next)
174 #define JITDATA_FLAG_PARSE 0x00000001
175 #define JITDATA_FLAG_VERIFY 0x00000002
177 #define JITDATA_FLAG_INSTRUMENT 0x00000004
179 #define JITDATA_FLAG_IFCONV 0x00000008
180 #define JITDATA_FLAG_REORDER 0x00000010
181 #define JITDATA_FLAG_INLINE 0x00000020
183 #define JITDATA_FLAG_COUNTDOWN 0x00000100
185 #define JITDATA_FLAG_SHOWINTERMEDIATE 0x20000000
186 #define JITDATA_FLAG_SHOWDISASSEMBLE 0x40000000
187 #define JITDATA_FLAG_VERBOSECALL 0x80000000
190 #define JITDATA_HAS_FLAG_PARSE(jd) \
191 ((jd)->flags & JITDATA_FLAG_PARSE)
193 #define JITDATA_HAS_FLAG_VERIFY(jd) \
194 ((jd)->flags & JITDATA_FLAG_VERIFY)
196 #define JITDATA_HAS_FLAG_INSTRUMENT(jd) \
197 ((jd)->flags & JITDATA_FLAG_INSTRUMENT)
199 #define JITDATA_HAS_FLAG_IFCONV(jd) \
200 ((jd)->flags & JITDATA_FLAG_IFCONV)
202 #define JITDATA_HAS_FLAG_REORDER(jd) \
203 ((jd)->flags & JITDATA_FLAG_REORDER)
205 #define JITDATA_HAS_FLAG_INLINE(jd) \
206 ((jd)->flags & JITDATA_FLAG_INLINE)
208 #define JITDATA_HAS_FLAG_COUNTDOWN(jd) \
209 ((jd)->flags & JITDATA_FLAG_COUNTDOWN)
211 #define JITDATA_HAS_FLAG_SHOWINTERMEDIATE(jd) \
212 ((jd)->flags & JITDATA_FLAG_SHOWINTERMEDIATE)
214 #define JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd) \
215 ((jd)->flags & JITDATA_FLAG_SHOWDISASSEMBLE)
217 #define JITDATA_HAS_FLAG_VERBOSECALL(jd) \
218 ((jd)->flags & JITDATA_FLAG_VERBOSECALL)
221 /* exception_entry ************************************************************/
223 struct exception_entry {
227 classref_or_classinfo catchtype; /* catchtype of exc. (NULL == catchall) */
228 exception_entry *next; /* next in list of exceptions when */
229 /* loops are copied */
230 exception_entry *down; /* next exception_entry */
234 /* stack element structure ****************************************************/
238 #define SAVEDVAR 1 /* variable has to survive method invocations */
239 #define INMEMORY 2 /* variable stored in memory */
240 #define SAVREG 4 /* allocated to a saved register */
241 #define ARGREG 8 /* allocated to an arg register */
242 #define PASSTHROUGH 32 /* stackslot was passed-through by an ICMD */
243 #define PREALLOC 64 /* preallocated var like for ARGVARS. Used */
244 /* with the new var system */
245 #define INOUT 128 /* variable is an invar or/and an outvar */
247 #define IS_SAVEDVAR(x) ((x) & SAVEDVAR)
248 #define IS_INMEMORY(x) ((x) & INMEMORY)
253 #define UNDEFVAR 0 /* stack slot will become temp during regalloc*/
254 #define TEMPVAR 1 /* stack slot is temp register */
255 #define STACKVAR 2 /* stack slot is numbered stack slot */
256 #define LOCALVAR 3 /* stack slot is local variable */
257 #define ARGVAR 4 /* stack slot is argument variable */
260 struct stackelement {
261 stackptr prev; /* pointer to next element towards bottom */
262 instruction *creator; /* instruction that created this element */
263 s4 type; /* slot type of stack element */
264 s4 flags; /* flags (SAVED, INMEMORY) */
265 s4 varkind; /* kind of variable or register */
266 s4 varnum; /* number of variable */
269 /* macros for accessing variables *********************************************
271 Use VAROP for s1, s2, s3 and dst operands (eg. VAROP(iptr->s1)),
272 use VAR if you have the variable index (eg. VAR(iptr->sx.s23.s2.args[0])).
274 ******************************************************************************/
276 #define VAROP(v) (jd->var + (v).varindex)
277 #define VAR(i) (jd->var + (i))
279 static inline bool var_is_local(const jitdata *jd, s4 i) {
280 return (i < jd->localcount);
283 static inline bool var_is_prealloc(const jitdata *jd, s4 i) {
284 return ((i >= jd->localcount) && (jd->var[i].flags & PREALLOC));
287 static inline bool var_is_inout(const jitdata *jd, s4 i) {
288 const varinfo *v = jd->var + i;
289 return ((i >= jd->localcount) && !(v->flags & PREALLOC) && (v->flags & INOUT));
292 static inline bool var_is_temp(const jitdata *jd, s4 i) {
293 const varinfo *v = jd->var + i;
294 return ((i >= jd->localcount) && !(v->flags & PREALLOC) && !(v->flags & INOUT));
297 static inline bool var_is_saved(const jitdata *jd, s4 i) {
298 return (jd->var[i].flags & SAVEDVAR);
302 /**************************** instruction structure ***************************/
304 /* branch_target_t: used in TABLESWITCH tables */
307 s4 insindex; /* used in parse */
308 basicblock *block; /* valid after parse */
311 /* lookup_target_t: used in LOOKUPSWITCH tables */
314 s4 value; /* case value */
315 branch_target_t target; /* branch target, see above */
330 classref_or_classinfo c;
331 unresolved_class *uc;
332 ptrint constval; /* for PUT*CONST */
333 s4 tablelow; /* for TABLESWITCH */
334 u4 lookupcount; /* for LOOKUPSWITCH */
335 s4 retaddrnr; /* for ASTORE */
343 classref_or_classinfo c;
344 constant_FMIref *fmiref;
345 unresolved_method *um;
346 unresolved_field *uf;
347 insinfo_inline *inlineinfo; /* for INLINE_START/END */
348 s4 tablehigh; /* for TABLESWITCH */
349 branch_target_t lookupdefault; /* for LOOKUPSWITCH */
350 branch_target_t jsrtarget; /* for JSR */
351 s4 javaindex; /* for *STORE */
352 struct builtintable_entry *bte;
355 /*** val operand ***/
363 java_handle_t *stringconst; /* for ACONST with string */
364 classref_or_classinfo c; /* for ACONST with class */
367 /*** dst operand ***/
371 basicblock *block; /* valid after parse */
372 branch_target_t *table; /* for TABLESWITCH */
373 lookup_target_t *lookup; /* for LOOKUPSWITCH */
374 s4 insindex; /* used in parse */
377 /*** flags (32 bits) ***/
379 #define INS_FLAG_BASICBLOCK 0x01 /* marks a basic block start */
380 #define INS_FLAG_UNRESOLVED 0x02 /* contains unresolved field/meth/class*/
381 #define INS_FLAG_CLASS 0x04 /* for ACONST, PUT*CONST with class */
382 #define INS_FLAG_ARRAY 0x08 /* for CHECKCAST/INSTANCEOF with array */
383 #define INS_FLAG_CHECK 0x10 /* for *ALOAD|*ASTORE: check index */
384 /* for BUILTIN: check exception */
385 #define INS_FLAG_KILL_PREV 0x04 /* for *STORE, invalidate prev local */
386 #define INS_FLAG_KILL_NEXT 0x08 /* for *STORE, invalidate next local */
387 #define INS_FLAG_RETADDR 0x10 /* for ASTORE: op is a returnAddress */
389 #define INS_FLAG_ID_SHIFT 5
390 #define INS_FLAG_ID_MASK (~0 << INS_FLAG_ID_SHIFT)
396 /*** instruction ***/
398 /* The instruction format for the intermediate representation: */
402 u2 line; /* line number */
403 #if SIZEOF_VOID_P == 8
404 flags_operand_t flags; /* 4 bytes */
406 s1_operand_t s1; /* pointer-size */
409 s2_operand_t s2; /* pointer-size */
410 s3_operand_t s3; /* pointer-size */
412 val_operand_t val; /* long-size */
414 dst_operand_t dst; /* pointer-size */
415 #if SIZEOF_VOID_P == 4
416 flags_operand_t flags; /* 4 bytes */
421 #define INSTRUCTION_STARTS_BASICBLOCK(iptr) \
422 ((iptr)->flags.bits & INS_FLAG_BASICBLOCK)
424 #define INSTRUCTION_IS_RESOLVED(iptr) \
425 (!((iptr)->flags.bits & INS_FLAG_UNRESOLVED))
427 #define INSTRUCTION_IS_UNRESOLVED(iptr) \
428 ((iptr)->flags.bits & INS_FLAG_UNRESOLVED)
430 #define INSTRUCTION_MUST_CHECK(iptr) \
431 ((iptr)->flags.bits & INS_FLAG_CHECK)
433 #define INSTRUCTION_GET_FIELDREF(iptr,fref) \
435 if (iptr->flags.bits & INS_FLAG_UNRESOLVED) \
436 fref = iptr->sx.s23.s3.uf->fieldref; \
438 fref = iptr->sx.s23.s3.fmiref; \
441 #define INSTRUCTION_GET_METHODREF(iptr,mref) \
443 if (iptr->flags.bits & INS_FLAG_UNRESOLVED) \
444 mref = iptr->sx.s23.s3.um->methodref; \
446 mref = iptr->sx.s23.s3.fmiref; \
449 #define INSTRUCTION_GET_METHODDESC(iptr, md) \
451 if (iptr->flags.bits & INS_FLAG_UNRESOLVED) \
452 md = iptr->sx.s23.s3.um->methodref->parseddesc.md; \
454 md = iptr->sx.s23.s3.fmiref->parseddesc.md; \
457 /* additional info structs for special instructions ***************************/
459 /* for ICMD_INLINE_START and ICMD_INLINE_END */
461 struct insinfo_inline {
462 /* fields copied from the inlining tree ----------------------------------*/
463 insinfo_inline *parent; /* insinfo of the surrounding inlining, if any*/
464 methodinfo *method; /* the inlined method starting/ending here */
465 methodinfo *outer; /* the outer method suspended/resumed here */
466 s4 synclocal; /* local index used for synchronization */
467 bool synchronize; /* true if synchronization is needed */
468 s4 throughcount; /* total # of pass-through variables */
469 s4 paramcount; /* number of parameters of original call */
470 s4 stackvarscount; /* source stackdepth at INLINE_START */
471 s4 *stackvars; /* stack vars at INLINE_START */
473 /* fields set by inlining ------------------------------------------------*/
474 s4 *javalocals_start; /* javalocals at start of inlined body */
475 s4 *javalocals_end; /* javalocals after inlined body */
477 /* fields set by replacement point creation ------------------------------*/
478 #if defined(ENABLE_REPLACEMENT)
479 rplpoint *rp; /* replacement point at INLINE_START */
482 /* fields set by the codegen ---------------------------------------------*/
483 s4 startmpc; /* machine code offset of start of inlining */
487 /* basicblock *****************************************************************/
496 #define BBTYPECHECK_UNDEF 2
497 #define BBTYPECHECK_REACHED 3
499 #define BBTYPE_STD 0 /* standard basic block type */
500 #define BBTYPE_EXH 1 /* exception handler basic block type */
501 #define BBTYPE_SBR 2 /* subroutine basic block type */
503 #define BBFLAG_REPLACEMENT 0x01 /* put a replacement point at the start */
505 /* XXX basicblock wastes quite a lot of memory by having four flag fields */
506 /* (flags, bitflags, type and lflags). Probably the last three could be */
507 /* combined without loss of efficiency. The first one could be combined with */
508 /* the others by using bitfields. */
510 /* XXX "flags" should probably be called "state", as it is an integer state */
513 s4 nr; /* basic block number */
514 s4 flags; /* used during stack analysis, init with -1 */
515 s4 bitflags; /* OR of BBFLAG_... constants, init with 0 */
516 s4 type; /* basic block type (std, xhandler, subroutine*/
517 s4 lflags; /* used during loop copying, init with 0 */
519 s4 icount; /* number of intermediate code instructions */
520 instruction *iinstr; /* pointer to intermediate code instructions */
522 varinfo *inlocals; /* copy of locals on block entry */
523 s4 *javalocals; /* map from java locals to cacao variables[+] */
524 s4 *invars; /* array of in-variables at begin of block */
525 s4 *outvars; /* array of out-variables at end of block */
526 s4 indepth; /* stack depth at begin of basic block */
527 s4 outdepth; /* stack depth end of basic block */
528 s4 varstart; /* index of first non-invar block variable */
529 s4 varcount; /* number of non-invar block variables */
533 basicblock **predecessors; /* array of predecessor basic blocks */
534 basicblock **successors; /* array of successor basic blocks */
536 branchref *branchrefs; /* list of branches to be patched */
538 basicblock *next; /* used to build a BB list (instead of array) */
539 basicblock *copied_to; /* points to the copy of this basic block */
540 /* when loop nodes are copied */
541 basicblock *original; /* block of which this block is a clone */
542 /* NULL for the original block itself */
543 methodinfo *method; /* method this block belongs to */
544 insinfo_inline *inlineinfo; /* inlineinfo for the start of this block */
546 s4 mpc; /* machine code pc at start of block */
548 /* TODO: those fields are probably usefull for other passes as well. */
550 #if defined(ENABLE_SSA)
551 basicblock *idom; /* Immediate dominator, parent in dominator tree */
552 basicblock **domsuccessors;/* Children in dominator tree */
553 s4 domsuccessorcount;
555 basicblock **domfrontier; /* Dominance frontier */
558 basicblock **exhandlers; /* Exception handlers for this block */
560 basicblock **expredecessors; /* Blocks this block is exception handler for */
561 s4 expredecessorcount;
562 s4 exouts; /* Number of exceptional exits */
564 basicblock *subbasicblocks;
566 void *vp; /* Freely used by different passes */
570 #define FOR_EACH_SUCCESSOR(bptr, it) \
571 for ((it) = (bptr)->successors; (it) != (bptr)->successors + (bptr)->successorcount; ++(it))
573 #define FOR_EACH_PREDECESSOR(bptr, it) \
575 (it) = (bptr)->predecessors; \
576 (it) != (bptr)->predecessors + ((bptr)->predecessorcount < 0 ? 0 : (bptr)->predecessorcount); \
580 #define FOR_EACH_INSTRUCTION(bptr, it) \
581 for ((it) = (bptr)->iinstr; (it) != (bptr)->iinstr + (bptr)->icount; ++(it))
583 #if defined(ENABLE_SSA)
585 #define FOR_EACH_EXHANDLER(bptr, it) \
586 for ((it) = (bptr)->exhandlers; (it) != (bptr)->exhandlers + (bptr)->exhandlercount; ++(it))
588 #define FOR_EACH_EXPREDECESSOR(bptr, it) \
589 for ((it) = (bptr)->expredecessors; (it) != (bptr)->expredecessors + (bptr)->expredecessorcount; ++(it))
593 /* [+]...the javalocals array: This array is indexed by the javaindex (the */
594 /* local variable index ocurring in the original bytecode). An element */
595 /* javalocals[javaindex] encodes where to find the contents of the */
596 /* original variable at this point in the program. */
597 /* There are three cases for javalocals[javaindex]: */
598 /* >= 0.......it's an index into the jd->var array, where the */
599 /* CACAO variable corresponding to the original local */
601 /* UNUSED.....the original variable is not live at this point */
602 /* < UNUSED...the original variable contains a returnAddress at */
603 /* this point. The number of the block to return to can */
604 /* be calculated using RETADDR_FROM_JAVALOCAL: */
606 /* javalocals[javaindex] == JAVALOCAL_FROM_RETADDR(nr) */
607 /* RETADDR_FROM_JAVALOCAL(javalocals[javaindex]) == nr */
609 #define JAVALOCAL_FROM_RETADDR(nr) (UNUSED - (1 + (nr)))
610 #define RETADDR_FROM_JAVALOCAL(jl) (UNUSED - (1 + (jl)))
613 /* Macro for initializing newly allocated basic block's. It does not
614 need to zero fields, as we zero out the whole basic block array. */
616 #define BASICBLOCK_INIT(bptr,m) \
620 bptr->type = BBTYPE_STD; \
621 bptr->method = (m); \
624 static inline bool basicblock_reached(const basicblock *bptr) {
625 return (bptr->flags >= BBREACHED);
628 /* data-flow constants for the ICMD table ************************************/
635 #define DF_DST_BASE 4 /* from this value on, iptr->dst is a variable */
637 #define DF_0_TO_1 (DF_DST_BASE + 0)
638 #define DF_1_TO_1 (DF_DST_BASE + 1)
639 #define DF_2_TO_1 (DF_DST_BASE + 2)
640 #define DF_3_TO_1 (DF_DST_BASE + 3)
641 #define DF_N_TO_1 (DF_DST_BASE + 4)
643 #define DF_INVOKE (DF_DST_BASE + 5)
644 #define DF_BUILTIN (DF_DST_BASE + 6)
646 #define DF_COPY (DF_DST_BASE + 7)
647 #define DF_MOVE (DF_DST_BASE + 8)
653 #define DF_DUP2_X1 -1
654 #define DF_DUP2_X2 -1
657 /* special data-flow recognized by verify/generate.pl: */
658 #define DF_LOAD DF_COPY
659 #define DF_STORE DF_MOVE
660 #define DF_IINC DF_1_TO_1
661 #define DF_POP DF_1_TO_0
662 #define DF_POP2 DF_2_TO_0
665 /* control-flow constants for the ICMD table *********************************/
670 #define CF_END_BASE 2 /* from here on, they mark the end of a superblock */
672 #define CF_END (CF_END_BASE + 0)
673 #define CF_GOTO (CF_END_BASE + 1)
674 #define CF_TABLE (CF_END_BASE + 2)
675 #define CF_LOOKUP (CF_END_BASE + 3)
676 #define CF_JSR (CF_END_BASE + 4)
677 #define CF_RET (CF_END_BASE + 5)
680 /* flag constants for the ICMD table *****************************************/
682 #define ICMDTABLE_PEI 0x0001 /* ICMD may throw an exception */
683 #define ICMDTABLE_CALLS 0x0002 /* needs registers to be saved, may call */
686 /* ICMD table entry **********************************************************/
688 typedef struct icmdtable_entry_t icmdtable_entry_t;
690 struct icmdtable_entry_t {
692 char *name; /* name, without ICMD_ prefix */
694 s4 dataflow; /* a DF_ constant, see above */
695 s4 controlflow; /* a CF_ constant, see above */
696 s4 flags; /* a combination of ICMDTABLE_ flags */
700 /* the ICMD table ************************************************************/
702 extern icmdtable_entry_t icmd_table[256];
705 /********** JavaVM operation codes (sorted) and instruction lengths ***********/
710 ICMD_ACONST = BC_aconst_null,
714 ICMD_ICONST = BC_iconst_0,
725 ICMD_LCONST = BC_lconst_0,
729 ICMD_FCONST = BC_fconst_0,
734 ICMD_DCONST = BC_dconst_0,
744 /* Order of LOAD instructions must be equal to order of TYPE_*
747 ICMD_ILOAD = BC_iload,
748 ICMD_LLOAD = BC_lload,
749 ICMD_FLOAD = BC_fload,
750 ICMD_DLOAD = BC_dload,
751 ICMD_ALOAD = BC_aload,
762 ICMD_IUSHRCONST = 34,
775 ICMD_LUSHRCONST = 44,
779 ICMD_IALOAD = BC_iaload,
780 ICMD_LALOAD = BC_laload,
781 ICMD_FALOAD = BC_faload,
782 ICMD_DALOAD = BC_daload,
783 ICMD_AALOAD = BC_aaload,
784 ICMD_BALOAD = BC_baload,
785 ICMD_CALOAD = BC_caload,
786 ICMD_SALOAD = BC_saload,
788 /* Order of STORE instructions must be equal to order of TYPE_*
791 ICMD_ISTORE = BC_istore,
792 ICMD_LSTORE = BC_lstore,
793 ICMD_FSTORE = BC_fstore,
794 ICMD_DSTORE = BC_dstore,
795 ICMD_ASTORE = BC_astore,
820 ICMD_IASTORE = BC_iastore,
821 ICMD_LASTORE = BC_lastore,
822 ICMD_FASTORE = BC_fastore,
823 ICMD_DASTORE = BC_dastore,
824 ICMD_AASTORE = BC_aastore,
825 ICMD_BASTORE = BC_bastore,
826 ICMD_CASTORE = BC_castore,
827 ICMD_SASTORE = BC_sastore,
832 ICMD_DUP_X1 = BC_dup_x1,
833 ICMD_DUP_X2 = BC_dup_x2,
835 ICMD_DUP2_X1 = BC_dup2_x1,
836 ICMD_DUP2_X2 = BC_dup2_x2,
873 ICMD_IUSHR = BC_iushr,
874 ICMD_LUSHR = BC_lushr,
898 ICMD_INT2BYTE = BC_int2byte,
899 ICMD_INT2CHAR = BC_int2char,
900 ICMD_INT2SHORT = BC_int2short,
903 ICMD_FCMPL = BC_fcmpl,
904 ICMD_FCMPG = BC_fcmpg,
905 ICMD_DCMPL = BC_dcmpl,
906 ICMD_DCMPG = BC_dcmpg,
915 ICMD_IF_ICMPEQ = BC_if_icmpeq,
916 ICMD_IF_ICMPNE = BC_if_icmpne,
917 ICMD_IF_ICMPLT = BC_if_icmplt,
918 ICMD_IF_ICMPGE = BC_if_icmpge,
919 ICMD_IF_ICMPGT = BC_if_icmpgt,
920 ICMD_IF_ICMPLE = BC_if_icmple,
921 ICMD_IF_ACMPEQ = BC_if_acmpeq,
922 ICMD_IF_ACMPNE = BC_if_acmpne,
928 ICMD_TABLESWITCH = BC_tableswitch,
929 ICMD_LOOKUPSWITCH = BC_lookupswitch,
931 ICMD_IRETURN = BC_ireturn,
932 ICMD_LRETURN = BC_lreturn,
933 ICMD_FRETURN = BC_freturn,
934 ICMD_DRETURN = BC_dreturn,
935 ICMD_ARETURN = BC_areturn,
936 ICMD_RETURN = BC_return,
938 ICMD_GETSTATIC = BC_getstatic,
939 ICMD_PUTSTATIC = BC_putstatic,
940 ICMD_GETFIELD = BC_getfield,
941 ICMD_PUTFIELD = BC_putfield,
943 ICMD_INVOKEVIRTUAL = BC_invokevirtual,
944 ICMD_INVOKESPECIAL = BC_invokespecial,
945 ICMD_INVOKESTATIC = BC_invokestatic,
946 ICMD_INVOKEINTERFACE = BC_invokeinterface,
951 ICMD_NEWARRAY = BC_newarray,
952 ICMD_ANEWARRAY = BC_anewarray,
954 ICMD_ARRAYLENGTH = BC_arraylength,
956 ICMD_ATHROW = BC_athrow,
958 ICMD_CHECKCAST = BC_checkcast,
959 ICMD_INSTANCEOF = BC_instanceof,
961 ICMD_MONITORENTER = BC_monitorenter,
962 ICMD_MONITOREXIT = BC_monitorexit,
966 ICMD_MULTIANEWARRAY = BC_multianewarray,
968 ICMD_IFNULL = BC_ifnull,
969 ICMD_IFNONNULL = BC_ifnonnull,
975 ICMD_IASTORECONST = 204,
976 ICMD_LASTORECONST = 205,
977 ICMD_FASTORECONST = 206,
978 ICMD_DASTORECONST = 207,
979 ICMD_AASTORECONST = 208,
980 ICMD_BASTORECONST = 209,
981 ICMD_CASTORECONST = 210,
982 ICMD_SASTORECONST = 211,
984 ICMD_PUTSTATICCONST = 212,
985 ICMD_PUTFIELDCONST = 213,
990 ICMD_INLINE_START = 251, /* instruction before inlined method */
991 ICMD_INLINE_END = 252, /* instruction after inlined method */
992 ICMD_INLINE_BODY = 253, /* start of inlined body */
994 ICMD_BUILTIN = 255 /* internal opcode */
997 /* Additional instruction accessors */
999 methoddesc *instruction_call_site(const instruction *iptr);
1001 static inline bool instruction_has_dst(const instruction *iptr) {
1003 (icmd_table[iptr->opc].dataflow == DF_INVOKE) ||
1004 (icmd_table[iptr->opc].dataflow == DF_BUILTIN)
1006 return instruction_call_site(iptr)->returntype.type != TYPE_VOID;
1008 return icmd_table[iptr->opc].dataflow >= DF_DST_BASE;
1012 /***************************** register types *********************************/
1014 #define REG_RES 0 /* reserved register for OS or code generator */
1015 #define REG_RET 1 /* return value register */
1016 #define REG_EXC 2 /* exception value register */
1017 #define REG_SAV 3 /* (callee) saved register */
1018 #define REG_TMP 4 /* scratch temporary register (caller saved) */
1019 #define REG_ARG 5 /* argument register (caller saved) */
1021 #define REG_END -1 /* last entry in tables */
1023 #define PARAMMODE_NUMBERED 0
1024 #define PARAMMODE_STUFFED 1
1027 /* function prototypes ********************************************************/
1029 /* compiler initialisation */
1030 void jit_init(void);
1032 /* compiler finalisation */
1033 void jit_close(void);
1035 /* create a new jitdata */
1036 jitdata *jit_jitdata_new(methodinfo *m);
1038 /* compile a method with jit compiler */
1039 u1 *jit_compile(methodinfo *m);
1040 u1 *jit_recompile(methodinfo *m);
1042 void jit_invalidate_code(methodinfo *m);
1043 codeinfo *jit_get_current_code(methodinfo *m);
1044 void jit_request_optimization(methodinfo *m);
1046 /* patch the method entrypoint */
1047 #if !defined(JIT_COMPILER_VIA_SIGNAL)
1048 u1 *jit_asm_compile(methodinfo *m, u1 *mptr, u1 *sp, u1 *ra);
1050 void *jit_compile_handle(methodinfo *m, void *pv, void *ra, void *mptr);
1052 s4 jit_complement_condition(s4 opcode);
1054 void jit_renumber_basicblocks(jitdata *jd);
1055 #if !defined(NDEBUG)
1056 void jit_check_basicblock_numbers(jitdata *jd);
1060 /* machine dependent functions ************************************************/
1062 #if defined(ENABLE_JIT)
1066 #if defined(ENABLE_INTRP)
1067 void intrp_md_init(void);
1070 void *md_jit_method_patch_address(void *pv, void *ra, void *mptr);
1076 * These are local overrides for various environment variables in Emacs.
1077 * Please do not remove this and leave it at the end of the file, where
1078 * Emacs will automagically detect them.
1079 * ---------------------------------------------------------------------
1082 * indent-tabs-mode: t
1086 * vim:noexpandtab:sw=4:ts=4: