* Removed all Id tags.
[cacao.git] / src / vm / jit / codegen-common.h
index c23ceef8b2fc7889d4dea9ab2173707ffa9bf43a..a571b71034273864c0b03b85b5565d17bec3be54 100644 (file)
@@ -22,8 +22,6 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: codegen-common.h 7283 2007-02-04 19:41:14Z pm $
-
 */
 
 
 
 /* forward typedefs ***********************************************************/
 
-typedef struct codegen_critical_section_t codegen_critical_section_t;
-typedef struct codegendata                codegendata;
-typedef struct jumpref                    jumpref;
-typedef struct dataref                    dataref;
-typedef struct exceptionref               exceptionref;
-typedef struct patchref                   patchref;
-typedef struct linenumberref              linenumberref;
+typedef struct codegendata            codegendata;
+typedef struct branchref              branchref;
+typedef struct branch_label_ref_t     branch_label_ref_t;
+typedef struct critical_section_ref_t critical_section_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"
@@ -86,20 +86,23 @@ typedef struct linenumberref              linenumberref;
 #define BRANCH_GT               (ICMD_IFGT - ICMD_IFEQ)
 #define BRANCH_LE               (ICMD_IFLE - ICMD_IFEQ)
 
-#define BRANCH_NAN              256
+#define BRANCH_ULT              256
+#define BRANCH_ULE              257
+#define BRANCH_UGE              258
+#define BRANCH_UGT              259
 
+#define BRANCH_NAN              260
 
-/************************* critical sections  *********************************/
 
-struct codegen_critical_section_t {
-       codegen_critical_section_t *next;
-       s4                  mcodebegin;
-       s4                  mcodeend;
-       s4                  mcoderestart;
-};
+/* common branch options ******************************************************/
+
+#define BRANCH_OPT_NONE         0
 
 
+/* 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)     */
@@ -125,13 +128,14 @@ struct codegendata {
 
        jumpref        *jumpreferences; /* list of jumptable target addresses     */
 
-#if defined(__I386__) || defined(__X86_64__) || defined(__XDSPCORE__) || defined(ENABLE_INTRP) || defined(__S390__)
+#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; */
+/*     list_t         *patchrefs; */
        patchref       *patchrefs;
+       list_t         *brancheslabel;
+       list_t         *listcritical;   /* list of critical sections              */
 
        linenumberref  *linenumberreferences; /* list of line numbers and the     */
                                        /* program counters of their first        */
@@ -142,11 +146,6 @@ struct codegendata {
 
        methodinfo     *method;
 
-       codegen_critical_section_t *threadcrit; /* List of critical code regions          */
-       codegen_critical_section_t threadcritcurrent;
-       s4                 threadcritcount; /* Number of critical regions         */
-
-       s4              maxstack;
        s4              stackframesize;    /* stackframe size of this method      */
 
 #if defined(ENABLE_REPLACEMENT)
@@ -155,6 +154,50 @@ struct codegendata {
 };
 
 
+#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_t linkage;
+};
+
+
+/* critical_section_ref_t *****************************************************/
+
+struct critical_section_ref_t {
+       s4         start;           /* relative offset to method entry-point      */
+       s4         end;
+       s4         restart;
+       listnode_t linkage;
+};
+
+
 /* jumpref ********************************************************************/
 
 struct jumpref {
@@ -172,16 +215,6 @@ struct dataref {
 };
 
 
-/* exceptionref ***************************************************************/
-
-struct exceptionref {
-       s4            branchpos;    /* patching position in code segment          */
-       s4            reg;          /* used for ArrayIndexOutOfBounds index reg   */
-       functionptr   function;     /* function pointer to generate exception     */
-       exceptionref *next;         /* next element in exceptionref list          */
-};
-
-
 /* patchref *******************************************************************/
 
 struct patchref {
@@ -227,6 +260,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);
@@ -235,17 +275,10 @@ void codegen_increase(codegendata *cd);
 u1 *codegen_ncode_increase(codegendata *cd, u1 *ncodeptr);
 #endif
 
-void codegen_add_branch_ref(codegendata *cd, basicblock *target);
-/* XXX REMOVE ME: don't-break-trunk macro */
-#define codegen_addreference codegen_add_branch_ref
+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_add_patch_ref(codegendata *cd, functionptr patcher, voidptr ref,
@@ -269,16 +302,17 @@ void codegen_set_replacement_point(codegendata *cd);
 
 void codegen_finish(jitdata *jd);
 
-codeinfo *codegen_createnativestub(functionptr f, methodinfo *m);
 #if defined(ENABLE_DISASSEMBLER)
 void codegen_disassemble_nativestub(methodinfo *m, u1 *start, u1 *end);
 #endif
 
-void codegen_start_native_call(u1 *datasp, u1 *pv, u1 *sp, u1 *ra);
-java_objectheader *codegen_finish_native_call(u1 *datasp);
+/* stub functions */
 
-u1 *createcompilerstub(methodinfo *m);
-u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd);
+u1       *codegen_generate_stub_compiler(methodinfo *m);
+codeinfo *codegen_generate_stub_native(methodinfo *m, functionptr f);
+
+void      codegen_emit_stub_compiler(jitdata *jd);
+void      codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f);
 
 #if defined(ENABLE_INTRP)
 u1 *intrp_createcompilerstub(methodinfo *m);
@@ -288,23 +322,32 @@ u1 *intrp_createnativestub(functionptr f, jitdata *jd, methoddesc *md);
 void removecompilerstub(u1 *stub);
 void removenativestub(u1 *stub);
 
+void codegen_start_native_call(u1 *datasp, u1 *pv, u1 *sp, u1 *ra);
+java_object_t *codegen_finish_native_call(u1 *datasp);
+
 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);
-void codegen_threadcritstart(codegendata *cd, int offset);
-void codegen_threadcritstop(codegendata *cd, int offset);
+void codegen_critical_section_new(codegendata *cd);
+void codegen_critical_section_start(codegendata *cd);
+void codegen_critical_section_end(codegendata *cd);
+
+# define CODEGEN_CRITICAL_SECTION_NEW      codegen_critical_section_new(cd)
+# define CODEGEN_CRITICAL_SECTION_START    codegen_critical_section_start(cd)
+# define CODEGEN_CRITICAL_SECTION_END      codegen_critical_section_end(cd)
+#else
+# define CODEGEN_CRITICAL_SECTION_NEW      /* no-op */
+# define CODEGEN_CRITICAL_SECTION_START    /* no-op */
+# define CODEGEN_CRITICAL_SECTION_END      /* no-op */
 #endif
 
 /* machine dependent functions */
-void md_codegen_patch_branch(codegendata *cd, s4 branchmpc, s4 targetmpc);
-u1  *md_codegen_get_pv_from_pc(u1 *ra);
+u1 *md_codegen_get_pv_from_pc(u1 *ra);
 
-bool codegen(jitdata *jd);
 
-#if defined(ENABLE_INTRP)
-bool intrp_codegen(jitdata *jd);
+#if defined(ENABLE_SSA)
+void codegen_emit_phi_moves(jitdata *jd, basicblock *bptr);
 #endif
 
 #endif /* _CODEGEN_COMMON_H */