* src/vm/jit/stack.h (COPY): Prevent setting varkind to STACKVAR for stackslots copie...
[cacao.git] / src / vm / jit / jit.h
index 565987a0cbe9c8f38a2f86a5871815de56aa0cdd..95bdbe1812cb72ab458b6e564dc6d664ab6c0524 100644 (file)
@@ -1,9 +1,9 @@
-/* jit/jit.h - code generation header
+/* src/vm/jit/jit.h - code generation header
 
-   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
-   R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
-   M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
-   P. Tomsich, J. Wenninger
+   Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+   C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+   E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+   J. Wenninger, Institut f. Computersprachen - TU Wien
 
    This file is part of CACAO.
 
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
 
-   Contact: cacao@complang.tuwien.ac.at
+   Contact: cacao@cacaojvm.org
 
    Authors: Andreas Krall
             Reinhard Grafl
 
    Changes: Christian Thalinger
+                       Edwin Steiner
 
-   $Id: jit.h 1038 2004-04-26 16:41:30Z twisti $
+   $Id: jit.h 4524 2006-02-16 19:39:36Z christian $
 
 */
 
 #ifndef _JIT_H
 #define _JIT_H
 
-#include "toolbox/chain.h"
-#include "global.h"
-#include "builtin.h"
-#include "typeinfo.h"
-
-/**************************** resolve typedef-cycles **************************/
+/* resolve typedef cycles *****************************************************/
 
 typedef struct stackelement stackelement;
 typedef stackelement *stackptr;
 typedef struct basicblock basicblock;
 typedef struct instruction instruction;
 typedef struct subroutineinfo subroutineinfo;
-typedef struct varinfo varinfo;
-typedef struct branchref branchref;
-typedef struct jumpref jumpref;
-typedef struct dataref dataref;
-typedef varinfo *varinfoptr;
-typedef struct linenumberref linenumberref;
+
+
+#include "config.h"
+#include "vm/types.h"
+
+#include "toolbox/chain.h"
+#include "vm/global.h"
+#include "vm/method.h"
+#include "vm/references.h"
+#include "vm/statistics.h"
+#include "vm/jit/codegen-common.h"
+#include "vm/jit/verify/typeinfo.h"
+
+
+/* common jit/codegen macros **************************************************/
+
+#if defined(ENABLE_STATISTICS)
+# define COUNT(x)        (x)++
+# define COUNT_SPILLS    count_spills++
+#else
+# define COUNT(x)        /* nothing */
+# define COUNT_SPILLS    /* nothing */
+#endif
 
 
 /************************** stack element structure ***************************/
@@ -70,9 +83,10 @@ typedef struct linenumberref linenumberref;
 #define TYPE_DBL   TYPE_DOUBLE  /*3*/  /* integer, long, float, double, address      */
 #define TYPE_ADR   TYPE_ADDRESS /*4*/
 
-#define IS_INT_LNG_TYPE(a)      (!((a)&TYPE_FLT))
-#define IS_FLT_DBL_TYPE(a)      ((a)&TYPE_FLT)
-#define IS_2_WORD_TYPE(a)       ((a)&TYPE_LNG)
+#define IS_INT_LNG_TYPE(a)      (!((a) & TYPE_FLT))
+#define IS_FLT_DBL_TYPE(a)      ((a) & TYPE_FLT)
+#define IS_2_WORD_TYPE(a)       ((a) & TYPE_LNG)
+#define IS_ADR_TYPE(a)          ((a) & TYPE_ADR)
 
 
 /* flags */
@@ -80,6 +94,9 @@ typedef struct linenumberref linenumberref;
 #define SAVEDVAR   1            /* variable has to survive method invocations */
 #define INMEMORY   2            /* variable stored in memory                  */
 #define SAVEDTMP   4            /* temporary variable using a saved register  */
+#define TMPARG     8            /* temporary variable using a arg register    */
+#define STCOPY    16            /* there is another stackslot alive           */
+                                /* using the same register/memory location    */
 
 /* variable kinds */
 
