1 /* src/vm/jit/jit.h - code generation header
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 /* forward typedefs ***********************************************************/
31 typedef struct jitdata jitdata;
32 typedef struct basicblock basicblock;
33 typedef struct instruction instruction;
34 typedef struct insinfo_inline insinfo_inline;
35 typedef struct exception_entry exception_entry;
41 #include "toolbox/chain.h"
43 #include "vm/global.h"
44 #include "vm/resolve.h"
46 #include "vm/jit/codegen-common.h"
47 #include "vm/jit/reg.h"
48 #include "vm/jit/replace.h"
49 #include "vm/jit/stack.h"
50 #include "vm/jit/stacktrace.h"
52 #if defined(ENABLE_INLINING)
53 # include "vm/jit/inline/inline.h"
56 #include "vm/jit/ir/bytecode.h"
58 #if defined(ENABLE_LOOP)
59 # include "vm/jit/loop/loop.h"
61 #if defined(ENABLE_SSA)
62 # include "vm/jit/optimizing/lsra.h"
64 #if defined(ENABLE_LSRA)
65 # include "vm/jit/allocator/lsra.h"
68 #include "vm/jit/verify/typeinfo.h"
70 #include "vmcore/method.h"
71 #include "vmcore/references.h"
73 #if defined(ENABLE_STATISTICS)
74 # include "vmcore/statistics.h"
78 /* common jit/codegen macros **************************************************/
80 #if defined(ENABLE_STATISTICS)
81 # define COUNT(x) (x)++
82 # define COUNT_SPILLS /* use COUNT_(READ|WRITE)_SPILLS instead */
83 # define COUNT_READ_SPILLS(var) \
85 case TYPE_FLT: count_spills_read_flt++; break; \
86 case TYPE_DBL: count_spills_read_dbl++; break; \
87 default: count_spills_read_ila++; break; \
90 # define COUNT_WRITE_SPILLS(var) \
92 case TYPE_FLT: count_spills_write_flt++; break; \
93 case TYPE_DBL: count_spills_write_dbl++; break; \
94 default: count_spills_write_ila++; break; \
98 # define COUNT(x) /* nothing */
99 # define COUNT_SPILLS /* nothing */
100 # define COUNT_READ_SPILLS(x) /* nothing */
101 # define COUNT_WRITE_SPILLS(x) /* nothing */
104 typedef struct interface_info interface_info;
106 struct interface_info {
112 /* jitdata ********************************************************************/
115 methodinfo *m; /* methodinfo of the method compiled */
119 #if defined(ENABLE_LOOP)
122 #if defined(ENABLE_SSA) || defined(ENABLE_LSRA)
126 u4 flags; /* contains JIT compiler flags */
128 instruction *instructions; /* ICMDs, valid between parse and stack */
129 basicblock *basicblocks; /* start of basic block list */
130 stackelement_t *stack; /* XXX should become stack.c internal */
131 s4 instructioncount;/* XXX remove this? */
132 s4 basicblockcount; /* number of basic blocks */
133 s4 stackcount; /* number of stackelements to allocate */
134 /* (passed from parse to stack) */
136 varinfo *var; /* array of variables */
137 s4 vartop; /* next free index in var array */
139 s4 varcount; /* number of variables in var array */
140 s4 localcount; /* number of locals at start of var ar. */
141 s4 *local_map; /* map for renaming (de-coallescing) */
142 /* locals and keeping the coalescing info for simplereg. */
143 /* local_map[javaindex * 5 + type] = */
144 /* >= 0......index into jd->var, or */
145 /* UNUSED....this (javaindex,type) pair is not used */
147 s4 *reverselocalmap; /* map from CACAO varindex to javaindex */
148 /* (varindex must be < localcount) */
150 s4 maxlocals; /* max. number of javalocals */
152 interface_info *interface_map; /* interface variables (for simplereg) */
153 s4 maxinterfaces; /* max. number of interface variables */
155 s4 exceptiontablelength; /* exceptiontable length */
156 exception_entry *exceptiontable; /* the exceptiontable */
158 basicblock *returnblock; /* block containing the *RETURN */
159 /* (only use if returncount==1) */
160 s4 returncount; /* number of return instructions */
161 bool branchtoentry; /* true if first block is a target */
162 bool branchtoend; /* true if end dummy is a target */
165 #define FOR_EACH_BASICBLOCK(jd, it) \
166 for ((it) = (jd)->basicblocks; (it) != NULL; (it) = (it)->next)
170 #define JITDATA_FLAG_PARSE 0x00000001
171 #define JITDATA_FLAG_VERIFY 0x00000002
173 #define JITDATA_FLAG_INSTRUMENT 0x00000004
175 #define JITDATA_FLAG_IFCONV 0x00000008
176 #define JITDATA_FLAG_REORDER 0x00000010
177 #define JITDATA_FLAG_INLINE 0x00000020
179 #define JITDATA_FLAG_COUNTDOWN 0x00000100
181 #define JITDATA_FLAG_SHOWINTERMEDIATE 0x20000000
182 #define JITDATA_FLAG_SHOWDISASSEMBLE 0x40000000
183 #define JITDATA_FLAG_VERBOSECALL 0x80000000
186 #define JITDATA_HAS_FLAG_PARSE(jd) \
187 ((jd)->flags & JITDATA_FLAG_PARSE)
189 #define JITDATA_HAS_FLAG_VERIFY(jd) \
190 ((jd)->flags & JITDATA_FLAG_VERIFY)
192 #define JITDATA_HAS_FLAG_INSTRUMENT(jd) \
193 ((jd)->flags & JITDATA_FLAG_INSTRUMENT)
195 #define JITDATA_HAS_FLAG_IFCONV(jd) \
196 ((jd)->flags & JITDATA_FLAG_IFCONV)
198 #define JITDATA_HAS_FLAG_REORDER(jd) \
199 ((jd)->flags & JITDATA_FLAG_REORDER)
201 #define JITDATA_HAS_FLAG_INLINE(jd) \
202 ((jd)->flags & JITDATA_FLAG_INLINE)
204 #define JITDATA_HAS_FLAG_COUNTDOWN(jd) \
205 ((jd)->flags & JITDATA_FLAG_COUNTDOWN)
207 #define JITDATA_HAS_FLAG_SHOWINTERMEDIATE(jd) \
208 ((jd)->flags & JITDATA_FLAG_SHOWINTERMEDIATE)
210 #define JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd) \
211 ((jd)->flags & JITDATA_FLAG_SHOWDISASSEMBLE)
213 #define JITDATA_HAS_FLAG_VERBOSECALL(jd) \
214 ((jd)->flags & JITDATA_FLAG_VERBOSECALL)
217 /* exception_entry ************************************************************/
219 struct exception_entry {
223 classref_or_classinfo catchtype; /* catchtype of exc. (NULL == catchall) */
224 exception_entry *next; /* next in list of exceptions when */
225 /* loops are copied */
226 exception_entry *down; /* next exception_entry */
230 /* macros for accessing variables *********************************************
232 Use VAROP for s1, s2, s3 and dst operands (eg. VAROP(iptr->s1)),
233 use VAR if you have the variable index (eg. VAR(iptr->sx.s23.s2.args[0])).
235 ******************************************************************************/
237 #define VAROP(v) (jd->var + (v).varindex)
238 #define VAR(i) (jd->var + (i))
240 static inline bool var_is_local(const jitdata *jd, s4 i) {
241 return (i < jd->localcount);
244 static inline bool var_is_prealloc(const jitdata *jd, s4 i) {
245 return ((i >= jd->localcount) && (jd->var[i].flags & PREALLOC));
248 static inline bool var_is_inout(const jitdata *jd, s4 i) {
249 const varinfo *v = jd->var + i;
250 return ((i >= jd->localcount) && !(v->flags & PREALLOC) && (v->flags & INOUT));
253 static inline bool var_is_temp(const jitdata *jd, s4 i) {
254 const varinfo *v = jd->var + i;
255 return ((i >= jd->localcount) && !(v->flags & PREALLOC) && !(v->flags & INOUT));
258 static inline bool var_is_saved(const jitdata *jd, s4 i) {
259 return (jd->var[i].flags & SAVEDVAR);
263 /**************************** instruction structure ***************************/
265 /* branch_target_t: used in TABLESWITCH tables */
268 s4 insindex; /* used in parse */
269 basicblock *block; /* valid after parse */
272 /* lookup_target_t: used in LOOKUPSWITCH tables */
275 s4 value; /* case value */
276 branch_target_t target; /* branch target, see above */
291 classref_or_classinfo c;
292 unresolved_class *uc;
293 ptrint constval; /* for PUT*CONST */
294 s4 tablelow; /* for TABLESWITCH */
295 u4 lookupcount; /* for LOOKUPSWITCH */
296 s4 retaddrnr; /* for ASTORE */
304 classref_or_classinfo c;
305 constant_FMIref *fmiref;
306 unresolved_method *um;
307 unresolved_field *uf;
308 insinfo_inline *inlineinfo; /* for INLINE_START/END */
309 s4 tablehigh; /* for TABLESWITCH */
310 branch_target_t lookupdefault; /* for LOOKUPSWITCH */
311 branch_target_t jsrtarget; /* for JSR */
312 s4 javaindex; /* for *STORE */
313 struct builtintable_entry *bte;
316 /*** val operand ***/
324 java_handle_t *stringconst; /* for ACONST with string */
325 classref_or_classinfo c; /* for ACONST with class */
328 /*** dst operand ***/
332 basicblock *block; /* valid after parse */
333 branch_target_t *table; /* for TABLESWITCH */
334 lookup_target_t *lookup; /* for LOOKUPSWITCH */
335 s4 insindex; /* used in parse */
338 /*** flags (32 bits) ***/
340 #define INS_FLAG_BASICBLOCK 0x01 /* marks a basic block start */
341 #define INS_FLAG_UNRESOLVED 0x02 /* contains unresolved field/meth/class*/
342 #define INS_FLAG_CLASS 0x04 /* for ACONST, PUT*CONST with class */
343 #define INS_FLAG_ARRAY 0x08 /* for CHECKCAST/INSTANCEOF with array */
344 #define INS_FLAG_CHECK 0x10 /* for *ALOAD|*ASTORE: check index */
345 /* for BUILTIN: check exception */
346 #define INS_FLAG_KILL_PREV 0x04 /* for *STORE, invalidate prev local */
347 #define INS_FLAG_KILL_NEXT 0x08 /* for *STORE, invalidate next local */
348 #define INS_FLAG_RETADDR 0x10 /* for ASTORE: op is a returnAddress */
350 #define INS_FLAG_ID_SHIFT 5
351 #define INS_FLAG_ID_MASK (~0 << INS_FLAG_ID_SHIFT)
357 /*** instruction ***/
359 /* The instruction format for the intermediate representation: */
363 u2 line; /* line number */
364 #if SIZEOF_VOID_P == 8
365 flags_operand_t flags; /* 4 bytes */
367 s1_operand_t s1; /* pointer-size */
370 s2_operand_t s2; /* pointer-size */
371 s3_operand_t s3; /* pointer-size */
373 val_operand_t val; /* long-size */
375 dst_operand_t dst; /* pointer-size */
376 #if SIZEOF_VOID_P == 4
377 flags_operand_t flags; /* 4 bytes */
382 #define INSTRUCTION_STARTS_BASICBLOCK(iptr) \
383 ((iptr)->flags.bits & INS_FLAG_BASICBLOCK)
385 #define INSTRUCTION_IS_RESOLVED(iptr) \
386 (!((iptr)->flags.bits & INS_FLAG_UNRESOLVED))
388 #define INSTRUCTION_IS_UNRESOLVED(iptr) \
389 ((iptr)->flags.bits & INS_FLAG_UNRESOLVED)
391 #define INSTRUCTION_MUST_CHECK(iptr) \
392 ((iptr)->flags.bits & INS_FLAG_CHECK)
394 #define INSTRUCTION_GET_FIELDREF(iptr,fref) \
396 if (iptr->flags.bits & INS_FLAG_UNRESOLVED) \
397 fref = iptr->sx.s23.s3.uf->fieldref; \
399 fref = iptr->sx.s23.s3.fmiref; \
402 #define INSTRUCTION_GET_METHODREF(iptr,mref) \
404 if (iptr->flags.bits & INS_FLAG_UNRESOLVED) \
405 mref = iptr->sx.s23.s3.um->methodref; \
407 mref = iptr->sx.s23.s3.fmiref; \
410 #define INSTRUCTION_GET_METHODDESC(iptr, md) \
412 if (iptr->flags.bits & INS_FLAG_UNRESOLVED) \
413 md = iptr->sx.s23.s3.um->methodref->parseddesc.md; \
415 md = iptr->sx.s23.s3.fmiref->parseddesc.md; \
418 /* additional info structs for special instructions ***************************/
420 /* for ICMD_INLINE_START and ICMD_INLINE_END */
422 struct insinfo_inline {
423 /* fields copied from the inlining tree ----------------------------------*/
424 insinfo_inline *parent; /* insinfo of the surrounding inlining, if any*/
425 methodinfo *method; /* the inlined method starting/ending here */
426 methodinfo *outer; /* the outer method suspended/resumed here */
427 s4 synclocal; /* local index used for synchronization */
428 bool synchronize; /* true if synchronization is needed */
429 s4 throughcount; /* total # of pass-through variables */
430 s4 paramcount; /* number of parameters of original call */
431 s4 stackvarscount; /* source stackdepth at INLINE_START */
432 s4 *stackvars; /* stack vars at INLINE_START */
434 /* fields set by inlining ------------------------------------------------*/
435 s4 *javalocals_start; /* javalocals at start of inlined body */
436 s4 *javalocals_end; /* javalocals after inlined body */
438 /* fields set by replacement point creation ------------------------------*/
439 #if defined(ENABLE_REPLACEMENT)
440 rplpoint *rp; /* replacement point at INLINE_START */
443 /* fields set by the codegen ---------------------------------------------*/
444 s4 startmpc; /* machine code offset of start of inlining */
448 /* basicblock *****************************************************************/
457 #define BBTYPECHECK_UNDEF 2
458 #define BBTYPECHECK_REACHED 3
460 #define BBTYPE_STD 0 /* standard basic block type */
461 #define BBTYPE_EXH 1 /* exception handler basic block type */
462 #define BBTYPE_SBR 2 /* subroutine basic block type */
464 #define BBFLAG_REPLACEMENT 0x01 /* put a replacement point at the start */
466 /* XXX basicblock wastes quite a lot of memory by having four flag fields */
467 /* (flags, bitflags, type and lflags). Probably the last three could be */
468 /* combined without loss of efficiency. The first one could be combined with */
469 /* the others by using bitfields. */
471 /* XXX "flags" should probably be called "state", as it is an integer state */
474 s4 nr; /* basic block number */
475 s4 flags; /* used during stack analysis, init with -1 */
476 s4 bitflags; /* OR of BBFLAG_... constants, init with 0 */
477 s4 type; /* basic block type (std, xhandler, subroutine*/
478 s4 lflags; /* used during loop copying, init with 0 */
480 s4 icount; /* number of intermediate code instructions */
481 instruction *iinstr; /* pointer to intermediate code instructions */
483 varinfo *inlocals; /* copy of locals on block entry */
484 s4 *javalocals; /* map from java locals to cacao variables[+] */
485 s4 *invars; /* array of in-variables at begin of block */
486 s4 *outvars; /* array of out-variables at end of block */
487 s4 indepth; /* stack depth at begin of basic block */
488 s4 outdepth; /* stack depth end of basic block */
489 s4 varstart; /* index of first non-invar block variable */
490 s4 varcount; /* number of non-invar block variables */
494 basicblock **predecessors; /* array of predecessor basic blocks */
495 basicblock **successors; /* array of successor basic blocks */
497 branchref *branchrefs; /* list of branches to be patched */
499 basicblock *next; /* used to build a BB list (instead of array) */
500 basicblock *copied_to; /* points to the copy of this basic block */
501 /* when loop nodes are copied */
502 basicblock *original; /* block of which this block is a clone */
503 /* NULL for the original block itself */
504 methodinfo *method; /* method this block belongs to */
505 insinfo_inline *inlineinfo; /* inlineinfo for the start of this block */
507 s4 mpc; /* machine code pc at start of block */
509 /* TODO: those fields are probably usefull for other passes as well. */
511 #if defined(ENABLE_SSA)
512 basicblock *idom; /* Immediate dominator, parent in dominator tree */
513 basicblock **domsuccessors;/* Children in dominator tree */
514 s4 domsuccessorcount;
516 basicblock **domfrontier; /* Dominance frontier */
519 basicblock **exhandlers; /* Exception handlers for this block */
521 basicblock **expredecessors; /* Blocks this block is exception handler for */
522 s4 expredecessorcount;
523 s4 exouts; /* Number of exceptional exits */
525 basicblock *subbasicblocks;
527 void *vp; /* Freely used by different passes */
531 #define FOR_EACH_SUCCESSOR(bptr, it) \
532 for ((it) = (bptr)->successors; (it) != (bptr)->successors + (bptr)->successorcount; ++(it))
534 #define FOR_EACH_PREDECESSOR(bptr, it) \
536 (it) = (bptr)->predecessors; \
537 (it) != (bptr)->predecessors + ((bptr)->predecessorcount < 0 ? 0 : (bptr)->predecessorcount); \
541 #define FOR_EACH_INSTRUCTION(bptr, it) \
542 for ((it) = (bptr)->iinstr; (it) != (bptr)->iinstr + (bptr)->icount; ++(it))
544 #if defined(ENABLE_SSA)
546 #define FOR_EACH_EXHANDLER(bptr, it) \
547 for ((it) = (bptr)->exhandlers; (it) != (bptr)->exhandlers + (bptr)->exhandlercount; ++(it))
549 #define FOR_EACH_EXPREDECESSOR(bptr, it) \
550 for ((it) = (bptr)->expredecessors; (it) != (bptr)->expredecessors + (bptr)->expredecessorcount; ++(it))
554 /* [+]...the javalocals array: This array is indexed by the javaindex (the */
555 /* local variable index ocurring in the original bytecode). An element */
556 /* javalocals[javaindex] encodes where to find the contents of the */
557 /* original variable at this point in the program. */
558 /* There are three cases for javalocals[javaindex]: */
559 /* >= 0.......it's an index into the jd->var array, where the */
560 /* CACAO variable corresponding to the original local */
562 /* UNUSED.....the original variable is not live at this point */
563 /* < UNUSED...the original variable contains a returnAddress at */
564 /* this point. The number of the block to return to can */
565 /* be calculated using RETADDR_FROM_JAVALOCAL: */
567 /* javalocals[javaindex] == JAVALOCAL_FROM_RETADDR(nr) */
568 /* RETADDR_FROM_JAVALOCAL(javalocals[javaindex]) == nr */
570 #define JAVALOCAL_FROM_RETADDR(nr) (UNUSED - (1 + (nr)))
571 #define RETADDR_FROM_JAVALOCAL(jl) (UNUSED - (1 + (jl)))
574 /* Macro for initializing newly allocated basic block's. It does not
575 need to zero fields, as we zero out the whole basic block array. */
577 #define BASICBLOCK_INIT(bptr,m) \
581 bptr->type = BBTYPE_STD; \
582 bptr->method = (m); \
585 static inline bool basicblock_reached(const basicblock *bptr) {
586 return (bptr->flags >= BBREACHED);
589 /* data-flow constants for the ICMD table ************************************/
596 #define DF_DST_BASE 4 /* from this value on, iptr->dst is a variable */
598 #define DF_0_TO_1 (DF_DST_BASE + 0)
599 #define DF_1_TO_1 (DF_DST_BASE + 1)
600 #define DF_2_TO_1 (DF_DST_BASE + 2)
601 #define DF_3_TO_1 (DF_DST_BASE + 3)
602 #define DF_N_TO_1 (DF_DST_BASE + 4)
604 #define DF_INVOKE (DF_DST_BASE + 5)
605 #define DF_BUILTIN (DF_DST_BASE + 6)
607 #define DF_COPY (DF_DST_BASE + 7)
608 #define DF_MOVE (DF_DST_BASE + 8)
614 #define DF_DUP2_X1 -1
615 #define DF_DUP2_X2 -1
618 /* special data-flow recognized by verify/generate.pl: */
619 #define DF_LOAD DF_COPY
620 #define DF_STORE DF_MOVE
621 #define DF_IINC DF_1_TO_1
622 #define DF_POP DF_1_TO_0
623 #define DF_POP2 DF_2_TO_0
626 /* control-flow constants for the ICMD table *********************************/
631 #define CF_END_BASE 2 /* from here on, they mark the end of a superblock */
633 #define CF_END (CF_END_BASE + 0)
634 #define CF_GOTO (CF_END_BASE + 1)
635 #define CF_TABLE (CF_END_BASE + 2)
636 #define CF_LOOKUP (CF_END_BASE + 3)
637 #define CF_JSR (CF_END_BASE + 4)
638 #define CF_RET (CF_END_BASE + 5)
641 /* flag constants for the ICMD table *****************************************/
643 #define ICMDTABLE_PEI 0x0001 /* ICMD may throw an exception */
644 #define ICMDTABLE_CALLS 0x0002 /* needs registers to be saved, may call */
647 /* ICMD table entry **********************************************************/
649 typedef struct icmdtable_entry_t icmdtable_entry_t;
651 struct icmdtable_entry_t {
653 char *name; /* name, without ICMD_ prefix */
655 s4 dataflow; /* a DF_ constant, see above */
656 s4 controlflow; /* a CF_ constant, see above */
657 s4 flags; /* a combination of ICMDTABLE_ flags */
661 /* the ICMD table ************************************************************/
663 extern icmdtable_entry_t icmd_table[256];
666 /********** JavaVM operation codes (sorted) and instruction lengths ***********/
671 ICMD_ACONST = BC_aconst_null,
675 ICMD_ICONST = BC_iconst_0,
686 ICMD_LCONST = BC_lconst_0,
690 ICMD_FCONST = BC_fconst_0,
695 ICMD_DCONST = BC_dconst_0,
705 /* Order of LOAD instructions must be equal to order of TYPE_*
708 ICMD_ILOAD = BC_iload,
709 ICMD_LLOAD = BC_lload,
710 ICMD_FLOAD = BC_fload,
711 ICMD_DLOAD = BC_dload,
712 ICMD_ALOAD = BC_aload,
723 ICMD_IUSHRCONST = 34,
736 ICMD_LUSHRCONST = 44,
740 ICMD_IALOAD = BC_iaload,
741 ICMD_LALOAD = BC_laload,
742 ICMD_FALOAD = BC_faload,
743 ICMD_DALOAD = BC_daload,
744 ICMD_AALOAD = BC_aaload,
745 ICMD_BALOAD = BC_baload,
746 ICMD_CALOAD = BC_caload,
747 ICMD_SALOAD = BC_saload,
749 /* Order of STORE instructions must be equal to order of TYPE_*
752 ICMD_ISTORE = BC_istore,
753 ICMD_LSTORE = BC_lstore,
754 ICMD_FSTORE = BC_fstore,
755 ICMD_DSTORE = BC_dstore,
756 ICMD_ASTORE = BC_astore,
781 ICMD_IASTORE = BC_iastore,
782 ICMD_LASTORE = BC_lastore,
783 ICMD_FASTORE = BC_fastore,
784 ICMD_DASTORE = BC_dastore,
785 ICMD_AASTORE = BC_aastore,
786 ICMD_BASTORE = BC_bastore,
787 ICMD_CASTORE = BC_castore,
788 ICMD_SASTORE = BC_sastore,
793 ICMD_DUP_X1 = BC_dup_x1,
794 ICMD_DUP_X2 = BC_dup_x2,
796 ICMD_DUP2_X1 = BC_dup2_x1,
797 ICMD_DUP2_X2 = BC_dup2_x2,
834 ICMD_IUSHR = BC_iushr,
835 ICMD_LUSHR = BC_lushr,
859 ICMD_INT2BYTE = BC_int2byte,
860 ICMD_INT2CHAR = BC_int2char,
861 ICMD_INT2SHORT = BC_int2short,
864 ICMD_FCMPL = BC_fcmpl,
865 ICMD_FCMPG = BC_fcmpg,
866 ICMD_DCMPL = BC_dcmpl,
867 ICMD_DCMPG = BC_dcmpg,
876 ICMD_IF_ICMPEQ = BC_if_icmpeq,
877 ICMD_IF_ICMPNE = BC_if_icmpne,
878 ICMD_IF_ICMPLT = BC_if_icmplt,
879 ICMD_IF_ICMPGE = BC_if_icmpge,
880 ICMD_IF_ICMPGT = BC_if_icmpgt,
881 ICMD_IF_ICMPLE = BC_if_icmple,
882 ICMD_IF_ACMPEQ = BC_if_acmpeq,
883 ICMD_IF_ACMPNE = BC_if_acmpne,
889 ICMD_TABLESWITCH = BC_tableswitch,
890 ICMD_LOOKUPSWITCH = BC_lookupswitch,
892 ICMD_IRETURN = BC_ireturn,
893 ICMD_LRETURN = BC_lreturn,
894 ICMD_FRETURN = BC_freturn,
895 ICMD_DRETURN = BC_dreturn,
896 ICMD_ARETURN = BC_areturn,
897 ICMD_RETURN = BC_return,
899 ICMD_GETSTATIC = BC_getstatic,
900 ICMD_PUTSTATIC = BC_putstatic,
901 ICMD_GETFIELD = BC_getfield,
902 ICMD_PUTFIELD = BC_putfield,
904 ICMD_INVOKEVIRTUAL = BC_invokevirtual,
905 ICMD_INVOKESPECIAL = BC_invokespecial,
906 ICMD_INVOKESTATIC = BC_invokestatic,
907 ICMD_INVOKEINTERFACE = BC_invokeinterface,
912 ICMD_NEWARRAY = BC_newarray,
913 ICMD_ANEWARRAY = BC_anewarray,
915 ICMD_ARRAYLENGTH = BC_arraylength,
917 ICMD_ATHROW = BC_athrow,
919 ICMD_CHECKCAST = BC_checkcast,
920 ICMD_INSTANCEOF = BC_instanceof,
922 ICMD_MONITORENTER = BC_monitorenter,
923 ICMD_MONITOREXIT = BC_monitorexit,
927 ICMD_MULTIANEWARRAY = BC_multianewarray,
929 ICMD_IFNULL = BC_ifnull,
930 ICMD_IFNONNULL = BC_ifnonnull,
936 ICMD_IASTORECONST = 204,
937 ICMD_LASTORECONST = 205,
938 ICMD_FASTORECONST = 206,
939 ICMD_DASTORECONST = 207,
940 ICMD_AASTORECONST = 208,
941 ICMD_BASTORECONST = 209,
942 ICMD_CASTORECONST = 210,
943 ICMD_SASTORECONST = 211,
945 ICMD_PUTSTATICCONST = 212,
946 ICMD_PUTFIELDCONST = 213,
951 ICMD_INLINE_START = 251, /* instruction before inlined method */
952 ICMD_INLINE_END = 252, /* instruction after inlined method */
953 ICMD_INLINE_BODY = 253, /* start of inlined body */
955 ICMD_BUILTIN = 255 /* internal opcode */
958 /* Additional instruction accessors */
960 methoddesc *instruction_call_site(const instruction *iptr);
962 static inline bool instruction_has_dst(const instruction *iptr) {
964 (icmd_table[iptr->opc].dataflow == DF_INVOKE) ||
965 (icmd_table[iptr->opc].dataflow == DF_BUILTIN)
967 return instruction_call_site(iptr)->returntype.type != TYPE_VOID;
969 return icmd_table[iptr->opc].dataflow >= DF_DST_BASE;
973 /***************************** register types *********************************/
975 #define REG_RES 0 /* reserved register for OS or code generator */
976 #define REG_RET 1 /* return value register */
977 #define REG_EXC 2 /* exception value register */
978 #define REG_SAV 3 /* (callee) saved register */
979 #define REG_TMP 4 /* scratch temporary register (caller saved) */
980 #define REG_ARG 5 /* argument register (caller saved) */
982 #define REG_END -1 /* last entry in tables */
984 #define PARAMMODE_NUMBERED 0
985 #define PARAMMODE_STUFFED 1
988 /* function prototypes ********************************************************/
990 /* compiler initialisation */
993 /* compiler finalisation */
994 void jit_close(void);
996 /* create a new jitdata */
997 jitdata *jit_jitdata_new(methodinfo *m);
999 /* compile a method with jit compiler */
1000 u1 *jit_compile(methodinfo *m);
1001 u1 *jit_recompile(methodinfo *m);
1003 void jit_invalidate_code(methodinfo *m);
1004 codeinfo *jit_get_current_code(methodinfo *m);
1005 void jit_request_optimization(methodinfo *m);
1007 /* patch the method entrypoint */
1008 #if !defined(JIT_COMPILER_VIA_SIGNAL)
1009 u1 *jit_asm_compile(methodinfo *m, u1 *mptr, u1 *sp, u1 *ra);
1011 void *jit_compile_handle(methodinfo *m, void *pv, void *ra, void *mptr);
1013 s4 jit_complement_condition(s4 opcode);
1015 void jit_renumber_basicblocks(jitdata *jd);
1016 #if !defined(NDEBUG)
1017 void jit_check_basicblock_numbers(jitdata *jd);
1021 /* machine dependent functions ************************************************/
1023 #if defined(ENABLE_JIT)
1027 #if defined(ENABLE_INTRP)
1028 void intrp_md_init(void);
1031 void *md_jit_method_patch_address(void *pv, void *ra, void *mptr);
1037 * These are local overrides for various environment variables in Emacs.
1038 * Please do not remove this and leave it at the end of the file, where
1039 * Emacs will automagically detect them.
1040 * ---------------------------------------------------------------------
1043 * indent-tabs-mode: t
1047 * vim:noexpandtab:sw=4:ts=4: