Skip to content

Conversation

@wenyongh
Copy link
Collaborator

No description provided.

@wenyongh wenyongh changed the title [WIP] Implement part of codegen Implement part of codegen Mar 21, 2022

/* Pop block and load block results */
block = jit_block_stack_pop(&cc->block_stack);
if (!load_block_results(cc, block)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

L414 if(!block->incoming_insn_for_end_bb) also needs to transfer return values from the if block or else block to the outer block.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Seems no need to change the jit_frame, just move result values from popped block's value stack into previous block's value stack?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, only return values . No basic_block, No modification of jit_frame.

Copy link
Contributor

Choose a reason for hiding this comment

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

But still, need to handle the special case of LABE_TYPE_FUNCTION

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!load_block_results(cc, block)) {
if (block->label_type == LABEL_TYPE_FUNCTION) {
handle_func_return(cc, block);
SET_BB_END_BCIP(cc->cur_basic_block, *p_frame_ip - 1);
}
else {
if (!load_block_result(cc, block) {
}

INSN(RETURNBC, Reg, 1, 0)
INSN(CALLBC, Reg, 3, 2)
INSN(RETURNBC, Reg, 3, 0)
INSN(RETURN, Reg, 1, 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the difference between CALLNATIVE and CALLBC? and between RETURNBC and RETURN ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

CALLNATIVE is to call a native function, including runtime APIs (e.g., jit_set_exception_with_id) and native APIs (e.g., libc-builtin, libc-wasi, etc.), we must use call instruction to call that native function, and pass the arguments/results according the calling convention of host, e.g., ABI of Linux/Windows.

CALLBC means call bytecode, it is to call the wasm function, currently we only call the jited code of wasm function, in the future, we might return back to interpreter to call the wasm function, if it hasn't been compiled into jited code. Note that we use jmp instruction but not call instruction to jump to the jited code, and the arguments/results are passed by interpreter stack frame.

RETURNBC is to return to the caller from current jited code, if the caller is a wasm function, we jump to the next instruction of caller's jmp instruction (used by CALLBC) to let caller continue to run. If the caller is interpreter, we jump to the global code block jit_globals->return_to_interp_from_jitted to return to interpreter.

RETURN is used when exception was thrown, and we want to return to interpreter directly.

@wenyongh wenyongh merged commit f7b6cd7 into bytecodealliance:dev/fast_jit Mar 22, 2022
wenyongh added a commit to wenyongh/wasm-micro-runtime that referenced this pull request Mar 22, 2022
Implement part of codegen, add asmjit and zydis (bytecodealliance#1050)
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.

2 participants