Skip to content

Commit

Permalink
[wasm] Introduce jiterpreter control flow pass (#83247)
Browse files Browse the repository at this point in the history
* Checkpoint CFG

Generate fallthrough in CFG

Generate branch block header partially in cfg

Emit branches in CFG

Checkpoint: Emit loop and exit return in CFG (broken)

Fix CFG emitting function header in the wrong place

Improve accuracy of cfg size estimation

Remove log messages

Checkpoint: Forward branches partially working

Fix non-conditional branches not being added to target table
Remove fallthrough

* Implement backward branches via a dispatch table

* Cleanup

* Cleanup

* Remove use of DataView since it has a hazard around heap growth
Use copyWithin to implement appendBytes where possible
More accurate overhead calculation
  • Loading branch information
kg committed Mar 10, 2023
1 parent 35f3853 commit b900242
Show file tree
Hide file tree
Showing 5 changed files with 414 additions and 185 deletions.
25 changes: 25 additions & 0 deletions src/mono/mono/mini/interp/jiterpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,31 @@ mono_jiterp_get_member_offset (int member) {
}
}

#define JITERP_NUMBER_MODE_U32 0
#define JITERP_NUMBER_MODE_I32 1
#define JITERP_NUMBER_MODE_F32 2
#define JITERP_NUMBER_MODE_F64 3

EMSCRIPTEN_KEEPALIVE void
mono_jiterp_write_number_unaligned (void *dest, double value, int mode) {
switch (mode) {
case JITERP_NUMBER_MODE_U32:
*((uint32_t *)dest) = (uint32_t)value;
return;
case JITERP_NUMBER_MODE_I32:
*((int32_t *)dest) = (int32_t)value;
return;
case JITERP_NUMBER_MODE_F32:
*((float *)dest) = (float)value;
return;
case JITERP_NUMBER_MODE_F64:
*((double *)dest) = value;
return;
default:
g_assert_not_reached();
}
}

// HACK: fix C4206
EMSCRIPTEN_KEEPALIVE
#endif // HOST_BROWSER
Expand Down
2 changes: 2 additions & 0 deletions src/mono/wasm/runtime/cwraps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const fn_signatures: SigLine[] = [
[false, "mono_jiterp_encode_leb52", "number", ["number", "number", "number"]],
[false, "mono_jiterp_encode_leb64_ref", "number", ["number", "number", "number"]],
[false, "mono_jiterp_encode_leb_signed_boundary", "number", ["number", "number", "number"]],
[false, "mono_jiterp_write_number_unaligned", "void", ["number", "number", "number"]],
[true, "mono_jiterp_type_is_byref", "number", ["number"]],
[true, "mono_jiterp_get_size_of_stackval", "number", []],
[true, "mono_jiterp_parse_option", "number", ["string"]],
Expand Down Expand Up @@ -234,6 +235,7 @@ export interface t_Cwraps {
mono_jiterp_debug_count(): number;
mono_jiterp_get_trace_hit_count(traceIndex: number): number;
mono_jiterp_get_polling_required_address(): Int32Ptr;
mono_jiterp_write_number_unaligned(destination: VoidPtr, value: number, mode: number): void;
}

const wrapped_c_functions: t_Cwraps = <any>{};
Expand Down
Loading

0 comments on commit b900242

Please sign in to comment.