diff --git a/jit/jit-dump.c b/jit/jit-dump.c index 34be06f..b8de4cd 100644 --- a/jit/jit-dump.c +++ b/jit/jit-dump.c @@ -782,19 +782,19 @@ void jit_dump_function(FILE *stream, jit_function_t func, const char *name) { /* We have extra hidden parameters */ putc('[', stream); - if(func->nested_parent) + if(value) { - jit_dump_value(stream, func, func->parent_frame, 0); - fputs(" : parent_frame", stream); - if(value) + jit_dump_value(stream, func, value, 0); + fputs(" : struct_ptr", stream); + if(func->nested_parent) { fputs(", ", stream); } } - if(value) + if(func->nested_parent) { - jit_dump_value(stream, func, value, 0); - fputs(" : struct_ptr", stream); + jit_dump_value(stream, func, func->parent_frame, 0); + fputs(" : parent_frame", stream); } putc(']', stream); if(num_params > 0) diff --git a/jit/jit-rules-interp.c b/jit/jit-rules-interp.c index 3def1f1..0a8d644 100644 --- a/jit/jit-rules-interp.c +++ b/jit/jit-rules-interp.c @@ -287,6 +287,17 @@ int _jit_create_entry_insns(jit_function_t func) flipped when we output the argument opcodes for interpretation */ offset = -1; + /* Allocate the structure return pointer */ + value = jit_value_get_struct_pointer(func); + if(value) + { + if(!jit_insn_incoming_frame_posn(func, value, offset)) + { + return 0; + } + --offset; + } + /* If the function is nested, then we an extra parameter to pass the pointer to the parent's frame */ if(func->nested_parent) @@ -308,17 +319,6 @@ int _jit_create_entry_insns(jit_function_t func) --offset; } - /* Allocate the structure return pointer */ - value = jit_value_get_struct_pointer(func); - if(value) - { - if(!jit_insn_incoming_frame_posn(func, value, offset)) - { - return 0; - } - --offset; - } - /* Allocate the parameter offsets */ num_params = jit_type_num_params(signature); for(param = 0; param < num_params; ++param) @@ -489,15 +489,15 @@ int _jit_create_call_setup_insns { /* Copy the arguments into our own parameter slots */ offset = -1; - if(func->nested_parent) - { - offset -= 2; - } type = jit_type_get_return(signature); if(jit_type_return_via_pointer(type)) { --offset; } + if(func->nested_parent) + { + --offset; + } for(arg_num = 0; arg_num < num_args; ++arg_num) { type = jit_type_get_param(signature, arg_num); @@ -1274,13 +1274,13 @@ void _jit_gen_insn(jit_gencode_t gen, jit_function_t func, _jit_gen_fix_value(insn->value2); offset = insn->value2->frame_offset; - if(offset >= 0) + if(offset > 0) { /* load the pointer to the stack frame the target value resides in into r0 */ load_value(gen, insn->value1, 1); } - else + else if(offset < 0) { /* The target value is in the argument frame of its function. We have to load the argument frame pointer first */ @@ -1289,7 +1289,7 @@ void _jit_gen_insn(jit_gencode_t gen, jit_function_t func, target_func->arguments_pointer_offset = target_func->arguments_pointer->frame_offset; - /* This will load the argument frame pointer into r0 */ + /* This will load the argument frame pointer into r1 */ load_value(gen, insn->value1, 1); jit_cache_native(gen, JIT_OP_LOAD_RELATIVE_LONG); jit_cache_native(gen, @@ -1305,6 +1305,12 @@ void _jit_gen_insn(jit_gencode_t gen, jit_function_t func, load_value(gen, insn->dest, 1); } } + else + { + /* The import targets address is 0 bytes off the frame pointer. This + means the import basically becomes an dest <- value1 op */ + load_value(gen, insn->value1, 0); + } if(offset != 0) { diff --git a/jit/jit-rules-x86-64.c b/jit/jit-rules-x86-64.c index e45b388..42014bf 100644 --- a/jit/jit-rules-x86-64.c +++ b/jit/jit-rules-x86-64.c @@ -3679,6 +3679,19 @@ _jit_create_entry_insns(jit_function_t func) /* Let the specific backend initialize it's part of the params */ _jit_init_args(abi, &passing); + /* Allocate the structure return pointer */ + if((value = jit_value_get_struct_pointer(func))) + { + jit_memset(&struct_return_param, 0, sizeof(_jit_param_t)); + if(!(_jit_classify_param(&passing, &struct_return_param, + jit_type_void_ptr))) + { + return 0; + } + struct_return_param.value = value; + has_struct_return = 1; + } + /* If the function is nested, then we need an extra parameter to pass the pointer to the parent's local variable frame */ if(func->nested_parent) @@ -3694,19 +3707,6 @@ _jit_create_entry_insns(jit_function_t func) jit_function_set_parent_frame(func, nested_param.value); } - /* Allocate the structure return pointer */ - if((value = jit_value_get_struct_pointer(func))) - { - jit_memset(&struct_return_param, 0, sizeof(_jit_param_t)); - if(!(_jit_classify_param(&passing, &struct_return_param, - jit_type_void_ptr))) - { - return 0; - } - struct_return_param.value = value; - has_struct_return = 1; - } - /* Let the backend classify the parameters */ for(current_param = 0; current_param < num_args; current_param++) { @@ -3741,17 +3741,17 @@ _jit_create_entry_insns(jit_function_t func) } } - if(has_struct_return) + if(func->nested_parent) { - if(!_jit_setup_incoming_param(func, &struct_return_param, jit_type_void_ptr)) + if(!_jit_setup_incoming_param(func, &nested_param, jit_type_void_ptr)) { return 0; } } - if(func->nested_parent) + if(has_struct_return) { - if(!_jit_setup_incoming_param(func, &nested_param, jit_type_void_ptr)) + if(!_jit_setup_incoming_param(func, &struct_return_param, jit_type_void_ptr)) { return 0; } @@ -3903,12 +3903,12 @@ int _jit_create_call_setup_insns } } - /* Handle the parent's frame pointer if it's passed on the stack */ - if(is_nested) + /* Handle the structure return pointer if it's passed on the stack */ + if(return_ptr) { - if(nested_param.arg_class == JIT_ARG_CLASS_STACK) + if(struct_return_param.arg_class == JIT_ARG_CLASS_STACK) { - if(!_jit_setup_outgoing_param(func, &nested_param, + if(!_jit_setup_outgoing_param(func, &struct_return_param, jit_type_void_ptr)) { return 0; @@ -3916,12 +3916,12 @@ int _jit_create_call_setup_insns } } - /* Handle the structure return pointer if it's passed on the stack */ - if(return_ptr) + /* Handle the parent's frame pointer if it's passed on the stack */ + if(is_nested) { - if(struct_return_param.arg_class == JIT_ARG_CLASS_STACK) + if(nested_param.arg_class == JIT_ARG_CLASS_STACK) { - if(!_jit_setup_outgoing_param(func, &struct_return_param, + if(!_jit_setup_outgoing_param(func, &nested_param, jit_type_void_ptr)) { return 0; diff --git a/jit/jit-rules.c b/jit/jit-rules.c index 7c770b3..ba9fba2 100644 --- a/jit/jit-rules.c +++ b/jit/jit-rules.c @@ -506,6 +506,10 @@ int _jit_create_call_setup_insns /* Determine how many parameters are going to end up in word registers, and compute the largest stack size needed to pass stack parameters */ + if(is_nested) + { + need_outgoing_word(&passing); + } type = jit_type_get_return(signature); if(jit_type_return_via_pointer(type)) { @@ -527,10 +531,6 @@ int _jit_create_call_setup_insns *struct_return = 0; return_ptr = 0; } - if(is_nested) - { - need_outgoing_word(&passing); - } partial = 0; for(param = 0; param < num_args; ++param) {