@@ -92,108 +109,86 @@ typedef struct linenumberref linenumberref;
 
 struct stackelement {
        stackptr prev;              /* pointer to next element towards bottom     */
-       int type;                   /* slot type of stack element                 */
-#ifdef CACAO_TYPECHECK
+       s4       type;              /* slot type of stack element                 */
+#ifdef ENABLE_VERIFIER
        typeinfo typeinfo;          /* info on reference types                    */
 #endif
-       int flags;                  /* flags (SAVED, INMEMORY)                    */
-       int varkind;                /* kind of variable or register               */
-       int varnum;                 /* number of variable                         */
-       int regoff;                 /* register number or memory offset           */
+       s4       flags;             /* flags (SAVED, INMEMORY)                    */
+       s4       varkind;           /* kind of variable or register               */
+       s4       varnum;            /* number of variable                         */
+       s4       regoff;            /* register number or memory offset           */
 };
 
 
 /**************************** instruction structure ***************************/
 
 struct instruction {
-       stackptr dst;               /* stack index of destination operand stack   */
-       u2  opc;                    /* opcode of intermediate code command        */
-       s4  op1;                    /* first operand, usually variable number     */
-       imm_union val;              /* immediate constant                         */
-       void *target;                   /* used for targets of branches and jumps         */
-                                       /* and as address for list of targets for         */
-                                       /* statements                                   */
-       u2 line;                                /* line number in source file */
-       classinfo *clazz;               /*needed for inlining. can't be done on basic block level, since an inlined
-                                       function doesn't start necessarily start a new block*/
+       stackptr    dst;            /* stack index of destination operand stack   */
+       u2          opc;            /* opcode of intermediate code command        */
+       s4          op1;            /* first operand, usually variable number     */
+       imm_union   val;            /* immediate constant                         */
+       void       *target;         /* used for targets of branches and jumps     */
+                                   /* and as address for list of targets for     */
+                                   /* statements                                 */
+       u2          line;           /* line number in source file                 */
+       methodinfo *method;         /* needed for inlining. can't be done on      */
+                                   /* basic block level, since an inlined        */
+                                   /* function doesn't necessarily start         */
+                                   /* a new block                                */
 };
 
+#define INSTRUCTION_PUTCONST_TYPE(iptr) \
+       ((iptr)[0].op1)
+
+#define INSTRUCTION_PUTCONST_VALUE_ADR(iptr) \
+       ((iptr)[0].val.a)
 
-/**************************** basic block structure ***************************/
+#define INSTRUCTION_PUTCONST_FIELDINFO(iptr) \
+       ((fieldinfo *)((iptr)[1].val.a))
+
+#define INSTRUCTION_PUTCONST_FIELDINFO_PTR(iptr) \
+       ((fieldinfo **) &((iptr)[1].val.a))
+
+#define INSTRUCTION_PUTCONST_FIELDREF(iptr) \
+       ((unresolved_field *)((iptr)[1].target))
+
+
+/* basicblock *****************************************************************/
  
-/*                    flags                                                   */
+/* flags */
+
+#define BBDELETED            -2
+#define BBUNDEF              -1
+#define BBREACHED            0
+#define BBFINISHED           1
 
-#define BBDELETED  -2
-#define BBUNDEF    -1
-#define BBREACHED  0
-#define BBFINISHED 1
 #define BBTYPECHECK_UNDEF    2
 #define BBTYPECHECK_REACHED  3
 
-#define BBTYPE_STD 0            /* standard basic block type                  */
-#define BBTYPE_EXH 1            /* exception handler basic block type         */
-#define BBTYPE_SBR 2            /* subroutine basic block type                */
+#define BBTYPE_STD           0  /* standard basic block type                  */
+#define BBTYPE_EXH           1  /* exception handler basic block type         */
+#define BBTYPE_SBR           2  /* subroutine basic block type                */
+
 
