Author: leo
Date: Fri Feb  3 05:09:11 2006
New Revision: 11413

Modified:
   trunk/docs/jit.pod
   trunk/include/parrot/jit.h
   trunk/src/exec.c
   trunk/src/interpreter.c
   trunk/src/jit.c
Log:
JIT - cleanup

* rename build_asm to parrot_build_asm
* get rid of unused C<pc> aka C<cur_op> function argument in build_asm
  and some optimizer functions called from it
* remove unused Parrot_jit_emit_mov_xx prototypes
* return jit_info instead of JITted code start
* prepare for creating JIT code per subroutine


Modified: trunk/docs/jit.pod
==============================================================================
--- trunk/docs/jit.pod  (original)
+++ trunk/docs/jit.pod  Fri Feb  3 05:09:11 2006
@@ -90,12 +90,12 @@ array, which maps from opcode addresses 
 
 =item jit.c
 
-B<build_asm>() is the main routine of the code generator, which loops over the
-parrot bytecode, calling the code generating routines for each opcode while
-filling in the B<op_map> array.  This array is used by the JIT subsystem to
-perform certain types of fixups on native code, as well as by the native code
-itself to convert bytecode program counters values (opcode_t *'s) to hardware
-program counter values.
+B<parrot_build_asm>() is the main routine of the code generator, which loops
+over the parrot bytecode, calling the code generating routines for each opcode
+while filling in the B<op_map> array.  This array is used by the JIT subsystem
+to perform certain types of fixups on native code, as well as by the native
+code itself to convert bytecode program counters values (opcode_t *'s) to
+hardware program counter values.
 
 The bytecode is considered an array of B<opcode_t> sized elements, with
 parallel entries in B<op_map>.  B<op_map> is initially populated with the
@@ -512,7 +512,7 @@ from Parrot_jit_debug, which generates a
 B<info stabs> for more (or less :-()
 
 The following script calls F<ddd> (the graphic debugger fronted) and attaches
-the symbol file, after it got built in F<build_asm>.
+the symbol file, after it got built in F<parrot_build_asm>.
 
     # dddp
     # run ddd parrot with given file

Modified: trunk/include/parrot/jit.h
==============================================================================
--- trunk/include/parrot/jit.h  (original)
+++ trunk/include/parrot/jit.h  Fri Feb  3 05:09:11 2006
@@ -9,9 +9,6 @@
 
 typedef void (*jit_f)(Interp *interpreter, opcode_t *pc);
 
-jit_f build_asm(Interp *interpreter, opcode_t *pc,
-                opcode_t *code_start, opcode_t *code_end,
-                void *objfile);
 
 void Parrot_destroy_jit(void *);
 
@@ -246,23 +243,8 @@ void Parrot_exec_restart_op(Parrot_jit_i
 
 /*
  * interface functions for the register save/restore code
- *
- * 1) old style with memory location of the register
- */
-
-void Parrot_jit_emit_mov_mr_n(
-    Interp *interpreter, char *mem, int);
-void Parrot_jit_emit_mov_mr(
-    Interp *interpreter, char *mem, int);
-void Parrot_jit_emit_mov_rm_n(
-    Interp *interpreter, int reg, char *mem);
-void Parrot_jit_emit_mov_rm(
-    Interp *interpreter, int reg, char *mem);
-
-/*
- * 2) new style with offsets relative to the base register
- *    These are used if the platform defines the macro
- *    Parrot_jit_emit_get_base_reg_no
+ * with offsets relative to the base register (obtained by
+ * Parrot_jit_emit_get_base_reg_no)
  */
 void Parrot_jit_emit_mov_mr_n_offs(
     Interp *, int base_reg, size_t offs, int src_reg);
@@ -273,6 +255,19 @@ void Parrot_jit_emit_mov_rm_n_offs(
 void Parrot_jit_emit_mov_rm_offs(
     Interp *, int dst_reg, int base_reg, size_t offs);
 
+typedef enum {
+    JIT_CODE_FILE,
+    JIT_CODE_SUB,
+    JIT_CODE_SUB_REGS_ONLY
+} enum_jit_code_type;
+
+/*
+ * interface to create JIT code
+ */
+Parrot_jit_info_t *
+parrot_build_asm(Interp *interpreter, 
+                opcode_t *code_start, opcode_t *code_end,
+                void *objfile, enum_jit_code_type);
 /*
  * NCI interface
  */

Modified: trunk/src/exec.c
==============================================================================
--- trunk/src/exec.c    (original)
+++ trunk/src/exec.c    Fri Feb  3 05:09:11 2006
@@ -75,8 +75,8 @@ Parrot_exec(Interp *interpreter, opcode_
     Parrot_exec_rel_addr = (char **)mem_sys_allocate_zeroed(4 * sizeof(char 
*));
     obj->bytecode_header_size =
         (interpreter->code->base.file_offset + 4) * sizeof(opcode_t);
-    (void) build_asm(interpreter, pc, code_start, code_end, obj);
-    jit_info = interpreter->code->jit_info;
+    jit_info = parrot_build_asm(interpreter, code_start, code_end, 
+            obj, JIT_CODE_FILE);
 
     /* TODO Go zero the calls to jited opcodes. */
     /* Place the program code in the data section. */

Modified: trunk/src/interpreter.c
==============================================================================
--- trunk/src/interpreter.c     (original)
+++ trunk/src/interpreter.c     Fri Feb  3 05:09:11 2006
@@ -472,6 +472,8 @@ init_jit(Interp *interpreter, opcode_t *
     UINTVAL code_size;          /* in opcodes */
     opcode_t *code_end;
     jit_f jit_code;
+    Parrot_jit_info_t *jit_info;
+
     if (interpreter->code->jit_info)
         return ((Parrot_jit_info_t *)interpreter->code->jit_info)->arena.start;
 
@@ -486,8 +488,10 @@ init_jit(Interp *interpreter, opcode_t *
 #    endif
 #  endif
 
-    jit_code = build_asm(interpreter, code_start, code_start, code_end, NULL);
-    return F2DPTR(jit_code);
+    interpreter->code->jit_info = 
+        jit_info = parrot_build_asm(interpreter, code_start, code_end, 
+            NULL, JIT_CODE_FILE);
+    return jit_info->arena.start;
 #else
     return NULL;
 #endif

Modified: trunk/src/jit.c
==============================================================================
--- trunk/src/jit.c     (original)
+++ trunk/src/jit.c     Fri Feb  3 05:09:11 2006
@@ -107,7 +107,7 @@ insert_fixup_targets(Interp* interpreter
 =item C<static void
 make_branch_list(Interp *interpreter,
         Parrot_jit_optimizer_t * optimizer,
-        opcode_t *cur_op, opcode_t *code_start, opcode_t *code_end)>
+        opcode_t *code_start, opcode_t *code_end)>
 
 C<< optimizer->map_branch >> parallels the opcodes with a list of
 branch information and register mapping information
@@ -132,10 +132,13 @@ got mapped
 static void
 make_branch_list(Interp *interpreter,
         Parrot_jit_optimizer_t * optimizer,
-        opcode_t *cur_op, opcode_t *code_start, opcode_t *code_end)
+         opcode_t *code_start, opcode_t *code_end)
 {
     op_info_t *op_info;
     char *branch;
+    opcode_t *cur_op;
+
+    cur_op = code_start;
 
     /* Allocate space for the branch information and register map */
     optimizer->map_branch = branch =
@@ -386,7 +389,7 @@ set_register_usage(Interp *interpreter,
 =item C<static void
 make_sections(Interp *interpreter,
         Parrot_jit_optimizer_t * optimizer,
-        opcode_t *cur_op, opcode_t *code_start, opcode_t *code_end)>
+        opcode_t *code_start, opcode_t *code_end)>
 
 I386 has JITed vtables, which have the vtable# in extcall.
 
@@ -404,13 +407,14 @@ This C<Parrot_jit_vtable_n_op()> does us
 static void
 make_sections(Interp *interpreter,
         Parrot_jit_optimizer_t * optimizer,
-        opcode_t *cur_op, opcode_t *code_start, opcode_t *code_end)
+         opcode_t *code_start, opcode_t *code_end)
 {
     Parrot_jit_optimizer_section_ptr cur_section, t_section, prev_section;
     opcode_t *next_op;
     op_info_t *op_info;
     char *branch;
     int branched, start_new;
+    opcode_t *cur_op;
 
     branch = optimizer->map_branch;
 
@@ -896,17 +900,17 @@ debug_sections(Interp *interpreter,
 /*
 
 =item C<static Parrot_jit_optimizer_t *
-optimize_jit(Interp *interpreter, opcode_t *cur_op,
+optimize_jit(Interp *interpreter, 
              opcode_t *code_start, opcode_t *code_end)>
 
-Called by C<build_asm()> to run the optimizer.
+Called by C<parrot_build_asm()> to run the optimizer.
 
 =cut
 
 */
 
 static Parrot_jit_optimizer_t *
-optimize_jit(Interp *interpreter, opcode_t *cur_op,
+optimize_jit(Interp *interpreter, 
              opcode_t *code_start, opcode_t *code_end)
 {
     Parrot_jit_optimizer_t *optimizer;
@@ -916,10 +920,10 @@ optimize_jit(Interp *interpreter, opcode
         mem_sys_allocate_zeroed(sizeof(Parrot_jit_optimizer_t));
 
     /* Look, which opcodes might branch */
-    make_branch_list(interpreter, optimizer, cur_op, code_start, code_end);
+    make_branch_list(interpreter, optimizer, code_start, code_end);
 
     /* ok, let's loop again and generate the sections */
-    make_sections(interpreter, optimizer, cur_op, code_start, code_end);
+    make_sections(interpreter, optimizer, code_start, code_end);
 
     /* look where a section jumps to */
     make_branch_targets(interpreter, optimizer, code_start);
@@ -943,7 +947,7 @@ optimize_jit(Interp *interpreter, opcode
 /*
 
 =item C<static Parrot_jit_optimizer_t *
-optimize_imcc_jit(Interp *interpreter, opcode_t *cur_op,
+optimize_imcc_jit(Interp *interpreter, 
              opcode_t *code_start, opcode_t *code_end,
              struct PackFile_Segment *jit_seg)>
 
@@ -954,7 +958,7 @@ Generate optimizer stuff from the C<_JIT
 */
 
 static Parrot_jit_optimizer_t *
-optimize_imcc_jit(Interp *interpreter, opcode_t *cur_op,
+optimize_imcc_jit(Interp *interpreter, 
              opcode_t *code_start, opcode_t *code_end,
              struct PackFile_Segment *jit_seg)
 {
@@ -965,6 +969,7 @@ optimize_imcc_jit(Interp *interpreter, o
     Parrot_jit_optimizer_section_ptr section, prev;
     char *branch;
     op_info_t *op_info;
+    opcode_t *cur_op;
 
     /* Allocate space for the optimizer */
     optimizer = (Parrot_jit_optimizer_t *)
@@ -1250,10 +1255,10 @@ set_reg_usage(Interp *interpreter, opcod
 
 /*
 
-=item C<jit_f
-build_asm(Interp *interpreter, opcode_t *pc,
+=item C<Parrot_jit_info_t *
+parrot_build_asm(Interp *interpreter, 
           opcode_t *code_start, opcode_t *code_end,
-          void *objfile)>
+          void *objfile, enum_jit_code_type)>
 
 This is the main function of the JIT code generator.
 
@@ -1277,10 +1282,10 @@ file.
 
 */
 
-jit_f
-build_asm(Interp *interpreter, opcode_t *pc,
+Parrot_jit_info_t *
+parrot_build_asm(Interp *interpreter, 
           opcode_t *code_start, opcode_t *code_end,
-          void *objfile)
+          void *objfile, enum_jit_code_type jit_type)
 {
     UINTVAL i;
     char *new_arena;
@@ -1301,15 +1306,9 @@ build_asm(Interp *interpreter, opcode_t 
     op_info_t *op_info;
     int n;
 
-    /* XXX assume, we restart */
-    if (interpreter->code->jit_info) {
-        jit_info = interpreter->code->jit_info;
-        return (jit_f)D2FPTR(jit_info->arena.start);
-    }
-    else {
-        jit_info = interpreter->code->jit_info =
+    jit_info = interpreter->code->jit_info =
             mem_sys_allocate(sizeof(Parrot_jit_info_t));
-    }
+
     jit_info->objfile = NULL;
 #if EXEC_CAPABLE
     if (objfile) {
@@ -1342,10 +1341,10 @@ build_asm(Interp *interpreter, opcode_t 
 #endif
     if (jit_seg)
         jit_info->optimizer =
-            optimize_imcc_jit(interpreter, pc, code_start, code_end, jit_seg);
+            optimize_imcc_jit(interpreter, code_start, code_end, jit_seg);
     else
         jit_info->optimizer =
-            optimize_jit(interpreter, pc, code_start, code_end);
+            optimize_jit(interpreter, code_start, code_end);
 
     /* Attach the register map to the jit_info structure */
     jit_info->intval_map = intval_map;
@@ -1592,7 +1591,7 @@ build_asm(Interp *interpreter, opcode_t 
 #endif
 #ifdef PARROT_IA64
     ia64_sync_cache(jit_info->arena.start, jit_info->native_ptr);
-    return (jit_f)D2FPTR(&(jit_info->arena.start));
+    return jit_info;
 #endif
 
 
@@ -1603,11 +1602,14 @@ build_asm(Interp *interpreter, opcode_t 
          * TODO same like above here e.g. create ASM listing of code
          *      if real debug support isn't available
          */
-        Parrot_jit_debug(interpreter);
+        if (jit_type == JIT_CODE_FILE) {
+            interpreter->code->jit_info = jit_info;
+            Parrot_jit_debug(interpreter);
+        }
     }
 #endif
 
-    return (jit_f)D2FPTR(jit_info->arena.start);
+    return jit_info;
 }
 
 /*

Reply via email to