Unified variables changes for common/i386.
[cacao.git] / src / vm / jit / jit.h
index e252852820aa2fc5a1c3af756e8b0c41bc2be798..9418bbca53f94cfc4daf78d95845fd3ef6a27ee1 100644 (file)
@@ -30,7 +30,7 @@
    Changes: Christian Thalinger
                        Edwin Steiner
 
-   $Id: jit.h 5217 2006-08-08 12:46:51Z edwin $
+   $Id: jit.h 5404 2006-09-07 13:29:05Z christian $
 
 */
 
@@ -38,6 +38,8 @@
 #ifndef _JIT_H
 #define _JIT_H
 
+#define NEW_VAR
+
 /* forward typedefs ***********************************************************/
 
 typedef struct jitdata jitdata;
@@ -46,7 +48,6 @@ typedef stackelement *stackptr;
 typedef struct basicblock basicblock;
 typedef struct branchref branchref;
 typedef struct instruction instruction;
-typedef struct new_instruction new_instruction;
 typedef struct insinfo_inline insinfo_inline;
 
 
@@ -70,10 +71,15 @@ typedef struct insinfo_inline insinfo_inline;
 #if defined(ENABLE_LOOP)
 # include "vm/jit/loop/loop.h"
 #endif
+#if defined(ENABLE_SSA) 
+# include "vm/jit/optimizing/lsra.h"
+#endif
+#if defined(ENABLE_LSRA)
+# include "vm/jit/allocator/lsra.h"
+#endif
 
 #include "vm/jit/verify/typeinfo.h"
 
-
 /* common jit/codegen macros **************************************************/
 
 #if defined(ENABLE_STATISTICS)