-struct basicblock { 
-       int          flags;         /* used during stack analysis, init with -1   */
-       int          type;          /* basic block type (std, xhandler, subroutine*/
+struct basicblock {
+       s4           debug_nr;      /* basic block number                         */
+       s4           flags;         /* used during stack analysis, init with -1   */
+       s4           type;          /* basic block type (std, xhandler, subroutine*/
        instruction *iinstr;        /* pointer to intermediate code instructions  */
-       int          icount;        /* number of intermediate code instructions   */
-       int          mpc;           /* machine code pc at start of block          */
+       s4           icount;        /* number of intermediate code instructions   */
+       s4           mpc;           /* machine code pc at start of block          */
        stackptr     instack;       /* stack at begin of basic block              */
        stackptr     outstack;      /* stack at end of basic block                */
-       int          indepth;       /* stack depth at begin of basic block        */
-       int          outdepth;      /* stack depth end of basic block             */
-       int          pre_count;     /* count of predecessor basic blocks          */
+       s4           indepth;       /* stack depth at begin of basic block        */
+       s4           outdepth;      /* stack depth end of basic block             */
+       s4           pre_count;     /* count of predecessor basic blocks          */
        branchref   *branchrefs;    /* list of branches to be patched             */
 
        basicblock  *next;          /* used to build a BB list (instead of array) */
-       int          lflags;        /* used during loop copying, init with 0      */
+       s4           lflags;        /* used during loop copying, init with 0      */
        basicblock  *copied_to;     /* points to the copy of this basic block     */
                                 /* when loop nodes are copied                 */
-       int debug_nr;
-};
-
-
-/************************* pseudo variable structure **************************/
-
-struct varinfo {
-       int type;                   /* basic type of variable                     */
-       int flags;                  /* flags (SAVED, INMEMORY)                    */
-       int regoff;                 /* register number or memory offset           */
-};
-
-typedef varinfo varinfo5[5];
-
-
-/***************** forward references in branch instructions ******************/
-
-struct branchref {
-       s4 branchpos;               /* patching position in code segment          */
-       s4 reg;                     /* used for ArrayIndexOutOfBounds index reg   */
-       branchref *next;            /* next element in branchref list             */
-};
-
-
-/******************** forward references in tables  ***************************/
-
-struct jumpref {
-       s4 tablepos;                /* patching position in data segment          */
-       basicblock *target;         /* target basic block                         */
-       jumpref *next;              /* next element in jumpref list               */
-};
-
-struct linenumberref {
-       s4 tablepos;                /* patching position in data segment          */
-       int targetmpc;             /* machine code program counter of first instruction for given line*/
-       u2 linenumber;              /* line number, used for inserting into the table and for validty checking*/
-       linenumberref *next;        /* next element in linenumberref list               */
-};
-
-
-struct dataref {
-       u1 *pos;                    /* patching position in generated code        */
-       dataref *next;              /* next element in dataref list               */
+       stackptr     stack;         /* start of stack array for this block        */
 };
 
 
@@ -215,13 +210,12 @@ extern int jcommandsize[256];
 #define ICMD_ACONST            1        /* val.a = constant                   */
 
 #define JAVA_ICONST_M1         2
-#define ICMD_NULLCHECKPOP      2
+#define ICMD_CHECKNULL         2
 
 #define JAVA_ICONST_0          3
 #define ICMD_ICONST            3        /* val.i = constant                   */
 
 #define JAVA_ICONST_1          4
-#define ICMD_IREM0X10001       4
 
 #define JAVA_ICONST_2          5
 #define ICMD_IDIVPOW2          5        /* val.i = constant                   */
@@ -232,7 +226,6 @@ extern int jcommandsize[256];
 #define JAVA_ICONST_4          7
 
 #define JAVA_ICONST_5          8
-#define ICMD_LREM0X10001       8
 
 #define JAVA_LCONST_0          9
 #define ICMD_LCONST            9        /* val.l = constant                   */
@@ -760,7 +753,7 @@ extern int jcommandsize[256];
 #define JAVA_INVOKEINTERFACE  185
 #define ICMD_INVOKEINTERFACE  185       /* val.a = method info pointer        */
 
-#define ICMD_CHECKASIZE       186       /*                                    */
+/* UNDEF186 */
 
 #define JAVA_NEW              187
 #define ICMD_NEW              187       /* op1 = 1, val.a = class pointer     */
@@ -806,22 +799,44 @@ extern int jcommandsize[256];
 
 #define JAVA_BREAKPOINT       202
 
-#define ICMD_CHECKOOM         203       /* check for out of memory error      */
+/* UNDEF203 */
+
+#define ICMD_IASTORECONST     204
+
+#define ICMD_LASTORECONST     205
+
+#define ICMD_FASTORECONST     206
+
+#define ICMD_DASTORECONST     207
+
+#define ICMD_AASTORECONST     208
+
+#define ICMD_BASTORECONST     209
+
+#define ICMD_CASTORECONST     210
+
+#define ICMD_SASTORECONST     211
+
+#define ICMD_PUTSTATICCONST   212
+
+#define ICMD_PUTFIELDCONST    213
+
+#define ICMD_IMULPOW2         214
+
+#define ICMD_LMULPOW2         215
+
+#define ICMD_INLINE_START     251       /* instruction before inlined method  */
+#define ICMD_INLINE_END       252       /* instruction after inlined method   */
+#define ICMD_INLINE_GOTO      253       /* jump to caller of inlined method   */
+
+#define ICMD_BUILTIN          255       /* internal opcode                    */
 
-#define ICMD_BUILTIN3         253       /* internal opcode */
-#define ICMD_BUILTIN2         254       /* internal opcode */
-#define ICMD_BUILTIN1         255       /* internal opcode */
 #define ICMD_READONLY_ARG     1024      /* used for inlining, opcodes 1024-1028 are used */
 #define ICMD_CLEAR_ARGREN     1029      /* indicates the start of a new inlined method argument renaming must be reset */
 
 
 /******************* description of JavaVM instructions ***********************/
 
-#if defined(USEBUILTINTABLE)
-
-builtin_descriptor *find_builtin(int opcode);
-
-#endif /* USEBUILTINTABLE */
 
 
 /***************************** register types *********************************/
@@ -841,132 +856,28 @@ builtin_descriptor *find_builtin(int opcode);
 
 /***************************** register info block ****************************/
 
-extern int nregdescint[];   /* description of integer registers               */
-extern int nregdescfloat[]; /* description of floating point registers        */
-
-extern int nreg_parammode;
-
-
-/* compiler switches (set by main function) ***********************************/
-
-extern int count_jit_calls;
-extern int count_methods;
-extern int count_spills;
-extern int count_pcmd_activ;
-extern int count_pcmd_drop;
-extern int count_pcmd_zero;
-extern int count_pcmd_const_store;
-extern int count_pcmd_const_alu;
-extern int count_pcmd_const_bra;
-extern int count_pcmd_load;
-extern int count_pcmd_move;
-extern int count_load_instruction;
-extern int count_pcmd_store;
-extern int count_pcmd_store_comb;
-extern int count_dup_instruction;
-extern int count_pcmd_op;
-extern int count_pcmd_mem;
-extern int count_pcmd_met;
-extern int count_pcmd_bra;
-extern int count_pcmd_table;
-extern int count_pcmd_return;
-extern int count_pcmd_returnx;
-extern int count_check_null;
-extern int count_check_bound;
-extern int count_max_basic_blocks;
-extern int count_basic_blocks;
-extern int count_max_javainstr;
-extern int count_javainstr;
-extern int count_javacodesize;
-extern int count_javaexcsize;
-extern int count_calls;
-extern int count_tryblocks;
-extern int count_code_len;
-extern int count_data_len;
-extern int count_cstub_len;
-extern int count_nstub_len;
-extern int count_max_new_stack;
-extern int count_upper_bound_new_stack;
-extern int *count_block_stack;
-extern int *count_analyse_iterations;
-extern int *count_method_bb_distribution;
-extern int *count_block_size_distribution;
-extern int *count_store_length;
-extern int *count_store_depth;
-
-
-/* global compiler variables */
-
-extern classinfo  *class;       /* class the compiled method belongs to       */
-extern methodinfo *method;      /* pointer to method info of compiled method  */
-extern utf        *descriptor;  /* type descriptor of compiled method         */
-extern int         mparamcount; /* number of parameters (incl. this)          */
-extern u1         *mparamtypes; /* types of all parameters (TYPE_INT, ...)    */
-       
-extern int maxstack;            /* maximal JavaVM stack size                  */
-extern int maxlocals;           /* maximal number of local JavaVM variables   */
-extern int jcodelength;         /* length of JavaVM-codes                     */
-extern u1 *jcode;               /* pointer to start of JavaVM-code            */
-extern lineinfo *jlinenumbers;  /* line information array                     */
-extern u2 jlinenumbercount;     /* number of entries in the linenumber array  */
-extern int exceptiontablelength;/* length of exception table                  */
-extern xtable *extable;         /* pointer to start of exception table        */
-extern exceptiontable *raw_extable;
-
-extern int block_count;         /* number of basic blocks                     */
-extern basicblock *block;       /* points to basic block array                */
-extern int *block_index;        /* a table which contains for every byte of   */
-                                /* JavaVM code a basic block index if at this */
-                                /* byte there is the start of a basic block   */
-
-extern int instr_count;         /* number of JavaVM instructions              */
-extern instruction *instr;      /* points to intermediate code instructions   */
-
-extern int stack_count;         /* number of stack elements                   */
-extern stackelement *stack;     /* points to intermediate code instructions   */
-
-extern bool isleafmethod;       /* true if a method doesn't call subroutines  */
-
-extern basicblock *last_block;  /* points to the end of the BB list           */
-
-extern bool regs_ok;            /* true if registers have been allocated      */
-
-
-/* list of all classes used by the compiled method which have to be           */
-/* initialised (if not already done) before execution of this method          */
-extern chain *uninitializedclasses;
-
 extern int stackreq[256];
 
 
-#if defined(__I386__)
-extern bool method_uses_ecx;
-extern bool method_uses_edx;
-#endif
-
-
-/* function prototypes */
-
-methodptr jit_compile (methodinfo *m);  /* compile a method with jit compiler */
+/* function prototypes ********************************************************/
 
-void jit_init();                        /* compiler initialisation            */
-void jit_close();                       /* compiler finalisation              */
+/* compiler initialisation */
+void jit_init(void);
 
-u1 *createcompilerstub(methodinfo *m);
-u1 *createnativestub(functionptr f, methodinfo *m);
+/* compiler finalisation */
+void jit_close(void);
 
-void removecompilerstub(u1 *stub);
-void removenativestub(u1 *stub);
+/* compile a method with jit compiler */
+u1 *jit_compile(methodinfo *m);
 
-void typecheck();
-
-/* debug helpers (in stack.c) */
+/* machine dependent initialization */
+#if defined(ENABLE_JIT)
+void md_init(void);
+#endif
 
-void icmd_print_stack(stackptr s);
-char *icmd_builtin_name(functionptr bptr);
-void show_icmd_block(basicblock *bptr);
-void show_icmd(instruction *iptr,bool deadcode);
-void show_icmd_method();
+#if defined(ENABLE_INTRP)
+void intrp_md_init(void);
+#endif
 
 #endif /* _JIT_H */
 
@@ -982,4 +893,5 @@ void show_icmd_method();
  * c-basic-offset: 4
  * tab-width: 4
  * End:
+ * vim:noexpandtab:sw=4:ts=4:
  */