From 00f8f12fb81aa0e9dbe365194925bc19ef9ef6fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20L=C3=B6w?= Date: Sun, 26 Aug 2018 18:17:55 +0200 Subject: [PATCH] Add a special OP for retrieving the frame pointer previousely this was handeled by incoming_reg however the register allocator doesn't allow to move registers from different reg classes. Nesting is tested on x86-86, x86 and the interpreter. --- attic/jit-rules-alpha.ins | 5 +++++ jit/jit-dump.c | 3 ++- jit/jit-insn.c | 30 ++---------------------------- jit/jit-interp.c | 8 ++++++++ jit/jit-opcodes.ops | 1 + jit/jit-rules-arm.ins | 5 +++++ jit/jit-rules-x86-64.ins | 5 +++++ jit/jit-rules-x86.ins | 5 +++++ jit/jit-rules.c | 3 ++- 9 files changed, 35 insertions(+), 30 deletions(-) diff --git a/attic/jit-rules-alpha.ins b/attic/jit-rules-alpha.ins index 5cc5810..768b9ea 100644 --- a/attic/jit-rules-alpha.ins +++ b/attic/jit-rules-alpha.ins @@ -450,6 +450,11 @@ JIT_OP_RETURN_REG: manual /* Nothing to do here */; } +JIT_OP_RETRIEVE_FRAME_POINTER: note + [=reg] -> { + alpha_mov(inst,$1,ALPHA_FP); + } + JIT_OP_PUSH_INT: note [imm] -> { alpha_li(inst,ALPHA_AT,$1); diff --git a/jit/jit-dump.c b/jit/jit-dump.c index 7d59e6c..51f70f7 100644 --- a/jit/jit-dump.c +++ b/jit/jit-dump.c @@ -794,7 +794,8 @@ void jit_dump_function(FILE *stream, jit_function_t func, const char *name) putc('[', stream); if(func->nested_parent) { - fputs("parent_frame", stream); + jit_dump_value(stream, func, func->parent_frame, 0); + fputs(" : parent_frame", stream); if(value) { fputs(", ", stream); diff --git a/jit/jit-insn.c b/jit/jit-insn.c index 7f044d6..c192fcd 100644 --- a/jit/jit-insn.c +++ b/jit/jit-insn.c @@ -6292,34 +6292,8 @@ jit_insn_flush_struct(jit_function_t func, jit_value_t value) jit_value_t jit_insn_get_frame_pointer(jit_function_t func) { - int reg; - jit_value_t value; - - value = jit_value_create(func, jit_type_void_ptr); - if(!value) - { - return 0; - } - - for(reg = 0; reg < JIT_NUM_REGS; reg++) - { - if(jit_reg_flags(reg) & JIT_REG_FRAME) - { - break; - } - } - - if(reg < JIT_NUM_REGS) - { - jit_insn_incoming_reg(func, value, reg); - } - else - { - jit_insn_incoming_frame_posn(func, value, 0); - value = jit_insn_address_of(func, value); - } - - return value; + return create_dest_note(func, JIT_OP_RETRIEVE_FRAME_POINTER, + jit_type_void_ptr); } static jit_value_t diff --git a/jit/jit-interp.c b/jit/jit-interp.c index 45e52f8..3d3706e 100644 --- a/jit/jit-interp.c +++ b/jit/jit-interp.c @@ -4892,6 +4892,14 @@ restart_tail: * Stack management. ******************************************************************/ + VMCASE(JIT_OP_RETRIEVE_FRAME_POINTER): + { + /* Move the frame pointer into the register 0 */ + VM_R0_PTR = frame; + VM_MODIFY_PC(1); + } + VMBREAK; + VMCASE(JIT_OP_POP_STACK): { /* Pop a specific number of items from the stack */ diff --git a/jit/jit-opcodes.ops b/jit/jit-opcodes.ops index 90ed882..a5c5de2 100644 --- a/jit/jit-opcodes.ops +++ b/jit/jit-opcodes.ops @@ -797,6 +797,7 @@ opcodes(JIT_OP_, "jit_opcode_info_t const jit_opcodes[JIT_OP_NUM_OPCODES]") op_def("outgoing_reg") { op_type(reg) } op_def("outgoing_frame_posn") { op_values(empty, any, int) } op_def("return_reg") { op_type(reg) } + op_def("retrieve_frame_pointer") { op_values(any, empty, empty) } op_def("push_int") { op_values(empty, int) } op_def("push_long") { op_values(empty, long) } op_def("push_float32") { op_values(empty, float32) } diff --git a/jit/jit-rules-arm.ins b/jit/jit-rules-arm.ins index 624fd45..861d1a0 100644 --- a/jit/jit-rules-arm.ins +++ b/jit/jit-rules-arm.ins @@ -1321,6 +1321,11 @@ JIT_OP_INCOMING_REG, JIT_OP_RETURN_REG: note * and free the register if the value is dead. */ } + +JIT_OP_RETRIEVE_FRAME_POINTER: note + [=reg] -> { + arm_mov_reg_reg(inst, $1, ARM_FP); + } JIT_OP_PUSH_INT: note [reg] -> { diff --git a/jit/jit-rules-x86-64.ins b/jit/jit-rules-x86-64.ins index 2a26669..80d0850 100644 --- a/jit/jit-rules-x86-64.ins +++ b/jit/jit-rules-x86-64.ins @@ -388,6 +388,11 @@ JIT_OP_INCOMING_REG, JIT_OP_RETURN_REG: note */ } +JIT_OP_RETRIEVE_FRAME_POINTER: note + [=reg] -> { + x86_64_mov_reg_reg_size(inst, $1, X86_64_RBP, 8); + } + JIT_OP_PUSH_INT: note [imm] -> { x86_64_push_imm(inst, $1); diff --git a/jit/jit-rules-x86.ins b/jit/jit-rules-x86.ins index c298a6b..2ab2177 100644 --- a/jit/jit-rules-x86.ins +++ b/jit/jit-rules-x86.ins @@ -1993,6 +1993,11 @@ JIT_OP_INCOMING_REG, JIT_OP_RETURN_REG: note */ } +JIT_OP_RETRIEVE_FRAME_POINTER: note + [=reg] -> { + x86_mov_reg_reg(inst, $1, X86_EBP, 4); + } + JIT_OP_PUSH_INT: note [imm] -> { x86_push_imm(inst, $1); diff --git a/jit/jit-rules.c b/jit/jit-rules.c index 5c0e8c8..7c770b3 100644 --- a/jit/jit-rules.c +++ b/jit/jit-rules.c @@ -172,7 +172,8 @@ int _jit_create_entry_insns(jit_function_t func) { return 0; } - func->builder->parent_frame = value; + + jit_function_set_parent_frame(func, value); if(!alloc_incoming_word(func, &passing, value, 0)) { return 0;