Skip to content

Add the tail-call feature support for classic-interp#8

Open
qinxk-inter wants to merge 2 commits into
mainfrom
tail_call
Open

Add the tail-call feature support for classic-interp#8
qinxk-inter wants to merge 2 commits into
mainfrom
tail_call

Conversation

@qinxk-inter
Copy link
Copy Markdown
Owner

@qinxk-inter qinxk-inter commented Sep 22, 2020

fast-interp is still WIP

}

func->has_op_func_call = true;
if (opcode == WASM_OP_RETURN_CALL_INDIRECT) { goto handle_op_return; }
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Postpone this part to fast-interpreter implementation.

Comment on lines +3240 to +3184
FREE_FRAME(exec_env, frame);
word_copy(frame->lp, frame_sp, cur_func->param_cell_num);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but logically, we had better FREE_FRAME after word_copy

Suggested change
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);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines 4532 to 4611
#if WASM_ENABLE_FAST_INTERP != 0
/* emit the offset after return opcode */
POP_OFFSET_TYPE(ret_type);
#endif
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Suggested change
#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

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Postpone this part to fast-interpreter implementation.

Comment on lines +1429 to +1433
if (cur_func->is_import_func
#if WASM_ENABLE_MULTI_MODULE != 0
&& !cur_func->import_func_inst
#endif
)

This comment was marked as resolved.

Comment thread core/iwasm/interpreter/wasm_opcode.h Outdated
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.

goto call_func_from_interp;
}

HANDLE_OP (WASM_OP_RETURN_CALL_INDIRECT):

This comment was marked as resolved.

This comment was marked as resolved.

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.

Comment thread core/iwasm/interpreter/wasm_loader.c Outdated
}

func->has_op_func_call = true;
if (opcode == WASM_OP_RETURN_CALL) { goto handle_op_return; }

This comment was marked as resolved.


case WASM_OP_RETURN:
{
int32 idx;

This comment was marked as resolved.

}

case WASM_OP_CALL_INDIRECT:
case WASM_OP_RETURN_CALL_INDIRECT:

This comment was marked as resolved.

@qinxk-inter qinxk-inter marked this pull request as draft September 23, 2020 08:36
@qinxk-inter qinxk-inter force-pushed the tail_call branch 2 times, most recently from a28deff to 96ebc37 Compare September 23, 2020 08:55
@qinxk-inter qinxk-inter marked this pull request as ready for review September 23, 2020 09:01
Comment on lines +1296 to +1297
wasm_set_exception(module, "unknown function");
goto got_exception;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@qinxk-inter qinxk-inter marked this pull request as draft September 23, 2020 09:54
@qinxk-inter qinxk-inter marked this pull request as ready for review September 23, 2020 10:06
@qinxk-inter qinxk-inter marked this pull request as draft September 23, 2020 10:19
Signed-off-by: Xiaokang Qin <xiaokang.qxk@antgroup.com>
@qinxk-inter qinxk-inter marked this pull request as ready for review September 23, 2020 12:11
* add CI for tail call and custom name section

* update CI for mac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants