Author: chromatic
Date: Sat May 5 01:01:11 2007
New Revision: 18424
Modified:
trunk/src/interpreter.c
trunk/src/jit.c
trunk/src/pic_jit.c
Log:
Minor coding standard cleanups I made while creating r18423.
Modified: trunk/src/interpreter.c
==============================================================================
--- trunk/src/interpreter.c (original)
+++ trunk/src/interpreter.c Sat May 5 01:01:11 2007
@@ -481,8 +481,9 @@
return ((Parrot_jit_info_t *)interp->code->jit_info)->arena.start;
code_start = interp->code->base.data;
- code_size = interp->code->base.size;
- code_end = code_start + code_size;
+ code_size = interp->code->base.size;
+ code_end = code_start + code_size;
+
# if defined HAVE_COMPUTED_GOTO && PARROT_I386_JIT_CGP
# ifdef __GNUC__
# ifdef PARROT_I386
@@ -494,6 +495,7 @@
interp->code->jit_info =
jit_info = parrot_build_asm(interp, code_start, code_end,
NULL, JIT_CODE_FILE);
+
return jit_info->arena.start;
#else
return NULL;
@@ -718,8 +720,7 @@
if (Interp_flags_TEST(interp, PARROT_PROFILE_FLAG)) {
core = runops_profile_core;
if (interp->profile == NULL) {
- interp->profile = (RunProfile *)
- mem_sys_allocate_zeroed(sizeof (RunProfile));
+ interp->profile =
mem_allocate_zeroed_typed(RunProfile);
interp->profile->data = (ProfData *)
mem_sys_allocate_zeroed((interp->op_count +
PARROT_PROF_EXTRA) * sizeof
(ProfData));
@@ -785,8 +786,6 @@
}
}
-
-
/*
=item C<static void
Modified: trunk/src/jit.c
==============================================================================
--- trunk/src/jit.c (original)
+++ trunk/src/jit.c Sat May 5 01:01:11 2007
@@ -1349,75 +1349,79 @@
*/
Parrot_jit_info_t *
-parrot_build_asm(Interp *interp,
- opcode_t *code_start, opcode_t *code_end,
+parrot_build_asm(Interp *interp, opcode_t *code_start, opcode_t *code_end,
void *objfile, INTVAL jit_type)
{
- UINTVAL i;
- char *new_arena;
- Parrot_jit_info_t *jit_info = NULL;
- opcode_t cur_opcode_byte, *cur_op;
- Parrot_jit_optimizer_section_ptr cur_section;
- PackFile_Segment *jit_seg;
- INTVAL * n_regs_used; /* INSP in PBC */
+ int n;
+ UINTVAL i;
+ char *new_arena;
+ Parrot_jit_info_t *jit_info = NULL;
+ opcode_t cur_opcode_byte;
+ opcode_t *cur_op;
+ PackFile_Segment *jit_seg;
+ char *map;
+ Parrot_jit_fn_info_t *op_func;
+ INTVAL *n_regs_used; /* INSP in PBC */
+ op_info_t *op_info;
+ const jit_arch_info *arch_info;
+ int needs_fs; /* fetch/store */
+
/* XXX
* no longer referenced due to disabled code below
char *name;
*/
- char *map;
- Parrot_jit_fn_info_t *op_func;
+
+ Parrot_jit_optimizer_section_ptr cur_section;
+
#if EXEC_CAPABLE
Parrot_exec_objfile_t *obj = (Parrot_exec_objfile_t *)objfile;
#endif
- op_info_t *op_info;
- int n;
- const jit_arch_info *arch_info;
- int needs_fs; /* fetch/store */
-
- jit_info = interp->code->jit_info =
- mem_allocate_typed(Parrot_jit_info_t);
-
- jit_info->flags = jit_type & JIT_CODE_RECURSIVE;
- jit_type &= ~ JIT_CODE_RECURSIVE;
- jit_info->code_type = jit_type;
- needs_fs = jit_type != JIT_CODE_SUB_REGS_ONLY;
+
+ jit_info = interp->code->jit_info = mem_allocate_typed(Parrot_jit_info_t);
+
+ jit_info->flags = jit_type & JIT_CODE_RECURSIVE;
+ jit_type &= ~ JIT_CODE_RECURSIVE;
+ jit_info->code_type = jit_type;
+ needs_fs = jit_type
+ != JIT_CODE_SUB_REGS_ONLY;
#if EXEC_CAPABLE
if (objfile) {
- op_func = op_exec;
+ op_func = op_exec;
jit_info->objfile = obj;
}
else
#endif
{
- op_func = op_jit;
+ op_func = op_jit;
jit_info->objfile = NULL;
}
- /* reset some exctall bits - all is JITed
+ /* reset some extcall bits - all is JITed
*/
if (jit_type == JIT_CODE_SUB_REGS_ONLY) {
op_func[PARROT_OP_set_returns_pc].extcall = 0;
- op_func[PARROT_OP_get_params_pc].extcall = 0;
- op_func[PARROT_OP_get_params_pc].extcall = 0;
- op_func[PARROT_OP_invokecc_p].extcall = 0;
+ op_func[PARROT_OP_get_params_pc].extcall = 0;
+ op_func[PARROT_OP_get_params_pc].extcall = 0;
+ op_func[PARROT_OP_invokecc_p].extcall = 0;
}
+
/* get register mappings and such */
arch_info = jit_info->arch_info = Parrot_jit_init(interp);
/*
- * check if IMCC did all he work. If yes, we got a PF segment with
+ * check if IMCC did all the work. If yes, we have a PF segment with
* register allocation information inside.
* See imcc/jit.c for more
*/
#if 0
/* XXX
- * JIT segs are currently not build
+ * JIT segs are currently not built
* the find_segments also segfaults on PPC eval_2
* maybe something not initialized correctly
* - disabled --leo
*/
- name = mem_sys_allocate(strlen(interp->code->base.name) + 5);
+ name = mem_sys_allocate(strlen(interp->code->base.name) + 5);
sprintf(name, "%s_JIT", interp->code->base.name);
jit_seg = PackFile_find_segment(interp,
interp->code->base.dir, name, 0);
@@ -1438,7 +1442,7 @@
/* Byte code size in opcode_t's */
jit_info->arena.map_size = (code_end - code_start) + 1;
- jit_info->arena.op_map =
+ jit_info->arena.op_map =
(Parrot_jit_opmap_t *)mem_sys_allocate_zeroed(
jit_info->arena.map_size * sizeof (* (jit_info->arena.op_map)));
@@ -1446,26 +1450,28 @@
Parrot_jit_init_arenas(jit_info);
#else
jit_info->arena.size = 1024;
+
/* estimate size needed
* 10 times pbc code size seems to be enough for i386
*/
- if ((size_t)jit_info->arena.map_size * 10 > (size_t)jit_info->arena.size)
- jit_info->arena.size = jit_info->arena.map_size * 10;
- jit_info->native_ptr = jit_info->arena.start =
+ if ((size_t)jit_info->arena.map_size * 20 > (size_t)jit_info->arena.size)
+ jit_info->arena.size = jit_info->arena.map_size * 20;
+ jit_info->native_ptr = jit_info->arena.start =
(char *)mem_alloc_executable((size_t)jit_info->arena.size);
+
# if EXEC_CAPABLE
if (obj)
jit_info->objfile->text.code = jit_info->arena.start;
# endif
#endif
- jit_info->op_i = 0;
+ jit_info->op_i = 0;
jit_info->arena.fixups = NULL;
/* The first section */
- cur_section = jit_info->optimizer->cur_section =
- jit_info->optimizer->sections;
- map = jit_info->optimizer->map_branch;
+ cur_section = jit_info->optimizer->cur_section
+ = jit_info->optimizer->sections;
+ map = jit_info->optimizer->map_branch;
/*
* from C's ABI all the emitted code here is one (probably big)
@@ -1474,6 +1480,7 @@
*/
jit_info->cur_op = cur_section->begin;
(arch_info->regs[jit_type].jit_begin)(jit_info, interp);
+
/*
* op_map holds the offset from arena.start
* of the parrot op at the given opcode index
@@ -1512,9 +1519,8 @@
set_reg_usage(interp, cur_op);
/* Load mapped registers for this section, if JIT */
- if (!jit_seg && cur_section->isjit && needs_fs) {
+ if (!jit_seg && cur_section->isjit && needs_fs)
Parrot_jit_load_registers(jit_info, interp, 0);
- }
/* The first opcode of each section doesn't have a previous one since
* it's impossible to be sure which was it */
@@ -1530,7 +1536,7 @@
new_arena = (char
*)mem_realloc_executable(jit_info->arena.start,
(size_t)jit_info->arena.size * 2);
jit_info->arena.size *= 2;
- jit_info->native_ptr = new_arena +
+ jit_info->native_ptr = new_arena +
(jit_info->native_ptr - jit_info->arena.start);
jit_info->arena.start = new_arena;
# if EXEC_CAPABLE
@@ -1582,9 +1588,9 @@
* via the wrapper opcode, which just runs one opcode
* see ops/core.ops for more
*/
- if (cur_opcode_byte >= jit_op_count()) {
+ if (cur_opcode_byte >= jit_op_count())
cur_opcode_byte = CORE_OPS_wrapper__;
- }
+
(op_func[cur_opcode_byte].fn) (jit_info, interp);
if (CALLS_C_CODE(cur_opcode_byte) && needs_fs) {
@@ -1598,41 +1604,55 @@
jit_info->prev_op = cur_op;
op_info = &interp->op_info_table[*cur_op];
- n = op_info->op_count;
+ n = op_info->op_count;
ADD_OP_VAR_PART(interp, interp->code, cur_op, n);
cur_op += n;
+
/* update op_i and cur_op accordingly */
- jit_info->op_i += n;
+ jit_info->op_i += n;
jit_info->cur_op += n;
if (*jit_info->prev_op == PARROT_OP_set_args_pc &&
jit_type == JIT_CODE_SUB_REGS_ONLY) {
assert(*cur_op == PARROT_OP_set_p_pc);
- cur_op += 3; /* skip it */
- jit_info->op_i += 3;
+
+ /* skip it */
+ cur_op += 3;
+ jit_info->op_i += 3;
jit_info->cur_op += 3;
+
jit_info->arena.op_map[jit_info->op_i].offset =
jit_info->native_ptr - jit_info->arena.start;
+
assert(*cur_op == PARROT_OP_get_results_pc);
+
/* now emit the call - use special op for this */
(op_func[PARROT_OP_pic_callr___pc].fn)(jit_info, interp);
+
/* and the get_results */
(op_func[*cur_op].fn)(jit_info, interp);
+
op_info = &interp->op_info_table[*cur_op];
- n = op_info->op_count;
+ n = op_info->op_count;
ADD_OP_VAR_PART(interp, interp->code, cur_op, n);
+
cur_op += n;
+
/* update op_i and cur_op accordingly */
- jit_info->op_i += n;
+ jit_info->op_i += n;
jit_info->cur_op += n;
+
jit_info->arena.op_map[jit_info->op_i].offset =
jit_info->native_ptr - jit_info->arena.start;
+
/* now at invoke */
assert(*cur_op == PARROT_OP_invokecc_p);
- cur_op += 2; /* skip it */
- jit_info->op_i += 2;
- jit_info->cur_op += 2;
+
+ cur_op += 2; /* skip it */
+ jit_info->op_i += 2;
+ jit_info->cur_op += 2;
}
+
/* if this is a branch target, align it */
#ifdef jit_emit_noop
# if JUMP_ALIGN
@@ -1644,7 +1664,6 @@
}
# endif
#endif
-
/* set the offset */
jit_info->arena.op_map[jit_info->op_i].offset =
jit_info->native_ptr - jit_info->arena.start;
@@ -1653,6 +1672,7 @@
/* Save mapped registers back to the Parrot registers */
if (!jit_seg && cur_section->isjit && needs_fs)
Parrot_jit_save_registers(jit_info, interp, 0);
+
/* update the offset for saved registers */
jit_info->arena.op_map[jit_info->op_i].offset =
jit_info->native_ptr - jit_info->arena.start;
@@ -1666,6 +1686,7 @@
* restore register usage
*/
CONTEXT(interp->ctx)->n_regs_used = n_regs_used;
+
/* Do fixups before converting offsets */
(arch_info->jit_dofixup)(jit_info, interp);
Modified: trunk/src/pic_jit.c
==============================================================================
--- trunk/src/pic_jit.c (original)
+++ trunk/src/pic_jit.c Sat May 5 01:01:11 2007
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2006, The Perl Foundation.
+Copyright (C) 2006-2007, The Perl Foundation.
$Id$
=head1 NAME
@@ -68,9 +68,11 @@
pic_test_func(Interp *interp, INTVAL *sig_bits, void **args)
{
INTVAL * const result = (INTVAL*) args[0];
- const INTVAL i = (INTVAL) args[1];
- const INTVAL j = (INTVAL) args[2];
+ INTVAL const i = (INTVAL) args[1];
+ INTVAL const j = (INTVAL) args[2];
+
*result = i + j;
+
return args[3];
}
# endif
@@ -80,23 +82,27 @@
{
const jit_arch_info * const info = Parrot_jit_init(interp);
const jit_arch_regs * const regs = info->regs + JIT_CODE_SUB_REGS_ONLY;
- INTVAL * const n_regs_used = PMC_sub(sub)->n_regs_used;
+ INTVAL * const n_regs_used = PMC_sub(sub)->n_regs_used;
/* if the sub is using more regs than the arch has
* we don't JIT it at all
*/
if (n_regs_used[REGNO_INT] > regs->n_mapped_I)
return 0;
+
if (n_regs_used[REGNO_NUM] > regs->n_mapped_F)
return 0;
+
/* if the Sub is using S regs, we can't JIT it yet */
if (n_regs_used[REGNO_STR])
return 0;
+
/* if the Sub is using more than 1 P reg, we can't JIT it yet
* the P reg could be a (recursive) call to a sub
*/
if (n_regs_used[REGNO_PMC] > 1)
return 0;
+
return 1;
}
@@ -110,55 +116,58 @@
if (*start != PARROT_OP_get_params_pc)
return 0;
+
sig_params = seg->const_table->constants[start[1]]->u.key;
+
/* verify that we actually can pass arguments */
ASSERT_SIG_PMC(sig_params);
n = parrot_pic_check_sig(interp, sig_args, sig_params, &type);
- if (n == -1) {
- /* arg count mismatch */
+
+ /* arg count mismatch */
+ if (n == -1)
return 0;
- }
- if (!n) {
- /* no args - this would be safe, if the JIT code could already
- * deal with no args
- * TODO
- */
+
+ /* no args - this would be safe, if the JIT code could already
+ * deal with no args
+ * TODO
+ */
+ if (!n)
return 0;
- }
- type &= ~PARROT_ARG_CONSTANT;
- switch (type) {
+
+ switch (type & ~PARROT_ARG_CONSTANT) {
case PARROT_ARG_INTVAL:
case PARROT_ARG_FLOATVAL:
return 1;
+ default:
+ return 0;
}
- return 0;
}
static int
returns_match_results(Interp *interp, PMC *sig_ret, PMC *sig_result)
{
int type;
-
const int n = parrot_pic_check_sig(interp, sig_ret, sig_result, &type);
- if (n == -1) {
- /* arg count mismatch */
+
+ /* arg count mismatch */
+ if (n == -1)
return 0;
- }
- if (!n) {
- /* no args - this would be safe, if the JIT code could already
- * deal with no args
- * TODO
- */
+
+ /* no args - this would be safe, if the JIT code could already
+ * deal with no args
+ * TODO
+ */
+ if (!n)
return 0;
- }
- type &= ~PARROT_ARG_CONSTANT;
- switch (type) {
+
+ switch (type & ~PARROT_ARG_CONSTANT ) {
case PARROT_ARG_INTVAL:
case PARROT_ARG_FLOATVAL:
return 1;
+ default:
+ return 0;
}
- return 0;
}
static int
@@ -166,28 +175,36 @@
{
PMC *called, *sig_results;
- opcode_t * pc = *set_args;
+ opcode_t * pc = *set_args;
PMC * const sig_args =
PMC_sub(sub)->seg->const_table->constants[pc[1]]->u.key;
/* ignore the signature for now */
pc += 2 + SIG_ELEMS(sig_args);
+
if (*pc != PARROT_OP_set_p_pc)
return 0;
+
called = PMC_sub(sub)->seg->const_table->constants[pc[2]]->u.key;
- if (called != sub) {
- /* we can JIT just recursive subs for now */
+
+ /* we can JIT just recursive subs for now */
+ if (called != sub)
return 0;
- }
+
pc += 3;
+
if (*pc != PARROT_OP_get_results_pc)
return 0;
- sig_results = PMC_sub(sub)->seg->const_table->constants[pc[1]]->u.key;
- pc += 2 + SIG_ELEMS(sig_results);
+
+ sig_results = PMC_sub(sub)->seg->const_table->constants[pc[1]]->u.key;
+ pc += 2 + SIG_ELEMS(sig_results);
+
if (*pc != PARROT_OP_invokecc_p)
return 0;
- pc += 2;
- *set_args = pc;
+
+ pc += 2;
+ *set_args = pc;
+
return 1;
}
@@ -195,16 +212,18 @@
ops_jittable(Interp *interp, PMC *sub, PMC *sig_results, PackFile_ByteCode
*seg,
opcode_t *pc, opcode_t *end, int *flags)
{
+ int op;
+ op_info_t *op_info;
+ int n;
+
while (pc < end) {
- /*
- * some special opcodes, which are handled, but not marked
- * as JITtable
- */
- const int op = *pc;
- op_info_t * const op_info = interp->op_info_table + op;
- int n = op_info->op_count;
+ /* special opcodes which are handled, but not marked as JITtable */
int i;
+ op = *pc;
+ op_info = interp->op_info_table + op;
+ n = op_info->op_count;
+
switch (op) {
case PARROT_OP_returncc:
case PARROT_OP_get_params_pc:
@@ -212,7 +231,8 @@
break;
case PARROT_OP_set_returns_pc:
{
- PMC * const sig_ret =
seg->const_table->constants[pc[1]]->u.key;
+ PMC *sig_ret;
+ sig_ret = seg->const_table->constants[pc[1]]->u.key;
if (!returns_match_results(interp, sig_ret, sig_results))
return 0;
}
@@ -225,10 +245,9 @@
*flags |= JIT_CODE_RECURSIVE;
continue;
default:
- if (op_jit[op].extcall != 0) {
- /* non-jitted or JITted vtable */
+ /* non-jitted or JITted vtable */
+ if (op_jit[op].extcall != 0)
return 0;
- }
break;
}
/*
@@ -274,11 +293,12 @@
*/
if (!jit_can_compile_sub(interp, sub))
return 0;
+
/*
* 2) check if get_params is matching set_args
*/
- base = PMC_sub(sub)->seg->base.data;
+ base = PMC_sub(sub)->seg->base.data;
start = base + PMC_sub(sub)->start_offs;
end = base + PMC_sub(sub)->end_offs;
@@ -307,17 +327,17 @@
/*
* create JIT code - just a test
*/
- opcode_t * const base = PMC_sub(sub)->seg->base.data;
+ opcode_t * const base = PMC_sub(sub)->seg->base.data;
opcode_t * const start = base + PMC_sub(sub)->start_offs;
opcode_t * const end = base + PMC_sub(sub)->end_offs;
/* TODO pass Sub */
- Parrot_jit_info_t * jit_info =
- parrot_build_asm(interp,
- start, end, NULL,
- JIT_CODE_SUB_REGS_ONLY | flags);
+ Parrot_jit_info_t * jit_info = parrot_build_asm(interp,
+ start, end, NULL, JIT_CODE_SUB_REGS_ONLY | flags);
+
if (!jit_info)
return NULLfunc;
+
return (funcptr_t) jit_info->arena.start;
# endif
}
@@ -341,7 +361,6 @@
#endif /* HAS_JIT */
-
/*
=back
@@ -359,7 +378,6 @@
*/
-
/*
* Local variables:
* c-file-style: "parrot"