Add the tail-call feature support for classic-interp#8
Conversation
| } | ||
|
|
||
| func->has_op_func_call = true; | ||
| if (opcode == WASM_OP_RETURN_CALL_INDIRECT) { goto handle_op_return; } |
There was a problem hiding this comment.
Same with the previous comment. Need to set a flag to avoid emitting operand when build as fast-interpreter
And same in wasm_loader.c
There was a problem hiding this comment.
Postpone this part to fast-interpreter implementation.
| FREE_FRAME(exec_env, frame); | ||
| word_copy(frame->lp, frame_sp, cur_func->param_cell_num); |
There was a problem hiding this comment.
This works, but logically, we had better FREE_FRAME after word_copy
| FREE_FRAME(exec_env, frame); | |
| word_copy(frame->lp, frame_sp, cur_func->param_cell_num); | |
| word_copy(frame->lp, frame_sp, cur_func->param_cell_num); | |
| FREE_FRAME(exec_env, frame); |
There was a problem hiding this comment.
FREE_FRAME() first is because the tail call logic, pop the stack frame then call. More clear way may be FREE_FRAME(), outs_area to get stack_top and then word_copy() to it. But actually the outs_area operations could be saved by using current frame directly, and this is also suggested by @wenyongh in ppt. :) So less codes or clear logic?
There was a problem hiding this comment.
Yes, we should use frame->lp directly rather than get outs_area.
My concern here is: the frame->lp is referenced after FREE_FRAME(exec_env, frame), we know this will work just because we know FREE_FRAME will not modify the content in the memory, but how about we don't know? Just like dereference a freed pointer free(ptr); a = *ptr;. On most platforms free will not set ptr to NULL, but we never do this.
How do you think of this? @wenyongh
| #if WASM_ENABLE_FAST_INTERP != 0 | ||
| /* emit the offset after return opcode */ | ||
| POP_OFFSET_TYPE(ret_type); | ||
| #endif |
There was a problem hiding this comment.
In fast-interpreter mode, when we jump into this branch from WASM_OP_RETURN_CALL the POP_OFFSET_TYPE(ret_type) will emit operand, which will make the generated code incorrect.
Maybe we need a flag to avoid POP_OFFSET_TYPE(ret_type) if we're checking result of tail call:
| #if WASM_ENABLE_FAST_INTERP != 0 | |
| /* emit the offset after return opcode */ | |
| POP_OFFSET_TYPE(ret_type); | |
| #endif | |
| #if WASM_ENABLE_FAST_INTERP != 0 | |
| if (!tail_call_return_check) | |
| /* emit the offset after return opcode */ | |
| POP_OFFSET_TYPE(ret_type); | |
| #endif |
and reset the flag after the switch block
There was a problem hiding this comment.
Postpone this part to fast-interpreter implementation.
| if (cur_func->is_import_func | ||
| #if WASM_ENABLE_MULTI_MODULE != 0 | ||
| && !cur_func->import_func_inst | ||
| #endif | ||
| ) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| WASM_OP_CALL = 0x10, /* call */ | ||
| WASM_OP_CALL_INDIRECT = 0x11, /* call_indirect */ | ||
| WASM_OP_RETURN_CALL = 0x12, /* return_call */ | ||
| WASM_OP_RETURN_CALL_INDIRECT = 0x13, /* return_call_indirect */ |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| goto call_func_from_interp; | ||
| } | ||
|
|
||
| HANDLE_OP (WASM_OP_RETURN_CALL_INDIRECT): |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| HANDLE_OP (WASM_OP_UNUSED_0x08): | ||
| HANDLE_OP (WASM_OP_UNUSED_0x09): | ||
| HANDLE_OP (WASM_OP_UNUSED_0x0a): | ||
| HANDLE_OP (WASM_OP_UNUSED_0x12): |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| } | ||
|
|
||
| func->has_op_func_call = true; | ||
| if (opcode == WASM_OP_RETURN_CALL) { goto handle_op_return; } |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
|
||
| case WASM_OP_RETURN: | ||
| { | ||
| int32 idx; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| } | ||
|
|
||
| case WASM_OP_CALL_INDIRECT: | ||
| case WASM_OP_RETURN_CALL_INDIRECT: |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
7d05f63 to
f182330
Compare
a28deff to
96ebc37
Compare
| wasm_set_exception(module, "unknown function"); | ||
| goto got_exception; |
There was a problem hiding this comment.
seems this file is 2 spaces indented
|
|
||
| #if WASM_ENABLE_TAIL_CALL != 0 | ||
| if (opcode == WASM_OP_RETURN_CALL_INDIRECT) | ||
| goto call_func_from_return_call; |
96ebc37 to
bcbe6a9
Compare
bcbe6a9 to
c23b603
Compare
Signed-off-by: Xiaokang Qin <xiaokang.qxk@antgroup.com>
* add CI for tail call and custom name section * update CI for mac
fast-interp is still WIP