* Merged in twisti-branch.
[cacao.git] / src / vm / jit / codegen-common.h
index 42cdd1fea08f9584537906d50e82f84dc3c88bf8..606d122c34aaaf479be4e122307909b6c89f851d 100644 (file)
@@ -1,6 +1,6 @@
 /* src/vm/jit/codegen-common.h - architecture independent code generator stuff
 
-   Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+   Copyright (C) 1996-2005, 2006, 2007 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
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Contact: cacao@cacaojvm.org
-
-   Authors: Christian Thalinger
-
-   Changes: Christian Ullrich
-            Edwin Steiner
-
-   $Id: codegen-common.h 5295 2006-09-05 09:59:53Z edwin $
+   $Id: codegen-common.h 7579 2007-03-25 22:42:13Z twisti $
 
 */
 
 
 /* forward typedefs ***********************************************************/
 
-typedef struct codegendata codegendata;
 typedef struct codegen_critical_section_t codegen_critical_section_t;
+typedef struct codegendata                codegendata;
+typedef struct branchref                  branchref;
+typedef struct branch_label_ref_t         branch_label_ref_t;
+typedef struct jumpref                    jumpref;
+typedef struct dataref                    dataref;
+typedef struct exceptionref               exceptionref;
+typedef struct patchref                   patchref;
+typedef struct linenumberref              linenumberref;
 
 
 #include "config.h"
 #include "vm/types.h"
 
 #include "vm/global.h"
-#include "vm/references.h"
-#include "vm/method.h"
+
 #include "vm/jit/dseg.h"
 #include "vm/jit/jit.h"
 #include "vm/jit/reg.h"
 #include "vm/jit/code.h"
+#include "vm/jit/replace.h"
+
+#include "vmcore/descriptor.h"
+#include "vmcore/method.h"
+#include "vmcore/references.h"
 
 
 #define MCODEINITSIZE (1<<15)       /* 32 Kbyte code area initialization size */
@@ -73,6 +77,31 @@ typedef struct codegen_critical_section_t codegen_critical_section_t;
 #define GET_HIGH_REG(a)    (((a) & 0xffff0000) >> 16)
 
 
+/* branch conditions **********************************************************/
+
+#define BRANCH_UNCONDITIONAL    -1
+
+#define BRANCH_EQ               (ICMD_IFEQ - ICMD_IFEQ)
+#define BRANCH_NE               (ICMD_IFNE - ICMD_IFEQ)
+#define BRANCH_LT               (ICMD_IFLT - ICMD_IFEQ)
+#define BRANCH_GE               (ICMD_IFGE - ICMD_IFEQ)
+#define BRANCH_GT               (ICMD_IFGT - ICMD_IFEQ)
+#define BRANCH_LE               (ICMD_IFLE - ICMD_IFEQ)
+
+#define BRANCH_ULT              256
+#define BRANCH_ULE              257
+#define BRANCH_UGE              258
+#define BRANCH_UGT              259
+
+#define BRANCH_NAN              260
+
+
+/* common branch options ******************************************************/
+
+#define BRANCH_OPT_NONE         0
+
+
+
 /************************* critical sections  *********************************/
 
 struct codegen_critical_section_t {
@@ -83,7 +112,10 @@ struct codegen_critical_section_t {
 };
 
 
+/* codegendata ****************************************************************/
+
 struct codegendata {
+       u4              flags;          /* code generator flags                   */
        u1             *mcodebase;      /* base pointer of code area              */
        u1             *mcodeend;       /* pointer to end of code area            */
        s4              mcodesize;      /* complete size of code area (bytes)     */
@@ -109,12 +141,13 @@ struct codegendata {
 
        jumpref        *jumpreferences; /* list of jumptable target addresses     */
 
-#if defined(__I386__) || defined(__X86_64__) || defined(__XDSPCORE__) || defined(ENABLE_INTRP)
+#if defined(__I386__) || defined(__X86_64__) || defined(__XDSPCORE__) || defined(__M68K__) || defined(ENABLE_INTRP) || defined(__S390__)
        dataref        *datareferences; /* list of data segment references        */
 #endif
 
-       exceptionref   *exceptionrefs;  /* list of exception branches             */
+/*     list           *patchrefs; */
        patchref       *patchrefs;
+       list           *brancheslabel;
 
        linenumberref  *linenumberreferences; /* list of line numbers and the     */
                                        /* program counters of their first        */
@@ -124,16 +157,98 @@ struct codegendata {
        s4              linenumbertab;
 
        methodinfo     *method;
-       s4              exceptiontablelength; /* exceptiontable length            */
-       exceptiontable *exceptiontable; /* the exceptiontable                     */
 
        codegen_critical_section_t *threadcrit; /* List of critical code regions          */
        codegen_critical_section_t threadcritcurrent;
        s4                 threadcritcount; /* Number of critical regions         */
 
        s4              maxstack;
-       s4              maxlocals;
        s4              stackframesize;    /* stackframe size of this method      */
+
+#if defined(ENABLE_REPLACEMENT)
+       rplpoint       *replacementpoint;  /* current replacement point           */
+#endif
+};
+
+
+#define CODEGENDATA_FLAG_ERROR           0x00000001
+#define CODEGENDATA_FLAG_LONGBRANCHES    0x00000002
+
+
+#define CODEGENDATA_HAS_FLAG_ERROR(cd) \
+    ((cd)->flags & CODEGENDATA_FLAG_ERROR)
+
+#define CODEGENDATA_HAS_FLAG_LONGBRANCHES(cd) \
+    ((cd)->flags & CODEGENDATA_FLAG_LONGBRANCHES)
+
+
+/* branchref *****************************************************************/
+
+struct branchref {
+       s4         branchmpc;       /* patching position in code segment          */
+       s4         condition;       /* conditional branch condition               */
+       s4         reg;             /* register number to check                   */
+       u4         options;         /* branch options                             */
+       branchref *next;            /* next element in branchref list             */
+};
+
+
+/* branch_label_ref_t *********************************************************/
+
+struct branch_label_ref_t {
+       s4         mpc;             /* position in code segment                   */
+       s4         label;           /* label number                               */
+       s4         condition;       /* conditional branch condition               */
+       s4         reg;             /* register number to check                   */
+       u4         options;         /* branch options                             */
+       listnode   linkage;
+};
+
+
+/* jumpref ********************************************************************/
+
+struct jumpref {
+       s4          tablepos;       /* patching position in data segment          */
+       basicblock *target;         /* target basic block                         */
+       jumpref    *next;           /* next element in jumpref list               */
+};
+
+
+/* dataref ********************************************************************/
+
+struct dataref {
+       s4       datapos;           /* patching position in generated code        */
+       dataref *next;              /* next element in dataref list               */
+};
+
+
+/* patchref *******************************************************************/
+
+struct patchref {
+       s4           branchpos;     /* relative offset to method entrypoint       */
+       s4           disp;          /* displacement of ref in the data segment    */
+       functionptr  patcher;       /* patcher function to call                   */
+       voidptr      ref;           /* reference passed                           */
+/*     listnode     linkage; */
+       patchref    *next;
+};
+
+
+/* linenumberref **************************************************************/
+
+struct linenumberref {
+       s4             tablepos;    /* patching position in data segment          */
+       s4             linenumber;  /* line number, used for inserting into the   */
+                                   /* table and for validity checking            */
+                                   /* -1......start of inlined body              */
+                                   /* -2......end of inlined body                */
+                                   /* <= -3...special entry with methodinfo *    */
+                                                               /* (see doc/inlining_stacktrace.txt)          */
+       ptrint         targetmpc;   /* machine code program counter of first      */
+                                   /* instruction for given line                 */
+                                                               /* NOTE: for linenumber <= -3 this is a the   */
+                                   /* (methodinfo *) of the inlined method       */
+       linenumberref *next;        /* next element in linenumberref list         */
 };
 
 
@@ -152,6 +267,13 @@ struct methodtree_element {
 void codegen_init(void);
 void codegen_setup(jitdata *jd);
 
+bool codegen_generate(jitdata *jd);
+bool codegen_emit(jitdata *jd);
+
+#if defined(ENABLE_INTRP)
+bool intrp_codegen(jitdata *jd);
+#endif
+
 void codegen_close(void);
 
 void codegen_increase(codegendata *cd);
@@ -160,23 +282,31 @@ void codegen_increase(codegendata *cd);
 u1 *codegen_ncode_increase(codegendata *cd, u1 *ncodeptr);
 #endif
 
-void codegen_addreference(codegendata *cd, basicblock *target);
+void codegen_add_branch_ref(codegendata *cd, basicblock *target, s4 condition, s4 reg, u4 options);
+void codegen_resolve_branchrefs(codegendata *cd, basicblock *bptr);
 
-void codegen_add_arithmeticexception_ref(codegendata *cd);
-void codegen_add_arrayindexoutofboundsexception_ref(codegendata *cd, s4 reg);
-void codegen_add_arraystoreexception_ref(codegendata *cd);
-void codegen_add_classcastexception_ref(codegendata *cd, s4 reg);
-void codegen_add_nullpointerexception_ref(codegendata *cd);
-void codegen_add_fillinstacktrace_ref(codegendata *cd);
+void codegen_branch_label_add(codegendata *cd, s4 label, s4 condition, s4 reg, u4 options);
 
 
-void codegen_addpatchref(codegendata *cd, functionptr patcher, voidptr ref,
-                                                s4 disp);
+void codegen_add_patch_ref(codegendata *cd, functionptr patcher, voidptr ref,
+                                                  s4 disp);
+/* XXX REMOVE ME: don't-break-trunk macro */
+#define codegen_addpatchref codegen_add_patch_ref
 
 void codegen_insertmethod(u1 *startpc, u1 *endpc);
 u1 *codegen_get_pv_from_pc(u1 *pc);
 u1 *codegen_get_pv_from_pc_nocheck(u1 *pc);
 
+#if defined(ENABLE_REPLACEMENT)
+#if !defined(NDEBUG)
+void codegen_set_replacement_point_notrap(codegendata *cd, s4 type);
+void codegen_set_replacement_point(codegendata *cd, s4 type);
+#else
+void codegen_set_replacement_point_notrap(codegendata *cd);
+void codegen_set_replacement_point(codegendata *cd);
+#endif
+#endif /* defined(ENABLE_REPLACEMENT) */
+
 void codegen_finish(jitdata *jd);
 
 codeinfo *codegen_createnativestub(functionptr f, methodinfo *m);
@@ -198,8 +328,8 @@ u1 *intrp_createnativestub(functionptr f, jitdata *jd, methoddesc *md);
 void removecompilerstub(u1 *stub);
 void removenativestub(u1 *stub);
 
-s4 codegen_reg_of_var(registerdata *rd, u2 opcode, stackptr v, s4 tempregnum);
-s4 codegen_reg_of_dst(jitdata *jd, new_instruction *iptr, s4 tempregnum);
+s4 codegen_reg_of_var(u2 opcode, varinfo *v, s4 tempregnum);
+s4 codegen_reg_of_dst(jitdata *jd, instruction *iptr, s4 tempregnum);
 
 #if defined(ENABLE_THREADS)
 void codegen_threadcritrestart(codegendata *cd, int offset);
@@ -210,12 +340,6 @@ void codegen_threadcritstop(codegendata *cd, int offset);
 /* machine dependent functions */
 u1 *md_codegen_get_pv_from_pc(u1 *ra);
 
-bool codegen(jitdata *jd);
-
-#if defined(ENABLE_INTRP)
-bool intrp_codegen(jitdata *jd);
-#endif
-
 #endif /* _CODEGEN_COMMON_H */