-
Notifications
You must be signed in to change notification settings - Fork 758
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Asyncify: Instrument indirect calls from functions in add-list or onl…
…y-list (#2913) When doing manual tuning of calls using asyncify lists, we want it to be possible to write out all the functions that can be on the stack when pausing, and for that to work. This did not quite work right with the ignore-indirect option: that would ignore all indirect calls all the time, so that if foo() calls bar() indirectly, that indirect call was not instrumented (we didn't check for a pause around it), even if both foo() and bar() were listed. There was no way to make that work (except for not ignoring indirect calls at all). This PR makes the add-list and only-lists fully instrument the functions mentioned in them: both themselves, and indirect calls from them. (Note that direct calls need no special handling - we can just add the direct call target to the add-list or only-list.) This may add some overhead to existing users, but only in a function that is instrumented anyhow, and also indirect calls are slow anyhow, so it's probably fine. And it is simpler to do it this way instead of adding another list for indirect call handling.
- Loading branch information
Showing
3 changed files
with
262 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 195 additions & 0 deletions
195
test/passes/asyncify_pass-arg=asyncify-addlist@foo_pass-arg=asyncify-ignore-indirect.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
(module | ||
(type $none_=>_none (func)) | ||
(type $i32_=>_none (func (param i32))) | ||
(type $none_=>_i32 (func (result i32))) | ||
(import "env" "import" (func $import)) | ||
(memory $0 1 2) | ||
(table $0 1 funcref) | ||
(global $__asyncify_state (mut i32) (i32.const 0)) | ||
(global $__asyncify_data (mut i32) (i32.const 0)) | ||
(export "asyncify_start_unwind" (func $asyncify_start_unwind)) | ||
(export "asyncify_stop_unwind" (func $asyncify_stop_unwind)) | ||
(export "asyncify_start_rewind" (func $asyncify_start_rewind)) | ||
(export "asyncify_stop_rewind" (func $asyncify_stop_rewind)) | ||
(export "asyncify_get_state" (func $asyncify_get_state)) | ||
(func $foo | ||
(local $0 i32) | ||
(local $1 i32) | ||
(if | ||
(i32.eq | ||
(global.get $__asyncify_state) | ||
(i32.const 2) | ||
) | ||
(nop) | ||
) | ||
(local.set $0 | ||
(block $__asyncify_unwind (result i32) | ||
(block | ||
(block | ||
(if | ||
(i32.eq | ||
(global.get $__asyncify_state) | ||
(i32.const 2) | ||
) | ||
(block | ||
(i32.store | ||
(global.get $__asyncify_data) | ||
(i32.add | ||
(i32.load | ||
(global.get $__asyncify_data) | ||
) | ||
(i32.const -4) | ||
) | ||
) | ||
(local.set $1 | ||
(i32.load | ||
(i32.load | ||
(global.get $__asyncify_data) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
(block | ||
(if | ||
(i32.eq | ||
(global.get $__asyncify_state) | ||
(i32.const 0) | ||
) | ||
(call $nothing) | ||
) | ||
(if | ||
(if (result i32) | ||
(i32.eq | ||
(global.get $__asyncify_state) | ||
(i32.const 0) | ||
) | ||
(i32.const 1) | ||
(i32.eq | ||
(local.get $1) | ||
(i32.const 0) | ||
) | ||
) | ||
(block | ||
(call_indirect (type $none_=>_none) | ||
(i32.const 0) | ||
) | ||
(if | ||
(i32.eq | ||
(global.get $__asyncify_state) | ||
(i32.const 1) | ||
) | ||
(br $__asyncify_unwind | ||
(i32.const 0) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
(return) | ||
) | ||
) | ||
) | ||
(block | ||
(i32.store | ||
(i32.load | ||
(global.get $__asyncify_data) | ||
) | ||
(local.get $0) | ||
) | ||
(i32.store | ||
(global.get $__asyncify_data) | ||
(i32.add | ||
(i32.load | ||
(global.get $__asyncify_data) | ||
) | ||
(i32.const 4) | ||
) | ||
) | ||
) | ||
(nop) | ||
) | ||
(func $bar | ||
(call $nothing) | ||
(call_indirect (type $none_=>_none) | ||
(i32.const 0) | ||
) | ||
) | ||
(func $nothing | ||
(nop) | ||
) | ||
(func $asyncify_start_unwind (param $0 i32) | ||
(global.set $__asyncify_state | ||
(i32.const 1) | ||
) | ||
(global.set $__asyncify_data | ||
(local.get $0) | ||
) | ||
(if | ||
(i32.gt_u | ||
(i32.load | ||
(global.get $__asyncify_data) | ||
) | ||
(i32.load offset=4 | ||
(global.get $__asyncify_data) | ||
) | ||
) | ||
(unreachable) | ||
) | ||
) | ||
(func $asyncify_stop_unwind | ||
(global.set $__asyncify_state | ||
(i32.const 0) | ||
) | ||
(if | ||
(i32.gt_u | ||
(i32.load | ||
(global.get $__asyncify_data) | ||
) | ||
(i32.load offset=4 | ||
(global.get $__asyncify_data) | ||
) | ||
) | ||
(unreachable) | ||
) | ||
) | ||
(func $asyncify_start_rewind (param $0 i32) | ||
(global.set $__asyncify_state | ||
(i32.const 2) | ||
) | ||
(global.set $__asyncify_data | ||
(local.get $0) | ||
) | ||
(if | ||
(i32.gt_u | ||
(i32.load | ||
(global.get $__asyncify_data) | ||
) | ||
(i32.load offset=4 | ||
(global.get $__asyncify_data) | ||
) | ||
) | ||
(unreachable) | ||
) | ||
) | ||
(func $asyncify_stop_rewind | ||
(global.set $__asyncify_state | ||
(i32.const 0) | ||
) | ||
(if | ||
(i32.gt_u | ||
(i32.load | ||
(global.get $__asyncify_data) | ||
) | ||
(i32.load offset=4 | ||
(global.get $__asyncify_data) | ||
) | ||
) | ||
(unreachable) | ||
) | ||
) | ||
(func $asyncify_get_state (result i32) | ||
(global.get $__asyncify_state) | ||
) | ||
) |
18 changes: 18 additions & 0 deletions
18
test/passes/asyncify_pass-arg=asyncify-addlist@foo_pass-arg=asyncify-ignore-indirect.wast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
(module | ||
(type $t (func)) | ||
(memory 1 2) | ||
(table 1 funcref) | ||
(elem (i32.const 0)) | ||
(import "env" "import" (func $import)) | ||
(func $foo ;; doesn't look like it needs instrumentation, but in add list | ||
(call $nothing) | ||
(call_indirect (type $t) (i32.const 0)) | ||
) | ||
(func $bar ;; doesn't look like it needs instrumentation, and not in add list | ||
(call $nothing) | ||
(call_indirect (type $t) (i32.const 0)) | ||
) | ||
(func $nothing | ||
) | ||
) | ||
|