@@ -95,11 +101,14 @@ struct jitdata {
 #if defined(ENABLE_LOOP)
        loopdata        *ld;
 #endif
+#if defined(ENABLE_SSA) || defined(ENABLE_LSRA)
+       lsradata     *ls;
+#endif
 
        u4               flags;             /* contains JIT compiler flags        */
        bool             isleafmethod;      /* does method call subroutines       */
 
-       new_instruction *new_instructions;
+       instruction     *new_instructions;
        basicblock      *new_basicblocks;
        s4              *new_basicblockindex;
        stackelement    *new_stack;
@@ -107,9 +116,22 @@ struct jitdata {
        s4               new_basicblockcount;
        s4               new_stackcount;
        s4               new_c_debug_nr;
-       registerdata    *new_rd;
+
+#if defined(NEW_VAR)
+       varinfo *var;
+       s4      vartop;
+    
+       s4      varcount;
+       s4      localcount;
+    s4      *local_map; /* internal structure to rename(de-coallesc) locals  */
+                           /* and keep the coalescing info for simplereg.       */
+                           /* local_map[local_index * 5 + local_type] =         */
+                           /* new_index in rd->var or LOCAL_UNUSED              */
+       s4      *interface_map; /* like local_map for interfaces */
+#endif
 };
 
+#define UNUSED                     -1
 
 #define JITDATA_FLAG_PARSE               0x00000001
 #define JITDATA_FLAG_VERIFY              0x00000002
@@ -149,7 +171,7 @@ struct jitdata {
     ((jd)->flags & JITDATA_FLAG_VERBOSECALL)
 
 
-/************************** stack element structure ***************************/
+/* stack element structure ****************************************************/
 
 /* flags */
 
@@ -161,6 +183,13 @@ struct jitdata {
                                 /* using the same register/memory location    */
 #define STKEEP    32            /* to prevent reg_mark_copy to free this      */
                                 /* stackslot */
+#define PREALLOC  64            /* preallocated var like for ARGVARS. Used    */
+                                /* with the new var system */
+#define OUTVAR   128            /* STACKVR flag for new var system */
+
+#define IS_SAVEDVAR(x)    ((x) & SAVEDVAR)
+#define IS_INMEMORY(x)    ((x) & INMEMORY)
+
 
 /* variable kinds */
 
@@ -203,16 +232,25 @@ typedef struct {
 /*** s1 operand ***/
 
 typedef union {
+#if defined(NEW_VAR)
+       s4                         varindex;
+#else
     stackptr                   var;
     s4                         localindex;
+#endif
     s4                         argcount;
 } s1_operand_t;
 
 /*** s2 operand ***/
 
 typedef union {
+#if defined(NEW_VAR)
+       s4                         varindex;
+       s4                         *args;
+#else
     stackptr                   var;
     stackptr                  *args;
+#endif
     classref_or_classinfo      c;
     unresolved_class          *uc;
     ptrint                     constval;         /* for PUT*CONST             */
@@ -223,7 +261,11 @@ typedef union {
 /*** s3 operand ***/
 
 typedef union {
+#if defined(NEW_VAR)
+       s4                         varindex;
+#else
     stackptr                   var;
+#endif
     ptrint                     constval;
     classref_or_classinfo      c;
     constant_FMIref           *fmiref;
@@ -251,13 +293,21 @@ typedef union {
 /*** dst operand ***/
 
 typedef union {
+#if defined(NEW_VAR)
+       s4                         varindex;
+#else
     stackptr                   var;
     s4                         localindex;
+#endif
     basicblock                *block;       /* valid after stack analysis     */
     branch_target_t           *table;       /* for TABLESWITCH                */
     lookup_target_t           *lookup;      /* for LOOKUPSWITCH               */
     s4                         insindex;    /* used between parse and stack   */
+#if defined(NEW_VAR)
+       s4                        *dupslots;    /* for SWAP, DUP* except DUP      */
+#else
        stackptr                  *dupslots;    /* for SWAP, DUP* except DUP      */
+#endif
 } dst_operand_t;
 
 /*** flags (32 bits) ***/
@@ -265,7 +315,8 @@ typedef union {
 #define INS_FLAG_UNRESOLVED    0x01    /* contains unresolved field/meth/class*/
 #define INS_FLAG_CLASS         0x02    /* for ACONST with class               */
 #define INS_FLAG_ARRAY         0x04    /* for CHECKCAST/INSTANCEOF with array */
-#define INS_FLAG_NOCHECK       0x08
+#define INS_FLAG_CHECK         0x08    /* for *ALOAD|*ASTORE: check index     */
+                                       /* for BUILTIN: check exception        */
 
 typedef union {
     u4                  bits;
@@ -296,9 +347,9 @@ typedef union {
 
 /*** instruction ***/
 
-/* The new instruction format for the intermediate representation: */
+/* The instruction format for the intermediate representation: */
 
-struct new_instruction {
+struct instruction {
     u2                      opc;    /* opcode       */
     u2                      line;   /* line number  */
 #if SIZEOF_VOID_P == 8
@@ -318,35 +369,17 @@ struct new_instruction {
 #endif
 };
 
-/* XXX This instruction format will become obsolete. */
-
-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                 */
-};
 
 #define INSTRUCTION_IS_RESOLVED(iptr) \
-       (!((ptrint)(iptr)->target & 0x01)) /* XXX target used temporarily as flag */
-
-#define INSTRUCTION_IS_UNRESOLVED(iptr) \
-       ((ptrint)(iptr)->target & 0x01) /* XXX target used temporarily as flag */
-
-#define NEW_INSTRUCTION_IS_RESOLVED(iptr) \
        (!((iptr)->flags.bits & INS_FLAG_UNRESOLVED))
 
-#define NEW_INSTRUCTION_IS_UNRESOLVED(iptr) \
+#define INSTRUCTION_IS_UNRESOLVED(iptr) \
        ((iptr)->flags.bits & INS_FLAG_UNRESOLVED)
 
-#define NEW_INSTRUCTION_MUST_CHECK(iptr) \
-       (!((iptr)->flags.bits & INS_FLAG_NOCHECK))
+#define INSTRUCTION_MUST_CHECK(iptr) \
+       ((iptr)->flags.bits & INS_FLAG_CHECK)
 
-#define NEW_INSTRUCTION_GET_FIELDREF(iptr,fref) \
+#define INSTRUCTION_GET_FIELDREF(iptr,fref) \
        do { \
                if (iptr->flags.bits & INS_FLAG_UNRESOLVED) \
                        fref = iptr->sx.s23.s3.uf->fieldref; \
@@ -354,15 +387,7 @@ struct instruction {
                        fref = iptr->sx.s23.s3.fmiref; \
        } while (0)
 
-#define INSTRUCTION_GET_FIELDREF(iptr,fref) \
-       do { \
-               if (INSTRUCTION_IS_UNRESOLVED(iptr)) \
-                       fref = ((unresolved_field *) (iptr)->val.a)->fieldref; \
-               else \
-                       fref = ((constant_FMIref *)(iptr)->val.a); \
-       } while (0)
-
-#define NEW_INSTRUCTION_GET_METHODREF(iptr,mref) \
+#define INSTRUCTION_GET_METHODREF(iptr,mref) \
        do { \
                if (iptr->flags.bits & INS_FLAG_UNRESOLVED) \
                        mref = iptr->sx.s23.s3.um->methodref; \
@@ -370,23 +395,7 @@ struct instruction {
                        mref = iptr->sx.s23.s3.fmiref; \
        } while (0)
 
-#define INSTRUCTION_GET_METHODREF(iptr,mref) \
-       do { \
-               if (INSTRUCTION_IS_UNRESOLVED(iptr)) \
-                       mref = ((unresolved_method *) (iptr)->val.a)->methodref; \
-               else \
-                       mref = ((constant_FMIref *)(iptr)->val.a); \
-       } while (0)
-
-#define INSTRUCTION_GET_FIELDDESC(iptr,fd) \
-       do { \
-               if (INSTRUCTION_IS_UNRESOLVED(iptr)) \
-                       fd = ((unresolved_field *)(iptr)->val.a)->fieldref->parseddesc.fd; \
-               else \
-                       fd = ((constant_FMIref *)(iptr)->val.a)->parseddesc.fd; \
-       } while (0)
-
-#define NEW_INSTRUCTION_GET_METHODDESC(iptr, md) \
+#define INSTRUCTION_GET_METHODDESC(iptr, md) \
        do { \
                if (iptr->flags.bits & INS_FLAG_UNRESOLVED) \
                        md = iptr->sx.s23.s3.um->methodref->parseddesc.md; \
@@ -394,61 +403,6 @@ struct instruction {
                        md = iptr->sx.s23.s3.fmiref->parseddesc.md; \
        } while (0)
 
-#define INSTRUCTION_GET_METHODDESC(iptr,md) \
-       do { \
-               if (INSTRUCTION_IS_UNRESOLVED(iptr)) \
-                       md = ((unresolved_method *) (iptr)->val.a)->methodref->parseddesc.md; \
-               else \
-                       md = ((constant_FMIref *)(iptr)->val.a)->parseddesc.md; \
-       } while (0)
-
-#define INSTRUCTION_UNRESOLVED_CLASS(iptr) \
-       ((unresolved_class *) (iptr)->val.a)
-
-#define INSTRUCTION_UNRESOLVED_METHOD(iptr) \
-       ((unresolved_method *) (iptr)->val.a)
-
-#define INSTRUCTION_UNRESOLVED_FIELD(iptr) \
-       ((unresolved_field *) (iptr)->val.a)
-
-#define INSTRUCTION_RESOLVED_FMIREF(iptr) \
-    ((constant_FMIref *)(iptr)->val.a)
-
-#define INSTRUCTION_RESOLVED_FIELDINFO(iptr) \
-    (INSTRUCTION_RESOLVED_FMIREF(iptr)->p.field)
-
-#define INSTRUCTION_RESOLVED_METHODINFO(iptr) \
-    (INSTRUCTION_RESOLVED_FMIREF(iptr)->p.method)
-
-#define INSTRUCTION_PUTCONST_TYPE(iptr) \
-       ((iptr)[0].op1)
-
-#define INSTRUCTION_PUTCONST_VALUE_ADR(iptr) \
-       ((iptr)[0].val.a)
-
-#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))
-
-/* for ICMD_ACONST */
-
-#define ICMD_ACONST_IS_CLASS(iptr) \
-       ((ptrint)(iptr)->target & 0x02) /* XXX target used temporarily as flag */
-
-#define ICMD_ACONST_CLASSREF_OR_CLASSINFO(iptr) \
-(CLASSREF_OR_CLASSINFO((iptr)->val.a))
-
-#define ICMD_ACONST_RESOLVED_CLASSINFO(iptr) \
-       ((classinfo *) (iptr)->val.a)
-
-#define ICMD_ACONST_UNRESOLVED_CLASSREF(iptr) \
-       ((constant_classref *) (iptr)->val.a)
-
 
 /* additional info structs for special instructions ***************************/
 
@@ -495,6 +449,13 @@ struct basicblock {
        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                */
+#if defined(NEW_VAR)
+       s4           *invars;       /* array of in-variables at begin of block    */
+       s4           *outvars;      /* array of out-variables at end of block     */
+#else
+       stackptr     *invars;       /* array of in-variables at begin of block    */
+       stackptr     *outvars;      /* array of out-variables at end of block     */
+#endif
        s4            indepth;      /* stack depth at begin of basic block        */
        s4            outdepth;     /* stack depth end of basic block             */
 
@@ -1210,7 +1171,14 @@ extern int jcommandsize[256];
 /***************************** register info block ****************************/
 
 extern int stackreq[256];
-
+/* extern int op_needs_saved[256];  */
+/* extern int op_is_pei[256];       */
+#define NEEDS_SAVED  0
+#define PEI          1
+#define OP_DATA_SIZE 2
+extern int op_data[256][OP_DATA_SIZE]; 
+/* [0..255][NEEDS_SAVED] ... if ICMD needs a SAVEDVAR         */
+/* [0..255][PEI]         ... if ICMD could throw an exception */
 
 /* function prototypes ********************************************************/