This unifies 32-bit and 64-bit insn selectors so code working on both arches can be shared.
Signed-off-by: Eduard - Gabriel Munteanu <eduard.munte...@linux360.ro> --- Makefile | 2 +- arch/x86/Makefile_32 | 2 +- arch/x86/Makefile_64 | 2 +- .../{insn-selector_32.brg => insn-selector.brg} | 100 ++++++++++---------- arch/x86/insn-selector_64.brg | 79 --------------- 5 files changed, 53 insertions(+), 132 deletions(-) rename arch/x86/{insn-selector_32.brg => insn-selector.brg} (95%) delete mode 100644 arch/x86/insn-selector_64.brg diff --git a/Makefile b/Makefile index 08cebfe..f654768 100644 --- a/Makefile +++ b/Makefile @@ -194,7 +194,7 @@ monoburg: $(E) " AS " $@ $(Q) $(CC) -c $(DEFAULT_CFLAGS) $(CFLAGS) $< -o $@ -arch/$(ARCH)/insn-selector$(ARCH_POSTFIX).c: monoburg FORCE +arch/$(ARCH)/insn-selector.c: monoburg FORCE $(E) " MONOBURG" $@ $(Q) $(MONOBURG) -p -e $(@:.c=.brg) > $@ diff --git a/arch/x86/Makefile_32 b/arch/x86/Makefile_32 index b55f4a6..71c9b85 100644 --- a/arch/x86/Makefile_32 +++ b/arch/x86/Makefile_32 @@ -3,7 +3,7 @@ ARCH_OBJS = \ arch/x86/disassemble.o \ arch/x86/emit-code.o \ arch/x86/exception.o \ - arch/x86/insn-selector_32.o \ + arch/x86/insn-selector.o \ arch/x86/instruction.o \ arch/x86/lir-printer.o \ arch/x86/registers_32.o \ diff --git a/arch/x86/Makefile_64 b/arch/x86/Makefile_64 index 7096e51..ab8c946 100644 --- a/arch/x86/Makefile_64 +++ b/arch/x86/Makefile_64 @@ -6,7 +6,7 @@ ARCH_OBJS = \ arch/x86/disassemble.o \ arch/x86/emit-code.o \ arch/x86/exception.o \ - arch/x86/insn-selector_64.o \ + arch/x86/insn-selector.o \ arch/x86/instruction.o \ arch/x86/lir-printer.o \ arch/x86/registers_64.o \ diff --git a/arch/x86/insn-selector_32.brg b/arch/x86/insn-selector.brg similarity index 95% rename from arch/x86/insn-selector_32.brg rename to arch/x86/insn-selector.brg index c0f418e..ac34ec0 100644 --- a/arch/x86/insn-selector_32.brg +++ b/arch/x86/insn-selector.brg @@ -144,7 +144,7 @@ freg: EXPR_FVALUE 0 expr = to_expr(tree); - esp = get_fixed_var(s->b_parent, REG_ESP); + esp = get_fixed_var(s->b_parent, REG_xSP); result = get_fpu_var(s->b_parent); state->reg1 = result; @@ -160,7 +160,7 @@ reg: freg 1 result = get_var(s->b_parent, J_INT); state->reg1 = result; - esp = get_fixed_var(s->b_parent, REG_ESP); + esp = get_fixed_var(s->b_parent, REG_xSP); select_insn(s, tree, reg_membase_insn(INSN_MOV_XMM_MEMBASE, in, esp, -4)); select_insn(s, tree, membase_reg_insn(INSN_MOV_MEMBASE_REG, esp, -4, result)); @@ -174,7 +174,7 @@ freg: reg 1 result = get_fpu_var(s->b_parent); state->reg1 = result; - esp = get_fixed_var(s->b_parent, REG_ESP); + esp = get_fixed_var(s->b_parent, REG_xSP); select_insn(s, tree, reg_membase_insn(INSN_MOV_REG_MEMBASE, in, esp, -4)); select_insn(s, tree, membase_reg_insn(INSN_MOV_MEMBASE_XMM, esp, -4, result)); @@ -359,7 +359,7 @@ reg: OP_MUL(reg, EXPR_LOCAL) 1 { struct var_info *eax; - eax = get_fixed_var(s->b_parent, REG_EAX); + eax = get_fixed_var(s->b_parent, REG_xAX); state->reg1 = eax; @@ -386,8 +386,8 @@ reg: OP_MUL_64(reg, reg) 1 { struct var_info *eax, *edx, *tmp1; - eax = get_fixed_var(s->b_parent, REG_EAX); - edx = get_fixed_var(s->b_parent, REG_EDX); + eax = get_fixed_var(s->b_parent, REG_xAX); + edx = get_fixed_var(s->b_parent, REG_xDX); state->reg1 = eax; state->reg2 = get_var(s->b_parent, J_INT); @@ -415,8 +415,8 @@ reg: OP_DIV(reg, reg) 1 struct var_info *edx; struct var_info *result; - edx = get_fixed_var(s->b_parent, REG_EDX); - result = get_fixed_var(s->b_parent, REG_EAX); + edx = get_fixed_var(s->b_parent, REG_xDX); + result = get_fixed_var(s->b_parent, REG_xAX); state->reg1 = result; @@ -443,8 +443,8 @@ reg: OP_REM(reg, EXPR_LOCAL) 1 div_reg_local(state, s, tree); - result = get_fixed_var(s->b_parent, REG_EAX); - remainder = get_fixed_var(s->b_parent, REG_EDX); + result = get_fixed_var(s->b_parent, REG_xAX); + remainder = get_fixed_var(s->b_parent, REG_xDX); select_insn(s, tree, reg_reg_insn(INSN_MOV_REG_REG, remainder, result)); } @@ -454,8 +454,8 @@ reg: OP_REM(reg, reg) 1 struct var_info *eax; struct var_info *result; - eax = get_fixed_var(s->b_parent, REG_EAX); - result = get_fixed_var(s->b_parent, REG_EDX); + eax = get_fixed_var(s->b_parent, REG_xAX); + result = get_fixed_var(s->b_parent, REG_xDX); state->reg1 = result; @@ -470,8 +470,8 @@ freg: OP_FREM(freg, freg) 1 state->reg1 = get_fpu_var(s->b_parent); - esp = get_fixed_var(s->b_parent, REG_ESP); - eax = get_fixed_var(s->b_parent, REG_EAX); + esp = get_fixed_var(s->b_parent, REG_xSP); + eax = get_fixed_var(s->b_parent, REG_xAX); select_insn(s, tree, reg_membase_insn(INSN_MOV_XMM_MEMBASE, state->left->reg1, esp, -8)); select_insn(s, tree, reg_membase_insn(INSN_MOV_XMM_MEMBASE, state->right->reg1, esp, -4)); @@ -514,7 +514,7 @@ freg: OP_FNEG(freg) 1 { struct var_info *result, *esp; - esp = get_fixed_var(s->b_parent, REG_ESP); + esp = get_fixed_var(s->b_parent, REG_xSP); result = get_fpu_var(s->b_parent); @@ -530,7 +530,7 @@ reg: OP_SHL(reg, reg) 1 { struct var_info *ecx; - ecx = get_fixed_var(s->b_parent, REG_ECX); + ecx = get_fixed_var(s->b_parent, REG_xCX); state->reg1 = state->left->reg1; @@ -557,7 +557,7 @@ reg: OP_SHR(reg, reg) 1 { struct var_info *ecx; - ecx = get_fixed_var(s->b_parent, REG_ECX); + ecx = get_fixed_var(s->b_parent, REG_xCX); state->reg1 = state->left->reg1; @@ -579,7 +579,7 @@ reg: OP_USHR(reg, reg) 1 { struct var_info *ecx; - ecx = get_fixed_var(s->b_parent, REG_ECX); + ecx = get_fixed_var(s->b_parent, REG_xCX); state->reg1 = state->left->reg1; @@ -690,11 +690,11 @@ reg: EXPR_INVOKE(arg) 1 method = expr->target_method; cu = method->compilation_unit; - eax = get_fixed_var(s->b_parent, REG_EAX); + eax = get_fixed_var(s->b_parent, REG_xAX); state->reg1 = get_var(s->b_parent, J_INT); if (get_method_return_type(method->type) == J_LONG) { - edx = get_fixed_var(s->b_parent, REG_EDX); + edx = get_fixed_var(s->b_parent, REG_xDX); state->reg2 = get_var(s->b_parent, J_INT); } @@ -721,11 +721,11 @@ reg: EXPR_INVOKEINTERFACE(arg) 1 method_offset = expr_method_index(expr) * sizeof(void *); - eax = get_fixed_var(s->b_parent, REG_EAX); + eax = get_fixed_var(s->b_parent, REG_xAX); state->reg1 = get_var(s->b_parent, J_INT); if (get_method_return_type(method->type) == J_LONG) { - edx = get_fixed_var(s->b_parent, REG_EDX); + edx = get_fixed_var(s->b_parent, REG_xDX); state->reg2 = get_var(s->b_parent, J_INT); } @@ -778,7 +778,7 @@ freg: EXPR_FINVOKE(arg) 1 invoke(s, tree, cu, method); - esp = get_fixed_var(s->b_parent, REG_ESP); + esp = get_fixed_var(s->b_parent, REG_xSP); select_insn(s, tree, membase_insn(INSN_FSTP_MEMBASE, esp, -4)); select_insn(s, tree, membase_reg_insn(INSN_MOV_MEMBASE_XMM, esp, -4, state->reg1)); } @@ -792,11 +792,11 @@ reg: EXPR_INVOKEVIRTUAL(arg) 1 expr = to_expr(tree); method = expr->target_method; - eax = get_fixed_var(s->b_parent, REG_EAX); + eax = get_fixed_var(s->b_parent, REG_xAX); state->reg1 = get_var(s->b_parent, J_INT); if (get_method_return_type(method->type) == J_LONG) { - edx = get_fixed_var(s->b_parent, REG_EDX); + edx = get_fixed_var(s->b_parent, REG_xDX); state->reg2 = get_var(s->b_parent, J_INT); } @@ -818,7 +818,7 @@ freg: EXPR_FINVOKEVIRTUAL(arg) 1 invokevirtual(state, s, tree); - esp = get_fixed_var(s->b_parent, REG_ESP); + esp = get_fixed_var(s->b_parent, REG_xSP); select_insn(s, tree, membase_insn(INSN_FSTP_MEMBASE, esp, -4)); select_insn(s, tree, membase_reg_insn(INSN_MOV_MEMBASE_XMM, esp, -4, state->reg1)); } @@ -829,8 +829,8 @@ reg: OP_CMPL(freg, freg) 1 state->reg1 = get_var(s->b_parent, J_INT); - esp = get_fixed_var(s->b_parent, REG_ESP); - eax = get_fixed_var(s->b_parent, REG_EAX); + esp = get_fixed_var(s->b_parent, REG_xSP); + eax = get_fixed_var(s->b_parent, REG_xAX); select_insn(s, tree, reg_membase_insn(INSN_MOV_XMM_MEMBASE, state->left->reg1, esp, -8)); select_insn(s, tree, reg_membase_insn(INSN_MOV_XMM_MEMBASE, state->right->reg1, esp, -4)); @@ -857,7 +857,7 @@ reg: OP_CMP(reg, EXPR_VALUE) 1 right = to_expr(expr->binary_right); state->reg1 = get_var(s->b_parent, J_INT); - eax = get_fixed_var(s->b_parent, REG_EAX); + eax = get_fixed_var(s->b_parent, REG_xAX); if (right->vm_type != J_LONG) { assert(!"OP_CMP implemented for J_LONG only"); @@ -1035,7 +1035,7 @@ reg: EXPR_NEW expr = to_expr(tree); - var = get_fixed_var(s->b_parent, REG_EAX); + var = get_fixed_var(s->b_parent, REG_xAX); state->reg1 = var; select_insn(s, tree, imm_insn(INSN_PUSH_IMM, @@ -1065,7 +1065,7 @@ reg: EXPR_NEWARRAY(reg) expr = to_expr(tree); - var = get_fixed_var(s->b_parent, REG_EAX); + var = get_fixed_var(s->b_parent, REG_xAX); state->reg1 = var; size = state->left->reg1; @@ -1132,10 +1132,10 @@ reg: EXPR_MULTIANEWARRAY(arg) expr = to_expr(tree); - var = get_fixed_var(s->b_parent, REG_EAX); + var = get_fixed_var(s->b_parent, REG_xAX); state->reg1 = var; - stack_ptr = get_fixed_var(s->b_parent, REG_ESP); + stack_ptr = get_fixed_var(s->b_parent, REG_xSP); size_check = to_expr(expr->multianewarray_dimensions); dimension = nr_args(to_expr(size_check->size_expr)); @@ -1158,7 +1158,7 @@ reg: EXPR_ANEWARRAY(reg) expr = to_expr(tree); - var = get_fixed_var(s->b_parent, REG_EAX); + var = get_fixed_var(s->b_parent, REG_xAX); state->reg1 = var; size = state->left->reg1; @@ -1195,7 +1195,7 @@ reg: EXPR_INSTANCEOF(reg) ref = state->left->reg1; - instanceof_result = get_fixed_var(s->b_parent, REG_EAX); + instanceof_result = get_fixed_var(s->b_parent, REG_xAX); state->reg1 = instanceof_result; select_insn(s, tree, imm_insn(INSN_PUSH_IMM, (unsigned long) expr->instanceof_class)); @@ -1346,13 +1346,13 @@ stmt: STMT_RETURN(reg) 1 expr = to_expr(tree); expr = to_expr(expr->unary_expression); - eax = get_fixed_var(s->b_parent, REG_EAX); + eax = get_fixed_var(s->b_parent, REG_xAX); src = state->left->reg1; select_insn(s, tree, reg_reg_insn(INSN_MOV_REG_REG, src, eax)); if (expr->vm_type == J_LONG) { - edx = get_fixed_var(s->b_parent, REG_EDX); + edx = get_fixed_var(s->b_parent, REG_xDX); src = state->left->reg2; select_insn(s, tree, reg_reg_insn(INSN_MOV_REG_REG, src, edx)); @@ -1370,7 +1370,7 @@ stmt: STMT_RETURN(freg) 1 expr = to_expr(expr->unary_expression); src = state->left->reg1; - esp = get_fixed_var(s->b_parent, REG_ESP); + esp = get_fixed_var(s->b_parent, REG_xSP); select_insn(s, tree, reg_membase_insn(INSN_MOV_XMM_MEMBASE, src, esp, -4)); select_insn(s, tree, membase_insn(INSN_FLD_MEMBASE, esp, -4)); @@ -1615,7 +1615,7 @@ stmt: STMT_ARRAY_STORE_CHECK(reg, reg) 1 stmt: STMT_ATHROW(reg) { - struct var_info *reg_eax = get_fixed_var(s->b_parent, REG_EAX); + struct var_info *reg_eax = get_fixed_var(s->b_parent, REG_xAX); select_insn(s, tree, reg_insn(INSN_PUSH_REG, state->left->reg1)); select_insn(s, tree, imm_insn(INSN_PUSH_IMM, (unsigned long)s->b_parent)); @@ -1855,7 +1855,7 @@ static void shift_reg_local(struct _MBState *state, struct basic_block *bb, disp = frame_local_offset(bb->b_parent->method, to_expr(expr->binary_right)); frame_ptr = bb->b_parent->frame_ptr; - shift_count = get_fixed_var(bb->b_parent, REG_ECX); + shift_count = get_fixed_var(bb->b_parent, REG_xCX); select_insn(bb, tree, membase_reg_insn(INSN_MOV_MEMBASE_REG, frame_ptr, disp, shift_count)); select_insn(bb, tree, reg_reg_insn(insn_type, shift_count, result)); @@ -1871,8 +1871,8 @@ static void div_reg_local(struct _MBState *state, struct basic_block *bb, expr = to_expr(tree); disp = frame_local_offset(bb->b_parent->method, to_expr(expr->binary_right)); - edx = get_fixed_var(bb->b_parent, REG_EDX); - result = get_fixed_var(bb->b_parent, REG_EAX); + edx = get_fixed_var(bb->b_parent, REG_xDX); + result = get_fixed_var(bb->b_parent, REG_xAX); state->reg1 = result; frame_ptr = bb->b_parent->frame_ptr; @@ -1889,11 +1889,11 @@ emulate_op_64(struct _MBState *state, struct basic_block *s, { struct var_info *eax, *edx = NULL; - eax = get_fixed_var(s->b_parent, REG_EAX); + eax = get_fixed_var(s->b_parent, REG_xAX); state->reg1 = get_var(s->b_parent, J_INT); if (return_type == J_LONG) { - edx = get_fixed_var(s->b_parent, REG_EDX); + edx = get_fixed_var(s->b_parent, REG_xDX); state->reg2 = get_var(s->b_parent, J_INT); } select_insn(s, tree, reg_insn(INSN_PUSH_REG, state->right->reg2)); @@ -2030,7 +2030,7 @@ static void select_eh_prologue(struct basic_block *bb) { struct var_info *reg_eax; - reg_eax = get_fixed_var(bb->b_parent, REG_EAX); + reg_eax = get_fixed_var(bb->b_parent, REG_xAX); /* Save exception from exception_holder to exception stack slot */ eh_add_insn(bb, imm_reg_insn(INSN_MOV_THREAD_LOCAL_MEMDISP_REG, @@ -2064,13 +2064,13 @@ int select_instructions(struct compilation_unit *cu) struct basic_block *bb; int err = 0; - cu->frame_ptr = get_fixed_var(cu, REG_EBP); + cu->frame_ptr = get_fixed_var(cu, REG_xBP); if (!cu->frame_ptr) { err = -ENOMEM; goto out; } - cu->stack_ptr = get_fixed_var(cu, REG_ESP); + cu->stack_ptr = get_fixed_var(cu, REG_xSP); if (!cu->stack_ptr) { err = -ENOMEM; goto out; @@ -2079,9 +2079,9 @@ int select_instructions(struct compilation_unit *cu) /* * Let the liveness analysis pass know about caller saved registers. */ - get_fixed_var(cu, REG_EAX); - get_fixed_var(cu, REG_ECX); - get_fixed_var(cu, REG_EDX); + get_fixed_var(cu, REG_xAX); + get_fixed_var(cu, REG_xCX); + get_fixed_var(cu, REG_xDX); for_each_basic_block(bb, &cu->bb_list) insn_select(bb); diff --git a/arch/x86/insn-selector_64.brg b/arch/x86/insn-selector_64.brg deleted file mode 100644 index cc35f6f..0000000 --- a/arch/x86/insn-selector_64.brg +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2008 Pekka Enberg - * - * This file is released under the GPL version 2 with the following - * clarification and special exception: - * - * Linking this library statically or dynamically with other modules is - * making a combined work based on this library. Thus, the terms and - * conditions of the GNU General Public License cover the whole - * combination. - * - * As a special exception, the copyright holders of this library give you - * permission to link this library with independent modules to produce an - * executable, regardless of the license terms of these independent - * modules, and to copy and distribute the resulting executable under terms - * of your choice, provided that you also meet, for each linked independent - * module, the terms and conditions of the license of that module. An - * independent module is a module which is not derived from or based on - * this library. If you modify this library, you may extend this exception - * to your version of the library, but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. - * - * Please refer to the file LICENSE for details. - */ - -#include <jit/basic-block.h> -#include <jit/compilation-unit.h> -#include <jit/compiler.h> -#include <jit/emulate.h> -#include <jit/expression.h> -#include <jit/statement.h> - -#include <arch/instruction.h> -#include <arch/stack-frame.h> - -#include <assert.h> -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <vm/class.h> - -#define MBCGEN_TYPE struct basic_block -#define MBCOST_DATA struct basic_block -#define MBTREE_TYPE struct tree_node -#define MBTREE_OP(t) tree_op(t) -#define MBTREE_LEFT(t) tree->kids[0] -#define MBTREE_RIGHT(t) tree->kids[1] -#define MBREG_TYPE struct var_info * - -#define MBMAX_OPCODES STMT_LAST - -#define MONOBURG_LOG 1 -#define HAVE_ARRAY_ELEM_INIT 1 - -%% - -%termprefix EXPR_ OP_ STMT_ - -%start stmt - -reg: EXPR_VALUE 0 -{ - abort(); -} - -stmt: STMT_RETURN(reg) -{ - abort(); -} - -%% - -int select_instructions(struct compilation_unit *cu) -{ - abort(); -} -- 1.6.0.6 ------------------------------------------------------------------------------ Enter the BlackBerry Developer Challenge This is your chance to win up to $100,000 in prizes! For a limited time, vendors submitting new applications to BlackBerry App World(TM) will have the opportunity to enter the BlackBerry Developer Challenge. See full prize details at: http://p.sf.net/sfu/Challenge _______________________________________________ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel